summaryrefslogtreecommitdiff
path: root/ext/B
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-11-18 18:01:52 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-11-18 18:01:52 +0000
commit36d57d93b96b25d607e30e624947d4248efa2ead (patch)
treee462432e9627ff01de3a67b806f901087e9bf24b /ext/B
parent3ac6e0f94cbac2937b08ea7ee5d77e4a19c63780 (diff)
downloadperl-36d57d93b96b25d607e30e624947d4248efa2ead.tar.gz
Fix deparsing of reversed foreach loops,
plus a bug in the previous commit p4raw-id: //depot/perl@23514
Diffstat (limited to 'ext/B')
-rw-r--r--ext/B/B/Deparse.pm9
-rw-r--r--ext/B/t/deparse.t6
2 files changed, 11 insertions, 4 deletions
diff --git a/ext/B/B/Deparse.pm b/ext/B/B/Deparse.pm
index e3ce2135fc..5d6b87e7cd 100644
--- a/ext/B/B/Deparse.pm
+++ b/ext/B/B/Deparse.pm
@@ -14,7 +14,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
OPpLVAL_INTRO OPpOUR_INTRO OPpENTERSUB_AMPER OPpSLICE OPpCONST_BARE
OPpTRANS_SQUASH OPpTRANS_DELETE OPpTRANS_COMPLEMENT OPpTARGET_MY
OPpCONST_ARYBASE OPpEXISTS_SUB OPpSORT_NUMERIC OPpSORT_INTEGER
- OPpSORT_REVERSE OPpSORT_INPLACE OPpSORT_DESCEND
+ OPpSORT_REVERSE OPpSORT_INPLACE OPpSORT_DESCEND OPpITER_REVERSED
SVf_IOK SVf_NOK SVf_ROK SVf_POK SVpad_OUR SVf_FAKE SVs_RMG SVs_SMG
CVf_METHOD CVf_LOCKED CVf_LVALUE CVf_ASSERTION
PMf_KEEP PMf_GLOBAL PMf_CONTINUE PMf_EVAL PMf_ONCE PMf_SKIPWHITE
@@ -2403,7 +2403,7 @@ sub pp_list {
} elsif ($lop->name ne "undef"
# specifically avoid the "reverse sort" optimisation,
# where "reverse" is nullified
- && !($lop->name eq 'sort' && ($lop->flags | OPpSORT_REVERSE)))
+ && !($lop->name eq 'sort' && ($lop->flags & OPpSORT_REVERSE)))
{
# local()
($local = "", last) if $local eq "my" || $local eq "our";
@@ -2501,7 +2501,10 @@ sub loop_common {
} elsif ($enter->name eq "enteriter") { # foreach
my $ary = $enter->first->sibling; # first was pushmark
my $var = $ary->sibling;
- if ($enter->flags & OPf_STACKED
+ if ($ary->name eq 'null' and $enter->private & OPpITER_REVERSED) {
+ # "reverse" was optimised away
+ $ary = "reverse " . $self->deparse($ary->first->sibling->first->sibling, 1);
+ } elsif ($enter->flags & OPf_STACKED
and not null $ary->first->sibling->sibling)
{
$ary = $self->deparse($ary->first->sibling, 9) . " .. " .
diff --git a/ext/B/t/deparse.t b/ext/B/t/deparse.t
index 6c5bcb9f93..9439ac9136 100644
--- a/ext/B/t/deparse.t
+++ b/ext/B/t/deparse.t
@@ -20,7 +20,7 @@ use warnings;
use strict;
use Config;
-print "1..35\n";
+print "1..36\n";
use B::Deparse;
my $deparse = B::Deparse->new() or print "not ";
@@ -277,3 +277,7 @@ print((sort {$b cmp $a} @x));
# 31
my @x;
print((reverse sort {$b <=> $a} @x));
+####
+# 32
+our @a;
+print $_ foreach (reverse @a);