diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-11-20 09:23:35 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-11-20 20:17:18 -0800 |
commit | 34b54951568575920f2307bea918f5549bd5a82f (patch) | |
tree | aea97f1e1778d7276ecf9b14e817a5f77965109d /perly.y | |
parent | 05be69bb15d7a722ee6bca574d29b98314e34918 (diff) | |
download | perl-34b54951568575920f2307bea918f5549bd5a82f.tar.gz |
[perl #77452] Deparse { ...; BEGIN{} } correctly
8635e3c2 (5.21.6) changed the COP sequence numbers for nested blocks,
such that most BEGIN blocks (incl. ‘use’ statements) and sub declara-
tions end up in the right place. However, it had the side effect of
causing declarations at the end of the enclosing scope to fall out of
it and appear below.
This commit fixes that by adding an extra nulled COP to the end of the
enclosing scope if that scope ends with a sub, so the final declara-
tion gets deparsed before it.
The frequency of sub declarations at the end of the enclosing scope is
sufficiently low (I’m guessing a bit here) that this slight increase
in run-time memory usage is probably acceptable.
I had to change B::Deparse to deparse nulled COPs the same way it does
live COPs, which means we get more extraneous semicolons than before.
I hope to fix that in a forthcoming commit. I also ran into a B bug,
in that null ops are not presented to Perl code with the right op
class (see the blessing in the patch). I plan to fix that in a separ-
ate commit, too.
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -194,7 +194,8 @@ formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.' ; remember: /* NULL */ /* start a full lexical scope */ - { $$ = block_start(TRUE); } + { $$ = block_start(TRUE); + parser->parsed_sub = 0; } ; mblock : '{' mremember stmtseq '}' @@ -205,7 +206,8 @@ mblock : '{' mremember stmtseq '}' ; mremember: /* NULL */ /* start a partial lexical scope */ - { $$ = block_start(FALSE); } + { $$ = block_start(FALSE); + parser->parsed_sub = 0; } ; /* A sequence of statements in the program */ @@ -293,6 +295,7 @@ barestmt: PLUGSTMT ; $$ = (OP*)NULL; intro_my(); + parser->parsed_sub = 1; } | PACKAGE WORD WORD ';' { @@ -307,6 +310,7 @@ barestmt: PLUGSTMT { SvREFCNT_inc_simple_void(PL_compcv); utilize($1, $2, $4, $5, $6); + parser->parsed_sub = 1; $$ = (OP*)NULL; } | IF '(' remember mexpr ')' mblock else |