mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make parser_params have parent_iseq instead of base_block
The parser needs to determine whether a local varaiable is defined or not in outer scope. For the sake, "base_block" field has kept the outer block. However, the whole block was actually unneeded; the parser used only base_block->iseq. So, this change lets parser_params have the iseq directly, instead of the whole block.
This commit is contained in:
parent
711c40ebdc
commit
b43afa0a8f
Notes:
git
2019-10-04 02:31:06 +09:00
5 changed files with 16 additions and 19 deletions
12
compile.c
12
compile.c
|
@ -9123,11 +9123,9 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params,
|
|||
/* for parser */
|
||||
|
||||
int
|
||||
rb_dvar_defined(ID id, const struct rb_block *base_block)
|
||||
rb_dvar_defined(ID id, const rb_iseq_t *iseq)
|
||||
{
|
||||
const rb_iseq_t *iseq;
|
||||
|
||||
if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
|
||||
if (iseq) {
|
||||
const struct rb_iseq_constant_body *body = iseq->body;
|
||||
while (body->type == ISEQ_TYPE_BLOCK ||
|
||||
body->type == ISEQ_TYPE_RESCUE ||
|
||||
|
@ -9150,11 +9148,9 @@ rb_dvar_defined(ID id, const struct rb_block *base_block)
|
|||
}
|
||||
|
||||
int
|
||||
rb_local_defined(ID id, const struct rb_block *base_block)
|
||||
rb_local_defined(ID id, const rb_iseq_t *iseq)
|
||||
{
|
||||
const rb_iseq_t *iseq;
|
||||
|
||||
if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
|
||||
if (iseq) {
|
||||
unsigned int i;
|
||||
const struct rb_iseq_constant_body *const body = iseq->body->local_iseq->body;
|
||||
|
||||
|
|
|
@ -1457,8 +1457,9 @@ VALUE rb_invcmp(VALUE, VALUE);
|
|||
|
||||
/* compile.c */
|
||||
struct rb_block;
|
||||
int rb_dvar_defined(ID, const struct rb_block *);
|
||||
int rb_local_defined(ID, const struct rb_block *);
|
||||
struct rb_iseq_struct;
|
||||
int rb_dvar_defined(ID, const struct rb_iseq_struct *);
|
||||
int rb_local_defined(ID, const struct rb_iseq_struct *);
|
||||
const char * rb_insns_name(int i);
|
||||
VALUE rb_insns_name_array(void);
|
||||
int rb_vm_insn_addr2insn(const void *);
|
||||
|
@ -1954,7 +1955,7 @@ struct RBasicRaw {
|
|||
VALUE rb_parser_get_yydebug(VALUE);
|
||||
VALUE rb_parser_set_yydebug(VALUE, VALUE);
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
VALUE rb_parser_set_context(VALUE, const struct rb_block *, int);
|
||||
VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int);
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
void *rb_parser_load_file(VALUE parser, VALUE name);
|
||||
int rb_is_const_name(VALUE name);
|
||||
|
|
2
iseq.c
2
iseq.c
|
@ -994,7 +994,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c
|
|||
}
|
||||
{
|
||||
const VALUE parser = rb_parser_new();
|
||||
rb_parser_set_context(parser, base_block, FALSE);
|
||||
rb_parser_set_context(parser, parent, FALSE);
|
||||
ast = (*parse)(parser, file, src, ln);
|
||||
}
|
||||
|
||||
|
|
12
parse.y
12
parse.y
|
@ -294,7 +294,7 @@ struct parser_params {
|
|||
NODE *eval_tree;
|
||||
VALUE error_buffer;
|
||||
VALUE debug_lines;
|
||||
const struct rb_block *base_block;
|
||||
const rb_iseq_t *parent_iseq;
|
||||
|
||||
struct {
|
||||
NODE *outer, *inner, *current;
|
||||
|
@ -329,7 +329,7 @@ static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const ch
|
|||
#ifdef RIPPER
|
||||
#define compile_for_eval (0)
|
||||
#else
|
||||
#define compile_for_eval (p->base_block != 0)
|
||||
#define compile_for_eval (p->parent_iseq != 0)
|
||||
#endif
|
||||
|
||||
#define token_column ((int)(p->lex.ptok - p->lex.pbeg))
|
||||
|
@ -11777,7 +11777,7 @@ local_id_ref(struct parser_params *p, ID id, ID **vidrefp)
|
|||
}
|
||||
|
||||
if (vars && vars->prev == DVARS_INHERIT) {
|
||||
return rb_local_defined(id, p->base_block);
|
||||
return rb_local_defined(id, p->parent_iseq);
|
||||
}
|
||||
else if (vtable_included(args, id)) {
|
||||
return 1;
|
||||
|
@ -11920,7 +11920,7 @@ dvar_defined_ref(struct parser_params *p, ID id, ID **vidrefp)
|
|||
}
|
||||
|
||||
if (vars == DVARS_INHERIT) {
|
||||
return rb_dvar_defined(id, p->base_block);
|
||||
return rb_dvar_defined(id, p->parent_iseq);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -12301,13 +12301,13 @@ rb_parser_new(void)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_parser_set_context(VALUE vparser, const struct rb_block *base, int main)
|
||||
rb_parser_set_context(VALUE vparser, const rb_iseq_t *base, int main)
|
||||
{
|
||||
struct parser_params *p;
|
||||
|
||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
||||
p->error_buffer = main ? Qfalse : Qnil;
|
||||
p->base_block = base;
|
||||
p->parent_iseq = base;
|
||||
return vparser;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1579,7 +1579,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind,
|
|||
fname = rb_fstring_lit("(eval)");
|
||||
}
|
||||
|
||||
rb_parser_set_context(parser, base_block, FALSE);
|
||||
rb_parser_set_context(parser, parent, FALSE);
|
||||
ast = rb_parser_compile_string_path(parser, fname, src, line);
|
||||
if (ast->body.root) {
|
||||
iseq = rb_iseq_new_with_opt(&ast->body,
|
||||
|
|
Loading…
Add table
Reference in a new issue