1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use only CMDARG/COND _PUSH/POP for cmdarg/cond management.

From: Ilya Bylich <ibylich@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-29 03:42:32 +00:00
parent e5a30879f9
commit 9c5d90b516
2 changed files with 22 additions and 19 deletions

33
parse.y
View file

@ -157,7 +157,6 @@ struct local_vars {
struct vtable *past; struct vtable *past;
# endif # endif
struct local_vars *prev; struct local_vars *prev;
stack_type cmdargs, cond; /* XXX: backup for cmdargs_stack and p->cond_stack. Because this is not a part of local variables, refactoring is needed. */
}; };
#define DVARS_INHERIT ((void*)1) #define DVARS_INHERIT ((void*)1)
@ -2271,13 +2270,12 @@ primary : literal
} }
| k_begin | k_begin
{ {
$<val>1 = p->cmdarg_stack; CMDARG_PUSH(0);
CMDARG_SET(0);
} }
bodystmt bodystmt
k_end k_end
{ {
CMDARG_SET($<val>1); CMDARG_POP();
/*%%%*/ /*%%%*/
set_line_body($3, @1.end_pos.lineno); set_line_body($3, @1.end_pos.lineno);
$$ = NEW_BEGIN($3, &@$); $$ = NEW_BEGIN($3, &@$);
@ -3267,14 +3265,14 @@ brace_body : {$<vars>$ = dyna_push(p);}
; ;
do_body : {$<vars>$ = dyna_push(p);} do_body : {$<vars>$ = dyna_push(p);}
{$<val>$ = p->cmdarg_stack; CMDARG_SET(0);} {CMDARG_PUSH(0);}
opt_block_param bodystmt opt_block_param bodystmt
{ {
/*%%%*/ /*%%%*/
$$ = NEW_ITER($3, $4, &@$); $$ = NEW_ITER($3, $4, &@$);
/*% %*/ /*% %*/
/*% ripper: do_block!(escape_Qundef($3), $4) %*/ /*% ripper: do_block!(escape_Qundef($3), $4) %*/
CMDARG_SET($<val>2); CMDARG_POP();
dyna_pop(p, $<vars>1); dyna_pop(p, $<vars>1);
} }
; ;
@ -3621,10 +3619,8 @@ string_content : tSTRING_CONTENT
} }
| tSTRING_DBEG | tSTRING_DBEG
{ {
$<val>1 = p->cond_stack; CMDARG_PUSH(0);
$<val>$ = p->cmdarg_stack; COND_PUSH(0);
COND_SET(0);
CMDARG_SET(0);
} }
{ {
/* need to backup p->lex.strterm so that a string literal `%!foo,#{ !0 },bar!` can be parsed */ /* need to backup p->lex.strterm so that a string literal `%!foo,#{ !0 },bar!` can be parsed */
@ -3645,8 +3641,8 @@ string_content : tSTRING_CONTENT
} }
compstmt tSTRING_DEND compstmt tSTRING_DEND
{ {
COND_SET($<val>1); COND_POP();
CMDARG_SET($<val>2); CMDARG_POP();
p->lex.strterm = $<strterm>3; p->lex.strterm = $<strterm>3;
SET_LEX_STATE($<num>4); SET_LEX_STATE($<num>4);
p->lex.brace_nest = $<num>5; p->lex.brace_nest = $<num>5;
@ -8006,10 +8002,11 @@ parser_yylex(struct parser_params *p)
return c; return c;
case '}': case '}':
/* tSTRING_DEND does COND_POP and CMDARG_POP in the yacc's rule */
if (!p->lex.brace_nest--) return tSTRING_DEND;
COND_POP(); COND_POP();
CMDARG_POP(); CMDARG_POP();
SET_LEX_STATE(EXPR_END); SET_LEX_STATE(EXPR_END);
if (!p->lex.brace_nest--) return tSTRING_DEND;
p->lex.paren_nest--; p->lex.paren_nest--;
return c; return c;
@ -10260,10 +10257,8 @@ local_push(struct parser_params *p, int toplevel_scope)
# if WARN_PAST_SCOPE # if WARN_PAST_SCOPE
local->past = 0; local->past = 0;
# endif # endif
local->cmdargs = p->cmdarg_stack; CMDARG_PUSH(0);
CMDARG_SET(0); COND_PUSH(0);
local->cond = p->cond_stack;
COND_SET(0);
p->lvtbl = local; p->lvtbl = local;
} }
@ -10284,8 +10279,8 @@ local_pop(struct parser_params *p)
# endif # endif
vtable_free(p->lvtbl->args); vtable_free(p->lvtbl->args);
vtable_free(p->lvtbl->vars); vtable_free(p->lvtbl->vars);
CMDARG_SET(p->lvtbl->cmdargs); CMDARG_POP();
COND_SET(p->lvtbl->cond); COND_POP();
xfree(p->lvtbl); xfree(p->lvtbl);
p->lvtbl = local; p->lvtbl = local;
} }

View file

@ -1149,6 +1149,14 @@ x = __ENCODING__
end end
end end
def test_command_def_cmdarg
assert_valid_syntax("\n#{<<~"begin;"}\n#{<<~'end;'}")
begin;
m def x(); end
1.tap do end
end;
end
=begin =begin
def test_past_scope_variable def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}