From 6385450ddba34bc28bd7492d126fd38cb3f86f36 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 12 Aug 2024 19:01:21 +0300 Subject: make id scope point to defining scope + Allows defers to refer to the correct scope, but might be a bit surprising since effectively all other nodes use the scope to refer to the containing scope rather than the defining scope. --- src/actualize.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/actualize.c') diff --git a/src/actualize.c b/src/actualize.c index 602325a..66fcff9 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -1183,12 +1183,12 @@ static int actualize_block(struct act_state *state, block_defers(node) = clone_defers(state, defers); if (!block_defers(node)) { internal_error("failed cloning defers"); + clear_defers(state, defers); return -1; } - - clear_defers(state, defers); } + clear_defers(state, defers); return 0; } @@ -1197,7 +1197,6 @@ static int actualize_id(struct act_state *state, { UNUSED(state); assert(id && id->k == AST_ID); - id->scope = scope; /** @todo vars and procs kind of override eachother, i.e. * do_something(){..} @@ -1218,8 +1217,13 @@ static int actualize_id(struct act_state *state, return -1; } + /* set scope of use to scope of definition, this makes sure that when + * lower() calls scope_find_*() it gets the one we just found and not a + * possible shadow. This is a pretty major hack, it might be more clean + * to add a ->def field into the AST or something but this works for + * now. */ + id->scope = decl->scope; set_type(id, decl->t); - decl->uses++; return 0; } @@ -2230,7 +2234,6 @@ static int actualize_dot(struct act_state *state, id); if (exists) { assert(exists->t); - exists->uses++; set_type(node, exists->t); return 0; } @@ -2415,7 +2418,6 @@ static int actualize_fetch(struct act_state *state, struct scope *scope, return -1; } - member->uses++; set_type(fetch, member->t); return 0; } -- cgit v1.3