Permalink
Browse files

Add correct shortcutting with redo, goto and die

  • Loading branch information...
1 parent 4a771ec commit 4d4cf6b0e8b7e9d3a2c73da88eab2906f5c3552b @pjcj committed Aug 6, 2010
View
@@ -80,7 +80,7 @@ my %Run; # Data collected from the run.
my $Const_right = qr/^(?:const|s?refgen|gelem|die|undef|bless|anon(?:list|hash)|
scalar)$/x; # constant ops
-my $Noret_right = qr/^(?:return|last|next)$/x;
+my $Noret_right = qr/^(?:return|last|next|redo|goto\s+\w+|die)$/x;
# ops which don't return
use vars '$File', # Last filename we saw. (localised)
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 83.9 81.0 19.1 100.0 71.0
-Total 83.9 81.0 19.1 100.0 71.0
+tests/cond_branch 85.3 82.1 19.1 100.0 73.0
+Total 85.3 82.1 19.1 100.0 73.0
------------------------------------------ ------ ------ ------ ------ ------
@@ -353,53 +353,88 @@ line err stmt bran cond sub code
8
303 {
304 8 100 my $z = $x || next;
-305 4 $x[47]++;
+305 4 $x[48]++;
306 }
307 },
-308 1 );
-309
-310 1 for my $s (@s)
- 7
-311 {
-312 7 for my $y (0, 1)
- 14
-313 {
-314 14 $s->($y)
-315 }
-316
-317 7 for my $y (1, 0)
- 14
-318 {
-319 14 $s->($y)
-320 }
-321 }
-322
-323
-324 1 my ($a, $b) = (0, 1);
-325
-326 *** 1 50 33 if ($a && $b)
+308
+309 sub
+310 {
+311 4 4 my $x = shift;
+312 4 for my $y (1 .. 2)
+ 8
+313 {
+314 10 100 my $z = $x++ || redo;
+315 8 $x[49]++;
+316 }
+317 },
+318
+319 sub
+320 {
+321 4 4 my $x = shift;
+322 4 for my $y (1 .. 2)
+ 4
+323 {
+324 6 100 my $z = $x || goto GR;
+325 4 $x[50]++;
+326 }
+327 GR:
+328 4 },
+329
+330 sub
+331 {
+332 4 4 my $x = shift;
+333 4 for my $y (1 .. 2)
+ 8
+334 {
+335 8 100 eval { my $z = $x || die };
+ 8
+336 8 $x[51]++;
+337 }
+338 },
+339 1 );
+340
+341 1 for my $s (@s)
+ 10
+342 {
+343 10 for my $y (0, 1)
+ 20
+344 {
+345 20 $s->($y)
+346 }
+347
+348 10 for my $y (1, 0)
+ 20
+349 {
+350 20 $s->($y)
+351 }
+352 }
+353
+354
+355 1 my ($a, $b) = (0, 1);
+356
+357 *** 1 50 33 if ($a && $b)
*** 50 33
*** 50 50
-327 {
-328 *** 0 print "path 1\n";
-329 }
-330 elsif (!$a && !$b)
-331 {
-332 *** 0 print "path 2\n";
-333 }
-334 elsif ($b || 0)
-335 {
-336 1 print "path 3\n";
-337 *** 1 50 33 if (!$b || $a)
+358 {
+359 *** 0 print "path 1\n";
+360 }
+361 elsif (!$a && !$b)
+362 {
+363 *** 0 print "path 2\n";
+364 }
+365 elsif ($b || 0)
+366 {
+367 1 print "path 3\n";
+368 *** 1 50 33 if (!$b || $a)
*** 50 33
-338 {
-339 *** 0 print "path 4\n";
-340 }
-341 elsif (!$a && $b)
-342 {
-343 1 print "path 5\n";
-344 }
-345 }
+369 {
+370 *** 0 print "path 4\n";
+371 }
+372 elsif (!$a && $b)
+373 {
+374 1 print "path 5\n";
+375 }
+376 }
Branches
@@ -452,10 +487,13 @@ line err % true false branch
285 100 2 2 if (shift @_)
294 100 2 4 unless ($x)
304 100 4 4 unless ($x)
-326 *** 50 0 1 if ($a and $b) { }
+314 100 2 8 unless ($x++)
+324 100 2 4 unless ($x)
+335 100 4 4 unless ($x)
+357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a and not $b) { }
*** 50 1 0 elsif ($b or 0) { }
-337 *** 50 0 1 if (not $b or $a) { }
+368 *** 50 0 1 if (not $b or $a) { }
*** 50 1 0 elsif (not $a and $b) { }
@@ -470,23 +508,23 @@ line err % !l l&&!r l&&r expr
51 *** 33 4 0 0 $y and $z
68 *** 33 4 0 0 $y and $z
*** 33 4 0 0 $y and $z
-326 *** 33 1 0 0 $a and $b
+357 *** 33 1 0 0 $a and $b
*** 33 0 1 0 not $a and not $b
-337 *** 33 0 0 1 not $a and $b
+368 *** 33 0 0 1 not $a and $b
or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
-326 *** 50 1 0 $b or 0
+357 *** 50 1 0 $b or 0
or 3 conditions
line err % l !l&&r !l&&!r expr
----- --- ------ ------ ------ ------ ----
27 *** 66 0 2 2 $y or $z
51 *** 66 0 2 2 $y or $z
-337 *** 33 0 0 1 not $b or $a
+368 *** 33 0 0 1 not $b or $a
xor 4 conditions
@@ -515,5 +553,8 @@ __ANON__ 4 tests/cond_branch:279
__ANON__ 4 tests/cond_branch:285
__ANON__ 4 tests/cond_branch:291
__ANON__ 4 tests/cond_branch:301
+__ANON__ 4 tests/cond_branch:311
+__ANON__ 4 tests/cond_branch:321
+__ANON__ 4 tests/cond_branch:332
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 86.4 81.0 19.1 100.0 74.2
-Total 86.4 81.0 19.1 100.0 74.2
+tests/cond_branch 87.4 82.1 19.1 100.0 75.8
+Total 87.4 82.1 19.1 100.0 75.8
------------------------------------------ ------ ------ ------ ------ ------
@@ -375,53 +375,88 @@ line err stmt bran cond sub code
8
303 {
304 8 100 my $z = $x || next;
-305 4 $x[47]++;
+305 4 $x[48]++;
306 }
307 },
-308 1 );
-309
-310 1 for my $s (@s)
- 7
-311 {
-312 7 for my $y (0, 1)
- 14
-313 {
-314 14 $s->($y)
-315 }
-316
-317 7 for my $y (1, 0)
- 14
-318 {
-319 14 $s->($y)
-320 }
-321 }
-322
-323
-324 1 my ($a, $b) = (0, 1);
-325
-326 *** 1 50 33 if ($a && $b)
+308
+309 sub
+310 {
+311 4 4 my $x = shift;
+312 4 for my $y (1 .. 2)
+ 8
+313 {
+314 10 100 my $z = $x++ || redo;
+315 8 $x[49]++;
+316 }
+317 },
+318
+319 sub
+320 {
+321 4 4 my $x = shift;
+322 4 for my $y (1 .. 2)
+ 4
+323 {
+324 6 100 my $z = $x || goto GR;
+325 4 $x[50]++;
+326 }
+327 GR:
+328 4 },
+329
+330 sub
+331 {
+332 4 4 my $x = shift;
+333 4 for my $y (1 .. 2)
+ 8
+334 {
+335 8 100 eval { my $z = $x || die };
+ 8
+336 8 $x[51]++;
+337 }
+338 },
+339 1 );
+340
+341 1 for my $s (@s)
+ 10
+342 {
+343 10 for my $y (0, 1)
+ 20
+344 {
+345 20 $s->($y)
+346 }
+347
+348 10 for my $y (1, 0)
+ 20
+349 {
+350 20 $s->($y)
+351 }
+352 }
+353
+354
+355 1 my ($a, $b) = (0, 1);
+356
+357 *** 1 50 33 if ($a && $b)
*** 50 33
*** 50 50
-327 {
-328 *** 0 print "path 1\n";
-329 }
-330 elsif (!$a && !$b)
-331 {
-332 *** 0 print "path 2\n";
-333 }
-334 elsif ($b || 0)
-335 {
-336 1 print "path 3\n";
-337 *** 1 50 33 if (!$b || $a)
+358 {
+359 *** 0 print "path 1\n";
+360 }
+361 elsif (!$a && !$b)
+362 {
+363 *** 0 print "path 2\n";
+364 }
+365 elsif ($b || 0)
+366 {
+367 1 print "path 3\n";
+368 *** 1 50 33 if (!$b || $a)
*** 50 33
-338 {
-339 *** 0 print "path 4\n";
-340 }
-341 elsif (!$a && $b)
-342 {
-343 1 print "path 5\n";
-344 }
-345 }
+369 {
+370 *** 0 print "path 4\n";
+371 }
+372 elsif (!$a && $b)
+373 {
+374 1 print "path 5\n";
+375 }
+376 }
Branches
@@ -474,10 +509,13 @@ line err % true false branch
285 100 2 2 if (shift @_)
294 100 2 4 unless ($x)
304 100 4 4 unless ($x)
-326 *** 50 0 1 if ($a and $b) { }
+314 100 2 8 unless ($x++)
+324 100 2 4 unless ($x)
+335 100 4 4 unless ($x)
+357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a and not $b) { }
*** 50 1 0 elsif ($b or 0) { }
-337 *** 50 0 1 if (not $b or $a) { }
+368 *** 50 0 1 if (not $b or $a) { }
*** 50 1 0 elsif (not $a and $b) { }
@@ -492,23 +530,23 @@ line err % !l l&&!r l&&r expr
51 *** 33 4 0 0 $y and $z
68 *** 33 4 0 0 $y and $z
*** 33 4 0 0 $y and $z
-326 *** 33 1 0 0 $a and $b
+357 *** 33 1 0 0 $a and $b
*** 33 0 1 0 not $a and not $b
-337 *** 33 0 0 1 not $a and $b
+368 *** 33 0 0 1 not $a and $b
or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
-326 *** 50 1 0 $b or 0
+357 *** 50 1 0 $b or 0
or 3 conditions
line err % l !l&&r !l&&!r expr
----- --- ------ ------ ------ ------ ----
27 *** 66 0 2 2 $y or $z
51 *** 66 0 2 2 $y or $z
-337 *** 33 0 0 1 not $b or $a
+368 *** 33 0 0 1 not $b or $a
xor 4 conditions
@@ -548,5 +586,8 @@ __ANON__ 4 tests/cond_branch:279
__ANON__ 4 tests/cond_branch:285
__ANON__ 4 tests/cond_branch:291
__ANON__ 4 tests/cond_branch:301
+__ANON__ 4 tests/cond_branch:311
+__ANON__ 4 tests/cond_branch:321
+__ANON__ 4 tests/cond_branch:332
Oops, something went wrong.

0 comments on commit 4d4cf6b

Please sign in to comment.