1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Yusuke Endoh 2021-08-20 16:18:36 +09:00
parent 4c93c124c2
commit cad83fa3c4
6 changed files with 34 additions and 34 deletions

32
ast.c
View file

@ -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);

12
ast.rb
View file

@ -29,8 +29,8 @@ module RubyVM::AbstractSyntaxTree
#
# 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
#
# 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
#
# 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

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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