From bb8d3aff71f8f89bed2ab94f382675a2312b1893 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 6 Apr 2024 21:10:55 -0600 Subject: Add test file, fix minor issues in SymbolTable --- st/ClassInstance.java | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'st/ClassInstance.java') diff --git a/st/ClassInstance.java b/st/ClassInstance.java index a5f1493..f926fa6 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -13,20 +13,7 @@ public class ClassInstance extends AbstractInstance { this.mtds = new ArrayList<>(); } - public ClassInstance(String name, ClassInstance ext) { - super(name, TypeEnum.classname); - this.ext = ext; - } - - public void addAttribute(TypeInstance attr) { - this.attrs.add(attr); - } - - public void addMethod(MethodInstance mtd) { - this.mtds.add(mtd); - } - - public AbstractInstance getExtend() { + public ClassInstance getExtend() { /** * Returns the parent class, or * `null' if unset. @@ -38,8 +25,23 @@ public class ClassInstance extends AbstractInstance { return this.attrs; } - public ArrayList getMethod() { + public ArrayList getMethods() { return this.mtds; } + protected void addAttribute(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; + } + } -- cgit v1.2.3