summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorydah <[email protected]>2024-09-27 23:55:48 +0900
committerYudai Takada <[email protected]>2025-01-03 23:03:04 +0900
commitc22b0598b0dd197a49212e06cfc91e4a3f2e058c ()
tree995b0050ace7bea2cdad77398d293802c57bc3bb
parent5cc4240dda72582456dc271ec580178d070197a9 (diff)
Implement SUPER NODE locations
Notes: Merged: https://.com/ruby/ruby/pull/11712
-rw-r--r--ast.c6
-rw-r--r--node_dump.c5
-rw-r--r--parse.y19
-rw-r--r--rubyparser.h3
-rw-r--r--test/ruby/test_ast.rb8
5 files changed, 35 insertions, 6 deletions
@@ -846,6 +846,12 @@ node_locations(VALUE ast_value, const NODE *node)
return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)),
location_new(&RNODE_SPLAT(node)->operator_loc));
case NODE_UNDEF:
return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)),
@@ -646,8 +646,11 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
ANN("super invocation");
ANN("format: super [nd_args]");
ANN("example: super 1");
- LAST_NODE;
F_NODE(nd_args, RNODE_SUPER, "arguments");
return;
case NODE_ZSUPER:
@@ -1094,7 +1094,7 @@ static rb_node_opcall_t *rb_node_opcall_new(struct parser_params *p, NODE *nd_re
static rb_node_fcall_t *rb_node_fcall_new(struct parser_params *p, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
static rb_node_vcall_t *rb_node_vcall_new(struct parser_params *p, ID nd_mid, const YYLTYPE *loc);
static rb_node_qcall_t *rb_node_qcall_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
-static rb_node_super_t *rb_node_super_new(struct parser_params *p, NODE *nd_args, const YYLTYPE *loc);
static rb_node_zsuper_t * rb_node_zsuper_new(struct parser_params *p, const YYLTYPE *loc);
static rb_node_list_t *rb_node_list_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
static rb_node_list_t *rb_node_list_new2(struct parser_params *p, NODE *nd_head, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
@@ -1202,7 +1202,7 @@ static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE
#define NEW_FCALL(m,a,loc) rb_node_fcall_new(p,m,a,loc)
#define NEW_VCALL(m,loc) (NODE *)rb_node_vcall_new(p,m,loc)
#define NEW_QCALL0(r,m,a,loc) (NODE *)rb_node_qcall_new(p,r,m,a,loc)
-#define NEW_SUPER(a,loc) (NODE *)rb_node_super_new(p,a,loc)
#define NEW_ZSUPER(loc) (NODE *)rb_node_zsuper_new(p,loc)
#define NEW_LIST(a,loc) (NODE *)rb_node_list_new(p,a,loc)
#define NEW_LIST2(h,l,n,loc) (NODE *)rb_node_list_new2(p,h,l,n,loc)
@@ -3509,7 +3509,7 @@ command : fcall command_args %prec tLOWEST
}
| keyword_super command_args
{
- $$ = NEW_SUPER($2, &@$);
fixpos($$, $2);
/*% ripper: super!($:2) %*/
}
@@ -5316,7 +5316,12 @@ method_call : fcall paren_args
}
| keyword_super paren_args
{
- $$ = NEW_SUPER($2, &@$);
/*% ripper: super!($:2) %*/
}
| keyword_super
@@ -11749,10 +11754,14 @@ rb_node_false_new(struct parser_params *p, const YYLTYPE *loc)
}
static rb_node_super_t *
-rb_node_super_new(struct parser_params *p, NODE *nd_args, const YYLTYPE *loc)
{
rb_node_super_t *n = NODE_NEWNODE(NODE_SUPER, rb_node_super_t, loc);
n->nd_args = nd_args;
return n;
}
@@ -541,6 +541,9 @@ typedef struct RNode_SUPER {
NODE node;
struct RNode *nd_args;
} rb_node_super_t;
typedef struct RNode_ZSUPER {
@@ -1456,6 +1456,14 @@ dummy
assert_locations(node.children[-1].children[1].children[0].children[0].locations, [[1, 13, 1, 15], [1, 13, 1, 14]])
end
def test_unless_locations
node = ast_parse("unless cond then 1 else 2 end")
assert_locations(node.children[-1].locations, [[1, 0, 1, 29], [1, 0, 1, 6], [1, 12, 1, 16], [1, 26, 1, 29]])