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

ruby-changes:50694

From: nobu <ko1@a...>
Date: Tue, 20 Mar 2018 22:31:04 +0900 (JST)
Subject: [ruby-changes:50694] nobu:r62861 (trunk): node.c: predicates for special NODEs

nobu	2018-03-20 22:30:57 +0900 (Tue, 20 Mar 2018)

  New Revision: 62861

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

  Log:
    node.c: predicates for special NODEs

  Modified files:
    trunk/compile.c
    trunk/ext/-test-/ast/ast.c
    trunk/node.c
    trunk/node.h
    trunk/parse.y
Index: compile.c
===================================================================
--- compile.c	(revision 62860)
+++ compile.c	(revision 62861)
@@ -4088,7 +4088,7 @@ compile_massign(rb_iseq_t *iseq, LINK_AN https://github.com/ruby/ruby/blob/trunk/compile.c#L4088
     const NODE *rhsn = node->nd_value;
     const NODE *splatn = node->nd_args;
     const NODE *lhsn = node->nd_head;
-    int lhs_splat = (splatn && splatn != NODE_SPECIAL_NO_NAME_REST) ? 1 : 0;
+    int lhs_splat = (splatn && NODE_NAMED_REST_P(splatn)) ? 1 : 0;
 
     if (!popped || splatn || !compile_massign_opt(iseq, ret, rhsn, lhsn)) {
 	int llen = 0;
@@ -4145,12 +4145,12 @@ compile_massign(rb_iseq_t *iseq, LINK_AN https://github.com/ruby/ruby/blob/trunk/compile.c#L4145
 		const NODE *postn = splatn->nd_2nd;
 		const NODE *restn = splatn->nd_1st;
 		int num = (int)postn->nd_alen;
-		int flag = 0x02 | ((restn == NODE_SPECIAL_NO_NAME_REST) ? 0x00 : 0x01);
+		int flag = 0x02 | (NODE_NAMED_REST_P(restn) ? 0x01 : 0x00);
 
 		ADD_INSN2(ret, nd_line(splatn), expandarray,
 			  INT2FIX(num), INT2FIX(flag));
 
-		if (restn != NODE_SPECIAL_NO_NAME_REST) {
+		if (NODE_NAMED_REST_P(restn)) {
 		    CHECK(compile_massign_lhs(iseq, ret, restn));
 		}
 		while (postn) {
Index: parse.y
===================================================================
--- parse.y	(revision 62860)
+++ parse.y	(revision 62861)
@@ -9955,10 +9955,9 @@ new_args_tail(struct parser_params *p, N https://github.com/ruby/ruby/blob/trunk/parse.y#L9955
 	int i;
 
 	while (kwn) {
-	    NODE *val_node = kwn->nd_body->nd_value;
 	    ID vid = kwn->nd_body->nd_vid;
 
-	    if (val_node == NODE_SPECIAL_REQUIRED_KEYWORD) {
+	    if (NODE_REQUIRED_KEYWORD_P(kwn->nd_body)) {
 		vtable_add(required_kw_vars, vid);
 	    }
 	    else {
Index: ext/-test-/ast/ast.c
===================================================================
--- ext/-test-/ast/ast.c	(revision 62860)
+++ ext/-test-/ast/ast.c	(revision 62861)
@@ -239,7 +239,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ext/-test-/ast/ast.c#L239
 	    return ary;
 	}
       case NODE_MASGN:
-        if (node->nd_args != NODE_SPECIAL_NO_NAME_REST) {
+        if (NODE_NAMED_REST_P(node->nd_args)) {
 	    return rb_ary_new_from_node_args(ast, 3, node->nd_value, node->nd_head, node->nd_args);
         }
 	return rb_ary_new_from_node_args(ast, 2, node->nd_value, node->nd_head);
@@ -253,7 +253,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ext/-test-/ast/ast.c#L253
 	goto asgn;
       case NODE_CVASGN:
       asgn:
-        if (node->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD) {
+        if (NODE_REQUIRED_KEYWORD_P(node)) {
 	    return rb_ary_new_from_node_args(ast, 0);
         }
 	return rb_ary_new_from_node_args(ast, 1, node->nd_value);
@@ -404,7 +404,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ext/-test-/ast/ast.c#L404
       case NODE_KW_ARG:
 	return rb_ary_new_from_node_args(ast, 2, node->nd_body, node->nd_next);
       case NODE_POSTARG:
-	if (node->nd_1st != NODE_SPECIAL_NO_NAME_REST) {
+	if (NODE_NAMED_REST_P(node->nd_1st)) {
 	    return rb_ary_new_from_node_args(ast, 2, node->nd_1st, node->nd_2nd);
 	}
 	return rb_ary_new_from_node_args(ast, 1, node->nd_2nd);
Index: node.c
===================================================================
--- node.c	(revision 62860)
+++ node.c	(revision 62861)
@@ -342,7 +342,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L342
 	ANN("example: a, b = foo");
 	F_NODE(nd_value, "rhsn");
 	F_NODE(nd_head, "lhsn");
-	if (node->nd_args != NODE_SPECIAL_NO_NAME_REST) {
+	if (NODE_NAMED_REST_P(node->nd_args)) {
 	    LAST_NODE;
 	    F_NODE(nd_args, "splatn");
 	}
@@ -356,7 +356,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L356
 	ANN("format: [nd_vid](lvar) = [nd_value]");
 	ANN("example: x = foo");
 	F_ID(nd_vid, "local variable");
-	if (node->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD) {
+	if (NODE_REQUIRED_KEYWORD_P(node)) {
 	    F_MSG(nd_value, "rvalue", "NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
 	}
 	else {
@@ -377,7 +377,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L377
 	ANN("format: [nd_vid](current dvar) = [nd_value]");
 	ANN("example: 1.times { x = foo }");
 	F_ID(nd_vid, "local variable");
-	if (node->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD) {
+	if (NODE_REQUIRED_KEYWORD_P(node)) {
 	    F_MSG(nd_value, "rvalue", "NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
 	}
 	else {
@@ -955,7 +955,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L955
 	ANN("post arguments");
 	ANN("format: *[nd_1st], [nd_2nd..] = ..");
 	ANN("example: a, *rest, z = foo");
-	if (node->nd_1st != NODE_SPECIAL_NO_NAME_REST) {
+	if (NODE_NAMED_REST_P(node->nd_1st)) {
 	    F_NODE(nd_1st, "rest argument");
 	}
 	else {
Index: node.h
===================================================================
--- node.h	(revision 62860)
+++ node.h	(revision 62861)
@@ -469,7 +469,9 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L469
 #define NEW_ATTRASGN(r,m,a,loc) NEW_NODE(NODE_ATTRASGN,r,m,a,loc)
 
 #define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
+#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)
 
 RUBY_SYMBOL_EXPORT_BEGIN
 

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

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