diff options
Diffstat (limited to 'st')
-rw-r--r-- | st/SymTableVars.java | 6 | ||||
-rw-r--r-- | st/SymbolTable.java | 23 | ||||
-rw-r--r-- | st/TokenKey.java | 9 |
3 files changed, 30 insertions, 8 deletions
diff --git a/st/SymTableVars.java b/st/SymTableVars.java index f356a8c..36f02fc 100644 --- a/st/SymTableVars.java +++ b/st/SymTableVars.java @@ -122,6 +122,7 @@ public class SymTableVars<R> extends GJDepthFirst<R,SymbolTable> { (ClassInstance) symt.getActive(TypeEnum.classname), (MethodInstance) symt.getActive(TypeEnum.method)); TypeEnum rtrn = TypeEnum.ERROR; + String cls = null; switch (n.f0.f0.which) { case 0: rtrn = TypeEnum.intarray; break; @@ -130,7 +131,8 @@ public class SymTableVars<R> extends GJDepthFirst<R,SymbolTable> { case 2: rtrn = TypeEnum.integer; break; case 3: - rtrn = TypeEnum.classname; break; + rtrn = TypeEnum.classname; + cls = ((Identifier) n.f0.f0.choice).f0.tokenImage; break; default: MinimalLogger.severe("Unsupported case"); } @@ -139,7 +141,7 @@ public class SymTableVars<R> extends GJDepthFirst<R,SymbolTable> { (ClassInstance) symt.getActive(TypeEnum.classname)); symt.put(id, instance); symt.addLocal(id.getName()); - + symt.addClassInstance(instance, cls); return null; } diff --git a/st/SymbolTable.java b/st/SymbolTable.java index a8a6dcf..ed1506b 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -109,6 +109,9 @@ public class SymbolTable { this.getClass(c) : null; + if (cls != null) + MinimalLogger.info(String.format("%s is an instance of class %s", + t.getName(), c)); t.addClassInstance(cls); } @@ -159,6 +162,20 @@ public class SymbolTable { return ret; } + public MethodInstance getMethod(String name, ClassInstance c) { + TokenKey id = new TokenKey(name, + c, + null); + AbstractInstance symbol; + MethodInstance ret = ((symbol = this.symt.get(id)) != + null && symbol instanceof MethodInstance) ? + (MethodInstance) symbol : null; + if (ret == null) + MinimalLogger.severe(String.format("getMethod returning null for missing alias %s!", + id)); + return ret; + } + public ClassInstance getClass(String name) { TokenKey id = new TokenKey(name, null, @@ -170,11 +187,13 @@ public class SymbolTable { if (ret == null) MinimalLogger.severe(String.format("getClass returning null for missing alias %s!", id)); - return ret; + MinimalLogger.severe(String.format("It was: %s", + this.symt.get(id))); + return ret; } public AbstractInstance getActive(TypeEnum type) { - return this.active.get(type); + return this.active.get(type); } } diff --git a/st/TokenKey.java b/st/TokenKey.java index 54086c5..941c83f 100644 --- a/st/TokenKey.java +++ b/st/TokenKey.java @@ -29,11 +29,12 @@ public class TokenKey { boolean ret = false; TokenKey o; if (other instanceof TokenKey && - (o = (TokenKey) other).name == this.name && - o.cls == this.cls && - o.mtd == this.mtd) { + (o = (TokenKey) other).name.equals(this.name) && + ((o.cls == null && this.cls == null) || + (o.cls != null && o.cls.equals(this.cls))) && + ((o.mtd == null && this.mtd == null) || + (o.mtd != null && o.mtd.equals(this.mtd)))) ret = true; - } return ret; } |