[前][次][番号順一覧][スレッド一覧]

ruby-changes:67202

From: Yusuke <ko1@a...>
Date: Fri, 20 Aug 2021 16:23:55 +0900 (JST)
Subject: [ruby-changes:67202] cad83fa3c4 (master): ast.c: Rename "save_script_lines" to "keep_script_lines"

https://git.ruby-lang.org/ruby.git/commit/?id=cad83fa3c4

From cad83fa3c4491153df0561b06bb261e25a831d0f Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 20 Aug 2021 16:18:36 +0900
Subject: 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 20c4588..0b6791d 100644
--- a/ast.c
+++ b/ast.c
@@ -64,8 +64,8 @@ ast_new_internal(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L64
     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) https://github.com/ruby/ruby/blob/trunk/ast.c#L85
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/ast.c#L119
     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) https://github.com/ruby/ruby/blob/trunk/ast.c#L139
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/ast.c#L193
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/ast.c#L221
     }
 
     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 34dd3f1..f866bd2 100644
--- a/ast.rb
+++ b/ast.rb
@@ -29,8 +29,8 @@ module RubyVM::AbstractSyntaxTree https://github.com/ruby/ruby/blob/trunk/ast.rb#L29
   #
   #    RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
   #    # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
-  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 https://github.com/ruby/ruby/blob/trunk/ast.rb#L44
   #
   #     RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb")
   #     # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-31:3>
-  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 https://github.com/ruby/ruby/blob/trunk/ast.rb#L63
   #
   #     RubyVM::AbstractSyntaxTree.of(method(:hello))
   #     # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-3:3>
-  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 588b2b3..cb95d76 100644
--- a/internal/parse.h
+++ b/internal/parse.h
@@ -15,7 +15,7 @@ struct rb_iseq_struct;          /* in vm_core.h */ https://github.com/ruby/ruby/blob/trunk/internal/parse.h#L15
 /* 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 1e91deb..1ae180a 100644
--- a/lib/error_highlight/core_ext.rb
+++ b/lib/error_highlight/core_ext.rb
@@ -16,7 +16,7 @@ module ErrorHighlight https://github.com/ruby/ruby/blob/trunk/lib/error_highlight/core_ext.rb#L16
 
       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 897b468..65c90a7 100644
--- a/parse.y
+++ b/parse.y
@@ -337,7 +337,7 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L337
     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) https://github.com/ruby/ruby/blob/trunk/parse.y#L6251
 	    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 https://github.com/ruby/ruby/blob/trunk/parse.y#L13197
 }
 
 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 3b4cbc7..3af67b1 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -393,8 +393,8 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L393
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L432
     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)
  (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]