ruby-changes:49586
From: mame <ko1@a...>
Date: Tue, 9 Jan 2018 10:49:45 +0900 (JST)
Subject: [ruby-changes:49586] mame:r61701 (trunk): parse.y: Remove special handling of tOROP and tANDOP
mame 2018-01-09 10:49:40 +0900 (Tue, 09 Jan 2018) New Revision: 61701 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61701 Log: parse.y: Remove special handling of tOROP and tANDOP The complexity is no longer considered necessary. Modified files: trunk/compile.c trunk/node.c trunk/parse.y Index: compile.c =================================================================== --- compile.c (revision 61700) +++ compile.c (revision 61701) @@ -5748,9 +5748,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5748 ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag)); flag |= asgnflag; - if (id == 0 || id == 1) { - /* 0: or, 1: and - a[x] ||= y + if (id == idOROP || id == idANDOP) { + /* a[x] ||= y or a[x] &&= y unless/if a[x] a[x]= y @@ -5762,12 +5761,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5761 LABEL *lfin = NEW_LABEL(line); ADD_INSN(ret, line, dup); - if (id == 0) { - /* or */ + if (id == idOROP) { ADD_INSNL(ret, line, branchif, label); } - else { - /* and */ + else { /* idANDOP */ ADD_INSNL(ret, line, branchunless, label); } ADD_INSN(ret, line, pop); @@ -5894,12 +5891,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5891 ADD_INSN(ret, line, dup); ADD_SEND(ret, line, vid, INT2FIX(0)); - if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */ + if (atype == idOROP || atype == idANDOP) { ADD_INSN(ret, line, dup); - if (atype == 0) { + if (atype == idOROP) { ADD_INSNL(ret, line, branchif, lcfin); } - else { + else { /* idANDOP */ ADD_INSNL(ret, line, branchunless, lcfin); } ADD_INSN(ret, line, pop); @@ -5959,7 +5956,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5956 } mid = node->nd_head->nd_mid; /* cref */ - if (node->nd_aid == 0) { + if (node->nd_aid == idOROP) { lassign = NEW_LABEL(line); ADD_INSN(ret, line, dup); /* cref cref */ ADD_INSN3(ret, line, defined, INT2FIX(DEFINED_CONST), @@ -5969,12 +5966,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5966 ADD_INSN(ret, line, dup); /* cref cref */ ADD_INSN1(ret, line, getconstant, ID2SYM(mid)); /* cref obj */ - if (node->nd_aid == 0 || node->nd_aid == 1) { + if (node->nd_aid == idOROP || node->nd_aid == idANDOP) { lfin = NEW_LABEL(line); if (!popped) ADD_INSN(ret, line, dup); /* cref [obj] obj */ - if (node->nd_aid == 0) + if (node->nd_aid == idOROP) ADD_INSNL(ret, line, branchif, lfin); - else + else /* idANDOP */ ADD_INSNL(ret, line, branchunless, lfin); /* cref [obj] */ if (!popped) ADD_INSN(ret, line, pop); /* cref */ Index: node.c =================================================================== --- node.c (revision 61700) +++ node.c (revision 61701) @@ -22,7 +22,6 @@ https://github.com/ruby/ruby/blob/trunk/node.c#L22 #define A_INT(val) rb_str_catf(buf, "%d", (val)) #define A_LONG(val) rb_str_catf(buf, "%ld", (val)) #define A_LIT(lit) AR(rb_inspect(lit)) -#define A_OPERATOR(id) add_operator(buf, (id)) #define A_NODE_HEADER(node, term) \ rb_str_catf(buf, "@ %s (line: %d, code_range: (%d,%d)-(%d,%d))%s"term, \ ruby_node_name(nd_type(node)), nd_line(node), \ @@ -63,7 +62,6 @@ https://github.com/ruby/ruby/blob/trunk/node.c#L62 #define F_INT(name, ann) SIMPLE_FIELD1(#name, ann) A_INT(node->name) #define F_LONG(name, ann) SIMPLE_FIELD1(#name, ann) A_LONG(node->name) #define F_LIT(name, ann) SIMPLE_FIELD1(#name, ann) A_LIT(node->name) -#define F_OPERATOR(name, ann) SIMPLE_FIELD1(#name, ann) A_OPERATOR(node->name) #define F_MSG(name, ann, desc) SIMPLE_FIELD1(#name, ann) A(desc) #define F_NODE(name, ann) \ @@ -99,16 +97,6 @@ add_id(VALUE buf, ID id) https://github.com/ruby/ruby/blob/trunk/node.c#L97 } } -static void -add_operator(VALUE buf, ID id) -{ - switch (id) { - case 0: A("0 (||)"); break; - case 1: A("1 (&&)"); break; - default: A_ID(id); - } -} - struct add_option_arg { VALUE buf, indent; st_index_t count; @@ -435,7 +423,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L423 ANN("format: [nd_value] [ [nd_args->nd_body] ] [nd_vid]= [nd_args->nd_head]"); ANN("example: ary[1] += foo"); F_NODE(nd_recv, "receiver"); - F_OPERATOR(nd_mid, "operator"); + F_ID(nd_mid, "operator"); F_NODE(nd_args->nd_head, "index"); LAST_NODE; F_NODE(nd_args->nd_body, "rvalue"); @@ -451,7 +439,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L439 if (node->nd_next->nd_aid) A("? "); A_ID(node->nd_next->nd_vid); } - F_OPERATOR(nd_next->nd_mid, "operator"); + F_ID(nd_next->nd_mid, "operator"); LAST_NODE; F_NODE(nd_value, "rvalue"); return; @@ -476,7 +464,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L464 ANN("format: [nd_head](constant) [nd_aid]= [nd_value]"); ANN("example: A::B ||= 1"); F_NODE(nd_head, "constant"); - F_OPERATOR(nd_aid, "operator"); + F_ID(nd_aid, "operator"); LAST_NODE; F_NODE(nd_value, "rvalue"); return; Index: parse.y =================================================================== --- parse.y (revision 61700) +++ parse.y (revision 61701) @@ -495,12 +495,6 @@ static NODE *new_attr_op_assign_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L495 #define new_attr_op_assign(lhs, type, attr, op, rhs, cr) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs), (cr)) static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *cr); #define new_const_op_assign(lhs, op, rhs, cr) new_const_op_assign_gen(parser, (lhs), (op), (rhs), (cr)) -static ID change_shortcut_operator_id(ID id) -{ - if (id == tOROP) return 0; - if (id == tANDOP) return 1; - return id; -} static NODE *const_path_field_gen(struct parser_params *parser, NODE *head, ID mid, const YYLTYPE *cr); #define const_path_field(w, n, cr) const_path_field_gen(parser, w, n, cr) @@ -1464,7 +1458,7 @@ command_asgn : lhs '=' command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1458 value_expr($6); $3 = make_array($3, &@3); args = arg_concat($3, $6, &@$); - $$ = NEW_OP_ASGN1($1, change_shortcut_operator_id($5), args, &@$); + $$ = NEW_OP_ASGN1($1, $5, args, &@$); fixpos($$, $1); /*% $$ = dispatch2(aref_field, $1, escape_Qundef($3)); @@ -2094,7 +2088,7 @@ arg : lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2088 else { args = arg_concat($3, $6, &@$); } - $$ = NEW_OP_ASGN1($1, change_shortcut_operator_id($5), args, &@$); + $$ = NEW_OP_ASGN1($1, $5, args, &@$); fixpos($$, $1); /*% $1 = dispatch2(aref_field, $1, escape_Qundef($3)); @@ -8369,7 +8363,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8363 if ((c = nextc()) == '&') { SET_LEX_STATE(EXPR_BEG); if ((c = nextc()) == '=') { - set_yylval_id(tANDOP); + set_yylval_id(idANDOP); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } @@ -8408,7 +8402,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8402 if ((c = nextc()) == '|') { SET_LEX_STATE(EXPR_BEG); if ((c = nextc()) == '=') { - set_yylval_id(tOROP); + set_yylval_id(idOROP); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } @@ -10562,7 +10556,7 @@ new_attr_op_assign_gen(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L10556 { NODE *asgn; - asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, change_shortcut_operator_id(op), rhs, cr); + asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, cr); fixpos(asgn, lhs); return asgn; } @@ -10573,7 +10567,7 @@ new_const_op_assign_gen(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L10567 NODE *asgn; if (lhs) { - asgn = NEW_OP_CDECL(lhs, change_shortcut_operator_id(op), rhs, cr); + asgn = NEW_OP_CDECL(lhs, op, rhs, cr); } else { asgn = NEW_BEGIN(0, cr); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/