diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-03-31 23:23:06 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-03-31 23:23:06 -0600 |
commit | 35b1ec663c4bf233c1beba823d2c2ebd2759289e (patch) | |
tree | dec867cc6e12f587e87aeb9eea0f7640e0b78d68 | |
parent | 23b6f865aad683d7f3590c46aa4b74f0a030f6af (diff) |
Partial implementation of full class definition storing in SymTable
-rw-r--r-- | st/ClassInstance.java | 18 | ||||
-rw-r--r-- | st/SymTableVis.java | 74 |
2 files changed, 55 insertions, 37 deletions
diff --git a/st/ClassInstance.java b/st/ClassInstance.java index 44b41c9..8b49236 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -11,7 +11,7 @@ public class ClassInstance extends AbstractInstance { super(name, TypeEnum.classname); this.attrs = new ArrayList<>(); this.mtds = new ArrayList<>(); - this.ext = null; + this.ext = ""; } public ClassInstance(String name, String ext) { @@ -20,20 +20,18 @@ public class ClassInstance extends AbstractInstance { } public String toString() { - return this.name + ":" + this.type + "(" + - this.ext + ")"; - } + return name + ":T[" + type + "]E[" + + this.ext + "]A[" + this.attrs.toString() + + "]";//M[" + this.mtds.toString() + "]"; - public void add_attribute(TypeInstance attr) { - this.attrs.add(attr); } - public void add_attribute(MethodInstance mtd) { - this.mtds.add(mtd); + public void set_attrs(ArrayList<TypeInstance> attrs) { + this.attrs = attrs; } - public String get_extend() { - return this.ext; + public void set_mtds(ArrayList<MethodInstance> mtds) { + this.mtds = mtds; } } diff --git a/st/SymTableVis.java b/st/SymTableVis.java index fb62979..2731a26 100644 --- a/st/SymTableVis.java +++ b/st/SymTableVis.java @@ -36,13 +36,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { */ public String visit(MainClass n, ArrayList<TypeInstance> argu) { - PrintFilter.print("Processing main", true); - - String id = n.f1.f0.tokenImage; - - ClassInstance type = new ClassInstance(id); - PrintFilter.print("Inserting " + id + " => " + type, true); - symt.put(id, type); + ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>(); n.f0.accept(this, argu); n.f1.accept(this, argu); @@ -58,10 +52,21 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { n.f11.accept(this, argu); n.f12.accept(this, argu); n.f13.accept(this, argu); - n.f14.accept(this, argu); + n.f14.accept(this, attr_list); n.f15.accept(this, argu); n.f16.accept(this, argu); n.f17.accept(this, argu); + + + PrintFilter.print("Processing main", true); + + String id = n.f1.f0.tokenImage; + + ClassInstance type = new ClassInstance(id); + type.set_attrs(attr_list); + PrintFilter.print("Inserting " + id + " => " + type, true); + symt.put(id, type); + return null; } @@ -76,22 +81,29 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { */ public String visit(ClassDeclaration n, ArrayList<TypeInstance> argu) { + ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>(); + // ArrayList<TypeInstance> mtd_list = new ArrayList<TypeInstance>(); + + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, attr_list); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + + PrintFilter.print("Processing class", true); String id = n.f1.f0.tokenImage; ClassInstance type = new ClassInstance(id); + type.set_attrs(attr_list); + // type.set_mtds(mtd_list); PrintFilter.print("Inserting " + id + " => " + type, true); // Safe? symt.put(id, type); - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); return null; } @@ -107,25 +119,32 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { * f7 -> "}" */ public String visit(ClassExtendsDeclaration n, ArrayList<TypeInstance> argu) { - PrintFilter.print("Processing class", true); - String id = n.f1.f0.tokenImage; - String ext = n.f3.f0.tokenImage; - - ClassInstance type = new ClassInstance(id, ext); - PrintFilter.print("Inserting " + id + " => " + type + - "(" + ext + ")", true); - - symt.put(id, type); + ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>(); + // ArrayList<TypeInstance> mtd_list = new ArrayList<TypeInstance>(); n.f0.accept(this, argu); n.f1.accept(this, argu); n.f2.accept(this, argu); n.f3.accept(this, argu); n.f4.accept(this, argu); - n.f5.accept(this, argu); + n.f5.accept(this, attr_list); n.f6.accept(this, argu); n.f7.accept(this, argu); + + + PrintFilter.print("Processing extension class", true); + + String id = n.f1.f0.tokenImage; + String ext = n.f3.f0.tokenImage; + + ClassInstance type = new ClassInstance(id, ext); + type.set_attrs(attr_list); + // type.set_mtds(mtd_list); + PrintFilter.print("Inserting " + id + " => " + type, true); + + symt.put(id, type); + return null; } @@ -230,7 +249,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { * f1 -> Identifier() */ public String visit(FormalParameter n, ArrayList<TypeInstance> argu) { - PrintFilter.print("Processing parameter", true); + // PrintFilter.print("Processing parameter", true); String id = n.f1.f0.tokenImage; TypeEnum rtrn = TypeEnum.ERROR; @@ -242,11 +261,12 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> { case 2: rtrn = TypeEnum.integer; break; default: - PrintFilter.print("Unsupported case", true); + // PrintFilter.print("Unsupported case", true); + ; } TypeInstance type = new TypeInstance(id, rtrn); - PrintFilter.print("Adding Argument " + type, true); + // PrintFilter.print("Adding Argument " + type, true); argu.add(type); n.f0.accept(this, argu); |