diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-06 19:02:21 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-06 19:02:21 -0600 |
commit | b03859dce5991169b07d1d5040c8faf7ba82e5b5 (patch) | |
tree | 5a1217d441c9323976aef6e45018c9c2522930a6 /st/ClassInstance.java | |
parent | 0ae01301d572b2e69585c4d1cb753ed7fc89dfe3 (diff) |
Rewrite SymbolTable again P1
Diffstat (limited to 'st/ClassInstance.java')
-rw-r--r-- | st/ClassInstance.java | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/st/ClassInstance.java b/st/ClassInstance.java index a444f26..a5f1493 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -3,35 +3,43 @@ package st; import java.util.ArrayList; public class ClassInstance extends AbstractInstance { - private ArrayList<String> attrs; // the list of class-fields - private ArrayList<String> mtds; // the list of methods - private String ext; // the name of the extended class (null if none) + private ClassInstance ext; // the name of the extended class (null if none) + private ArrayList<TypeInstance> attrs; // the list of class-fields + private ArrayList<MethodInstance> mtds; // the list of methods public ClassInstance(String name) { super(name, TypeEnum.classname); this.attrs = new ArrayList<>(); this.mtds = new ArrayList<>(); - this.ext = ""; } - public ClassInstance(String name, String ext) { + public ClassInstance(String name, ClassInstance ext) { super(name, TypeEnum.classname); this.ext = ext; } - public String toString() { - return name + ":T[" + type + "]E[" + - this.ext + "]A[" + this.attrs.toString() + - "]M[" + this.mtds.toString() + "]"; + public void addAttribute(TypeInstance attr) { + this.attrs.add(attr); + } + + public void addMethod(MethodInstance mtd) { + this.mtds.add(mtd); + } + public AbstractInstance getExtend() { + /** + * Returns the parent class, or + * `null' if unset. + */ + return this.ext; } - public void set_attrs(ArrayList<String> attrs) { - this.attrs = attrs; + public ArrayList<TypeInstance> getAttributes() { + return this.attrs; } - public void set_mtds(ArrayList<String> mtds) { - this.mtds = mtds; + public ArrayList<MethodInstance> getMethod() { + return this.mtds; } } |