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

ruby-changes:56004

From: Yusuke <ko1@a...>
Date: Tue, 4 Jun 2019 23:17:40 +0900 (JST)
Subject: [ruby-changes:56004] Yusuke Endoh: 0872ea5330 (trunk): node.h: Avoid a magic number to represent excessed comma

https://git.ruby-lang.org/ruby.git/commit/?id=0872ea5330

From 0872ea53303499caf3584e40f2a5438e86eb4fed Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Tue, 4 Jun 2019 23:11:38 +0900
Subject: node.h: Avoid a magic number to represent excessed comma

`(ID)1` was assigned to NODE_ARGS#rest_arg for `{|x,| }`.
This change removes the magic number by introducing an explicit macro
variable for it: NODE_SPECIAL_EXCESSED_COMMA.

diff --git a/compile.c b/compile.c
index 64bde0c..e1a8885 100644
--- a/compile.c
+++ b/compile.c
@@ -1632,7 +1632,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *const optargs, const NODE *cons https://github.com/ruby/ruby/blob/trunk/compile.c#L1632
 	debugs("  - argc: %d\n", body->param.lead_num);
 
 	rest_id = args->rest_arg;
-	if (rest_id == 1) {
+	if (rest_id == NODE_SPECIAL_EXCESSED_COMMA) {
 	    last_comma = 1;
 	    rest_id = 0;
 	}
diff --git a/node.c b/node.c
index 558a4ce..864e115 100644
--- a/node.c
+++ b/node.c
@@ -1010,7 +1010,14 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node) https://github.com/ruby/ruby/blob/trunk/node.c#L1010
 	F_INT(nd_ainfo->post_args_num, "count of mandatory post-arguments");
 	F_NODE(nd_ainfo->post_init, "initialization of post-arguments");
 	F_ID(nd_ainfo->first_post_arg, "first post argument");
-	F_ID(nd_ainfo->rest_arg, "rest argument");
+        F_CUSTOM1(nd_ainfo->rest_arg, "rest argument") {
+            if (node->nd_ainfo->rest_arg == NODE_SPECIAL_EXCESSED_COMMA) {
+		A("1 (excessed comma)");
+	    }
+	    else {
+		A_ID(node->nd_ainfo->rest_arg);
+	    }
+	}
 	F_ID(nd_ainfo->block_arg, "block argument");
 	F_NODE(nd_ainfo->opt_args, "optional arguments");
 	F_NODE(nd_ainfo->kw_args, "keyword arguments");
diff --git a/node.h b/node.h
index 57a0ea3..539c372 100644
--- a/node.h
+++ b/node.h
@@ -383,6 +383,7 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L383
 #define NODE_REQUIRED_KEYWORD_P(node) ((node)->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD)
 #define NODE_SPECIAL_NO_NAME_REST     ((NODE *)-1)
 #define NODE_NAMED_REST_P(node) ((node) != NODE_SPECIAL_NO_NAME_REST)
+#define NODE_SPECIAL_EXCESSED_COMMA   ((ID)1)
 
 VALUE rb_node_case_when_optimizable_literal(const NODE *const node);
 
diff --git a/parse.y b/parse.y
index a35b526..4446a29 100644
--- a/parse.y
+++ b/parse.y
@@ -325,10 +325,6 @@ static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const ch https://github.com/ruby/ruby/blob/trunk/parse.y#L325
 
 #define lambda_beginning_p() (p->lex.lpar_beg == p->lex.paren_nest)
 
-#ifndef RIPPER
-static const ID excessed_comma = 1;
-#endif
-
 static enum yytokentype yylex(YYSTYPE*, YYLTYPE*, struct parser_params*);
 
 #ifndef RIPPER
@@ -3261,7 +3257,7 @@ block_param	: f_arg ',' f_block_optarg ',' f_rest_arg opt_block_args_tail https://github.com/ruby/ruby/blob/trunk/parse.y#L3257
 		    {
 		    /*%%%*/
 			/* magic number for rest_id in iseq_set_arguments() */
-			$$ = new_args(p, $1, Qnone, excessed_comma, Qnone, new_args_tail(p, Qnone, Qnone, Qnone, &@1), &@$);
+			$$ = new_args(p, $1, Qnone, NODE_SPECIAL_EXCESSED_COMMA, Qnone, new_args_tail(p, Qnone, Qnone, Qnone, &@1), &@$);
 		    /*% %*/
 		    /*% ripper: new_args(p, $1, Qnone, excessed_comma!, Qnone, new_args_tail(p, Qnone, Qnone, Qnone, NULL), NULL) %*/
 		    }
@@ -11134,7 +11130,7 @@ args_with_numbered(struct parser_params *p, NODE *args, int max_numparam) https://github.com/ruby/ruby/blob/trunk/parse.y#L11130
     if (max_numparam > 0) {
 	if (!args) args = new_args_tail(p, 0, 0, 0, 0);
 	args->nd_ainfo->pre_args_num = max_numparam;
-	args->nd_ainfo->rest_arg = excessed_comma;
+	args->nd_ainfo->rest_arg = NODE_SPECIAL_EXCESSED_COMMA;
     }
     return args;
 }
-- 
cgit v0.10.2


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

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