diff options
Diffstat (limited to 'st/SymbolTable.java')
-rw-r--r-- | st/SymbolTable.java | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/st/SymbolTable.java b/st/SymbolTable.java index 0793a6a..1ec8d29 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -79,6 +79,7 @@ public class SymbolTable { this.symt.put(k, m); cls.addMethod(m); } else { + // if the method exists, we must check if it was overwritten, or overloaded... MethodInstance exist = (MethodInstance) this.symt.get(k); ArrayList<TypeInstance> expected = exist.getArguments(); ArrayList<TypeInstance> actual = m.getArguments(); @@ -183,8 +184,7 @@ public class SymbolTable { (ClassInstance) this.getActive(TypeEnum.classname), (MethodInstance) this.getActive(TypeEnum.method)); AbstractInstance symbol; - TypeInstance ret = ((symbol = this.symt.get(id)) != - null && symbol instanceof TypeInstance) ? + TypeInstance ret = ((symbol = this.symt.get(id)) != null) ? (TypeInstance) symbol : null; if (ret == null) // class var @@ -192,8 +192,7 @@ public class SymbolTable { TypeEnum.integer, (ClassInstance) this.getActive(TypeEnum.classname), null); - ret = ((symbol = this.symt.get(id)) != - null && symbol instanceof TypeInstance) ? + ret = ((symbol = this.symt.get(id)) != null) ? (TypeInstance) symbol : null; if (ret == null) throw new TypecheckException(String.format("No type symbol with name %s was found in %s, %s!", @@ -207,28 +206,20 @@ public class SymbolTable { * Extracts a 'method' (non-type,class) symbol from the * symbol table, with proper scoping. Throws a typecheck error if missing. */ - TokenKey id = new TokenKey(name, - TypeEnum.method, - (ClassInstance) this.getActive(TypeEnum.classname), - null); - AbstractInstance symbol; - MethodInstance ret = ((symbol = this.symt.get(id)) != - null && symbol instanceof MethodInstance) ? - (MethodInstance) symbol : null; - if (ret == null) - throw new TypecheckException(String.format("No method symbol with name %s was found in %s!", - name, this.getActive(TypeEnum.classname))); - return ret; + return this.getMethod(name, (ClassInstance) this.getActive(TypeEnum.classname)); } public MethodInstance getMethod(String name, ClassInstance c) { + /** + * Extracts a 'method' (non-type,class) symbol from the + * symbol table, with proper scoping. Throws a typecheck error if missing. + */ TokenKey id = new TokenKey(name, TypeEnum.method, c, null); AbstractInstance symbol; - MethodInstance ret = ((symbol = this.symt.get(id)) != - null && symbol instanceof MethodInstance) ? + MethodInstance ret = ((symbol = this.symt.get(id)) != null) ? (MethodInstance) symbol : null; if (ret == null) throw new TypecheckException(String.format("No method symbol with name %s was found in %s!", @@ -242,8 +233,7 @@ public class SymbolTable { null, null); AbstractInstance symbol; - ClassInstance ret = ((symbol = this.symt.get(id)) != - null && symbol instanceof ClassInstance) ? + ClassInstance ret = ((symbol = this.symt.get(id)) != null) ? (ClassInstance) symbol : null; if (ret == null) throw new TypecheckException(String.format("No class symbol with name %s was found!", |