Skip to content

Commit

Permalink
Set SCRIPT_LINES__ outside of parser
Browse files Browse the repository at this point in the history
Parser should not depend on functions defiend on "ruby_parser.c".
  • Loading branch information
yui-knk committed Apr 26, 2024
1 parent 500586b commit 140c59c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion internal/ruby_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ VALUE rb_parser_end_seen_p(VALUE);
VALUE rb_parser_encoding(VALUE);
VALUE rb_parser_set_yydebug(VALUE, VALUE);
VALUE rb_parser_build_script_lines_from(rb_parser_ary_t *script_lines);
void rb_parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *script_lines);
void rb_parser_set_options(VALUE, int, int, int, int);
VALUE rb_parser_load_file(VALUE parser, VALUE name);
void rb_parser_set_script_lines(VALUE vparser);
Expand Down
1 change: 0 additions & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -7722,7 +7722,6 @@ yycompile0(VALUE arg)
n = yyparse(p);
RUBY_DTRACE_PARSE_HOOK(END);

rb_parser_aset_script_lines_for(p->ruby_sourcefile_string, p->debug_lines);
p->debug_lines = 0;

xfree(p->lex.strterm);
Expand Down
22 changes: 16 additions & 6 deletions ruby_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ lex_get_str(struct parser_params *p, rb_parser_input_data input, int line_count)
return rb_parser_lex_get_str((struct lex_pointer_string *)input);
}

static void parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *lines);

static rb_ast_t*
parser_compile(rb_parser_t *p, rb_parser_lex_gets_func *gets, VALUE fname, rb_parser_input_data input, int line)
{
rb_ast_t *ast = rb_parser_compile(p, gets, fname, input, line);
parser_aset_script_lines_for(fname, ast->body.script_lines);
return ast;
}

static rb_ast_t*
parser_compile_string0(struct ruby_parser *parser, VALUE fname, VALUE s, int line)
{
Expand All @@ -668,7 +678,7 @@ parser_compile_string0(struct ruby_parser *parser, VALUE fname, VALUE s, int lin
parser->data.lex_str.str = str;
parser->data.lex_str.ptr = 0;

return rb_parser_compile(parser->parser_params, lex_get_str, fname, (rb_parser_input_data)&parser->data, line);
return parser_compile(parser->parser_params, lex_get_str, fname, (rb_parser_input_data)&parser->data, line);
}

static rb_encoding *
Expand Down Expand Up @@ -724,7 +734,7 @@ parser_compile_file_path(struct ruby_parser *parser, VALUE fname, VALUE file, in
parser->type = lex_type_io;
parser->data.lex_io.file = file;

return rb_parser_compile(parser->parser_params, lex_io_gets, fname, (rb_parser_input_data)file, start);
return parser_compile(parser->parser_params, lex_io_gets, fname, (rb_parser_input_data)file, start);
}

static rb_ast_t*
Expand All @@ -733,15 +743,15 @@ parser_compile_array(struct ruby_parser *parser, VALUE fname, VALUE array, int s
parser->type = lex_type_array;
parser->data.lex_array.ary = array;

return rb_parser_compile(parser->parser_params, lex_gets_array, fname, (rb_parser_input_data)array, start);
return parser_compile(parser->parser_params, lex_gets_array, fname, (rb_parser_input_data)array, start);
}

static rb_ast_t*
parser_compile_generic(struct ruby_parser *parser, rb_parser_lex_gets_func *lex_gets, VALUE fname, VALUE input, int start)
{
parser->type = lex_type_generic;

return rb_parser_compile(parser->parser_params, lex_gets, fname, (rb_parser_input_data)input, start);
return parser_compile(parser->parser_params, lex_gets, fname, (rb_parser_input_data)input, start);
}

static void
Expand Down Expand Up @@ -1100,8 +1110,8 @@ rb_node_encoding_val(const NODE *node)
return rb_enc_from_encoding(RNODE_ENCODING(node)->enc);
}

void
rb_parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *lines)
static void
parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *lines)
{
VALUE hash, script_lines;
ID script_lines_id;
Expand Down

0 comments on commit 140c59c

Please sign in to comment.