Merge RNode_OP_ASGN2 and RNode_OP_ASGN22

This commit is contained in:
yui-knk 2023-09-27 21:58:16 +09:00 коммит произвёл Yuichiro Kaneko
Родитель 23bcdda377
Коммит 37a783a30c
5 изменённых файлов: 13 добавлений и 33 удалений

9
ast.c
Просмотреть файл

@ -474,13 +474,10 @@ node_children(rb_ast_t *ast, const NODE *node)
NEW_CHILD(ast, RNODE_ARGSCAT(RNODE_OP_ASGN1(node)->nd_args)->nd_head),
NEW_CHILD(ast, RNODE_ARGSCAT(RNODE_OP_ASGN1(node)->nd_args)->nd_body));
case NODE_OP_ASGN2:
// NODE_OP_ASGN2 has NODE_OP_ASGN2 in its nd_next, however nd_next
// has different structure, whose u1 is ID attr, u2 is ID op, u3 is bool.
// See: NEW_OP_ASGN2
return rb_ary_new_from_args(5, NEW_CHILD(ast, RNODE_OP_ASGN2(node)->nd_recv),
RBOOL(RNODE_OP_ASGN22(RNODE_OP_ASGN2(node)->nd_next)->nd_aid),
ID2SYM(RNODE_OP_ASGN22(RNODE_OP_ASGN2(node)->nd_next)->nd_vid),
ID2SYM(RNODE_OP_ASGN22(RNODE_OP_ASGN2(node)->nd_next)->nd_mid),
RBOOL(RNODE_OP_ASGN2(node)->nd_aid),
ID2SYM(RNODE_OP_ASGN2(node)->nd_vid),
ID2SYM(RNODE_OP_ASGN2(node)->nd_mid),
NEW_CHILD(ast, RNODE_OP_ASGN2(node)->nd_value));
case NODE_OP_ASGN_AND:
return rb_ary_new_from_args(3, NEW_CHILD(ast, RNODE_OP_ASGN_AND(node)->nd_head), ID2SYM(idANDOP),

Просмотреть файл

@ -8708,8 +8708,8 @@ static int
compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped)
{
const int line = nd_line(node);
ID atype = RNODE_OP_ASGN2(node)->nd_next->nd_mid;
ID vid = RNODE_OP_ASGN2(node)->nd_next->nd_vid, aid = rb_id_attrset(vid);
ID atype = RNODE_OP_ASGN2(node)->nd_mid;
ID vid = RNODE_OP_ASGN2(node)->nd_vid, aid = rb_id_attrset(vid);
int asgnflag;
LABEL *lfin = NEW_LABEL(line);
LABEL *lcfin = NEW_LABEL(line);
@ -8769,7 +8769,7 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
asgnflag = COMPILE_RECV(ret, "NODE_OP_ASGN2#recv", node, RNODE_OP_ASGN2(node)->nd_recv);
CHECK(asgnflag != -1);
if (RNODE_OP_ASGN2(node)->nd_next->nd_aid) {
if (RNODE_OP_ASGN2(node)->nd_aid) {
lskip = NEW_LABEL(line);
ADD_INSN(ret, node, dup);
ADD_INSNL(ret, node, branchnil, lskip);

Просмотреть файл

@ -479,10 +479,10 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
ANN("example: struct.field += foo");
F_NODE(nd_recv, RNODE_OP_ASGN2, "receiver");
F_CUSTOM1(nd_next->nd_vid, "attr") {
if (RNODE_OP_ASGN2(node)->nd_next->nd_aid) A("? ");
A_ID(RNODE_OP_ASGN2(node)->nd_next->nd_vid);
if (RNODE_OP_ASGN2(node)->nd_aid) A("? ");
A_ID(RNODE_OP_ASGN2(node)->nd_vid);
}
F_ID(nd_next->nd_mid, RNODE_OP_ASGN2, "operator");
F_ID(nd_mid, RNODE_OP_ASGN2, "operator");
LAST_NODE;
F_NODE(nd_value, RNODE_OP_ASGN2, "rvalue");
return;

17
parse.y
Просмотреть файл

@ -914,8 +914,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, 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, rb_node_argscat_t *nd_args, const YYLTYPE *loc);
static rb_node_op_asgn2_t *rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, rb_node_op_asgn22_t *nd_next, const YYLTYPE *loc);
static rb_node_op_asgn22_t *rb_node_op_asgn22_new(struct parser_params *p, 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);
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, const YYLTYPE *loc);
@ -1016,8 +1015,7 @@ static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE
#define NEW_CDECL(v,val,path,loc) (NODE *)rb_node_cdecl_new(p,v,val,path,loc)
#define NEW_CVASGN(v,val,loc) (NODE *)rb_node_cvasgn_new(p,v,val,loc)
#define NEW_OP_ASGN1(r,id,a,loc) (NODE *)rb_node_op_asgn1_new(p,r,id,a,loc)
#define NEW_OP_ASGN2(r,t,i,o,val,loc) (NODE *)rb_node_op_asgn2_new(p,r,val,NEW_OP_ASGN22(i,o,t,loc),loc)
#define NEW_OP_ASGN22(i,o,t,loc) rb_node_op_asgn22_new(p,i,o,t,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_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,loc) (NODE *)rb_node_op_cdecl_new(p,v,val,op,loc)
@ -11619,20 +11617,11 @@ rb_node_op_asgn1_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, rb_node_
}
static rb_node_op_asgn2_t *
rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, rb_node_op_asgn22_t *nd_next, 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)
{
rb_node_op_asgn2_t *n = NODE_NEWNODE(NODE_OP_ASGN2, rb_node_op_asgn2_t, loc);
n->nd_recv = nd_recv;
n->nd_value = nd_value;
n->nd_next = nd_next;
return n;
}
static rb_node_op_asgn22_t *
rb_node_op_asgn22_new(struct parser_params *p, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc)
{
rb_node_op_asgn22_t *n = NODE_NEWNODE(NODE_OP_ASGN2, rb_node_op_asgn22_t, loc);
n->nd_vid = nd_vid;
n->nd_mid = nd_mid;
n->nd_aid = nd_aid;

Просмотреть файл

@ -438,16 +438,10 @@ typedef struct RNode_OP_ASGN2 {
struct RNode *nd_recv;
struct RNode *nd_value;
struct RNode_OP_ASGN22 *nd_next;
} rb_node_op_asgn2_t;
typedef struct RNode_OP_ASGN22 {
NODE node;
ID nd_vid;
ID nd_mid;
bool nd_aid;
} rb_node_op_asgn22_t;
} rb_node_op_asgn2_t;
typedef struct RNode_OP_ASGN_AND {
NODE node;