summaryrefslogtreecommitdiff
path: root/st/AbstractInstance.java
diff options
context:
space:
mode:
Diffstat (limited to 'st/AbstractInstance.java')
-rw-r--r--st/AbstractInstance.java34
1 files changed, 20 insertions, 14 deletions
diff --git a/st/AbstractInstance.java b/st/AbstractInstance.java
index a6c2ca1..bddaccf 100644
--- a/st/AbstractInstance.java
+++ b/st/AbstractInstance.java
@@ -1,14 +1,17 @@
package st;
+import java.util.ArrayList;
+
public abstract class AbstractInstance {
- protected String name; // the literal name of the declaration
- protected TypeEnum type; // the type of the declaration
- protected int size; // the size in memory
- protected AbstractInstance scope; // the surrounding method or class
+ protected String name; // the literal name of the declaration
+ protected TypeEnum type; // the type of the declaration
+ protected int size; // the size in memory
+ protected ArrayList<AbstractInstance> scope; // the scope where the instance is valid
public AbstractInstance(String name, TypeEnum type) {
this.type = type;
this.name = name;
+ this.scope = new ArrayList<>();
}
public String toString() {
@@ -24,11 +27,18 @@ public abstract class AbstractInstance {
return this.name.hashCode();
}
- public void setScope(AbstractInstance cls) {
- if (this.scope != null)
- throw new RuntimeException("setScope: Attempted to set scope twice!");
-
- this.scope = cls;
+ public void setScope(AbstractInstance ins) {
+ /**
+ * If the scope is a MethodInstance, add the single method.
+ * If the scope is a ClassInstance, add the classes' methods,
+ * and the class itself.
+ */
+ if (ins instanceof MethodInstance)
+ this.scope.add(ins);
+ else if (ins instanceof ClassInstance) {
+ for (MethodInstance mtd : ((ClassInstance) ins).getMethods())
+ this.scope.add(mtd);
+ }
}
public String getName() {
@@ -43,11 +53,7 @@ public abstract class AbstractInstance {
return this.size;
}
- public AbstractInstance getScope() {
- /**
- * Returns the scope of the method, or
- * `null' if unset.
- */
+ public ArrayList<AbstractInstance> getScope() {
return this.scope;
}