From b43afa0a8f82a5d806adc24afa2eaf41479da1a3 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 4 Oct 2019 01:48:31 +0900 Subject: 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. --- compile.c | 12 ++++-------- internal.h | 7 ++++--- iseq.c | 2 +- parse.y | 12 ++++++------ vm_eval.c | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/compile.c b/compile.c index 78d2fd4dd0..7a88f81daa 100644 --- a/compile.c +++ b/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; diff --git a/internal.h b/internal.h index 2346703d68..7d24e33bd1 100644 --- a/internal.h +++ b/internal.h @@ -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); diff --git a/iseq.c b/iseq.c index ae7b1cc30a..d7e8cce821 100644 --- a/iseq.c +++ b/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); } diff --git a/parse.y b/parse.y index 651e2cea6e..8ff7b8aa29 100644 --- a/parse.y +++ b/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 diff --git a/vm_eval.c b/vm_eval.c index 1c205f0a30..07af3b4b58 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -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, -- cgit v1.2.3