summaryrefslogtreecommitdiff
path: root/st
diff options
context:
space:
mode:
Diffstat (limited to 'st')
-rw-r--r--st/AbstractInstance.java3
-rw-r--r--st/ClassInstance.java32
-rw-r--r--st/MethodInstance.java13
-rw-r--r--st/SymbolTable.java16
-rw-r--r--st/TypeInstance.java2
5 files changed, 42 insertions, 24 deletions
diff --git a/st/AbstractInstance.java b/st/AbstractInstance.java
index 7acc3e5..a6c2ca1 100644
--- a/st/AbstractInstance.java
+++ b/st/AbstractInstance.java
@@ -16,7 +16,8 @@ public abstract class AbstractInstance {
}
public boolean equals(AbstractInstance other) {
- return this.name == other.getName();
+ return this.name == other.getName() &&
+ this.type == this.type;
}
public int hashCode() {
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<MethodInstance> getMethod() {
+ public ArrayList<MethodInstance> 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;
+ }
+
}
diff --git a/st/MethodInstance.java b/st/MethodInstance.java
index 25096d2..c7df92f 100644
--- a/st/MethodInstance.java
+++ b/st/MethodInstance.java
@@ -6,7 +6,6 @@ public class MethodInstance extends AbstractInstance {
private ArrayList<TypeInstance> args; // the list of arguments
private ArrayList<TypeInstance> lvars; // the list of local variables
private TypeEnum rtrn; // the returned type
- private ClassInstance scope; // the surrounding class
public MethodInstance(String name, TypeEnum rtrn) {
super(name, TypeEnum.method);
@@ -15,12 +14,20 @@ public class MethodInstance extends AbstractInstance {
this.rtrn = rtrn;
}
- public void addArgument(TypeInstance arg) {
+ public ArrayList<TypeInstance> getArguments() {
+ return this.args;
+ }
+
+ public ArrayList<TypeInstance> getLocals() {
+ return this.lvars;
+ }
+
+ protected void addArgument(TypeInstance arg) {
this.args.add(arg);
this.lvars.add(arg);
}
- public void addLocal(TypeInstance lvar) {
+ protected void addLocal(TypeInstance lvar) {
this.lvars.add(lvar);
}
diff --git a/st/SymbolTable.java b/st/SymbolTable.java
index d6bba37..154c142 100644
--- a/st/SymbolTable.java
+++ b/st/SymbolTable.java
@@ -19,7 +19,7 @@ public class SymbolTable {
public String toString() {
StringBuilder mapAsString = new StringBuilder("{");
for (String key : this.symt.keySet()) {
- mapAsString.append(key + ":" + this.symt.get(key) + ", ");
+ mapAsString.append(key + ":" + this.symt.get(key).getType() + ", ");
}
mapAsString.delete(mapAsString.length()-2, mapAsString.length()).append("}");
return mapAsString.toString();
@@ -37,10 +37,20 @@ public class SymbolTable {
/**
* Methods intended to be used during the second pass
*/
- public void setActive(TypeEnum type, String id) {
+ public void setActive(String id, TypeEnum type) {
this.active.put(type, id);
}
+ public void setExtend(String arg) {
+ String str = this.active.get(TypeEnum.classname);
+ ClassInstance cls = this.getClass(str);
+ ClassInstance ext = this.getClass(arg);
+
+ cls.setExtend(ext);
+ // for (TypeInstance : ext.attrs) //FIXME add the extended classes' stuff
+ // cls.add
+ }
+
public void addAttribute(String arg) {
String str = this.active.get(TypeEnum.classname);
ClassInstance cls = this.getClass(str);
@@ -74,7 +84,7 @@ public class SymbolTable {
TypeInstance var = this.getType(lvar);
var.setScope(mtd);
- mtd.addArgument(var);
+ mtd.addLocal(var);
}
diff --git a/st/TypeInstance.java b/st/TypeInstance.java
index b4031d9..302f9f0 100644
--- a/st/TypeInstance.java
+++ b/st/TypeInstance.java
@@ -2,8 +2,6 @@ package st;
public class TypeInstance extends AbstractInstance {
- private AbstractInstance scope;
-
public TypeInstance(String name, TypeEnum type) {
super(name, type);
}