[前][次][番号順一覧][スレッド一覧]

ruby-changes:49725

From: mame <ko1@a...>
Date: Mon, 15 Jan 2018 15:25:50 +0900 (JST)
Subject: [ruby-changes:49725] mame:r61842 (trunk): parse.y (new_ary_op_assign): Factor out the typical code clone

mame	2018-01-15 15:25:43 +0900 (Mon, 15 Jan 2018)

  New Revision: 61842

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61842

  Log:
    parse.y (new_ary_op_assign): Factor out the typical code clone

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61841)
+++ parse.y	(revision 61842)
@@ -404,6 +404,7 @@ static void rb_backref_error(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L404
 static NODE *node_assign(struct parser_params*,NODE*,NODE*,const YYLTYPE*);
 
 static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, 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);
 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_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *loc);
 
@@ -486,6 +487,7 @@ static VALUE new_qcall(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L487
 #define new_nil(loc) Qnil
 #define new_op_assign(p,lhs,op,rhs,loc) dispatch3(opassign, (lhs), (op), (rhs))
 
+static VALUE new_ary_op_assign(struct parser_params *p, VALUE ary, VALUE args, VALUE op, VALUE rhs, const YYLTYPE *args_loc, const YYLTYPE *loc);
 static VALUE new_attr_op_assign(struct parser_params *p, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs, const YYLTYPE *loc);
 #define new_const_op_assign(p, lhs, op, rhs, loc) new_op_assign(p, lhs, op, rhs, loc)
 
@@ -1293,23 +1295,8 @@ command_asgn	: lhs '=' command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1295
 		    }
 		| primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs
 		    {
-		    /*%%%*/
-			NODE *args;
-
 			value_expr($6);
-			$3 = make_array($3, &@3);
-			if (nd_type($3) == NODE_BLOCK_PASS) {
-			    args = NEW_ARGSCAT($3, $6, &@$);
-			}
-			else {
-			    args = arg_concat(p, $3, $6, &@$);
-			}
-			$$ = NEW_OP_ASGN1($1, $5, args, &@$);
-			fixpos($$, $1);
-		    /*%
-			$$ = dispatch2(aref_field, $1, escape_Qundef($3));
-			$$ = dispatch3(opassign, $$, $5, $6);
-		    %*/
+			$$ = new_ary_op_assign(p, $1, $3, $5, $6, &@3, &@$);
 		    }
 		| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
 		    {
@@ -1923,23 +1910,8 @@ arg		: lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1910
 		    }
 		| primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs
 		    {
-		    /*%%%*/
-			NODE *args;
-
 			value_expr($6);
-			$3 = make_array($3, &@3);
-			if (nd_type($3) == NODE_BLOCK_PASS) {
-			    args = NEW_ARGSCAT($3, $6, &@$);
-			}
-			else {
-			    args = arg_concat(p, $3, $6, &@$);
-			}
-			$$ = NEW_OP_ASGN1($1, $5, args, &@$);
-			fixpos($$, $1);
-		    /*%
-			$1 = dispatch2(aref_field, $1, escape_Qundef($3));
-			$$ = dispatch3(opassign, $1, $5, $6);
-		    %*/
+			$$ = new_ary_op_assign(p, $1, $3, $5, $6, &@3, &@$);
 		    }
 		| primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
 		    {
@@ -10403,6 +10375,24 @@ new_op_assign(struct parser_params *p, N https://github.com/ruby/ruby/blob/trunk/parse.y#L10375
 }
 
 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)
+{
+    NODE *asgn;
+
+    args = make_array(args, args_loc);
+    if (nd_type(args) == NODE_BLOCK_PASS) {
+	args = NEW_ARGSCAT(args, rhs, loc);
+    }
+    else {
+	args = arg_concat(p, args, rhs, loc);
+    }
+    asgn = NEW_OP_ASGN1(ary, op, args, loc);
+    fixpos(asgn, ary);
+    return asgn;
+}
+
+static NODE *
 new_attr_op_assign(struct parser_params *p, NODE *lhs,
 		   ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc)
 {
@@ -10438,6 +10428,14 @@ const_decl(struct parser_params *p, NODE https://github.com/ruby/ruby/blob/trunk/parse.y#L10428
 }
 #else
 static VALUE
+new_ary_op_assign(struct parser_params *p, VALUE ary,
+		  VALUE args, VALUE op, VALUE rhs, const YYLTYPE *args_loc, const YYLTYPE *loc)
+{
+    VALUE recv = dispatch2(aref_field, ary, escape_Qundef(args));
+    return dispatch3(opassign, recv, op, rhs);
+}
+
+static VALUE
 new_attr_op_assign(struct parser_params *p, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs, const YYLTYPE *loc)
 {
     VALUE recv = dispatch3(field, lhs, type, attr);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]