diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 00:35:18 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 00:35:18 -0600 |
commit | bd44adf2b180fcc1198d612a8ae0d2a28468088d (patch) | |
tree | 943261bdab0abcba47388c0ec594a6b84d839102 | |
parent | 765337c53286db39ffc3c64eede602afe3899647 (diff) |
Basic support for 'extended' classes in SymbolTable
-rw-r--r-- | boil/library/BoilVisitor.java | 4 | ||||
-rw-r--r-- | st/AbstractInstance.java | 21 | ||||
-rw-r--r-- | st/SymbolTable.java | 18 |
3 files changed, 14 insertions, 29 deletions
diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java index 43360b9..00d7dc7 100644 --- a/boil/library/BoilVisitor.java +++ b/boil/library/BoilVisitor.java @@ -37,7 +37,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { return attr_index; } - public String memoryReadFilter(String rhs) { + public String memoryReadFilter(TokenKey rhs) { /** * when a method recieves an id of either an alias * or an untranslated variable name, this method will @@ -48,7 +48,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { TypeInstance t; if ((t = this.symt.getType(rhs)) != null) { // memory store - ClassInstance cur = this.symt.getClass(this.symt.getActive(TypeEnum.classname)); + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); attr_index = getVarIndex(cur, t); rhs = String.format("[this+%d]", attr_index); } diff --git a/st/AbstractInstance.java b/st/AbstractInstance.java index 6db9d3c..cdeef8e 100644 --- a/st/AbstractInstance.java +++ b/st/AbstractInstance.java @@ -5,13 +5,11 @@ import java.util.ArrayList; public abstract class AbstractInstance { protected String name; // the literal name of the declaration protected TypeEnum type; // the type of the declaration - protected ArrayList<AbstractInstance> scope; // the scope where the instance is valid protected ClassInstance cls; // the surrounding class public AbstractInstance(String name, TypeEnum type) { this.type = type; this.name = name; - this.scope = new ArrayList<>(); } @Override public String toString() { @@ -27,21 +25,6 @@ public abstract class AbstractInstance { return this.name.hashCode(); } - public void setScope(AbstractInstance ins) { - /** - * If the scope is a MethodInstance, add the single method. - * If the scope is a ClassInstance, add the classes' methods, - * and the class itself. - */ - // FIXME add third pass to properly add all scope information - if (ins instanceof MethodInstance) - this.scope.add(ins); - else if (ins instanceof ClassInstance) { - for (MethodInstance mtd : ((ClassInstance) ins).getMethods()) - this.scope.add(mtd); - } - } - public void addClassInstance(ClassInstance cls) { this.cls = cls; } @@ -54,10 +37,6 @@ public abstract class AbstractInstance { return this.type; } - public ArrayList<AbstractInstance> getScope() { - return this.scope; - } - public ClassInstance getClassInstance() { return this.cls; } diff --git a/st/SymbolTable.java b/st/SymbolTable.java index e6c4738..dcc1f5b 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -50,8 +50,18 @@ public class SymbolTable { cls.getName(), ext.getName())); cls.setExtend(ext); - // for (TypeInstance : ext.attrs) //FIXME add the extended classes' stuff - // cls.add + for (TypeInstance t : ext.getLocals()) { + MinimalLogger.info(String.format("Added %s (%s) as a local var of %s (%s)", + t.getName(), t.getType(), + cls.getName(), cls.getType())); + cls.addLocal(t); + } + for (MethodInstance m : ext.getMethods()) { + MinimalLogger.info(String.format("Added %s (%s) as a method of %s (%s)", + m.getName(), m.getType(), + cls.getName(), cls.getType())); + cls.addMethod(m); + } } public void addLocal(TokenKey lvar) { @@ -60,12 +70,10 @@ public class SymbolTable { if (this.active.get(TypeEnum.method) != null) { // we are in a method MethodInstance par1 = (MethodInstance) this.active.get(TypeEnum.method); par1.addLocal(var); - var.setScope(par1); par = par1; } else { ClassInstance par1 = (ClassInstance) this.active.get(TypeEnum.classname); par1.addLocal(var); - var.setScope(par1); par = par1; } MinimalLogger.info(String.format("Added %s (%s) as a local var of %s (%s)", @@ -77,7 +85,6 @@ public class SymbolTable { ClassInstance cls = (ClassInstance) this.active.get(TypeEnum.classname); MethodInstance lmtd = this.getMethod(mtd); - lmtd.setScope(cls); cls.addMethod(lmtd); MinimalLogger.info(String.format("Added %s as a method of %s", @@ -88,7 +95,6 @@ public class SymbolTable { MethodInstance mtd = (MethodInstance) this.active.get(TypeEnum.method); TypeInstance para = this.getType(arg); - para.setScope(mtd); mtd.addArgument(para); // also adds to local vars MinimalLogger.info(String.format("Added %s as a parameter of %s", |