node.h: introduce nd_brace to determine if a hash literal is a keyword
NODE_HASH#nd_brace is a flag that is 1 for `foo({ k: 1 })` and 0 for `foo(k: 1)`. nd_alen had been abused for the flag (and the implementation is completely the same), but an explicit name is better to read. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
560bb32fb2
commit
c36a6f97f2
@ -3801,7 +3801,7 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
|
|||||||
|
|
||||||
assert(nd_type(node) == NODE_ARRAY);
|
assert(nd_type(node) == NODE_ARRAY);
|
||||||
if (!key_node) {
|
if (!key_node) {
|
||||||
if (flag && !root_node->nd_alen) *flag |= VM_CALL_KW_SPLAT;
|
if (flag && !root_node->nd_brace) *flag |= VM_CALL_KW_SPLAT;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else if (nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) {
|
else if (nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) {
|
||||||
@ -4785,7 +4785,7 @@ check_keyword(const NODE *node)
|
|||||||
node = node->nd_head;
|
node = node->nd_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nd_type(node) == NODE_HASH && !node->nd_alen) return TRUE;
|
if (nd_type(node) == NODE_HASH && !node->nd_brace) return TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
node.c
6
node.c
@ -557,7 +557,7 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case NODE_HASH:
|
case NODE_HASH:
|
||||||
if (!node->nd_alen) {
|
if (!node->nd_brace) {
|
||||||
ANN("keyword arguments");
|
ANN("keyword arguments");
|
||||||
ANN("format: nd_head");
|
ANN("format: nd_head");
|
||||||
ANN("example: a: 1, b: 2");
|
ANN("example: a: 1, b: 2");
|
||||||
@ -567,8 +567,8 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
|||||||
ANN("format: { [nd_head] }");
|
ANN("format: { [nd_head] }");
|
||||||
ANN("example: { 1 => 2, 3 => 4 }");
|
ANN("example: { 1 => 2, 3 => 4 }");
|
||||||
}
|
}
|
||||||
F_CUSTOM1(nd_alen, "keyword arguments or hash literal") {
|
F_CUSTOM1(nd_brace, "keyword arguments or hash literal") {
|
||||||
switch (node->nd_alen) {
|
switch (node->nd_brace) {
|
||||||
case 0: A("0 (keyword argument)"); break;
|
case 0: A("0 (keyword argument)"); break;
|
||||||
case 1: A("1 (hash literal)"); break;
|
case 1: A("1 (hash literal)"); break;
|
||||||
}
|
}
|
||||||
|
2
node.h
2
node.h
@ -266,6 +266,8 @@ typedef struct RNode {
|
|||||||
#define nd_orig u2.id
|
#define nd_orig u2.id
|
||||||
#define nd_undef u2.node
|
#define nd_undef u2.node
|
||||||
|
|
||||||
|
#define nd_brace u2.argc
|
||||||
|
|
||||||
#define NEW_NODE(t,a0,a1,a2,loc) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2),loc)
|
#define NEW_NODE(t,a0,a1,a2,loc) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2),loc)
|
||||||
|
|
||||||
#define NEW_DEFN(i,a,d,loc) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d,loc),loc)
|
#define NEW_DEFN(i,a,d,loc) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d,loc),loc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user