diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-25 16:53:29 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-25 18:23:05 +0900 |
commit | 6aa16f9ec14a296f549dc955774ad2293d1c54d6 (patch) | |
tree | 39498c84bbdf2d7edd499d6e60642c1ca34cb908 /parse.y | |
parent | d9cba2fc74addc3e0a6da0fe230fd333fb1c31ac (diff) |
Move SCRIPT_LINES__ away from parse.y
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8289
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 60 |
1 files changed, 15 insertions, 45 deletions
@@ -151,26 +151,6 @@ literal_hash(VALUE a) return rb_iseq_cdhash_hash(a); } -static ID -script_lines(void) -{ - ID script_lines; - CONST_ID(script_lines, "SCRIPT_LINES__"); - return script_lines; -} - -static int -script_lines_defined(void) -{ - return rb_const_defined_at(rb_cObject, script_lines()); -} - -static VALUE -script_lines_get(void) -{ - return rb_const_get_at(rb_cObject, script_lines()); -} - static VALUE syntax_error_new(void) { @@ -550,7 +530,6 @@ struct parser_params { unsigned int do_loop: 1; unsigned int do_chomp: 1; unsigned int do_split: 1; - unsigned int keep_script_lines: 1; unsigned int error_tolerant: 1; unsigned int keep_tokens: 1; @@ -6844,20 +6823,6 @@ static void parser_prepare(struct parser_params *p); #ifndef RIPPER static NODE *parser_append_options(struct parser_params *p, NODE *node); -static VALUE -debug_lines(struct parser_params *p, VALUE fname) -{ - if (script_lines_defined()) { - VALUE hash = script_lines_get(); - if (RB_TYPE_P(hash, T_HASH)) { - VALUE lines = rb_ary_new(); - rb_hash_aset(hash, fname, lines); - return lines; - } - } - return 0; -} - static int e_option_supplied(struct parser_params *p) { @@ -6873,7 +6838,6 @@ yycompile0(VALUE arg) int cov = FALSE; if (!compile_for_eval && !NIL_P(p->ruby_sourcefile_string)) { - p->debug_lines = debug_lines(p, p->ruby_sourcefile_string); if (p->debug_lines && p->ruby_sourceline > 0) { VALUE str = rb_default_rs; n = p->ruby_sourceline; @@ -6887,11 +6851,7 @@ yycompile0(VALUE arg) } } - if (p->keep_script_lines || ruby_vm_keep_script_lines) { - if (!p->debug_lines) { - p->debug_lines = rb_ary_new(); - } - + if (p->debug_lines) { RB_OBJ_WRITE(p->ast, &p->ast->body.script_lines, p->debug_lines); } @@ -13983,9 +13943,19 @@ rb_ruby_parser_set_context(rb_parser_t *p, const struct rb_iseq_struct *base, in } void -rb_ruby_parser_keep_script_lines(rb_parser_t *p) +rb_ruby_parser_set_script_lines(rb_parser_t *p, VALUE lines) { - p->keep_script_lines = 1; + if (!RTEST(lines)) { + lines = Qfalse; + } + else if (lines == Qtrue) { + lines = rb_ary_new(); + } + else { + Check_Type(lines, T_ARRAY); + rb_ary_modify(lines); + } + p->debug_lines = lines; } void @@ -14073,12 +14043,12 @@ rb_parser_error_tolerant(VALUE vparser) } void -rb_parser_keep_script_lines(VALUE vparser) +rb_parser_set_script_lines(VALUE vparser, VALUE lines) { struct parser_params *p; TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p); - rb_ruby_parser_keep_script_lines(p); + rb_ruby_parser_set_script_lines(p, lines); } void |