From ef07fab261cce781ca750c1288574d4001f14bcf Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 30 Apr 2023 01:48:18 +0200 Subject: parser: Registry identifiers on scope We are parsing variables/functions and checking if they are defined on scope. Otherwise we fail the parsing with a nice message. Signed-off-by: Johnny Richard Co-authored-by: Carlos Maniero --- src/scope.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/scope.c') diff --git a/src/scope.c b/src/scope.c index 5b696ad..662e59c 100644 --- a/src/scope.c +++ b/src/scope.c @@ -54,7 +54,7 @@ scope_new(void) void scope_destroy(scope_t *scope) { - if (scope->stack->size) { + if (scope->stack->size != 1) { fprintf(stderr, "Stack not cleaned before destroying. This may lead to memory leaks.\n" "Please make sure to call the leave function before destroying it."); @@ -97,7 +97,7 @@ scope_leave(scope_t *scope) } ast_node_t * -scope_get(scope_t *scope, ast_identifier_t *identifier) +scope_get(scope_t *scope, string_view_t name) { for (size_t i = scope->stack->size; i > 0; i--) { vector_t *current_level = vector_at(scope->stack, i - 1); @@ -105,7 +105,7 @@ scope_get(scope_t *scope, ast_identifier_t *identifier) for (size_t j = 0; j < current_level->size; j++) { scope_item_t *item = vector_at(current_level, j); - if (string_view_eq(identifier->name, item->identifier->name)) { + if (string_view_eq(name, item->identifier->name)) { return item->node; } } -- cgit v1.2.3