aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-10-16 14:28:17 -0700
committergit <svn-admin@ruby-lang.org>2023-10-16 21:53:11 +0000
commit67a987f82bc8a2b7ec15581306873530821fcf9e (patch)
tree74eede466a548ea4ea1bf8721069b67d9fdbae60 /prism
parent3dec5dc3462286cdbdb53e496e6175a82bdc39b7 (diff)
downloadruby-67a987f82bc8a2b7ec15581306873530821fcf9e.tar.gz
[ruby/prism] Change ScopeNode to point to previous ScopeNode
Amend ScopeNode to point to previous ScopeNode, and to have void* pointers to constants and index_lookup_table https://github.com/ruby/prism/commit/0534324312
Diffstat (limited to 'prism')
-rw-r--r--prism/node.h7
-rw-r--r--prism/prism.c12
-rw-r--r--prism/prism.h2
3 files changed, 18 insertions, 3 deletions
diff --git a/prism/node.h b/prism/node.h
index cbfed1b7c9..403e84e0d3 100644
--- a/prism/node.h
+++ b/prism/node.h
@@ -33,10 +33,17 @@ 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;
+ struct pm_scope_node *previous;
pm_node_t *ast_node;
struct pm_parameters_node *parameters;
pm_node_t *body;
pm_constant_id_list_t locals;
+ pm_parser_t *parser;
+
+ // We don't have the CRuby types ID and st_table within Prism
+ // so we use void *
+ void *constants; // ID *constants
+ void *index_lookup_table; // st_table *index_lookup_table
} pm_scope_node_t;
#endif // PRISM_NODE_H
diff --git a/prism/prism.c b/prism/prism.c
index 02175334d5..aa69a938b2 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -664,14 +664,22 @@ pm_arguments_validate_block(pm_parser_t *parser, pm_arguments_t *arguments, pm_b
// Generate a scope node from the given node.
void
-pm_scope_node_init(pm_node_t *node, pm_scope_node_t *scope) {
+pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous, pm_parser_t *parser) {
scope->base.type = PM_SCOPE_NODE;
scope->base.location.start = node->location.start;
scope->base.location.end = node->location.end;
- scope->ast_node = node;
+ scope->previous = previous;
+ scope->parser = parser;
+ scope->ast_node = (pm_node_t *)node;
scope->parameters = NULL;
scope->body = NULL;
+ scope->constants = NULL;
+ if (previous) {
+ scope->constants = previous->constants;
+ }
+ scope->index_lookup_table = NULL;
+
pm_constant_id_list_init(&scope->locals);
switch (PM_NODE_TYPE(node)) {
diff --git a/prism/prism.h b/prism/prism.h
index 797004d4f8..c06e0fd278 100644
--- a/prism/prism.h
+++ b/prism/prism.h
@@ -34,7 +34,7 @@ void pm_print_node(pm_parser_t *parser, pm_node_t *node);
void pm_parser_metadata(pm_parser_t *parser, const char *metadata);
// Generate a scope node from the given node.
-void pm_scope_node_init(pm_node_t *node, pm_scope_node_t *dest);
+void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous, pm_parser_t *parser);
// The prism version and the serialization format.
PRISM_EXPORTED_FUNCTION const char * pm_version(void);