updates
authorbdemsky <bdemsky>
Sat, 25 Feb 2006 00:03:44 +0000 (00:03 +0000)
committerbdemsky <bdemsky>
Sat, 25 Feb 2006 00:03:44 +0000 (00:03 +0000)
Robust/src/IR/ClassDescriptor.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Flat/FlatNode.java
Robust/src/IR/Tree/LiteralNode.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java [new file with mode: 0644]
Robust/src/Main/Main.java

index 72b0802a6004876c36cb3900305a323c6a3e35d3..f9af871cb7b0caf1e9ea57ab60738550171d6fb2 100644 (file)
@@ -81,4 +81,8 @@ public class ClassDescriptor extends Descriptor {
     public void setSuper(String superclass) {
        this.superclass=superclass;
     }
+
+    protected String getSuper() {
+       return superclass;
+    }
 }
index 137358718a330896d19fda1143053d95a12a517d..f8c214f58250a1a2fa0cb88d7cfa17a8222f730d 100644 (file)
@@ -69,7 +69,6 @@ public class BuildFlat {
        return new NodePair(fln,fln);
     }
 
-
     private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) {
        TypeDescriptor td=con.getType();
        FlatNew fn=new FlatNew(td, out_temp);
@@ -97,9 +96,9 @@ public class BuildFlat {
        FlatNode last=null;
        TempDescriptor thisarg=null;
 
-       if (min.getExpression()==null) {
+       if (min.getExpression()!=null) {
            thisarg=TempDescriptor.tempFactory("thisarg");
-           NodePair np=flattenExpressionNode(min.getExpression(),temps[0]);
+           NodePair np=flattenExpressionNode(min.getExpression(),thisarg);
            first=np.getBegin();
            last=np.getEnd();
        }
index 4824875ac575001852b5a123ae7a135855c48183..ba5641bf2d05489f1fa298058fdc5d120771a1d4 100644 (file)
@@ -5,6 +5,11 @@ public class FlatNode {
     protected Vector next;
     protected Vector prev;
 
+    public FlatNode() {
+       next=new Vector();
+       prev=new Vector();
+    }
+
     public String toString() {
        throw new Error();
     }
index db1f90cb2d25c823fb73a93ba90c6863527514c7..f3b71f01f8a99c42562e848a12bbaf4f213d8b11 100644 (file)
@@ -1,4 +1,7 @@
 package IR.Tree;
+import IR.TypeDescriptor;
+import IR.TypeUtil;
+
 
 public class LiteralNode extends ExpressionNode {
     public final static int INTEGER=1;
@@ -9,57 +12,34 @@ public class LiteralNode extends ExpressionNode {
     public final static int NULL=6;
 
     Object value;
-    int type;
-    
+    TypeDescriptor type;
+    String typestr;
+
     public LiteralNode(String type, Object o) {
-       this.type=parseType(type);
+       typestr=type;
        value=o;
+       type=null;
     }
 
-    public Object getValue() {
-       return value;
+    public TypeDescriptor getType() {
+       return type;
     }
 
-    private static int parseType(String type) {
-       if (type.equals("integer"))
-           return INTEGER;
-       else if (type.equals("float"))
-           return FLOAT;
-       else if (type.equals("boolean"))
-           return BOOLEAN;
-       else if (type.equals("char"))
-           return CHAR;
-       else if (type.equals("string"))
-           return STRING;
-       else if (type.equals("null"))
-           return NULL;
-       else throw new Error();
+    public void setType(TypeDescriptor td) {
+       type=td;
     }
 
-    private String getStringType() {
-       if (type==INTEGER)
-           return "integer";
-       else if (type==FLOAT)
-           return "float";     
-       else if (type==BOOLEAN)
-           return "boolean";
-       else if (type==CHAR)
-           return "char";
-       else if (type==STRING)
-           return "string";
-       else if (type==NULL)
-           return "null";
-       else throw new Error();
-
+    public Object getValue() {
+       return value;
     }
 
     public String printNode(int indent) {
-       if (type==NULL)
+       if (typestr.equals("null"))
            return "null";
-       if (type==STRING) {
+       if (typestr.equals("string")) {
            return '"'+escapeString(value.toString())+'"';
        }
-       return "/*"+getType()+ "*/"+value.toString();
+       return "/*"+typestr+ "*/"+value.toString();
     }
     private static String escapeString(String st) {
        String new_st="";
index 9c8294b72adcc684831a98cd11256e7968d10552..fcec66abc6ee9afdc50761b411481c4269de495c 100644 (file)
@@ -5,9 +5,11 @@ import IR.*;
 
 public class SemanticCheck {
     State state;
+    TypeUtil typeutil;
 
-    public SemanticCheck(State state) {
+    public SemanticCheck(State state, TypeUtil tu) {
        this.state=state;
+       this.typeutil=tu;
     }
 
     public void semanticCheck() {
@@ -112,7 +114,8 @@ public class SemanticCheck {
            nametable.add(vd);
        } else
            throw new Error(vd.getSymbol()+" defined a second time");
-       checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
+       if (dn.getExpression()!=null)
+           checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
     }
     
     void checkSubBlockNode(MethodDescriptor md, SymbolTable nametable, SubBlockNode sbn) {
@@ -173,6 +176,7 @@ public class SemanticCheck {
     }
 
     void checkLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
+       
     }
 
     void checkMethodInvokeNode(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java
new file mode 100644 (file)
index 0000000..9912380
--- /dev/null
@@ -0,0 +1,51 @@
+package IR;
+import java.util.*;
+
+public class TypeUtil {
+    public static final String StringClass="java.lang.String";
+    State state;
+    Hashtable supertable;
+
+    public TypeUtil(State state) {
+       this.state=state;
+       createTables();
+    }
+
+    public ClassDescriptor getClass(String classname) {
+       ClassDescriptor cd=(ClassDescriptor)state.getClassSymbolTable().get(classname);
+       return cd;
+    }
+
+    private void createTables() {
+       supertable=new Hashtable();
+       Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+       while(classit.hasNext()) {
+           ClassDescriptor cd=(ClassDescriptor)classit.next();
+           String superc=cd.getSuper();
+           if (superc!=null) {
+               ClassDescriptor cd_super=getClass(superc);
+               supertable.put(cd,cd_super);
+           }
+       }
+    }
+
+    public ClassDescriptor getSuper(ClassDescriptor cd) {
+       return (ClassDescriptor)supertable.get(cd);
+    }
+
+    public boolean isSuperorType(ClassDescriptor possiblesuper, ClassDescriptor cd2) {
+       if (possiblesuper==cd2)
+           return true;
+       else
+           return isSuper(possiblesuper, cd2);
+    }
+
+    public boolean isSuper(ClassDescriptor possiblesuper, ClassDescriptor cd2) {
+       while(cd2!=null) {
+           cd2=getSuper(cd2);
+           if (cd2==possiblesuper)
+               return true;
+       }
+       return false;
+    }
+}
index e9d89b963862aa09a68c22c933696c556da97990..f8a83bb00321919487920bc9ed71e57157afcb2d 100644 (file)
@@ -8,6 +8,7 @@ import IR.Tree.BuildIR;
 import IR.Tree.SemanticCheck;
 import IR.Flat.BuildFlat;
 import IR.State;
+import IR.TypeUtil;
 
 public class Main {
   public static void main(String args[]) throws Exception {
@@ -26,7 +27,9 @@ public class Main {
     BuildIR bir=new BuildIR(state);
     bir.buildtree();
 
-    SemanticCheck sc=new SemanticCheck(state);
+    TypeUtil tu=new TypeUtil(state);
+    
+    SemanticCheck sc=new SemanticCheck(state,tu);
     sc.semanticCheck();
     
     BuildFlat bf=new BuildFlat(state);