ruby-changes:70045
From: S.H <ko1@a...>
Date: Sat, 4 Dec 2021 00:01:37 +0900 (JST)
Subject: [ruby-changes:70045] ec7f14d9fa (master): Add `nd_type_p` macro
https://git.ruby-lang.org/ruby.git/commit/?id=ec7f14d9fa From ec7f14d9fab82b097fb8b58501461cd0e19d6bdf Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Sat, 4 Dec 2021 00:01:24 +0900 Subject: Add `nd_type_p` macro --- ast.c | 6 ++-- compile.c | 90 +++++++++++++++++++++++++++---------------------------- node.c | 6 ++-- node.h | 1 + parse.y | 100 +++++++++++++++++++++++++++++++------------------------------- 5 files changed, 102 insertions(+), 101 deletions(-) diff --git a/ast.c b/ast.c index 8139fcd390d..ceb03c29d4f 100644 --- a/ast.c +++ b/ast.c @@ -298,7 +298,7 @@ dump_block(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L298 do { rb_ary_push(ary, NEW_CHILD(ast, node->nd_head)); } while (node->nd_next && - nd_type(node->nd_next) == NODE_BLOCK && + nd_type_p(node->nd_next, NODE_BLOCK) && (node = node->nd_next, 1)); if (node->nd_next) { rb_ary_push(ary, NEW_CHILD(ast, node->nd_next)); @@ -313,7 +313,7 @@ dump_array(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L313 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_LIST) { + while (node->nd_next && nd_type_p(node->nd_next, NODE_LIST)) { node = node->nd_next; rb_ary_push(ary, NEW_CHILD(ast, node->nd_head)); } @@ -399,7 +399,7 @@ node_children(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L399 while (1) { rb_ary_push(ary, NEW_CHILD(ast, node->nd_1st)); - if (!node->nd_2nd || nd_type(node->nd_2nd) != (int)type) + if (!node->nd_2nd || !nd_type_p(node->nd_2nd, type)) break; node = node->nd_2nd; } diff --git a/compile.c b/compile.c index efe90bed10f..fc9f2eee6b3 100644 --- a/compile.c +++ b/compile.c @@ -753,7 +753,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L753 iseq_set_local_table(iseq, 0); } /* assume node is T_NODE */ - else if (nd_type(node) == NODE_SCOPE) { + else if (nd_type_p(node, NODE_SCOPE)) { /* iseq type of top, method, class, block */ iseq_set_local_table(iseq, node->nd_tbl); iseq_set_arguments(iseq, ret, node->nd_args); @@ -1783,7 +1783,7 @@ iseq_set_arguments_keywords(rb_iseq_t *iseq, LINK_ANCHOR *const optargs, https://github.com/ruby/ruby/blob/trunk/compile.c#L1783 dv = Qfalse; break; default: - NO_CHECK(COMPILE_POPPED(optargs, "kwarg", node)); /* nd_type(node) == NODE_KW_ARG */ + NO_CHECK(COMPILE_POPPED(optargs, "kwarg", node)); /* nd_type_p(node, NODE_KW_ARG) */ dv = complex_mark; } @@ -3914,7 +3914,7 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cons https://github.com/ruby/ruby/blob/trunk/compile.c#L3914 while (list) { const NODE *const head = list->nd_head; - if (nd_type(head) == NODE_STR) { + if (nd_type_p(head, NODE_STR)) { lit = rb_fstring(head->nd_lit); ADD_INSN1(ret, head, putobject, lit); RB_OBJ_WRITTEN(iseq, Qundef, lit); @@ -3938,7 +3938,7 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cons https://github.com/ruby/ruby/blob/trunk/compile.c#L3938 static int compile_block(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped) { - while (node && nd_type(node) == NODE_BLOCK) { + while (node && nd_type_p(node, NODE_BLOCK)) { CHECK(COMPILE_(ret, "BLOCK body", node->nd_head, (node->nd_next ? 1 : popped))); node = node->nd_next; @@ -4083,7 +4083,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co https://github.com/ruby/ruby/blob/trunk/compile.c#L4083 static int keyword_node_p(const NODE *const node) { - return nd_type(node) == NODE_HASH && (node->nd_brace & HASH_BRACE) != HASH_BRACE; + return nd_type_p(node, NODE_HASH) && (node->nd_brace & HASH_BRACE) != HASH_BRACE; } static int @@ -4094,7 +4094,7 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4094 { if (kw_arg_ptr == NULL) return FALSE; - if (root_node->nd_head && nd_type(root_node->nd_head) == NODE_LIST) { + if (root_node->nd_head && nd_type_p(root_node->nd_head, NODE_LIST)) { const NODE *node = root_node->nd_head; int seen_nodes = 0; @@ -4102,8 +4102,8 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4102 const NODE *key_node = node->nd_head; seen_nodes++; - assert(nd_type(node) == NODE_LIST); - if (key_node && nd_type(key_node) == NODE_LIT && SYMBOL_P(key_node->nd_lit)) { + assert(nd_type_p(node, NODE_LIST)); + if (key_node && nd_type_p(key_node, NODE_LIT) && SYMBOL_P(key_node->nd_lit)) { /* can be keywords */ } else { @@ -4224,7 +4224,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int pop https://github.com/ruby/ruby/blob/trunk/compile.c#L4224 { const NODE *line_node = node; - if (nd_type(node) == NODE_ZLIST) { + if (nd_type_p(node, NODE_ZLIST)) { if (!popped) { ADD_INSN1(ret, line_node, newarray, INT2FIX(0)); } @@ -4361,7 +4361,7 @@ compile_hash(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int meth https://github.com/ruby/ruby/blob/trunk/compile.c#L4361 node = node->nd_head; - if (!node || nd_type(node) == NODE_ZLIST) { + if (!node || nd_type_p(node, NODE_ZLIST)) { if (!popped) { ADD_INSN1(ret, line_node, newhash, INT2FIX(0)); } @@ -4484,7 +4484,7 @@ compile_hash(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int meth https://github.com/ruby/ruby/blob/trunk/compile.c#L4484 FLUSH_CHUNK(); const NODE *kw = node->nd_next->nd_head; - int empty_kw = nd_type(kw) == NODE_LIT && RB_TYPE_P(kw->nd_lit, T_HASH); /* foo( ..., **{}, ...) */ + int empty_kw = nd_type_p(kw, NODE_LIT) && RB_TYPE_P(kw->nd_lit, T_HASH); /* foo( ..., **{}, ...) */ int first_kw = first_chunk && stack_len == 0; /* foo(1,2,3, **kw, ...) */ int last_kw = !node->nd_next->nd_next; /* foo( ..., **kw) */ int only_kw = last_kw && first_kw; /* foo(1,2,3, **kw) */ @@ -4590,7 +4590,7 @@ when_vals(rb_iseq_t *iseq, LINK_ANCHOR *const cond_seq, const NODE *vals, https://github.com/ruby/ruby/blob/trunk/compile.c#L4590 rb_hash_aset(literals, lit, (VALUE)(l1) | 1); } - if (nd_type(val) == NODE_STR) { + if (nd_type_p(val, NODE_STR)) { debugp_param("nd_lit", val->nd_lit); lit = rb_fstring(val->nd_lit); ADD_INSN1(cond_seq, val, putobject, lit); @@ -4884,7 +4884,7 @@ compile_massign_opt(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4884 mem[memindex++] = (v); \ } - if (rhsn == 0 || nd_type(rhsn) != NODE_LIST) { + if (rhsn == 0 || !nd_type_p(rhsn, NODE_LIST)) { return 0; } @@ -4952,7 +4952,7 @@ compile_massign0(rb_iseq_t *iseq, LINK_ANCHOR *const pre, LINK_ANCHOR *const rhs https://github.com/ruby/ruby/blob/trunk/compile.c#L4952 } if (lhs_splat) { - if (nd_type(splatn) == NODE_POSTARG) { + if (nd_type_p(splatn, NODE_POSTARG)) { /*a, b, *r, p1, p2 */ const NODE *postn = splatn->nd_2nd; const NODE *restn = splatn->nd_1st; @@ -5069,7 +5069,7 @@ compile_const_prefix(rb_iseq_t *iseq, const NODE *const node, https://github.com/ruby/ruby/blob/trunk/compile.c#L5069 static int compile_cpath(LINK_ANCHOR *const ret, rb_iseq_t *iseq, const NODE *cpath) { - if (nd_type(cpath) == NODE_COLON3) { + if (nd_type_p(cpath, NODE_COLON3)) { /* toplevel class ::Foo */ ADD_INSN1(ret, cpath, putobject, rb_cObject); return VM_DEFINECLASS_FLAG_SCOPED; @@ -5090,7 +5090,7 @@ compile_cpath(LINK_ANCHOR *const ret, rb_iseq_t *iseq, const NODE *cpath) https://github.com/ruby/ruby/blob/trunk/compile.c#L5090 static inline int private_recv_p(const NODE *node) { - if (nd_type(node->nd_recv) == NODE_SELF) { + if (nd_type_p(node->nd_recv, NODE_SELF)) { NODE *self = node->nd_recv; return self->nd_state != 0; } @@ -5479,7 +5479,7 @@ check_keyword(const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L5479 { /* This check is essentially a code clone of compile_keyword_arg. */ - if (nd_type(node) == NODE_LIST) { + if (nd_type_p(node, NODE_LIST)) { while (node->nd_next) { node = node->nd_next; } @@ -5503,9 +5503,9 @@ setup_args_core(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, https://github.com/ruby/ruby/blob/trunk/compile.c#L5503 } case NODE_ARGSCAT: case NODE_ARGSPUSH: { - int next_is_list = (nd_type(argn->nd_head) == NODE_LIST); + int next_is_list = (nd_type_p(argn->nd_head, NODE_LIST)); VALUE argc = setup_args_core(iseq, args, argn->nd_head, 1, NULL, NULL); - if (nd_type(argn->nd_body) == NODE_LIST) { + if (nd_type_p(argn->nd_body, NODE_LIST)) { /* This branch is needed to avoid "newarraykwsplat" [Bug #16442] */ int rest_len = compile_args(iseq, args, argn->nd_body, NULL, NULL); ADD_INSN1(args, argn, newarray, INT2FIX(rest_len)); @@ -5520,7 +5520,7 @@ setup_args_core(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, https://github.com/ruby/ruby/blob/trunk/compile.c#L5520 if (check_keyword(argn->nd_body)) *flag |= VM_CALL_KW_SPLAT; } - if (nd_type(argn) == NODE_ARGSCAT) { + if (nd_type_p(argn, N (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/