From: bdemsky Date: Sat, 25 Feb 2006 00:03:44 +0000 (+0000) Subject: updates X-Git-Tag: preEdgeChange~966 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=50995c8b04832effecb46d20912183e3623b2ddc;p=IRC.git updates --- diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index 72b0802a..f9af871c 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -81,4 +81,8 @@ public class ClassDescriptor extends Descriptor { public void setSuper(String superclass) { this.superclass=superclass; } + + protected String getSuper() { + return superclass; + } } diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index 13735871..f8c214f5 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -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(); } diff --git a/Robust/src/IR/Flat/FlatNode.java b/Robust/src/IR/Flat/FlatNode.java index 4824875a..ba5641bf 100644 --- a/Robust/src/IR/Flat/FlatNode.java +++ b/Robust/src/IR/Flat/FlatNode.java @@ -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(); } diff --git a/Robust/src/IR/Tree/LiteralNode.java b/Robust/src/IR/Tree/LiteralNode.java index db1f90cb..f3b71f01 100644 --- a/Robust/src/IR/Tree/LiteralNode.java +++ b/Robust/src/IR/Tree/LiteralNode.java @@ -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=""; diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index 9c8294b7..fcec66ab 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -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 index 00000000..99123806 --- /dev/null +++ b/Robust/src/IR/TypeUtil.java @@ -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; + } +} diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index e9d89b96..f8a83bb0 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -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);