Skip to content

Commit 0534324

Browse files
committed
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
1 parent b309d3e commit 0534324

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

include/prism.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void pm_print_node(pm_parser_t *parser, pm_node_t *node);
3434
void pm_parser_metadata(pm_parser_t *parser, const char *metadata);
3535

3636
// Generate a scope node from the given node.
37-
void pm_scope_node_init(pm_node_t *node, pm_scope_node_t *dest);
37+
void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous, pm_parser_t *parser);
3838

3939
// The prism version and the serialization format.
4040
PRISM_EXPORTED_FUNCTION const char * pm_version(void);

include/prism/node.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ PRISM_EXPORTED_FUNCTION const char * pm_node_type_to_str(pm_node_type_t node_typ
3333
// declare them here to avoid generating them.
3434
typedef struct pm_scope_node {
3535
pm_node_t base;
36+
struct pm_scope_node *previous;
3637
pm_node_t *ast_node;
3738
struct pm_parameters_node *parameters;
3839
pm_node_t *body;
3940
pm_constant_id_list_t locals;
41+
pm_parser_t *parser;
42+
43+
// We don't have the CRuby types ID and st_table within Prism
44+
// so we use void *
45+
void *constants; // ID *constants
46+
void *index_lookup_table; // st_table *index_lookup_table
4047
} pm_scope_node_t;
4148

4249
#endif // PRISM_NODE_H

src/prism.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,22 @@ pm_arguments_validate_block(pm_parser_t *parser, pm_arguments_t *arguments, pm_b
664664

665665
// Generate a scope node from the given node.
666666
void
667-
pm_scope_node_init(pm_node_t *node, pm_scope_node_t *scope) {
667+
pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous, pm_parser_t *parser) {
668668
scope->base.type = PM_SCOPE_NODE;
669669
scope->base.location.start = node->location.start;
670670
scope->base.location.end = node->location.end;
671671

672-
scope->ast_node = node;
672+
scope->previous = previous;
673+
scope->parser = parser;
674+
scope->ast_node = (pm_node_t *)node;
673675
scope->parameters = NULL;
674676
scope->body = NULL;
677+
scope->constants = NULL;
678+
if (previous) {
679+
scope->constants = previous->constants;
680+
}
681+
scope->index_lookup_table = NULL;
682+
675683
pm_constant_id_list_init(&scope->locals);
676684

677685
switch (PM_NODE_TYPE(node)) {

0 commit comments

Comments
 (0)