$priv{$_}{128} = "LVINTRO"
for ("pos", "substr", "vec", "threadsv", "gvsv", "rv2sv", "rv2hv", "rv2gv",
"rv2av", "rv2arylen", "aelem", "helem", "aslice", "hslice", "padsv",
- "padav", "padhv");
+ "padav", "padhv", "enteriter");
$priv{$_}{64} = "REFC" for ("leave", "leavesub", "leavesublv", "leavewrite");
$priv{"aassign"}{64} = "COMMON";
$priv{"sassign"}{64} = "BKWARD";
@{$priv{$_}}{4,8,128} = ("INARGS","AMPER","NO()") for ("entersub", "rv2cv");
$priv{"gv"}{32} = "EARLYCV";
$priv{"aelem"}{16} = $priv{"helem"}{16} = "LVDEFER";
-$priv{$_}{16} = "OURINTR" for ("gvsv", "rv2sv", "rv2av", "rv2hv", "r2gv");
+$priv{$_}{16} = "OURINTR" for ("gvsv", "rv2sv", "rv2av", "rv2hv", "r2gv",
+ "enteriter");
$priv{$_}{16} = "TARGMY"
for (map(($_,"s$_"),"chop", "chomp"),
map(($_,"i_$_"), "postinc", "postdec", "multiply", "divide", "modulo",
my $body;
my $cond = undef;
if ($kid->name eq "lineseq") { # bare or infinite loop
- if (is_state $kid->last) { # infinite
+ if ($kid->last->name eq "unstack") { # infinite
$head = "while (1) "; # Can't use for(;;) if there's a continue
$cond = "";
} else {
$var = $self->pp_threadsv($enter, 1);
} else { # regular my() variable
$var = $self->pp_padsv($enter, 1);
- if ($self->padname_sv($enter->targ)->IVX ==
- $kid->first->first->sibling->last->cop_seq)
- {
- # If the scope of this variable closes at the last
- # statement of the loop, it must have been
- # declared here.
- $var = "my " . $var;
- }
}
} elsif ($var->name eq "rv2gv") {
$var = $self->pp_rv2sv($var, 1);
+ if ($enter->private & OPpOUR_INTRO) {
+ # our declarations don't have package names
+ $var =~ s/^(.).*::/$1/;
+ $var = "our $var";
+ }
} elsif ($var->name eq "gv") {
$var = "\$" . $self->deparse($var, 1);
}
return "{;}"; # {} could be a hashref
}
# If there isn't a continue block, then the next pointer for the loop
- # will point to the unstack, which is kid's penultimate child, except
+ # will point to the unstack, which is kid's last child, except
# in a bare loop, when it will point to the leaveloop. When neither of
- # these conditions hold, then the third-to-last child in the continue
+ # these conditions hold, then the second-to-last child is the continue
# block (or the last in a bare loop).
my $cont_start = $enter->nextop;
my $cont;
- if ($$cont_start != $$op && ${$cont_start->sibling} != ${$body->last}) {
+ if ($$cont_start != $$op && ${$cont_start} != ${$body->last}) {
if ($bare) {
$cont = $body->last;
} else {
$cont = $body->first;
- while (!null($cont->sibling->sibling->sibling)) {
+ while (!null($cont->sibling->sibling)) {
$cont = $cont->sibling;
}
}
$b=<<EOF;
leave enter nextstate label leaveloop enterloop null and defined null
threadsv readline gv lineseq nextstate aassign null pushmark split pushre
-threadsv const null pushmark rvav gv nextstate subst const unstack nextstate
+threadsv const null pushmark rvav gv nextstate subst const unstack
EOF
} else {
$b=<<EOF;
leave enter nextstate label leaveloop enterloop null and defined null
null gvsv readline gv lineseq nextstate aassign null pushmark split pushre
-null gvsv const null pushmark rvav gv nextstate subst const unstack nextstate
+null gvsv const null pushmark rvav gv nextstate subst const unstack
EOF
}
$b=~s/\n/ /g;$b=~s/\s+/ /g;
use strict;
use Config;
-print "1..18\n";
+print "1..31\n";
use B::Deparse;
my $deparse = B::Deparse->new() or print "not ";
####
# 15
s/x/'y';/e;
+####
+# 16 - various lypes of loop
+{ my $x; }
+####
+# 17
+while (1) { my $k; }
+####
+# 18
+my ($x,@a);
+$x=1 for @a;
+>>>>
+my($x, @a);
+foreach $_ (@a) {
+ $x = 1;
+}
+####
+# 19
+for (my $i = 0; $i < 2;) {
+ my $z = 1;
+}
+####
+# 20
+for (my $i = 0; $i < 2; ++$i) {
+ my $z = 1;
+}
+####
+# 21
+for (my $i = 0; $i < 2; ++$i) {
+ my $z = 1;
+}
+####
+# 22
+my $i;
+while ($i) { my $z = 1; } continue { $i = 99; }
+####
+# 23
+foreach $i (1, 2) {
+ my $z = 1;
+}
+####
+# 24
+my $i;
+foreach $i (1, 2) {
+ my $z = 1;
+}
+####
+# 25
+my $i;
+foreach my $i (1, 2) {
+ my $z = 1;
+}
+####
+# 26
+foreach my $i (1, 2) {
+ my $z = 1;
+}
+####
+# 27
+foreach our $i (1, 2) {
+ my $z = 1;
+}
+####
+# 28
+my $i;
+foreach our $i (1, 2) {
+ my $z = 1;
+}
if (!next)
next = unstack;
cont = append_elem(OP_LINESEQ, cont, unstack);
- if ((line_t)whileline != NOLINE) {
- PL_copline = (line_t)whileline;
- cont = append_elem(OP_LINESEQ, cont,
- newSTATEOP(0, Nullch, Nullop));
- }
}
listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
OP *wop;
PADOFFSET padoff = 0;
I32 iterflags = 0;
+ I32 iterpflags = 0;
if (sv) {
if (sv->op_type == OP_RV2SV) { /* symbol table variable */
+ iterpflags = sv->op_private & OPpOUR_INTRO; /* for our $x () */
sv->op_type = OP_RV2GV;
sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
}
else if (sv->op_type == OP_PADSV) { /* private variable */
+ iterpflags = sv->op_private & OPpLVAL_INTRO; /* for my $x () */
padoff = sv->op_targ;
sv->op_targ = 0;
op_free(sv);
loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
append_elem(OP_LIST, expr, scalar(sv))));
assert(!loop->op_next);
+ /* for my $x () sets OPpLVAL_INTRO;
+ * for our $x () sets OPpOUR_INTRO; both only used by Deparse.pm */
+ loop->op_private = iterpflags;
#ifdef PL_OP_SLAB_ALLOC
{
LOOP *tmp;
#define OPpEARLY_CV 32 /* foo() called before sub foo was parsed */
/* OP_?ELEM only */
#define OPpLVAL_DEFER 16 /* Defer creation of array/hash elem */
- /* OP_RV2?V, OP_GVSV only */
+ /* OP_RV2?V, OP_GVSV, OP_ENTERITER only */
#define OPpOUR_INTRO 16 /* Variable was in an our() */
/* OP_RV2[AH]V, OP_PAD[AH]V, OP_[AH]ELEM */
#define OPpMAYBE_LVSUB 8 /* We might be an lvalue to return */
# "This IS structured code. It's just randomly structured."
-print "1..28\n";
+print "1..29\n";
while ($?) {
$foo = 1;
}
f1();
+# bug #22181 - this used to coredump or make $x undefined, due to
+# erroneous popping of the inner BLOCK context
+
+for ($i=0; $i<2; $i++) {
+ my $x = 1;
+ goto LABEL29;
+ LABEL29:
+ print "not " if !defined $x || $x != 1;
+}
+print "ok 29 - goto in for(;;) with continuation\n";
+
exit;
bypass:
switches => [ '-Ilib', '-d:switchd' ],
progfile => $filename,
);
- like($r, qr/^main,swdtest.tmp,9;Foo,swdtest.tmp,5;Foo,swdtest.tmp,6;Foo,swdtest.tmp,6;Bar,swdtest.tmp,2;Foo,swdtest.tmp,6;Bar,swdtest.tmp,2;Foo,swdtest.tmp,6;Bar,swdtest.tmp,2;Foo,swdtest.tmp,6;$/i);
+ like($r, qr/^main,swdtest.tmp,9;Foo,swdtest.tmp,5;Foo,swdtest.tmp,6;Foo,swdtest.tmp,6;Bar,swdtest.tmp,2;Bar,swdtest.tmp,2;Bar,swdtest.tmp,2;$/i);
}