summaryrefslogtreecommitdiff
path: root/src/scope.c
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-04-30 01:48:18 +0200
committerJohnny Richard <johnny@johnnyrichard.com>2023-04-30 01:55:29 +0200
commitef07fab261cce781ca750c1288574d4001f14bcf (patch)
tree9b4da44aee7cc64cec448adeee31b38e12d29e6d /src/scope.c
parent88a08db927629032d6d4c662e00f0dce2c112ce4 (diff)
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 <johnny@johnnyrichard.com> Co-authored-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'src/scope.c')
-rw-r--r--src/scope.c6
1 files changed, 3 insertions, 3 deletions
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;
}
}