Implement OP_ASGN2 NODE locations
This commit is contained in:
parent
027ef60500
commit
8f678d6989
Notes:
git
2024-09-28 11:53:27 +00:00
6
ast.c
6
ast.c
@ -822,6 +822,12 @@ node_locations(VALUE ast_value, const NODE *node)
|
||||
location_new(&RNODE_OP_ASGN1(node)->opening_loc),
|
||||
location_new(&RNODE_OP_ASGN1(node)->closing_loc),
|
||||
location_new(&RNODE_OP_ASGN1(node)->binary_operator_loc));
|
||||
case NODE_OP_ASGN2:
|
||||
return rb_ary_new_from_args(4,
|
||||
location_new(nd_code_loc(node)),
|
||||
location_new(&RNODE_OP_ASGN2(node)->call_operator_loc),
|
||||
location_new(&RNODE_OP_ASGN2(node)->message_loc),
|
||||
location_new(&RNODE_OP_ASGN2(node)->binary_operator_loc));
|
||||
case NODE_REDO:
|
||||
return rb_ary_new_from_args(2,
|
||||
location_new(nd_code_loc(node)),
|
||||
|
@ -560,8 +560,11 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
||||
A_ID(RNODE_OP_ASGN2(node)->nd_vid);
|
||||
}
|
||||
F_ID(nd_mid, RNODE_OP_ASGN2, "operator");
|
||||
LAST_NODE;
|
||||
F_NODE(nd_value, RNODE_OP_ASGN2, "rvalue");
|
||||
F_LOC(call_operator_loc, RNODE_OP_ASGN2);
|
||||
F_LOC(message_loc, RNODE_OP_ASGN2);
|
||||
LAST_NODE;
|
||||
F_LOC(binary_operator_loc, RNODE_OP_ASGN2);
|
||||
return;
|
||||
|
||||
case NODE_OP_ASGN_AND:
|
||||
|
26
parse.y
26
parse.y
@ -1087,7 +1087,7 @@ static rb_node_iasgn_t *rb_node_iasgn_new(struct parser_params *p, ID nd_vid, NO
|
||||
static rb_node_cdecl_t *rb_node_cdecl_new(struct parser_params *p, ID nd_vid, NODE *nd_value, NODE *nd_else, enum rb_parser_shareability shareability, const YYLTYPE *loc);
|
||||
static rb_node_cvasgn_t *rb_node_cvasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
|
||||
static rb_node_op_asgn1_t *rb_node_op_asgn1_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *index, NODE *rvalue, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc);
|
||||
static rb_node_op_asgn2_t *rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc);
|
||||
static rb_node_op_asgn2_t *rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc);
|
||||
static rb_node_op_asgn_or_t *rb_node_op_asgn_or_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc);
|
||||
static rb_node_op_asgn_and_t *rb_node_op_asgn_and_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc);
|
||||
static rb_node_op_cdecl_t *rb_node_op_cdecl_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, ID nd_aid, enum rb_parser_shareability shareability, const YYLTYPE *loc);
|
||||
@ -1195,7 +1195,7 @@ static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE
|
||||
#define NEW_CDECL(v,val,path,share,loc) (NODE *)rb_node_cdecl_new(p,v,val,path,share,loc)
|
||||
#define NEW_CVASGN(v,val,loc) (NODE *)rb_node_cvasgn_new(p,v,val,loc)
|
||||
#define NEW_OP_ASGN1(r,id,idx,rval,loc,c_op_loc,o_loc,c_loc,b_op_loc) (NODE *)rb_node_op_asgn1_new(p,r,id,idx,rval,loc,c_op_loc,o_loc,c_loc,b_op_loc)
|
||||
#define NEW_OP_ASGN2(r,t,i,o,val,loc) (NODE *)rb_node_op_asgn2_new(p,r,val,i,o,t,loc)
|
||||
#define NEW_OP_ASGN2(r,t,i,o,val,loc,c_op_loc,m_loc,b_op_loc) (NODE *)rb_node_op_asgn2_new(p,r,val,i,o,t,loc,c_op_loc,m_loc,b_op_loc)
|
||||
#define NEW_OP_ASGN_OR(i,val,loc) (NODE *)rb_node_op_asgn_or_new(p,i,val,loc)
|
||||
#define NEW_OP_ASGN_AND(i,val,loc) (NODE *)rb_node_op_asgn_and_new(p,i,val,loc)
|
||||
#define NEW_OP_CDECL(v,op,val,share,loc) (NODE *)rb_node_op_cdecl_new(p,v,val,op,share,loc)
|
||||
@ -1454,7 +1454,7 @@ static NODE *node_assign(struct parser_params*,NODE*,NODE*,struct lex_context,co
|
||||
|
||||
static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, const YYLTYPE *loc);
|
||||
static NODE *new_ary_op_assign(struct parser_params *p, NODE *ary, NODE *args, ID op, NODE *rhs, const YYLTYPE *args_loc, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc);
|
||||
static NODE *new_attr_op_assign(struct parser_params *p, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc);
|
||||
static NODE *new_attr_op_assign(struct parser_params *p, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc);
|
||||
static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, const YYLTYPE *loc);
|
||||
static NODE *new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc);
|
||||
|
||||
@ -3278,7 +3278,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs
|
||||
}
|
||||
| primary_value call_op ident_or_const tOP_ASGN lex_ctxt command_rhs
|
||||
{
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$);
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
|
||||
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
|
||||
}
|
||||
| primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt command_rhs
|
||||
@ -3289,7 +3289,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs
|
||||
}
|
||||
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt command_rhs
|
||||
{
|
||||
$$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$);
|
||||
$$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$, &@2, &@3, &@4);
|
||||
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
|
||||
}
|
||||
| defn_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
|
||||
@ -3878,17 +3878,17 @@ arg : lhs '=' lex_ctxt arg_rhs
|
||||
}
|
||||
| primary_value call_op tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs
|
||||
{
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$);
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
|
||||
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
|
||||
}
|
||||
| primary_value call_op tCONSTANT tOP_ASGN lex_ctxt arg_rhs
|
||||
{
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$);
|
||||
$$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
|
||||
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
|
||||
}
|
||||
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs
|
||||
{
|
||||
$$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$);
|
||||
$$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$, &@2, &@3, &@4);
|
||||
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
|
||||
}
|
||||
| primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt arg_rhs
|
||||
@ -11940,7 +11940,7 @@ rb_node_op_asgn1_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *in
|
||||
}
|
||||
|
||||
static rb_node_op_asgn2_t *
|
||||
rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc)
|
||||
rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc)
|
||||
{
|
||||
rb_node_op_asgn2_t *n = NODE_NEWNODE(NODE_OP_ASGN2, rb_node_op_asgn2_t, loc);
|
||||
n->nd_recv = nd_recv;
|
||||
@ -11948,6 +11948,9 @@ rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID
|
||||
n->nd_vid = nd_vid;
|
||||
n->nd_mid = nd_mid;
|
||||
n->nd_aid = nd_aid;
|
||||
n->call_operator_loc = *call_operator_loc;
|
||||
n->message_loc = *message_loc;
|
||||
n->binary_operator_loc = *binary_operator_loc;
|
||||
|
||||
return n;
|
||||
}
|
||||
@ -14849,11 +14852,12 @@ new_ary_op_assign(struct parser_params *p, NODE *ary,
|
||||
|
||||
static NODE *
|
||||
new_attr_op_assign(struct parser_params *p, NODE *lhs,
|
||||
ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc)
|
||||
ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc,
|
||||
const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc)
|
||||
{
|
||||
NODE *asgn;
|
||||
|
||||
asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, loc);
|
||||
asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, loc, call_operator_loc, message_loc, binary_operator_loc);
|
||||
fixpos(asgn, lhs);
|
||||
return asgn;
|
||||
}
|
||||
|
@ -469,6 +469,9 @@ typedef struct RNode_OP_ASGN2 {
|
||||
ID nd_vid;
|
||||
ID nd_mid;
|
||||
bool nd_aid;
|
||||
rb_code_location_t call_operator_loc;
|
||||
rb_code_location_t message_loc;
|
||||
rb_code_location_t binary_operator_loc;
|
||||
} rb_node_op_asgn2_t;
|
||||
|
||||
typedef struct RNode_OP_ASGN_AND {
|
||||
|
@ -1397,6 +1397,20 @@ dummy
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 6], [1, 2, 1, 4]])
|
||||
end
|
||||
|
||||
def test_op_asgn2_locations
|
||||
node = ast_parse("a.b += 1")
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 8], [1, 1, 1, 2], [1, 2, 1, 3], [1, 4, 1, 6]])
|
||||
|
||||
node = ast_parse("A::B.c += d")
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 11], [1, 4, 1, 5], [1, 5, 1, 6], [1, 7, 1, 9]])
|
||||
|
||||
node = ast_parse("a = b.c += d")
|
||||
assert_locations(node.children[-1].children[-1].locations, [[1, 4, 1, 12], [1, 5, 1, 6], [1, 6, 1, 7], [1, 8, 1, 10]])
|
||||
|
||||
node = ast_parse("a = A::B.c += d")
|
||||
assert_locations(node.children[-1].children[-1].locations, [[1, 4, 1, 15], [1, 8, 1, 9], [1, 9, 1, 10], [1, 11, 1, 13]])
|
||||
end
|
||||
|
||||
def test_redo_locations
|
||||
node = ast_parse("loop { redo }")
|
||||
assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 7, 1, 11], [1, 7, 1, 11]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user