summaryrefslogtreecommitdiff
path: root/stTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'stTest.java')
-rw-r--r--stTest.java145
1 files changed, 0 insertions, 145 deletions
diff --git a/stTest.java b/stTest.java
deleted file mode 100644
index b6fd7ae..0000000
--- a/stTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-import java.io.*;
-import visitor.*;
-import parse.*;
-import syntaxtree.*;
-import java.util.*;
-import st.*;
-import misc.*;
-
-
-/**
- * A small method to test the basic functionality
- * of the st Instance library
- */
-public class stTest {
-
- public static void FactorialTests(SymbolTable symt) {
- /*
- class Factorial{
- ....public static void main(String[] a){
- ........System.out.println(new Fac().ComputeFac(10));
- ....}
- }
- class Fac {
- ....int[] useless_var ;
- ....public int ComputeFac(int num){
- ........int num_aux ;
- ........if (num < 1)
- ............num_aux = 1 ;
- ........else
- ............num_aux = num * (this.ComputeFac(num-1)) ;
- ........return num_aux ;
- ....}
- }
- class Fac2 extends Fac {
- }
-
- The below is a manual practice run of the SymbolTable class.
- */
-
- ArrayList<TypeInstance> attrs_in_factorial = new ArrayList<>();
- ArrayList<MethodInstance> mtds_in_factorial = new ArrayList<>();
- mtds_in_factorial.add(symt.getMethod("main"));
- ArrayList<TypeInstance> attrs_in_fac = new ArrayList<>();
- attrs_in_fac.add(symt.getType("useless_var"));
- ArrayList<MethodInstance> mtds_in_fac = new ArrayList<>();
- mtds_in_fac.add(symt.getMethod("ComputeFac"));
- ArrayList<TypeInstance> attrs_in_fac2 = new ArrayList<>(); // FIXME
- ArrayList<MethodInstance> mtds_in_fac2 = new ArrayList<>(); // FIXME
-
- System.out.println("test class children");
- System.out.println(symt.getClass("Factorial").getLocals().equals(attrs_in_factorial));
- System.out.println(symt.getClass("Factorial").getMethods().equals(mtds_in_factorial));
- System.out.println(symt.getClass("Fac").getLocals().equals(attrs_in_fac));
- System.out.println(symt.getClass("Fac").getMethods().equals(mtds_in_fac));
- System.out.println(symt.getClass("Fac2").getLocals().equals(attrs_in_fac2));
- System.out.println(symt.getClass("Fac2").getMethods().equals(mtds_in_fac2));
-
- ArrayList<TypeInstance> args_in_computefac = new ArrayList<>();
- args_in_computefac.add(symt.getType("num"));
- ArrayList<TypeInstance> locals_in_computefac = new ArrayList<>(args_in_computefac);
- locals_in_computefac.add(symt.getType("num_aux"));
-
- System.out.println("test method children");
- System.out.println(symt.getMethod("ComputeFac").getArguments().equals(args_in_computefac));
- System.out.println(symt.getMethod("ComputeFac").getLocals().equals(locals_in_computefac));
-
- ClassInstance exts_factorial = null;
- ClassInstance exts_fac = null;
- ClassInstance exts_fac2 = symt.getClass("Fac");
-
- System.out.println("test inheritance");
- System.out.println(symt.getClass("Factorial").getExtend() == exts_factorial);
- System.out.println(symt.getClass("Fac").getExtend() == exts_fac);
- System.out.println(symt.getClass("Fac2").getExtend() == exts_fac2);
-
- ArrayList<AbstractInstance> scope_main = new ArrayList<>();
- scope_main.add(symt.getClass("Factorial"));
- ArrayList<AbstractInstance> scope_computefac = new ArrayList<>();
- scope_computefac.add(symt.getClass("Fac"));
- ArrayList<AbstractInstance> scope_uselessvar = new ArrayList<>();
- scope_uselessvar.add(symt.getClass("Fac"));
- ArrayList<AbstractInstance> scope_num = new ArrayList<>();
- scope_num.add(symt.getMethod("ComputeFac"));
- ArrayList<AbstractInstance> scope_numaux = new ArrayList<>();
- scope_numaux.add(symt.getMethod("ComputeFac"));
-
- System.out.println("test scope");
- System.out.println(symt.getMethod("main").getScope().equals(scope_main));
- System.out.println(symt.getMethod("ComputeFac").getScope().equals(scope_computefac));
- System.out.println(symt.getType("useless_var").getScope().equals(scope_uselessvar));
- System.out.println(symt.getType("num").getScope().equals(scope_num));
- System.out.println(symt.getType("num_aux").getScope().equals(scope_numaux));
- System.out.println();
- }
-
- public static void main(String[] args) {
-
- SymbolTable symt = new SymbolTable();
-
- /* pass one */
- symt.put("Factorial", new ClassInstance("Factorial"));
- symt.put("main", new MethodInstance("main", TypeEnum.ERROR));
- symt.put("Fac", new ClassInstance("Fac"));
- symt.put("useless_var", new TypeInstance("useless_var", TypeEnum.intarray));
- symt.put("ComputeFac", new MethodInstance("ComputeFac", TypeEnum.integer));
- symt.put("num", new TypeInstance("num", TypeEnum.integer));
- symt.put("num_aux", new TypeInstance("num_aux", TypeEnum.integer));
- symt.put("Fac2", new ClassInstance("Fac2"));
-
- /* pass two */
- symt.setActive(TypeEnum.classname, "Factorial");
- symt.setActive(TypeEnum.method, "main");
- symt.addMethod("main");
- symt.removeActive(TypeEnum.method);
- symt.setActive(TypeEnum.classname, "Fac");
- symt.addLocal("useless_var");
- symt.setActive(TypeEnum.method, "ComputeFac");
- symt.addMethod("ComputeFac");
- symt.addParameter("num");
- symt.addLocal("num_aux");
- symt.removeActive(TypeEnum.method);
- symt.setActive(TypeEnum.classname, "Fac2");
- symt.setExtend("Fac");
-
- System.out.println("Manual results:");
- FactorialTests(symt);
-
- /* using the visitors */
- // Node root = null;
- // try {
- // root = new MiniJavaParser(System.in).Goal();
- // symt = new SymbolTable();
- // root.accept(new SymTableBottomUp<Void>(), symt);
- // root.accept(new SymTableTopDown<Void>(), symt);
-
- // System.out.println("Visitor results:");
- // FactorialTests(symt);
- // }
- // catch (ParseException e) {
- // System.out.println(e.toString());
- // System.exit(1);
- // }
-
- }
-}