many changes towards classpath...
authorbdemsky <bdemsky>
Thu, 9 Jun 2011 05:07:44 +0000 (05:07 +0000)
committerbdemsky <bdemsky>
Thu, 9 Jun 2011 05:07:44 +0000 (05:07 +0000)
Robust/src/IR/ClassDescriptor.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/JavaBuilder.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java

index faa7224244b9ac79fd9f2124fc6e0d36a5a3fccb..e218c79001e9624fee570f29c5333b6f9110cd0a 100644 (file)
@@ -18,6 +18,8 @@ public class ClassDescriptor extends Descriptor {
   Vector fieldvec;
   SymbolTable flags;
   SymbolTable methods;
+  boolean inline=false;
+  
 
   ChainHashMap mandatoryImports;
   ChainHashMap multiImports;
@@ -265,6 +267,14 @@ public class ClassDescriptor extends Descriptor {
     this.modifiers=modifiers;
   }
 
+  public void setInline() {
+    this.inline=true;
+  }
+
+  public boolean getInline() {
+    return inline;
+  }
+
   public void setSuper(String superclass) {
     this.superclass=superclass;
   }
@@ -273,7 +283,7 @@ public class ClassDescriptor extends Descriptor {
     return superdesc;
   }
 
-  public void setSuper(ClassDescriptor scd) {
+  public void setSuperDesc(ClassDescriptor scd) {
     this.superdesc=scd;
   }
 
@@ -431,7 +441,7 @@ public class ClassDescriptor extends Descriptor {
   }
 
   //Returns the full name/path of another class referenced from this class via imports.
-  public String getCannonicalImportMapName(String otherClassname) {
+  public String getCanonicalImportMapName(String otherClassname) {
     if(mandatoryImports.containsKey(otherClassname)) {
       return (String) mandatoryImports.get(otherClassname);
     } else if(multiImports.containsKey(otherClassname)) {
index fdc78e8c6a2f4468009145e3d91c9bbbd2f79358..fb9ecf313aec9dbfe174283632ba3bf8d09a3217 100644 (file)
@@ -220,36 +220,41 @@ public class BuildFlat {
     NodePair np=flattenBlockNode(bn);
     FlatNode fn=np.getBegin();
     if ((state.THREAD||state.MGC)&&currmd.getModifiers().isSynchronized()) {
-      MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
-      FlatNode first = null;
-      FlatNode end = null;
-
-      {
-        if (lockStack.size()!=1) {
-          throw new Error("TOO MANY THINGS ON LOCKSTACK");
-        }
-        TempDescriptor thistd = this.lockStack.elementAt(0);
-        FlatCall fc = new FlatCall(memd, null, thistd, new TempDescriptor[0]);
-        fc.setNumLine(bn.getNumLine());
-        first = end = fc;
-      }
-
-      end.addNext(fn);
-      fn=first;
-      end = np.getEnd();
-      if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
-        MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
-        while(!this.lockStack.isEmpty()) {
-          TempDescriptor thistd = this.lockStack.pop();
-          FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
-          fcunlock.setNumLine(bn.getNumLine());
-          end.addNext(fcunlock);
-          end = fcunlock;
-        }
-        FlatNode rnflat=spliceReturn(end);
-        rnflat.addNext(fe);
+      if (state.JNI) {
+       //XXXXXXXX: FIX THIS
+       this.lockStack.clear();
       } else {
-        this.lockStack.clear();
+       MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
+       FlatNode first = null;
+       FlatNode end = null;
+       
+       {
+         if (lockStack.size()!=1) {
+           throw new Error("TOO MANY THINGS ON LOCKSTACK");
+         }
+         TempDescriptor thistd = this.lockStack.elementAt(0);
+         FlatCall fc = new FlatCall(memd, null, thistd, new TempDescriptor[0]);
+         fc.setNumLine(bn.getNumLine());
+         first = end = fc;
+       }
+       
+       end.addNext(fn);
+       fn=first;
+       end = np.getEnd();
+       if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
+         MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+         while(!this.lockStack.isEmpty()) {
+           TempDescriptor thistd = this.lockStack.pop();
+           FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
+           fcunlock.setNumLine(bn.getNumLine());
+           end.addNext(fcunlock);
+           end = fcunlock;
+         }
+         FlatNode rnflat=spliceReturn(end);
+         rnflat.addNext(fe);
+       } else {
+         this.lockStack.clear();
+       }
       }
     } else if (state.DSM&&currmd.getModifiers().isAtomic()) {
       curran.addNext(fn);
@@ -1408,19 +1413,23 @@ public class BuildFlat {
     rnflat.addNext(fe);
     FlatNode ln=rnflat;
     if ((state.THREAD||state.MGC)&&!this.lockStack.isEmpty()) {
-      FlatNode end = null;
-      MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
-      for(int j = this.lockStack.size(); j > 0; j--) {
-        TempDescriptor thistd = this.lockStack.elementAt(j-1);
-        FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
-        fcunlock.setNumLine(rntree.getNumLine());
-        if(end != null) {
-          end.addNext(fcunlock);
-        }
-        end = fcunlock;
+      if (state.JNI) {
+       //XXXXXXXXX: FIX THIS
+      } else {
+       FlatNode end = null;
+       MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+       for(int j = this.lockStack.size(); j > 0; j--) {
+         TempDescriptor thistd = this.lockStack.elementAt(j-1);
+         FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
+         fcunlock.setNumLine(rntree.getNumLine());
+         if(end != null) {
+           end.addNext(fcunlock);
+         }
+         end = fcunlock;
+       }
+       end.addNext(ln);
+       ln=end;
       }
-      end.addNext(ln);
-      ln=end;
     }
     if (state.DSM&&currmd.getModifiers().isAtomic()) {
       FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
@@ -1493,29 +1502,33 @@ public class BuildFlat {
     }
     this.lockStack.push(montmp);
     NodePair npblock=flattenBlockNode(sbn.getBlockNode());
-
-    MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
-    FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
-    fcen.setNumLine(sbn.getNumLine());
-
-    MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
-    FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
-    fcex.setNumLine(sbn.getNumLine());
-
-    this.lockStack.pop();
-
-    if(first != null) {
-      end.addNext(fcen);
-    } else {
-      first = fcen;
-    }
-    fcen.addNext(npblock.getBegin());
-
-    if (npblock.getEnd()!=null&&npblock.getEnd().kind()!=FKind.FlatReturnNode) {
-      npblock.getEnd().addNext(fcex);
-      return new NodePair(first, fcex);
+    if (state.JNI) {
+      this.lockStack.pop();
+      return npblock;
     } else {
-      return new NodePair(first, null);
+      MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
+      FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
+      fcen.setNumLine(sbn.getNumLine());
+      
+      MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+      FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
+      fcex.setNumLine(sbn.getNumLine());
+      
+      this.lockStack.pop();
+      
+      if(first != null) {
+       end.addNext(fcen);
+      } else {
+       first = fcen;
+      }
+      fcen.addNext(npblock.getBegin());
+      
+      if (npblock.getEnd()!=null&&npblock.getEnd().kind()!=FKind.FlatReturnNode) {
+       npblock.getEnd().addNext(fcex);
+       return new NodePair(first, fcex);
+      } else {
+       return new NodePair(first, null);
+      }
     }
   }
 
index 6b94d45d5f5dce16bfb52abd6b8be03f91887774..30440944e12ba848cfe29967e08b5b00dd2cc796 100644 (file)
@@ -632,10 +632,10 @@ public class BuildIR {
       parseInnerClassDecl(cn,innerclassnode);
       return;
     }
-    ParseNode innerinterfacenode=pn.getChild("interface_declaration");
+     ParseNode innerinterfacenode=pn.getChild("interface_declaration");
     if (innerinterfacenode!=null) {
       parseInterfaceDecl(innerinterfacenode, cn);
+      return;
     }
 
     ParseNode enumnode=pn.getChild("enum_declaration");
@@ -653,6 +653,7 @@ public class BuildIR {
     if(emptynode != null) {
       return;
     }
+    System.out.println("Unrecognized node:"+pn.PPrint(2,true));
     throw new Error();
   }
 
@@ -984,10 +985,13 @@ public class BuildIR {
       pushChainMaps();
       cnnew.setImports(mandatoryImports, multiimports);
       cnnew.setSuper(td.getSymbol());
+      cnnew.setInline();
       parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
+      TypeDescriptor tdnew=state.getTypeDescriptor(cnnew.getSymbol());
+
       Vector args=parseArgumentList(pn);
 
-      CreateObjectNode con=new CreateObjectNode(td, false, null);
+      CreateObjectNode con=new CreateObjectNode(tdnew, false, null);
       con.setNumLine(pn.getLine());
       for(int i=0; i<args.size(); i++) {
         con.addArgument((ExpressionNode)args.get(i));
index eea8b016d1c5f9c8631f47ca17900d8928084643..c4de9ee1f89bec0c89007563a155662ef353b6d6 100644 (file)
@@ -157,7 +157,7 @@ public class JavaBuilder implements CallGraph {
   }
 
   void initClassDesc(ClassDescriptor cd, int init) {
-    if (classStatus.get(cd)==null||classStatus.get(cd)!=init) {
+    if (classStatus.get(cd)==null||classStatus.get(cd)<init) {
       if (classStatus.get(cd)==null) {
         MethodDescriptor mdstaticinit = (MethodDescriptor)cd.getMethodTable().get("staticblocks");
         if (mdstaticinit!=null) {
@@ -313,12 +313,30 @@ searchimp:
       callMap.put(md, new HashSet<MethodDescriptor>());
 
     FlatMethod fm=state.getMethodFlat(md);
-    for(FlatNode fn : fm.getNodeSet()) {
+    for(FlatNode fn: fm.getNodeSet()) {
       switch(fn.kind()) {
-      case FKind.FlatCall : {
-          FlatCall fcall=(FlatCall)fn;
-          processCall(md, fcall);
-          break;
+      case FKind.FlatFieldNode: {
+       FieldDescriptor fd=((FlatFieldNode)fn).getField();
+       if (fd.isStatic()) {
+         ClassDescriptor cd=fd.getClassDescriptor();
+         initClassDesc(cd, CDINIT);
+       }
+       break;
+      }
+
+      case FKind.FlatSetFieldNode: {
+       FieldDescriptor fd=((FlatSetFieldNode)fn).getField();
+       if (fd.isStatic()) {
+         ClassDescriptor cd=fd.getClassDescriptor();
+         initClassDesc(cd, CDINIT);
+       }
+       break;
+      }
+
+      case FKind.FlatCall: {
+       FlatCall fcall=(FlatCall)fn;
+       processCall(md, fcall);
+       break;
       }
 
       case FKind.FlatNew: {
index 29f36b33b04165f83bb6d52d6df1206cbab3b8fd..4e36cee08699e3a4223944a940bf301166fe3e25 100644 (file)
@@ -38,13 +38,8 @@ public class SemanticCheck {
     return getClass(context, classname, INIT);
   }
   public ClassDescriptor getClass(ClassDescriptor context, String classnameIn, int fullcheck) {
-    String classname = classnameIn;
-    if (context!=null) {
-      classname = context.getCannonicalImportMapName(classnameIn);
-    }
-    ClassDescriptor cd=typeutil.getClass(classname, toanalyze);
+    ClassDescriptor cd=typeutil.getClass(context, classnameIn, toanalyze);
     checkClass(cd, fullcheck);
-
     return cd;
   }
 
@@ -60,17 +55,25 @@ public class SemanticCheck {
       if (fullcheck>=REFERENCE&&oldstatus<INIT) {
         //Set superclass link up
         if (cd.getSuper()!=null) {
-          cd.setSuper(getClass(cd, cd.getSuper(), fullcheck));
-          if(cd.getSuperDesc().isInterface()) {
-            throw new Error("Error! Class " + cd.getSymbol() + " extends interface " + cd.getSuper());
-          }
-          // Link together Field, Method, and Flag tables so classes
-          // inherit these from their superclasses
-          if (oldstatus<REFERENCE) {
-            cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
-            cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
-            cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
-          }
+         ClassDescriptor superdesc=getClass(cd, cd.getSuper(), fullcheck);
+         if (superdesc.isInterface()) {
+           if (cd.getInline()) {
+             cd.setSuper(null);
+             cd.getSuperInterface().add(superdesc.getSymbol());
+           } else {
+             throw new Error("Error! Class " + cd.getSymbol() + " extends interface " + cd.getSuper());
+           }
+         } else {
+           cd.setSuperDesc(superdesc);
+
+           // Link together Field, Method, and Flag tables so classes
+           // inherit these from their superclasses
+           if (oldstatus<REFERENCE) {
+             cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
+             cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
+             cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
+           }
+         }
         }
         // Link together Field, Method tables do classes inherit these from
         // their ancestor interfaces
@@ -91,11 +94,21 @@ public class SemanticCheck {
         /* Check to see that fields are well typed */
         for(Iterator field_it=cd.getFields(); field_it.hasNext(); ) {
           FieldDescriptor fd=(FieldDescriptor)field_it.next();
+         try {
           checkField(cd,fd);
+         } catch (Error e) {
+           System.out.println("Class/Field in "+cd+":"+fd);
+           throw e;
+         }
         }
         for(Iterator method_it=cd.getMethods(); method_it.hasNext(); ) {
           MethodDescriptor md=(MethodDescriptor)method_it.next();
+         try {
           checkMethod(cd,md);
+         } catch (Error e) {
+           System.out.println("Class/Method in "+cd+":"+md);
+           throw e;
+         }
         }
       }
     }
@@ -613,6 +626,17 @@ public class SemanticCheck {
     if (typeutil.isCastable(etd, cast_type))
       return;
 
+    //rough hack to handle interfaces...should clean up
+    if (etd.isClass()&&cast_type.isClass()) {
+      ClassDescriptor cdetd=etd.getClassDesc();
+      ClassDescriptor cdcast_type=cast_type.getClassDesc();
+
+      if (cdetd.isInterface()&&!cdcast_type.getModifier().isFinal())
+       return;
+      
+      if (cdcast_type.isInterface()&&!cdetd.getModifier().isFinal())
+       return;
+    }
     /* Different branches */
     /* TODO: change if add interfaces */
     throw new Error("Cast will always fail\n"+cn.printNode(0));
@@ -854,8 +878,6 @@ public class SemanticCheck {
 
     if (td!=null) {
       if (!typeutil.isSuperorType(td, ofn.getType())) {
-        System.out.println(td);
-        System.out.println(ofn.getType());
         throw new Error("Type of rside not compatible with type of lside"+ofn.printNode(0));
       }
     }
@@ -883,8 +905,8 @@ public class SemanticCheck {
       vec_type.add(ain.getVarInitializer(i).getType());
     }
     // descide the type of this variableInitializerNode
-    TypeDescriptor out_type = vec_type.elementAt(0);
-    for(int i = 1; i < vec_type.size(); i++) {
+    TypeDescriptor out_type = null;
+    for(int i = 0; i < vec_type.size(); i++) {
       TypeDescriptor tmp_type = vec_type.elementAt(i);
       if(out_type == null) {
         if(tmp_type != null) {
@@ -918,7 +940,6 @@ public class SemanticCheck {
     }
     if(out_type != null) {
       out_type = out_type.makeArray(state);
-      //out_type.setStatic();
     }
     ain.setType(out_type);
   }
@@ -1083,7 +1104,7 @@ public class SemanticCheck {
       ClassDescriptor classtolookin = typetolookin.getClassDesc();
       checkClass(classtolookin, INIT);
 
-      Set methoddescriptorset = classtolookin.getMethodTable().getSet(typetolookin.getSymbol());
+      Set methoddescriptorset = classtolookin.getMethodTable().getSet(classtolookin.getSymbol());
       MethodDescriptor bestmd = null;
 NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.hasNext(); ) {
         MethodDescriptor currmd = (MethodDescriptor) methodit.next();
@@ -1116,8 +1137,9 @@ NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.ha
           /* Is this more specific than bestmd */
         }
       }
-      if (bestmd == null)
+      if (bestmd == null) {
         throw new Error("No method found for " + con.printNode(0) + " in " + md);
+      }
       con.setConstructor(bestmd);
     }
   }
@@ -1233,7 +1255,6 @@ NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.ha
       throw new Error("Error with method call to "+min.getMethodName());
     ClassDescriptor classtolookin=typetolookin.getClassDesc();
     checkClass(classtolookin, INIT);
-    //System.out.println("Method name="+min.getMethodName());
 
     Set methoddescriptorset=classtolookin.getMethodTable().getSet(min.getMethodName());
     MethodDescriptor bestmd=null;
@@ -1526,8 +1547,6 @@ NextMethod:
 
     if (td!=null)
       if (!typeutil.isSuperorType(td, on.getType())) {
-        System.out.println(td);
-        System.out.println(on.getType());
         throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));
       }
   }
index 69fb890d7a1942d0386f56ef988d4ba171ca9c79..4b9fac3ad448af332cf79028aa20edbbc44ed5bc 100644 (file)
@@ -54,7 +54,6 @@ public class TypeUtil {
     for (int i = 0; i < state.classpath.size(); i++) {
       String path = (String) state.classpath.get(i);
       File f = new File(path, cl.replace('.', '/') + ".java");
-//      System.out.println("Looking in " + f.getAbsolutePath());
       if (f.exists()) {
         try {
           ParseNode pn = Main.readSourceFile(state, f.getCanonicalPath());
@@ -65,7 +64,6 @@ public class TypeUtil {
         }
       }
     }
-    throw new Error("Couldn't find class " + cl);
   }
 
 
@@ -80,25 +78,59 @@ public class TypeUtil {
     return cd;
   }
 
-  public ClassDescriptor getClass(String classname, HashSet todo) {
+  public ClassDescriptor getClass(ClassDescriptor context, String classnameIn, HashSet todo) {
+    int fileindex=0;
+    do {
+      int dotindex=classnameIn.indexOf('.',fileindex);
+      fileindex=dotindex+1;
+
+      if(dotindex==-1) {
+       //get entire class name
+       dotindex=classnameIn.length();
+      }
+
+      String classnamestr = classnameIn.substring(0, dotindex);
+      String remainder = classnameIn.substring(dotindex, classnameIn.length());
+      
+      if (context!=null) {
+       classnamestr = context.getCanonicalImportMapName(classnamestr);
+      }
+      ClassDescriptor cd=helperGetClass(classnamestr, remainder, todo);
+
+      if (cd!=null) {
+       return cd;
+      }
+    } while(fileindex!=0);
+    throw new Error("Cannot find class: "+classnameIn);
+  }
+
+  private ClassDescriptor helperGetClass(String classname, String remainder, HashSet todo) {
     String cl = classname;
     if(state.MGC) {
       // do not consider package or import when compiling MGC version
       cl = (cl.lastIndexOf('.')==-1)?cl:cl.substring(cl.lastIndexOf('.')+1);
     }
+
     ClassDescriptor cd=(ClassDescriptor)state.getClassSymbolTable().get(cl);
     if (cd==null) {
       //have to find class
       addNewClass(cl, todo);
-      cd=(ClassDescriptor)state.getClassSymbolTable().get(cl);
-
+      String cl2=cl+remainder.replace('.','$');
+      cd=(ClassDescriptor)state.getClassSymbolTable().get(cl2);
+      if (cd==null)
+       return null;
       System.out.println("Build class:"+cd);
       todo.add(cd);
+    } else {
+      String cl2=cl+remainder.replace('.','$');
+      cd=(ClassDescriptor)state.getClassSymbolTable().get(cl2);
+      if (cd==null)
+       return null;
     }
     if (!supertable.containsKey(cd)) {
       String superc=cd.getSuper();
       if (superc!=null) {
-        ClassDescriptor cd_super=getClass(superc, todo);
+        ClassDescriptor cd_super=getClass(cd, superc, todo);
         supertable.put(cd,cd_super);
       }
     }
@@ -109,7 +141,7 @@ public class TypeUtil {
       Vector<String> superifv = cd.getSuperInterface();
       for(int i = 0; i < superifv.size(); i++) {
         String superif = superifv.elementAt(i);
-        ClassDescriptor if_super = getClass(superif, todo);
+        ClassDescriptor if_super = getClass(cd, superif, todo);
         hs.add(if_super);
       }
     }