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

ruby-changes:48777

From: nobu <ko1@a...>
Date: Fri, 24 Nov 2017 13:26:40 +0900 (JST)
Subject: [ruby-changes:48777] nobu:r60893 (trunk): parse.y: make_array

nobu	2017-11-24 13:26:29 +0900 (Fri, 24 Nov 2017)

  New Revision: 60893

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

  Log:
    parse.y: make_array
    
    * parse.y (make_array): turn NULL node into zero length array.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 60892)
+++ parse.y	(revision 60893)
@@ -549,6 +549,7 @@ static NODE *new_undef_gen(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L549
 
 static NODE *new_zarray_gen(struct parser_params *parser, const YYLTYPE *location);
 #define new_zarray(location) new_zarray_gen(parser, location)
+#define make_array(ary, location) ((ary) ? (ary) : new_zarray(location))
 
 static NODE *new_ivar_gen(struct parser_params *parser, ID id, const YYLTYPE *location);
 #define new_ivar(id, location) new_ivar_gen(parser,id,location)
@@ -1508,7 +1509,7 @@ command_asgn	: lhs '=' command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1509
 			NODE *args;
 
 			value_expr($6);
-			if (!$3) $3 = new_zarray(&@$);
+			$3 = make_array($3, &@$);
 			args = arg_concat($3, $6, &@$);
 			if ($5 == tOROP) {
 			    $5 = 0;
@@ -2158,7 +2159,7 @@ arg		: lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2159
 			NODE *args;
 
 			value_expr($6);
-			if (!$3) $3 = new_zarray(&@$);
+			$3 = make_array($3, &@$);
 			if (nd_type($3) == NODE_BLOCK_PASS) {
 			    args = NEW_ARGSCAT($3, $6);
 			    args->nd_loc = @$;
@@ -2724,12 +2725,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2725
 		| tLBRACK aref_args ']'
 		    {
 		    /*%%%*/
-			if ($2 == 0) {
-			    $$ = new_zarray(&@$); /* zero length array*/
-			}
-			else {
-			    $$ = $2;
-			}
+			$$ = make_array($2, &@$);
 		    /*%
 			$$ = dispatch1(array, escape_Qundef($2));
 		    %*/
@@ -3955,7 +3951,7 @@ regexp		: tREGEXP_BEG regexp_contents tR https://github.com/ruby/ruby/blob/trunk/parse.y#L3951
 words		: tWORDS_BEG ' ' word_list tSTRING_END
 		    {
 		    /*%%%*/
-			$$ = $3 ? $3 : new_zarray(&@$);
+			$$ = make_array($3, &@$);
 		    /*%
 			$$ = dispatch1(array, $3);
 		    %*/
@@ -4001,7 +3997,7 @@ word		: string_content https://github.com/ruby/ruby/blob/trunk/parse.y#L3997
 symbols 	: tSYMBOLS_BEG ' ' symbol_list tSTRING_END
 		    {
 		    /*%%%*/
-			$$ = $3 ? $3 : new_zarray(&@$);
+			$$ = make_array($3, &@$);
 		    /*%
 			$$ = dispatch1(array, $3);
 		    %*/
@@ -4037,7 +4033,7 @@ symbol_list	: /* none */ https://github.com/ruby/ruby/blob/trunk/parse.y#L4033
 qwords		: tQWORDS_BEG ' ' qword_list tSTRING_END
 		    {
 		    /*%%%*/
-			$$ = $3 ? $3 : new_zarray(&@$);
+			$$ = make_array($3, &@$);
 		    /*%
 			$$ = dispatch1(array, $3);
 		    %*/
@@ -4047,7 +4043,7 @@ qwords		: tQWORDS_BEG ' ' qword_list tST https://github.com/ruby/ruby/blob/trunk/parse.y#L4043
 qsymbols	: tQSYMBOLS_BEG ' ' qsym_list tSTRING_END
 		    {
 		    /*%%%*/
-			$$ = $3 ? $3 : new_zarray(&@$);
+			$$ = make_array($3, &@$);
 		    /*%
 			$$ = dispatch1(array, $3);
 		    %*/

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

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