summaryrefslogtreecommitdiff
path: root/st/SymTableVis.java
diff options
context:
space:
mode:
Diffstat (limited to 'st/SymTableVis.java')
-rw-r--r--st/SymTableVis.java53
1 files changed, 30 insertions, 23 deletions
diff --git a/st/SymTableVis.java b/st/SymTableVis.java
index 2731a26..399ea09 100644
--- a/st/SymTableVis.java
+++ b/st/SymTableVis.java
@@ -9,7 +9,7 @@ import misc.*;
* Provides default methods which visit each node in the tree in depth-first
* order. Your visitors may extend this class.
*/
-public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
+public class SymTableVis<R> extends GJDepthFirst<R,ArrayList<String>> {
public HashMap<String,AbstractInstance> symt = new HashMap<>();
@@ -34,9 +34,10 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f16 -> "}"
* f17 -> "}"
*/
- public String visit(MainClass n, ArrayList<TypeInstance> argu) {
+ public R visit(MainClass n, ArrayList<String> argu) {
- ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>();
+ ArrayList<String> attr_list = new ArrayList<String>();
+ ArrayList<String> mtd_list = new ArrayList<String>();
n.f0.accept(this, argu);
n.f1.accept(this, argu);
@@ -53,7 +54,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
n.f12.accept(this, argu);
n.f13.accept(this, argu);
n.f14.accept(this, attr_list);
- n.f15.accept(this, argu);
+ n.f15.accept(this, mtd_list);
n.f16.accept(this, argu);
n.f17.accept(this, argu);
@@ -63,7 +64,8 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
String id = n.f1.f0.tokenImage;
ClassInstance type = new ClassInstance(id);
- type.set_attrs(attr_list);
+ type.set_attrs(attr_list);
+ type.set_mtds(mtd_list);
PrintFilter.print("Inserting " + id + " => " + type, true);
symt.put(id, type);
@@ -79,16 +81,16 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f4 -> ( MethodDeclaration() )*
* f5 -> "}"
*/
- public String visit(ClassDeclaration n, ArrayList<TypeInstance> argu) {
+ public R visit(ClassDeclaration n, ArrayList<String> argu) {
- ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>();
- // ArrayList<TypeInstance> mtd_list = new ArrayList<TypeInstance>();
+ ArrayList<String> attr_list = new ArrayList<String>();
+ ArrayList<String> mtd_list = new ArrayList<String>();
n.f0.accept(this, argu);
n.f1.accept(this, argu);
n.f2.accept(this, argu);
n.f3.accept(this, attr_list);
- n.f4.accept(this, argu);
+ n.f4.accept(this, mtd_list);
n.f5.accept(this, argu);
@@ -98,7 +100,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
ClassInstance type = new ClassInstance(id);
type.set_attrs(attr_list);
- // type.set_mtds(mtd_list);
+ type.set_mtds(mtd_list);
PrintFilter.print("Inserting " + id + " => " + type, true);
// Safe?
@@ -118,10 +120,10 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f6 -> ( MethodDeclaration() )*
* f7 -> "}"
*/
- public String visit(ClassExtendsDeclaration n, ArrayList<TypeInstance> argu) {
+ public R visit(ClassExtendsDeclaration n, ArrayList<String> argu) {
- ArrayList<TypeInstance> attr_list = new ArrayList<TypeInstance>();
- // ArrayList<TypeInstance> mtd_list = new ArrayList<TypeInstance>();
+ ArrayList<String> attr_list = new ArrayList<String>();
+ ArrayList<String> mtd_list = new ArrayList<String>();
n.f0.accept(this, argu);
n.f1.accept(this, argu);
@@ -129,7 +131,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
n.f3.accept(this, argu);
n.f4.accept(this, argu);
n.f5.accept(this, attr_list);
- n.f6.accept(this, argu);
+ n.f6.accept(this, mtd_list);
n.f7.accept(this, argu);
@@ -140,7 +142,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
ClassInstance type = new ClassInstance(id, ext);
type.set_attrs(attr_list);
- // type.set_mtds(mtd_list);
+ type.set_mtds(mtd_list);
PrintFilter.print("Inserting " + id + " => " + type, true);
symt.put(id, type);
@@ -154,7 +156,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f1 -> Identifier()
* f2 -> ";"
*/
- public String visit(VarDeclaration n, ArrayList<TypeInstance> argu) {
+ public R visit(VarDeclaration n, ArrayList<String> argu) {
PrintFilter.print("Processing declaration", true);
@@ -176,7 +178,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
TypeInstance type = new TypeInstance(id, rtrn);
PrintFilter.print("Inserting " + type, true);
symt.put(id, type);
- argu.add(type);
+ argu.add(id);
n.f0.accept(this, argu);
n.f1.accept(this, argu);
@@ -199,10 +201,10 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f11 -> ";"
* f12 -> "}"
*/
- public String visit(MethodDeclaration n, ArrayList<TypeInstance> argu) {
+ public R visit(MethodDeclaration n, ArrayList<String> argu) {
- ArrayList<TypeInstance> argu_list = new ArrayList<TypeInstance>();
- ArrayList<TypeInstance> var_list = new ArrayList<TypeInstance>();
+ ArrayList<String> argu_list = new ArrayList<String>();
+ ArrayList<String> var_list = new ArrayList<String>();
n.f0.accept(this, argu);
n.f1.accept(this, argu);
@@ -236,11 +238,15 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
}
MethodInstance type = new MethodInstance(id, rtrn);
+ // add children to current class
type.set_args(argu_list);
type.set_locals(var_list);
PrintFilter.print("Inserting " + type, true);
symt.put(id, type);
+ // add method to parent class
+ argu.add(id);
+
return null;
}
@@ -248,7 +254,7 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
* f0 -> Type()
* f1 -> Identifier()
*/
- public String visit(FormalParameter n, ArrayList<TypeInstance> argu) {
+ public R visit(FormalParameter n, ArrayList<String> argu) {
// PrintFilter.print("Processing parameter", true);
String id = n.f1.f0.tokenImage;
@@ -266,8 +272,9 @@ public class SymTableVis extends GJDepthFirst<String,ArrayList<TypeInstance>> {
}
TypeInstance type = new TypeInstance(id, rtrn);
- // PrintFilter.print("Adding Argument " + type, true);
- argu.add(type);
+
+ // add type to parent class
+ argu.add(id);
n.f0.accept(this, argu);
n.f1.accept(this, argu);