summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
authoryui-knk <[email protected]>2024-07-18 13:47:13 +0900
committerYuichiro Kaneko <[email protected]>2024-07-20 11:25:26 +0900
commit6be539aab5b8fd66685e6079afc6ca83c89fcbd6 (patch)
treefc3164f28dbb1f2a4ee752626521648937f15289 /node.c
parent174c01b80e31236ca144dc510a662cd18b9a20ee (diff)
Change UNDEF Node structure
Change UNDEF Node to hold their items to keep the original grammar structure. For example: ``` undef a, b ``` Before: ``` @ NODE_BLOCK (id: 4, line: 1, location: (1,6)-(1,10))* +- nd_head (1): | @ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,7)) | +- nd_undef: | @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7)) | +- string: :a +- nd_head (2): @ NODE_UNDEF (id: 3, line: 1, location: (1,9)-(1,10)) +- nd_undef: @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10)) +- string: :b ``` After: ``` @ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,10))* +- nd_undefs: +- length: 2 +- element (0): | @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7)) | +- string: :a +- element (1): @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10)) +- string: :b ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11213
Diffstat (limited to 'node.c')
-rw-r--r--node.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/node.c b/node.c
index 2efcd6eba8..1a52fbba3d 100644
--- a/node.c
+++ b/node.c
@@ -163,6 +163,14 @@ parser_tokens_free(rb_ast_t *ast, rb_parser_ary_t *tokens)
}
static void
+parser_nodes_free(rb_ast_t *ast, rb_parser_ary_t *nodes)
+{
+ /* Do nothing for nodes because nodes are freed when rb_ast_t is freed */
+ xfree(nodes->data);
+ xfree(nodes);
+}
+
+static void
free_ast_value(rb_ast_t *ast, void *ctx, NODE *node)
{
switch (nd_type(node)) {
@@ -206,6 +214,9 @@ free_ast_value(rb_ast_t *ast, void *ctx, NODE *node)
case NODE_IMAGINARY:
xfree(RNODE_IMAGINARY(node)->val);
break;
+ case NODE_UNDEF:
+ parser_nodes_free(ast, RNODE_UNDEF(node)->nd_undefs);
+ break;
default:
break;
}