blib/lib/ExtUtils/XSpp/Lexer.pm

filter: Statementstmt 94.7% 250 / 264 Branchbran 78.5% 66 / 84 Conditioncond 88.2% 15 / 17 MC/DCmcdc 70.0% 7 / 10 Subroutinesub 96.2% 51 / 53 Podpod 0.0% 0 / 27 totaltotal 85.4% 389 / 455 CC 52 SCAR 23.3
CC
52
Cov
91%
yylex
30.0
create_class
8.2
yyerror
6.0
CRAP 10.2
« blib/lib/ExtUtils/XSpp/Cmd.pm ↑ Summary blib/lib/ExtUtils/XSpp/Node/Class.pm »
1 # this module will be loaded by ExtUtils/XSpp/Grammar.pm and needs to
2 # define subroutines in the ExtUtils::XSpp::Grammar namespace
3 package ExtUtils::XSpp::Lexer;
4 # for the indexer and friends
5 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package ExtUtils::XSpp::Grammar;
9  
10 21 ▶use ExtUtils::XSpp::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use ExtUtils::XSpp::Node::Access;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use ExtUtils::XSpp::Node::Argument;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use ExtUtils::XSpp::Node::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use ExtUtils::XSpp::Node::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use ExtUtils::XSpp::Node::Constructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use ExtUtils::XSpp::Node::Destructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use ExtUtils::XSpp::Node::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 21 ▶use ExtUtils::XSpp::Node::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 21 ▶use ExtUtils::XSpp::Node::Member;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 ▶use ExtUtils::XSpp::Node::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 21 ▶use ExtUtils::XSpp::Node::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 21 ▶use ExtUtils::XSpp::Node::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 21 ▶use ExtUtils::XSpp::Node::Raw;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 21 ▶use ExtUtils::XSpp::Node::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 21 ▶use ExtUtils::XSpp::Node::PercAny;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 21 ▶use ExtUtils::XSpp::Node::Enum;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 21 ▶use ExtUtils::XSpp::Node::EnumValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 21 ▶use ExtUtils::XSpp::Node::Preprocessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 21 ▶use ExtUtils::XSpp::Typemap;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 21 ▶use ExtUtils::XSpp::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 21 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 21 my %tokens = ( '::' => 'DCOLON',
36 ':' => 'COLON',
37 '%{' => 'OPSPECIAL',
38 '%}' => 'CLSPECIAL',
39 '{%' => 'OPSPECIAL',
40 '{' => 'OPCURLY',
41 '}' => 'CLCURLY',
42 '(' => 'OPPAR',
43 ')' => 'CLPAR',
44 ';' => 'SEMICOLON',
45 '%' => 'PERC',
46 '~' => 'TILDE',
47 '*' => 'STAR',
48 '&' => 'AMP',
49 '|' => 'PIPE',
50 ',' => 'COMMA',
51 '=' => 'EQUAL',
52 '/' => 'SLASH',
53 '.' => 'DOT',
54 '-' => 'DASH',
55 '<' => 'OPANG',
56 '>' => 'CLANG',
57 # these are here due to my lack of skill with yacc
58 '%name' => 'p_name',
59 '%typemap' => 'p_typemap',
60 '%exception' => 'p_exceptionmap',
61 '%catch' => 'p_catch',
62 '%file' => 'p_file',
63 '%module' => 'p_module',
64 '%code' => 'p_code',
65 '%cleanup' => 'p_cleanup',
66 '%postcall' => 'p_postcall',
67 '%package' => 'p_package',
68 '%length' => 'p_length',
69 '%loadplugin' => 'p_loadplugin',
70 '%include' => 'p_include',
71 '%alias' => 'p_alias',
72 '%_type' => 'p__type',
73 );
74  
75 21 my %keywords = ( const => 1,
76 class => 1,
77 unsigned => 1,
78 short => 1,
79 long => 1,
80 int => 1,
81 char => 1,
82 void => 1,
83 package_static => 1,
84 class_static => 1,
85 static => 1,
86 public => 1,
87 private => 1,
88 protected => 1,
89 virtual => 1,
90 enum => 1,
91 );
92  
93 3603 ▶sub get_lex_mode { return $_[0]->YYData->{LEX}{MODES}[0] || '' }
Subroutine get_lex_mode: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
$_[0]->YYData->{'LEX'}{'MODES'}[0] || ''
l!l
1143489
MC/DC100%1/1
$_[0]->YYData->{'LEX'}{'MODES'}[0] || ''
$_[0]->YYData->{'LEX'}{'MODES'}[0]
Truth table100%2/2
A
A= $_[0]->YYData->{'LEX'}{'MODES'}[0]
Aresult
11
00
94  
95 33 ▶sub push_lex_mode {
Subroutine push_lex_mode: called CC=1 SCAR=0.0
Pod undocumented
96 33 my( $p, $mode ) = @_;
97  
98 33 push @{$p->YYData->{LEX}{MODES}}, $mode;
99 }
100  
101 33 ▶sub pop_lex_mode {
Subroutine pop_lex_mode: called CC=2 SCAR=7.0
Pod undocumented
102 33 my( $p, $mode ) = @_;
103  
104 33 ▶ die "Unexpected mode: '$mode'"
Branch: 1 branch
BranchTrueFalseTotal
unless get_lex_mode($p) eq $mode 0 33 33
105 unless get_lex_mode( $p ) eq $mode;
106  
107 33 pop @{$p->YYData->{LEX}{MODES}};
108 }
109  
110 841 ▶sub read_more {
Subroutine read_more: called CC=4 SCAR=13.9
Pod undocumented
111 841 my $v = readline $_[0]->YYData->{LEX}{FH};
112 841 my $buf = $_[0]->YYData->{LEX}{BUFFER};
113  
114 841 ▶ unless( defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 88 753 841
115 88 ▶ if( $_[0]->YYData->{LEX}{NEXT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->YYData->{'LEX'}{'NEXT'}) { } 2 86 88
116 2 $_[0]->YYData->{LEX} = $_[0]->YYData->{LEX}{NEXT};
117 2 $buf = $_[0]->YYData->{LEX}{BUFFER};
118  
119 2 ▶ return $buf if length $$buf;
Branch: 1 branch
BranchTrueFalseTotal
if length $$buf 2 0 2
120 0 return read_more( $_[0] );
121 } else {
122 86 return;
123 }
124 }
125  
126 753 $$buf .= $v;
127  
128 753 return $buf;
129 }
130  
131 # for tests
132 0 ▶sub _random_digits { sprintf '%06d', rand 100000 }
Subroutine _random_digits: not called CC=1 SCAR=6.9
133  
134 12 ▶sub push_conditional {
Subroutine push_conditional: called CC=2 SCAR=7.0
Pod undocumented
135 12 my $p = $_[0];
136 my $file = $p->YYData->{LEX}{FILE} ?
137 12 ▶ substr md5_hex( $p->YYData->{LEX}{FILE} ), 0, 8 :
Branch: 1 branch
BranchTrueFalseTotal
$p->YYData->{'LEX'}{'FILE'} ? : 0 12 12
138 'zzzzzzzz';
139 12 my $rand = _random_digits;
140  
141 12 my $symbol = 'XSpp_' . $file . '_' . $rand;
142 12 push @{$p->YYData->{LEX}{CONDITIONAL}}, $symbol;
143  
144 12 return $symbol;
145 }
146  
147 12 ▶sub pop_conditional {
Subroutine pop_conditional: called CC=1 SCAR=0.0
Pod undocumented
148 12 pop @{$_[0]->YYData->{LEX}{CONDITIONAL}};
149 }
150  
151 171 ▶sub get_conditional {
Subroutine get_conditional: called CC=3 SCAR=11.0
Pod undocumented
152 171 ▶ return undef unless $_[0]->YYData->{LEX}{CONDITIONAL};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->YYData->{"LEX"}{"CONDITIONAL"} 163 8 171
153 8 ▶ return undef unless @{$_[0]->YYData->{LEX}{CONDITIONAL}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0]->YYData->{"LEX"}{"CONDITIONAL"};} 0 8 8
154 8 return $_[0]->YYData->{LEX}{CONDITIONAL}[-1];
155 }
156  
157 2972 ▶sub yylex {
Subroutine yylex: called CC=29 SCAR=34.0
Pod undocumented
158 2972 my $data = $_[0]->YYData->{LEX};
159 2972 my $buf = $data->{BUFFER};
160  
161 2972 for(;;) {
162 3656 ▶ if( !length( $$buf ) && !( $buf = read_more( $_[0] ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$buf or $buf = read_more($_[0])) 86 3570 3656
Condition100%3/3
length $$buf or $buf = read_more($_[0])
l!l&&r!l&&!r
281875286
MC/DC100%2/2
length $$buf or $buf = read_more($_[0])
length $$buf $buf = read_more($_[0])
Truth table100%3/3
A or B
A= length $$bufB= $buf = read_more($_[0])
ABresult
1X1
011
000
163 86 return ( '', undef );
164 }
165  
166 3570 ▶ if( get_lex_mode( $_[0] ) eq 'special' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (get_lex_mode($_[0]) eq 'special') { } 81 3489 3570
167 81 ▶ if( $$buf =~ s/^%}// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$buf =~ s/^%}//) { } 33 48 81
elsif ($$buf =~ s/^([^\n]*)\n$//) { } 48 0 48
168 33 return ( 'CLSPECIAL', '%}' );
169 } elsif( $$buf =~ s/^([^\n]*)\n$// ) {
170 48 my $line = $1;
171  
172 48 ▶ if( $line =~ m/^(.*?)\%}(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.*?)\%}(.*)$/) 27 21 48
173 27 $$buf = "%}$2\n";
174 27 $line = $1;
175 }
176  
177 48 return ( 'line', $line );
178 }
179 } else {
180 3489 $$buf =~ s/^[\s\n\r]+//;
181 3489 ▶ next unless length $$buf;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$buf 684 2805 3489
182  
183 2805 ▶ if( $$buf =~ s/^([+-]?0x[0-9a-fA-F]+)// ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($$buf =~ s/^([+-]?0x[0-9a-fA-F]+)//) { } 1 2804 2805
elsif ($$buf =~ s/^([+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)//) { } 14 2790 2804
elsif ($$buf =~ s[^//(.*)(?:\r\n|\r|\n)][]) { } 4 2786 2790
elsif ($$buf =~ m[^/\*]) { } 1 2785 2786
elsif ($$buf =~ s/^(\%\w+)//) { } 300 2485 2785
elsif ($$buf =~ s[^( \%} | \%\{ | \{\% | [{}();%~*&,=/\.\-<>|] | :: | : )][]x) { } 1491 994 2485
elsif ($$buf =~ s/^(INCLUDE(?:_COMMAND)?:.*)(?:\r\n|\r|\n)//) { } 0 994 994
elsif ($$buf =~ s/^([a-zA-Z_]\w*)//) { } 954 40 994
elsif ($$buf =~ s/^("[^"]*")//) { } 0 40 40
elsif ($$buf =~ s/^(#\s*(if|ifdef|ifndef|else|elif|endif)\b.*)(?:\r\n|\r|\n)//) { } 22 18 40
elsif ($$buf =~ s/^(#.*)(?:\r\n|\r|\n)//) { } 18 0 18
184 1 return ( 'INTEGER', $1 );
185 } elsif( $$buf =~ s/^([+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)// ) {
186 14 my $v = $1;
187 14 ▶ return ( 'INTEGER', $v ) if $v =~ /^[+-]?\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /^[+-]?\d+$/ 14 0 14
188 0 return ( 'FLOAT', $v );
189 } elsif( $$buf =~ s/^\/\/(.*)(?:\r\n|\r|\n)// ) {
190 4 return ( 'COMMENT', [ $1 ] );
191 } elsif( $$buf =~ /^\/\*/ ) {
192 1 my @rows;
193 1 ▶ for(; length( $$buf ) || ( $buf = read_more( $_[0] ) ); $$buf = '') {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$buf or $buf = read_more($_[0])) 4 0 4
Condition66%2/3
length $$buf or $buf = read_more($_[0])
l!l&&r!l&&!r
130
MC/DC0%0/2
length $$buf or $buf = read_more($_[0])
length $$buf $buf = read_more($_[0])
Truth table66%2/3
A or B
A= length $$bufB= $buf = read_more($_[0])
ABresult
1X1
011
000
194 4 ▶ if( $$buf =~ s/(.*?\*\/)// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$buf =~ s[(.*?\*/)][]) 1 3 4
195 1 push @rows, $1;
196 1 return ( 'COMMENT', \@rows );
197 }
198 3 $$buf =~ s/(?:\r\n|\r|\n)$//;
199 3 push @rows, $$buf;
200 }
201 } elsif( $$buf =~ s/^(\%\w+)// ) {
202 300 ▶ return ( $tokens{$1}, $1 ) if exists $tokens{$1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tokens{$1} 241 59 300
203 59 return ( 'p_any', substr $1, 1 );
204 } elsif( $$buf =~ s/^( \%}
205 | \%\{ | \{\%
206 | [{}();%~*&,=\/\.\-<>|]
207 | :: | :
208 )//x ) {
209 1491 return ( $tokens{$1}, $1 );
210 } elsif( $$buf =~ s/^(INCLUDE(?:_COMMAND)?:.*)(?:\r\n|\r|\n)// ) {
211 0 return ( 'RAW_CODE', "$1\n" );
212 } elsif( $$buf =~ s/^([a-zA-Z_]\w*)// ) {
213 954 ▶ return ( $1, $1 ) if exists $keywords{$1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $keywords{$1} 316 638 954
214  
215 638 return ( 'ID', $1 );
216 } elsif( $$buf =~ s/^("[^"]*")// ) {
217 0 return ( 'QUOTED_STRING', $1 );
218 } elsif( $$buf =~ s/^(#\s*(if|ifdef|ifndef|else|elif|endif)\b.*)(?:\r\n|\r|\n)// ) {
219 22 my $symbol;
220 22 ▶ if( $2 eq 'else' || $2 eq 'elif' || $2 eq 'endif' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "else" or $2 eq "elif" or $2 eq "endif") 12 10 22
Condition100%6/6
$2 eq "else" or $2 eq "elif" or $2 eq "endif"
l!l&&r!l&&!r
21010
$2 eq "else" or $2 eq "elif"
l!l&&r!l&&!r
1120
MC/DC100%3/3
$2 eq "else" or $2 eq "elif" or $2 eq "endif"
$2 eq "else" $2 eq "elif" $2 eq "endif"
Truth table100%4/4
A or B or C
A= $2 eq "else"B= $2 eq "elif"C= $2 eq "endif"
ABCresult
1XX1
01X1
0011
0000
221 12 pop_conditional( $_[0] );
222 }
223 22 ▶ if( $2 ne 'endif' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 ne "endif") 12 10 22
224 12 $symbol = push_conditional( $_[0] );
225 }
226  
227 22 return ( 'PREPROCESSOR', [ $1, $symbol ] );
228 } elsif( $$buf =~ s/^(#.*)(?:\r\n|\r|\n)// ) {
229 18 return ( 'RAW_CODE', $1 );
230 } else {
231 0 die $$buf;
232 }
233 }
234 }
235 }
236  
237 0 ▶sub yyerror {
Subroutine yyerror: not called CC=2 SCAR=17.9
Pod undocumented
238 0 my $data = $_[0]->YYData->{LEX};
239 0 my $buf = $data->{BUFFER};
240 0 my $fh = $data->{FH};
241  
242 0 ▶ print STDERR "Error: line " . $fh->input_line_number . " (Current token type: '",
Branch: 1 branch
BranchTrueFalseTotal
$buf ? : 0 0 0
243 $_[0]->YYCurtok, "') (Current value: '",
244 $_[0]->YYCurval, '\') Buffer: "', ( $buf ? $$buf : '--empty buffer--' ),
245 q{"} . "\n";
246 0 print STDERR "Expecting: (", ( join ", ", map { "'$_'" } $_[0]->YYExpect ),
247 ")\n";
248 }
249  
250 16 ▶sub make_const { $_[0]->{CONST} = 1; $_[0] }
Subroutine make_const: called CC=1 SCAR=0.0
Pod undocumented
251 13 ▶sub make_ref { $_[0]->{REFERENCE} = 1; $_[0] }
Subroutine make_ref: called CC=1 SCAR=0.0
Pod undocumented
252 9 ▶sub make_ptr { $_[0]->{POINTER}++; $_[0] }
Subroutine make_ptr: called CC=1 SCAR=0.0
Pod undocumented
253 256 ▶sub make_type { ExtUtils::XSpp::Node::Type->new( base => $_[0] ) }
Subroutine make_type: called CC=1 SCAR=0.0
Pod undocumented
254  
255 9 ▶sub make_template {
Subroutine make_template: called CC=1 SCAR=0.0
Pod undocumented
256 9 ExtUtils::XSpp::Node::Type->new( base => $_[0],
257 template_args => $_[1],
258 )
259 }
260  
261 28 ▶sub add_typemap {
Subroutine add_typemap: called CC=1 SCAR=0.0
Pod undocumented
262 28 my( $name, $type, @args ) = @_;
263 28 my $tm = ExtUtils::XSpp::Typemap::create( $name, type => $type, @args );
264  
265 28 ExtUtils::XSpp::Typemap::add_typemap_for_type( $type, $tm );
266 }
267  
268 24 ▶sub add_data_raw {
Subroutine add_data_raw: called CC=1 SCAR=0.0
Pod undocumented
269 24 my $p = shift;
270 24 my $rows = shift;
271  
272 24 ExtUtils::XSpp::Node::Raw->new( rows => $rows );
273 }
274  
275 5 ▶sub add_data_comment {
Subroutine add_data_comment: called CC=1 SCAR=0.0
Pod undocumented
276 5 my $p = shift;
277 5 my $rows = shift;
278  
279 5 ExtUtils::XSpp::Node::Comment->new( rows => $rows );
280 }
281  
282 2 ▶sub add_top_level_directive {
Subroutine add_top_level_directive: called CC=1 SCAR=0.0
Pod undocumented
283 2 my( $parser, %args ) = @_;
284  
285 $parser->YYData->{PARSER}->handle_toplevel_tag_plugins
286 ( $args{any},
287 named => $args{named},
288 positional => $args{positional},
289 any_named_arguments => $args{named},
290 any_positional_arguments => $args{positional},
291 2 condition => $parser->get_conditional,
292 );
293 }
294  
295 114 ▶sub make_argument {
Subroutine make_argument: called CC=1 SCAR=0.0
Pod undocumented
296 114 my( $p, $type, $name, $default, @args ) = @_;
297 114 my %args = @args;
298 114 _merge_keys( 'tag', \%args, \@args );
299  
300 my $arg = ExtUtils::XSpp::Node::Argument->new
301 ( type => $type,
302 name => $name,
303 default => $default,
304 114 tags => $args{tag} );
305  
306 114 return $arg;
307 }
308  
309 54 ▶sub create_class {
Subroutine create_class: called CC=8 SCAR=21.1
Pod undocumented
310 54 my( $parser, $name, $bases, $metadata, $methods, $condition ) = @_;
311 54 my %args = @$metadata;
312 54 _merge_keys( 'catch', \%args, $metadata );
313  
314 54 my $class = ExtUtils::XSpp::Node::Class->new( %args, # <-- catch only for now
315 cpp_name => $name,
316 base_classes => $bases,
317 condition => $condition,
318 );
319  
320 # when adding a class C, automatically add weak typemaps for C* and C&
321 54 ExtUtils::XSpp::Typemap::add_class_default_typemaps( $name );
322  
323 54 my @any = grep $_->isa( 'ExtUtils::XSpp::Node::PercAny' ), @$methods;
324 54 my @rest = grep !$_->isa( 'ExtUtils::XSpp::Node::PercAny' ), @$methods;
325  
326 # finish creating the class
327 54 $class->add_methods( @rest );
328  
329 54 foreach my $meth ( grep $_->isa( 'ExtUtils::XSpp::Node::Method' ), @rest ) {
330 51 call_argument_tags( $parser, $meth );
331  
332 51 my $nodes = $parser->YYData->{PARSER}->handle_method_tags_plugins( $meth, $meth->tags );
333  
334 51 $class->add_methods( @$nodes );
335 }
336  
337 54 foreach my $any ( @any ) {
338 8 ▶ if( $any->{NAME} eq 'accessors' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($any->{"NAME"} eq "accessors") 6 2 8
339 # TODO use plugin infrastructure, add decent validation
340 6 my %args = @{$any->{NAMED_ARGUMENTS}};
341 6 ▶ if( $args{get_style} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"get_style"}) 6 0 6
342 6 ▶ if( @{$args{get_style}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args{'get_style'};}) { } 6 0 6
343 6 $class->set_getter_style( $args{get_style}[0][0] );
344 } else {
345 0 die "Invalid accessor style declaration";
346 }
347 }
348 6 ▶ if( $args{set_style} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"set_style"}) 6 0 6
349 6 ▶ if( @{$args{set_style}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args{'set_style'};}) { } 6 0 6
350 6 $class->set_setter_style( $args{set_style}[0][0] );
351 } else {
352 0 die "Invalid accessor style declaration";
353 }
354 }
355 6 next;
356 }
357  
358 my $nodes = $parser->YYData->{PARSER}->handle_class_tag_plugins
359 ( $class, $any->{NAME},
360 named => $any->{NAMED_ARGUMENTS},
361 positional => $any->{POSITIONAL_ARGUMENTS},
362 any_named_arguments => $any->{NAMED_ARGUMENTS},
363 any_positional_arguments => $any->{POSITIONAL_ARGUMENTS},
364 2 );
365  
366 2 $class->add_methods( @$nodes );
367 }
368  
369 54 return $class;
370 }
371  
372 # support multiple occurrances of specific keys
373 # => transform to flattened array ref
374 458 ▶sub _merge_keys {
Subroutine _merge_keys: called CC=5 SCAR=16.1
375 458 my $key = shift;
376 458 my $argshash = shift;
377 458 my $paramlist = shift;
378 458 my @occurrances;
379 458 ▶ for (my $i = 0; $i < @$paramlist; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$paramlist) 1679 458 2137
380 1679 ▶ if (defined $paramlist->[$i] and $paramlist->[$i] eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $paramlist->[$i] and $paramlist->[$i] eq $key) 52 1627 1679
Condition66%2/3
defined $paramlist->[$i] and $paramlist->[$i] eq $key
!ll&&!rl&&r
0162752
MC/DC50%1/2
defined $paramlist->[$i] and $paramlist->[$i] eq $key
defined $paramlist->[$i] $paramlist->[$i] eq $key
Truth table66%2/3
A and B
A= defined $paramlist->[$i]B= $paramlist->[$i] eq $key
ABresult
0X0
100
111
381 52 push @occurrances, $paramlist->[$i+1];
382 }
383 }
384 458 ▶ @occurrances = map {ref($_) eq 'ARRAY' ? @$_ : $_} @occurrances;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 5 47 52
385 458 $argshash->{$key} = \@occurrances;
386 }
387  
388  
389 12 ▶sub create_member {
Subroutine create_member: called CC=1 SCAR=0.0
Pod undocumented
390 12 my( $parser, @args ) = @_;
391 12 my %args = @args;
392 12 _merge_keys( 'tag', \%args, \@args );
393  
394 return ExtUtils::XSpp::Node::Member->new
395 ( cpp_name => $args{name},
396 perl_name => $args{perl_name},
397 class => $args{class},
398 type => $args{type},
399 condition => $args{condition},
400 tags => $args{tag},
401 12 );
402 }
403  
404 44 ▶sub add_data_function {
Subroutine add_data_function: called CC=2 SCAR=7.0
Pod undocumented
405 44 my( $parser, @args ) = @_;
406 44 my %args = @args;
407 44 _merge_keys( 'catch', \%args, \@args );
408 44 _merge_keys( 'alias', \%args, \@args );
409 44 _merge_keys( 'tag', \%args, \@args );
410 44 ▶ $args{alias} = +{@{$args{alias}}} if exists $args{alias};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"alias"} 44 0 44
411  
412 return ExtUtils::XSpp::Node::Function->new
413 ( cpp_name => $args{name},
414 perl_name => $args{perl_name},
415 class => $args{class},
416 ret_type => $args{ret_type},
417 arguments => $args{arguments},
418 code => $args{code},
419 cleanup => $args{cleanup},
420 postcall => $args{postcall},
421 catch => $args{catch},
422 condition => $args{condition},
423 alias => $args{alias},
424 tags => $args{tag},
425 44 );
426 }
427  
428 44 ▶sub add_data_method {
Subroutine add_data_method: called CC=2 SCAR=6.9
Pod undocumented
429 44 my( $parser, @args ) = @_;
430 44 my %args = @args;
431 44 _merge_keys( 'catch', \%args, \@args );
432 44 _merge_keys( 'alias', \%args, \@args );
433 44 _merge_keys( 'tag', \%args, \@args );
434 44 ▶ $args{alias} = +{@{$args{alias}}} if exists $args{alias};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"alias"} 44 0 44
435  
436 my $m = ExtUtils::XSpp::Node::Method->new
437 ( cpp_name => $args{name},
438 ret_type => $args{ret_type},
439 arguments => $args{arguments},
440 const => $args{const},
441 code => $args{code},
442 cleanup => $args{cleanup},
443 postcall => $args{postcall},
444 perl_name => $args{perl_name},
445 catch => $args{catch},
446 condition => $args{condition},
447 alias => $args{alias},
448 tags => $args{tag},
449 44 );
450  
451 44 return $m;
452 }
453  
454 4 ▶sub add_data_ctor {
Subroutine add_data_ctor: called CC=1 SCAR=0.0
Pod undocumented
455 4 my( $parser, @args ) = @_;
456 4 my %args = @args;
457 4 _merge_keys( 'catch', \%args, \@args );
458 4 _merge_keys( 'tag', \%args, \@args );
459  
460 my $m = ExtUtils::XSpp::Node::Constructor->new
461 ( cpp_name => $args{name},
462 arguments => $args{arguments},
463 code => $args{code},
464 cleanup => $args{cleanup},
465 postcall => $args{postcall},
466 catch => $args{catch},
467 condition => $args{condition},
468 tags => $args{tag},
469 4 );
470  
471 4 return $m;
472 }
473  
474 3 ▶sub add_data_dtor {
Subroutine add_data_dtor: called CC=1 SCAR=0.0
Pod undocumented
475 3 my( $parser, @args ) = @_;
476 3 my %args = @args;
477 3 _merge_keys( 'catch', \%args, \@args );
478 3 _merge_keys( 'tag', \%args, \@args );
479  
480 my $m = ExtUtils::XSpp::Node::Destructor->new
481 ( cpp_name => $args{name},
482 code => $args{code},
483 cleanup => $args{cleanup},
484 postcall => $args{postcall},
485 catch => $args{catch},
486 condition => $args{condition},
487 tags => $args{tag},
488 3 );
489  
490 3 return $m;
491 }
492  
493 44 ▶sub process_function {
Subroutine process_function: called CC=1 SCAR=0.0
Pod undocumented
494 44 my( $parser, $function ) = @_;
495  
496 44 $function->resolve_typemaps;
497 44 $function->resolve_exceptions;
498 44 call_argument_tags( $parser, $function );
499  
500 44 my $nodes = $parser->YYData->{PARSER}->handle_function_tags_plugins( $function, $function->tags );
501  
502 44 return [ $function, @$nodes ];
503 }
504  
505 95 ▶sub call_argument_tags {
Subroutine call_argument_tags: called CC=2 SCAR=6.9
Pod undocumented
506 95 my( $parser, $function ) = @_;
507  
508 95 foreach my $arg ( @{$function->arguments} ) {
509 114 $parser->YYData->{PARSER}->handle_argument_tags_plugins( $arg, $arg->tags );
510 }
511 }
512  
513 21 1;
« blib/lib/ExtUtils/XSpp/Cmd.pm ↑ Summary blib/lib/ExtUtils/XSpp/Node/Class.pm »