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;
# endif
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)
@ -2271,13 +2270,12 @@ primary : literal
}
| k_begin
{
$<val>1 = p->cmdarg_stack;
CMDARG_SET(0);
CMDARG_PUSH(0);
}
bodystmt
k_end
{
CMDARG_SET($<val>1);
CMDARG_POP();
/*%%%*/
set_line_body($3, @1.end_pos.lineno);
$$ = NEW_BEGIN($3, &@$);
@ -3267,14 +3265,14 @@ brace_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
{
/*%%%*/
$$ = NEW_ITER($3, $4, &@$);
/*% %*/
/*% ripper: do_block!(escape_Qundef($3), $4) %*/
CMDARG_SET($<val>2);
CMDARG_POP();
dyna_pop(p, $<vars>1);
}
;
@ -3621,10 +3619,8 @@ string_content : tSTRING_CONTENT
}
| tSTRING_DBEG
{
$<val>1 = p->cond_stack;
$<val>$ = p->cmdarg_stack;
COND_SET(0);
CMDARG_SET(0);
CMDARG_PUSH(0);
COND_PUSH(0);
}
{
/* 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
{
COND_SET($<val>1);
CMDARG_SET($<val>2);
COND_POP();
CMDARG_POP();
p->lex.strterm = $<strterm>3;
SET_LEX_STATE($<num>4);
p->lex.brace_nest = $<num>5;
@ -8006,10 +8002,11 @@ parser_yylex(struct parser_params *p)
return c;
case '}':
/* tSTRING_DEND does COND_POP and CMDARG_POP in the yacc's rule */
if (!p->lex.brace_nest--) return tSTRING_DEND;
COND_POP();
CMDARG_POP();
SET_LEX_STATE(EXPR_END);
if (!p->lex.brace_nest--) return tSTRING_DEND;
p->lex.paren_nest--;
return c;
@ -10260,10 +10257,8 @@ local_push(struct parser_params *p, int toplevel_scope)
# if WARN_PAST_SCOPE
local->past = 0;
# endif
local->cmdargs = p->cmdarg_stack;
CMDARG_SET(0);
local->cond = p->cond_stack;
COND_SET(0);
CMDARG_PUSH(0);
COND_PUSH(0);
p->lvtbl = local;
}
@ -10284,8 +10279,8 @@ local_pop(struct parser_params *p)
# endif
vtable_free(p->lvtbl->args);
vtable_free(p->lvtbl->vars);
CMDARG_SET(p->lvtbl->cmdargs);
COND_SET(p->lvtbl->cond);
CMDARG_POP();
COND_POP();
xfree(p->lvtbl);
p->lvtbl = local;
}

View file

@ -1149,6 +1149,14 @@ x = __ENCODING__
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
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}