From 0fdee133fccbd34af31f5f4ca530838920d8fc06 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Fri, 6 Oct 2023 14:29:47 +0100 Subject: [PATCH] [ruby/prism] Attach the ast node to the scope So when building instruction sequences for a scope we can reference items from the ast node that requires the scope. This is useful for for loops, where the local variable tables from the parent scope will need to be referenced. https://github.com/ruby/prism/commit/426b1ca094 --- prism/node.h | 1 + prism/prism.c | 1 + 2 files changed, 2 insertions(+) diff --git a/prism/node.h b/prism/node.h index a532badef8..cbfed1b7c9 100644 --- a/prism/node.h +++ b/prism/node.h @@ -33,6 +33,7 @@ PRISM_EXPORTED_FUNCTION const char * pm_node_type_to_str(pm_node_type_t node_typ // declare them here to avoid generating them. typedef struct pm_scope_node { pm_node_t base; + pm_node_t *ast_node; struct pm_parameters_node *parameters; pm_node_t *body; pm_constant_id_list_t locals; diff --git a/prism/prism.c b/prism/prism.c index 9b8ee23253..c43f2687d0 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -669,6 +669,7 @@ pm_scope_node_init(pm_node_t *node, pm_scope_node_t *scope) { scope->base.location.start = node->location.start; scope->base.location.end = node->location.end; + scope->ast_node = node; scope->parameters = NULL; scope->body = NULL; pm_constant_id_list_init(&scope->locals);