diff options
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 |