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

ruby-changes:57638

From: Yusuke <ko1@a...>
Date: Sat, 7 Sep 2019 13:57:06 +0900 (JST)
Subject: [ruby-changes:57638] 99c9431ea1 (master): Rename NODE_ARRAY to NODE_LIST to reflect its actual use cases

https://git.ruby-lang.org/ruby.git/commit/?id=99c9431ea1

From 99c9431ea1cc538489c3da70f52121aa8bc0800b Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 7 Sep 2019 10:42:00 +0900
Subject: Rename NODE_ARRAY to NODE_LIST to reflect its actual use cases

and NODE_ZARRAY to NODE_ZLIST.

NODE_ARRAY is used not only by an Array literal, but also the contents
of Hash literals, method call arguments, dynamic string literals, etc.
In addition, the structure of NODE_ARRAY is a linked list, not an array.

This is very confusing, so I believe `NODE_LIST` is a better name.

diff --git a/ast.c b/ast.c
index fdb4b7a..7f54d85 100644
--- a/ast.c
+++ b/ast.c
@@ -337,7 +337,7 @@ dump_array(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L337
     VALUE ary = rb_ary_new();
     rb_ary_push(ary, NEW_CHILD(ast, node->nd_head));
 
-    while (node->nd_next && nd_type(node->nd_next) == NODE_ARRAY) {
+    while (node->nd_next && nd_type(node->nd_next) == NODE_LIST) {
         node = node->nd_next;
         rb_ary_push(ary, NEW_CHILD(ast, node->nd_head));
     }
@@ -491,12 +491,12 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L491
         return rb_ary_new_from_node_args(ast, 1, node->nd_args);
       case NODE_ZSUPER:
         return rb_ary_new_from_node_args(ast, 0);
-      case NODE_ARRAY:
+      case NODE_LIST:
         goto ary;
       case NODE_VALUES:
       ary:
         return dump_array(ast, node);
-      case NODE_ZARRAY:
+      case NODE_ZLIST:
         return rb_ary_new_from_node_args(ast, 0);
       case NODE_HASH:
         return rb_ary_new_from_node_args(ast, 1, node->nd_head);
diff --git a/compile.c b/compile.c
index aca710e..6f9e2aa 100644
--- a/compile.c
+++ b/compile.c
@@ -3758,7 +3758,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co https://github.com/ruby/ruby/blob/trunk/compile.c#L3758
       case NODE_LIT:		/* NODE_LIT is always true */
       case NODE_TRUE:
       case NODE_STR:
-      case NODE_ZARRAY:
+      case NODE_ZLIST:
       case NODE_LAMBDA:
 	/* printf("useless condition eliminate (%s)\n",  ruby_node_name(nd_type(cond))); */
 	ADD_INSNL(ret, nd_line(cond), jump, then_label);
@@ -3768,7 +3768,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co https://github.com/ruby/ruby/blob/trunk/compile.c#L3768
 	/* printf("useless condition eliminate (%s)\n", ruby_node_name(nd_type(cond))); */
 	ADD_INSNL(ret, nd_line(cond), jump, else_label);
 	break;
-      case NODE_ARRAY:
+      case NODE_LIST:
       case NODE_ARGSCAT:
       case NODE_DREGX:
       case NODE_DSTR:
@@ -3802,13 +3802,13 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L3802
 {
     if (kw_arg_ptr == NULL) return FALSE;
 
-    if (nd_type(root_node) == NODE_HASH && !root_node->nd_brace && root_node->nd_head && nd_type(root_node->nd_head) == NODE_ARRAY) {
+    if (nd_type(root_node) == NODE_HASH && !root_node->nd_brace && root_node->nd_head && nd_type(root_node->nd_head) == NODE_LIST) {
 	const NODE *node = root_node->nd_head;
 
 	while (node) {
 	    const NODE *key_node = node->nd_head;
 
-	    assert(nd_type(node) == NODE_ARRAY);
+	    assert(nd_type(node) == NODE_LIST);
 	    if (!key_node) {
 		if (flag) *flag |= VM_CALL_KW_SPLAT;
 		return FALSE;
@@ -3857,7 +3857,7 @@ compile_args(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_roo https://github.com/ruby/ruby/blob/trunk/compile.c#L3857
 
     for (; node; len++, node = node->nd_next) {
         if (CPDEBUG > 0) {
-            EXPECT_NODE("compile_args", node, NODE_ARRAY, -1);
+            EXPECT_NODE("compile_args", node, NODE_LIST, -1);
         }
 
         if (node->nd_next == NULL /* last node */ &&
@@ -3929,7 +3929,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro https://github.com/ruby/ruby/blob/trunk/compile.c#L3929
     int line = (int)nd_line(node);
     int len = 0;
 
-    if (nd_type(node) == NODE_ZARRAY) {
+    if (nd_type(node) == NODE_ZLIST) {
 	if (!popped) {
 	    switch (type) {
 	      case COMPILE_ARRAY_TYPE_ARRAY: ADD_INSN1(ret, line, newarray, INT2FIX(0)); break;
@@ -3952,7 +3952,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro https://github.com/ruby/ruby/blob/trunk/compile.c#L3952
 
 	    for (i=0; i<max && node; i++, len++, node = node->nd_next) {
 		if (CPDEBUG > 0) {
-		    EXPECT_NODE("compile_array", node, NODE_ARRAY, -1);
+		    EXPECT_NODE("compile_array", node, NODE_LIST, -1);
 		}
 
                 if (type == COMPILE_ARRAY_TYPE_HASH && !node->nd_head) {
@@ -4184,7 +4184,7 @@ when_splat_vals(rb_iseq_t *iseq, LINK_ANCHOR *const cond_seq, const NODE *vals, https://github.com/ruby/ruby/blob/trunk/compile.c#L4184
     const int line = nd_line(vals);
 
     switch (nd_type(vals)) {
-      case NODE_ARRAY:
+      case NODE_LIST:
         if (when_vals(iseq, cond_seq, vals, l1, only_special_literals, literals) < 0)
             return COMPILE_NG;
         break;
@@ -4294,7 +4294,7 @@ compile_massign_opt(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4294
     mem[memindex++] = (v); \
 }
 
-    if (rhsn == 0 || nd_type(rhsn) != NODE_ARRAY) {
+    if (rhsn == 0 || nd_type(rhsn) != NODE_LIST) {
 	return 0;
     }
 
@@ -4514,7 +4514,7 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4514
 	expr_type = DEFINED_FALSE;
 	break;
 
-      case NODE_ARRAY:{
+      case NODE_LIST:{
 	const NODE *vals = node;
 
 	do {
@@ -4529,7 +4529,7 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4529
         /* fall through */
       case NODE_STR:
       case NODE_LIT:
-      case NODE_ZARRAY:
+      case NODE_ZLIST:
       case NODE_AND:
       case NODE_OR:
       default:
@@ -4815,7 +4815,7 @@ check_keyword(const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L4815
 {
     /* This check is essentially a code clone of compile_keyword_arg. */
 
-    if (nd_type(node) == NODE_ARRAY) {
+    if (nd_type(node) == NODE_LIST) {
         while (node->nd_next) {
             node = node->nd_next;
         }
@@ -4840,7 +4840,7 @@ setup_args_core(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, https://github.com/ruby/ruby/blob/trunk/compile.c#L4840
           }
           case NODE_ARGSCAT:
           case NODE_ARGSPUSH: {
-            int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY);
+            int next_is_array = (nd_type(argn->nd_head) == NODE_LIST);
             VALUE argc = setup_args_core(iseq, args, argn->nd_head, 1, NULL, NULL);
             NO_CHECK(COMPILE(args, "args (cat: splat)", argn->nd_body));
             if (flag) {
@@ -4867,7 +4867,7 @@ setup_args_core(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, https://github.com/ruby/ruby/blob/trunk/compile.c#L4867
                 return argc;
             }
           }
-          case NODE_ARRAY: {
+          case NODE_LIST: {
             int len = compile_args(iseq, args, argn, keywords, flag);
             return INT2FIX(len);
           }
@@ -5136,7 +5136,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_nod https://github.com/ruby/ruby/blob/trunk/compile.c#L5136
 	vals = node->nd_head;
 	if (vals) {
 	    switch (nd_type(vals)) {
-	      case NODE_ARRAY:
+	      case NODE_LIST:
 		only_special_literals = when_vals(iseq, cond_seq, vals, l1, only_special_literals, literals);
 		if (only_special_literals < 0) return COMPILE_NG;
 		break;
@@ -5151,7 +5151,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_nod https://github.com/ruby/ruby/blob/trunk/compile.c#L5151
 	    }
 	}
 	else {
-	    EXPECT_NODE_NONULL("NODE_CASE", node, NODE_ARRAY, COMPILE_NG);
+	    EXPECT_NODE_NONULL("NODE_CASE", node, NODE_LIST, COMPILE_NG);
 	}
 
 	node = node->nd_next;
@@ -5234,11 +5234,11 @@ compile_case2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_no https://github.com/ruby/ruby/blob/trunk/compile.c#L5234
 
 	vals = node->nd_head;
 	if (!vals) {
-	    COMPILE_ERROR(ERROR_ARGS "NODE_WHEN: must be NODE_ARRAY, but 0");
+	    COMPILE_ERROR(ERROR_ARGS "NODE_WHEN: must be NODE_LIST, but 0");
 	    return COMPILE_NG;
 	}
 	switch (nd_type(vals)) {
-	  case NODE_ARRAY:
+	  case NODE_LIST:
 	    while (vals) {
 		LABEL *lnext;
 		val = vals->nd_head;
@@ -5639,8 +5639,8 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c https://github.com/ruby/ruby/blob/trunk/compile.c#L5639
       case NODE_DSTR:
       case NODE_DSYM:
       case NODE_DREGX:
-      case NODE_ARRAY:
-      case NODE_ZARRAY:
+      case NODE_LIST:
+      case NODE_ZLIST:
       case NODE_LAMBDA:
       case NODE_DOT2:
       case NODE_DOT3:
@@ -5729,7 +5729,7 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c https://github.com/ruby/ruby/blob/trunk/compile.c#L5729
         fin = NEW_LABEL(line);
 
         n = node->nd_head;
-        if (! (nd_type(n) == NODE_ARRAY && n->nd_alen == 2)) {
+        if (! (nd_type(n) == NODE_LIST && n->nd_alen == 2)) {
             COMPILE_ERROR(ERROR_ARGS "unexpected node");
             return COMPILE_NG;
         }
@@ -6322,7 +6322,7 @@ compile_resbody(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, https://github.com/ruby/ruby/blob/trunk/compile.c#L6322
 	narg = resq->nd_args;
 	if (narg) {
 	    switch (nd_type(narg)) {
-	      case NODE_ARRAY:
+	      case NODE_LIST:
 		while (narg) {
 		    ADD_GETLOCAL(ret, line, LVAR_ERRINFO, 0);
 		    CHECK(COMPILE(ret, "rescue arg", narg->nd_head));
@@ -6549,7 +6549,7 @@ compile_call_precheck_freeze(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE https://github.com/ruby/ruby/blob/trunk/compile.c#L6549
      *   obj["literal"] -> opt_aref_with(obj, "literal")
      */
     if  (... truncated)

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

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