From cad83fa3c4491153df0561b06bb261e25a831d0f Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 20 Aug 2021 16:18:36 +0900 Subject: [PATCH] ast.c: Rename "save_script_lines" to "keep_script_lines" ... as per ko1's preference. He is preparing to extend this feature to ISeq for his new debugger. He prefers "keep" to "save" for this wording. This API is internal and not included in any released version, so I change it in advance. --- ast.c | 32 ++++++++++++++++---------------- ast.rb | 12 ++++++------ internal/parse.h | 2 +- lib/error_highlight/core_ext.rb | 2 +- parse.y | 8 ++++---- test/ruby/test_ast.rb | 12 ++++++------ 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ast.c b/ast.c index 20c4588cd7..0b6791d221 100644 --- a/ast.c +++ b/ast.c @@ -64,8 +64,8 @@ ast_new_internal(rb_ast_t *ast, const NODE *node) return obj; } -static VALUE rb_ast_parse_str(VALUE str, VALUE save_script_lines); -static VALUE rb_ast_parse_file(VALUE path, VALUE save_script_lines); +static VALUE rb_ast_parse_str(VALUE str, VALUE keep_script_lines); +static VALUE rb_ast_parse_file(VALUE path, VALUE keep_script_lines); static VALUE ast_parse_new(void) @@ -85,31 +85,31 @@ ast_parse_done(rb_ast_t *ast) } static VALUE -ast_s_parse(rb_execution_context_t *ec, VALUE module, VALUE str, VALUE save_script_lines) +ast_s_parse(rb_execution_context_t *ec, VALUE module, VALUE str, VALUE keep_script_lines) { - return rb_ast_parse_str(str, save_script_lines); + return rb_ast_parse_str(str, keep_script_lines); } static VALUE -rb_ast_parse_str(VALUE str, VALUE save_script_lines) +rb_ast_parse_str(VALUE str, VALUE keep_script_lines) { rb_ast_t *ast = 0; StringValue(str); VALUE vparser = ast_parse_new(); - if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser); + if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser); ast = rb_parser_compile_string_path(vparser, Qnil, str, 1); return ast_parse_done(ast); } static VALUE -ast_s_parse_file(rb_execution_context_t *ec, VALUE module, VALUE path, VALUE save_script_lines) +ast_s_parse_file(rb_execution_context_t *ec, VALUE module, VALUE path, VALUE keep_script_lines) { - return rb_ast_parse_file(path, save_script_lines); + return rb_ast_parse_file(path, keep_script_lines); } static VALUE -rb_ast_parse_file(VALUE path, VALUE save_script_lines) +rb_ast_parse_file(VALUE path, VALUE keep_script_lines) { VALUE f; rb_ast_t *ast = 0; @@ -119,7 +119,7 @@ rb_ast_parse_file(VALUE path, VALUE save_script_lines) f = rb_file_open_str(path, "r"); rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-")); VALUE vparser = ast_parse_new(); - if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser); + if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser); ast = rb_parser_compile_file_path(vparser, Qnil, f, 1); rb_io_close(f); return ast_parse_done(ast); @@ -139,13 +139,13 @@ lex_array(VALUE array, int index) } static VALUE -rb_ast_parse_array(VALUE array, VALUE save_script_lines) +rb_ast_parse_array(VALUE array, VALUE keep_script_lines) { rb_ast_t *ast = 0; array = rb_check_array_type(array); VALUE vparser = ast_parse_new(); - if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser); + if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser); ast = rb_parser_compile_generic(vparser, lex_array, Qnil, array, 1); return ast_parse_done(ast); } @@ -193,7 +193,7 @@ script_lines(VALUE path) } static VALUE -ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE save_script_lines) +ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines) { VALUE path, node, lines; int node_id; @@ -221,13 +221,13 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE save_script } if (!NIL_P(lines = script_lines(path))) { - node = rb_ast_parse_array(lines, save_script_lines); + node = rb_ast_parse_array(lines, keep_script_lines); } else if (RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0) { - node = rb_ast_parse_str(rb_e_script, save_script_lines); + node = rb_ast_parse_str(rb_e_script, keep_script_lines); } else { - node = rb_ast_parse_file(path, save_script_lines); + node = rb_ast_parse_file(path, keep_script_lines); } return node_find(node, node_id); diff --git a/ast.rb b/ast.rb index 34dd3f1d49..f866bd23e5 100644 --- a/ast.rb +++ b/ast.rb @@ -29,8 +29,8 @@ module RubyVM::AbstractSyntaxTree # # RubyVM::AbstractSyntaxTree.parse("x = 1 + 2") # # => # - def self.parse string, save_script_lines: false - Primitive.ast_s_parse string, save_script_lines + def self.parse string, keep_script_lines: false + Primitive.ast_s_parse string, keep_script_lines end # call-seq: @@ -44,8 +44,8 @@ module RubyVM::AbstractSyntaxTree # # RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb") # # => # - def self.parse_file pathname, save_script_lines: false - Primitive.ast_s_parse_file pathname, save_script_lines + def self.parse_file pathname, keep_script_lines: false + Primitive.ast_s_parse_file pathname, keep_script_lines end # call-seq: @@ -63,8 +63,8 @@ module RubyVM::AbstractSyntaxTree # # RubyVM::AbstractSyntaxTree.of(method(:hello)) # # => # - def self.of body, save_script_lines: false - Primitive.ast_s_of body, save_script_lines + def self.of body, keep_script_lines: false + Primitive.ast_s_of body, keep_script_lines end # RubyVM::AbstractSyntaxTree::Node instances are created by parse methods in diff --git a/internal/parse.h b/internal/parse.h index 588b2b34da..cb95d76a6c 100644 --- a/internal/parse.h +++ b/internal/parse.h @@ -15,7 +15,7 @@ struct rb_iseq_struct; /* in vm_core.h */ /* parse.y */ VALUE rb_parser_set_yydebug(VALUE, VALUE); void *rb_parser_load_file(VALUE parser, VALUE name); -void rb_parser_save_script_lines(VALUE vparser); +void rb_parser_keep_script_lines(VALUE vparser); RUBY_SYMBOL_EXPORT_BEGIN VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int); diff --git a/lib/error_highlight/core_ext.rb b/lib/error_highlight/core_ext.rb index 1e91debc0c..1ae180aeac 100644 --- a/lib/error_highlight/core_ext.rb +++ b/lib/error_highlight/core_ext.rb @@ -16,7 +16,7 @@ module ErrorHighlight loc = locs.first begin - node = RubyVM::AbstractSyntaxTree.of(loc, save_script_lines: true) + node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) opts = {} case self diff --git a/parse.y b/parse.y index 897b46838e..65c90a7a68 100644 --- a/parse.y +++ b/parse.y @@ -337,7 +337,7 @@ struct parser_params { unsigned int do_loop: 1; unsigned int do_chomp: 1; unsigned int do_split: 1; - unsigned int save_script_lines: 1; + unsigned int keep_script_lines: 1; NODE *eval_tree_begin; NODE *eval_tree; @@ -6251,7 +6251,7 @@ yycompile0(VALUE arg) cov = Qtrue; } } - if (p->save_script_lines) { + if (p->keep_script_lines) { if (!p->debug_lines) { p->debug_lines = rb_ary_new(); } @@ -13197,12 +13197,12 @@ rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main } void -rb_parser_save_script_lines(VALUE vparser) +rb_parser_keep_script_lines(VALUE vparser) { struct parser_params *p; TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p); - p->save_script_lines = 1; + p->keep_script_lines = 1; } #endif diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 3b4cbc7dee..3af67b1495 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -393,8 +393,8 @@ class TestAst < Test::Unit::TestCase assert_equal(:a, args.children[rest]) end - def test_save_script_lines_for_parse - node = RubyVM::AbstractSyntaxTree.parse(<<~END, save_script_lines: true) + def test_keep_script_lines_for_parse + node = RubyVM::AbstractSyntaxTree.parse(<<~END, keep_script_lines: true) 1.times do 2.times do end @@ -432,14 +432,14 @@ dummy assert_equal(expected, node.children.last.children.last.children.last.source) end - def test_save_script_lines_for_of + def test_keep_script_lines_for_of proc = Proc.new { 1 + 2 } method = self.method(__method__) - node_proc = RubyVM::AbstractSyntaxTree.of(proc, save_script_lines: true) - node_method = RubyVM::AbstractSyntaxTree.of(method, save_script_lines: true) + node_proc = RubyVM::AbstractSyntaxTree.of(proc, keep_script_lines: true) + node_method = RubyVM::AbstractSyntaxTree.of(method, keep_script_lines: true) assert_equal("{ 1 + 2 }", node_proc.source) - assert_equal("def test_save_script_lines_for_of\n", node_method.source.lines.first) + assert_equal("def test_keep_script_lines_for_of\n", node_method.source.lines.first) end end