summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2020-10-20 14:34:14 -0300
committerGeorge Marques <george@gmarqu.es>2020-10-20 14:57:31 -0300
commit11c05642fe1e57f87a0a5dbee822c13e45f0f54b (patch)
tree361a473edb3e951185bc44342ebfe5643fdd3cef /modules
parent48b91b900dac5327da55f499e720c538f8649c02 (diff)
downloadredot-engine-11c05642fe1e57f87a0a5dbee822c13e45f0f54b.tar.gz
GDScript: Fix handling of scope for local variables
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_compiler.h14
1 files changed, 5 insertions, 9 deletions
diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h
index db02079d26..fe34d6cba3 100644
--- a/modules/gdscript/gdscript_compiler.h
+++ b/modules/gdscript/gdscript_compiler.h
@@ -51,12 +51,11 @@ class GDScriptCompiler {
GDScriptCodeGenerator *generator = nullptr;
Map<StringName, GDScriptCodeGenerator::Address> parameters;
Map<StringName, GDScriptCodeGenerator::Address> locals;
- List<Set<StringName>> locals_in_scope;
+ List<Map<StringName, GDScriptCodeGenerator::Address>> locals_stack;
GDScriptCodeGenerator::Address add_local(const StringName &p_name, const GDScriptDataType &p_type) {
uint32_t addr = generator->add_local(p_name, p_type);
locals[p_name] = GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::LOCAL_VARIABLE, addr, p_type);
- locals_in_scope.back()->get().insert(p_name);
return locals[p_name];
}
@@ -102,17 +101,14 @@ class GDScriptCompiler {
}
void start_block() {
- Set<StringName> scope;
- locals_in_scope.push_back(scope);
+ Map<StringName, GDScriptCodeGenerator::Address> old_locals = locals;
+ locals_stack.push_back(old_locals);
generator->start_block();
}
void end_block() {
- Set<StringName> &scope = locals_in_scope.back()->get();
- for (Set<StringName>::Element *E = scope.front(); E; E = E->next()) {
- locals.erase(E->get());
- }
- locals_in_scope.pop_back();
+ locals = locals_stack.back()->get();
+ locals_stack.pop_back();
generator->end_block();
}
};