package st; import java.util.ArrayList; public class ClassInstance extends AbstractInstance { 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<>(); } @Override public boolean equals(Object other) { ClassInstance o; return (other instanceof ClassInstance && ((o = (ClassInstance) other).getName() == this.getName())); } public ClassInstance getExtend() { /** * Returns the parent class, or * `null' if unset. */ return this.ext; } public ArrayList getLocals() { return this.attrs; } public ArrayList getMethods() { return this.mtds; } public int getSize() { return 4 * (this.attrs.size() + this.mtds.size()); } protected void addLocal(TypeInstance attr) { this.attrs.add(attr); } protected void addMethod(MethodInstance mtd) { this.mtds.add(mtd); } protected void setExtend(ClassInstance ext) { if (this.ext != null) throw new RuntimeException("setExtend: Attempted to set extended class twice!"); this.ext = ext; } }