From b03859dce5991169b07d1d5040c8faf7ba82e5b5 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 6 Apr 2024 19:02:21 -0600 Subject: Rewrite SymbolTable again P1 --- st/ClassInstance.java | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'st/ClassInstance.java') 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 attrs; // the list of class-fields - private ArrayList 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 attrs; // the list of class-fields + private ArrayList 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 attrs) { - this.attrs = attrs; + public ArrayList getAttributes() { + return this.attrs; } - public void set_mtds(ArrayList mtds) { - this.mtds = mtds; + public ArrayList getMethod() { + return this.mtds; } } -- cgit v1.2.3