Decode/Parser.pm

filter: Statementstmt 57.7% 1758 / 3046 Branchbran 49.3% 909 / 1844 Conditioncond 51.8% 500 / 965 MC/DCmcdc 36.7% 199 / 541 Subroutinesub 85.0% 91 / 107 Podpod 3.1% 3 / 94 totaltotal 52.4% 3460 / 6597 CC 1309 SCAR 89.8
CC
1309
Cov
54%
translate_stmt
41006.0
map_stmt
6509.7
_read_statement
4075.0
CRAP 7935.2
« Decode/Func.pm ↑ Summary Decode/Transformer.pm »
1 #
2 # parse PHP source files
3 #
4 package PHP::Decode::Parser;
5 6 ▶use base 'PHP::Decode::Tokenizer';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use PHP::Decode::Array qw(is_int_index);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 our @EXPORT_OK = qw(is_variable is_symbol is_null is_const is_numval is_strval is_array is_block global_var global_split inst_var inst_split method_name method_split ns_name ns_split);
14 6 our %EXPORT_TAGS = (all => \@EXPORT_OK);
15  
16 6 our $VERSION = '0.130';
17  
18 # avoid 'Deep recursion' warnings for depth > 100
19 #
20 6 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 my $stridx = 1;
23 6 my $numidx = 1;
24 6 my $constidx = 1;
25 6 my $funidx = 1;
26 6 my $callidx = 1;
27 6 my $elemidx = 1;
28 6 my $expridx = 1;
29 6 my $stmtidx = 1;
30 6 my $blkidx = 1;
31 6 my $pfxidx = 1;
32 6 my $objidx = 1; # obj->
33 6 my $scopeidx = 1; # class::
34 6 my $refidx = 1; # & $var
35 6 my $classidx = 1; # class name {}
36 6 my $instidx = 1; # class instance
37 6 my $traitidx = 1; # trait name {}
38 6 my $nsidx = 1; # namespace\
39 6 my $fhidx = 1;
40  
41 # Initialize new parser using PHP::Decode::Tokenizer
42 # {inscript} - set to indicate already inside of script
43 # {warn} - warning message handler
44 # {log} - log message handler
45 # {debug} - debug message handler
46 # {filename} - optional filename (if not stdin or textstr)
47 # {max_strlen} - max strlen for debug strings
48 #
49 820 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
50 820 my ($class, %args) = @_;
51 820 ▶ my $strmap = $args{strmap} or croak __PACKAGE__ . " expects strmap";
Branch: 1 branch
BranchTrueFalseTotal
my $strmap = $args{"strmap"} or croak("PHP::Decode::Parser expects strmap") 820 0 820
52  
53 820 my $self = $class->SUPER::new(%args);
54 820 ▶ $self->{max_strlen} = 0 unless exists $self->{max_strlen};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"max_strlen"} 750 70 820
55 820 $self->{tok} = []; # init token list
56  
57 # filename is required to decode __FILE__
58 820 ▶ $self->{filename} = '__FILE__' unless exists $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"filename"} 750 70 820
59  
60 820 ▶ $strmap->{'__LINE__'} = 1 unless exists $strmap->{'__LINE__'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $strmap->{"__LINE__"} 750 70 820
61 820 ▶ $strmap->{'#null'} = '' unless exists $strmap->{'#null'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $strmap->{"#null"} 750 70 820
62 820 return $self;
63 }
64  
65 # A sub parser is always inscript (the parent might have inscript=0)
66 #
67 70 ▶sub subparser {
Subroutine subparser: called CC=4 SCAR=14.6
Pod undocumented
68 70 my ($self, %args) = @_;
69 70 my $parser = PHP::Decode::Parser->new(strmap => $self->{strmap}, inscript => 1, filename => $self->{filename}, max_strlen => $self->{max_strlen}, warn => $self->{warn});
70 70 ▶ $parser->{log} = $self->{log} if exists $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"log"} 0 70 70
71 70 ▶ $parser->{debug} = $self->{debug} if exists $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"debug"} 0 70 70
72  
73 70 foreach my $k (keys %args) {
74 0 $parser->{$k} = $args{$k};
75 }
76 70 return $parser;
77 }
78  
79 0 ▶sub clear_strmap {
Subroutine clear_strmap: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my ($self) = @_;
81  
82 0 $stridx = 1;
83 0 $self->{strmap} = {};
84 0 $self->{strmap}{'__LINE__'} = 1;
85 0 return;
86 }
87  
88 6 my %ctrlmap = map { chr($_) => sprintf "\\x%02x", $_ } (0x00..0x1f, 0x7f);
89  
90 # convert controls from pattern to "\xNN"
91 #
92 0 ▶sub escape_ctrl {
Subroutine escape_ctrl: not called CC=5 SCAR=34.0
Pod undocumented
93 0 my ($s, $pat) = @_;
94 0 my @list = ();
95  
96 0 ▶ return "''" if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
97  
98 0 $_ = $s;
99 0 while (1) {
100 #if(/\G([${pat}])/sgc) {
101 # push(@list, sprintf "\"\\x%02x\"", ord($1));
102 0 ▶ if(/\G([${pat}]+)/sgc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G([$pat]+)/cgs) { } 0 0 0
elsif (/\G([^$pat]+)/cgs) { } 0 0 0
103 0 ▶ push(@list, '"' . join('', map { exists $ctrlmap{$_} ? $ctrlmap{$_} : $_ } split(//, $1)) . '"');
Branch: 1 branch
BranchTrueFalseTotal
exists $ctrlmap{$_} ? : 0 0 0
104 } elsif (/\G([^${pat}]+)/sgc) {
105 0 push(@list, "'" . $1 . "'");
106 } else {
107 0 last;
108 }
109 }
110 0 return join('.', @list);
111 }
112  
113 0 ▶sub shortstr {
Subroutine shortstr: not called CC=7 SCAR=40.3
Pod undocumented
114 0 my ($self, $s, $maxlen) = @_;
115  
116 0 ▶ if (!defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s) 0 0 0
117 0 return '(null)';
118 }
119  
120 # remove linefeeds
121 #
122 #$s =~ s/\r\n/ /g;
123  
124 # remove non-printable
125 #
126 0 $s =~ s/[\x01-\x1f\x7f]/\./g;
127  
128 0 ▶ if (($self->{max_strlen} > 0) && (!$maxlen || ($maxlen > $self->{max_strlen}))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}) 0 0 0
Condition0%0/6
$self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}
!ll&&!rl&&r
000
not $maxlen or $maxlen > $self->{"max_strlen"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}
$self->{"max_strlen"} > 0 not $maxlen $maxlen > $self->{"max_strlen"}
Truth table0%0/4
A and not(B) or C
A= $self->{"max_strlen"} > 0B= not $maxlenC= $maxlen > $self->{"max_strlen"}
ABCresult
0XX0
1000
11X1
1011
129 0 $maxlen = $self->{max_strlen};
130 }
131 0 ▶ if ($maxlen && (length($s) > $maxlen)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxlen and length $s > $maxlen) 0 0 0
Condition0%0/3
$maxlen and length $s > $maxlen
!ll&&!rl&&r
000
MC/DC0%0/2
$maxlen and length $s > $maxlen
$maxlen length $s > $maxlen
Truth table0%0/3
A and B
A= $maxlenB= length $s > $maxlen
ABresult
0X0
100
111
132 0 $s = substr($s, 0, $maxlen-2).'..';
133 }
134 0 return $s;
135 }
136  
137 # 'str' -> #str$i
138 #
139 2368 ▶sub setstr {
Subroutine setstr: called CC=4 SCAR=14.1
Pod undocumented
140 2368 my ($self, $v) = @_;
141 2368 my $k;
142  
143 2368 ▶ if (exists $self->{strmap}->{rev}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'rev'}{$v}) { } 320 2048 2368
144 320 $k = $self->{strmap}->{rev}{$v};
145 320 return $k;
146 } else {
147 2048 $k = "#str$stridx";
148 2048 $stridx++;
149 2048 $self->{strmap}->{$k} = $v;
150 2048 $self->{strmap}->{rev}{$v} = $k;
151 }
152 # TODO: log also for $opt{P}
153 2048 ▶ $self->{log}->('setstr', "%s = %s", $k, $self->shortstr($v, $self->{max_strlen} || 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 2048 2048
Condition0%0/2
$self->{'max_strlen'} || 60
l!l
00
MC/DC0%0/1
$self->{'max_strlen'} || 60
$self->{'max_strlen'}
Truth table0%0/2
A
A= $self->{'max_strlen'}
Aresult
11
00
154 2048 return $k;
155 }
156  
157 # for expensive operations like repeated strconcat don't
158 # store reverse entry to save some space
159 #
160 111 ▶sub setstr_norev {
Subroutine setstr_norev: called CC=4 SCAR=14.1
Pod undocumented
161 111 my ($self, $v) = @_;
162 111 my $k;
163  
164 111 ▶ if (exists $self->{strmap}->{rev}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'rev'}{$v}) { } 21 90 111
165 21 $k = $self->{strmap}->{rev}{$v};
166 21 return $k;
167 } else {
168 90 $k = "#str$stridx";
169 90 $stridx++;
170 90 $self->{strmap}->{$k} = $v;
171 }
172 # TODO: log also for $opt{P}
173 90 ▶ $self->{log}->('setstr', "%s = %s [norev]", $k, $self->shortstr($v, $self->{max_strlen} || 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 90 90
Condition0%0/2
$self->{'max_strlen'} || 60
l!l
00
MC/DC0%0/1
$self->{'max_strlen'} || 60
$self->{'max_strlen'}
Truth table0%0/2
A
A= $self->{'max_strlen'}
Aresult
11
00
174 90 return $k;
175 }
176  
177 # number -> #num$i
178 #
179 912 ▶sub setnum {
Subroutine setnum: called CC=3 SCAR=11.0
Pod undocumented
180 912 my ($self, $v) = @_;
181 912 my $k;
182  
183 912 ▶ if (exists $self->{strmap}->{num}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'num'}{$v}) { } 188 724 912
184 188 $k = $self->{strmap}->{num}{$v};
185 188 return $k;
186 } else {
187 724 $k = "#num$numidx";
188 724 $numidx++;
189 724 $self->{strmap}->{$k} = $v;
190 724 $self->{strmap}->{num}{$v} = $k;
191 }
192 724 ▶ $self->{log}->('setnum', "%s = %s", $k, $self->shortstr($v, 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 724 724
193 724 return $k;
194 }
195  
196 # 'const' -> #const$i
197 #
198 344 ▶sub setconst {
Subroutine setconst: called CC=2 SCAR=7.0
Pod undocumented
199 344 my ($self, $v) = @_;
200 344 my $k = "#const$constidx";
201 344 $constidx++;
202  
203 344 $self->{strmap}->{$k} = $v;
204 344 ▶ $self->{log}->('setconst', "%s = %s", $k, $v) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 344 344
205 344 return $k;
206 }
207  
208 282 ▶sub newarr {
Subroutine newarr: called CC=2 SCAR=7.0
Pod undocumented
209 282 my ($self) = @_;
210 282 my $arr = PHP::Decode::Array->new(strmap => $self->{strmap});
211 282 ▶ $self->{log}->('newarr', "%s", $arr->{name}) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 282 282
212 282 return $arr;
213 }
214  
215 # function -> #fun$i
216 #
217 309 ▶sub setfun {
Subroutine setfun: called CC=2 SCAR=7.0
Pod undocumented
218 309 my ($self, $cmd, $arglist, $block, $p) = @_;
219 309 my $k = "#fun$funidx";
220 309 $funidx++;
221  
222 309 $self->{strmap}->{$k} = [$cmd, $arglist, $block, $p];
223 309 ▶ $self->{log}->('setfun', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 309 309
224 309 return $k;
225 }
226  
227 815 ▶sub setcall {
Subroutine setcall: called CC=2 SCAR=7.0
Pod undocumented
228 815 my ($self, $cmd, $arglist) = @_;
229 815 my $k = "#call$callidx";
230 815 $callidx++;
231  
232 815 $self->{strmap}->{$k} = [$cmd, $arglist];
233 815 ▶ $self->{log}->('setcall', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 815 815
234 815 return $k;
235 }
236  
237 540 ▶sub setelem {
Subroutine setelem: called CC=2 SCAR=7.0
Pod undocumented
238 540 my ($self, $var, $idx) = @_;
239 540 my $k = "#elem$elemidx";
240 540 $elemidx++;
241  
242 540 $self->{strmap}->{$k} = [$var, $idx];
243 540 ▶ $self->{log}->('setelem', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 540 540
244 540 return $k;
245 }
246  
247 2039 ▶sub setexpr {
Subroutine setexpr: called CC=2 SCAR=7.0
Pod undocumented
248 2039 my ($self, $op, $v1, $v2) = @_;
249 2039 my $k = "#expr$expridx";
250 2039 $expridx++;
251  
252 2039 $self->{strmap}->{$k} = [$op, $v1, $v2];
253 2039 ▶ $self->{log}->('setexpr', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 2039 2039
254 2039 return $k;
255 }
256  
257 2938 ▶sub setblk {
Subroutine setblk: called CC=2 SCAR=7.0
Pod undocumented
258 2938 my ($self, $type, $a) = @_;
259 2938 my $k = "#blk$blkidx";
260 2938 $blkidx++;
261  
262 2938 $self->{strmap}->{$k} = [$type, $a];
263 2938 ▶ $self->{log}->('setblk', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 2938 2938
264 2938 return $k;
265 }
266  
267 869 ▶sub setstmt {
Subroutine setstmt: called CC=2 SCAR=7.0
Pod undocumented
268 869 my ($self, $s) = @_;
269 869 my $k = "#stmt$stmtidx";
270 869 $stmtidx++;
271  
272 869 $self->{strmap}->{$k} = $s;
273 869 ▶ $self->{log}->('setstmt', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 869 869
274 869 return $k;
275 }
276  
277 55 ▶sub setpfx {
Subroutine setpfx: called CC=2 SCAR=7.0
Pod undocumented
278 55 my ($self, $s) = @_;
279 55 my $k = "#pfx$pfxidx";
280 55 $pfxidx++;
281  
282 55 $self->{strmap}->{$k} = $s;
283 55 ▶ $self->{log}->('setpfx', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 55 55
284 55 return $k;
285 }
286  
287 52 ▶sub setobj {
Subroutine setobj: called CC=2 SCAR=7.0
Pod undocumented
288 52 my ($self, $s, $property) = @_;
289 52 my $k = "#obj$objidx";
290 52 $objidx++;
291  
292 52 $self->{strmap}->{$k} = [$s, $property];
293 52 ▶ $self->{log}->('setobj', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 52 52
294 52 return $k;
295 }
296  
297 41 ▶sub setscope {
Subroutine setscope: called CC=2 SCAR=7.0
Pod undocumented
298 41 my ($self, $s, $elem) = @_;
299 41 my $k = "#scope$scopeidx";
300 41 $scopeidx++;
301  
302 41 $self->{strmap}->{$k} = [$s, $elem];
303 41 ▶ $self->{log}->('setscope', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 41 41
304 41 return $k;
305 }
306  
307 8 ▶sub setref {
Subroutine setref: called CC=2 SCAR=7.0
Pod undocumented
308 8 my ($self, $s) = @_;
309 8 my $k = "#ref$refidx";
310 8 $refidx++;
311  
312 8 $self->{strmap}->{$k} = [$s];
313 8 ▶ $self->{log}->('setref', "%s = %s", $k, $s) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 8 8
314 8 return $k;
315 }
316  
317 69 ▶sub setclass {
Subroutine setclass: called CC=2 SCAR=7.0
Pod undocumented
318 69 my ($self, $name, $block, $p) = @_;
319 69 my $k = "#class$classidx";
320 69 $classidx++;
321  
322 69 $self->{strmap}->{$k} = [$name, $block, $p];
323 69 ▶ $self->{log}->('setclass', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 69 69
324 69 return $k;
325 }
326  
327 1 ▶sub settrait {
Subroutine settrait: called CC=2 SCAR=7.0
Pod undocumented
328 1 my ($self, $name, $block) = @_;
329 1 my $k = "#trait$traitidx";
330 1 $traitidx++;
331  
332 1 $self->{strmap}->{$k} = [$name, $block];
333 1 ▶ $self->{log}->('settrait', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 1 1
334 1 return $k;
335 }
336  
337 34 ▶sub setinst {
Subroutine setinst: called CC=2 SCAR=7.0
Pod undocumented
338 34 my ($self, $class, $initcall, $instctx) = @_;
339 34 my $k = "#inst$instidx";
340 34 $instidx++;
341  
342 34 $self->{strmap}->{$k} = [$class, $initcall, $instctx];
343 34 ▶ $self->{log}->('setinst', "%s = %s", $k, $class) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 34 34
344 34 return $k;
345 }
346  
347 12 ▶sub setns {
Subroutine setns: called CC=2 SCAR=7.0
Pod undocumented
348 12 my ($self, $name, $elem) = @_;
349 12 my $k = "#ns$nsidx";
350 12 $nsidx++;
351  
352 12 $self->{strmap}->{$k} = [$name, $elem];
353 12 ▶ $self->{log}->('setns', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 12 12
354 12 return $k;
355 }
356  
357 2 ▶sub newfh {
Subroutine newfh: called CC=3 SCAR=11.9
Pod undocumented
358 2 my ($self, $filename, $mode) = @_;
359 2 my %file;
360 my $a;
361 2 my $fh = "#fh$fhidx";
362 2 $fhidx++;
363  
364 2 $self->{strmap}->{$fh} = \%file;
365 2 $self->{strmap}->{idx}{$fh} = 0;
366  
367 2 $file{name} = $filename;
368 2 $file{mode} = $mode;
369 2 $file{pos} = 0;
370 2 ▶ if ($filename eq '__FILE__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq '__FILE__') { } 0 2 2
371 0 $file{buf} = $self->{strmap}->{$filename}; # todo: cleanup
372 } else {
373 2 $file{buf} = '';
374 2 return; # TODO: support write & non-existing files
375 }
376 0 ▶ $self->{log}->('newfh', "$fh ($filename, $mode)") if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
377 0 return ($fh, \%file);
378 }
379  
380 71 ▶sub stmt_str {
Subroutine stmt_str: called CC=58 SCAR=78.8
Pod undocumented
381 71 my ($self, $s) = @_;
382  
383 71 ▶ unless ($s =~ /^#\w+\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ /^#\w+\d+$/) 0 71 71
384 0 return $s;
385 }
386  
387 71 ▶ if ($s =~ /^#null$/) {
Branch: 20 branches
BranchTrueFalseTotal
if ($s =~ /^#null$/) { } 0 71 71
elsif ($s =~ /^#num\d+$/) { } 0 71 71
elsif ($s =~ /^#const\d+$/) { } 0 71 71
elsif ($s =~ /^#str\d+$/) { } 0 71 71
elsif ($s =~ /^#arr\d+$/) { } 0 71 71
elsif ($s =~ /^#fun\d+$/) { } 0 71 71
elsif ($s =~ /^#call\d+$/) { } 69 2 71
elsif ($s =~ /^#elem\d+$/) { } 2 0 2
elsif ($s =~ /^#expr\d+$/) { } 0 0 0
elsif ($s =~ /^#pfx\d+$/) { } 0 0 0
elsif ($s =~ /^#obj\d+$/) { } 0 0 0
elsif ($s =~ /^#scope\d+$/) { } 0 0 0
elsif ($s =~ /^#ns\d+$/) { } 0 0 0
elsif ($s =~ /^#inst\d+$/) { } 0 0 0
elsif ($s =~ /^#ref\d+$/) { } 0 0 0
elsif ($s =~ /^#class\d+$/) { } 0 0 0
elsif ($s =~ /^#trait\d+$/) { } 0 0 0
elsif ($s =~ /^#fh\d+$/) { } 0 0 0
elsif ($s =~ /^#blk\d+$/) { } 0 0 0
elsif ($s =~ /^#stmt\d+$/) { } 0 0 0
388 0 return 'null'; # '' or 0 in str/num context
389 } elsif ($s =~ /^#num\d+$/) {
390 0 return $self->{strmap}{$s};
391 } elsif ($s =~ /^#const\d+$/) {
392 0 return $self->{strmap}{$s};
393 } elsif ($s =~ /^#str\d+$/) {
394 0 my $v = $self->{strmap}{$s};
395 0 return $self->shortstr($v, 60);
396 } elsif ($s =~ /^#arr\d+$/) {
397 0 my $arr = $self->{strmap}{$s};
398 0 my $keys = $arr->get_keys();
399 0 my $size = scalar @$keys;
400  
401 0 return $arr->{name} . "[size $size]";
402 } elsif ($s =~ /^#fun\d+$/) {
403 0 my ($f, $a, $b, $p) = @{$self->{strmap}{$s}};
404 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
405  
406 0 ▶ return (defined $f ? $f : '') . "(" . join(', ', @$a) . ") { " . join(' ', @$stmts) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $f ? : 0 0 0
407 } elsif ($s =~ /^#call\d+$/) {
408 69 my ($f, $a) = @{$self->{strmap}->{$s}};
409  
410 69 return $f . "(" . join(', ', @$a) . ")";
411 } elsif ($s =~ /^#elem\d+$/) {
412 2 my ($v, $i) = @{$self->{strmap}{$s}};
413  
414 2 ▶ return $v . "[" . (defined $i ? $i : '') . "]";
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 2 0 2
415 } elsif ($s =~ /^#expr\d+$/) {
416 # if v1 missing: prefix op
417 # if v2 missing: postfix op
418 0 my ($op, $v1, $v2) = @{$self->{strmap}{$s}};
419  
420 0 ▶ return (defined $v1 ? $v1 . " " : '') . $op . (defined $v2 ? " " . $v2 : '');
Branch: 2 branches
BranchTrueFalseTotal
defined $v1 ? : 0 0 0
defined $v2 ? : 0 0 0
421 } elsif ($s =~ /^#pfx\d+$/) {
422 0 my $pfx = $self->{strmap}{$s};
423 0 return join(' ', sort keys %$pfx);
424 } elsif ($s =~ /^#obj\d+$/) {
425 0 my ($o, $m) = @{$self->{strmap}{$s}};
426 0 return $o . "->" . $m;
427 } elsif ($s =~ /^#scope\d+$/) {
428 0 my ($c, $e) = @{$self->{strmap}{$s}};
429 0 return $c . "::" . $e;
430 } elsif ($s =~ /^#ns\d+$/) {
431 0 my ($n, $e) = @{$self->{strmap}{$s}};
432 0 ▶ return (defined $n ? $n : '') . '\\' . $e;
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
433 } elsif ($s =~ /^#inst\d+$/) {
434 0 my ($c, $f, $i) = @{$self->{strmap}{$s}};
435 0 return $c;
436 } elsif ($s =~ /^#ref\d+$/) {
437 0 my ($v) = @{$self->{strmap}{$s}};
438 0 return "&" . $v;
439 } elsif ($s =~ /^#class\d+$/) {
440 0 my ($c, $b, $p) = @{$self->{strmap}{$s}};
441 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
442  
443 0 ▶ return (defined $c ? $c : '') . (exists $p->{parent} ? " extends $p->{parent}" : '') . " { " . join(' ', @$stmts) . " }";
Branch: 2 branches
BranchTrueFalseTotal
defined $c ? : 0 0 0
exists $p->{'parent'} ? : 0 0 0
444 } elsif ($s =~ /^#trait\d+$/) {
445 0 my ($t, $b) = @{$self->{strmap}{$s}};
446 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
447  
448 0 ▶ return (defined $t ? $t : '') . " { " . join(' ', @$stmts) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 0 0 0
449 } elsif ($s =~ /^#fh\d+$/) {
450 0 my $f = $self->{strmap}{$s}{name};
451 0 my $m = $self->{strmap}{$s}{mode};
452 0 my $p = $self->{strmap}{$s}{pos};
453  
454 0 return "(" . $f . ", " . $m . ")";
455 } elsif ($s =~ /^#blk\d+$/) {
456 0 my ($type, $a) = @{$self->{strmap}{$s}};
457 0 return $type . " { " . join(' ', @$a) . " }";
458 } elsif ($s =~ /^#stmt\d+$/) {
459 0 my $cmd = $self->{strmap}{$s}[0];
460  
461 0 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 0 0 0
elsif ($cmd eq 'print') { } 0 0 0
elsif ($cmd eq 'namespace') { } 0 0 0
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 0 0
elsif ($cmd eq 'use') { } 0 0 0
elsif ($cmd eq 'global') { } 0 0 0
elsif ($cmd eq 'static') { } 0 0 0
elsif ($cmd eq 'const') { } 0 0 0
elsif ($cmd eq 'unset') { } 0 0 0
elsif ($cmd eq 'return') { } 0 0 0
elsif ($cmd eq 'goto') { } 0 0 0
elsif ($cmd eq 'label') { } 0 0 0
elsif ($cmd eq 'throw') { } 0 0 0
elsif ($cmd eq 'if') { } 0 0 0
elsif ($cmd eq 'while') { } 0 0 0
elsif ($cmd eq 'do') { } 0 0 0
elsif ($cmd eq 'for') { } 0 0 0
elsif ($cmd eq 'foreach') { } 0 0 0
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'case') { } 0 0 0
elsif ($cmd eq 'try') { } 0 0 0
462 0 my $a = $self->{strmap}{$s}[1];
463 0 return $cmd . " " . join(', ', @$a);
464 } elsif ($cmd eq 'print') {
465 0 my $arg = $self->{strmap}{$s}[1];
466 0 return $cmd . " " . $arg;
467 } elsif ($cmd eq 'namespace') {
468 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
469 0 ▶ return $cmd . " " . $arg . (defined $block ? " { $block }" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $block ? : 0 0 0
470 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
471 0 my $arg = $self->{strmap}{$s}[1];
472 0 return $cmd . " " . $arg;
473 } elsif ($cmd eq 'use') {
474 0 my $a = $self->{strmap}{$s}[1];
475 0 return $cmd . " " . join(', ', @$a);
476 } elsif ($cmd eq 'global') {
477 0 my $a = $self->{strmap}{$s}[1];
478 0 return $cmd . " " . join(', ', @$a);
479 } elsif ($cmd eq 'static') {
480 0 my ($a, $p) = @{$self->{strmap}{$s}}[1..2];
481 0 return $cmd . join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd) . ' ' . join(', ', @$a);
482 } elsif ($cmd eq 'const') {
483 0 my ($a, $p) = @{$self->{strmap}{$s}}[1..2];
484 0 return $cmd . join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd) . ' ' . join(', ', @$a);
485 } elsif ($cmd eq 'unset') {
486 0 my $a = $self->{strmap}{$s}[1];
487 0 return $cmd . " (" . join(', ', @$a) . ")";
488 } elsif ($cmd eq 'return') {
489 0 my $a = $self->{strmap}{$s}[1];
490 0 return $cmd . " " . $a;
491 } elsif ($cmd eq 'goto') {
492 0 my $a = $self->{strmap}{$s}[1];
493 0 return $cmd . " " . $a;
494 } elsif ($cmd eq 'label') {
495 0 my $a = $self->{strmap}{$s}[1];
496 0 return $cmd . " " . $a . ":";
497 } elsif ($cmd eq 'throw') {
498 0 my $arg = $self->{strmap}{$s}[1];
499 0 return $cmd . " " . $arg;
500 } elsif ($cmd eq 'if') {
501 0 my ($cond, $then, $else) = @{$self->{strmap}{$s}}[1..3];
502 0 ▶ return $cmd . " ($cond) then $then" . (defined $else ? " else $else" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $else ? : 0 0 0
503 } elsif ($cmd eq 'while') {
504 0 my ($cond, $block) = @{$self->{strmap}{$s}}[1..2];
505 0 return $cmd . " ($cond) { $block }";
506 } elsif ($cmd eq 'do') {
507 0 my ($cond, $block) = @{$self->{strmap}{$s}}[1..2];
508 0 return $cmd . " { $block } while ($cond)";
509 } elsif ($cmd eq 'for') {
510 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}{$s}}[1..4];
511 0 return $cmd . " ($pre; $cond; $post) { $block }";
512 } elsif ($cmd eq 'foreach') {
513 0 my ($expr, $key, $value, $block) = @{$self->{strmap}{$s}}[1..4];
514 0 ▶ return $cmd . " ($expr " . (defined $key ? "$key => " : '') . "$value) { $block }";
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 0 0 0
515 } elsif ($cmd eq 'switch') {
516 0 my ($expr, $cases) = @{$self->{strmap}{$s}}[1..2];
517 0 ▶ return $cmd . " ($expr) { " . join(' ', map { sprintf "%s %s", defined $_->[0] ? "case $_->[0]:" : "default:", $_->[1]; } @$cases) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[0] ? : 0 0 0
518 } elsif ($cmd eq 'case') {
519 0 my $expr = $self->{strmap}{$s}[1];
520 0 ▶ return (defined $expr ? "case $expr:" : "default:");
Branch: 1 branch
BranchTrueFalseTotal
defined $expr ? : 0 0 0
521 } elsif ($cmd eq 'try') {
522 0 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
523 0 ▶ return $cmd . " { $try }" . join(' ', map { sprintf " catch (%s) { %s }", $_->[0] // '-', $_->[1]; } @$catches) . (defined $finally ? " finally { $finally }" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $finally ? : 0 0 0
Condition0%0/2
$_->[0] // "-"
l!l
00
MC/DC0%0/1
$_->[0] // "-"
$_->[0]
Truth table0%0/2
A
A= $_->[0]
Aresult
11
00
524 } else {
525 0 return $cmd;
526 }
527 }
528 0 return $s;
529 }
530  
531 0 ▶sub val {
Subroutine val: not called CC=1 SCAR=6.9
Pod undocumented
532 0 my ($self, $s) = @_;
533 #exists $self->{strmap}{$s} || die "assert: bad statement $s passed to parser->val()";
534 0 return $self->{strmap}{$s}; # for lookup after is_strval(), is_array(), ..
535 }
536  
537 1269 ▶sub get_strval {
Subroutine get_strval: called CC=2 SCAR=6.9
Pod undocumented
538 1269 my ($self, $s) = @_;
539 #defined($s) || die "assert: undefined statement passed to parser->get_strval()";
540  
541 1269 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 1248 21 1269
542 1248 return $self->{strmap}{$s};
543 }
544 21 return;
545 }
546  
547 199 ▶sub get_strval_or_str {
Subroutine get_strval_or_str: called CC=2 SCAR=6.9
Pod undocumented
548 199 my ($self, $s) = @_;
549  
550 199 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 64 135 199
551 64 $s = $self->{strmap}{$s};
552 }
553 199 return $s;
554 }
555  
556 0 ▶sub get_numval {
Subroutine get_numval: not called CC=2 SCAR=17.9
Pod undocumented
557 0 my ($self, $s) = @_;
558  
559 0 ▶ if ($s =~ /^(\#num\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#num\d+|\#null)$/) 0 0 0
560 0 $s = $self->{strmap}{$s};
561 }
562 0 return $s;
563 }
564  
565 1083 ▶sub is_null {
Subroutine is_null: called CC=2 SCAR=6.9
Pod undocumented
566 1083 my ($s) = @_;
567  
568 1083 ▶ if ($s =~ /^(\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#null)$/) 57 1026 1083
569 57 return 1;
570 }
571 1026 return 0;
572 }
573  
574 7761 ▶sub is_const {
Subroutine is_const: called CC=2 SCAR=6.9
Pod undocumented
575 7761 my ($s) = @_;
576  
577 7761 ▶ if ($s =~ /^(\#const\d++)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#const\d++)$/) 259 7502 7761
578 259 return 1;
579 }
580 7502 return 0;
581 }
582  
583 190 ▶sub is_numval {
Subroutine is_numval: called CC=2 SCAR=6.9
Pod undocumented
584 190 my ($s) = @_;
585  
586 190 ▶ if ($s =~ /^(\#num\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#num\d+)$/) 135 55 190
587 135 return 1;
588 }
589 55 return 0;
590 }
591  
592 16540 ▶sub is_strval {
Subroutine is_strval: called CC=2 SCAR=6.9
Pod undocumented
593 16540 my ($s) = @_;
594  
595 16540 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 5893 10647 16540
596 5893 return 1;
597 }
598 10647 return 0;
599 }
600  
601 2511 ▶sub is_array {
Subroutine is_array: called CC=2 SCAR=6.9
Pod undocumented
602 2511 my ($s) = @_;
603  
604 2511 ▶ if ($s =~ /^#arr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#arr\d+$/) 971 1540 2511
605 971 return 1;
606 }
607 1540 return 0;
608 }
609  
610 13095 ▶sub is_block {
Subroutine is_block: called CC=2 SCAR=6.9
Pod undocumented
611 13095 my ($s) = @_;
612  
613 13095 ▶ if ($s =~ /^#blk\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#blk\d+$/) 4331 8764 13095
614 4331 return 1;
615 }
616 8764 return 0;
617 }
618  
619 4 ▶sub bighex {
Subroutine bighex: called CC=5 SCAR=17.4
Pod undocumented
620 4 my ($hex) = @_;
621  
622 # hex() warns for 64-bit numbers like 0x10000000
623 # (Hexadecimal number > 0xffffffff non-portable)
624 # php converts such numbers to float.
625 #
626 # The 'use bigint qw/hex/' workaround would transparently
627 # use Math::BigInt internally. So convert 64-bit floats
628 # manually to float.
629 #
630 # also: perl warns for '0X'-prefix - php not
631 #
632 4 ▶ if (length($hex) <= 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $hex <= 10) 3 1 4
633 3 ▶ if ($hex =~ /^0X(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hex =~ /^0X(.*)$/) { } 0 3 3
634 0 return hex($1);
635 } else {
636 3 return hex($hex);
637 }
638 }
639 1 my ($high, $low) = $hex =~ /^0[xX]([0-9a-fA-F]{1,8})([0-9a-fA-F]{8})$/;
640 1 ▶ unless (defined $high) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $high) 0 1 1
641 0 warn "$hex is not a 64-bit hex number";
642 0 return hex($hex);
643 }
644 # with 32bit integers perl truncates (1 << 32) to 0x1
645 #
646 # use bignum instead of bigint here - bigint overrides the
647 # operators to result in a bigint when one of its operands
648 # is a bigint (so division would never result in a float).
649 # https://perldoc.perl.org/bigint
650 #
651 1 ▶ if ($Config{ivsize} == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PHP::Decode::Parser::Config{'ivsize'} == 4) { } 0 1 1
652 6 ▶ use bignum;
Subroutine BEGIN: called CC=1 SCAR=0.0
653 0 return hex("0x$low") + (hex("0x$high") << 32);
654 } else {
655 1 return hex("0x$low") + (hex("0x$high") << 32);
656 }
657 }
658  
659 # override methods inherited from PhpTokenizer
660 {
661 3281 ▶ sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
662 3281 my ($tab, $sym) = @_;
663 3281 push(@{$tab->{tok}}, $sym);
664 3281 return;
665 }
666 2325 ▶ sub add_open {
Subroutine add_open: called CC=1 SCAR=0.0
Pod undocumented
667 2325 my ($tab, $sym) = @_;
668 2325 push(@{$tab->{tok}}, $sym);
669 2325 return;
670 }
671 2317 ▶ sub add_close {
Subroutine add_close: called CC=8 SCAR=20.9
Pod undocumented
672 2317 my ($tab, $sym) = @_;
673 2317 my $pos = scalar @{$tab->{tok}};
674  
675 # join string literals with '.' operator if possible
676 # (this should also be done by php_decode)
677 #
678 2317 ▶ if (defined $tab->{strmap}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'} and $sym eq ')' and $pos > 2 and $tab->{'tok'}[$pos - 1] =~ /^#num\d+$/ and $tab->{'tok'}[$pos - 2] eq '(' and $tab->{'tok'}[$pos - 3] =~ /^chr$/i) { } 6 2311 2317
Condition93%14/15
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "(" and $tab->{"tok"}[$pos - 3] =~ /^chr$/i
!ll&&!rl&&r
2229826
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "("
!ll&&!rl&&r
21705988
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/
!ll&&!rl&&r
10131157147
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2
!ll&&!rl&&r
983301304
defined $tab->{"strmap"} and $sym eq ")"
!ll&&!rl&&r
09831334
MC/DC83%5/6
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "(" and $tab->{"tok"}[$pos - 3] =~ /^chr$/i
defined $tab->{"strmap"} $sym eq ")" $pos > 2 $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ $tab->{"tok"}[$pos - 2] eq "(" $tab->{"tok"}[$pos - 3] =~ /^chr$/i
Truth table85%6/7
A and B and C and D and E and F
A= defined $tab->{"strmap"}B= $sym eq ")"C= $pos > 2D= $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/E= $tab->{"tok"}[$pos - 2] eq "("F= $tab->{"tok"}[$pos - 3] =~ /^chr$/i
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
679 && ($sym eq ')')
680 && ($pos > 2)
681 && ($tab->{tok}->[$pos-1] =~ /^#num\d+$/)
682 && ($tab->{tok}->[$pos-2] eq '(')
683 && ($tab->{tok}->[$pos-3] =~ /^chr$/i)) {
684 6 my $val = $tab->{strmap}->{$tab->{tok}->[$pos-1]};
685 6 ▶ if ($val != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val != 0) { } 6 0 6
686 6 my $ch = chr(int($val) & 0xff);
687 6 pop(@{$tab->{tok}});
688 6 pop(@{$tab->{tok}});
689 6 pop(@{$tab->{tok}});
690 #$tab->{log}->('tokenize', "CHR chr($val) [$ch]") if $tab->{log};
691 6 $tab->add_str($ch);
692 } else {
693 0 push(@{$tab->{tok}}, $sym);
694 }
695 } else {
696 2311 push(@{$tab->{tok}}, $sym);
697 }
698 2317 return;
699 }
700 3596 ▶ sub add_white {
Subroutine add_white: called CC=3 SCAR=11.0
Pod undocumented
701 3596 my ($tab, $sym) = @_;
702 3596 ▶ if ($sym eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq "\n") 10 3586 3596
703 10 $tab->{strmap}->{'__LINE__'} += 1;
704 10 ▶ $tab->{debug}->('tokenize', "set linenum: %d", $tab->{strmap}->{'__LINE__'}) if $tab->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $tab->{"debug"} 0 10 10
705 }
706 #push(@{$tab->{tok}}, ' ');
707 3596 return;
708 }
709 9 ▶ sub add_comment {
Subroutine add_comment: called CC=1 SCAR=0.0
Pod undocumented
710 9 my ($tab, $sym) = @_;
711 #push(@{$tab->{tok}}, "/*$sym*/");
712 9 return;
713 }
714 2265 ▶ sub add_sym {
Subroutine add_sym: called CC=2 SCAR=6.9
Pod undocumented
715 2265 my ($tab, $sym) = @_;
716 2265 ▶ if ($sym eq '__LINE__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq '__LINE__') { } 12 2253 2265
717 # TODO: track line-number for each symbol, so that
718 # it is also valid in eval()-code?
719 #
720 12 $tab->{warn}->('tokenize', "substitute __LINE__ with %d", $tab->{strmap}->{'__LINE__'});
721 12 my $k = $tab->setnum($tab->{strmap}->{'__LINE__'});
722 12 push(@{$tab->{tok}}, $k);
723 } else {
724 2253 push(@{$tab->{tok}}, $sym);
725 }
726 2265 return;
727 }
728 1836 ▶ sub add_var {
Subroutine add_var: called CC=1 SCAR=0.0
Pod undocumented
729 1836 my ($tab, $sym) = @_;
730 1836 push(@{$tab->{tok}}, '$'.$sym);
731 1836 return;
732 }
733 1054 ▶ sub add_str {
Subroutine add_str: called CC=5 SCAR=16.6
Pod undocumented
734 1054 my ($tab, $sym) = @_;
735  
736 1054 ▶ if (defined $tab->{strmap}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'}) { } 1054 0 1054
737 1054 my $pos = scalar @{$tab->{tok}};
738  
739 # join string literals with '.' operator if possible
740 # (this should also be done by php_decode)
741 #
742 1054 ▶ if (($pos > 1) && ($tab->{tok}->[$pos-1] eq '.') && ($tab->{tok}->[$pos-2] =~ /^#str\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/) 11 1043 1054
Condition100%6/6
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
!ll&&!rl&&r
10152811
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "."
!ll&&!rl&&r
4696939
MC/DC100%3/3
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
$pos > 1 $tab->{"tok"}[$pos - 1] eq "." $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
Truth table100%4/4
A and B and C
A= $pos > 1B= $tab->{"tok"}[$pos - 1] eq "."C= $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
ABCresult
0XX0
10X0
1100
1111
743 11 my $oldstr = $tab->{strmap}->{$tab->{tok}->[$pos-2]};
744 11 pop(@{$tab->{tok}});
745 11 pop(@{$tab->{tok}});
746 #$tab->{log}->('tokenize', "JOIN $oldstr . $sym") if $tab->{log};
747 11 $sym = $oldstr . $sym;
748 }
749  
750 # remember last linenum for each new #str symbol
751 #
752 1054 $tab->{strmap}->{'__LINEMAP__'}{"#str$stridx"} = $tab->{strmap}->{'__LINE__'};
753  
754 # substitute: 'str' -> #str$i
755 #
756 1054 my $k = $tab->setstr($sym);
757 1054 push(@{$tab->{tok}}, $k);
758 } else {
759 0 push(@{$tab->{tok}}, '\'');
760 0 push(@{$tab->{tok}}, $sym);
761 0 push(@{$tab->{tok}}, '\'');
762 }
763 1054 return;
764 }
765 572 ▶ sub add_num {
Subroutine add_num: called CC=5 SCAR=16.7
Pod undocumented
766 572 my ($tab, $sym) = @_;
767  
768 572 ▶ if (defined $tab->{strmap}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'}) { } 572 0 572
769 # substitute: number -> #num$i
770 #
771 572 my $num;
772 572 ▶ if ($sym =~ /^0[xX][0-9a-fA-F]+$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($sym =~ /^0[xX][0-9a-fA-F]+$/) { } 4 568 572
elsif ($sym =~ /^0[0-7]+$/) { } 0 568 568
elsif ($sym =~ /^[0-9]*\.[0-9]*/) { } 7 561 568
773 #$num = hex($sym);
774 4 $num = bighex($sym);
775 } elsif ($sym =~ /^0[0-7]+$/) {
776 0 $num = oct($sym);
777 } elsif ($sym =~ /^[0-9]*\.[0-9]*/) {
778 7 $num = $sym * 1;
779 } else {
780 561 $num = $sym;
781 }
782 572 my $k = $tab->setnum($num);
783 572 push(@{$tab->{tok}}, $k);
784 } else {
785 0 push(@{$tab->{tok}}, $sym);
786 }
787 572 return;
788 }
789 13 ▶ sub add_script_start {
Subroutine add_script_start: called CC=1 SCAR=0.0
Pod undocumented
790 13 my ($tab, $sym) = @_;
791 #push(@{$tab->{tok}}, $sym);
792 13 return;
793 }
794 829 ▶ sub add_script_end {
Subroutine add_script_end: called CC=2 SCAR=6.9
Pod undocumented
795 829 my ($tab, $sym) = @_;
796 #push(@{$tab->{tok}}, $sym);
797 829 ▶ if ($sym =~ /\n$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym =~ /\n$/) 4 825 829
798 4 $tab->add_white("\n");
799 }
800 829 return;
801 }
802 8 ▶ sub add_noscript {
Subroutine add_noscript: called CC=3 SCAR=11.0
Pod undocumented
803 8 my ($tab, $sym) = @_;
804  
805 8 ▶ if ((scalar @{$tab->{tok}} > 0) && ($tab->{tok}->[-1] ne ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";") 1 7 8
Condition100%3/3
scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";"
!ll&&!rl&&r
611
MC/DC100%2/2
scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";"
scalar @{$tab->{"tok"};} > 0 $tab->{"tok"}[-1] ne ";"
Truth table100%3/3
A and B
A= scalar @{$tab->{"tok"};} > 0B= $tab->{"tok"}[-1] ne ";"
ABresult
0X0
100
111
806 # append ';' if missing at end of php-block
807 1 $tab->add(';');
808 }
809 8 $tab->add_sym('echo');
810 8 $tab->add_str($sym);
811 8 $tab->add(';');
812 8 $tab->add_script_end('');
813 8 return;
814 }
815 0 ▶ sub add_bad_open {
Subroutine add_bad_open: not called CC=1 SCAR=6.9
Pod undocumented
816 0 my ($tab, $sym) = @_;
817  
818 0 $tab->{warn}->('tokenize', "in script got bad open %s", $sym);
819 0 $tab->add($sym);
820 0 return;
821 }
822 0 ▶ sub tok_dump {
Subroutine tok_dump: not called CC=1 SCAR=6.9
Pod undocumented
823 0 my ($tab) = @_;
824 0 return join('', @{$tab->{tok}});
825 }
826 0 ▶ sub tok_count {
Subroutine tok_count: not called CC=1 SCAR=6.9
Pod undocumented
827 0 my ($tab) = @_;
828 0 return scalar @{$tab->{tok}};
829 }
830 }
831  
832 # http://php.net/manual/en/reserved.keywords.php
833 #
834 6 my %php_keywords = map { $_ => 1 } ('__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor');
835  
836 6 my %php_modifiers = map { $_ => 1 } ('const', 'final', 'private', 'protected', 'public', 'readonly', 'static', 'var');
837  
838 # All magic constants are resolved at compile time
839 # https://www.php.net/manual/en/language.constants.magic.php
840 #
841 6 my %magic_constants = map { $_ => 1 } ('__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__', 'ClassName::class');
842  
843 # builtin types: https://www.php.net/manual/en/language.types.intro.php
844 #
845 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
846 6 T_VOID => 0x0001,
847 T_INT => 0x0002,
848 T_FLOAT => 0x0004,
849 T_BOOL => 0x0008,
850 T_STR => 0x0010,
851 T_ARRAY => 0x0020,
852 T_OBJECT => 0x0040,
853 T_CALL => 0x0080,
854 T_MASK => 0xffff,
855 6 };
856  
857  
858 # see: http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
859 # http://php.net/manual/en/language.operators.precedence.php
860 #
861 6 my %op_prio = (
862 '\\' => 0,
863 '->' => 1,
864 '::' => 1,
865 '+-' => 2, # sign
866 '$' => 2,
867 '++' => 2,
868 '--' => 2,
869 'new'=> 2, # unary
870 '**' => 3,
871 '!' => 4, # unary
872 '~' => 4, # unary
873 '*' => 5,
874 '/' => 5,
875 '%' => 5,
876 '+' => 6,
877 '-' => 6,
878 '.' => 6,
879 '<<' => 7,
880 '>>' => 7,
881 '<' => 8,
882 '>' => 8,
883 '<=' => 8,
884 '>=' => 8,
885 'lt' => 8, # (does not exist in php5-8)
886 'gt' => 8, # (does not exist in php5-8)
887 'le' => 8, # (does not exist in php5-8)
888 'ge' => 8, # (does not exist in php5-8)
889 '==' => 9,
890 '!=' => 9,
891 '<>' => 9, # diamond seems to work as != even if not documented
892 '===' => 9,
893 '!==' => 9,
894 '<=>' => 9, # spaceship since php7
895 'eq' => 9, # (does not exist in php5-8)
896 'ne' => 9, # (does not exist in php5-8)
897 '&' => 10,
898 '^' => 11,
899 '|' => 12,
900 '&&' => 13,
901 '||' => 14,
902 '??' => 15, # right since php7
903 ':' => 16, # right
904 '?' => 17, # right
905 '?:' => 17, # right
906 '=' => 18, # right
907 'not'=> 19, # right (does not exist in php5-8)
908 'and'=> 20,
909 'or' => 21,
910 'xor'=> 21,
911 'instanceof'=> 21,
912 '...'=> 22, # ellipses
913 );
914  
915 6 my %op_right = (
916 '**' => 1, # right associative
917 '->' => 1, # right associative
918 '::' => 1, # right associative
919 '??' => 1, # right associative
920 '$' => 1, # right associative
921 '=' => 1, # right associative
922 );
923  
924 6 my %op_unary = (
925 'new'=> 1, # unary
926 '!' => 1, # unary
927 '~' => 1, # unary
928 '?' => 1, # in ternary (dummy for op_prio)
929 ':' => 1, # in ternary (dummy for op_prio)
930 );
931  
932 # Variables, constants & function names: ^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$
933 # see: https://www.php.net/manual/en/language.variables.basics.php
934 # see: https://www.php.net/manual/en/language.constants.php
935 # see: https://www.php.net/manual/en/functions.user-defined.php
936 #
937 22559 ▶sub is_variable {
Subroutine is_variable: called CC=2 SCAR=6.9
Pod undocumented
938 22559 my ($s) = @_;
939  
940 # represent global vars as $GLOBALS$varname
941 # represent class vars as $classname$varname
942 # represent instance vars as $#instNNN$varname
943 # represent non symbol ${"xxx"} vars also as $#instNNN$varname
944 #
945 22559 ▶ if ($s =~/^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?(\$|[^\$]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?(\$|[^\$]*)$/) 7807 14752 22559
946 7807 return 1;
947 }
948 14752 return 0;
949 }
950  
951 10684 ▶sub is_strict_variable {
Subroutine is_strict_variable: called CC=2 SCAR=6.9
Pod undocumented
952 10684 my ($s) = @_;
953  
954 10684 ▶ if ($s =~/^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) 4610 6074 10684
955 4610 return 1;
956 }
957 6074 return 0;
958 }
959  
960 2155 ▶sub is_symbol {
Subroutine is_symbol: called CC=2 SCAR=6.9
Pod undocumented
961 2155 my ($s) = @_;
962  
963 2155 ▶ if ($s =~/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) 1883 272 2155
964 1883 return 1;
965 }
966 272 return 0;
967 }
968  
969 17 ▶sub is_magic_const {
Subroutine is_magic_const: called CC=3 SCAR=11.0
Pod undocumented
970 17 my ($self, $s) = @_;
971  
972 17 ▶ if ($s =~ /^#const\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#const\d+$/) 17 0 17
973 17 ▶ if (exists $magic_constants{$self->{strmap}->{$s}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $magic_constants{$self->{"strmap"}{$s}}) 12 5 17
974 12 return $self->{strmap}->{$s};
975 }
976 }
977 5 return;
978 }
979  
980 # check if statement is empty block
981 #
982 149 ▶sub is_empty_block {
Subroutine is_empty_block: called CC=3 SCAR=11.0
Pod undocumented
983 149 my ($self, $s) = @_;
984  
985 149 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) 85 64 149
986 85 my ($type, $a) = @{$self->{strmap}->{$s}};
987 85 ▶ if (scalar @$a == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 0) 79 6 85
988 79 return 1;
989 }
990 }
991 70 return 0;
992 }
993  
994 # flatten block (and remove #null statements)
995 #
996 3852 ▶sub flatten_block {
Subroutine flatten_block: called CC=4 SCAR=13.9
Pod undocumented
997 3852 my ($self, $s, $out) = @_;
998  
999 3852 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) { } 695 3157 3852
1000 695 my ($type, $a) = @{$self->{strmap}{$s}};
1001 695 foreach my $stmt (@$a) {
1002 876 $self->flatten_block($stmt, $out);
1003 }
1004 } else {
1005 3157 ▶ if ($s ne '#null') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne "#null") 3054 103 3157
1006 3054 push(@$out, $s);
1007 }
1008 }
1009 3852 return;
1010 }
1011  
1012 # flatten block with single statement
1013 #
1014 245 ▶sub flatten_block_if_single {
Subroutine flatten_block_if_single: called CC=3 SCAR=11.0
Pod undocumented
1015 245 my ($self, $s) = @_;
1016  
1017 245 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) 238 7 245
1018 238 my ($type, $a) = @{$self->{strmap}{$s}};
1019 238 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) 147 91 238
1020 147 return $a->[0];
1021 }
1022 }
1023 98 return $s;
1024 }
1025  
1026 # create and split global var
1027 #
1028 59 ▶sub global_var {
Subroutine global_var: called CC=1 SCAR=0.0
Pod undocumented
1029 59 my ($global) = @_;
1030 59 return '$GLOBALS' . $global;
1031 }
1032  
1033 6253 ▶sub global_split {
Subroutine global_split: called CC=1 SCAR=0.0
Pod undocumented
1034 6253 my ($var) = @_;
1035 6253 my ($global) = $var =~ /^\$GLOBALS(\$.*)$/;
1036 6253 return $global;
1037 }
1038  
1039 # create and split method name
1040 #
1041 354 ▶sub method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
1042 354 my ($class, $name) = @_;
1043 354 return $class . '::' . $name;
1044 }
1045  
1046 2168 ▶sub method_split {
Subroutine method_split: called CC=1 SCAR=0.0
Pod undocumented
1047 2168 my ($method) = @_;
1048 # allow namespace prefix
1049 2168 my ($class, $name) = $method =~ /^(#inst\d+|[\w\x80-\xff\\]+)::([\w\x80-\xff]+)$/;
1050 2168 return ($class, $name);
1051 }
1052  
1053 # create and split instance var
1054 #
1055 53 ▶sub inst_var {
Subroutine inst_var: called CC=1 SCAR=0.0
Pod undocumented
1056 53 my ($inst, $var) = @_;
1057 53 return '$' . $inst . $var;
1058 }
1059  
1060 7273 ▶sub inst_split {
Subroutine inst_split: called CC=1 SCAR=0.0
Pod undocumented
1061 7273 my ($instvar) = @_;
1062 7273 my ($inst, $var) = $instvar =~ /^\$(#inst\d+|[\w\x80-\xff]+)(\$.*)$/;
1063 7273 return ($inst, $var);
1064 }
1065  
1066 # create and split namespace name
1067 #
1068 31 ▶sub ns_name {
Subroutine ns_name: called CC=1 SCAR=0.0
Pod undocumented
1069 31 my ($name, $elem) = @_;
1070 31 return $name . '\\' . $elem;
1071 }
1072  
1073 0 ▶sub ns_split {
Subroutine ns_split: not called CC=1 SCAR=6.9
Pod undocumented
1074 0 my ($name) = @_;
1075 0 my ($ns, $elem) = $name =~ /^([^\\]*)\\(.+)$/;
1076 0 return ($ns, $elem);
1077 }
1078  
1079 # create path from namespace
1080 #
1081 14 ▶sub ns_to_str {
Subroutine ns_to_str: called CC=5 SCAR=16.1
Pod undocumented
1082 14 my ($self, $var) = @_;
1083  
1084 14 ▶ if ($var =~ /^#ns\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var =~ /^#ns\d+$/) { } 3 11 14
elsif (is_strval($var)) { } 8 3 11
1085 3 my ($n, $e) = @{$self->{strmap}{$var}};
1086  
1087 3 ▶ unless (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 2 1 3
1088 2 $n = ''; # toplevel
1089 }
1090 3 $e = $self->ns_to_str($e);
1091 3 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 3 0 3
1092 3 return ns_name($n, $e);
1093 }
1094 } elsif (is_strval($var)) {
1095 8 return $self->{strmap}{$var};
1096 } else {
1097 3 return $var;
1098 }
1099 0 return;
1100 }
1101  
1102 # create variable from variable variable
1103 # $$var -> $val
1104 # ${$var} -> $val
1105 #
1106 90 ▶sub varvar_to_var {
Subroutine varvar_to_var: called CC=2 SCAR=6.9
Pod undocumented
1107 90 my ($self, $var) = @_;
1108  
1109 90 ▶ if (is_strval($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($var)) 79 11 90
1110 79 my $str = $self->{strmap}{$var};
1111  
1112 # variable names are only handled up to first '$'.
1113 # also 'null' is allowed (represented as '' or ${null})
1114 #
1115 79 my ($suffix) = $str =~ /^(\$$|[^\$]*)/;
1116 79 return '$' . $suffix;
1117 }
1118 11 return;
1119 }
1120  
1121 # $GLOBALS['str'] -> $str
1122 #
1123 606 ▶sub globalvar_to_var {
Subroutine globalvar_to_var: called CC=3 SCAR=11.0
Pod undocumented
1124 606 my ($self, $base, $idx) = @_;
1125  
1126 606 ▶ if ($base =~ /^\$GLOBALS$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base =~ /^\$GLOBALS$/) 124 482 606
1127 124 my $idxval = $self->get_strval($idx);
1128 124 ▶ if (defined $idxval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idxval) 123 1 124
1129 # variable names are only handled up to first '$'.
1130 # also 'null' is allowed (represented as '' or ${null})
1131 #
1132 123 my ($suffix) = $idxval =~ /^(\$$|[^\$]*)/;
1133 123 return '$' . $suffix;
1134 }
1135 }
1136 483 return;
1137 }
1138  
1139 # return base var of multi dimensional elem
1140 #
1141 387 ▶sub elem_base {
Subroutine elem_base: called CC=4 SCAR=13.9
Pod undocumented
1142 387 my ($self, $s) = @_;
1143  
1144 387 ▶ while ($s =~ /^#elem\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#elem\d+$/) 54 379 433
1145 54 my ($v, $i) = @{$self->{strmap}->{$s}};
1146  
1147 54 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 37 17 54
1148 # add resolvable globals
1149 #
1150 37 my $g = $self->globalvar_to_var($v, $i);
1151 37 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) 8 29 37
1152 8 $g = global_var($g);
1153 8 return $g;
1154 }
1155 }
1156 46 $s = $v;
1157 }
1158 379 return $s;
1159 }
1160  
1161 0 ▶sub getline {
Subroutine getline: not called CC=1 SCAR=6.9
Pod undocumented
1162 0 my ($self) = @_;
1163  
1164 #$self->{log}->('getline', "%d", $self->{strmap}->{'__LINE__'}) if $self->{log};
1165 0 return $self->{strmap}->{'__LINE__'};
1166 }
1167  
1168 1040 ▶sub updateline {
Subroutine updateline: called CC=4 SCAR=15.9
Pod undocumented
1169 1040 my ($self, $var) = @_;
1170  
1171 #$self->{log}->('updateline', "test $var") if $self->{log};
1172  
1173 # update line number based on preceeding string
1174 #
1175 1040 ▶ if (exists $self->{strmap}->{'__LINEMAP__'}{$var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{"__LINEMAP__"}{$var}) 1039 1 1040
1176 1039 my $val = $self->{strmap}->{'__LINEMAP__'}{$var};
1177 1039 ▶ if ($self->{strmap}->{'__LINE__'} < $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"strmap"}{"__LINE__"} < $val) 0 1039 1039
1178 0 ▶ $self->{log}->('updateline', "[$var] %d -> %d", $self->{strmap}->{'__LINE__'}, $val) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1179 0 $self->{strmap}->{'__LINE__'} = $val;
1180 }
1181 }
1182 1040 return;
1183 }
1184  
1185 0 ▶sub trim_list {
Subroutine trim_list: not called CC=5 SCAR=34.0
Pod undocumented
1186 0 my ($list) = @_;
1187  
1188 0 ▶ while ((scalar @$list > 0) && ($list->[0] =~ /^\s+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 0 and $list->[0] =~ /^\s+$/) 0 0 0
Condition0%0/3
scalar @$list > 0 and $list->[0] =~ /^\s+$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$list > 0 and $list->[0] =~ /^\s+$/
scalar @$list > 0 $list->[0] =~ /^\s+$/
Truth table0%0/3
A and B
A= scalar @$list > 0B= $list->[0] =~ /^\s+$/
ABresult
0X0
100
111
1189 0 shift @$list;
1190 }
1191 0 ▶ while ((scalar @$list > 0) && ($list->[-1] =~ /^\s+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 0 and $list->[-1] =~ /^\s+$/) 0 0 0
Condition0%0/3
scalar @$list > 0 and $list->[-1] =~ /^\s+$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$list > 0 and $list->[-1] =~ /^\s+$/
scalar @$list > 0 $list->[-1] =~ /^\s+$/
Truth table0%0/3
A and B
A= scalar @$list > 0B= $list->[-1] =~ /^\s+$/
ABresult
0X0
100
111
1192 0 pop @$list;
1193 }
1194 }
1195  
1196 810 ▶sub unspace_list {
Subroutine unspace_list: called CC=1 SCAR=0.0
Pod undocumented
1197 810 my ($list) = @_;
1198 # remove empty fields
1199 810 my @filtered = grep { $_ !~ /^\s+$/ } @$list;
1200  
1201 # remove comments
1202 810 @filtered = grep { $_ !~ /^\/\*.*\*\/$/ } @filtered;
1203  
1204 810 return \@filtered;
1205 }
1206  
1207 6277 ▶sub unquote_names {
Subroutine unquote_names: called CC=1 SCAR=0.1
Pod undocumented
1208 6277 my ($str) = @_;
1209  
1210 # todo: is this really needed?
1211 6277 if (1) {
1212 # \xXX
1213 0 $str =~ s/\\x([0-9a-fA-F]{2})/chr(hex($1))/ge;
1214 }
1215 6277 return $str;
1216 }
1217  
1218 0 ▶sub dump_line {
Subroutine dump_line: not called CC=3 SCAR=24.8
Pod undocumented
1219 0 my ($self, $prefix, $tok) = @_;
1220  
1221 0 ▶ for (my $i=0; $i < scalar @$tok; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$tok) 0 0 0
1222 0 my $word = $tok->[$i];
1223  
1224 0 ▶ if ($word =~ /^#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^#/) { } 0 0 0
1225 0 my $s = $self->shortstr($self->{strmap}->{$word}, 100);
1226 0 print "$prefix> $word [$s]\n";
1227 } else {
1228 0 my $t = unquote_names($word);
1229 0 print "$prefix> $t [$word]\n";
1230 }
1231 }
1232 0 my $q = join('', @$tok);
1233 0 print "$prefix> SHORTQ: $q\n";
1234 0 return;
1235 }
1236  
1237 145 ▶sub read_array {
Subroutine read_array: called CC=21 SCAR=33.3
Pod undocumented
1238 145 my ($self, $tok, $close, $arr) = @_;
1239  
1240 145 while (1) {
1241 244 ▶ if (scalar @$tok == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok == 0) 0 244 244
1242 0 last;
1243 }
1244 244 ▶ if ($tok->[0] eq $close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] eq $close) 25 219 244
1245 25 shift @$tok;
1246 25 last;
1247 }
1248 219 my $val = $self->read_statement($tok, undef);
1249 219 ▶ if (!defined $val || ($val eq $close)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq $close) 0 219 219
Condition33%1/3
not defined $val or $val eq $close
l!l&&r!l&&!r
00219
MC/DC0%0/2
not defined $val or $val eq $close
not defined $val $val eq $close
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq $close
ABresult
1X1
011
000
1250 0 last;
1251 }
1252 219 ▶ if ($val eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq ",") 1 218 219
1253 1 $arr->set(undef, undef);
1254 1 next; # allow empty fields for list()
1255 }
1256 218 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 218 0 218
1257 218 ▶ if ($tok->[0] eq $close) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tok->[0] eq $close) { } 103 115 218
elsif ($tok->[0] eq ',') { } 82 33 115
elsif ($tok->[0] eq '=>') { } 33 0 33
1258 103 shift @$tok;
1259 103 $arr->set(undef, $val);
1260 103 last;
1261 } elsif ($tok->[0] eq ',') {
1262 82 shift @$tok;
1263 82 $arr->set(undef, $val);
1264 82 next;
1265 } elsif ($tok->[0] eq '=>') {
1266 33 shift @$tok;
1267 33 my $key = $val;
1268 33 ▶ if ($key =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /^#expr\d+$/) { } 2 31 33
elsif (is_null($key)) { } 1 30 31
1269 2 my ($op, $v1, $v2) = @{$self->{strmap}->{$key}};
1270 2 ▶ if (($op eq '-') && !defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-" and not defined $v1) 2 0 2
Condition33%1/3
$op eq "-" and not defined $v1
!ll&&!rl&&r
002
MC/DC0%0/2
$op eq "-" and not defined $v1
$op eq "-" not defined $v1
Truth table33%1/3
A and not(B)
A= $op eq "-"B= not defined $v1
ABresult
0X0
100
111
1271 2 my $str = $self->get_strval($v2);
1272 2 ▶ if (defined $str && is_int_index($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and is_int_index($str)) 2 0 2
Condition33%1/3
defined $str and is_int_index($str)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $str and is_int_index($str)
defined $str is_int_index($str)
Truth table33%1/3
A and B
A= defined $strB= is_int_index($str)
ABresult
0X0
100
111
1273 2 $key = -$str;
1274 }
1275 }
1276 } elsif (is_null($key)) {
1277 1 $key = $self->setstr(''); # null maps to '' array index
1278 }
1279 33 $val = $self->read_statement($tok, undef);
1280 33 ▶ if (!defined $val || ($val eq $close)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq $close) 0 33 33
Condition33%1/3
not defined $val or $val eq $close
l!l&&r!l&&!r
0033
MC/DC0%0/2
not defined $val or $val eq $close
not defined $val $val eq $close
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq $close
ABresult
1X1
011
000
1281 0 $arr->set($key, undef);
1282 0 last;
1283 }
1284 33 $arr->set($key, $val);
1285 33 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) { } 33 0 33
1286 33 ▶ if ($tok->[0] eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->[0] eq $close) { } 17 16 33
elsif ($tok->[0] eq ',') { } 16 0 16
1287 17 shift @$tok;
1288 17 last;
1289 } elsif ($tok->[0] eq ',') {
1290 16 shift @$tok;
1291 16 next;
1292 }
1293 } else {
1294 0 last;
1295 }
1296 }
1297 }
1298 }
1299 145 return;
1300 }
1301  
1302 # last_op is optional param
1303 #
1304 13835 ▶sub _read_statement {
Subroutine _read_statement: called CC=387 SCAR=83.1
1305 13835 my ($self, $tok, $last_op) = @_;
1306  
1307 13835 ▶ if ((scalar @$tok > 0) && ($tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i)) {
Branch: 47 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i) { } 3525 10310 13835
elsif (scalar @$tok > 0 and $tok->[0] =~ /^null$/i) { } 16 10294 10310
elsif (scalar @$tok > 1 and $tok->[0] eq '{') { } 187 10107 10294
elsif (scalar @$tok > 1 and $tok->[0] eq '(') { } 60 10047 10107
elsif (scalar @$tok > 1 and $tok->[0] eq '[') { } 12 10035 10047
elsif (scalar @$tok > 1 and $tok->[0] eq '&') { } 8 10027 10035
elsif (scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ':' && $tok->[2] ne ':' and not exists $php_keywords{$tok->[0]}) { } 6277 3750 10027
elsif (scalar @$tok > 1 and $tok->[0] eq '<' and $tok->[1] eq '?') { } 0 3750 3750
elsif (scalar @$tok > 5 and $tok->[0] eq '<' and $tok->[1] eq 'script' and $tok->[2] eq 'type' and $tok->[3] eq '=' and $tok->[5] eq '>') { } 0 3750 3750
elsif (scalar @$tok > 1 and $tok->[0] eq '?' and $tok->[1] eq '>') { } 0 3750 3750
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'echo') { } 147 3603 3750
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'print') { } 0 3603 3603
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'namespace') { } 10 3593 3603
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'use') { } 0 3593 3593
elsif (scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i) { } 0 3593 3593
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'global') { } 6 3587 3593
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'return') { } 118 3469 3587
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'goto') { } 1 3468 3469
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'throw') { } 0 3468 3468
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'break') { } 2 3466 3468
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'continue') { } 0 3466 3466
elsif (scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/) { } 55 3411 3466
elsif (scalar @$tok > 0 and lc $tok->[0] eq '__halt_compiler') { } 0 3411 3411
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'if' and $tok->[1] eq '(') { } 133 3278 3411
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'switch' and $tok->[1] eq '(') { } 10 3268 3278
elsif (scalar @$tok > 2 and lc $tok->[0] eq 'case') { } 16 3252 3268
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'default') { } 0 3252 3252
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'try' and $tok->[1] eq '{') { } 2 3250 3252
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'for' and $tok->[1] eq '(') { } 21 3229 3250
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'while' and $tok->[1] eq '(') { } 12 3217 3229
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'do' and $tok->[1] eq '{') { } 7 3210 3217
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'foreach' and $tok->[1] eq '(') { } 19 3191 3210
elsif (scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq '(') { } 133 3058 3191
elsif (scalar @$tok > 4 and lc $tok->[0] eq 'function' || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq 'function') { } 228 2830 3058
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'class' || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq 'class') { } 56 2774 2830
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'trait') { } 1 2773 2774
elsif (scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/) { } 36 2737 2773
elsif (scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq '(') { } 755 1982 2737
elsif (scalar @$tok > 1 and $tok->[0] eq '$' and is_symbol($tok->[1])) { } 0 1982 1982
elsif (scalar @$tok > 1 and $tok->[0] eq '$' and $tok->[1] =~ /^\$/) { } 6 1976 1982
elsif (scalar @$tok > 3 and $tok->[0] eq '$' and $tok->[1] eq '{') { } 78 1898 1976
elsif (scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq '[' || $tok->[1] eq '{') { } 422 1476 1898
elsif (scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]) { } 12 1464 1476
elsif (scalar @$tok > 3 and $tok->[0] eq '.' and $tok->[1] eq '.' and $tok->[2] eq '.') { } 0 1464 1464
elsif (scalar @$tok > 1 and $tok->[0] =~ /^\\$/) { } 7 1457 1464
elsif (scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i) { } 68 1389 1457
elsif (scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i) { } 1376 13 1389
Condition66%2/3
scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i
!ll&&!rl&&r
0103103525
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i
scalar @$tok > 0 $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|endswitch|as|=>|catch|finally)$/i
ABresult
0X0
100
111
1308 3525 my $sym = shift @$tok;
1309 3525 return $sym;
1310 ▶ } elsif ((scalar @$tok > 0) && ($tok->[0] =~ /^null$/i)) {
Condition66%2/3
scalar @$tok > 0 and $tok->[0] =~ /^null$/i
!ll&&!rl&&r
01029416
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] =~ /^null$/i
scalar @$tok > 0 $tok->[0] =~ /^null$/i
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] =~ /^null$/i
ABresult
0X0
100
111
1311 16 shift @$tok;
1312 16 unshift(@$tok, '#null');
1313 16 my $res = $self->read_statement($tok, $last_op);
1314 16 return $res;
1315 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '{')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "{"
!ll&&!rl&&r
20528055187
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "{"
scalar @$tok > 1 $tok->[0] eq "{"
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "{"
ABresult
0X0
100
111
1316 # block expression { statement1; statement2; ... }
1317 # also allow empty { } block
1318 #
1319 187 shift @$tok;
1320 187 my $arglist = $self->read_code_block($tok, '}', ';');
1321 187 my $k = $self->setblk('std', $arglist);
1322 187 return $k;
1323 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '(')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "("
!ll&&!rl&&r
2052799560
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "("
scalar @$tok > 1 $tok->[0] eq "("
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "("
ABresult
0X0
100
111
1324 # brace expression ( expr | call ) => result
1325 # also: allow empty ( ) block
1326 # also: type casting (int|bool|float|array|object|unset)
1327 # http://php.net/manual/en/language.types.type-juggling.php
1328 #
1329 60 shift @$tok;
1330 60 my $arglist = $self->read_block($tok, ')', undef);
1331  
1332 60 ▶ if (scalar @$arglist > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist > 0) 60 0 60
1333 60 ▶ if (scalar @$arglist == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist == 1) 60 0 60
1334 60 my $ref = $arglist->[0];
1335 60 my $str = $self->get_strval_or_str($ref);
1336 #$self->{log}->('parse', "braces: $ref, $str") if $self->{log};
1337 60 ▶ if (is_strval($ref) && ($str =~ /^(int|bool|float|string|array|object|unset)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/) 2 58 60
Condition100%3/3
is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/
!ll&&!rl&&r
5712
MC/DC100%2/2
is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/
is_strval($ref) $str =~ /^(int|bool|float|string|array|object|unset)$/
Truth table100%3/3
A and B
A= is_strval($ref)B= $str =~ /^(int|bool|float|string|array|object|unset)$/
ABresult
0X0
100
111
1338 # type casting
1339 # https://www.php.net/manual/en/language.types.type-juggling.php
1340 # https://www.php.net/manual/en/function.settype.php
1341 #
1342 2 my $res = $self->read_statement($tok, $last_op);
1343 2 my $k;
1344 2 ▶ if ($str eq 'int') {
Branch: 12 branches
BranchTrueFalseTotal
if ($str eq 'int') { } 1 1 2
elsif ($str eq 'integer') { } 0 1 1
elsif ($str eq 'string') { } 1 0 1
elsif ($str eq 'binary') { } 0 0 0
elsif ($str eq 'float') { } 0 0 0
elsif ($str eq 'double') { } 0 0 0
elsif ($str eq 'real') { } 0 0 0
elsif ($str eq 'bool') { } 0 0 0
elsif ($str eq 'boolean') { } 0 0 0
elsif ($str eq 'array') { } 0 0 0
elsif ($str eq 'object') { } 0 0 0
elsif ($str eq 'unset') { } 0 0 0
1345 1 $k = $self->setcall('intval', [$res]);
1346 } elsif ($str eq 'integer') {
1347 0 $k = $self->setcall('intval', [$res]);
1348 } elsif ($str eq 'string') {
1349 1 $k = $self->setcall('strval', [$res]);
1350 } elsif ($str eq 'binary') {
1351 0 $k = $self->setcall('strval', [$res]);
1352 } elsif ($str eq 'float') {
1353 0 $k = $self->setcall('floatval', [$res]);
1354 } elsif ($str eq 'double') {
1355 0 $k = $self->setcall('floatval', [$res]);
1356 } elsif ($str eq 'real') { # removed in php8
1357 0 $k = $self->setcall('floatval', [$res]);
1358 } elsif ($str eq 'bool') {
1359 0 $k = $self->setcall('boolval', [$res]);
1360 } elsif ($str eq 'boolean') {
1361 0 $k = $self->setcall('boolval', [$res]);
1362 } elsif ($str eq 'array') {
1363 0 $k = $self->setcall('array', [$res]);
1364 } elsif ($str eq 'object') {
1365 0 $k = $self->setcall('object', [$res]);
1366 } elsif ($str eq 'unset') { # removed in php8
1367 0 my $t = $self->setstr('null');
1368 0 $k = $self->setcall('settype', [$res, $t]);
1369 } else {
1370 0 $k = $self->setcall('settype', [$res, $ref]);
1371 }
1372 2 unshift(@$tok, $k);
1373 2 $res = $self->read_statement($tok, $last_op);
1374 2 return $res;
1375 }
1376 58 ▶ if (is_strval($ref) || ($ref =~ /^#expr\d+$/) || ($ref =~ /^#call\d+$/) || ($ref =~ /^#inst\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/) 56 2 58
Condition88%8/9
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/
l!l&&r!l&&!r
5602
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/
l!l&&r!l&&!r
5062
is_strval($ref) or $ref =~ /^#expr\d+$/
l!l&&r!l&&!r
1498
MC/DC75%3/4
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/
is_strval($ref) $ref =~ /^#expr\d+$/ $ref =~ /^#call\d+$/ $ref =~ /^#inst\d+$/
Truth table80%4/5
A or B or C or D
A= is_strval($ref)B= $ref =~ /^#expr\d+$/C= $ref =~ /^#call\d+$/D= $ref =~ /^#inst\d+$/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1377 56 unshift(@$tok, $ref);
1378 56 my $res = $self->read_statement($tok, $last_op);
1379 56 return $res;
1380 }
1381 }
1382 2 my $res = $self->setblk('brace', $arglist);
1383  
1384 # - anonymous functions might be called directly -> '(function () { return 1; })()'
1385 # - also subexpressions might use braces -> '$x = ($y) ? 1 : 2'
1386 #
1387 2 unshift(@$tok, $res);
1388 2 $res = $self->read_statement($tok, $last_op);
1389 2 return $res;
1390 }
1391 0 my $res = $self->setblk('brace', []);
1392 0 return $res;
1393 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '[')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "["
!ll&&!rl&&r
2052798312
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "["
scalar @$tok > 1 $tok->[0] eq "["
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "["
ABresult
0X0
100
111
1394 # $array = ['a','b','c']
1395 #
1396 12 shift @$tok;
1397  
1398 12 my $arr = $self->newarr();
1399 12 $self->read_array($tok, ']', $arr);
1400  
1401 #my $arglist = $self->read_block($tok, ']', ',');
1402 #foreach my $val (@$arglist) {
1403 # $arr->set(undef, $val);
1404 #}
1405 12 unshift(@$tok, $arr->{name});
1406 12 my $res = $self->read_statement($tok, $last_op);
1407 12 return $res;
1408 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '&')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "&"
!ll&&!rl&&r
205279758
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "&"
scalar @$tok > 1 $tok->[0] eq "&"
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "&"
ABresult
0X0
100
111
1409 # variable reference
1410 # & $var
1411 #
1412 8 shift @$tok;
1413  
1414 8 my $var = $self->read_statement($tok, undef);
1415 8 my $k = $self->setref($var);
1416 8 return $k;
1417 ▶ } elsif (((scalar @$tok == 1)
Condition94%17/18
scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ":" && $tok->[2] ne ":" and not exists $php_keywords{$tok->[0]}
!ll&&!rl&&r
374826277
scalar @$tok == 1 or scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ or scalar @$tok > 2 and $tok->[1] eq ":" and $tok->[2] ne ":"
l!l&&r!l&&!r
6246333748
scalar @$tok == 1 or scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/
l!l&&r!l&&!r
205241943781
scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/
!ll&&!rl&&r
037814194
scalar @$tok > 2 and $tok->[1] eq ":" and $tok->[2] ne ":"
!ll&&!rl&&r
37074133
scalar @$tok > 2 and $tok->[1] eq ":"
!ll&&!rl&&r
8369974
MC/DC85%6/7
scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ":" && $tok->[2] ne ":" and not exists $php_keywords{$tok->[0]}
scalar @$tok == 1 scalar @$tok > 1 $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ scalar @$tok > 2 $tok->[1] eq ":" $tok->[2] ne ":" not exists $php_keywords{$tok->[0]}
Truth table50%7/14
A or B and C or D and E and F and not(G)
A= scalar @$tok == 1B= scalar @$tok > 1C= $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/D= scalar @$tok > 2E= $tok->[1] eq ":"F= $tok->[2] ne ":"G= not exists $php_keywords{$tok->[0]}
ABCDEFGresult
00X0XXX0
00X10XX0
00X110X0
0100XXX0
01010XX0
010110X0
1XXXXX00
011XXX00
00X11100
01011100
1XXXXX11
011XXX11
00X11111
01011111
1418 || ((scalar @$tok > 1) && ($tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/))
1419 || ((scalar @$tok > 2) && ($tok->[1] eq ':') && ($tok->[2] ne ':'))) && !exists $php_keywords{$tok->[0]}) {
1420 # variable dereference
1421 # #str/#num/#const
1422 # constant
1423 # __FILE__
1424 # __LINE__
1425 #
1426 6277 my $sym = shift @$tok;
1427 6277 my $var = unquote_names($sym);
1428  
1429 6277 ▶ if (is_strict_variable($var) || ($var =~ /^#/)) {
Branch: 6 branches
BranchTrueFalseTotal
if (is_strict_variable($var) or $var =~ /^#/) { } 5927 350 6277
elsif ($var =~ /^__FILE__$/) { } 0 350 350
elsif ($var =~ /^__LINE__$/) { } 0 350 350
elsif ($var =~ /^false$/i) { } 3 347 350
elsif ($var =~ /^true$/i) { } 3 344 347
elsif (is_symbol($var)) { } 344 0 344
Condition100%3/3
is_strict_variable($var) or $var =~ /^#/
l!l&&r!l&&!r
14874440350
MC/DC100%2/2
is_strict_variable($var) or $var =~ /^#/
is_strict_variable($var) $var =~ /^#/
Truth table100%3/3
A or B
A= is_strict_variable($var)B= $var =~ /^#/
ABresult
1X1
011
000
1430 5927 ▶ if ($var =~ /^#str/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^#str/) 1040 4887 5927
1431 1040 $self->updateline($var);
1432 }
1433 5927 return $var;
1434 } elsif ($var =~ /^__FILE__$/) {
1435 0 my $v = $self->{filename};
1436 0 my $k = $self->setstr($v);
1437 0 ▶ $self->{log}->('parse', "getfile: $k -> $v") if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1438 0 return $k;
1439 } elsif ($var =~ /^__LINE__$/) {
1440 0 my $k = $self->setnum($self->getline());
1441 0 ▶ $self->{log}->('parse', "getline: $k -> %d", $self->{strmap}->{$k}) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1442 0 return $k;
1443 } elsif ($var =~ /^false$/i) {
1444 3 return $self->setnum(0);
1445 } elsif ($var =~ /^true$/i) {
1446 3 return $self->setnum(1);
1447 } elsif (is_symbol($var)) {
1448 # constants are always global
1449 # (undefined constants are propagated to string in exec)
1450 #
1451 344 my $k = $self->setconst($var);
1452 344 ▶ if ((scalar @$tok > 1) && ($tok->[0] eq ':') && ($tok->[1] ne ':') && !defined $last_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op) 2 342 344
Condition77%7/9
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op
!ll&&!rl&&r
34202
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":"
!ll&&!rl&&r
34202
scalar @$tok > 1 and $tok->[0] eq ":"
!ll&&!rl&&r
270722
MC/DC50%2/4
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op
scalar @$tok > 1 $tok->[0] eq ":" $tok->[1] ne ":" not defined $last_op
Truth table60%3/5
A and B and C and not(D)
A= scalar @$tok > 1B= $tok->[0] eq ":"C= $tok->[1] ne ":"D= not defined $last_op
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1453 2 shift @$tok;
1454 2 $k = $self->setstmt(['label', $k]); # goto label
1455 }
1456 344 return $k;
1457 }
1458 0 return $var;
1459 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '<') && ($tok->[1] eq '?')) {
Condition33%2/6
scalar @$tok > 1 and $tok->[0] eq "<" and $tok->[1] eq "?"
!ll&&!rl&&r
375000
scalar @$tok > 1 and $tok->[0] eq "<"
!ll&&!rl&&r
037500
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "<" and $tok->[1] eq "?"
scalar @$tok > 1 $tok->[0] eq "<" $tok->[1] eq "?"
Truth table25%1/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "<"C= $tok->[1] eq "?"
ABCresult
0XX0
10X0
1100
1111
1460 0 ▶ if ((scalar @$tok > 2) && ($tok->[2] eq 'php')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 2 and $tok->[2] eq 'php') { } 0 0 0
Condition0%0/3
scalar @$tok > 2 and $tok->[2] eq "php"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 2 and $tok->[2] eq "php"
scalar @$tok > 2 $tok->[2] eq "php"
Truth table0%0/3
A and B
A= scalar @$tok > 2B= $tok->[2] eq "php"
ABresult
0X0
100
111
1461 0 shift @$tok;
1462 0 shift @$tok;
1463 0 shift @$tok;
1464 0 return '<?php';
1465 } else {
1466 0 shift @$tok;
1467 0 shift @$tok;
1468 0 return '<?';
1469 }
1470 ▶ } elsif ((scalar @$tok > 5) && ($tok->[0] eq '<') && ($tok->[1] eq 'script') && ($tok->[2] eq 'type') && ($tok->[3] eq '=') && ($tok->[5] eq '>')) {
Condition40%6/15
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "=" and $tok->[5] eq ">"
!ll&&!rl&&r
375000
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "="
!ll&&!rl&&r
375000
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type"
!ll&&!rl&&r
375000
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script"
!ll&&!rl&&r
375000
scalar @$tok > 5 and $tok->[0] eq "<"
!ll&&!rl&&r
66730830
MC/DC0%0/6
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "=" and $tok->[5] eq ">"
scalar @$tok > 5 $tok->[0] eq "<" $tok->[1] eq "script" $tok->[2] eq "type" $tok->[3] eq "=" $tok->[5] eq ">"
Truth table28%2/7
A and B and C and D and E and F
A= scalar @$tok > 5B= $tok->[0] eq "<"C= $tok->[1] eq "script"D= $tok->[2] eq "type"E= $tok->[3] eq "="F= $tok->[5] eq ">"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1471 # filter out bad javascript tags in scripts with no proper end-tag
1472 # (this avoids misinterpretations of javascript while(1)-loops)
1473 #
1474 0 my @list = ();
1475 0 push(@list, shift @$tok);
1476 0 push(@list, shift @$tok);
1477 0 push(@list, shift @$tok);
1478 0 push(@list, shift @$tok);
1479 0 push(@list, shift @$tok); # type
1480 0 push(@list, shift @$tok);
1481  
1482 0 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 0 0 0
1483 0 ▶ if ((scalar @$tok > 3) && ($tok->[0] eq '<') && ($tok->[1] eq '/') && ($tok->[2] eq 'script') && ($tok->[3] eq '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">") 0 0 0
Condition0%0/12
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<"
!ll&&!rl&&r
000
MC/DC0%0/5
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">"
scalar @$tok > 3 $tok->[0] eq "<" $tok->[1] eq "/" $tok->[2] eq "script" $tok->[3] eq ">"
Truth table0%0/6
A and B and C and D and E
A= scalar @$tok > 3B= $tok->[0] eq "<"C= $tok->[1] eq "/"D= $tok->[2] eq "script"E= $tok->[3] eq ">"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1484 0 push(@list, shift @$tok);
1485 0 push(@list, shift @$tok);
1486 0 push(@list, shift @$tok);
1487 0 push(@list, shift @$tok);
1488 0 last;
1489 }
1490 0 my $sym = shift @$tok;
1491 0 push(@list, $sym);
1492 }
1493 0 my $script = join(' ', @list);
1494 0 my $s = $self->setstr($script);
1495 0 my $k = $self->setstmt(['echo', [$s]]);
1496 0 ▶ $self->{log}->('parse', "javascript string: %s", $script) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1497 0 return $k;
1498 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '?') && ($tok->[1] eq '>')) {
Condition33%2/6
scalar @$tok > 1 and $tok->[0] eq "?" and $tok->[1] eq ">"
!ll&&!rl&&r
375000
scalar @$tok > 1 and $tok->[0] eq "?"
!ll&&!rl&&r
037500
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "?" and $tok->[1] eq ">"
scalar @$tok > 1 $tok->[0] eq "?" $tok->[1] eq ">"
Truth table25%1/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "?"C= $tok->[1] eq ">"
ABCresult
0XX0
10X0
1100
1111
1499 0 shift @$tok;
1500 0 shift @$tok;
1501 0 return '?>';
1502 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'echo')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "echo"
!ll&&!rl&&r
03603147
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "echo"
scalar @$tok > 1 lc $tok->[0] eq "echo"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "echo"
ABresult
0X0
100
111
1503 147 shift @$tok;
1504 147 my $all_str = 1;
1505 147 my @args = ();
1506 147 while (1) {
1507 156 my $arg = $self->read_statement($tok, undef);
1508  
1509 156 ▶ unless (is_strval($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_strval($arg)) 64 92 156
1510 64 $all_str = 0;
1511 }
1512 156 ▶ if ($arg ne ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne ",") 156 0 156
1513 156 push(@args, $arg);
1514 }
1515 156 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 147 9 156
Condition100%3/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
91389
MC/DC100%2/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table100%3/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1516 147 last;
1517 }
1518 9 shift @$tok;
1519 }
1520 147 my $k = $self->setstmt(['echo', \@args]);
1521  
1522 # execute expr & might continue with operation
1523 #
1524 147 unshift(@$tok, $k);
1525 147 return $self->read_statement($tok, $last_op);
1526 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'print')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "print"
!ll&&!rl&&r
036030
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "print"
scalar @$tok > 1 lc $tok->[0] eq "print"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "print"
ABresult
0X0
100
111
1527 0 shift @$tok;
1528 0 my $arg = $self->read_statement($tok, undef);
1529 0 my $k = $self->setstmt(['print', $arg]);
1530  
1531 # execute expr & might continue with operation
1532 #
1533 0 unshift(@$tok, $k);
1534 0 return $self->read_statement($tok, $last_op);
1535 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'namespace')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "namespace"
!ll&&!rl&&r
0359310
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "namespace"
scalar @$tok > 1 lc $tok->[0] eq "namespace"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "namespace"
ABresult
0X0
100
111
1536 10 shift @$tok;
1537  
1538 10 my $arg = ''; # toplevel
1539 10 ▶ if ($tok->[0] ne '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] ne "{") 9 1 10
1540 9 $arg = $self->read_statement($tok, undef);
1541 9 my $str = $self->ns_to_str($arg);
1542 9 ▶ if (defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str) { } 9 0 9
1543 9 $arg = $str;
1544 } else {
1545 0 $self->{warn}->('parse', "bad namespace: %s", $arg);
1546 }
1547 }
1548 10 my $block;
1549 10 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 2 8 10
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
082
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1550 2 shift @$tok;
1551 2 my $arglist = $self->read_code_block($tok, '}', ';');
1552 2 $block = $self->setblk('std', $arglist);
1553 }
1554 10 return $self->setstmt(['namespace', $arg, $block]);
1555 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'use')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "use"
!ll&&!rl&&r
035930
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "use"
scalar @$tok > 1 lc $tok->[0] eq "use"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "use"
ABresult
0X0
100
111
1556 0 shift @$tok;
1557 # https://php.net/manual/en/language.oop5.traits.php
1558 0 my @args = ();
1559 0 while (1) {
1560 0 my $arg = $self->read_statement($tok, undef);
1561  
1562 0 push(@args, $arg);
1563 0 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1564 0 last;
1565 }
1566 0 shift @$tok;
1567 }
1568 0 return $self->setstmt(['use', \@args]);
1569 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^(include|include_once|require|require_once)$/i)) {
Condition33%1/3
scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i
!ll&&!rl&&r
035930
MC/DC0%0/2
scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i
scalar @$tok > 1 $tok->[0] =~ /^(include|include_once|require|require_once)$/i
Truth table33%1/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^(include|include_once|require|require_once)$/i
ABresult
0X0
100
111
1570 0 my $type = lc(shift @$tok);
1571 0 my $arg = $self->read_statement($tok, undef);
1572 0 return $self->setstmt([$type, $arg]);
1573 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'global')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "global"
!ll&&!rl&&r
035876
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "global"
scalar @$tok > 1 lc $tok->[0] eq "global"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "global"
ABresult
0X0
100
111
1574 6 shift @$tok;
1575 6 my @args = ();
1576 6 while (1) {
1577 6 my $arg = $self->read_statement($tok, undef);
1578  
1579 6 push(@args, $arg);
1580 6 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 6 0 6
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
060
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1581 6 last;
1582 }
1583 0 shift @$tok;
1584 }
1585 6 return $self->setstmt(['global', \@args]);
1586 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'return')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "return"
!ll&&!rl&&r
03469118
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "return"
scalar @$tok > 1 lc $tok->[0] eq "return"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "return"
ABresult
0X0
100
111
1587 118 shift @$tok;
1588 118 my $res = $self->read_statement($tok, undef);
1589 # remove trailing ';' if evaluated as string
1590 #
1591 118 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 99 19 118
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
01999
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1592 99 shift @$tok;
1593 }
1594 118 return $self->setstmt(['return', $res]);
1595 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'goto')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "goto"
!ll&&!rl&&r
034681
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "goto"
scalar @$tok > 1 lc $tok->[0] eq "goto"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "goto"
ABresult
0X0
100
111
1596 1 shift @$tok;
1597 1 my $res = $self->read_statement($tok, undef);
1598 # remove trailing ';' if evaluated as string
1599 #
1600 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1601 1 shift @$tok;
1602 }
1603 1 return $self->setstmt(['goto', $res]);
1604 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'throw')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "throw"
!ll&&!rl&&r
034680
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "throw"
scalar @$tok > 1 lc $tok->[0] eq "throw"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "throw"
ABresult
0X0
100
111
1605 0 shift @$tok;
1606 0 my $arg = $self->read_statement($tok, undef);
1607 0 return $self->setstmt(['throw', $arg]);
1608 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'break')) {
Condition66%2/3
scalar @$tok > 0 and lc $tok->[0] eq "break"
!ll&&!rl&&r
034662
MC/DC50%1/2
scalar @$tok > 0 and lc $tok->[0] eq "break"
scalar @$tok > 0 lc $tok->[0] eq "break"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "break"
ABresult
0X0
100
111
1609 2 shift @$tok;
1610 2 my $res = $self->read_statement($tok, undef); # optional level
1611 2 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 2 2
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
020
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1612 0 shift @$tok;
1613 }
1614 2 return $self->setstmt(['break', $res]);
1615 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'continue')) {
Condition33%1/3
scalar @$tok > 0 and lc $tok->[0] eq "continue"
!ll&&!rl&&r
034660
MC/DC0%0/2
scalar @$tok > 0 and lc $tok->[0] eq "continue"
scalar @$tok > 0 lc $tok->[0] eq "continue"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "continue"
ABresult
0X0
100
111
1616 0 shift @$tok;
1617 0 my $res = $self->read_statement($tok, undef); # optional level
1618 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1619 0 shift @$tok;
1620 }
1621 0 return $self->setstmt(['continue', $res]);
1622 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/)) {
Condition66%2/3
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
!ll&&!rl&&r
0341155
MC/DC50%1/2
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
scalar @$tok > 0 lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
ABresult
0X0
100
111
1623 55 my $type = shift @$tok;
1624 55 my $pfx = {$type => 1};
1625  
1626 55 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/) 7 48 55
Condition66%2/3
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
!ll&&!rl&&r
0487
MC/DC50%1/2
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
scalar @$tok > 0 lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
ABresult
0X0
100
111
1627 7 $type = shift @$tok;
1628 7 $pfx->{$type} = 1;
1629 }
1630 55 my $k = $self->setpfx($pfx);
1631 55 unshift(@$tok, $k);
1632 55 return $self->read_statement($tok);
1633 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq '__halt_compiler')) {
Condition33%1/3
scalar @$tok > 0 and lc $tok->[0] eq "__halt_compiler"
!ll&&!rl&&r
034110
MC/DC0%0/2
scalar @$tok > 0 and lc $tok->[0] eq "__halt_compiler"
scalar @$tok > 0 lc $tok->[0] eq "__halt_compiler"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "__halt_compiler"
ABresult
0X0
100
111
1634 0 my $k = shift @$tok;
1635 0 @$tok = ();
1636 0 return $k;
1637 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'if') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "if" and $tok->[1] eq "("
!ll&&!rl&&r
32780133
scalar @$tok > 3 and lc $tok->[0] eq "if"
!ll&&!rl&&r
1013177133
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "if" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "if" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "if"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1638 133 shift @$tok;
1639 133 shift @$tok;
1640 133 my $expr = $self->read_block($tok, ')', undef);
1641 133 my $then;
1642 my $else;
1643  
1644 133 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 10 123 133
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
012310
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1645 # allow alternative block syntax
1646 # http://php.net/manual/en/control-structures.alternative-syntax.php
1647 #
1648 10 shift @$tok;
1649 10 my $block = $self->read_code_block($tok, 'endif', ';', ['else', 'elseif']);
1650 10 $then = $self->setblk('std', $block);
1651 } else {
1652 123 $then = $self->read_statement($tok);
1653 123 ▶ if (!is_block($then)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($then)) 16 107 123
1654 16 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 16 16
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
1150
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1655 0 shift @$tok;
1656 }
1657 # always put '{ .. }' braces around if/else
1658 16 $then = $self->setblk('std', [$then]);
1659 }
1660 }
1661 133 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) eq 'else')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc $tok->[0] eq 'else') { } 23 110 133
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'elseif') { } 8 170 178
Condition100%3/3
scalar @$tok > 0 and lc $tok->[0] eq "else"
!ll&&!rl&&r
684223
MC/DC100%2/2
scalar @$tok > 0 and lc $tok->[0] eq "else"
scalar @$tok > 0 lc $tok->[0] eq "else"
Truth table100%3/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "else"
ABresult
0X0
100
111
1662 23 shift @$tok;
1663 23 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 6 17 23
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0176
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1664 # allow alternative block syntax
1665 # http://php.net/manual/en/control-structures.alternative-syntax.php
1666 #
1667 6 shift @$tok;
1668 6 my $block = $self->read_code_block($tok, 'endif', ';');
1669 6 $else = $self->setblk('std', $block);
1670 } else {
1671 17 $else = $self->read_statement($tok);
1672 17 ▶ if (!is_block($else)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($else)) 1 16 17
1673 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1674 1 shift @$tok;
1675 }
1676 1 $else = $self->setblk('std', [$else]);
1677 }
1678 }
1679 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'elseif')) {
Condition100%3/3
scalar @$tok > 0 and lc $tok->[0] eq "elseif"
!ll&&!rl&&r
68348
MC/DC100%2/2
scalar @$tok > 0 and lc $tok->[0] eq "elseif"
scalar @$tok > 0 lc $tok->[0] eq "elseif"
Truth table100%3/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "elseif"
ABresult
0X0
100
111
1680 8 shift @$tok;
1681 8 unshift(@$tok, 'if');
1682 8 $else = $self->read_statement($tok, undef);
1683 8 ▶ if (!is_block($else)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($else)) 8 0 8
1684 8 $else = $self->setblk('std', [$else]);
1685 }
1686 }
1687 133 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 133 133
1688 0 $self->{warn}->('parse', "if: bad cond %s", join(' ', @$expr));
1689 0 my $badcond = $self->setblk('expr', $expr);
1690 0 $expr = [$badcond];
1691 }
1692 133 return $self->setstmt(['if', $expr->[0], $then, $else]);
1693 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'switch') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "switch" and $tok->[1] eq "("
!ll&&!rl&&r
3268010
scalar @$tok > 3 and lc $tok->[0] eq "switch"
!ll&&!rl&&r
101316710
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "switch" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "switch" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "switch"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1694 10 shift @$tok;
1695 10 shift @$tok;
1696 10 my $expr = $self->read_block($tok, ')', undef);
1697 10 my $block = [];
1698 10 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 1 9 10
elsif (scalar @$tok > 0 and $tok->[0] eq '{') { } 9 0 9
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
091
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1699 # allow alternative block syntax
1700 # http://php.net/manual/en/control-structures.alternative-syntax.php
1701 #
1702 1 shift @$tok;
1703 1 $block = $self->read_code_block($tok, 'endswitch', ';');
1704 ▶ } elsif ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
009
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1705 9 shift @$tok;
1706 9 $block = $self->read_code_block($tok, '}', ';');
1707 } else {
1708 0 $self->{warn}->('parse', "expected switch block {}");
1709 }
1710 10 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 10 10
1711 0 $self->{warn}->('parse', "switch: bad cond %s", join(' ', @$expr));
1712 0 my $badcond = $self->setblk('expr', $expr);
1713 0 $expr = [$badcond];
1714 }
1715 10 my @cases = ();
1716 10 my $inst;
1717 10 foreach my $e (@$block) {
1718 31 ▶ if ($e =~ /^#stmt\d+$/ && (lc($self->{strmap}->{$e}->[0]) eq 'case')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^#stmt\d+$/ and lc $self->{'strmap'}{$e}[0] eq 'case') { } 16 15 31
Condition100%3/3
$e =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$e}[0] eq "case"
!ll&&!rl&&r
14116
MC/DC100%2/2
$e =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$e}[0] eq "case"
$e =~ /^#stmt\d+$/ lc $self->{"strmap"}{$e}[0] eq "case"
Truth table100%3/3
A and B
A= $e =~ /^#stmt\d+$/B= lc $self->{"strmap"}{$e}[0] eq "case"
ABresult
0X0
100
111
1719 16 my $c = $self->{strmap}->{$e}->[1]; # undef for default case
1720 16 $inst = [];
1721 16 my $b = $self->setblk('case', $inst); # block content added in next iterations
1722 16 push (@cases, [$c, $b]);
1723 } else {
1724 15 ▶ if (!defined $inst) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inst) 0 15 15
1725 0 $self->{warn}->('parse', "switch: inst w/o case: %s", $e);
1726 0 $inst = [];
1727 }
1728 15 push (@$inst, $e);
1729 }
1730 }
1731 10 return $self->setstmt(['switch', $expr->[0], \@cases]);
1732 ▶ } elsif ((scalar @$tok > 2) && (lc($tok->[0]) eq 'case')) {
Condition100%3/3
scalar @$tok > 2 and lc $tok->[0] eq "case"
!ll&&!rl&&r
4324816
MC/DC100%2/2
scalar @$tok > 2 and lc $tok->[0] eq "case"
scalar @$tok > 2 lc $tok->[0] eq "case"
Truth table100%3/3
A and B
A= scalar @$tok > 2B= lc $tok->[0] eq "case"
ABresult
0X0
100
111
1733 16 shift @$tok;
1734 16 my $expr = $self->read_statement($tok, undef);
1735 # 'case' might also be terminated by ';'
1736 #
1737 16 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':') || ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";") 15 1 16
Condition66%4/6
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
l!l&&r!l&&!r
1501
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0115
MC/DC33%1/3
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ":" $tok->[0] eq ";"
Truth table40%2/5
A and B or C
A= scalar @$tok > 0B= $tok->[0] eq ":"C= $tok->[0] eq ";"
ABCresult
11X1
0X11
1011
0X00
1000
1738 15 shift @$tok;
1739 }
1740 16 ▶ if ($expr =~ /^#stmt\d+$/ && (lc($self->{strmap}->{$expr}->[0]) eq 'label')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label") 1 15 16
Condition66%2/3
$expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label"
!ll&&!rl&&r
1501
MC/DC50%1/2
$expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label"
$expr =~ /^#stmt\d+$/ lc $self->{"strmap"}{$expr}[0] eq "label"
Truth table66%2/3
A and B
A= $expr =~ /^#stmt\d+$/B= lc $self->{"strmap"}{$expr}[0] eq "label"
ABresult
0X0
100
111
1741 1 $expr = $self->{strmap}->{$expr}->[1]; # label -> const
1742 }
1743 16 return $self->setstmt(['case', $expr]);
1744 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'default')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "default"
!ll&&!rl&&r
032520
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "default"
scalar @$tok > 1 lc $tok->[0] eq "default"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "default"
ABresult
0X0
100
111
1745 0 shift @$tok;
1746 # 'case' might also be terminated by ';'
1747 #
1748 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':') || ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";") 0 0 0
Condition0%0/6
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
l!l&&r!l&&!r
000
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ":" $tok->[0] eq ";"
Truth table0%0/5
A and B or C
A= scalar @$tok > 0B= $tok->[0] eq ":"C= $tok->[0] eq ";"
ABCresult
11X1
0X11
1011
0X00
1000
1749 0 shift @$tok;
1750 }
1751 0 return $self->setstmt(['case', undef]);
1752 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'try') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "try" and $tok->[1] eq "{"
!ll&&!rl&&r
325002
scalar @$tok > 3 and lc $tok->[0] eq "try"
!ll&&!rl&&r
10131492
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "try" and $tok->[1] eq "{"
scalar @$tok > 3 lc $tok->[0] eq "try" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "try"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
1753 2 shift @$tok;
1754 2 my $try;
1755 my $finally;
1756  
1757 # https://www.php.net/manual/en/language.exceptions.php
1758 #
1759 2 $try = $self->read_statement($tok);
1760 2 ▶ if (!is_block($try)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($try)) 0 2 2
1761 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1762 0 shift @$tok;
1763 }
1764 # always put '{ .. }' braces around try
1765 0 $try = $self->setblk('std', [$try]);
1766 }
1767 2 my @catches = ();
1768 2 ▶ while ((scalar @$tok > 1) && (lc($tok->[0]) eq 'catch') && ($tok->[1] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "(") 2 2 4
Condition66%4/6
scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "("
!ll&&!rl&&r
202
scalar @$tok > 1 and lc $tok->[0] eq "catch"
!ll&&!rl&&r
022
MC/DC33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "("
scalar @$tok > 1 lc $tok->[0] eq "catch" $tok->[1] eq "("
Truth table50%2/4
A and B and C
A= scalar @$tok > 1B= lc $tok->[0] eq "catch"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1769 2 shift @$tok;
1770 2 shift @$tok;
1771 2 my $exception = $self->read_block($tok, ')', undef);
1772 2 my $block= $self->read_statement($tok);
1773  
1774 2 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 2 2
1775 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1776 0 shift @$tok;
1777 }
1778 # always put '{ .. }' braces around catch
1779 0 $block = $self->setblk('std', [$block]);
1780 }
1781 2 push (@catches, [$exception->[0], $block]);
1782 }
1783 2 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) eq 'finally')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc $tok->[0] eq "finally") 1 1 2
Condition66%2/3
scalar @$tok > 0 and lc $tok->[0] eq "finally"
!ll&&!rl&&r
011
MC/DC50%1/2
scalar @$tok > 0 and lc $tok->[0] eq "finally"
scalar @$tok > 0 lc $tok->[0] eq "finally"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "finally"
ABresult
0X0
100
111
1784 1 shift @$tok;
1785 1 $finally= $self->read_statement($tok);
1786  
1787 1 ▶ if (!is_block($finally)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($finally)) 0 1 1
1788 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1789 0 shift @$tok;
1790 }
1791 # always put '{ .. }' braces around finally
1792 0 $finally = $self->setblk('std', [$finally]);
1793 }
1794 }
1795 2 return $self->setstmt(['try', $try, \@catches, $finally]);
1796 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'for') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "for" and $tok->[1] eq "("
!ll&&!rl&&r
3229021
scalar @$tok > 3 and lc $tok->[0] eq "for"
!ll&&!rl&&r
101312821
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "for" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "for" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "for"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1797 # note: just for-loops can take ',' operators in pre- and post-cond.
1798 # All 3 expressions can be empty;
1799 # http://php.net/manual/en/control-structures.for.php
1800 #
1801 21 shift @$tok;
1802 21 shift @$tok;
1803 21 my $expr1 = $self->read_code_block($tok, ';', ',');
1804 21 my $expr2 = $self->read_code_block($tok, ';', ',');
1805 21 my $expr3 = $self->read_code_block($tok, ')', ',');
1806 21 my $block;
1807 21 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 1 20 21
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0201
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1808 # allow alternative block syntax
1809 # http://php.net/manual/en/control-structures.alternative-syntax.php
1810 #
1811 1 shift @$tok;
1812 1 $block = $self->read_code_block($tok, 'endfor', ';');
1813 1 $block = $self->setblk('std', $block);
1814 } else {
1815 20 $block = $self->read_statement($tok);
1816 20 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 20 20
1817 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1818 0 shift @$tok;
1819 }
1820 # always put '{ .. }' braces around if/else
1821 0 $block = $self->setblk('std', [$block]);
1822 }
1823 }
1824 21 my $pre = $self->setblk('expr', $expr1);
1825 21 my $cond = $self->setblk('expr', $expr2);
1826 21 my $post = $self->setblk('expr', $expr3);
1827 21 return $self->setstmt(['for', $pre, $cond, $post, $block]);
1828 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'while') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
!ll&&!rl&&r
3217012
scalar @$tok > 3 and lc $tok->[0] eq "while"
!ll&&!rl&&r
101311612
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "while" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "while"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1829 12 shift @$tok;
1830 12 shift @$tok;
1831 12 my $expr = $self->read_block($tok, ')', ',');
1832 12 my $block;
1833 12 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 1 11 12
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0111
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1834 # allow alternative block syntax
1835 # http://php.net/manual/en/control-structures.alternative-syntax.php
1836 #
1837 1 shift @$tok;
1838 1 $block = $self->read_code_block($tok, 'endwhile', ';');
1839 1 $block = $self->setblk('std', $block);
1840 } else {
1841 11 $block = $self->read_statement($tok);
1842 11 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 1 10 11
1843 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1844 1 shift @$tok;
1845 }
1846 # always put '{ .. }' braces around if/else
1847 1 $block = $self->setblk('std', [$block]);
1848 }
1849 }
1850 12 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 12 12
1851 0 $self->{warn}->('parse', "while: bad cond %s", join(' ', @$expr));
1852 0 my $badcond = $self->setblk('expr', $expr);
1853 0 $expr = [$badcond];
1854 }
1855 12 return $self->setstmt(['while', $expr->[0], $block]);
1856 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'do') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "do" and $tok->[1] eq "{"
!ll&&!rl&&r
321007
scalar @$tok > 3 and lc $tok->[0] eq "do"
!ll&&!rl&&r
10131097
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "do" and $tok->[1] eq "{"
scalar @$tok > 3 lc $tok->[0] eq "do" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "do"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
1857 7 shift @$tok;
1858 7 my $block;
1859 my $expr;
1860  
1861 7 $block = $self->read_statement($tok);
1862 7 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 7 7
1863 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1864 0 shift @$tok;
1865 }
1866 # always put '{ .. }' braces around do-while block
1867 0 $block = $self->setblk('std', [$block]);
1868 }
1869 7 ▶ if ((scalar @$tok > 3) && (lc($tok->[0]) eq 'while') && ($tok->[1] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 3 and lc $tok->[0] eq 'while' and $tok->[1] eq '(') { } 7 0 7
Condition33%2/6
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
!ll&&!rl&&r
007
scalar @$tok > 3 and lc $tok->[0] eq "while"
!ll&&!rl&&r
007
MC/DC0%0/3
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "while" $tok->[1] eq "("
Truth table25%1/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "while"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1870 7 shift @$tok;
1871 7 shift @$tok;
1872 7 $expr = $self->read_block($tok, ')', ',');
1873  
1874 7 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 7 7
1875 0 $self->{warn}->('parse', "do-while: bad cond %s", join(' ', @$expr));
1876 0 my $badcond = $self->setblk('expr', $expr);
1877 0 $expr = [$badcond];
1878 }
1879 } else {
1880 0 $self->{warn}->('parse', "do-while: miss while");
1881 0 my $badcond = $self->setblk('expr', undef);
1882 0 $expr = [$badcond];
1883 }
1884 7 return $self->setstmt(['do', $expr->[0], $block]);
1885 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'foreach') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "foreach" and $tok->[1] eq "("
!ll&&!rl&&r
3191019
scalar @$tok > 3 and lc $tok->[0] eq "foreach"
!ll&&!rl&&r
101309019
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "foreach" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "foreach" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "foreach"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1886 19 shift @$tok;
1887 19 shift @$tok;
1888 19 my $expr = $self->read_block($tok, ')', ',');
1889 19 my $key;
1890 my $value;
1891  
1892 19 ▶ if ((scalar @$expr == 3) && (lc($expr->[1]) eq 'as')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$expr == 3 and lc $expr->[1] eq 'as') { } 7 12 19
elsif (scalar @$expr == 5 and lc $expr->[1] eq 'as' and $expr->[3] eq '=>') { } 12 0 12
Condition66%2/3
scalar @$expr == 3 and lc $expr->[1] eq "as"
!ll&&!rl&&r
1207
MC/DC50%1/2
scalar @$expr == 3 and lc $expr->[1] eq "as"
scalar @$expr == 3 lc $expr->[1] eq "as"
Truth table66%2/3
A and B
A= scalar @$expr == 3B= lc $expr->[1] eq "as"
ABresult
0X0
100
111
1893 7 $value = $expr->[2];
1894 ▶ } elsif ((scalar @$expr == 5) && (lc($expr->[1]) eq 'as') && ($expr->[3] eq '=>')) {
Condition33%2/6
scalar @$expr == 5 and lc $expr->[1] eq "as" and $expr->[3] eq "=>"
!ll&&!rl&&r
0012
scalar @$expr == 5 and lc $expr->[1] eq "as"
!ll&&!rl&&r
0012
MC/DC0%0/3
scalar @$expr == 5 and lc $expr->[1] eq "as" and $expr->[3] eq "=>"
scalar @$expr == 5 lc $expr->[1] eq "as" $expr->[3] eq "=>"
Truth table25%1/4
A and B and C
A= scalar @$expr == 5B= lc $expr->[1] eq "as"C= $expr->[3] eq "=>"
ABCresult
0XX0
10X0
1100
1111
1895 12 $key = $expr->[2];
1896 12 $value = $expr->[4];
1897 } else {
1898 0 $self->{warn}->('parse', "foreach: bad expr %s", join(' ', @$expr));
1899 0 my $badcond = $self->setblk('expr', $expr);
1900 0 $expr = [$badcond];
1901 }
1902 19 my $block;
1903 19 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 1 18 19
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0181
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1904 # allow alternative block syntax
1905 # http://php.net/manual/en/control-structures.alternative-syntax.php
1906 #
1907 1 shift @$tok;
1908 1 $block = $self->read_code_block($tok, 'endforeach', ';');
1909 1 $block = $self->setblk('std', $block);
1910 } else {
1911 18 $block = $self->read_statement($tok);
1912 18 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 1 17 18
1913 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1914 1 shift @$tok;
1915 }
1916 # always put '{ .. }' braces around if/else
1917 1 $block = $self->setblk('std', [$block]);
1918 }
1919 }
1920 19 return $self->setstmt(['foreach', $expr->[0], $key, $value, $block]);
1921 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] =~ /^array$/i) && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq "("
!ll&&!rl&&r
30580133
scalar @$tok > 2 and $tok->[0] =~ /^array$/i
!ll&&!rl&&r
43054133
MC/DC66%2/3
scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq "("
scalar @$tok > 2 $tok->[0] =~ /^array$/i $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 2B= $tok->[0] =~ /^array$/iC= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1922 133 shift @$tok;
1923 133 shift @$tok;
1924  
1925 133 my $arr = $self->newarr();
1926 133 $self->read_array($tok, ')', $arr);
1927  
1928 # execute expr & might continue with operation -> 'array(...)[idx]'?
1929 #
1930 133 unshift(@$tok, $arr->{name});
1931 133 return $self->read_statement($tok, $last_op);
1932 ▶ } elsif ((scalar @$tok > 4) && ((lc($tok->[0]) eq 'function') || (($tok->[0] =~ /^#pfx\d+$/) && (lc($tok->[1]) eq 'function')))) {
Condition100%9/9
scalar @$tok > 4 and lc $tok->[0] eq "function" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "function"
!ll&&!rl&&r
3192511228
lc $tok->[0] eq "function" or $tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "function"
l!l&&r!l&&!r
209192511
$tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "function"
!ll&&!rl&&r
24753619
MC/DC100%4/4
scalar @$tok > 4 and lc $tok->[0] eq "function" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "function"
scalar @$tok > 4 lc $tok->[0] eq "function" $tok->[0] =~ /^#pfx\d+$/ lc $tok->[1] eq "function"
Truth table100%5/5
A and B or C and D
A= scalar @$tok > 4B= lc $tok->[0] eq "function"C= $tok->[0] =~ /^#pfx\d+$/D= lc $tok->[1] eq "function"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1933 228 my $pfx = shift @$tok;
1934 228 my $p = {};
1935  
1936 228 ▶ if ($pfx =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pfx =~ /^#pfx\d+$/) 19 209 228
1937 19 $p = $self->{strmap}->{$pfx};
1938 19 shift @$tok;
1939 }
1940 228 my $cmd;
1941  
1942 # also allow anonymous funcs: http://php.net/manual/en/functions.anonymous.php
1943 #
1944 228 ▶ if ($tok->[0] ne '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] ne "(") 212 16 228
1945 212 my $sym = shift @$tok;
1946 212 $cmd = $self->read_statement([$sym], undef);
1947 212 ▶ if (is_strval($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($cmd)) 211 1 212
1948 211 $cmd = $self->{strmap}{$cmd};
1949 }
1950 }
1951 228 my $arglist = [];
1952 228 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq '(') { } 228 0 228
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "("
!ll&&!rl&&r
00228
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "("
scalar @$tok > 0 $tok->[0] eq "("
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "("
ABresult
0X0
100
111
1953 228 shift @$tok;
1954 228 $arglist = $self->read_block($tok, ')', ',');
1955 } else {
1956 0 $self->{warn}->('parse', "expected function arglist ()");
1957 }
1958 228 my $block = [];
1959 228 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq '{') { } 228 0 228
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
00228
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1960 228 shift @$tok;
1961 228 $block = $self->read_code_block($tok, '}', ';');
1962 } else {
1963 0 $self->{warn}->('parse', "expected function block {}");
1964 }
1965 228 $block = $self->setblk('std', $block);
1966  
1967 # function are registered later via registerfun
1968 #
1969 228 my $k = $self->setfun($cmd, $arglist, $block, $p);
1970  
1971 228 ▶ unless (defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmd) 16 212 228
1972 # anonymous functions might be called directly -> 'function () { return 1; }()'
1973 #
1974 16 unshift(@$tok, $k);
1975 16 $k = $self->read_statement($tok, $last_op);
1976 }
1977 228 return $k;
1978 ▶ } elsif ((scalar @$tok > 3) && ((lc($tok->[0]) eq 'class') || (($tok->[0] =~ /^#pfx\d+$/) && (lc($tok->[1]) eq 'class')))) {
Condition77%7/9
scalar @$tok > 3 and lc $tok->[0] eq "class" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "class"
!ll&&!rl&&r
101267356
lc $tok->[0] eq "class" or $tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "class"
l!l&&r!l&&!r
5602673
$tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "class"
!ll&&!rl&&r
2637360
MC/DC50%2/4
scalar @$tok > 3 and lc $tok->[0] eq "class" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "class"
scalar @$tok > 3 lc $tok->[0] eq "class" $tok->[0] =~ /^#pfx\d+$/ lc $tok->[1] eq "class"
Truth table80%4/5
A and B or C and D
A= scalar @$tok > 3B= lc $tok->[0] eq "class"C= $tok->[0] =~ /^#pfx\d+$/D= lc $tok->[1] eq "class"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1979 56 my $pfx = shift @$tok;
1980 56 my $p = {};
1981  
1982 56 ▶ if ($pfx =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pfx =~ /^#pfx\d+$/) 0 56 56
1983 0 $p = $self->{strmap}->{$pfx};
1984 0 shift @$tok;
1985 }
1986 56 my $name = shift @$tok;
1987  
1988 # http://php.net/manual/en/language.oop5.basic.php
1989 #
1990 56 ▶ if ($tok->[0] eq 'extends') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] eq "extends") 0 56 56
1991 0 shift @$tok;
1992 0 $p->{parent} = shift @$tok;
1993 }
1994 56 my $block = [];
1995 56 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 56 0 56
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
0056
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1996 56 shift @$tok;
1997 56 $block = $self->read_block($tok, '}', ';');
1998 }
1999 56 $block = $self->setblk('std', $block);
2000 56 return $self->setclass($name, $block, $p);
2001 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'trait')) {
Condition100%3/3
scalar @$tok > 3 and lc $tok->[0] eq "trait"
!ll&&!rl&&r
10126721
MC/DC100%2/2
scalar @$tok > 3 and lc $tok->[0] eq "trait"
scalar @$tok > 3 lc $tok->[0] eq "trait"
Truth table100%3/3
A and B
A= scalar @$tok > 3B= lc $tok->[0] eq "trait"
ABresult
0X0
100
111
2002 1 shift @$tok;
2003 1 my $name = shift @$tok;
2004  
2005 # https://www.php.net/manual/en/language.oop5.traits.php
2006 #
2007 1 my $block = [];
2008 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
2009 1 shift @$tok;
2010 1 $block = $self->read_block($tok, '}', ';');
2011 }
2012 1 $block = $self->setblk('std', $block);
2013 1 return $self->settrait($name, $block);
2014 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^#pfx\d+$/)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/
!ll&&!rl&&r
0273736
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/
scalar @$tok > 1 $tok->[0] =~ /^#pfx\d+$/
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^#pfx\d+$/
ABresult
0X0
100
111
2015 36 my $sym = shift @$tok;
2016  
2017 # TODO: support const and other visibility modifiers
2018 # https://www.php.net/manual/en/language.oop5.visibility.php
2019 #
2020 36 ▶ if (exists $self->{strmap}->{$sym}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$sym}) 36 0 36
2021 36 my $pfx = $self->{strmap}->{$sym};
2022 36 ▶ if (exists $pfx->{static}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"static"}) 11 25 36
2023 11 my @args = ();
2024 11 while (1) {
2025 11 my $arg = $self->read_statement($tok, undef);
2026  
2027 11 push(@args, $arg);
2028 11 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 11 0 11
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
0110
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
2029 11 last;
2030 }
2031 0 shift @$tok;
2032 }
2033 11 return $self->setstmt(['static', \@args, $pfx]);
2034 }
2035 25 ▶ if (exists $pfx->{const}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"const"}) 9 16 25
2036 9 my @args = ();
2037 9 while (1) {
2038 9 my $arg = $self->read_statement($tok, undef);
2039  
2040 9 push(@args, $arg);
2041 9 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 9 0 9
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
090
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
2042 9 last;
2043 }
2044 0 shift @$tok;
2045 }
2046 9 return $self->setstmt(['const', \@args, $pfx]);
2047 }
2048 }
2049 16 return $sym;
2050 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] !~ /^([\~\!\+\-\\]|new)$/i) && ($tok->[1] eq '(')) {
Condition100%6/6
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq "("
!ll&&!rl&&r
871895755
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i
!ll&&!rl&&r
4832650
MC/DC100%3/3
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq "("
scalar @$tok > 2 not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i $tok->[1] eq "("
Truth table100%4/4
A and not(B) and C
A= scalar @$tok > 2B= not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/iC= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
2051 # function call
2052 # (function name might be variable)
2053 #
2054 755 my $sym = shift @$tok;
2055 755 my $cmd = $sym;
2056  
2057 755 ▶ unless (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($sym)) 78 677 755
2058 78 $cmd = $self->read_statement([$sym], undef);
2059 }
2060 755 ▶ if (defined $last_op && ($last_op eq '$')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "\$") 1 754 755
Condition100%3/3
defined $last_op and $last_op eq "\$"
!ll&&!rl&&r
4762781
MC/DC100%2/2
defined $last_op and $last_op eq "\$"
defined $last_op $last_op eq "\$"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "\$"
ABresult
0X0
100
111
2061 # handle case: $$var(x) is ${$var}(x)
2062 1 return $cmd;
2063 }
2064 754 ▶ if (defined $last_op && ($last_op eq '::')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "::") 23 731 754
Condition100%3/3
defined $last_op and $last_op eq "::"
!ll&&!rl&&r
47625523
MC/DC100%2/2
defined $last_op and $last_op eq "::"
defined $last_op $last_op eq "::"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "::"
ABresult
0X0
100
111
2065 # handle case: (class::member)(x)
2066 23 return $cmd;
2067 }
2068 731 ▶ if (defined $last_op && ($last_op eq '->')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "->") 26 705 731
Condition100%3/3
defined $last_op and $last_op eq "->"
!ll&&!rl&&r
47622926
MC/DC100%2/2
defined $last_op and $last_op eq "->"
defined $last_op $last_op eq "->"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "->"
ABresult
0X0
100
111
2069 # handle case: ($obj->method)(x)
2070 26 return $cmd;
2071 }
2072 705 ▶ if (defined $last_op && ($last_op eq '\\')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "\\") 2 703 705
Condition100%3/3
defined $last_op and $last_op eq "\\"
!ll&&!rl&&r
4762272
MC/DC100%2/2
defined $last_op and $last_op eq "\\"
defined $last_op $last_op eq "\\"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "\\"
ABresult
0X0
100
111
2073 # handle case: (ns \\ cmd)(x)
2074 2 return $cmd;
2075 }
2076 703 ▶ if (is_strict_variable($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strict_variable($sym)) 16 687 703
2077 16 $cmd = $sym; # don't insert copy anonymous function here
2078 }
2079 703 shift @$tok;
2080  
2081 703 ▶ if (is_strval($cmd) && !is_null($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($cmd) and not is_null($cmd)) 0 703 703
Condition33%1/3
is_strval($cmd) and not is_null($cmd)
!ll&&!rl&&r
70300
MC/DC0%0/2
is_strval($cmd) and not is_null($cmd)
is_strval($cmd) not is_null($cmd)
Truth table33%1/3
A and not(B)
A= is_strval($cmd)B= not is_null($cmd)
ABresult
0X0
100
111
2082 0 $cmd = $self->{strmap}{$cmd};
2083 }
2084 703 ▶ if ($cmd =~ /^\@(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^\@(.*)$/) 0 703 703
2085 # remove optional '@' error suppress operator
2086 0 $cmd = $1;
2087 }
2088 # get arglist so that ref-params are not resolved to value
2089 # (need function definition to decide how to resolve variables)
2090 #
2091 703 my $arglist = $self->read_block($tok, ')', ',');
2092 703 my $k;
2093 703 ▶ if ($cmd eq 'unset') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd eq 'unset') { } 5 698 703
elsif ($cmd eq 'list') { } 2 696 698
2094 5 $k = $self->setstmt(['unset', $arglist]);
2095 } elsif ($cmd eq 'list') {
2096 2 my $arr = $self->newarr();
2097 2 foreach my $val (@$arglist) {
2098 4 $arr->set(undef, $val);
2099 }
2100 2 $k = $arr->{name};
2101 } else {
2102 696 $k = $self->setcall($cmd, $arglist);
2103 }
2104 703 unshift(@$tok, $k);
2105 703 return $self->read_statement($tok, $last_op);
2106 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '$') && (is_symbol($tok->[1]))) {
Condition66%4/6
scalar @$tok > 1 and $tok->[0] eq "\$" and is_symbol($tok->[1])
!ll&&!rl&&r
1898840
scalar @$tok > 1 and $tok->[0] eq "\$"
!ll&&!rl&&r
0189884
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "\$" and is_symbol($tok->[1])
scalar @$tok > 1 $tok->[0] eq "\$" is_symbol($tok->[1])
Truth table50%2/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "\$"C= is_symbol($tok->[1])
ABCresult
0XX0
10X0
1100
1111
2107 # variable reference via $ val => $val
2108 #
2109 0 shift @$tok;
2110 0 my $sym = shift @$tok;
2111  
2112 0 my $str = $self->get_strval_or_str($sym);
2113 0 my $var = '$' . $str;
2114 0 unshift(@$tok, $var);
2115 0 return $self->read_statement($tok, $last_op);
2116 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '$') && ($tok->[1] =~ /^\$/)) {
Condition83%5/6
scalar @$tok > 1 and $tok->[0] eq "\$" and $tok->[1] =~ /^\$/
!ll&&!rl&&r
1898786
scalar @$tok > 1 and $tok->[0] eq "\$"
!ll&&!rl&&r
0189884
MC/DC66%2/3
scalar @$tok > 1 and $tok->[0] eq "\$" and $tok->[1] =~ /^\$/
scalar @$tok > 1 $tok->[0] eq "\$" $tok->[1] =~ /^\$/
Truth table75%3/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "\$"C= $tok->[1] =~ /^\$/
ABCresult
0XX0
10X0
1100
1111
2117 # variable variable via $ $var => $<string-in-var>
2118 # Attention:
2119 # - $$var[x] is ${$var[x]}
2120 # - $$var(x) is ${$var}(x)
2121 #
2122 6 shift @$tok;
2123 6 my $res = $self->read_statement($tok, '$');
2124 6 my $k = $self->setexpr('$', undef, $res);
2125  
2126 6 unshift(@$tok, $k);
2127 6 return $self->read_statement($tok, $last_op);
2128 #} elsif ((scalar @$tok > 1) && ($tok->[0] eq '#') && ($tok->[1] =~ /^(str|num)\d+$/)) {
2129 # # for re-eval: literal reference via # str/num => #str
2130 # #
2131 # shift @$tok;
2132 # my $sym = shift @$tok;
2133 #
2134 # my $var = '#' . $sym;
2135 # unshift(@$tok, $var);
2136 # return $self->read_statement($tok, $last_op);
2137 ▶ } elsif ((scalar @$tok > 3) && ($tok->[0] eq '$') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and $tok->[0] eq "\$" and $tok->[1] eq "{"
!ll&&!rl&&r
1898078
scalar @$tok > 3 and $tok->[0] eq "\$"
!ll&&!rl&&r
74182478
MC/DC66%2/3
scalar @$tok > 3 and $tok->[0] eq "\$" and $tok->[1] eq "{"
scalar @$tok > 3 $tok->[0] eq "\$" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= $tok->[0] eq "\$"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
2138 # variable variable via $ { string } => $string
2139 # variable variable via $ { func(xxx) } is also allowed
2140 #
2141 78 shift @$tok;
2142 78 shift @$tok;
2143  
2144 78 my $arglist = $self->read_block($tok, '}', undef);
2145 78 my $k;
2146 78 ▶ if (scalar @$arglist == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist == 1) { } 78 0 78
2147 78 my $res = $arglist->[0];
2148 78 ▶ if (is_strval($res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($res)) 21 57 78
2149 21 my $str = $self->{strmap}{$res};
2150 21 ▶ if (is_symbol($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_symbol($str)) 16 5 21
2151 16 my $var = '$' . $str;
2152 16 unshift(@$tok, $var);
2153 16 return $self->read_statement($tok, $last_op);
2154 }
2155 }
2156 62 $k = $self->setexpr('$', undef, $res);
2157 } else {
2158 0 $self->{warn}->('parse', "bad arglist \$ { %s }", join(' ', @$arglist));
2159 0 my $res = $self->setblk('std', $arglist);
2160 0 $k = $self->setexpr('$', undef, $res);
2161 }
2162 62 unshift(@$tok, $k);
2163 62 return $self->read_statement($tok, $last_op);
2164 ▶ } elsif ((scalar @$tok > 3) && (is_strict_variable($tok->[0]) || ($tok->[0] =~ /^#/)) && (($tok->[1] eq '[') || ($tok->[1] eq '{'))) {
Condition100%12/12
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq "[" || $tok->[1] eq "{"
!ll&&!rl&&r
2351241422
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/
!ll&&!rl&&r
741611663
is_strict_variable($tok->[0]) or $tok->[0] =~ /^#/
l!l&&r!l&&!r
1229434161
$tok->[1] eq "[" or $tok->[1] eq "{"
l!l&&r!l&&!r
42021241
MC/DC100%5/5
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq "[" || $tok->[1] eq "{"
scalar @$tok > 3 is_strict_variable($tok->[0]) $tok->[0] =~ /^#/ $tok->[1] eq "[" $tok->[1] eq "{"
Truth table87%7/8
A and B or C and D or E
A= scalar @$tok > 3B= is_strict_variable($tok->[0])C= $tok->[0] =~ /^#/D= $tok->[1] eq "["E= $tok->[1] eq "{"
ABCDEresult
0XXXX0
100XX0
11X000
101000
11X1X1
11X011
1011X1
101011
2165 # array reference via $var['string']
2166 # or: variable $GLOBALS['string'] -> $string
2167 # or: $strvar[idx] -> char
2168 #
2169 # or: $var[string] -> string
2170 # (old: php autoconverts bare string into string const which
2171 # contains the string - not always the same as the 'str' index
2172 # see: http://php.net/manual/en/language.types.array.php
2173 # see: define('const', 'val')
2174 # )
2175 #
2176 # http://php.net/manual/de/language.types.string.php
2177 # - Strings may also be accessed using braces, as in $str{42},
2178 # for the same purpose. However, this syntax is deprecated as
2179 # of php7.4 and disabled in php8. Use square brackets instead.
2180 #
2181 422 my $sym = shift @$tok;
2182  
2183 422 ▶ if (defined $last_op && ($last_op eq '::')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "::") 4 418 422
Condition100%3/3
defined $last_op and $last_op eq "::"
!ll&&!rl&&r
354644
MC/DC100%2/2
defined $last_op and $last_op eq "::"
defined $last_op $last_op eq "::"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "::"
ABresult
0X0
100
111
2184 # handle case: (class::$var)(x)
2185 4 return $sym;
2186 }
2187 418 ▶ if (defined $last_op && ($last_op eq '->')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "->") 0 418 418
Condition66%2/3
defined $last_op and $last_op eq "->"
!ll&&!rl&&r
354640
MC/DC0%0/2
defined $last_op and $last_op eq "->"
defined $last_op $last_op eq "->"
Truth table66%2/3
A and B
A= defined $last_opB= $last_op eq "->"
ABresult
0X0
100
111
2188 # handle case: ($obj->var)(x)
2189 0 return $sym;
2190 }
2191 418 my $bracket = shift @$tok;
2192 418 my $arglist;
2193  
2194 418 ▶ if ($bracket eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bracket eq '[') { } 416 2 418
2195 416 $arglist = $self->read_index_block($tok, ']', undef);
2196 } else {
2197 2 $arglist = $self->read_index_block($tok, '}', undef);
2198 }
2199 418 ▶ if (scalar @$arglist > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist > 1) 0 418 418
2200 0 $self->{warn}->('parse', "bad arglist %s [ %s ]", $sym, join(' ', @$arglist));
2201 0 unshift(@$tok, ('[', @$arglist, ']'));
2202 0 return $sym;
2203 }
2204 418 ▶ if ((scalar @$arglist == 1) && is_strval($arglist->[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$arglist == 1 and is_strval($arglist->[0])) { } 322 96 418
elsif (scalar @$arglist == 1 and is_symbol($arglist->[0])) { } 0 112 112
Condition100%3/3
scalar @$arglist == 1 and is_strval($arglist->[0])
!ll&&!rl&&r
1680322
MC/DC100%2/2
scalar @$arglist == 1 and is_strval($arglist->[0])
scalar @$arglist == 1 is_strval($arglist->[0])
Truth table100%3/3
A and B
A= scalar @$arglist == 1B= is_strval($arglist->[0])
ABresult
0X0
100
111
2205 322 my $str = $arglist->[0];
2206 322 if (0) {
2207 if ($sym =~ /^\$GLOBALS$/) {
2208 my $val = $self->get_strval($str);
2209 my $var = '$' . $val;
2210 unshift(@$tok, $var);
2211 my $res = $self->read_statement($tok, $last_op);
2212 return $res;
2213 }
2214 }
2215 ▶ } elsif ((scalar @$arglist == 1) && (is_symbol($arglist->[0]))) {
Condition66%2/3
scalar @$arglist == 1 and is_symbol($arglist->[0])
!ll&&!rl&&r
16800
MC/DC0%0/2
scalar @$arglist == 1 and is_symbol($arglist->[0])
scalar @$arglist == 1 is_symbol($arglist->[0])
Truth table66%2/3
A and B
A= scalar @$arglist == 1B= is_symbol($arglist->[0])
ABresult
0X0
100
111
2216 # bare string
2217 0 my $str = $arglist->[0];
2218 0 my $k = $self->setstr($str);
2219 0 unshift(@$tok, ($sym, '[', $k, ']'));
2220 0 my $res = $self->read_statement($tok, $last_op);
2221 0 return $res;
2222 }
2223 418 my $k = $self->setelem($sym, $arglist->[0]);
2224  
2225 # execute expr & might continue with lower prio operation
2226 #
2227 418 unshift(@$tok, $k);
2228 418 return $self->read_statement($tok, $last_op);
2229 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] =~ /^(\+|\-)$/) && ($tok->[1] eq $tok->[0])) {
Condition100%6/6
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]
!ll&&!rl&&r
1457712
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/
!ll&&!rl&&r
2145519
MC/DC100%3/3
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]
scalar @$tok > 2 $tok->[0] =~ /^(\+|\-)$/ $tok->[1] eq $tok->[0]
Truth table100%4/4
A and B and C
A= scalar @$tok > 2B= $tok->[0] =~ /^(\+|\-)$/C= $tok->[1] eq $tok->[0]
ABCresult
0XX0
10X0
1100
1111
2230 # ++$var
2231 # --$var
2232 #
2233 12 my $op = shift @$tok;
2234 12 shift @$tok;
2235  
2236 12 my $var = $self->read_statement($tok, "$op$op");
2237 12 my $k = $self->setexpr($op.$op, undef, $var);
2238  
2239 # execute expr & might continue with lower prio operation
2240 #
2241 12 unshift(@$tok, $k);
2242 12 return $self->read_statement($tok, $last_op);
2243 ▶ } elsif ((scalar @$tok > 3) && ($tok->[0] eq '.') && ($tok->[1] eq '.') && ($tok->[2] eq '.')) {
Condition44%4/9
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "." and $tok->[2] eq "."
!ll&&!rl&&r
146400
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "."
!ll&&!rl&&r
146400
scalar @$tok > 3 and $tok->[0] eq "."
!ll&&!rl&&r
7213920
MC/DC0%0/4
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "." and $tok->[2] eq "."
scalar @$tok > 3 $tok->[0] eq "." $tok->[1] eq "." $tok->[2] eq "."
Truth table40%2/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[0] eq "."C= $tok->[1] eq "."D= $tok->[2] eq "."
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2244 # ...$var
2245 #
2246 0 shift @$tok;
2247 0 shift @$tok;
2248 0 shift @$tok;
2249  
2250 0 my $var = $self->read_statement($tok, '...');
2251 0 my $k = $self->setexpr('...', undef, $var);
2252  
2253 # execute expr & might continue with lower prio operation
2254 #
2255 0 unshift(@$tok, $k);
2256 0 return $self->read_statement($tok, $last_op);
2257 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^\\$/)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^\\$/
!ll&&!rl&&r
014577
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^\\$/
scalar @$tok > 1 $tok->[0] =~ /^\\$/
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^\\$/
ABresult
0X0
100
111
2258 # \val
2259 #
2260 7 my $op = shift @$tok;
2261  
2262 7 my $val = $self->read_statement($tok, $op);
2263 7 my $k = $self->setns(undef, $val); # toplevel namespace
2264  
2265 # execute expr & might continue with lower prio operation
2266 #
2267 7 unshift(@$tok, $k);
2268 7 return $self->read_statement($tok, $last_op);
2269 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
!ll&&!rl&&r
0138968
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
scalar @$tok > 1 $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
ABresult
0X0
100
111
2270 # ~val
2271 # !val
2272 # +val
2273 # -val
2274 # new val
2275 #
2276 68 my $op = shift @$tok;
2277 68 my $val;
2278  
2279 68 ▶ if (($op eq '+') || ($op eq '-')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+' or $op eq '-') { } 8 60 68
elsif (lc $op eq 'new') { } 39 21 60
Condition100%3/3
$op eq "+" or $op eq "-"
l!l&&r!l&&!r
1760
MC/DC100%2/2
$op eq "+" or $op eq "-"
$op eq "+" $op eq "-"
Truth table100%3/3
A or B
A= $op eq "+"B= $op eq "-"
ABresult
1X1
011
000
2280 8 $val = $self->read_statement($tok, '+-');
2281 } elsif (lc($op) eq 'new') {
2282 # add optional parenthesis for 'new a' if necessary
2283 # -> with parenthesis $val is parsed as #call
2284 #
2285 39 $val = $self->read_statement($tok, $op);
2286 39 ▶ if ($val =~ /^#(str|const)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^#(str|const)/) 7 32 39
2287 7 $val = $self->setcall($self->{strmap}->{$val}, []);
2288 }
2289 } else {
2290 21 $val = $self->read_statement($tok, $op);
2291 }
2292 68 my $k = $self->setexpr($op, undef, $val);
2293  
2294 # execute expr & might continue with lower prio operation
2295 #
2296 68 unshift(@$tok, $k);
2297 68 return $self->read_statement($tok, $last_op);
2298 ▶ } elsif ((scalar @$tok > 2) && ($tok->[1] =~ /^([\.\+\-\*\/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$/i)) {
Condition66%2/3
scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
!ll&&!rl&&r
0131376
MC/DC50%1/2
scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
scalar @$tok > 2 $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
Truth table66%2/3
A and B
A= scalar @$tok > 2B= $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
ABresult
0X0
100
111
2299 # val1 . val2
2300 # val1 + val2
2301 # val1 - val2
2302 # val1 ^ val2
2303 # ...
2304 #
2305 1376 ▶ if (($tok->[1] =~ /^[<>\&\|\*\?]$/) && ($tok->[2] eq $tok->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]) 16 1360 1376
Condition100%3/3
$tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]
!ll&&!rl&&r
12916916
MC/DC100%2/2
$tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]
$tok->[1] =~ /^[<>\&\|\*\?]$/ $tok->[2] eq $tok->[1]
Truth table100%3/3
A and B
A= $tok->[1] =~ /^[<>\&\|\*\?]$/B= $tok->[2] eq $tok->[1]
ABresult
0X0
100
111
2306 # val1 << val2 (also: <<=)
2307 # val1 >> val2 (also: >>=)
2308 # val1 ** val2 (also: **=)
2309 # val1 ?? val2 (also: ??=)
2310 # val1 || val2
2311 # val1 && val2
2312 #
2313 16 my $sym = shift @$tok;
2314 16 my $op = shift @$tok;
2315 16 shift @$tok;
2316 16 unshift(@$tok, ($sym, $op.$op));
2317 # fall through
2318 }
2319 1376 ▶ if (($tok->[2] eq '=') && ($tok->[1] =~ /^([\.\+\-\*\/\^\&\|\%]|<<|>>|\*\*|\?\?)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]) 31 1345 1376
Condition100%3/3
$tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
!ll&&!rl&&r
13172831
MC/DC100%2/2
$tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
$tok->[2] eq "=" $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
Truth table100%3/3
A and B
A= $tok->[2] eq "="B= $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
ABresult
0X0
100
111
2320 # num += ...
2321 # num .= ...
2322 #
2323 31 my $sym = shift @$tok;
2324 31 my $op = shift @$tok;
2325 31 shift @$tok;
2326  
2327 # keep in_block flag for '='
2328 31 my $op2 = $self->read_statement($tok, undef);
2329  
2330 # keep precedence of $op against following expr
2331 31 my $k2 = $self->setexpr($op, $sym, $op2);
2332 31 unshift(@$tok, ($sym, '=', $k2));
2333 31 return $self->read_statement($tok, $last_op);
2334 }
2335 1345 ▶ if (($tok->[1] eq '=') && ($tok->[2] eq '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[1] eq "=" and $tok->[2] eq ">") 45 1300 1345
Condition100%3/3
$tok->[1] eq "=" and $tok->[2] eq ">"
!ll&&!rl&&r
39190945
MC/DC100%2/2
$tok->[1] eq "=" and $tok->[2] eq ">"
$tok->[1] eq "=" $tok->[2] eq ">"
Truth table100%3/3
A and B
A= $tok->[1] eq "="B= $tok->[2] eq ">"
ABresult
0X0
100
111
2336 # $expr1 =>
2337 #
2338 45 my $sym = shift @$tok;
2339 45 shift @$tok;
2340 45 shift @$tok;
2341 45 unshift(@$tok, ($sym, '=>'));
2342  
2343 45 return $self->read_statement($tok, $last_op);
2344 }
2345 1300 ▶ if (($tok->[1] =~ /^(\+|\-)$/) && ($tok->[2] eq $tok->[1]) && (is_strict_variable($tok->[0]) || ($tok->[0] =~ /^#(scope|inst)\d+$/))) {
Branch: 9 branches
BranchTrueFalseTotal
if ($tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/) { } 35 1265 1300
elsif (scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq '=' and $tok->[3] eq '=') { } 5 1260 1265
elsif (scalar @$tok > 3 and $tok->[1] eq '<' and $tok->[2] eq '=' and $tok->[3] eq '>') { } 3 1257 1260
elsif ($tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq '=') { } 20 1237 1257
elsif ($tok->[1] eq '<' and $tok->[2] eq '>') { } 0 1237 1237
elsif ($tok->[1] =~ /^[=\!]$/ and $tok->[2] eq '==') { } 0 1237 1237
elsif ($tok->[1] eq '-' and $tok->[2] eq '>') { } 52 1185 1237
elsif ($tok->[1] eq ':' and $tok->[2] eq ':') { } 41 1144 1185
elsif ($tok->[1] eq '?' and $tok->[2] eq ':') { } 3 2266 2269
Condition88%8/9
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/
!ll&&!rl&&r
1264135
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1]
!ll&&!rl&&r
11699536
is_strict_variable($tok->[0]) or $tok->[0] =~ /^#(scope|inst)\d+$/
l!l&&r!l&&!r
3501
MC/DC75%3/4
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/
$tok->[1] =~ /^(\+|\-)$/ $tok->[2] eq $tok->[1] is_strict_variable($tok->[0]) $tok->[0] =~ /^#(scope|inst)\d+$/
Truth table80%4/5
A and B and C or D
A= $tok->[1] =~ /^(\+|\-)$/B= $tok->[2] eq $tok->[1]C= is_strict_variable($tok->[0])D= $tok->[0] =~ /^#(scope|inst)\d+$/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2346 # $var++
2347 # $var--
2348 #
2349 35 my $sym = shift @$tok;
2350 35 my $op = shift @$tok;
2351 35 shift @$tok;
2352 35 unshift(@$tok, ($sym, $op.$op));
2353 # fall through
2354 ▶ } elsif ((scalar @$tok > 3) && ($tok->[1] =~ /^[=\!]$/) && ($tok->[2] eq '=') && ($tok->[3] eq '=')) {
Condition100%9/9
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=" and $tok->[3] eq "="
!ll&&!rl&&r
1244165
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "="
!ll&&!rl&&r
38486021
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/
!ll&&!rl&&r
67317881
MC/DC100%4/4
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=" and $tok->[3] eq "="
scalar @$tok > 3 $tok->[1] =~ /^[=\!]$/ $tok->[2] eq "=" $tok->[3] eq "="
Truth table100%5/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[1] =~ /^[=\!]$/C= $tok->[2] eq "="D= $tok->[3] eq "="
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2355 # val1 === val2
2356 # val1 !== val2
2357 #
2358 5 my $sym = shift @$tok;
2359 5 my $op = shift @$tok;
2360 5 shift @$tok;
2361 5 shift @$tok;
2362 5 unshift(@$tok, ($sym, $op.'=='));
2363 # fall through
2364 ▶ } elsif ((scalar @$tok > 3) && ($tok->[1] eq '<') && ($tok->[2] eq '=') && ($tok->[3] eq '>')) {
Condition100%9/9
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "=" and $tok->[3] eq ">"
!ll&&!rl&&r
125433
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "="
!ll&&!rl&&r
1223316
scalar @$tok > 3 and $tok->[1] eq "<"
!ll&&!rl&&r
67115637
MC/DC100%4/4
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "=" and $tok->[3] eq ">"
scalar @$tok > 3 $tok->[1] eq "<" $tok->[2] eq "=" $tok->[3] eq ">"
Truth table100%5/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[1] eq "<"C= $tok->[2] eq "="D= $tok->[3] eq ">"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2365 # val1 <=> val2
2366 #
2367 3 my $sym = shift @$tok;
2368 3 my $op = shift @$tok;
2369 3 shift @$tok;
2370 3 shift @$tok;
2371 3 unshift(@$tok, ($sym, '<=>'));
2372 # fall through
2373 ▶ } elsif (($tok->[1] =~ /^[=\!<>]$/) && ($tok->[2] eq '=')) {
Condition100%3/3
$tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq "="
!ll&&!rl&&r
31492320
MC/DC100%2/2
$tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq "="
$tok->[1] =~ /^[=\!<>]$/ $tok->[2] eq "="
Truth table100%3/3
A and B
A= $tok->[1] =~ /^[=\!<>]$/B= $tok->[2] eq "="
ABresult
0X0
100
111
2374 # val1 == val2
2375 # val1 != val2
2376 # val1 <= val2
2377 # val1 >= val2
2378 #
2379 20 my $sym = shift @$tok;
2380 20 my $op = shift @$tok;
2381 20 shift @$tok;
2382 20 unshift(@$tok, ($sym, $op.'='));
2383 # fall through
2384 ▶ } elsif (($tok->[1] eq '<') && ($tok->[2] eq '>')) {
Condition66%2/3
$tok->[1] eq "<" and $tok->[2] eq ">"
!ll&&!rl&&r
1206310
MC/DC0%0/2
$tok->[1] eq "<" and $tok->[2] eq ">"
$tok->[1] eq "<" $tok->[2] eq ">"
Truth table66%2/3
A and B
A= $tok->[1] eq "<"B= $tok->[2] eq ">"
ABresult
0X0
100
111
2385 # val1 <> val2 (diamond operator work as !=)
2386 #
2387 0 my $sym = shift @$tok;
2388 0 my $op = shift @$tok;
2389 0 shift @$tok;
2390 0 unshift(@$tok, ($sym, '!='));
2391 # fall through
2392 ▶ } elsif (($tok->[1] =~ /^[=\!]$/) && ($tok->[2] eq '==')) { # TODO: does this occur?
Condition66%2/3
$tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=="
!ll&&!rl&&r
3478900
MC/DC0%0/2
$tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=="
$tok->[1] =~ /^[=\!]$/ $tok->[2] eq "=="
Truth table66%2/3
A and B
A= $tok->[1] =~ /^[=\!]$/B= $tok->[2] eq "=="
ABresult
0X0
100
111
2393 # val1 === val2
2394 # val1 !== val2
2395 #
2396 0 my $sym = shift @$tok;
2397 0 my $op = shift @$tok;
2398 0 shift @$tok;
2399 0 unshift(@$tok, ($sym, $op.'=='));
2400 # fall through
2401 ▶ } elsif (($tok->[1] eq '-') && ($tok->[2] eq '>')) {
Condition100%3/3
$tok->[1] eq "-" and $tok->[2] eq ">"
!ll&&!rl&&r
1181452
MC/DC100%2/2
$tok->[1] eq "-" and $tok->[2] eq ">"
$tok->[1] eq "-" $tok->[2] eq ">"
Truth table100%3/3
A and B
A= $tok->[1] eq "-"B= $tok->[2] eq ">"
ABresult
0X0
100
111
2402 # $obj -> member
2403 #
2404 52 my $sym = shift @$tok;
2405 52 shift @$tok;
2406 52 shift @$tok;
2407 52 unshift(@$tok, ($sym, '->')); # for operator precedence
2408 # fall through
2409 ▶ } elsif (($tok->[1] eq ':') && ($tok->[2] eq ':')) {
Condition66%2/3
$tok->[1] eq ":" and $tok->[2] eq ":"
!ll&&!rl&&r
1144041
MC/DC50%1/2
$tok->[1] eq ":" and $tok->[2] eq ":"
$tok->[1] eq ":" $tok->[2] eq ":"
Truth table66%2/3
A and B
A= $tok->[1] eq ":"B= $tok->[2] eq ":"
ABresult
0X0
100
111
2410 # class :: elem
2411 #
2412 41 my $sym = shift @$tok;
2413 41 shift @$tok;
2414 41 shift @$tok;
2415 41 unshift(@$tok, ($sym, '::'));
2416 # fall through
2417 ▶ } elsif (($tok->[1] eq '?') && ($tok->[2] eq ':')) {
Condition100%3/3
$tok->[1] eq "?" and $tok->[2] eq ":"
!ll&&!rl&&r
1125163
MC/DC100%2/2
$tok->[1] eq "?" and $tok->[2] eq ":"
$tok->[1] eq "?" $tok->[2] eq ":"
Truth table100%3/3
A and B
A= $tok->[1] eq "?"B= $tok->[2] eq ":"
ABresult
0X0
100
111
2418 # ternary: $expr1 ?: $expr3
2419 #
2420 3 my $sym = shift @$tok;
2421 3 shift @$tok;
2422 3 shift @$tok;
2423 3 unshift(@$tok, ($sym, '?:'));
2424 # fall through
2425 }
2426 # remaining binary ops
2427 # variable assignment
2428 #
2429 1300 my $sym = shift @$tok;
2430 1300 my $op = shift @$tok;
2431 1300 my $op1;
2432 1300 $op = lc($op);
2433  
2434 1300 ▶ if (($op eq '->') || ($op eq '::') || ($op eq '\\')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '->' or $op eq '::' or $op eq '\\') { } 103 1197 1300
Condition100%6/6
$op eq "->" or $op eq "::" or $op eq "\\"
l!l&&r!l&&!r
9491197
$op eq "->" or $op eq "::"
l!l&&r!l&&!r
52421206
MC/DC100%3/3
$op eq "->" or $op eq "::" or $op eq "\\"
$op eq "->" $op eq "::" $op eq "\\"
Truth table100%4/4
A or B or C
A= $op eq "->"B= $op eq "::"C= $op eq "\\"
ABCresult
1XX1
01X1
0011
0000
2435 103 $op1 = $sym; # don't evaluate lefthand side variable
2436 } else {
2437 1197 $op1 = $self->read_statement([$sym], undef);
2438 }
2439 1300 ▶ if (defined $last_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op) 176 1124 1300
2440 176 ▶ unless (exists $op_prio{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $op_prio{$op}) 0 176 176
2441 0 $self->{warn}->('parse', "missing op_prio(%s) [last %s]", $op, $last_op);
2442 }
2443 176 ▶ unless (exists $op_prio{$last_op}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $op_prio{$last_op}) 0 176 176
2444 0 $self->{warn}->('parse', "op_prio(%s) [op %s]", $last_op, $op);
2445 }
2446 176 ▶ $self->{debug}->('parse', "SYM $sym OP %s LAST %s", $op, $last_op) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 176 176
2447 176 ▶ if ($op_prio{$op} >= $op_prio{$last_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op_prio{$op} >= $op_prio{$last_op}) 66 110 176
2448 # - for right associative ops like '=' continue to parse left-hand side.
2449 # - but for identical ops like '$a=$b=1' parse right-hand side first.
2450 # - there is a special case for unary op and '=' ('!$x=2' is same as '!($x=2)')
2451 #
2452 66 ▶ if (($op ne $last_op) || !exists $op_right{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne $last_op or not exists $op_right{$op}) 62 4 66
Condition100%3/3
$op ne $last_op or not exists $op_right{$op}
l!l&&r!l&&!r
27354
MC/DC100%2/2
$op ne $last_op or not exists $op_right{$op}
$op ne $last_op not exists $op_right{$op}
Truth table100%3/3
A or not(B)
A= $op ne $last_opB= not exists $op_right{$op}
ABresult
1X1
011
000
2453 62 ▶ unless (($op eq '=') && (exists $op_unary{$last_op} || !exists $op_right{$last_op})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}) 58 4 62
Condition100%6/6
$op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}
!ll&&!rl&&r
46124
exists $op_unary{$last_op} or not exists $op_right{$last_op}
l!l&&r!l&&!r
3112
MC/DC100%3/3
$op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}
$op eq "=" exists $op_unary{$last_op} not exists $op_right{$last_op}
Truth table100%4/4
A and B or not(C)
A= $op eq "="B= exists $op_unary{$last_op}C= not exists $op_right{$last_op}
ABCresult
0XX0
1000
11X1
1011
2454 58 ▶ $self->{log}->('parse', "curr %s %s has higher/equal prio than last %s", $op1, $op, $last_op) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 58 58
2455 58 unshift(@$tok, $op);
2456 58 return $op1;
2457 }
2458 }
2459 }
2460 }
2461 1242 my $k;
2462 1242 ▶ if ($op eq '?') {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '?') { } 15 1227 1242
elsif ($op eq '->') { } 52 1175 1227
elsif ($op eq '::') { } 41 1134 1175
elsif ($op eq '\\') { } 5 1129 1134
elsif ($op eq '++' or $op eq '--') { } 35 1094 1129
2463 # ternary: $op1 ? $expr2 : $expr3
2464 #
2465 15 my $expr2 = $self->read_statement($tok, $op);
2466 15 ▶ if ((scalar @$tok > 0) && $tok->[0] eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 15 0 15
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0015
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
2467 15 shift @$tok;
2468 } else {
2469 0 $self->{warn}->('parse', "ternary: missing : [%s ? %s]", $sym, $expr2);
2470 }
2471 15 my $expr3 = $self->read_statement($tok, ':');
2472 15 my $op2 = $self->setexpr(':', $expr2, $expr3);
2473 15 $k = $self->setexpr('?', $op1, $op2);
2474 } elsif ($op eq '->') {
2475 # $obj -> member
2476 #
2477 52 my $op2 = $self->read_statement($tok, $op);
2478  
2479 52 ▶ if (is_block($op2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($op2)) 2 50 52
2480 # $obj -> {'member'}
2481 #
2482 2 my ($type, $a) = @{$self->{strmap}->{$op2}};
2483 2 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) 2 0 2
2484 2 $op2 = $a->[0];
2485 }
2486 }
2487 52 $op2 = $self->get_strval_or_str($op2);
2488  
2489 52 $k = $self->setobj($op1, $op2);
2490 } elsif ($op eq '::') {
2491 # class :: member
2492 #
2493 41 my $class = $sym;
2494 41 ▶ unless (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($sym)) 1 40 41
2495 1 $class = $self->read_statement([$sym], undef);
2496 1 $class = $self->get_strval_or_str($class);
2497 }
2498 41 my $elem = $self->read_statement($tok, $op);
2499 41 $elem = $self->get_strval_or_str($elem);
2500  
2501 41 $k = $self->setscope($class, $elem);
2502 } elsif ($op eq '\\') {
2503 # ns/elem
2504 #
2505 5 my $op2 = $self->read_statement($tok, $op);
2506 5 $op1 = $self->get_strval_or_str($op1);
2507  
2508 5 $k = $self->setns($op1, $op2);
2509 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition100%3/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
3411094
MC/DC100%2/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table100%3/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
2510 # $var++
2511 # $var--
2512 #
2513 35 $k = $self->setexpr($op, $op1, undef);
2514 } else {
2515 1094 if (1) {
2516 # optimize long concat chains to avoid memory exhaustion
2517 # (sometimes hundreds of strings get concatted)
2518 #
2519 1094 ▶ if (($op eq '.') && is_strval($op1) && (scalar @$tok > 2) && is_strval($tok->[0]) && ($tok->[1] eq '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq ".") 0 1094 1094
Condition75%9/12
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
!ll&&!rl&&r
109400
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0])
!ll&&!rl&&r
1065290
$op eq "." and is_strval($op1) and scalar @$tok > 2
!ll&&!rl&&r
1061429
$op eq "." and is_strval($op1)
!ll&&!rl&&r
10124933
MC/DC0%0/5
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
$op eq "." is_strval($op1) scalar @$tok > 2 is_strval($tok->[0]) $tok->[1] eq "."
Truth table66%4/6
A and B and C and D and E
A= $op eq "."B= is_strval($op1)C= scalar @$tok > 2D= is_strval($tok->[0])E= $tok->[1] eq "."
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
2520 0 my @list;
2521 0 push(@list, $op1);
2522 0 ▶ while ((scalar @$tok > 2) && is_strval($tok->[0]) && ($tok->[1] eq '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq ".") 0 0 0
Condition0%0/6
scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
!ll&&!rl&&r
000
scalar @$tok > 2 and is_strval($tok->[0])
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
scalar @$tok > 2 is_strval($tok->[0]) $tok->[1] eq "."
Truth table0%0/4
A and B and C
A= scalar @$tok > 2B= is_strval($tok->[0])C= $tok->[1] eq "."
ABCresult
0XX0
10X0
1100
1111
2523 0 my $s = shift @$tok;
2524 0 shift @$tok;
2525 0 push(@list, $s);
2526 }
2527 0 $self->{warn}->('parse', "optimize concat chain here: %s", join(' ', @list));
2528 0 my $line = join('', map { $self->{strmap}->{$_} } @list);
2529 0 $op1 = $self->setstr($line);
2530 }
2531 }
2532 1094 my $op2 = $self->read_statement($tok, $op);
2533 1094 $k = $self->setexpr($op, $op1, $op2);
2534 }
2535 # execute expr & might continue with lower prio operation
2536 #
2537 1242 unshift(@$tok, $k);
2538 1242 return $self->read_statement($tok, $last_op);
2539 }
2540  
2541 13 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 13 0 13
2542 13 my $sym = shift @$tok;
2543  
2544 # some symbols are pushed back into token-stream and might be passed through here
2545 #
2546 13 ▶ $self->{log}->('parse', "skip symbol %s", $sym) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 13 13
2547 13 return $sym;
2548 }
2549 0 return;
2550 }
2551  
2552 # last_op & in_block are optional params
2553 #
2554 13835 ▶sub read_statement {
Subroutine read_statement: called CC=6 SCAR=18.1
Pod undocumented
2555 13835 my ($self, $tok, $last_op) = @_;
2556 13835 my $level = 0;
2557  
2558 13835 ▶ if (exists $self->{strmap}->{_LEVEL}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'_LEVEL'}) { } 13090 745 13835
2559 13090 $self->{strmap}->{_LEVEL} += 1;
2560 } else {
2561 745 $self->{strmap}->{_LEVEL} = 1;
2562 }
2563 13835 $level = $self->{strmap}->{_LEVEL};
2564  
2565 # show next 10 tokens to process
2566 #
2567 13835 ▶ my $tl = (scalar @$tok > 10) ? 10 : scalar @$tok;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$tok > 10 ? : 5246 8589 13835
2568 #$self->{log}->('PARSE', "[%d:%d] %s %s", $level, scalar @$tok, join(' ', @$tok[0..$tl-1]), (scalar @$tok > 10) ? '...' : '') if $self->{log};
2569 13835 ▶ my $tab = ($level <= 1) ? '' : ('....' x ($level-2)) . '... ';
Branch: 1 branch
BranchTrueFalseTotal
$level <= 1 ? : 2263 11572 13835
2570 13835 ▶ $self->{log}->('PARSE', "$tab%s%s", join(' ', @$tok[0..$tl-1]), (scalar @$tok > 10) ? ' ..['.(scalar @$tok - 10).']' : '') if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 13835 13835
scalar @$tok > 10 ? : 0 0 0
2571  
2572 13835 my $ret = $self->_read_statement($tok, $last_op);
2573 13835 $self->{strmap}->{_LEVEL} -= 1;
2574 13835 return $ret;
2575 }
2576  
2577 3658 ▶sub filter_bad_brace {
Subroutine filter_bad_brace: called CC=2 SCAR=7.6
Pod undocumented
2578 3658 my ($stmt) = @_;
2579  
2580 3658 ▶ if ($stmt =~ /^[\)\]\}]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^[\)\]\}]$/) 0 3658 3658
2581 0 $stmt = "<BAD_BRACE_$stmt>";
2582 }
2583 3658 return $stmt;
2584 }
2585  
2586 418 ▶sub read_index_block {
Subroutine read_index_block: called CC=7 SCAR=21.1
Pod undocumented
2587 418 my ($self, $tok, $close, $separator) = @_;
2588 418 my @out = ();
2589  
2590 418 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 418 418
2591  
2592 418 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 820 0 820
2593 # always resolve assignment in index to value
2594 #
2595 820 my $stmt = $self->read_statement($tok, undef);
2596  
2597 820 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 820 820
2598  
2599 820 ▶ if ($stmt eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt eq $close) { } 418 402 820
elsif (defined $separator and $stmt eq $separator) { } 0 402 402
2600 # block end
2601 #
2602 418 return \@out;
2603 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition33%1/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
40200
MC/DC0%0/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table33%1/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2604 #push(@out, $separator);
2605 } else {
2606 402 $stmt = filter_bad_brace($stmt);
2607 402 push(@out, $stmt);
2608 }
2609 }
2610 0 return \@out;
2611 }
2612  
2613 1309 ▶sub read_block {
Subroutine read_block: called CC=9 SCAR=23.2
Pod undocumented
2614 1309 my ($self, $tok, $close, $separator) = @_;
2615 1309 my @out = ();
2616 1309 my $last;
2617  
2618 1309 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1309 1309
2619  
2620 1309 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 2632 0 2632
2621 2632 my $stmt = $self->read_statement($tok, undef);
2622  
2623 2632 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2632 2632
2624  
2625 2632 ▶ if ($stmt eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt eq $close) { } 1309 1323 2632
elsif (defined $separator and $stmt eq $separator) { } 160 1163 1323
2626 # block end
2627 #
2628 1309 return \@out;
2629 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition100%3/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
283880160
MC/DC100%2/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table100%3/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2630 160 ▶ if (defined $last && ($last eq $separator)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last and $last eq $separator) 0 160 160
Condition33%1/3
defined $last and $last eq $separator
!ll&&!rl&&r
01600
MC/DC0%0/2
defined $last and $last eq $separator
defined $last $last eq $separator
Truth table33%1/3
A and B
A= defined $lastB= $last eq $separator
ABresult
0X0
100
111
2631 0 push(@out, undef); # allow empty field
2632 }
2633 #push(@out, $separator);
2634 } else {
2635 1163 $stmt = filter_bad_brace($stmt);
2636 1163 push(@out, $stmt);
2637 }
2638 1323 $last = $stmt;
2639 }
2640 0 return \@out;
2641 }
2642  
2643 # $stop is optional list of keywords which end the block
2644 # without being consumed (like 'else' for alternative if syntax)
2645 #
2646 1319 ▶sub read_code_block {
Subroutine read_code_block: called CC=9 SCAR=22.0
Pod undocumented
2647 1319 my ($self, $tok, $close, $separator, $stop) = @_;
2648 1319 my @out = ();
2649  
2650 1319 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1319 1319
2651  
2652 1319 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 3705 818 4523
2653 3705 ▶ if (defined $stop && grep { lc($tok->[0]) eq $_ } @$stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stop and grep {lc $tok->[0] eq $_;} @$stop) 8 3697 3705
Condition100%3/3
defined $stop and grep {lc $tok->[0] eq $_;} @$stop
!ll&&!rl&&r
3676218
MC/DC100%2/2
defined $stop and grep {lc $tok->[0] eq $_;} @$stop
defined $stop grep {lc $tok->[0] eq $_;} @$stop
Truth table100%3/3
A and B
A= defined $stopB= grep {lc $tok->[0] eq $_;} @$stop
ABresult
0X0
100
111
2654 8 return \@out;
2655 }
2656 3697 my $stmt = $self->read_statement($tok, undef);
2657  
2658 3697 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 3697 3697
2659  
2660 3697 ▶ if (lc($stmt) eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $stmt eq $close) { } 493 3204 3697
elsif (defined $separator and $stmt eq $separator) { } 1111 2093 3204
2661 # block end
2662 #
2663 493 return \@out;
2664 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition66%2/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
020931111
MC/DC50%1/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table66%2/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2665 #push(@out, $separator);
2666 } else {
2667 2093 $stmt = filter_bad_brace($stmt);
2668 2093 push(@out, $stmt);
2669 }
2670 }
2671 818 return \@out;
2672 }
2673  
2674 1 ▶sub tokens {
Subroutine tokens: called CC=1 SCAR=0.0
Pod undocumented
2675 1 my ($self) = @_;
2676 1 return $self->{tok};
2677 }
2678  
2679 810 ▶sub read_code {
Subroutine read_code: called CC=2 SCAR=6.9
Pod documented
2680 810 my ($self, $tok) = @_;
2681 810 my $in;
2682 810 my @out = ();
2683  
2684 810 $in = unspace_list($tok);
2685  
2686 810 my $stmts = $self->read_code_block($in, '?>', ';');
2687 810 ▶ if (scalar @$stmts == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$stmts == 1) 340 470 810
2688 340 return $stmts->[0];
2689 }
2690 470 my $k = $self->setblk('flat', $stmts);
2691 470 return $k;
2692 }
2693  
2694 3116 ▶sub map_stmt {
Subroutine map_stmt: called CC=165 SCAR=87.8
Pod undocumented
2695 3116 my ($self, $s, $cb, @params) = @_;
2696  
2697 #$self->{log}->('MAP', "$s") if $self->{log};
2698  
2699 3116 my $k = $cb->($s, @params);
2700 3116 ▶ if (defined $k) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 286 2830 3116
2701 286 return $k;
2702 }
2703 2830 my $s0 = $s;
2704  
2705 2830 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 2830 2830
elsif ($s =~ /^#null$/) { } 22 2808 2830
elsif ($s =~ /^#num\d+$/) { } 164 2644 2808
elsif ($s =~ /^#const\d+$/) { } 0 2644 2644
elsif ($s =~ /^#str\d+$/) { } 484 2160 2644
elsif ($s =~ /^#arr\d+$/) { } 133 2027 2160
elsif ($s =~ /^#fun\d+$/) { } 14 2013 2027
elsif ($s =~ /^#call\d+$/) { } 87 1926 2013
elsif ($s =~ /^#elem\d+$/) { } 50 1876 1926
elsif ($s =~ /^#expr\d+$/) { } 282 1594 1876
elsif ($s =~ /^#pfx\d+$/) { } 0 1594 1594
elsif ($s =~ /^#obj\d+$/) { } 12 1582 1594
elsif ($s =~ /^#scope\d+$/) { } 0 1582 1582
elsif ($s =~ /^#ns\d+$/) { } 0 1582 1582
elsif ($s =~ /^#inst\d+$/) { } 0 1582 1582
elsif ($s =~ /^#ref\d+$/) { } 0 1582 1582
elsif ($s =~ /^#class\d+$/) { } 0 1582 1582
elsif ($s =~ /^#trait\d+$/) { } 0 1582 1582
elsif ($s =~ /^#fh\d+$/) { } 0 1582 1582
elsif ($s =~ /^#blk\d+$/) { } 602 980 1582
elsif ($s =~ /^#stmt\d+$/) { } 529 451 980
elsif (is_variable($s)) { } 352 99 451
2706 0 $self->{warn}->('map', "undefined symbol");
2707 # keep
2708 } elsif ($s =~ /^#null$/) {
2709 # keep
2710 } elsif ($s =~ /^#num\d+$/) {
2711 # keep
2712 } elsif ($s =~ /^#const\d+$/) {
2713 # keep
2714 } elsif ($s =~ /^#str\d+$/) {
2715 # keep
2716 } elsif ($s =~ /^#arr\d+$/) {
2717 133 my $arr = $self->{strmap}{$s};
2718 133 my $keys = $arr->get_keys();
2719 133 my %newmap;
2720 133 my @newkeys = ();
2721 133 my $changed = 0;
2722  
2723 133 foreach my $k (@$keys) {
2724 236 my $val = $arr->val($k);
2725 236 ▶ if ((is_int_index($k) || is_strval($k)) && (!defined $val
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)) { } 236 0 236
Condition33%4/12
is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)
!ll&&!rl&&r
00236
is_int_index($k) or is_strval($k)
l!l&&r!l&&!r
23600
not defined $val or defined $val and is_strval($val)
l!l&&r!l&&!r
02360
defined $val and is_strval($val)
!ll&&!rl&&r
00236
MC/DC0%0/5
is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)
is_int_index($k) is_strval($k) not defined $val defined $val is_strval($val)
Truth table11%1/9
A or B and not(C) or D and E
A= is_int_index($k)B= is_strval($k)C= not defined $valD= defined $valE= is_strval($val)
ABCDEresult
00XXX0
1X00X0
1X0100
0100X0
010100
1X1XX1
1X0111
011XX1
010111
2726 || (defined $val && is_strval($val)))) {
2727 236 push(@newkeys, $k);
2728 236 $newmap{$k} = $val;
2729 } else {
2730 0 my $k2 = $k;
2731 0 ▶ unless (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_int_index($k)) 0 0 0
2732 0 $k2 = $self->map_stmt($k, $cb, @params);
2733 }
2734 0 push(@newkeys, $k2);
2735 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
2736 0 my $v = $self->map_stmt($val, $cb, @params);
2737 0 $newmap{$k2} = $v;
2738 } else {
2739 0 $newmap{$k2} = undef;
2740 }
2741 0 ▶ if (($k ne $k2) || ($val ne $newmap{$k2})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k ne $k2 or $val ne $newmap{$k2}) 0 0 0
Condition0%0/3
$k ne $k2 or $val ne $newmap{$k2}
l!l&&r!l&&!r
000
MC/DC0%0/2
$k ne $k2 or $val ne $newmap{$k2}
$k ne $k2 $val ne $newmap{$k2}
Truth table0%0/3
A or B
A= $k ne $k2B= $val ne $newmap{$k2}
ABresult
1X1
011
000
2742 0 $changed = 1;
2743 }
2744 }
2745 }
2746 133 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 0 133 133
2747 0 $arr = $self->newarr();
2748 0 foreach my $k (@newkeys) {
2749 0 $arr->set($k, $newmap{$k});
2750 }
2751 0 $s = $arr->{name};
2752 }
2753 } elsif ($s =~ /^#fun\d+$/) {
2754 14 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
2755 # no context change here
2756 } elsif ($s =~ /^#call\d+$/) {
2757 87 my ($f, $a) = @{$self->{strmap}->{$s}};
2758 87 my @args = ();
2759 87 my $arg_changed = 0;
2760 87 my $name = $f;
2761  
2762 87 ▶ if ($f =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /^#fun\d+$/) { } 0 87 87
2763 # no context change here
2764 #$name = $self->map_stmt($f, $cb, @params);
2765 } else {
2766 87 $name = $self->map_stmt($f, $cb, @params);
2767 }
2768 87 foreach my $k (@$a) {
2769 65 my $v = $self->map_stmt($k, $cb, @params);
2770 65 push(@args, $v);
2771 65 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 65 65
2772 0 $arg_changed = 1;
2773 }
2774 }
2775 87 ▶ if (($name ne $f) || $arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne $f or $arg_changed) 0 87 87
Condition33%1/3
$name ne $f or $arg_changed
l!l&&r!l&&!r
0087
MC/DC0%0/2
$name ne $f or $arg_changed
$name ne $f $arg_changed
Truth table33%1/3
A or B
A= $name ne $fB= $arg_changed
ABresult
1X1
011
000
2776 0 $s = $self->setcall($name, \@args);
2777 }
2778 } elsif ($s =~ /^#elem\d+$/) {
2779 50 my ($v, $i) = @{$self->{strmap}->{$s}};
2780 50 my $vv = $self->map_stmt($v, $cb, @params);
2781 50 my $ii = $i;
2782  
2783 50 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 50 0 50
2784 50 $ii = $self->map_stmt($i, $cb, @params);
2785 }
2786 50 ▶ if (($v ne $vv) || (defined $i && ($i ne $ii))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $vv or defined $i and $i ne $ii) 0 50 50
Condition33%2/6
$v ne $vv or defined $i and $i ne $ii
l!l&&r!l&&!r
0050
defined $i and $i ne $ii
!ll&&!rl&&r
0500
MC/DC0%0/3
$v ne $vv or defined $i and $i ne $ii
$v ne $vv defined $i $i ne $ii
Truth table25%1/4
A or B and C
A= $v ne $vvB= defined $iC= $i ne $ii
ABCresult
1XX1
0111
00X0
0100
2787 0 $s = $self->setelem($vv, $ii);
2788 }
2789 } elsif ($s =~ /^#expr\d+$/) {
2790 # if v1 missing: prefix op
2791 # if v2 missing: postfix op
2792 282 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
2793 282 my $vv1 = $v1;
2794 282 my $vv2 = $v2;
2795  
2796 282 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 276 6 282
2797 276 $vv1 = $self->map_stmt($v1, $cb, @params);
2798 }
2799 282 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 282 0 282
2800 282 $vv2 = $self->map_stmt($v2, $cb, @params);
2801 }
2802 282 ▶ if ((defined $v1 && ($v1 ne $vv1)) || (defined $v2 && ($v2 ne $vv2))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2) 10 272 282
Condition66%6/9
defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2
l!l&&r!l&&!r
100272
defined $v1 and $v1 ne $vv1
!ll&&!rl&&r
626610
defined $v2 and $v2 ne $vv2
!ll&&!rl&&r
02720
MC/DC50%2/4
defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2
defined $v1 $v1 ne $vv1 defined $v2 $v2 ne $vv2
Truth table42%3/7
A and B or C and D
A= defined $v1B= $v1 ne $vv1C= defined $v2D= $v2 ne $vv2
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2803 10 $s = $self->setexpr($op, $vv1, $vv2);
2804 }
2805 } elsif ($s =~ /^#pfx\d+$/) {
2806 # keep
2807 } elsif ($s =~ /^#obj\d+$/) {
2808 12 my ($o, $m) = @{$self->{strmap}->{$s}};
2809 12 my $oo = $o;
2810 12 my $mm = $m;
2811  
2812 12 ▶ unless ($o =~ /^#call\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o =~ /^#call\d+$/) 12 0 12
2813 # not 'new'
2814 12 $oo = $self->map_stmt($o, $cb, @params);
2815 }
2816 12 ▶ unless (exists $self->{strmap}->{$m} && is_symbol($self->{strmap}->{$m})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})) 12 0 12
Condition33%1/3
exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})
!ll&&!rl&&r
1200
MC/DC0%0/2
exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})
exists $self->{"strmap"}{$m} is_symbol($self->{"strmap"}{$m})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$m}B= is_symbol($self->{"strmap"}{$m})
ABresult
0X0
100
111
2817 # not 'sym'
2818 12 $mm = $self->map_stmt($m, $cb, @params);
2819 }
2820 12 ▶ if (($o ne $oo) || ($m ne $mm)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o ne $oo or $m ne $mm) 0 12 12
Condition33%1/3
$o ne $oo or $m ne $mm
l!l&&r!l&&!r
0012
MC/DC0%0/2
$o ne $oo or $m ne $mm
$o ne $oo $m ne $mm
Truth table33%1/3
A or B
A= $o ne $ooB= $m ne $mm
ABresult
1X1
011
000
2821 0 $s = $self->setobj($oo, $mm);
2822 }
2823 } elsif ($s =~ /^#scope\d+$/) {
2824 0 my ($c, $e) = @{$self->{strmap}->{$s}};
2825 0 my $cc = $c;
2826 0 my $ee = $e;
2827  
2828 0 ▶ unless (exists $self->{strmap}->{$c} && is_symbol($self->{strmap}->{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
exists $self->{"strmap"}{$c} is_symbol($self->{"strmap"}{$c})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$c}B= is_symbol($self->{"strmap"}{$c})
ABresult
0X0
100
111
2829 # not 'class'
2830 0 $cc = $self->map_stmt($c, $cb, @params);
2831 }
2832 0 ▶ unless (exists $self->{strmap}->{$e} && is_symbol($self->{strmap}->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
exists $self->{"strmap"}{$e} is_symbol($self->{"strmap"}{$e})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$e}B= is_symbol($self->{"strmap"}{$e})
ABresult
0X0
100
111
2833 # not 'sym'
2834 0 $ee = $self->map_stmt($e, $cb, @params);
2835 }
2836 0 ▶ if (($c ne $cc) || ($e ne $ee)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne $cc or $e ne $ee) 0 0 0
Condition0%0/3
$c ne $cc or $e ne $ee
l!l&&r!l&&!r
000
MC/DC0%0/2
$c ne $cc or $e ne $ee
$c ne $cc $e ne $ee
Truth table0%0/3
A or B
A= $c ne $ccB= $e ne $ee
ABresult
1X1
011
000
2837 0 $s = $self->setscope($cc, $ee);
2838 }
2839 } elsif ($s =~ /^#ns\d+$/) {
2840 0 my ($n, $e) = @{$self->{strmap}->{$s}};
2841 0 my $nn = $n;
2842 0 my $ee = $self->map_stmt($e, $cb, @params);
2843  
2844 0 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 0 0 0
2845 # non-sym should be error
2846 0 ▶ unless (exists $self->{strmap}->{$n} && is_symbol($self->{strmap}->{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
exists $self->{"strmap"}{$n} is_symbol($self->{"strmap"}{$n})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$n}B= is_symbol($self->{"strmap"}{$n})
ABresult
0X0
100
111
2847 0 $nn = $self->map_stmt($n, $cb, @params);
2848 }
2849 }
2850 0 ▶ if ((defined $n && ($n ne $nn)) || ($e ne $ee)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n ne $nn or $e ne $ee) 0 0 0
Condition0%0/6
defined $n and $n ne $nn or $e ne $ee
l!l&&r!l&&!r
000
defined $n and $n ne $nn
!ll&&!rl&&r
000
MC/DC0%0/3
defined $n and $n ne $nn or $e ne $ee
defined $n $n ne $nn $e ne $ee
Truth table0%0/5
A and B or C
A= defined $nB= $n ne $nnC= $e ne $ee
ABCresult
11X1
0X11
1011
0X00
1000
2851 0 $s = $self->setobj($nn, $ee);
2852 }
2853 } elsif ($s =~ /^#inst\d+$/) {
2854 0 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
2855 } elsif ($s =~ /^#ref\d+$/) {
2856 0 my ($v) = @{$self->{strmap}->{$s}};
2857 } elsif ($s =~ /^#class\d+$/) {
2858 0 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
2859 # no context change here
2860 } elsif ($s =~ /^#trait\d+$/) {
2861 0 my ($t, $b) = @{$self->{strmap}->{$s}};
2862 # no context change here
2863 } elsif ($s =~ /^#fh\d+$/) {
2864 0 my $f = $self->{strmap}->{$s}{name};
2865 0 my $m = $self->{strmap}->{$s}{mode};
2866 0 my $p = $self->{strmap}->{$s}{pos};
2867 } elsif ($s =~ /^#blk\d+$/) {
2868 602 my ($type, $a) = @{$self->{strmap}->{$s}};
2869 602 my @args = ();
2870 602 my $arg_changed = 0;
2871  
2872 602 foreach my $k (@$a) {
2873 698 my $v = $self->map_stmt($k, $cb, @params);
2874 698 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) { } 93 605 698
2875 93 ▶ unless ($self->is_empty_block($v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_empty_block($v)) 18 75 93
2876 18 push(@args, $v);
2877 }
2878 93 $arg_changed = 1;
2879 } else {
2880 605 push(@args, $v);
2881 }
2882 }
2883 602 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 85 517 602
2884 85 $s = $self->setblk($type, \@args);
2885 }
2886 } elsif ($s =~ /^#stmt\d+$/) {
2887 529 my $cmd = $self->{strmap}->{$s}->[0];
2888 529 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 108 421 529
elsif ($cmd eq 'print') { } 0 421 421
elsif ($cmd eq 'namespace') { } 0 421 421
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 421 421
elsif ($cmd eq 'use') { } 0 421 421
elsif ($cmd eq 'global') { } 8 413 421
elsif ($cmd eq 'static') { } 8 405 413
elsif ($cmd eq 'const') { } 0 405 405
elsif ($cmd eq 'unset') { } 0 405 405
elsif ($cmd eq 'return') { } 386 19 405
elsif ($cmd eq 'goto') { } 0 19 19
elsif ($cmd eq 'label') { } 0 19 19
elsif ($cmd eq 'throw') { } 0 19 19
elsif ($cmd eq 'if') { } 15 4 19
elsif ($cmd eq 'while') { } 0 4 4
elsif ($cmd eq 'do') { } 0 4 4
elsif ($cmd eq 'for') { } 0 4 4
elsif ($cmd eq 'foreach') { } 4 0 4
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'case') { } 0 0 0
elsif ($cmd eq 'try') { } 0 0 0
2889 108 my $a = $self->{strmap}->{$s}->[1];
2890 108 my @args = ();
2891 108 my $arg_changed = 0;
2892  
2893 108 foreach my $k (@$a) {
2894 108 my $v = $self->map_stmt($k, $cb, @params);
2895 108 push(@args, $v);
2896 108 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 108 108
2897 0 $arg_changed = 1;
2898 }
2899 }
2900 108 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 108 108
2901 0 $s = $self->setstmt(['echo', \@args]);
2902 }
2903 } elsif ($cmd eq 'print') {
2904 0 my $arg = $self->{strmap}->{$s}->[1];
2905 0 my $v = $self->map_stmt($arg, $cb, @params);
2906  
2907 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
2908 0 $s = $self->setstmt(['print', $v]);
2909 }
2910 } elsif ($cmd eq 'namespace') {
2911 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
2912 0 my $v = $arg;
2913 0 my $block1 = $block;
2914  
2915 0 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 0 0 0
2916 0 $block1 = $self->map_stmt($block, $cb, @params);
2917 }
2918 0 ▶ if (($v ne $arg) || ($block1 ne $block)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg or $block1 ne $block) 0 0 0
Condition0%0/3
$v ne $arg or $block1 ne $block
l!l&&r!l&&!r
000
MC/DC0%0/2
$v ne $arg or $block1 ne $block
$v ne $arg $block1 ne $block
Truth table0%0/3
A or B
A= $v ne $argB= $block1 ne $block
ABresult
1X1
011
000
2919 0 $s = $self->setstmt(['namespace', $v, $block1]);
2920 }
2921 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
2922 0 my $arg = $self->{strmap}->{$s}->[1];
2923 0 my $v = $self->map_stmt($arg, $cb, @params);
2924  
2925 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
2926 0 $s = $self->setstmt([$cmd, $v]);
2927 }
2928 } elsif ($cmd eq 'use') {
2929 0 my $a = $self->{strmap}->{$s}->[1];
2930 0 my @args = ();
2931 0 my $arg_changed = 0;
2932  
2933 0 foreach my $k (@$a) {
2934 0 my $v = $self->map_stmt($k, $cb, @params);
2935 0 push(@args, $v);
2936 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2937 0 $arg_changed = 1;
2938 }
2939 }
2940 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
2941 0 $s = $self->setstmt(['use', \@args]);
2942 }
2943 } elsif ($cmd eq 'global') {
2944 8 my $a = $self->{strmap}->{$s}->[1];
2945 8 my @args = ();
2946 8 my $arg_changed = 0;
2947  
2948 8 foreach my $k (@$a) {
2949 8 my $v = $self->map_stmt($k, $cb, @params);
2950 8 push(@args, $v);
2951 8 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 8 8
2952 0 $arg_changed = 1;
2953 }
2954 }
2955 8 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 8 8
2956 0 $s = $self->setstmt(['global', \@args]);
2957 }
2958 } elsif ($cmd eq 'static') {
2959 8 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
2960 8 my @args = ();
2961 8 my $arg_changed = 0;
2962  
2963 8 foreach my $k (@$a) {
2964 8 my $v = $self->map_stmt($k, $cb, @params);
2965 8 push(@args, $v);
2966 8 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 8 8
2967 0 $arg_changed = 1;
2968 }
2969 }
2970 8 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 8 8
2971 0 $s = $self->setstmt(['static', \@args, $p]);
2972 }
2973 } elsif ($cmd eq 'const') {
2974 0 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
2975 0 my @args = ();
2976 0 my $arg_changed = 0;
2977  
2978 0 foreach my $k (@$a) {
2979 0 my $v = $self->map_stmt($k, $cb, @params);
2980 0 push(@args, $v);
2981 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2982 0 $arg_changed = 1;
2983 }
2984 }
2985 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
2986 0 $s = $self->setstmt(['const', \@args, $p]);
2987 }
2988 } elsif ($cmd eq 'unset') {
2989 0 my $a = $self->{strmap}->{$s}->[1];
2990 0 my @args = ();
2991 0 my $arg_changed = 0;
2992  
2993 0 foreach my $k (@$a) {
2994 0 my $v = $self->map_stmt($k, $cb, @params);
2995 0 push(@args, $v);
2996 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2997 0 $arg_changed = 1;
2998 }
2999 }
3000 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
3001 0 $s = $self->setstmt(['unset', \@args]);
3002 }
3003 } elsif ($cmd eq 'return') {
3004 386 my $arg = $self->{strmap}->{$s}->[1];
3005 386 my $v = $arg;
3006  
3007 386 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 386 0 386
3008 386 $v = $self->map_stmt($arg, $cb, @params);
3009 }
3010 386 ▶ if (defined $v && ($v ne $arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v ne $arg) 0 386 386
Condition33%1/3
defined $v and $v ne $arg
!ll&&!rl&&r
03860
MC/DC0%0/2
defined $v and $v ne $arg
defined $v $v ne $arg
Truth table33%1/3
A and B
A= defined $vB= $v ne $arg
ABresult
0X0
100
111
3011 0 $s = $self->setstmt(['return', $v]);
3012 }
3013 } elsif ($cmd eq 'goto') {
3014 0 my $arg = $self->{strmap}->{$s}->[1];
3015 0 my $v = $self->map_stmt($arg, $cb, @params);
3016  
3017 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3018 0 $s = $self->setstmt(['goto', $v]);
3019 }
3020 } elsif ($cmd eq 'label') {
3021 0 my $arg = $self->{strmap}->{$s}->[1];
3022 0 my $v = $self->map_stmt($arg, $cb, @params);
3023  
3024 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3025 0 $s = $self->setstmt(['label', $v]);
3026 }
3027 } elsif ($cmd eq 'throw') {
3028 0 my $arg = $self->{strmap}->{$s}->[1];
3029 0 my $v = $self->map_stmt($arg, $cb, @params);
3030  
3031 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3032 0 $s = $self->setstmt(['throw', $v]);
3033 }
3034 } elsif ($cmd eq 'if') {
3035 15 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
3036 15 my $cond1 = $self->map_stmt($cond, $cb, @params);
3037 15 my $then1 = $self->map_stmt($then, $cb, @params);
3038 15 my $else1 = $else;
3039  
3040 15 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 0 15 15
3041 0 $else1 = $self->map_stmt($else, $cb, @params);
3042 }
3043 15 ▶ if (($cond ne $cond1) || ($then ne $then1) || (defined $else && ($else ne $else1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1) 2 13 15
Condition55%5/9
$cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1
l!l&&r!l&&!r
2013
$cond ne $cond1 or $then ne $then1
l!l&&r!l&&!r
0213
defined $else and $else ne $else1
!ll&&!rl&&r
1300
MC/DC25%1/4
$cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1
$cond ne $cond1 $then ne $then1 defined $else $else ne $else1
Truth table40%2/5
A or B or C and D
A= $cond ne $cond1B= $then ne $then1C= defined $elseD= $else ne $else1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3044 2 ▶ if ($self->is_empty_block($then1) && (!defined $else || $self->is_empty_block($else1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)) { } 2 0 2
Condition33%2/6
$self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)
!ll&&!rl&&r
002
not defined $else or $self->is_empty_block($else1)
l!l&&r!l&&!r
200
MC/DC0%0/3
$self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)
$self->is_empty_block($then1) not defined $else $self->is_empty_block($else1)
Truth table25%1/4
A and not(B) or C
A= $self->is_empty_block($then1)B= not defined $elseC= $self->is_empty_block($else1)
ABCresult
0XX0
1000
11X1
1011
3045 2 $s = $cond1;
3046 } else {
3047 0 $s = $self->setstmt(['if', $cond1, $then1, $else1]);
3048 }
3049 }
3050 } elsif ($cmd eq 'while') {
3051 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3052 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3053 0 my $block1 = $self->map_stmt($block, $cb, @params);
3054  
3055 0 ▶ if (($cond ne $cond1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $block ne $block1) 0 0 0
Condition0%0/3
$cond ne $cond1 or $block ne $block1
l!l&&r!l&&!r
000
MC/DC0%0/2
$cond ne $cond1 or $block ne $block1
$cond ne $cond1 $block ne $block1
Truth table0%0/3
A or B
A= $cond ne $cond1B= $block ne $block1
ABresult
1X1
011
000
3056 0 $s = $self->setstmt(['while', $cond1, $block1]);
3057 }
3058 } elsif ($cmd eq 'do') {
3059 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3060 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3061 0 my $block1 = $self->map_stmt($block, $cb, @params);
3062  
3063 0 ▶ if (($cond ne $cond1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $block ne $block1) 0 0 0
Condition0%0/3
$cond ne $cond1 or $block ne $block1
l!l&&r!l&&!r
000
MC/DC0%0/2
$cond ne $cond1 or $block ne $block1
$cond ne $cond1 $block ne $block1
Truth table0%0/3
A or B
A= $cond ne $cond1B= $block ne $block1
ABresult
1X1
011
000
3064 0 $s = $self->setstmt(['do', $cond1, $block1]);
3065 }
3066 } elsif ($cmd eq 'for') {
3067 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
3068 0 my $pre1 = $self->map_stmt($pre, $cb, @params);
3069 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3070 0 my $post1 = $self->map_stmt($post, $cb, @params);
3071 0 my $block1 = $self->map_stmt($block, $cb, @params);
3072  
3073 0 ▶ if (($pre ne $pre1) || ($cond ne $cond1) || ($post ne $post1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1) 0 0 0
Condition0%0/9
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1
l!l&&r!l&&!r
000
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1
l!l&&r!l&&!r
000
$pre ne $pre1 or $cond ne $cond1
l!l&&r!l&&!r
000
MC/DC0%0/4
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1
$pre ne $pre1 $cond ne $cond1 $post ne $post1 $block ne $block1
Truth table0%0/5
A or B or C or D
A= $pre ne $pre1B= $cond ne $cond1C= $post ne $post1D= $block ne $block1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3074 0 $s = $self->setstmt(['for', $pre1, $cond1, $post1, $block1]);
3075 }
3076 } elsif ($cmd eq 'foreach') {
3077 4 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
3078 4 my $expr1 = $self->map_stmt($expr, $cb, @params);
3079 4 my $key1 = $key;
3080  
3081 4 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 4 0 4
3082 4 $key1 = $self->map_stmt($key, $cb, @params);
3083 }
3084 4 my $value1 = $self->map_stmt($value, $cb, @params);
3085 4 my $block1 = $self->map_stmt($block, $cb, @params);
3086  
3087 4 ▶ if (($expr ne $expr1) || (defined $key && ($key ne $key1)) || ($value ne $value1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1) 1 3 4
Condition41%5/12
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1
l!l&&r!l&&!r
013
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1
l!l&&r!l&&!r
004
$expr ne $expr1 or defined $key and $key ne $key1
l!l&&r!l&&!r
004
defined $key and $key ne $key1
!ll&&!rl&&r
040
MC/DC20%1/5
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1
$expr ne $expr1 defined $key $key ne $key1 $value ne $value1 $block ne $block1
Truth table25%2/8
A or B and C or D or E
A= $expr ne $expr1B= defined $keyC= $key ne $key1D= $value ne $value1E= $block ne $block1
ABCDEresult
1XXXX1
011XX1
00X1X1
0101X1
00X011
010011
00X000
010000
3088 1 $s = $self->setstmt(['foreach', $expr1, $key1, $value1, $block1]);
3089 }
3090 } elsif ($cmd eq 'switch') {
3091 0 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
3092 0 my $expr1 = $self->map_stmt($expr, $cb, @params);
3093 0 my @cnew = ();
3094 0 my $changed = 0;
3095  
3096 0 foreach my $e (@$cases) {
3097 0 my $c = $e->[0];
3098 0 my $b = $e->[1];
3099 0 my $c1 = $c;
3100  
3101 0 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 0 0 0
3102 0 $c1 = $self->map_stmt($c, $cb, @params);
3103 }
3104 0 my $b1 = $self->map_stmt($b, $cb, @params);
3105  
3106 0 ▶ if ((defined $c1 && ($c ne $c1)) || ($b ne $b1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c1 and $c ne $c1 or $b ne $b1) 0 0 0
Condition0%0/6
defined $c1 and $c ne $c1 or $b ne $b1
l!l&&r!l&&!r
000
defined $c1 and $c ne $c1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c1 and $c ne $c1 or $b ne $b1
defined $c1 $c ne $c1 $b ne $b1
Truth table0%0/5
A and B or C
A= defined $c1B= $c ne $c1C= $b ne $b1
ABCresult
11X1
0X11
1011
0X00
1000
3107 0 $changed = 1;
3108 }
3109 0 push (@cnew, [$c1, $b1]);
3110 }
3111 0 ▶ if (($expr ne $expr1) || $changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr ne $expr1 or $changed) 0 0 0
Condition0%0/3
$expr ne $expr1 or $changed
l!l&&r!l&&!r
000
MC/DC0%0/2
$expr ne $expr1 or $changed
$expr ne $expr1 $changed
Truth table0%0/3
A or B
A= $expr ne $expr1B= $changed
ABresult
1X1
011
000
3112 0 $s = $self->setstmt(['switch', $expr1, \@cnew]);
3113 }
3114 } elsif ($cmd eq 'case') {
3115 0 my $expr = $self->{strmap}->{$s}->[1];
3116 0 my $expr1 = $expr;
3117  
3118 0 ▶ if (!defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expr) 0 0 0
3119 0 $expr1 = $self->map_stmt($expr, $cb, @params);
3120 }
3121 0 ▶ if (defined $expr && ($expr ne $expr1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr and $expr ne $expr1) 0 0 0
Condition0%0/3
defined $expr and $expr ne $expr1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expr and $expr ne $expr1
defined $expr $expr ne $expr1
Truth table0%0/3
A and B
A= defined $exprB= $expr ne $expr1
ABresult
0X0
100
111
3122 0 $s = $self->setstmt(['case', $expr1]);
3123 }
3124 } elsif ($cmd eq 'try') {
3125 0 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
3126 0 my $try1 = $self->map_stmt($try, $cb, @params);
3127 0 my $finally1 = $finally;
3128 0 my @cnew = ();
3129 0 my $changed = 0;
3130  
3131 0 foreach my $c (@$catches) {
3132 0 my $e = $c->[0];
3133 0 my $b = $c->[1];
3134  
3135 0 my $e1 = $self->map_stmt($e, $cb, @params);
3136 0 my $b1 = $self->map_stmt($b, $cb, @params);
3137  
3138 0 ▶ if ((defined $e1 && ($e ne $e1)) || ($b ne $b1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e1 and $e ne $e1 or $b ne $b1) 0 0 0
Condition0%0/6
defined $e1 and $e ne $e1 or $b ne $b1
l!l&&r!l&&!r
000
defined $e1 and $e ne $e1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $e1 and $e ne $e1 or $b ne $b1
defined $e1 $e ne $e1 $b ne $b1
Truth table0%0/5
A and B or C
A= defined $e1B= $e ne $e1C= $b ne $b1
ABCresult
11X1
0X11
1011
0X00
1000
3139 0 $changed = 1;
3140 }
3141 0 push (@cnew, [$e1, $b1]);
3142 }
3143 0 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 0 0 0
3144 0 $finally1 = $self->map_stmt($finally, $cb, @params);
3145 }
3146 0 ▶ if (($try ne $try1) || $changed || (defined $finally && ($finally ne $finally1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try ne $try1 or $changed or defined $finally and $finally ne $finally1) 0 0 0
Condition0%0/9
$try ne $try1 or $changed or defined $finally and $finally ne $finally1
l!l&&r!l&&!r
000
$try ne $try1 or $changed
l!l&&r!l&&!r
000
defined $finally and $finally ne $finally1
!ll&&!rl&&r
000
MC/DC0%0/4
$try ne $try1 or $changed or defined $finally and $finally ne $finally1
$try ne $try1 $changed defined $finally $finally ne $finally1
Truth table0%0/5
A or B or C and D
A= $try ne $try1B= $changedC= defined $finallyD= $finally ne $finally1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3147 0 $s = $self->setstmt(['try', $try1, \@cnew, $finally1]);
3148 }
3149 }
3150 } elsif (is_variable($s)) {
3151 # keep
3152 }
3153 2830 ▶ if ($s ne $s0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne $s0) 98 2732 2830
3154 98 ▶ $self->{debug}->('map', "map %s -> %s", $s0, $s) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 98 98
3155 }
3156 2830 return $s;
3157 }
3158  
3159 1190 ▶sub escape_str {
Subroutine escape_str: called CC=2 SCAR=7.1
Pod undocumented
3160 1190 my ($s, $fmt) = @_;
3161  
3162 # escape string (keep newlines as newline like php does)
3163 # http://php.net/manual/de/language.types.string.php
3164 # - php single quoted strings suppport backslash escapes
3165 # for literal backslash & single quote.
3166 # - use single quotes to avoid string interpolation on
3167 # re-evaluation.
3168 #
3169 1190 $s =~ s/\\/\\\\/sg;
3170 1190 $s =~ s/'/\\'/sg;
3171  
3172 1190 ▶ if (exists $fmt->{escape_ctrl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{'escape_ctrl'}) { } 0 1190 1190
3173 # convert controls other than \t\r\n to "\xNN"
3174 0 $s = escape_ctrl($s, "\x00-\x08\x0b\x0c\x0e-\x1f\x7f");
3175 } else {
3176 1190 $s = "'" . $s . "'";
3177 }
3178 1190 return $s;
3179 }
3180  
3181 8748 ▶sub expand_stmt {
Subroutine expand_stmt: called CC=166 SCAR=60.3
Pod undocumented
3182 8748 my ($self, $out, $s, $fmt) = @_;
3183  
3184 #$self->{log}->('EXPAND', "$s") if $self->{log};
3185  
3186 8748 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 8748 8748
elsif ($s =~ /^#null$/) { } 30 8718 8748
elsif ($s =~ /^#num\d+$/) { } 607 8111 8718
elsif ($s =~ /^#const\d+$/) { } 23 8088 8111
elsif ($s =~ /^#str\d+$/) { } 1189 6899 8088
elsif ($s =~ /^#arr\d+$/) { } 191 6708 6899
elsif ($s =~ /^#fun\d+$/) { } 239 6469 6708
elsif ($s =~ /^#call\d+$/) { } 400 6069 6469
elsif ($s =~ /^#elem\d+$/) { } 275 5794 6069
elsif ($s =~ /^#expr\d+$/) { } 1377 4417 5794
elsif ($s =~ /^#pfx\d+$/) { } 16 4401 4417
elsif ($s =~ /^#obj\d+$/) { } 34 4367 4401
elsif ($s =~ /^#scope\d+$/) { } 4 4363 4367
elsif ($s =~ /^#ns\d+$/) { } 0 4363 4363
elsif ($s =~ /^#inst\d+$/) { } 21 4342 4363
elsif ($s =~ /^#ref\d+$/) { } 8 4334 4342
elsif ($s =~ /^#class\d+$/) { } 56 4278 4334
elsif ($s =~ /^#trait\d+$/) { } 1 4277 4278
elsif ($s =~ /^#fh\d+$/) { } 0 4277 4277
elsif ($s =~ /^#blk\d+$/) { } 1147 3130 4277
elsif ($s =~ /^#stmt\d+$/) { } 556 2574 3130
elsif (is_variable($s)) { } 1897 677 2574
3187 0 $self->{warn}->('expand', "undefined symbol");
3188 0 push(@$out, '<UNDEF>');
3189 } elsif ($s =~ /^#null$/) {
3190 30 push(@$out, 'null');
3191 } elsif ($s =~ /^#num\d+$/) {
3192 607 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 607 0 607
3193 607 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 607 0 607
3194 607 $s = $self->{strmap}->{$s};
3195 }
3196 }
3197 607 push(@$out, $s);
3198 } elsif ($s =~ /^#const\d+$/) {
3199 23 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 23 0 23
3200 23 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 23 0 23
3201 23 $s = $self->{strmap}->{$s};
3202 }
3203 }
3204 23 push(@$out, $s);
3205 } elsif ($s =~ /^#str\d+$/) {
3206 1189 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 1189 0 1189
3207 1189 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 1189 0 1189
3208 1189 $s = $self->{strmap}->{$s};
3209 1189 ▶ if (exists $fmt->{mask_eval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"mask_eval"}) 0 1189 1189
3210 # substitute 'eval' in strings on output
3211 0 $s =~ s/(^|\W)eval(\s*\()/$1$fmt->{mask_eval}$2/g;
3212 }
3213 1189 ▶ if (exists $fmt->{max_strlen} && (length($s) > $fmt->{max_strlen})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}) 0 1189 1189
Condition33%1/3
exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}
!ll&&!rl&&r
118900
MC/DC0%0/2
exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}
exists $fmt->{"max_strlen"} length $s > $fmt->{"max_strlen"}
Truth table33%1/3
A and B
A= exists $fmt->{"max_strlen"}B= length $s > $fmt->{"max_strlen"}
ABresult
0X0
100
111
3214 0 $s = substr($s, 0, $fmt->{max_strlen}-2).'..';
3215 }
3216 1189 $s = escape_str($s, $fmt);
3217 }
3218 }
3219 1189 push(@$out, $s);
3220 } elsif ($s =~ /^#arr\d+$/) {
3221 191 my $arr = $self->{strmap}{$s};
3222 191 my $keys = $arr->get_keys();
3223 191 push(@$out, 'array');
3224 191 push(@$out, '(');
3225  
3226 191 foreach my $k (@$keys) {
3227 293 my $val = $arr->val($k);
3228 293 $self->expand_stmt($out, $k, $fmt);
3229 293 push(@$out, '=>');
3230 293 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 293 0 293
3231 293 $self->expand_stmt($out, $val, $fmt);
3232 }
3233 293 push(@$out, ',');
3234 }
3235 191 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 167 24 191
3236 167 pop(@$out);
3237 }
3238 191 push(@$out, ')');
3239 } elsif ($s =~ /^#fun\d+$/) {
3240 239 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
3241  
3242 239 foreach my $k (sort grep { exists $php_modifiers{$_} } keys %$p) {
3243 25 push(@$out, $k);
3244 }
3245 239 push(@$out, 'function');
3246 239 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 213 26 239
3247 213 push(@$out, $f);
3248 }
3249 239 push(@$out, '(');
3250 239 foreach my $k (@$a) {
3251 #push(@$out, $k);
3252 104 $self->expand_stmt($out, $k, $fmt);
3253 104 push(@$out, ',');
3254 }
3255 239 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 100 139 239
3256 100 pop(@$out);
3257 }
3258 239 push(@$out, ')');
3259 239 $self->expand_stmt($out, $b, $fmt);
3260 #push(@$out, '{');
3261 #foreach my $k (@$b) {
3262 # $self->expand_stmt($out, $k, $fmt);
3263 # push(@$out, ';');
3264 #}
3265 #if (scalar @$b > 0) {
3266 # pop(@$out);
3267 #}
3268 #push(@$out, '}');
3269 } elsif ($s =~ /^#call\d+$/) {
3270 400 my ($f, $a) = @{$self->{strmap}->{$s}};
3271  
3272 400 ▶ if ($f =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /^#fun\d+$/) { } 4 396 400
3273 # anonymous function call requires braces around func
3274 4 push(@$out, '(');
3275 4 $self->expand_stmt($out, $f, $fmt);
3276 4 push(@$out, ')');
3277 } else {
3278 396 $self->expand_stmt($out, $f, $fmt);
3279 }
3280 400 push(@$out, '(');
3281 400 foreach my $k (@$a) {
3282 211 $self->expand_stmt($out, $k, $fmt);
3283 211 push(@$out, ',');
3284 }
3285 400 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 179 221 400
3286 179 pop(@$out);
3287 }
3288 400 push(@$out, ')');
3289 } elsif ($s =~ /^#elem\d+$/) {
3290 275 my ($v, $i) = @{$self->{strmap}->{$s}};
3291  
3292 275 $self->expand_stmt($out, $v, $fmt);
3293 275 push(@$out, '[');
3294 275 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 254 21 275
3295 254 $self->expand_stmt($out, $i, $fmt);
3296 }
3297 275 push(@$out, ']');
3298 } elsif ($s =~ /^#expr\d+$/) {
3299 # if v1 missing: prefix op
3300 # if v2 missing: postfix op
3301 1377 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
3302  
3303 1377 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 1325 52 1377
3304 1325 ▶ if ($v1 =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v1 =~ /^#expr\d+$/) { } 30 1295 1325
elsif ($op eq '=' and $v1 =~ /^#arr\d+$/) { } 6 1289 1295
3305 30 my ($vop, $vv1, $vv2) = @{$self->{strmap}->{$v1}};
3306 30 my $add_brace = 0;
3307 30 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 6 24 30
Condition100%3/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
6186
MC/DC100%2/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table100%3/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
3308 6 $add_brace = 1;
3309 }
3310 30 ▶ if (exists $op_unary{$vop} && ($vop ne 'new') && (is_variable($vv2) || ($vv2 =~ /^#elem\d+$/) || ($vv2 =~ /^#call\d+$/))) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/) 0 30 30
Condition16%2/12
exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
!ll&&!rl&&r
3000
exists $op_unary{$vop} and $vop ne "new"
!ll&&!rl&&r
3000
is_variable($vv2) or $vv2 =~ /^#elem\d+$/ or $vv2 =~ /^#call\d+$/
l!l&&r!l&&!r
000
is_variable($vv2) or $vv2 =~ /^#elem\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/5
exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
exists $op_unary{$vop} $vop ne "new" is_variable($vv2) $vv2 =~ /^#elem\d+$/ $vv2 =~ /^#call\d+$/
Truth table16%1/6
A and B and C or D or E
A= exists $op_unary{$vop}B= $vop ne "new"C= is_variable($vv2)D= $vv2 =~ /^#elem\d+$/E= $vv2 =~ /^#call\d+$/
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
3311 0 $add_brace = 0;
3312 }
3313 30 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 6 24 30
3314 6 push(@$out, '(');
3315 }
3316 30 $self->expand_stmt($out, $v1, $fmt);
3317 30 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 6 24 30
3318 6 push(@$out, ')');
3319 }
3320 ▶ } elsif (($op eq '=') && ($v1 =~ /^#arr\d+$/)) {
Condition100%3/3
$op eq "=" and $v1 =~ /^#arr\d+$/
!ll&&!rl&&r
20610836
MC/DC100%2/2
$op eq "=" and $v1 =~ /^#arr\d+$/
$op eq "=" $v1 =~ /^#arr\d+$/
Truth table100%3/3
A and B
A= $op eq "="B= $v1 =~ /^#arr\d+$/
ABresult
0X0
100
111
3321 # output lhs array() as list() and allow empty elems
3322 #
3323 6 my $arr = $self->{strmap}{$v1};
3324 6 my $keys = $arr->get_keys();
3325 6 my $numerical = $arr->is_numerical();
3326 6 push(@$out, 'list');
3327 6 push(@$out, '(');
3328  
3329 6 foreach my $k (@$keys) {
3330 13 my $val = $arr->val($k);
3331 13 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 12 1 13
3332 12 ▶ unless ($numerical) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($numerical) 0 12 12
3333 0 $self->expand_stmt($out, $k, $fmt);
3334 0 push(@$out, '=>');
3335 }
3336 12 $self->expand_stmt($out, $val, $fmt);
3337 }
3338 13 push(@$out, ',');
3339 }
3340 6 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 6 0 6
3341 6 pop(@$out);
3342 }
3343 6 push(@$out, ')');
3344 } else {
3345 1289 $self->expand_stmt($out, $v1, $fmt);
3346 }
3347 }
3348 1377 push(@$out, $op);
3349 1377 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 1342 35 1377
3350 1342 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 24 1318 1342
3351 24 push(@$out, '{');
3352 }
3353 1342 ▶ if ($v2 =~ /^#expr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2 =~ /^#expr\d+$/) { } 100 1242 1342
3354 100 my ($vop, $vv1, $vv2) = @{$self->{strmap}->{$v2}};
3355 100 my $add_brace = 0;
3356 100 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 8 92 100
Condition100%6/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
9028
$op ne "?" and $op ne "="
!ll&&!rl&&r
88210
MC/DC100%3/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table100%4/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
3357 8 $add_brace = 1;
3358 }
3359 100 ▶ if (exists $op_unary{$vop} && (is_variable($vv2) || ($vv2 =~ /^#elem\d+$/) || ($vv2 =~ /^#call\d+$/))) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/) 8 92 100
Condition66%6/9
exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
!ll&&!rl&&r
79138
is_variable($vv2) or $vv2 =~ /^#elem\d+$/ or $vv2 =~ /^#call\d+$/
l!l&&r!l&&!r
0813
is_variable($vv2) or $vv2 =~ /^#elem\d+$/
l!l&&r!l&&!r
0021
MC/DC50%2/4
exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
exists $op_unary{$vop} is_variable($vv2) $vv2 =~ /^#elem\d+$/ $vv2 =~ /^#call\d+$/
Truth table60%3/5
A and B or C or D
A= exists $op_unary{$vop}B= is_variable($vv2)C= $vv2 =~ /^#elem\d+$/D= $vv2 =~ /^#call\d+$/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
3360 8 $add_brace = 0;
3361 }
3362 100 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 7 93 100
3363 7 push(@$out, '(');
3364 }
3365 100 $self->expand_stmt($out, $v2, $fmt);
3366 100 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 7 93 100
3367 7 push(@$out, ')');
3368 }
3369 } else {
3370 1242 $self->expand_stmt($out, $v2, $fmt);
3371 }
3372 1342 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 24 1318 1342
3373 24 push(@$out, '}');
3374 }
3375 }
3376 } elsif ($s =~ /^#pfx\d+$/) {
3377 16 my $pfx = $self->{strmap}->{$s};
3378 16 foreach my $k (sort keys %$pfx) {
3379 16 push(@$out, $k);
3380 }
3381 } elsif ($s =~ /^#obj\d+$/) {
3382 34 my ($o, $m) = @{$self->{strmap}->{$s}};
3383  
3384 34 ▶ if ($o =~ /^#call\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /^#call\d+$/) { } 0 34 34
3385 0 push(@$out, '(');
3386 0 $self->expand_stmt($out, $o, $fmt);
3387 0 push(@$out, ')');
3388 } else {
3389 34 $self->expand_stmt($out, $o, $fmt);
3390 }
3391 34 push(@$out, '->');
3392 34 ▶ if (exists $self->{strmap}->{$m} && is_strval($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$m} and is_strval($m)) { } 0 34 34
Condition33%1/3
exists $self->{"strmap"}{$m} and is_strval($m)
!ll&&!rl&&r
3400
MC/DC0%0/2
exists $self->{"strmap"}{$m} and is_strval($m)
exists $self->{"strmap"}{$m} is_strval($m)
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$m}B= is_strval($m)
ABresult
0X0
100
111
3393 0 my $sym = $self->{strmap}->{$m};
3394 0 ▶ if (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_symbol($sym)) { } 0 0 0
3395 0 push(@$out, $sym);
3396 } else {
3397 0 $sym = escape_str($sym, $fmt);
3398  
3399 0 push(@$out, '{');
3400 0 push(@$out, $sym);
3401 0 push(@$out, '}');
3402 }
3403 } else {
3404 34 $self->expand_stmt($out, $m, $fmt);
3405 }
3406 } elsif ($s =~ /^#scope\d+$/) {
3407 4 my ($c, $e) = @{$self->{strmap}->{$s}};
3408  
3409 4 ▶ if (exists $self->{strmap}->{$c} && is_symbol($self->{strmap}->{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$c} and is_symbol($self->{'strmap'}{$c})) { } 0 4 4
Condition33%1/3
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
!ll&&!rl&&r
400
MC/DC0%0/2
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
exists $self->{"strmap"}{$c} is_symbol($self->{"strmap"}{$c})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$c}B= is_symbol($self->{"strmap"}{$c})
ABresult
0X0
100
111
3410 0 push(@$out, $self->{strmap}->{$c});
3411 } else {
3412 4 $self->expand_stmt($out, $c, $fmt);
3413 }
3414 4 push(@$out, '::');
3415 4 ▶ if (exists $self->{strmap}->{$e} && is_symbol($self->{strmap}->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$e} and is_symbol($self->{'strmap'}{$e})) { } 0 4 4
Condition33%1/3
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
!ll&&!rl&&r
400
MC/DC0%0/2
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
exists $self->{"strmap"}{$e} is_symbol($self->{"strmap"}{$e})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$e}B= is_symbol($self->{"strmap"}{$e})
ABresult
0X0
100
111
3416 0 push(@$out, $self->{strmap}->{$e});
3417 } else {
3418 4 $self->expand_stmt($out, $e, $fmt);
3419 }
3420 } elsif ($s =~ /^#ns\d+$/) {
3421 0 my ($n, $e) = @{$self->{strmap}->{$s}};
3422  
3423 0 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 0 0 0
3424 0 ▶ if (exists $self->{strmap}->{$n} && is_symbol($self->{strmap}->{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$n} and is_symbol($self->{'strmap'}{$n})) { } 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
exists $self->{"strmap"}{$n} is_symbol($self->{"strmap"}{$n})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$n}B= is_symbol($self->{"strmap"}{$n})
ABresult
0X0
100
111
3425 0 push(@$out, $self->{strmap}->{$n});
3426 } else {
3427 0 $self->expand_stmt($out, $n, $fmt);
3428 }
3429 }
3430 0 push(@$out, '\\');
3431 0 $self->expand_stmt($out, $e, $fmt);
3432 } elsif ($s =~ /^#inst\d+$/) {
3433 21 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
3434  
3435 21 push(@$out, 'new');
3436 21 $self->expand_stmt($out, $f, $fmt);
3437 } elsif ($s =~ /^#ref\d+$/) {
3438 8 my ($v) = @{$self->{strmap}->{$s}};
3439  
3440 8 push(@$out, '&');
3441 8 $self->expand_stmt($out, $v, $fmt);
3442 } elsif ($s =~ /^#class\d+$/) {
3443 56 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
3444  
3445 0 foreach my $k (sort grep { exists $php_modifiers{$_} } keys %$p) {
3446 0 push(@$out, $k);
3447 }
3448 56 push(@$out, 'class');
3449 56 push(@$out, $c);
3450  
3451 56 ▶ if (exists $p->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"parent"}) 0 56 56
3452 0 push(@$out, 'extends');
3453 0 push(@$out, $p->{parent});
3454 }
3455 56 $self->expand_stmt($out, $b, $fmt);
3456 } elsif ($s =~ /^#trait\d+$/) {
3457 1 my ($t, $b) = @{$self->{strmap}->{$s}};
3458  
3459 1 push(@$out, 'trait');
3460 1 push(@$out, $t);
3461 1 $self->expand_stmt($out, $b, $fmt);
3462 } elsif ($s =~ /^#fh\d+$/) {
3463 0 my $f = $self->{strmap}->{$s}{name};
3464 0 my $m = $self->{strmap}->{$s}{mode};
3465 0 my $p = $self->{strmap}->{$s}{pos};
3466 0 push(@$out, 'FH');
3467 0 push(@$out, '(');
3468 0 push(@$out, $f);
3469 0 push(@$out, ',');
3470 0 push(@$out, $m);
3471 0 push(@$out, ')');
3472 } elsif ($s =~ /^#blk\d+$/) {
3473 1147 my ($type, $a) = @{$self->{strmap}->{$s}};
3474 1147 ▶ if ($type eq 'expr') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'expr') { } 99 1048 1147
elsif ($type eq 'flat') { } 516 532 1048
elsif ($type eq 'case') { } 9 523 532
elsif ($type eq 'brace') { } 1 522 523
3475 99 foreach my $k (@$a) {
3476 88 $self->expand_stmt($out, $k, $fmt);
3477 88 push(@$out, ',');
3478 }
3479 99 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 84 15 99
3480 84 pop(@$out);
3481 }
3482 } elsif ($type eq 'flat') {
3483 516 foreach my $k (@$a) {
3484 1329 $self->expand_stmt($out, $k, $fmt);
3485 1329 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 1329 1329
3486 0 next; # avoid ;
3487 }
3488 1329 ▶ if (($out->[-1] ne '}') && ($out->[-1] ne ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}" and $out->[-1] ne ":") 1063 266 1329
Condition100%3/3
$out->[-1] ne "}" and $out->[-1] ne ":"
!ll&&!rl&&r
26511063
MC/DC100%2/2
$out->[-1] ne "}" and $out->[-1] ne ":"
$out->[-1] ne "}" $out->[-1] ne ":"
Truth table100%3/3
A and B
A= $out->[-1] ne "}"B= $out->[-1] ne ":"
ABresult
0X0
100
111
3489 1063 push(@$out, ';');
3490 }
3491 }
3492 516 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 444 72 516
Condition100%3/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
468444
MC/DC100%2/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table100%3/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3493 444 ▶ pop(@$out) if $fmt->{avoid_semicolon};
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->{"avoid_semicolon"} 0 444 444
3494 }
3495 } elsif ($type eq 'case') {
3496 9 foreach my $k (@$a) {
3497 9 $self->expand_stmt($out, $k, $fmt);
3498 9 push(@$out, ';');
3499 }
3500 9 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 9 0 9
3501 9 pop(@$out);
3502 }
3503 } elsif ($type eq 'brace') {
3504 1 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) { } 1 0 1
3505 1 $self->expand_stmt($out, $a->[0], $fmt);
3506 } else {
3507 0 push(@$out, '(');
3508 0 foreach my $k (@$a) {
3509 0 $self->expand_stmt($out, $k, $fmt);
3510 0 ▶ if ($out->[-1] ne ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne ")") 0 0 0
3511 0 push(@$out, ';');
3512 }
3513 }
3514 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3515 0 pop(@$out);
3516 }
3517 0 push(@$out, ')');
3518 }
3519 } else {
3520 522 push(@$out, '{');
3521 522 foreach my $k (@$a) {
3522 690 $self->expand_stmt($out, $k, $fmt);
3523 690 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 16 674 690
3524 16 next; # avoid ;
3525 }
3526 674 ▶ if (($out->[-1] ne '}') && ($out->[-1] ne ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}" and $out->[-1] ne ":") 556 118 674
Condition66%2/3
$out->[-1] ne "}" and $out->[-1] ne ":"
!ll&&!rl&&r
1180556
MC/DC50%1/2
$out->[-1] ne "}" and $out->[-1] ne ":"
$out->[-1] ne "}" $out->[-1] ne ":"
Truth table66%2/3
A and B
A= $out->[-1] ne "}"B= $out->[-1] ne ":"
ABresult
0X0
100
111
3527 556 push(@$out, ';');
3528 }
3529 }
3530 522 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 405 117 522
Condition100%3/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
1899405
MC/DC100%2/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table100%3/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3531 405 ▶ pop(@$out) if $fmt->{avoid_semicolon};
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->{"avoid_semicolon"} 0 405 405
3532 }
3533 522 push(@$out, '}');
3534 }
3535 } elsif ($s =~ /^#stmt\d+$/) {
3536 556 my $cmd = $self->{strmap}->{$s}->[0];
3537 556 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 183 373 556
elsif ($cmd eq 'print') { } 0 373 373
elsif ($cmd eq 'namespace') { } 10 363 373
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 363 363
elsif ($cmd eq 'use') { } 0 363 363
elsif ($cmd eq 'global') { } 6 357 363
elsif ($cmd eq 'static') { } 11 346 357
elsif ($cmd eq 'const') { } 9 337 346
elsif ($cmd eq 'unset') { } 5 332 337
elsif ($cmd eq 'return') { } 116 216 332
elsif ($cmd eq 'goto') { } 1 215 216
elsif ($cmd eq 'label') { } 1 214 215
elsif ($cmd eq 'throw') { } 0 214 214
elsif ($cmd eq 'if') { } 112 102 214
elsif ($cmd eq 'while') { } 20 82 102
elsif ($cmd eq 'do') { } 8 74 82
elsif ($cmd eq 'for') { } 33 41 74
elsif ($cmd eq 'foreach') { } 31 10 41
elsif ($cmd eq 'switch') { } 7 3 10
elsif ($cmd eq 'case') { } 0 3 3
elsif ($cmd eq 'try') { } 2 1 3
3538 183 my $a = $self->{strmap}->{$s}->[1];
3539 183 push(@$out, $cmd);
3540 183 foreach my $k (@$a) {
3541 186 $self->expand_stmt($out, $k, $fmt);
3542 186 push(@$out, ',');
3543 }
3544 183 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 183 0 183
3545 183 pop(@$out);
3546 }
3547 #push(@$out, ';');
3548 } elsif ($cmd eq 'print') {
3549 0 my $arg = $self->{strmap}->{$s}->[1];
3550 0 push(@$out, $cmd);
3551 0 $self->expand_stmt($out, $arg, $fmt);
3552 } elsif ($cmd eq 'namespace') {
3553 10 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
3554 10 push(@$out, $cmd);
3555 10 ▶ if ($arg ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne "") 9 1 10
3556 9 push(@$out, $arg);
3557 }
3558 10 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 2 8 10
3559 2 $self->expand_stmt($out, $block, $fmt);
3560 }
3561 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
3562 0 my $arg = $self->{strmap}->{$s}->[1];
3563 0 push(@$out, $cmd);
3564 0 $self->expand_stmt($out, $arg, $fmt);
3565 } elsif ($cmd eq 'use') {
3566 0 my $a = $self->{strmap}->{$s}->[1];
3567 0 push(@$out, $cmd);
3568 0 foreach my $k (@$a) {
3569 0 $self->expand_stmt($out, $k, $fmt);
3570 0 push(@$out, ',');
3571 }
3572 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
3573 0 pop(@$out);
3574 }
3575 } elsif ($cmd eq 'global') {
3576 6 my $a = $self->{strmap}->{$s}->[1];
3577 6 push(@$out, $cmd);
3578 6 foreach my $k (@$a) {
3579 6 $self->expand_stmt($out, $k, $fmt);
3580 6 push(@$out, ',');
3581 }
3582 6 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 6 0 6
3583 6 pop(@$out);
3584 }
3585 } elsif ($cmd eq 'static') {
3586 11 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
3587  
3588 #push(@$out, join(' ', sort keys %$p));
3589 11 push(@$out, join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd));
3590 #push(@$out, $cmd);
3591 11 foreach my $k (@$a) {
3592 11 $self->expand_stmt($out, $k, $fmt);
3593 11 push(@$out, ',');
3594 }
3595 11 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 11 0 11
3596 11 pop(@$out);
3597 }
3598 } elsif ($cmd eq 'const') {
3599 9 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
3600  
3601 #push(@$out, join(' ', sort keys %$p));
3602 9 push(@$out, join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd));
3603 #push(@$out, $cmd);
3604 9 foreach my $k (@$a) {
3605 9 $self->expand_stmt($out, $k, $fmt);
3606 9 push(@$out, ',');
3607 }
3608 9 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 9 0 9
3609 9 pop(@$out);
3610 }
3611 } elsif ($cmd eq 'unset') {
3612 5 my $a = $self->{strmap}->{$s}->[1];
3613 5 push(@$out, $cmd);
3614 5 push(@$out, '(');
3615 5 foreach my $k (@$a) {
3616 5 $self->expand_stmt($out, $k, $fmt);
3617 5 push(@$out, ',');
3618 }
3619 5 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 5 0 5
3620 5 pop(@$out);
3621 }
3622 5 push(@$out, ')');
3623 } elsif ($cmd eq 'return') {
3624 116 my $a = $self->{strmap}->{$s}->[1];
3625 116 push(@$out, $cmd);
3626 116 $self->expand_stmt($out, $a, $fmt);
3627 } elsif ($cmd eq 'goto') {
3628 1 my $a = $self->{strmap}->{$s}->[1];
3629 1 push(@$out, $cmd);
3630 1 $self->expand_stmt($out, $a, $fmt);
3631 } elsif ($cmd eq 'label') {
3632 1 my $a = $self->{strmap}->{$s}->[1];
3633 1 $self->expand_stmt($out, $a, $fmt);
3634 1 push(@$out, ':');
3635 } elsif ($cmd eq 'throw') {
3636 0 my $arg = $self->{strmap}->{$s}->[1];
3637 0 push(@$out, $cmd);
3638 0 $self->expand_stmt($out, $arg, $fmt);
3639 } elsif ($cmd eq 'if') {
3640 112 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
3641  
3642 112 push(@$out, $cmd);
3643 112 push(@$out, '(');
3644 112 $self->expand_stmt($out, $cond, $fmt);
3645 112 push(@$out, ')');
3646 112 $self->expand_stmt($out, $then, $fmt);
3647 112 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 22 90 112
3648 22 push(@$out, 'else');
3649  
3650 # remove block around 'if else'
3651 #
3652 22 ▶ my $stmts = is_block($else) ? $self->{strmap}->{$else}->[1] : [];
Branch: 1 branch
BranchTrueFalseTotal
is_block($else) ? : 22 0 22
3653 22 ▶ if ((@$stmts == 1) && ($stmts->[0] =~ /#stmt\d+$/) && ($self->{strmap}->{$stmts->[0]}->[0] eq 'if')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{'strmap'}{$stmts->[0]}[0] eq 'if') { } 7 15 22
Condition100%6/6
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{"strmap"}{$stmts->[0]}[0] eq "if"
!ll&&!rl&&r
1237
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/
!ll&&!rl&&r
11110
MC/DC100%3/3
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{"strmap"}{$stmts->[0]}[0] eq "if"
@$stmts == 1 $stmts->[0] =~ /#stmt\d+$/ $self->{"strmap"}{$stmts->[0]}[0] eq "if"
Truth table100%4/4
A and B and C
A= @$stmts == 1B= $stmts->[0] =~ /#stmt\d+$/C= $self->{"strmap"}{$stmts->[0]}[0] eq "if"
ABCresult
0XX0
10X0
1100
1111
3654 7 $self->expand_stmt($out, $stmts->[0], $fmt);
3655 } else {
3656 15 $self->expand_stmt($out, $else, $fmt);
3657 }
3658 }
3659 } elsif ($cmd eq 'while') {
3660 20 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3661  
3662 20 push(@$out, $cmd);
3663 20 push(@$out, '(');
3664 20 $self->expand_stmt($out, $cond, $fmt);
3665 20 push(@$out, ')');
3666 20 $self->expand_stmt($out, $block, $fmt);
3667 } elsif ($cmd eq 'do') {
3668 8 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3669  
3670 8 push(@$out, $cmd);
3671 8 $self->expand_stmt($out, $block, $fmt);
3672 8 push(@$out, 'while');
3673 8 push(@$out, '(');
3674 8 $self->expand_stmt($out, $cond, $fmt);
3675 8 push(@$out, ')');
3676 } elsif ($cmd eq 'for') {
3677 33 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
3678  
3679 33 push(@$out, $cmd);
3680 33 push(@$out, '(');
3681 33 $self->expand_stmt($out, $pre, $fmt);
3682 33 push(@$out, ';');
3683 33 $self->expand_stmt($out, $cond, $fmt);
3684 33 push(@$out, ';');
3685 33 $self->expand_stmt($out, $post, $fmt);
3686 33 push(@$out, ')');
3687 33 $self->expand_stmt($out, $block, $fmt);
3688 } elsif ($cmd eq 'foreach') {
3689 31 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
3690  
3691 31 push(@$out, $cmd);
3692 31 push(@$out, '(');
3693 31 $self->expand_stmt($out, $expr, $fmt);
3694 31 push(@$out, 'as');
3695 31 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 19 12 31
3696 19 $self->expand_stmt($out, $key, $fmt);
3697 19 push(@$out, '=>');
3698 }
3699 31 $self->expand_stmt($out, $value, $fmt);
3700 31 push(@$out, ')');
3701 31 $self->expand_stmt($out, $block, $fmt);
3702 } elsif ($cmd eq 'switch') {
3703 7 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
3704  
3705 7 push(@$out, $cmd);
3706 7 push(@$out, '(');
3707 7 $self->expand_stmt($out, $expr, $fmt);
3708 7 push(@$out, ')');
3709 7 push(@$out, '{');
3710 7 foreach my $e (@$cases) {
3711 9 my $c = $e->[0];
3712 9 my $b = $e->[1];
3713 9 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) { } 9 0 9
3714 9 push(@$out, 'case');
3715 9 $self->expand_stmt($out, $c, $fmt);
3716 9 push(@$out, ':');
3717 } else {
3718 0 push(@$out, 'default');
3719 0 push(@$out, ':');
3720 }
3721 9 $self->expand_stmt($out, $b, $fmt);
3722 9 push(@$out, ';');
3723 }
3724 7 push(@$out, '}');
3725 } elsif ($cmd eq 'case') {
3726 0 my $expr = $self->{strmap}->{$s}->[1];
3727 0 ▶ if (!defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $expr) { } 0 0 0
3728 0 push(@$out, 'default');
3729 0 push(@$out, ':');
3730 } else {
3731 0 push(@$out, 'case');
3732 0 $self->expand_stmt($out, $expr, $fmt);
3733 0 push(@$out, ':');
3734 }
3735 } elsif ($cmd eq 'try') {
3736 2 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
3737  
3738 2 push(@$out, $cmd);
3739 2 $self->expand_stmt($out, $try, $fmt);
3740 2 foreach my $c (@$catches) {
3741 2 my $e = $c->[0];
3742 2 my $b = $c->[1];
3743 2 push(@$out, 'catch');
3744 2 push(@$out, '(');
3745 2 $self->expand_stmt($out, $e, $fmt);
3746 2 push(@$out, ')');
3747 2 $self->expand_stmt($out, $b, $fmt);
3748 }
3749 2 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 1 1 2
3750 1 push(@$out, 'finally');
3751 1 $self->expand_stmt($out, $finally, $fmt);
3752 }
3753 } else {
3754 1 push(@$out, $cmd);
3755 }
3756 } elsif (is_variable($s)) {
3757 1897 my ($global) = global_split($s);
3758 1897 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) { } 35 1862 1897
3759 35 my ($sym) = $global =~ /^\$(.*)$/;
3760 35 push(@$out, '$GLOBALS');
3761 35 push(@$out, '[');
3762 35 push(@$out, '\'' . $sym . '\'');
3763 35 push(@$out, ']');
3764 } else {
3765 1862 my ($class, $sym) = inst_split($s);
3766 1862 ▶ if (defined $class) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $class) { } 14 1848 1862
elsif ($s eq '$') { } 4 1844 1848
elsif (not is_strict_variable($s)) { } 1 1843 1844
3767 14 push(@$out, $class);
3768 14 push(@$out, '::');
3769 14 push(@$out, $sym);
3770 } elsif ($s eq '$') {
3771 4 push(@$out, '$');
3772 4 push(@$out, '{');
3773 4 push(@$out, 'null');
3774 4 push(@$out, '}');
3775 } elsif (!is_strict_variable($s)) {
3776 1 ($sym) = $s =~ /^\$(.*)$/;
3777 1 $sym = escape_str($sym, $fmt);
3778  
3779 1 push(@$out, '$');
3780 1 push(@$out, '{');
3781 1 push(@$out, $sym);
3782 1 push(@$out, '}');
3783 } else {
3784 1843 push(@$out, $s);
3785 }
3786 }
3787 } else {
3788 677 my ($class, $sym) = method_split($s);
3789 677 ▶ if (defined $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) { } 12 665 677
3790 12 ▶ if ($class =~ /^(#inst\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^(#inst\d+)$/) { } 0 12 12
3791 0 $self->expand_stmt($out, $class, $fmt);
3792 0 push(@$out, '->');
3793 0 push(@$out, $sym);
3794 } else {
3795 12 push(@$out, $class);
3796 12 push(@$out, '::');
3797 12 push(@$out, $sym);
3798 }
3799 } else {
3800 665 push(@$out, $s);
3801 }
3802 }
3803 8748 return;
3804 }
3805  
3806 0 ▶sub expand_formatted {
Subroutine expand_formatted: not called CC=29 SCAR=67.7
Pod undocumented
3807 0 my ($out, $in, $tabs) = @_;
3808 0 my $orgtabs = $tabs;
3809 0 my $spc = "\t" x $tabs;
3810 0 my $val;
3811 my $lastval;
3812 0 my $varblk = 0;
3813  
3814 # insert newlines and indent {}-blocks
3815 #
3816 0 while (1) {
3817 0 my $val = shift @$in;
3818 0 my $isfor = 0;
3819 0 my $isswitch = 0;
3820 0 my $iscase = 0;
3821 0 my $isfunc = 0;
3822 0 my $exprblk = 0;
3823  
3824 0 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
3825 0 return;
3826 }
3827 0 ▶ if ($val eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "}") 0 0 0
3828 0 return;
3829 }
3830 0 push(@$out, $spc);
3831 0 ▶ STMT: while(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
3832 0 ▶ if ($val =~ /^(case|default)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(case|default)$/) { } 0 0 0
elsif ($val =~ /^(function|class)$/) { } 0 0 0
3833 0 $iscase = 1;
3834 } elsif ($val =~ /^(function|class)$/) {
3835 0 $isfunc = 1;
3836 }
3837 0 ▶ if ((scalar @$in > 0) && ($in->[0] =~ /^(case|default)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$in > 0 and $in->[0] =~ /^(case|default)$/) 0 0 0
Condition0%0/3
scalar @$in > 0 and $in->[0] =~ /^(case|default)$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$in > 0 and $in->[0] =~ /^(case|default)$/
scalar @$in > 0 $in->[0] =~ /^(case|default)$/
Truth table0%0/3
A and B
A= scalar @$in > 0B= $in->[0] =~ /^(case|default)$/
ABresult
0X0
100
111
3838 0 $tabs = $orgtabs;
3839 0 $spc = "\t" x $tabs;
3840 }
3841 0 push(@$out, $val);
3842 0 ▶ if (($val eq '{') && defined $lastval && ($lastval eq '$')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($val eq '{' and defined $lastval and $lastval eq '$') { } 0 0 0
elsif ($val eq '(') { } 0 0 0
elsif ($val eq '{') { } 0 0 0
elsif ($val eq ';') { } 0 0 0
elsif ($val eq ':') { } 0 0 0
Condition0%0/6
$val eq "{" and defined $lastval and $lastval eq "\$"
!ll&&!rl&&r
000
$val eq "{" and defined $lastval
!ll&&!rl&&r
000
MC/DC0%0/3
$val eq "{" and defined $lastval and $lastval eq "\$"
$val eq "{" defined $lastval $lastval eq "\$"
Truth table0%0/4
A and B and C
A= $val eq "{"B= defined $lastvalC= $lastval eq "\$"
ABCresult
0XX0
10X0
1100
1111
3843 0 $varblk++;
3844 } elsif ($val eq '(') {
3845 0 ▶ if (defined $lastval && ($lastval eq 'for')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $lastval and $lastval eq 'for') { } 0 0 0
elsif (defined $lastval and $lastval eq 'switch') { } 0 0 0
Condition0%0/3
defined $lastval and $lastval eq "for"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lastval and $lastval eq "for"
defined $lastval $lastval eq "for"
Truth table0%0/3
A and B
A= defined $lastvalB= $lastval eq "for"
ABresult
0X0
100
111
3846 0 $isfor = 1;
3847 ▶ } elsif (defined $lastval && ($lastval eq 'switch')) {
Condition0%0/3
defined $lastval and $lastval eq "switch"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lastval and $lastval eq "switch"
defined $lastval $lastval eq "switch"
Truth table0%0/3
A and B
A= defined $lastvalB= $lastval eq "switch"
ABresult
0X0
100
111
3848 0 $isswitch = 1;
3849 }
3850 0 $exprblk++;
3851 } elsif ($val eq '{') {
3852 0 push(@$out, "\n");
3853 0 ▶ if ($isswitch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isswitch) { } 0 0 0
3854 0 &expand_formatted($out, $in, $tabs);
3855 } else {
3856 0 &expand_formatted($out, $in, $tabs+1);
3857 }
3858 0 push(@$out, $spc);
3859 0 push(@$out, "}");
3860 0 ▶ if ((scalar @$in > 0) && !($in->[0] =~ /^(else|catch|finally|\))$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/) 0 0 0
Condition0%0/3
scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/
scalar @$in > 0 not $in->[0] =~ /^(else|catch|finally|\))$/
Truth table0%0/3
A and not(B)
A= scalar @$in > 0B= not $in->[0] =~ /^(else|catch|finally|\))$/
ABresult
0X0
100
111
3861 0 push(@$out, "\n");
3862 #push(@$out, "\n") if $isfunc; # blank line after function?
3863 0 last STMT;
3864 }
3865 } elsif ($val eq ';') {
3866 0 ▶ if (!$isfor) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isfor) 0 0 0
3867 0 push(@$out, "\n");
3868 0 last STMT;
3869 }
3870 } elsif ($val eq ':') {
3871 0 ▶ if ($iscase) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iscase) 0 0 0
3872 0 push(@$out, "\n");
3873 0 $iscase = 0;
3874 0 $tabs++;
3875 0 $spc .= "\t";
3876 0 last STMT;
3877 }
3878 }
3879 0 $lastval = $val;
3880 0 $val = shift @$in;
3881  
3882 0 ▶ if (defined $val && ($val eq '}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq "}") 0 0 0
Condition0%0/3
defined $val and $val eq "}"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val eq "}"
defined $val $val eq "}"
Truth table0%0/3
A and B
A= defined $valB= $val eq "}"
ABresult
0X0
100
111
3883 0 ▶ if ($varblk == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($varblk == 0) 0 0 0
3884 0 return;
3885 }
3886 0 $varblk--;
3887 }
3888 0 ▶ if (defined $val && ($val eq ')')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq ")") 0 0 0
Condition0%0/3
defined $val and $val eq ")"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val eq ")"
defined $val $val eq ")"
Truth table0%0/3
A and B
A= defined $valB= $val eq ")"
ABresult
0X0
100
111
3889 0 $exprblk--;
3890 }
3891 }
3892 }
3893 0 return;
3894 }
3895  
3896 0 ▶sub insert_blanks {
Subroutine insert_blanks: not called CC=16 SCAR=56.1
Pod undocumented
3897 0 my ($in) = @_;
3898 0 my @out = ();
3899 0 my $lastval;
3900  
3901 0 while (1) {
3902 0 my $val = shift @$in;
3903 0 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
3904 0 last;
3905 }
3906 # - no blanks in parenthesis or square brackets
3907 # - blank after semicolon or comma
3908 # - blank after most php keywords
3909 # - no blank after function calls
3910 # - no blank after unary ops
3911 # - no blank in pre/post inc/decrement
3912 # - no blank in object/scope reference
3913 #
3914 0 ▶ if (defined $lastval && ($lastval ne "\n") && ($lastval !~ /^\t*$/)) { # zero or more tabs
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/) 0 0 0
Condition0%0/6
defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/
!ll&&!rl&&r
000
defined $lastval and $lastval ne "\n"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/
defined $lastval $lastval ne "\n" not $lastval =~ /^\t*$/
Truth table0%0/4
A and B and not(C)
A= defined $lastvalB= $lastval ne "\n"C= not $lastval =~ /^\t*$/
ABCresult
0XX0
10X0
1100
1111
3915 0 ▶ if ($val !~ /^(\[|\]|\(|\)|\;|\,|\\n|->|::)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $val =~ /^(\[|\]|\(|\)|\;|\,|\\n|->|::)$/) { } 0 0 0
elsif ($val eq '(' and exists $php_keywords{lc $lastval}) { } 0 0 0
elsif ($val eq '(' and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/) { } 0 0 0
3916 0 ▶ if ($lastval !~ /^(\[|\(|\!|\~|->|::)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lastval =~ /^(\[|\(|\!|\~|->|::)$/) 0 0 0
3917 0 ▶ unless ((($val eq '++') || ($val eq '--')) && is_strict_variable($lastval)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val eq "++" || $val eq "--" and is_strict_variable($lastval)) 0 0 0
Condition0%0/6
$val eq "++" || $val eq "--" and is_strict_variable($lastval)
!ll&&!rl&&r
000
$val eq "++" or $val eq "--"
l!l&&r!l&&!r
000
MC/DC0%0/3
$val eq "++" || $val eq "--" and is_strict_variable($lastval)
$val eq "++" $val eq "--" is_strict_variable($lastval)
Truth table0%0/5
A or B and C
A= $val eq "++"B= $val eq "--"C= is_strict_variable($lastval)
ABCresult
00X0
1X00
0100
1X11
0111
3918 0 push(@out, ' ');
3919 }
3920 }
3921 ▶ } elsif (($val eq '(') && exists $php_keywords{lc($lastval)}) {
Condition0%0/3
$val eq "(" and exists $php_keywords{lc $lastval}
!ll&&!rl&&r
000
MC/DC0%0/2
$val eq "(" and exists $php_keywords{lc $lastval}
$val eq "(" exists $php_keywords{lc $lastval}
Truth table0%0/3
A and B
A= $val eq "("B= exists $php_keywords{lc $lastval}
ABresult
0X0
100
111
3922 0 ▶ unless ($lastval =~ /^(array|empty|isset|unset|list)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lastval =~ /^(array|empty|isset|unset|list)$/) 0 0 0
3923 0 push(@out, ' ');
3924 }
3925 ▶ } elsif (($val eq '(') && !is_symbol($lastval) && ($lastval !~ /^(\[|\]|\(|\))$/)) {
Condition0%0/6
$val eq "(" and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/
!ll&&!rl&&r
000
$val eq "(" and not is_symbol($lastval)
!ll&&!rl&&r
000
MC/DC0%0/3
$val eq "(" and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/
$val eq "(" not is_symbol($lastval) not $lastval =~ /^(\[|\]|\(|\))$/
Truth table0%0/4
A and not(B) and not(C)
A= $val eq "("B= not is_symbol($lastval)C= not $lastval =~ /^(\[|\]|\(|\))$/
ABCresult
0XX0
10X0
1100
1111
3926 0 push(@out, ' ');
3927 }
3928 }
3929 0 push(@out, $val);
3930 0 $lastval = $val;
3931 }
3932 0 return @out;
3933 }
3934  
3935 # convert statements to code (flags are optional)
3936 # {indent} - output indented multiline code
3937 # {unified} - unified #str/#num output
3938 # {mask_eval} - mask eval in strings with pattern
3939 # {escape_ctrl} - escape control characters in output strings
3940 # {avoid_semicolon} - avoid semicolons after braces
3941 # {max_strlen} - max length for strings in output
3942 #
3943 812 ▶sub format_stmt {
Subroutine format_stmt: called CC=7 SCAR=19.7
Pod documented
3944 812 my ($self, $line, $fmt) = @_;
3945 812 my @out = ();
3946 812 ▶ $fmt = {} unless defined $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt 810 2 812
3947  
3948 812 $self->expand_stmt(\@out, $line, $fmt);
3949  
3950 812 ▶ if (!$fmt->{avoid_semicolon} && (scalar @out > 0) && ($out[-1] ne '}') && ($out[-1] ne ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";") 184 628 812
Condition100%9/9
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";"
!ll&&!rl&&r
184444184
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}"
!ll&&!rl&&r
5179628
not $fmt->{"avoid_semicolon"} and scalar @out > 0
!ll&&!rl&&r
14807
MC/DC100%4/4
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";"
not $fmt->{"avoid_semicolon"} scalar @out > 0 $out[-1] ne "}" $out[-1] ne ";"
Truth table100%5/5
not(A) and B and C and D
A= not $fmt->{"avoid_semicolon"}B= scalar @out > 0C= $out[-1] ne "}"D= $out[-1] ne ";"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3951 184 push(@out, ';');
3952 }
3953 812 ▶ if (exists $fmt->{indent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"indent"}) 0 812 812
3954 0 my @tmp = ();
3955 0 expand_formatted(\@tmp, \@out, 0);
3956 0 return join('', insert_blanks(\@tmp));
3957 }
3958 812 return join(' ', @out);
3959 }
3960  
3961 6 ▶use constant HINT_ASSIGN => 0x10000; # variable is assigned to
Subroutine BEGIN: called CC=1 SCAR=0.0
3962 6 ▶use constant HINT_UNSET => 0x20000; # variable is unset
Subroutine BEGIN: called CC=1 SCAR=0.0
3963  
3964 # if expression in block contains an unresolvable variable, then return it
3965 #
3966 5695 ▶sub stmt_info {
Subroutine stmt_info: called CC=107 SCAR=56.0
Pod undocumented
3967 5695 my ($self, $s, $info, $hint) = @_;
3968  
3969 5695 ▶ if ($s =~ /^#blk\d+$/) {
Branch: 18 branches
BranchTrueFalseTotal
if ($s =~ /^#blk\d+$/) { } 713 4982 5695
elsif ($s =~ /^#const\d+$/) { } 12 4970 4982
elsif ($s =~ /^#arr\d+$/) { } 291 4679 4970
elsif ($s =~ /^#fun\d+$/) { } 23 4656 4679
elsif ($s =~ /^#expr\d+$/) { } 515 4141 4656
elsif ($s =~ /^#elem\d+$/) { } 174 3967 4141
elsif ($s =~ /^#obj\d+$/) { } 9 3958 3967
elsif ($s =~ /^#inst\d+$/) { } 19 3939 3958
elsif ($s =~ /^#scope\d+$/) { } 0 3939 3939
elsif ($s =~ /^#ns\d+$/) { } 0 3939 3939
elsif ($s =~ /^#ref\d+$/) { } 0 3939 3939
elsif ($s =~ /^#call\d+$/) { } 313 3626 3939
elsif ($s =~ /^#pfx\d+$/) { } 0 3626 3626
elsif ($s =~ /^#class\d+$/) { } 19 3607 3626
elsif ($s =~ /^#trait\d+$/) { } 0 3607 3607
elsif ($s =~ /^#fh\d+$/) { } 0 3607 3607
elsif ($s =~ /^#stmt\d+$/) { } 600 3007 3607
elsif (is_variable($s)) { } 798 2209 3007
3970 713 my ($type, $a) = @{$self->{strmap}->{$s}};
3971 713 foreach my $stmt (@$a) {
3972 924 $self->stmt_info($stmt, $info);
3973 }
3974 #} elsif ($s =~ /^#num\d+$/) {
3975 # my $v = $self->{strmap}->{$s};
3976 # $info->{nums}{$s} = $v;
3977 #} elsif ($s =~ /^#str\d+$/) {
3978 # my $v = $self->{strmap}->{$s};
3979 # $info->{strs}{$s} = $v;
3980 } elsif ($s =~ /^#const\d+$/) {
3981 12 $s = $self->{strmap}->{$s};
3982 12 $info->{consts}{$s} = 1;
3983 } elsif ($s =~ /^#arr\d+$/) {
3984 291 my $arr = $self->{strmap}{$s};
3985 291 my $keys = $arr->get_keys();
3986 291 my $haskey = 0;
3987  
3988 291 foreach my $k (@$keys) {
3989 472 my $val = $arr->val($k);
3990 472 ▶ unless (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_int_index($k)) 21 451 472
3991 21 $self->stmt_info($k, $info);
3992 }
3993 472 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 472 0 472
3994 472 $self->stmt_info($val, $info);
3995 472 $haskey = 1;
3996 }
3997 }
3998 291 ▶ if ($haskey) {
Branch: 1 branch
BranchTrueFalseTotal
if ($haskey) { } 269 22 291
3999 269 $info->{arrays}{$s} = 'map';
4000 } else {
4001 22 $info->{arrays}{$s} = 'array';
4002 }
4003 } elsif ($s =~ /^#fun\d+$/) {
4004 23 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
4005 23 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) { } 8 15 23
4006 8 $info->{funcs}{$f} = 1;
4007 } else {
4008 15 $info->{funcs}{$s} = 1; # anon func
4009 }
4010 } elsif ($s =~ /^#expr\d+$/) {
4011 515 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
4012 515 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 482 33 515
4013 482 ▶ if (($op eq '=') && ($v1 =~ /^#elem\d+$/) && defined $v2) {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '=' and $v1 =~ /^#elem\d+$/ and defined $v2) { } 51 431 482
elsif ($op eq '=' and defined $v2 and $v2 =~ /^#call\d+$/) { } 17 414 431
elsif ($op eq '=' and defined $v2) { } 304 110 414
elsif ($op eq '.') { } 30 80 110
elsif ($op eq '++' or $op eq '--') { } 14 66 80
Condition83%5/6
$op eq "=" and $v1 =~ /^#elem\d+$/ and defined $v2
!ll&&!rl&&r
431051
$op eq "=" and $v1 =~ /^#elem\d+$/
!ll&&!rl&&r
11032151
MC/DC66%2/3
$op eq "=" and $v1 =~ /^#elem\d+$/ and defined $v2
$op eq "=" $v1 =~ /^#elem\d+$/ defined $v2
Truth table75%3/4
A and B and C
A= $op eq "="B= $v1 =~ /^#elem\d+$/C= defined $v2
ABCresult
0XX0
10X0
1100
1111
4014 51 my ($v, $i) = @{$self->{strmap}->{$v1}};
4015  
4016 51 ▶ unless (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 34 17 51
4017 17 $self->stmt_info($v1, $info, T_ARRAY|HINT_ASSIGN);
4018 } else {
4019 34 $self->stmt_info($v1, $info, HINT_ASSIGN);
4020 }
4021 ▶ } elsif (($op eq '=') && defined $v2 && ($v2 =~ /^#call\d+$/)) {
Condition83%5/6
$op eq "=" and defined $v2 and $v2 =~ /^#call\d+$/
!ll&&!rl&&r
11030417
$op eq "=" and defined $v2
!ll&&!rl&&r
1100321
MC/DC66%2/3
$op eq "=" and defined $v2 and $v2 =~ /^#call\d+$/
$op eq "=" defined $v2 $v2 =~ /^#call\d+$/
Truth table75%3/4
A and B and C
A= $op eq "="B= defined $v2C= $v2 =~ /^#call\d+$/
ABCresult
0XX0
10X0
1100
1111
4022 17 my ($f, $a) = @{$self->{strmap}->{$v2}};
4023  
4024 17 ▶ if ($f eq 'range') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq 'range') { } 0 17 17
4025 0 $self->stmt_info($v1, $info, T_ARRAY|HINT_ASSIGN);
4026 } else {
4027 17 $self->stmt_info($v1, $info, HINT_ASSIGN);
4028 }
4029 ▶ } elsif (($op eq '=') && defined $v2) {
Condition66%2/3
$op eq "=" and defined $v2
!ll&&!rl&&r
1100304
MC/DC50%1/2
$op eq "=" and defined $v2
$op eq "=" defined $v2
Truth table66%2/3
A and B
A= $op eq "="B= defined $v2
ABresult
0X0
100
111
4030 304 $self->stmt_info($v1, $info, HINT_ASSIGN);
4031 } elsif ($op eq '.') {
4032 30 $self->stmt_info($v1, $info, T_STR);
4033 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition66%2/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
14066
MC/DC50%1/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table66%2/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
4034 14 $self->stmt_info($v1, $info, HINT_ASSIGN);
4035 } else {
4036 66 $self->stmt_info($v1, $info);
4037 }
4038 482 ▶ if ($op eq '=') {
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq '=') { } 372 110 482
elsif ($op eq '++') { } 14 96 110
elsif ($op eq '--') { } 0 96 96
4039 372 my $vb = $self->elem_base($v1);
4040 372 $info->{assigns}{$vb} = 1;
4041 } elsif ($op eq '++') {
4042 14 my $vb = $self->elem_base($v1);
4043 14 $info->{assigns}{$vb} = 1;
4044 } elsif ($op eq '--') {
4045 0 my $vb = $self->elem_base($v1);
4046 0 $info->{assigns}{$vb} = 1;
4047 }
4048 }
4049 515 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 501 14 515
4050 501 ▶ if ($op eq '.') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '.') { } 30 471 501
elsif ($op eq '++' or $op eq '--') { } 1 470 471
4051 30 $self->stmt_info($v2, $info, T_STR);
4052 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition66%2/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
01470
MC/DC50%1/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table66%2/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
4053 1 $self->stmt_info($v2, $info, HINT_ASSIGN);
4054 } else {
4055 470 $self->stmt_info($v2, $info);
4056 }
4057 501 ▶ if ($op eq '++') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '++') { } 0 501 501
elsif ($op eq '--') { } 1 500 501
4058 0 my $vb = $self->elem_base($v2);
4059 0 $info->{assigns}{$vb} = 1;
4060 } elsif ($op eq '--') {
4061 1 my $vb = $self->elem_base($v2);
4062 1 $info->{assigns}{$vb} = 1;
4063 }
4064 }
4065 } elsif ($s =~ /^#elem\d+$/) {
4066 174 my ($v, $i) = @{$self->{strmap}->{$s}};
4067 174 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 174 0 174
4068 174 my $hint_assign = 0;
4069 174 ▶ $hint_assign = HINT_ASSIGN if (defined $hint && ($hint & HINT_ASSIGN));
Branch: 1 branch
BranchTrueFalseTotal
if defined $hint and $hint & 65536 54 120 174
Condition100%3/3
defined $hint and $hint & 65536
!ll&&!rl&&r
982254
MC/DC100%2/2
defined $hint and $hint & 65536
defined $hint $hint & 65536
Truth table100%3/3
A and B
A= defined $hintB= $hint & 65536
ABresult
0X0
100
111
4070 174 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 157 17 174
4071 157 $self->stmt_info($v, $info, $hint_assign);
4072 } else {
4073 17 $self->stmt_info($v, $info, T_STR|T_ARRAY|$hint_assign);
4074 }
4075 }
4076 174 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 157 17 174
4077 157 $self->stmt_info($i, $info);
4078  
4079 # add resolvable globals
4080 #
4081 157 my $g = $self->globalvar_to_var($v, $i);
4082 157 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) 22 135 157
4083 22 $info->{globals}{$g} = 1;
4084 }
4085 }
4086 } elsif ($s =~ /^#obj\d+$/) {
4087 9 my ($o, $m) = @{$self->{strmap}->{$s}};
4088 9 ▶ if (lc($o) ne '$this') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $o ne "\$this") 4 5 9
4089 4 $self->stmt_info($o, $info);
4090 }
4091 9 ▶ if (defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m) 9 0 9
4092 9 $self->stmt_info($m, $info);
4093 }
4094 } elsif ($s =~ /^#inst\d+$/) {
4095 19 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
4096 19 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 19 0 19
4097 19 $self->stmt_info($c, $info);
4098 }
4099 } elsif ($s =~ /^#scope\d+$/) {
4100 0 my ($c, $e) = @{$self->{strmap}->{$s}};
4101 0 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
4102 0 $self->stmt_info($e, $info);
4103 }
4104 } elsif ($s =~ /^#ns\d+$/) {
4105 0 my ($n, $e) = @{$self->{strmap}->{$s}};
4106 0 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
4107 0 $self->stmt_info($e, $info);
4108 }
4109 } elsif ($s =~ /^#ref\d+$/) {
4110 0 my $v = $self->{strmap}->{$s}->[0];
4111 0 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
4112 0 $self->stmt_info($v, $info);
4113 }
4114 } elsif ($s =~ /^#call\d+$/) {
4115 313 my ($f, $a) = @{$self->{strmap}->{$s}};
4116 313 my $narg = scalar @$a;
4117 313 ▶ if (exists $info->{state} && $info->{state}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'state'} and $info->{'state'}) { } 14 299 313
Condition66%2/3
exists $info->{"state"} and $info->{"state"}
!ll&&!rl&&r
299014
MC/DC50%1/2
exists $info->{"state"} and $info->{"state"}
exists $info->{"state"} $info->{"state"}
Truth table66%2/3
A and B
A= exists $info->{"state"}B= $info->{"state"}
ABresult
0X0
100
111
4118 14 $info->{calls}{$f} = $info->{state};
4119 } else {
4120 299 $info->{calls}{$f} = 1;
4121 }
4122 313 $info->{callargs}{$f}{$narg} = 1; # track args count
4123  
4124 313 foreach my $k (@$a) {
4125 193 ▶ if ($f eq 'strlen') {
Branch: 3 branches
BranchTrueFalseTotal
if ($f eq 'strlen') { } 3 190 193
elsif ($f eq 'base64_decode') { } 2 188 190
elsif ($f eq 'gzinflate') { } 0 188 188
4126 3 $self->stmt_info($k, $info, T_STR);
4127 } elsif ($f eq 'base64_decode') {
4128 2 $self->stmt_info($k, $info, T_STR);
4129 } elsif ($f eq 'gzinflate') {
4130 0 $self->stmt_info($k, $info, T_STR);
4131 } else {
4132 188 $self->stmt_info($k, $info);
4133 }
4134 }
4135 } elsif ($s =~ /^#pfx\d+$/) {
4136 0 my $pfx = $self->{strmap}->{$s};
4137 } elsif ($s =~ /^#class\d+$/) {
4138 19 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
4139 19 $info->{classes}{$c} = 1;
4140 } elsif ($s =~ /^#trait\d+$/) {
4141 0 my ($t, $b) = @{$self->{strmap}->{$s}};
4142 0 $info->{traits}{$t} = 1;
4143 } elsif ($s =~ /^#fh\d+$/) {
4144 0 my $f = $self->{strmap}->{$s}{name};
4145 0 my $m = $self->{strmap}->{$s}{mode};
4146 0 my $p = $self->{strmap}->{$s}{pos};
4147 0 $info->{fhs}{$f} = 1;
4148 } elsif ($s =~ /^#stmt\d+$/) {
4149 600 my $cmd = $self->{strmap}->{$s}->[0];
4150 600 ▶ if ($cmd eq 'echo') {
Branch: 23 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 128 472 600
elsif ($cmd eq 'print') { } 0 472 472
elsif ($cmd eq 'namespace') { } 0 472 472
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 472 472
elsif ($cmd eq 'use') { } 0 472 472
elsif ($cmd eq 'global') { } 9 463 472
elsif ($cmd eq 'static') { } 6 457 463
elsif ($cmd eq 'const') { } 0 457 457
elsif ($cmd eq 'unset') { } 0 457 457
elsif ($cmd eq 'return') { } 276 181 457
elsif ($cmd eq 'goto') { } 0 181 181
elsif ($cmd eq 'label') { } 0 181 181
elsif ($cmd eq 'throw') { } 0 181 181
elsif ($cmd eq 'if') { } 141 40 181
elsif ($cmd eq 'while') { } 8 32 40
elsif ($cmd eq 'do') { } 1 31 32
elsif ($cmd eq 'for') { } 9 22 31
elsif ($cmd eq 'foreach') { } 12 10 22
elsif ($cmd eq 'switch') { } 8 2 10
elsif ($cmd eq 'case') { } 0 2 2
elsif ($cmd eq 'try') { } 1 1 2
elsif ($cmd eq 'break') { } 1 0 1
elsif ($cmd eq 'continue') { } 0 0 0
4151 128 my $a = $self->{strmap}->{$s}->[1];
4152 128 foreach my $k (@$a) {
4153 128 $self->stmt_info($k, $info);
4154 }
4155 128 $info->{stmts}{$s} = 1;
4156 } elsif ($cmd eq 'print') {
4157 0 my $arg = $self->{strmap}->{$s}->[1];
4158 0 $self->stmt_info($arg, $info);
4159 0 $info->{stmts}{$s} = 1;
4160 } elsif ($cmd eq 'namespace') {
4161 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
4162 0 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 0 0 0
4163 0 $self->stmt_info($block, $info);
4164 }
4165 0 $info->{stmts}{$s} = 1;
4166 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
4167 0 my $arg = $self->{strmap}->{$s}->[1];
4168 0 $info->{includes}{$arg} = 1;
4169 0 $self->stmt_info($arg, $info);
4170 } elsif ($cmd eq 'use') {
4171 0 my $a = $self->{strmap}->{$s}->[1];
4172 0 foreach my $v (@$a) {
4173 0 $self->stmt_info($v, $info);
4174 }
4175 0 $info->{stmts}{$s} = 1;
4176 } elsif ($cmd eq 'global') {
4177 9 my $a = $self->{strmap}->{$s}->[1];
4178 9 foreach my $v (@$a) {
4179 9 $info->{globals}{$v} = 1;
4180 9 $self->stmt_info($v, $info);
4181 }
4182 } elsif ($cmd eq 'static') {
4183 6 my $a = $self->{strmap}->{$s}->[1];
4184 6 foreach my $v (@$a) {
4185 6 $info->{statics}{$v} = 1;
4186 6 $self->stmt_info($v, $info);
4187 }
4188 } elsif ($cmd eq 'const') {
4189 0 my $a = $self->{strmap}->{$s}->[1];
4190 0 foreach my $v (@$a) {
4191 0 $info->{const}{$v} = 1;
4192 0 $self->stmt_info($v, $info);
4193 }
4194 } elsif ($cmd eq 'unset') {
4195 0 my $a = $self->{strmap}->{$s}->[1];
4196 0 foreach my $v (@$a) {
4197 0 $info->{assigns}{$v} = 1;
4198 0 $self->stmt_info($v, $info, HINT_ASSIGN|HINT_UNSET);
4199 }
4200 } elsif ($cmd eq 'return') {
4201 276 my $a = $self->{strmap}->{$s}->[1];
4202 276 my $old;
4203 276 ▶ $old = $info->{state} if exists $info->{state};
Branch: 1 branch
BranchTrueFalseTotal
if exists $info->{"state"} 1 275 276
4204 276 $info->{state} = 'return';
4205 276 $self->stmt_info($a, $info);
4206 276 $info->{state} = $old;
4207 276 $info->{returns}{$a} = 1;
4208 } elsif ($cmd eq 'goto') {
4209 0 my $arg = $self->{strmap}->{$s}->[1];
4210 0 $self->stmt_info($arg, $info);
4211 0 $info->{stmts}{$s} = 1;
4212 } elsif ($cmd eq 'label') {
4213 0 my $arg = $self->{strmap}->{$s}->[1];
4214 0 $self->stmt_info($arg, $info);
4215 0 $info->{stmts}{$s} = 1;
4216 } elsif ($cmd eq 'throw') {
4217 0 my $arg = $self->{strmap}->{$s}->[1];
4218 0 $self->stmt_info($arg, $info);
4219 0 $info->{stmts}{$s} = 1;
4220 } elsif ($cmd eq 'if') {
4221 141 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
4222  
4223 141 $self->stmt_info($cond, $info);
4224 141 $self->stmt_info($then, $info);
4225 141 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 25 116 141
4226 25 $self->stmt_info($else, $info);
4227 }
4228 141 $info->{stmts}{$s} = 1;
4229 } elsif ($cmd eq 'while') {
4230 8 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4231  
4232 8 $self->stmt_info($cond, $info);
4233 8 $self->stmt_info($block, $info);
4234 8 $info->{stmts}{$s} = 1;
4235 } elsif ($cmd eq 'do') {
4236 1 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4237  
4238 1 $self->stmt_info($block, $info);
4239 1 $self->stmt_info($cond, $info);
4240 1 $info->{stmts}{$s} = 1;
4241 } elsif ($cmd eq 'for') {
4242 9 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
4243  
4244 9 $self->stmt_info($pre, $info);
4245 9 $self->stmt_info($cond, $info);
4246 9 $self->stmt_info($post, $info);
4247 9 $self->stmt_info($block, $info);
4248 9 $info->{stmts}{$s} = 1;
4249 } elsif ($cmd eq 'foreach') {
4250 12 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
4251  
4252 12 $self->stmt_info($expr, $info);
4253 12 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 7 5 12
4254 7 $self->stmt_info($key, $info);
4255 7 $info->{assigns}{$key} = 1;
4256 }
4257 12 $self->stmt_info($value, $info);
4258 12 $info->{assigns}{$value} = 1;
4259 12 $self->stmt_info($block, $info);
4260 12 $info->{stmts}{$s} = 1;
4261 } elsif ($cmd eq 'switch') {
4262 8 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
4263  
4264 8 $self->stmt_info($expr, $info);
4265 8 foreach my $e (@$cases) {
4266 10 my $c = $e->[0];
4267 10 my $b = $e->[1];
4268 10 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 10 0 10
4269 10 $self->stmt_info($c, $info);
4270 }
4271 10 $self->stmt_info($b, $info);
4272 }
4273 8 $info->{stmts}{$s} = 1;
4274 } elsif ($cmd eq 'case') {
4275 0 my $expr = $self->{strmap}->{$s}->[1];
4276 0 ▶ if (defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr) 0 0 0
4277 0 $self->stmt_info($expr, $info);
4278 }
4279 } elsif ($cmd eq 'try') {
4280 1 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
4281  
4282 1 $self->stmt_info($try, $info);
4283 1 foreach my $c (@$catches) {
4284 1 my $e = $c->[0];
4285 1 my $b = $c->[1];
4286 1 $self->stmt_info($e, $info);
4287 1 $self->stmt_info($b, $info);
4288 }
4289 1 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 0 1 1
4290 0 $self->stmt_info($finally, $info);
4291 }
4292 1 $info->{stmts}{$s} = 1;
4293 } elsif ($cmd eq 'break') {
4294 1 $info->{breaks}{$s} = 1;
4295 } elsif ($cmd eq 'continue') {
4296 0 $info->{continues}{$s} = 1;
4297 }
4298 } elsif (is_variable($s)) {
4299 798 my ($global) = global_split($s);
4300 798 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) { } 48 750 798
4301 48 $info->{globals}{$global} = 1;
4302 } else {
4303 750 ▶ if (defined $hint) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hint) { } 493 257 750
4304 493 $info->{vars}{$s} |= ($hint & T_MASK);
4305 493 ▶ $info->{noassigns}{$s} |= ($hint & T_MASK) unless ($hint & HINT_ASSIGN);
Branch: 1 branch
BranchTrueFalseTotal
unless $hint & 65536 132 361 493
4306 } else {
4307 257 $info->{vars}{$s} |= 0;
4308 257 $info->{noassigns}{$s} |= 0;
4309 }
4310 }
4311 }
4312 5695 return;
4313 }
4314  
4315 0 ▶sub translate_stmt {
Subroutine translate_stmt: not called CC=202 SCAR=106.2
Pod undocumented
4316 0 my ($self, $out, $s, $info) = @_;
4317  
4318 #$self->{log}->('TRANSLATE', "$s") if $self->{log};
4319  
4320 0 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 0 0
elsif ($s =~ /^#null$/) { } 0 0 0
elsif ($s =~ /^#num\d+$/) { } 0 0 0
elsif ($s =~ /^#const\d+$/) { } 0 0 0
elsif ($s =~ /^#str\d+$/) { } 0 0 0
elsif ($s =~ /^#arr\d+$/) { } 0 0 0
elsif ($s =~ /^#fun\d+$/) { } 0 0 0
elsif ($s =~ /^#call\d+$/) { } 0 0 0
elsif ($s =~ /^#elem\d+$/) { } 0 0 0
elsif ($s =~ /^#expr\d+$/) { } 0 0 0
elsif ($s =~ /^#pfx\d+$/) { } 0 0 0
elsif ($s =~ /^#obj\d+$/) { } 0 0 0
elsif ($s =~ /^#scope\d+$/) { } 0 0 0
elsif ($s =~ /^#ns\d+$/) { } 0 0 0
elsif ($s =~ /^#inst\d+$/) { } 0 0 0
elsif ($s =~ /^#ref\d+$/) { } 0 0 0
elsif ($s =~ /^#class\d+$/) { } 0 0 0
elsif ($s =~ /^#trait\d+$/) { } 0 0 0
elsif ($s =~ /^#fh\d+$/) { } 0 0 0
elsif ($s =~ /^#blk\d+$/) { } 0 0 0
elsif ($s =~ /^#stmt\d+$/) { } 0 0 0
elsif (is_variable($s)) { } 0 0 0
4321 0 $self->{warn}->('translate', "undefined symbol");
4322 0 return;
4323 } elsif ($s =~ /^#null$/) {
4324 0 push(@$out, 'undef');
4325 } elsif ($s =~ /^#num\d+$/) {
4326 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4327 0 $self->{warn}->('translate', "num $s not found");
4328 0 return;
4329 }
4330 0 $s = $self->{strmap}->{$s};
4331 0 push(@$out, $s);
4332 } elsif ($s =~ /^#const\d+$/) {
4333 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4334 0 $self->{warn}->('translate', "bad const $s");
4335 0 return;
4336 }
4337 0 $s = $self->{strmap}->{$s};
4338 0 ▶ unless (is_symbol($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($s)) 0 0 0
4339 0 $self->{warn}->('translate', "bad const name $s");
4340 0 return;
4341 }
4342 0 push(@$out, '$'.$s); # convert to var
4343 } elsif ($s =~ /^#str\d+$/) {
4344 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4345 0 $self->{warn}->('translate', "bad str $s");
4346 0 return;
4347 }
4348 0 $s = $self->{strmap}->{$s};
4349 # escape string (keep newlines as newline like php does)
4350 #
4351 0 $s =~ s/\\/\\\\/sg;
4352 0 $s =~ s/'/\\'/sg;
4353 0 $s = '\'' . $s . '\'';
4354 0 push(@$out, $s);
4355 } elsif ($s =~ /^#arr\d+$/) {
4356 0 my $arr = $self->{strmap}{$s};
4357 0 my $keys = $arr->get_keys();
4358 0 push(@$out, '{');
4359  
4360 0 foreach my $k (@$keys) {
4361 0 my $val = $arr->val($k);
4362 0 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) { } 0 0 0
4363 0 push(@$out, $k);
4364 } else {
4365 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4366 }
4367 0 push(@$out, '=>');
4368 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
4369 0 ▶ return unless $self->translate_stmt($out, $val, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $val, $info) 0 0 0
4370 } else {
4371 0 push(@$out, 'undef');
4372 }
4373 0 push(@$out, ',');
4374 }
4375 0 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 0 0 0
4376 0 pop(@$out);
4377 }
4378 0 push(@$out, '}');
4379 } elsif ($s =~ /^#fun\d+$/) {
4380 0 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
4381  
4382 0 push(@$out, 'sub');
4383 0 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 0 0 0
4384 0 ▶ unless (is_symbol($f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($f)) 0 0 0
4385 0 $self->{warn}->('translate', "bad func name $s $f not supported");
4386 0 return;
4387 }
4388 0 $self->{warn}->('translate', "func in func $s $f not supported");
4389 0 return;
4390 #push(@$out, $f);
4391 }
4392 0 push(@$out, '{');
4393 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4394 0 push(@$out, 'my');
4395 0 push(@$out, '(');
4396 0 foreach my $k (@$a) {
4397 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4398 0 push(@$out, ',');
4399 }
4400 0 pop(@$out);
4401 0 push(@$out, ')');
4402 0 push(@$out, '=');
4403 0 push(@$out, '@_');
4404 0 push(@$out, ';');
4405 }
4406 # TODO: don't pass local func info from outside
4407 #
4408 0 ▶ if (keys %{$info->{locals}} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"locals"};} > 0) 0 0 0
4409 0 push(@$out, 'my');
4410 0 push(@$out, '(');
4411 0 foreach my $k (keys %{$info->{locals}}) {
4412 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4413 0 push(@$out, ',');
4414 }
4415 0 pop(@$out);
4416 0 push(@$out, ')');
4417 0 push(@$out, ';');
4418 }
4419 #$self->translate_stmt($out, $b, $info);
4420  
4421 0 my ($type, $c) = @{$self->{strmap}->{$b}};
4422 0 foreach my $k (@$c) {
4423 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4424 #if ($out->[-1] ne '}') {
4425 0 push(@$out, ';');
4426 #}
4427 }
4428 0 push(@$out, '}');
4429 } elsif ($s =~ /^#call\d+$/) {
4430 0 my ($f, $a) = @{$self->{strmap}->{$s}};
4431  
4432 0 ▶ unless (is_symbol($f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($f)) 0 0 0
4433 0 $self->{warn}->('translate', "call name $s $f not supported");
4434 0 return;
4435 }
4436 0 ▶ if (($f eq 'strlen') && (scalar @$a == 1)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($f eq 'strlen' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'isset' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'range' and scalar @$a == 2) { } 0 0 0
elsif ($f eq 'base64_encode' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'base64_decode' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'gzinflate' and scalar @$a == 1) { } 0 0 0
elsif ($f =~ /^(chr|ord)$/ and scalar @$a == 1) { } 0 0 0
Condition0%0/3
$f eq "strlen" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "strlen" and scalar @$a == 1
$f eq "strlen" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "strlen"B= scalar @$a == 1
ABresult
0X0
100
111
4437 0 push(@$out, 'length');
4438 ▶ } elsif (($f eq 'isset') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "isset" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "isset" and scalar @$a == 1
$f eq "isset" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "isset"B= scalar @$a == 1
ABresult
0X0
100
111
4439 0 push(@$out, 'defined');
4440 ▶ } elsif (($f eq 'range') && (scalar @$a == 2)) {
Condition0%0/3
$f eq "range" and scalar @$a == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "range" and scalar @$a == 2
$f eq "range" scalar @$a == 2
Truth table0%0/3
A and B
A= $f eq "range"B= scalar @$a == 2
ABresult
0X0
100
111
4441 0 push(@$out, '[');
4442 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4443 0 push(@$out, '..');
4444 0 ▶ return unless $self->translate_stmt($out, $a->[1], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[1], $info) 0 0 0
4445 0 push(@$out, ']');
4446 0 return 1;
4447 ▶ } elsif (($f eq 'base64_encode') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "base64_encode" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "base64_encode" and scalar @$a == 1
$f eq "base64_encode" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "base64_encode"B= scalar @$a == 1
ABresult
0X0
100
111
4448 # encode_base64($s,'')
4449 0 push(@$out, 'encode_base64');
4450 0 push(@$out, '(');
4451 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4452 0 push(@$out, ',');
4453 0 push(@$out, '\'\'');
4454 0 push(@$out, ')');
4455 0 return 1;
4456 ▶ } elsif (($f eq 'base64_decode') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "base64_decode" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "base64_decode" and scalar @$a == 1
$f eq "base64_decode" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "base64_decode"B= scalar @$a == 1
ABresult
0X0
100
111
4457 # decode_base64($s)
4458 0 push(@$out, 'decode_base64');
4459 0 push(@$out, '(');
4460 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4461 0 push(@$out, ')');
4462 0 return 1;
4463 ▶ } elsif (($f eq 'gzinflate') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "gzinflate" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "gzinflate" and scalar @$a == 1
$f eq "gzinflate" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "gzinflate"B= scalar @$a == 1
ABresult
0X0
100
111
4464 # (Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS))->inflate($s))[0])
4465 0 push(@$out, '(');
4466 0 push(@$out, 'Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS))->inflate');
4467 0 push(@$out, '(');
4468 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4469 0 push(@$out, ')');
4470 0 push(@$out, ')');
4471 0 push(@$out, '[');
4472 0 push(@$out, '0');
4473 0 push(@$out, ']');
4474 0 return 1;
4475 ▶ } elsif (($f =~ /^(chr|ord)$/) && (scalar @$a == 1)) {
Condition0%0/3
$f =~ /^(chr|ord)$/ and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f =~ /^(chr|ord)$/ and scalar @$a == 1
$f =~ /^(chr|ord)$/ scalar @$a == 1
Truth table0%0/3
A and B
A= $f =~ /^(chr|ord)$/B= scalar @$a == 1
ABresult
0X0
100
111
4476 0 push(@$out, $f);
4477 } else {
4478 0 $self->{warn}->('translate', "call $s $f not supported");
4479 0 return;
4480 }
4481 0 push(@$out, '(');
4482 0 foreach my $k (@$a) {
4483 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4484 0 push(@$out, ',');
4485 }
4486 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4487 0 pop(@$out);
4488 }
4489 0 push(@$out, ')');
4490 } elsif ($s =~ /^#elem\d+$/) {
4491 0 my ($v, $i) = @{$self->{strmap}->{$s}};
4492  
4493 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} & T_MASK) == T_STR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16) 0 0 0
Condition0%0/3
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16
!ll&&!rl&&r
000
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16
exists $info->{"vars"}{$v} ($info->{"vars"}{$v} & 65535) == 16
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= ($info->{"vars"}{$v} & 65535) == 16
ABresult
0X0
100
111
4494 0 push(@$out, 'substr');
4495 0 push(@$out, '(');
4496 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4497 0 push(@$out, ',');
4498 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 0 0 0
4499 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4500 0 push(@$out, ',');
4501 0 push(@$out, '1');
4502 } else {
4503 0 push(@$out, '-1');
4504 }
4505 0 push(@$out, ')');
4506 0 return 1;
4507 }
4508 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4509 0 push(@$out, '->');
4510 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} & T_MASK) == T_ARRAY)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'vars'}{$v} and ($info->{'vars'}{$v} & 65535) == 32) { } 0 0 0
Condition0%0/3
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 32
!ll&&!rl&&r
000
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 32
exists $info->{"vars"}{$v} ($info->{"vars"}{$v} & 65535) == 32
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= ($info->{"vars"}{$v} & 65535) == 32
ABresult
0X0
100
111
4511 0 push(@$out, '[');
4512 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 0 0 0
4513 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4514 }
4515 0 push(@$out, ']');
4516 } else {
4517 0 push(@$out, '{');
4518 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 0 0 0
4519 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4520 }
4521 0 push(@$out, '}');
4522 }
4523 } elsif ($s =~ /^#expr\d+$/) {
4524 0 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
4525  
4526 0 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 0 0 0
4527 0 ▶ if ($v1 =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v1 =~ /^#expr\d+$/) { } 0 0 0
elsif ($v1 =~ /^#elem\d+$/ and defined $v2 and $op eq '=') { } 0 0 0
4528 0 my $vop = $self->{strmap}->{$v1}->[0];
4529 0 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 0 0 0
Condition0%0/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
000
MC/DC0%0/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table0%0/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
4530 0 push(@$out, '(');
4531 }
4532 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4533 0 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 0 0 0
Condition0%0/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
000
MC/DC0%0/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table0%0/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
4534 0 push(@$out, ')');
4535 }
4536 ▶ } elsif (($v1 =~ /^#elem\d+$/) && defined $v2 && ($op eq '=')) {
Condition0%0/6
$v1 =~ /^#elem\d+$/ and defined $v2 and $op eq "="
!ll&&!rl&&r
000
$v1 =~ /^#elem\d+$/ and defined $v2
!ll&&!rl&&r
000
MC/DC0%0/3
$v1 =~ /^#elem\d+$/ and defined $v2 and $op eq "="
$v1 =~ /^#elem\d+$/ defined $v2 $op eq "="
Truth table0%0/4
A and B and C
A= $v1 =~ /^#elem\d+$/B= defined $v2C= $op eq "="
ABCresult
0XX0
10X0
1100
1111
4537 0 my $v = $self->{strmap}->{$v1}->[0];
4538 0 my $i = $self->{strmap}->{$v1}->[1];
4539 0 ▶ unless (defined $i && is_strict_variable($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and is_strict_variable($v)) { } 0 0 0
Condition0%0/3
defined $i and is_strict_variable($v)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $i and is_strict_variable($v)
defined $i is_strict_variable($v)
Truth table0%0/3
A and B
A= defined $iB= is_strict_variable($v)
ABresult
0X0
100
111
4540 # try to emulate php-arrays with perl-maps
4541 # see: https://www.php.net/manual/en/language.types.array.php
4542 # - if no key is specified, the maximum of the existing int
4543 # indices is taken, and the new key will be that maximum
4544 # value plus 1 (but at least 0).
4545 # - If no int indices exist yet, the key will be 0 (zero).
4546 #
4547 # TODO: Note that the maximum integer key used for this
4548 # need not currently exist in the array. It need only
4549 # have existed in the array at some time since the
4550 # last time the array was re-indexed.
4551 #
4552 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} && T_MASK) == T_ARRAY)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'vars'}{$v} and ($info->{'vars'}{$v} && 65535) == 32) { } 0 0 0
Condition0%0/5
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} && 65535) == 32
!ll&&!rl&&r
000
$info->{'vars'}{$v} && 65535
!ll
00
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} && 65535) == 32
exists $info->{"vars"}{$v} $info->{'vars'}{$v}
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= $info->{'vars'}{$v}
ABresult
0X0
100
111
4553 # for 'array' convert '$x[] = $v' to:
4554 # push(@{$x}, $v)
4555 #
4556 0 push(@$out, 'push');
4557 0 push(@$out, '(');
4558 0 push(@$out, '@');
4559 0 push(@$out, '{');
4560 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4561 0 push(@$out, '}');
4562 0 push(@$out, ',');
4563 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4564 0 push(@$out, ')');
4565 0 return 1;
4566 } else {
4567 # for 'map' convert '$x[] = $v' to:
4568 # $x->{(max keys %$x)[-1] + 1} = $v
4569 # (or: $x->{keys %$x ? (sort keys %$x)[-1] + 1 : 0} = $v)
4570 #
4571 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4572 0 my $vx = $out->[-1];
4573 0 push(@$out, '->');
4574 0 push(@$out, '{');
4575 0 push(@$out, '(');
4576 0 push(@$out, 'max');
4577 0 push(@$out, 'keys');
4578 0 push(@$out, '%'.$vx);
4579 0 push(@$out, ')');
4580 0 push(@$out, '[');
4581 0 push(@$out, '-1');
4582 0 push(@$out, ']');
4583 0 push(@$out, '+');
4584 0 push(@$out, '1');
4585 0 push(@$out, '}');
4586 }
4587 } else {
4588 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4589 }
4590 } else {
4591 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4592 }
4593 }
4594 0 ▶ if ($op eq '==') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '==') { } 0 0 0
elsif ($op eq '!=') { } 0 0 0
4595 0 push(@$out, 'eq');
4596 } elsif ($op eq '!=') {
4597 0 push(@$out, 'ne');
4598 } else {
4599 0 push(@$out, $op);
4600 }
4601 0 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 0 0 0
4602 0 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 0 0 0
4603 0 push(@$out, '{');
4604 }
4605 0 ▶ if ($v2 =~ /^#expr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2 =~ /^#expr\d+$/) { } 0 0 0
4606 0 my $vop = $self->{strmap}->{$v2}->[0];
4607 0 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 0 0 0
Condition0%0/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
000
$op ne "?" and $op ne "="
!ll&&!rl&&r
000
MC/DC0%0/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table0%0/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
4608 0 push(@$out, '(');
4609 }
4610 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4611 0 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 0 0 0
Condition0%0/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
000
$op ne "?" and $op ne "="
!ll&&!rl&&r
000
MC/DC0%0/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table0%0/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
4612 0 push(@$out, ')');
4613 }
4614 } else {
4615 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4616 }
4617 0 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 0 0 0
4618 0 push(@$out, '}');
4619 }
4620 }
4621 } elsif ($s =~ /^#pfx\d+$/) {
4622 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4623 0 $self->{warn}->('translate', "pfx $s not found");
4624 0 return;
4625 }
4626 0 my $pfx = $self->{strmap}->{$s};
4627 0 ▶ if (exists $pfx->{global}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"global"}) 0 0 0
4628 0 my $s = join(' ', sort keys %$pfx);
4629 0 $self->{warn}->('translate', "global pfx $s");
4630 0 return;
4631 }
4632 0 push(@$out, 'my');
4633 } elsif ($s =~ /^#obj\d+$/) {
4634 0 my ($o, $m) = @{$self->{strmap}->{$s}};
4635  
4636 0 $self->{warn}->('translate', "obj $s $o->$m not supported");
4637 0 return;
4638 } elsif ($s =~ /^#scope\d+$/) {
4639 0 my ($c, $e) = @{$self->{strmap}->{$s}};
4640  
4641 0 $self->{warn}->('translate', "scope $s $c::$e not supported");
4642 0 return;
4643 } elsif ($s =~ /^#ns\d+$/) {
4644 0 my ($n, $e) = @{$self->{strmap}->{$s}};
4645  
4646 0 $self->{warn}->('translate', "namespace $s $n::$e not supported");
4647 0 return;
4648 } elsif ($s =~ /^#inst\d+$/) {
4649 0 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
4650  
4651 0 $self->{warn}->('translate', "new inst $s $f not supported");
4652 0 return;
4653 } elsif ($s =~ /^#ref\d+$/) {
4654 0 my $v = $self->{strmap}->{$s}->[0];
4655 0 push(@$out, '\\');
4656 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4657 } elsif ($s =~ /^#class\d+$/) {
4658 0 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
4659  
4660 0 $self->{warn}->('translate', "class $s $c not supported");
4661 0 return;
4662 } elsif ($s =~ /^#trait\d+$/) {
4663 0 my ($t, $b) = @{$self->{strmap}->{$s}};
4664  
4665 0 $self->{warn}->('translate', "trait $s $t not supported");
4666 0 return;
4667 } elsif ($s =~ /^#fh\d+$/) {
4668 0 my $f = $self->{strmap}->{$s}{name};
4669 0 my $m = $self->{strmap}->{$s}{mode};
4670 0 my $p = $self->{strmap}->{$s}{pos};
4671  
4672 0 $self->{warn}->('translate', "fh $s $f not supported");
4673 0 return;
4674 } elsif ($s =~ /^#blk\d+$/) {
4675 0 my ($type, $a) = @{$self->{strmap}->{$s}};
4676  
4677 0 ▶ if ($type eq 'expr') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'expr') { } 0 0 0
elsif ($type eq 'flat') { } 0 0 0
elsif ($type eq 'case') { } 0 0 0
elsif ($type eq 'brace') { } 0 0 0
4678 0 foreach my $k (@$a) {
4679 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4680 0 push(@$out, ',');
4681 }
4682 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4683 0 pop(@$out);
4684 }
4685 } elsif ($type eq 'flat') {
4686 0 foreach my $k (@$a) {
4687 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4688 0 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 0 0
4689 0 next; # avoid ;
4690 }
4691 0 ▶ if ($out->[-1] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}") 0 0 0
4692 0 push(@$out, ';');
4693 }
4694 }
4695 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4696 0 pop(@$out);
4697 }
4698 } elsif ($type eq 'case') {
4699 0 foreach my $k (@$a) {
4700 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4701 0 push(@$out, ';');
4702 }
4703 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4704 0 pop(@$out);
4705 }
4706 } elsif ($type eq 'brace') {
4707 0 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) { } 0 0 0
4708 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4709 } else {
4710 0 push(@$out, '(');
4711 0 foreach my $k (@$a) {
4712 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4713 0 ▶ if ($out->[-1] ne ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne ")") 0 0 0
4714 0 push(@$out, ';');
4715 }
4716 }
4717 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4718 0 pop(@$out);
4719 }
4720 0 push(@$out, ')');
4721 }
4722 } else {
4723 0 push(@$out, '{');
4724 0 foreach my $k (@$a) {
4725 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4726 0 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 0 0
4727 0 next; # avoid ;
4728 }
4729 0 ▶ if ($out->[-1] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}") 0 0 0
4730 0 push(@$out, ';');
4731 }
4732 }
4733 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4734 0 pop(@$out);
4735 }
4736 0 push(@$out, '}');
4737 }
4738 } elsif ($s =~ /^#stmt\d+$/) {
4739 0 my $cmd = $self->{strmap}->{$s}->[0];
4740 0 ▶ if ($cmd eq 'echo') {
Branch: 20 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 0 0 0
elsif ($cmd eq 'print') { } 0 0 0
elsif ($cmd eq 'namespace') { } 0 0 0
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 0 0
elsif ($cmd eq 'use') { } 0 0 0
elsif ($cmd eq 'global') { } 0 0 0
elsif ($cmd eq 'static') { } 0 0 0
elsif ($cmd eq 'const') { } 0 0 0
elsif ($cmd eq 'unset') { } 0 0 0
elsif ($cmd eq 'return') { } 0 0 0
elsif ($cmd eq 'goto') { } 0 0 0
elsif ($cmd eq 'label') { } 0 0 0
elsif ($cmd eq 'if') { } 0 0 0
elsif ($cmd eq 'while') { } 0 0 0
elsif ($cmd eq 'do') { } 0 0 0
elsif ($cmd eq 'for') { } 0 0 0
elsif ($cmd eq 'foreach') { } 0 0 0
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'break') { } 0 0 0
elsif ($cmd eq 'continue') { } 0 0 0
4741 0 my $a = $self->{strmap}->{$s}->[1];
4742 0 push(@$out, 'print');
4743 0 foreach my $k (@$a) {
4744 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4745 0 push(@$out, ',');
4746 }
4747 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4748 0 pop(@$out);
4749 }
4750 } elsif ($cmd eq 'print') {
4751 0 my $arg = $self->{strmap}->{$s}->[1];
4752 0 push(@$out, $cmd);
4753 0 ▶ return unless $self->translate_stmt($out, $arg, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $arg, $info) 0 0 0
4754 } elsif ($cmd eq 'namespace') {
4755 0 my ($a, $block) = @{$self->{strmap}->{$s}}[1..2];
4756 0 $self->{warn}->('translate', "namespace $s $a not supported");
4757 0 return;
4758 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
4759 0 my $arg = $self->{strmap}->{$s}->[1];
4760 0 push(@$out, $cmd);
4761 0 ▶ return unless $self->translate_stmt($out, $arg, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $arg, $info) 0 0 0
4762 } elsif ($cmd eq 'use') {
4763 0 my $a = $self->{strmap}->{$s}->[1];
4764 0 $self->{warn}->('translate', "use $s not supported");
4765 0 return;
4766 } elsif ($cmd eq 'global') {
4767 0 my $a = $self->{strmap}->{$s}->[1];
4768 0 $self->{warn}->('translate', "global $s not supported");
4769 0 return;
4770 } elsif ($cmd eq 'static') {
4771 0 my $a = $self->{strmap}->{$s}->[1];
4772 0 $self->{warn}->('translate', "static $s not supported");
4773 0 return;
4774 } elsif ($cmd eq 'const') {
4775 0 my $a = $self->{strmap}->{$s}->[1];
4776 0 $self->{warn}->('translate', "const $s not supported");
4777 0 return;
4778 } elsif ($cmd eq 'unset') {
4779 0 my $a = $self->{strmap}->{$s}->[1];
4780 0 $self->{warn}->('translate', "unset $s not supported");
4781 0 return;
4782 } elsif ($cmd eq 'return') {
4783 0 my $a = $self->{strmap}->{$s}->[1];
4784 0 push(@$out, $cmd);
4785 0 ▶ return unless $self->translate_stmt($out, $a, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a, $info) 0 0 0
4786 } elsif ($cmd eq 'goto') {
4787 0 my $a = $self->{strmap}->{$s}->[1];
4788 0 $self->{warn}->('translate', "goto $s not supported");
4789 0 return;
4790 } elsif ($cmd eq 'label') {
4791 0 my $a = $self->{strmap}->{$s}->[1];
4792 0 $self->{warn}->('translate', "label $s not supported");
4793 0 return;
4794 } elsif ($cmd eq 'if') {
4795 0 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
4796  
4797 0 push(@$out, $cmd);
4798 0 push(@$out, '(');
4799 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4800 0 push(@$out, ')');
4801 0 ▶ return unless $self->translate_stmt($out, $then, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $then, $info) 0 0 0
4802 0 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 0 0 0
4803 0 push(@$out, 'else');
4804 0 ▶ return unless $self->translate_stmt($out, $else, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $else, $info) 0 0 0
4805 }
4806 } elsif ($cmd eq 'while') {
4807 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4808  
4809 0 push(@$out, $cmd);
4810 0 push(@$out, '(');
4811 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4812 0 push(@$out, ')');
4813 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4814 } elsif ($cmd eq 'do') {
4815 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4816  
4817 0 push(@$out, $cmd);
4818 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4819 0 push(@$out, 'while');
4820 0 push(@$out, '(');
4821 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4822 0 push(@$out, ')');
4823 } elsif ($cmd eq 'for') {
4824 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
4825  
4826 0 push(@$out, $cmd);
4827 0 push(@$out, '(');
4828 #push(@$out, 'my'); # set as local -> persists after for-loop
4829 0 ▶ return unless $self->translate_stmt($out, $pre, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $pre, $info) 0 0 0
4830 0 push(@$out, ';');
4831 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4832 0 push(@$out, ';');
4833 0 ▶ return unless $self->translate_stmt($out, $post, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $post, $info) 0 0 0
4834 0 push(@$out, ')');
4835 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4836 } elsif ($cmd eq 'foreach') {
4837 0 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
4838  
4839 0 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 0 0 0
4840 # convert 'foreach ($x as $k => $v)' to
4841 # foreach my $k ( sort { $a <=> $b } keys %$x ) { my $v = $x->{$k}; .. }
4842 #
4843 0 push(@$out, 'foreach');
4844 #push(@$out, 'my');
4845 0 ▶ return unless $self->translate_stmt($out, $key, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $key, $info) 0 0 0
4846 0 push(@$out, '(');
4847 0 push(@$out, 'sort');
4848 0 push(@$out, '{');
4849 0 push(@$out, '$a');
4850 0 push(@$out, '<=>');
4851 0 push(@$out, '$b');
4852 0 push(@$out, '}');
4853 0 push(@$out, 'keys');
4854 0 push(@$out, '%');
4855 0 push(@$out, '{');
4856 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4857 0 push(@$out, '}');
4858 0 push(@$out, ')');
4859 0 push(@$out, '{');
4860  
4861 #push(@$out, 'my');
4862 0 ▶ return unless $self->translate_stmt($out, $value, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $value, $info) 0 0 0
4863 0 push(@$out, '=');
4864 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4865 0 push(@$out, '->');
4866 0 push(@$out, '{');
4867 0 ▶ return unless $self->translate_stmt($out, $key, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $key, $info) 0 0 0
4868 0 push(@$out, '}');
4869 0 push(@$out, ';');
4870  
4871 0 my $type = $self->{strmap}->{$block}->[1];
4872 0 my $c = $self->{strmap}->{$block}->[2];
4873 0 foreach my $k (@$c) {
4874 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4875 #if ($out->[-1] ne '}') {
4876 0 push(@$out, ';'); # might follow {} after map define/deref
4877 #}
4878 }
4879 0 push(@$out, '}');
4880 0 return 1;
4881 } else {
4882 0 push(@$out, $cmd);
4883 0 push(@$out, 'my');
4884 0 ▶ return unless $self->translate_stmt($out, $value, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $value, $info) 0 0 0
4885 0 push(@$out, '(');
4886 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4887 0 push(@$out, ')');
4888 }
4889 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4890 } elsif ($cmd eq 'switch') {
4891 0 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
4892 0 my $first = 1;
4893  
4894 0 foreach my $e (@$cases) {
4895 0 my $c = $e->[0];
4896 0 my $b = $e->[1];
4897 0 ▶ if (!defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c) { } 0 0 0
4898 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) 0 0 0
4899 0 $self->{warn}->('translate', "bad switch $s");
4900 0 return;
4901 }
4902 0 push(@$out, 'else');
4903 } else {
4904 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 0 0 0
4905 0 push(@$out, 'if');
4906 0 $first = 0;
4907 } else {
4908 0 push(@$out, 'elsif');
4909 }
4910 0 push(@$out, '(');
4911 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4912 0 push(@$out, '==');
4913 0 push(@$out, '(');
4914 0 ▶ return unless $self->translate_stmt($out, $c, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $c, $info) 0 0 0
4915 0 push(@$out, ')');
4916 0 push(@$out, ')');
4917 }
4918 0 push(@$out, '{');
4919 0 ▶ return unless $self->translate_stmt($out, $b, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $b, $info) 0 0 0
4920 0 push(@$out, '}');
4921 }
4922 } elsif ($cmd eq 'break') {
4923 0 push(@$out, 'last');
4924 } elsif ($cmd eq 'continue') {
4925 0 push(@$out, 'next');
4926 } else {
4927 0 $self->{warn}->('translate', "bad statement $s");
4928 0 return;
4929 }
4930 } elsif (is_variable($s)) {
4931 0 my ($global) = global_split($s);
4932 0 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) 0 0 0
4933 0 $self->{warn}->('translate', "global $s not supported");
4934 0 return;
4935 }
4936 0 ▶ unless (is_symbol($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($s)) 0 0 0
4937 0 $self->{warn}->('translate', "bad var name $s not supported");
4938 0 return;
4939 }
4940 0 push(@$out, $s);
4941 } else {
4942 0 $self->{warn}->('translate', "bad symbol $s not supported");
4943 0 return;
4944 }
4945 0 return 1;
4946 }
4947  
4948 0 ▶sub translate_func {
Subroutine translate_func: not called CC=22 SCAR=62.3
Pod undocumented
4949 0 my ($self, $s, $maxlen, $format) = @_;
4950 0 my @out = ();
4951  
4952 0 ▶ unless ($s =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ /^#fun\d+$/) 0 0 0
4953 0 $self->{warn}->('translate', "no func $s");
4954 0 return;
4955 }
4956 # create anonymous subroutine here
4957 #
4958 0 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
4959 0 $f = $self->setfun(undef, $a, $b, $p);
4960  
4961 0 my $info = {args => {}, vars => {}, locals => {}, globals => {}, calls => {}, returns => {}};
4962 0 $self->stmt_info($b, $info);
4963  
4964 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) { } 0 0 0
4965 0 foreach my $v (@$a) {
4966 0 $info->{args}{$v} = 0;
4967 }
4968 0 foreach my $v (keys %{$info->{vars}}) {
4969 0 ▶ $info->{locals}{$v} |= $info->{vars}{$v} unless exists $info->{args}{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"args"}{$v} 0 0 0
4970 }
4971 0 foreach my $v (keys %{$info->{args}}) {
4972 0 ▶ $info->{vars}{$v} |= $info->{args}{$v} unless exists $info->{vars}{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"vars"}{$v} 0 0 0
4973 }
4974 } else {
4975 0 $info->{locals} = $info->{vars};
4976 }
4977 0 ▶ if (keys %{$info->{args}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"args"};}) 0 0 0
4978 0 ▶ $self->{log}->('translate', "local args: %s", join(' ', map { ($info->{vars}{$_} ne '1') ? "$_:$info->{vars}{$_}" : $_ } keys %{$info->{args}})) if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
$info->{'vars'}{$_} ne '1' ? : 0 0 0
4979 }
4980 0 ▶ if (keys %{$info->{locals}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"locals"};}) 0 0 0
4981 0 ▶ $self->{log}->('translate', "local vars: %s", join(' ', map { ($info->{vars}{$_} ne '1') ? "$_:$info->{vars}{$_}" : $_ } keys %{$info->{locals}})) if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
$info->{'vars'}{$_} ne '1' ? : 0 0 0
4982 }
4983 0 ▶ if (keys %{$info->{globals}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"globals"};}) 0 0 0
4984 0 ▶ $self->{log}->('translate', "globals: %s", join(' ', keys %{$info->{globals}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4985 }
4986 0 ▶ if (keys %{$info->{calls}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"calls"};}) 0 0 0
4987 0 ▶ $self->{log}->('translate', "calls: %s", join(' ', keys %{$info->{calls}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4988 }
4989 0 ▶ if (keys %{$info->{returns}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{'returns'};}) { } 0 0 0
4990 0 ▶ $self->{log}->('translate', "returns: %s", join(' ', keys %{$info->{returns}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4991 } else {
4992 0 $self->{warn}->('translate', "no return for func $s");
4993 0 return;
4994 }
4995  
4996 0 ▶ unless ($self->translate_stmt(\@out, $f, $info)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->translate_stmt(\@out, $f, $info)) 0 0 0
4997 0 return;
4998 }
4999  
5000 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 0 0 0
5001 0 my @tmp = ();
5002 0 expand_formatted(\@tmp, \@out, 0);
5003 0 return join(' ', @tmp);
5004 }
5005 0 return join(' ', @out);
5006 }
5007  
5008 6 1;
5009  
5010 __END__
« Decode/Func.pm ↑ Summary Decode/Transformer.pm »