summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2021-02-01 19:21:03 +0900
committerNARUSE, Yui <naruse@airemix.jp>2021-02-01 19:21:03 +0900
commit42f02a0bac2c037b4e00a9811c5548c5ec7d28a7 (patch)
treeb8369210f34cdfeef3071489f83e81b22b776730 /node.c
parent1b0622d7a9451dbeaadccc1f416b71a98271e097 (diff)
merge revision(s) 6bcc4664bdaebbf9b28a762ae63f476a1ec6cfb2,bb40c5cbe977de9f36a2a739e94e9b2fd4496b6e,c060bdc2b4ab8eeef5374f4174f5de48ab936d74: [Backport #17541]
Return new NODE_LIT As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as NODE_LIT. --- parse.y | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) Ensure symbol list node is either NODE_STR or NODE_DSTR --- parse.y | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) NODE markability should not change by nd_set_type --- node.c | 31 +++++++++++++++++++++++++------ node.h | 12 ++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-)
Diffstat (limited to 'node.c')
-rw-r--r--node.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/node.c b/node.c
index 9b4255bf4a..bef9d7bcbd 100644
--- a/node.c
+++ b/node.c
@@ -1139,7 +1139,7 @@ void
rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
{
n->flags = T_NODE;
- nd_set_type(n, type);
+ nd_init_type(n, type);
n->u1.value = a0;
n->u2.value = a1;
n->u3.value = a2;
@@ -1238,10 +1238,10 @@ ast_newnode_in_bucket(node_buffer_list_t *nb)
return &nb->head->buf[nb->idx++];
}
-NODE *
-rb_ast_newnode(rb_ast_t *ast, enum node_type type)
+RBIMPL_ATTR_PURE()
+static bool
+nodetype_markable_p(enum node_type type)
{
- node_buffer_t *nb = ast->node_buffer;
switch (type) {
case NODE_MATCH:
case NODE_LIT:
@@ -1254,9 +1254,28 @@ rb_ast_newnode(rb_ast_t *ast, enum node_type type)
case NODE_ARGS:
case NODE_ARYPTN:
case NODE_FNDPTN:
- return ast_newnode_in_bucket(&nb->markable);
+ return true;
default:
- return ast_newnode_in_bucket(&nb->unmarkable);
+ return false;
+ }
+}
+
+NODE *
+rb_ast_newnode(rb_ast_t *ast, enum node_type type)
+{
+ node_buffer_t *nb = ast->node_buffer;
+ node_buffer_list_t *bucket =
+ (nodetype_markable_p(type) ? &nb->markable : &nb->unmarkable);
+ return ast_newnode_in_bucket(bucket);
+}
+
+void
+rb_ast_node_type_change(NODE *n, enum node_type type)
+{
+ enum node_type old_type = nd_type(n);
+ if (nodetype_markable_p(old_type) != nodetype_markable_p(type)) {
+ rb_bug("node type changed: %s -> %s",
+ ruby_node_name(old_type), ruby_node_name(type));
}
}