diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-06 22:36:22 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-06 22:38:00 -0600 |
commit | 8f1eeb71061e4009abec9356c9430075c0a7f7ee (patch) | |
tree | 5d4f35717bd90711b19acbb4feab37f469be19ac /st/SymbolTable.java | |
parent | 1eac68a0e5fd00ee563ac43cb6f4dac3a4fb2c33 (diff) |
Add SymTableTopDown, changes to SymbolTable to make it possible
Delete SymTableVis
Diffstat (limited to 'st/SymbolTable.java')
-rw-r--r-- | st/SymbolTable.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/st/SymbolTable.java b/st/SymbolTable.java index 154c142..9d7ffb4 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -37,10 +37,14 @@ public class SymbolTable { /** * Methods intended to be used during the second pass */ - public void setActive(String id, TypeEnum type) { + public void setActive(TypeEnum type, String id) { this.active.put(type, id); } + public void removeActive(TypeEnum type) { + this.active.remove(type); + } + public void setExtend(String arg) { String str = this.active.get(TypeEnum.classname); ClassInstance cls = this.getClass(str); @@ -51,13 +55,19 @@ public class SymbolTable { // cls.add } - public void addAttribute(String arg) { - String str = this.active.get(TypeEnum.classname); - ClassInstance cls = this.getClass(str); - TypeInstance attr = this.getType(arg); - - attr.setScope(cls); - cls.addAttribute(attr); + public void addLocal(String lvar) { + TypeInstance var = this.getType(lvar); + if (this.active.get(TypeEnum.method) != null) { // we are in a method + String str = this.active.get(TypeEnum.method); + MethodInstance mtd = this.getMethod(str); + mtd.addLocal(var); + var.setScope(mtd); + } else { + String str = this.active.get(TypeEnum.classname); + ClassInstance cls = this.getClass(str); + cls.addLocal(var); + var.setScope(cls); + } } public void addMethod(String mtd) { @@ -78,15 +88,6 @@ public class SymbolTable { mtd.addArgument(para); // also adds to local vars } - public void addLocal(String lvar) { - String str = this.active.get(TypeEnum.method); - MethodInstance mtd = this.getMethod(str); - TypeInstance var = this.getType(lvar); - - var.setScope(mtd); - mtd.addLocal(var); - } - /** * Methods to safely retrieve differentiable types |