summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2005-05-07 12:57:06 +0000
committerDave Mitchell <davem@fdisolutions.com>2005-05-07 12:57:06 +0000
commita034e688aeb372632feafc428b392a22393dec55 (patch)
tree00edd69325fa45e86f3a3a37b5ef01820d454559 /perly.y
parent5203fbcae61b42c66ba138a48162ecc0880db2c9 (diff)
downloadperl-a034e688aeb372632feafc428b392a22393dec55.tar.gz
while (my $x ...) { ...; redo } shouldn't undef $x.
In the presence of 'my' in the conditional of a while(), until(), or for(;;) loop, add an extra scope to the body so that redo doesn't undef the lexical p4raw-id: //depot/perl@24412
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y29
1 files changed, 16 insertions, 13 deletions
diff --git a/perly.y b/perly.y
index 2d989b3a30..308176f88b 100644
--- a/perly.y
+++ b/perly.y
@@ -48,11 +48,11 @@
%token <ival> LOCAL MY MYSUB
%token COLONATTR
-%type <ival> prog decl format startsub startanonsub startformsub
+%type <ival> prog decl format startsub startanonsub startformsub mintro
%type <ival> progstart remember mremember '&' savescope
%type <opval> block mblock lineseq line loop cond else
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
-%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr
+%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr
%type <opval> listexpr listexprcom indirob listop method
%type <opval> formname subname proto subbody cont my_scalar
%type <opval> subattrlist myattrlist mysubrout myattrterm myterm
@@ -207,18 +207,18 @@ cont : /* NULL */
;
/* Loops: while, until, for, and a bare block */
-loop : label WHILE '(' remember mtexpr ')' mblock cont
+loop : label WHILE '(' remember texpr ')' mintro mblock cont
{ PL_copline = (line_t)$2;
$$ = block_end($4,
newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
- $2, $5, $7, $8))); }
- | label UNTIL '(' remember miexpr ')' mblock cont
+ $2, $5, $8, $9, $7))); }
+ | label UNTIL '(' remember iexpr ')' mintro mblock cont
{ PL_copline = (line_t)$2;
$$ = block_end($4,
newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
- $2, $5, $7, $8))); }
+ $2, $5, $8, $9, $7))); }
| label FOR MY remember my_scalar '(' mexpr ')' mblock cont
{ $$ = block_end($4,
newFOROP(0, $1, (line_t)$2, $5, $7, $9, $10)); }
@@ -229,14 +229,15 @@ loop : label WHILE '(' remember mtexpr ')' mblock cont
| label FOR '(' remember mexpr ')' mblock cont
{ $$ = block_end($4,
newFOROP(0, $1, (line_t)$2, Nullop, $5, $7, $8)); }
- | label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock
+ | label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
+ mblock
/* basically fake up an initialize-while lineseq */
{ OP *forop;
PL_copline = (line_t)$2;
forop = newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
$2, scalar($7),
- $11, $9));
+ $12, $10, $9));
if ($5) {
forop = append_elem(OP_LINESEQ,
newSTATEOP(0, ($1?savepv($1):Nullch),
@@ -248,9 +249,15 @@ loop : label WHILE '(' remember mtexpr ')' mblock cont
| label block cont /* a block is a loop that happens once */
{ $$ = newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
- NOLINE, Nullop, $2, $3)); }
+ NOLINE, Nullop, $2, $3, 0)); }
;
+/* determine whether there are any new my declarations */
+mintro : /* NULL */
+ { $$ = (PL_min_intro_pending &&
+ PL_max_intro_pending >= PL_min_intro_pending);
+ intro_my(); }
+
/* Normal expression */
nexpr : /* NULL */
{ $$ = Nullop; }
@@ -277,10 +284,6 @@ mnexpr : nexpr
{ $$ = $1; intro_my(); }
;
-mtexpr : texpr
- { $$ = $1; intro_my(); }
- ;
-
miexpr : iexpr
{ $$ = $1; intro_my(); }
;