ruby-changes:49556
From: mame <ko1@a...>
Date: Mon, 8 Jan 2018 12:22:18 +0900 (JST)
Subject: [ruby-changes:49556] mame:r61672 (trunk): parse.y: Factor out special handling of a short-cut operator id
mame 2018-01-08 12:22:13 +0900 (Mon, 08 Jan 2018) New Revision: 61672 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61672 Log: parse.y: Factor out special handling of a short-cut operator id Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61671) +++ parse.y (revision 61672) @@ -495,6 +495,12 @@ 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, location) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs), (location)) static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *location); #define new_const_op_assign(lhs, op, rhs, location) new_const_op_assign_gen(parser, (lhs), (op), (rhs), (location)) +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 *location); #define const_path_field(w, n, location) const_path_field_gen(parser, w, n, location) @@ -2108,13 +2114,7 @@ arg : lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2114 else { args = arg_concat($3, $6, &@$); } - if ($5 == tOROP) { - $5 = 0; - } - else if ($5 == tANDOP) { - $5 = 1; - } - $$ = NEW_OP_ASGN1($1, $5, args, &@$); + $$ = NEW_OP_ASGN1($1, change_shortcut_operator_id($5), args, &@$); fixpos($$, $1); /*% $1 = dispatch2(aref_field, $1, escape_Qundef($3)); @@ -10675,13 +10675,7 @@ new_attr_op_assign_gen(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L10675 { NODE *asgn; - if (op == tOROP) { - op = 0; - } - else if (op == tANDOP) { - op = 1; - } - asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, location); + asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, change_shortcut_operator_id(op), rhs, location); fixpos(asgn, lhs); return asgn; } @@ -10691,14 +10685,8 @@ new_const_op_assign_gen(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L10685 { NODE *asgn; - if (op == tOROP) { - op = 0; - } - else if (op == tANDOP) { - op = 1; - } if (lhs) { - asgn = NEW_OP_CDECL(lhs, op, rhs, location); + asgn = NEW_OP_CDECL(lhs, change_shortcut_operator_id(op), rhs, location); } else { asgn = NEW_BEGIN(0, location); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/