diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 12:58:10 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 12:58:10 -0600 |
commit | c28a1cc9d206bdde41a621b018c01980b3c8a617 (patch) | |
tree | 90e9de370313682558172c8cebac9389b48c0855 /st/SymbolTable.java | |
parent | bd44adf2b180fcc1198d612a8ae0d2a28468088d (diff) |
Rewrote Symbol Table to be more context aware and avoid collisions
Diffstat (limited to 'st/SymbolTable.java')
-rw-r--r-- | st/SymbolTable.java | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/st/SymbolTable.java b/st/SymbolTable.java index dcc1f5b..a8a6dcf 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -42,7 +42,7 @@ public class SymbolTable { /** * Methods intended to be used during the second pass */ - public void setExtend(TokenKey arg) { + public void setExtend(String arg) { ClassInstance cls = (ClassInstance) this.active.get(TypeEnum.classname); ClassInstance ext = this.getClass(arg); @@ -64,7 +64,7 @@ public class SymbolTable { } } - public void addLocal(TokenKey lvar) { + public void addLocal(String lvar) { TypeInstance var = this.getType(lvar); AbstractInstance par; if (this.active.get(TypeEnum.method) != null) { // we are in a method @@ -81,7 +81,7 @@ public class SymbolTable { par.getName(), par.getType())); } - public void addMethod(TokenKey mtd) { + public void addMethod(String mtd) { ClassInstance cls = (ClassInstance) this.active.get(TypeEnum.classname); MethodInstance lmtd = this.getMethod(mtd); @@ -91,7 +91,7 @@ public class SymbolTable { lmtd.getName(), cls.getName())); } - public void addParameter(TokenKey arg) { + public void addParameter(String arg) { MethodInstance mtd = (MethodInstance) this.active.get(TypeEnum.method); TypeInstance para = this.getType(arg); @@ -99,11 +99,14 @@ public class SymbolTable { MinimalLogger.info(String.format("Added %s as a parameter of %s", para.getName(), mtd.getName())); + MinimalLogger.info(String.format("Added %s as a localvar of %s", + para.getName(), mtd.getName())); + } - public void addClassInstance(AbstractInstance t, String c) { + public void addClassInstance(TypeInstance t, String c) { ClassInstance cls = (c != null) ? - this.getClass(new TokenKey(c, 0)) : + this.getClass(c) : null; t.addClassInstance(cls); @@ -128,7 +131,10 @@ public class SymbolTable { this.active.remove(type); } - public TypeInstance getType(TokenKey id) { + public TypeInstance getType(String name) { + TokenKey id = new TokenKey(name, + (ClassInstance) this.getActive(TypeEnum.classname), + (MethodInstance) this.getActive(TypeEnum.method)); AbstractInstance symbol; TypeInstance ret = ((symbol = this.symt.get(id)) != null && symbol instanceof TypeInstance) ? @@ -139,7 +145,10 @@ public class SymbolTable { return ret; } - public MethodInstance getMethod(TokenKey id) { + public MethodInstance getMethod(String name) { + TokenKey id = new TokenKey(name, + (ClassInstance) this.getActive(TypeEnum.classname), + null); AbstractInstance symbol; MethodInstance ret = ((symbol = this.symt.get(id)) != null && symbol instanceof MethodInstance) ? @@ -150,7 +159,10 @@ public class SymbolTable { return ret; } - public ClassInstance getClass(TokenKey id) { + public ClassInstance getClass(String name) { + TokenKey id = new TokenKey(name, + null, + null); AbstractInstance symbol; ClassInstance ret = ((symbol = this.symt.get(id)) != null && symbol instanceof ClassInstance) ? |