Skip to content

Commit

Permalink
parse.y: new_attr_op_assign
Browse files Browse the repository at this point in the history
* parse.y (new_attr_op_assign): extract.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Sep 15, 2012
1 parent 2bfc48d commit 47b642b
Showing 1 changed file with 33 additions and 78 deletions.
111 changes: 33 additions & 78 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*);
#define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))

static NODE *new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs);
static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID attr, ID op, NODE *rhs);
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (attr), (op), (rhs))

static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
#define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
Expand Down Expand Up @@ -450,6 +452,8 @@ static int id_is_var_gen(struct parser_params *parser, ID id);
#define node_assign(node1, node2) dispatch2(assign, (node1), (node2))

static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs);
static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs);
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs))

#endif /* !RIPPER */

Expand Down Expand Up @@ -1166,37 +1170,13 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
}
| primary_value '.' tIDENTIFIER tOP_ASGN command_call
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
$$ = dispatch3(opassign, $$, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_id2sym('.'), $3, $4, $5);
}
| primary_value '.' tCONSTANT tOP_ASGN command_call
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
$$ = dispatch3(opassign, $$, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_id2sym('.'), $3, $4, $5);
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
{
Expand All @@ -1211,20 +1191,8 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$$ = dispatch3(field, $1, ripper_intern("::"), $3);
$$ = dispatch3(opassign, $$, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_intern("::"), $3, $4, $5);
}
| backref tOP_ASGN command_call
{
Expand Down Expand Up @@ -1993,54 +1961,18 @@ arg : lhs '=' arg
}
| primary_value '.' tIDENTIFIER tOP_ASGN arg
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
$$ = dispatch3(opassign, $1, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_id2sym('.'), $3, $4, $5);
}
| primary_value '.' tCONSTANT tOP_ASGN arg
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
$$ = dispatch3(opassign, $1, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_id2sym('.'), $3, $4, $5);
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
{
/*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
}
else if ($4 == tANDOP) {
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
/*%
$1 = dispatch3(field, $1, ripper_intern("::"), $3);
$$ = dispatch3(opassign, $1, $4, $5);
%*/
$$ = new_attr_op_assign($1, ripper_intern("::"), $3, $4, $5);
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
{
Expand Down Expand Up @@ -9387,12 +9319,35 @@ new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs)
}
return asgn;
}

static NODE *
new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID attr, ID op, NODE *rhs)
{
NODE *asgn;

if (op == tOROP) {
op = 0;
}
else if (op == tANDOP) {
op = 1;
}
asgn = NEW_OP_ASGN2(lhs, attr, op, rhs);
fixpos(asgn, lhs);
return asgn;
}
#else
static VALUE
new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs)
{
return dispatch3(opassign, lhs, op, rhs);
}

static VALUE
new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs)
{
VALUE recv = dispatch3(field, lhs, type, attr);
return dispatch3(opassign, recv, op, rhs);
}
#endif

static void
Expand Down

0 comments on commit 47b642b

Please sign in to comment.