Bug fixes for MGC
authorjzhou <jzhou>
Fri, 18 Feb 2011 01:45:00 +0000 (01:45 +0000)
committerjzhou <jzhou>
Fri, 18 Feb 2011 01:45:00 +0000 (01:45 +0000)
12 files changed:
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildCodeMGC.java
Robust/src/IR/Flat/BuildCodeMultiCore.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/MethodInvokeNode.java
Robust/src/IR/Tree/NameNode.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeDescriptor.java
Robust/src/IR/TypeUtil.java
Robust/src/Tests/EnumTest.java
Robust/src/buildscript

index a85621aedce350ea056623d08d8d72b2030b350d..26290be75b3c607543469f84b0e2ba6e12503d93 100644 (file)
@@ -66,6 +66,9 @@ public class BuildCode {
   DiscoverConflicts recorddc;
   DCWrapper delaycomp;
   CallGraph callgraph;
+  Hashtable<String, ClassDescriptor> printedfieldstbl;
+  Hashtable<ClassDescriptor, Hashtable<String, ClassDescriptor>> cd2fieldstbl;
+  Hashtable<ClassDescriptor, Vector<FieldDescriptor>> cd2shadowfields;
 
 
   public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
@@ -111,6 +114,9 @@ public class BuildCode {
       recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null);
       recorddc.doAnalysis();
     }
+    printedfieldstbl = new Hashtable<String, ClassDescriptor>();
+    cd2fieldstbl = new Hashtable<ClassDescriptor, Hashtable<String, ClassDescriptor>>();
+    cd2shadowfields = new Hashtable<ClassDescriptor, Vector<FieldDescriptor>>();
   }
 
   /** The buildCode method outputs C code for all the methods.  The Flat
@@ -658,22 +664,22 @@ public class BuildCode {
 
     outstructs.println("#define STRINGARRAYTYPE "+
                        (state.getArrayNumber(
-                          (new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass))).makeArray(state))+state.numClasses()));
+                          (new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass))).makeArray(state, true))+state.numClasses()));
 
     outstructs.println("#define OBJECTARRAYTYPE "+
                        (state.getArrayNumber(
-                          (new TypeDescriptor(typeutil.getClass(TypeUtil.ObjectClass))).makeArray(state))+state.numClasses()));
+                          (new TypeDescriptor(typeutil.getClass(TypeUtil.ObjectClass))).makeArray(state, true))+state.numClasses()));
 
 
     outstructs.println("#define STRINGTYPE "+typeutil.getClass(TypeUtil.StringClass).getId());
     outstructs.println("#define CHARARRAYTYPE "+
-                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.CHAR)).makeArray(state))+state.numClasses()));
+                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.CHAR)).makeArray(state, true))+state.numClasses()));
 
     outstructs.println("#define BYTEARRAYTYPE "+
-                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state))+state.numClasses()));
+                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state, true))+state.numClasses()));
 
     outstructs.println("#define BYTEARRAYARRAYTYPE "+
-                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state).makeArray(state))+state.numClasses()));
+                       (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state, true).makeArray(state, true))+state.numClasses()));
 
     outstructs.println("#define NUMCLASSES "+state.numClasses());
     int totalClassSize = state.numClasses() + state.numArrays();
@@ -682,7 +688,7 @@ public class BuildCode {
       outstructs.println("#define STARTUPTYPE "+typeutil.getClass(TypeUtil.StartupClass).getId());
       outstructs.println("#define TAGTYPE "+typeutil.getClass(TypeUtil.TagClass).getId());
       outstructs.println("#define TAGARRAYTYPE "+
-                         (state.getArrayNumber(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass)).makeArray(state))+state.numClasses()));
+                         (state.getArrayNumber(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass)).makeArray(state, true))+state.numClasses()));
     }
   }
 
@@ -762,6 +768,7 @@ public class BuildCode {
     }
 
     printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+    printedfieldstbl.clear();
 
     if (state.STMARRAY) {
       outclassdefs.println("  int lowindex;");
@@ -821,6 +828,7 @@ public class BuildCode {
       }
     }
     printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+    printedfieldstbl.clear();
     outclassdefs.println("};\n");
     }
     
@@ -1491,25 +1499,69 @@ public class BuildCode {
   /** Force consistent field ordering between inherited classes. */
 
   private void printClassStruct(ClassDescriptor cn, PrintWriter classdefout, PrintWriter globaldefout) {
-
+    
     ClassDescriptor sp=cn.getSuperDesc();
     if (sp!=null)
-      printClassStruct(sp, classdefout, globaldefout);
+      printClassStruct(sp, classdefout, /*globaldefout*/null);
+    
+    // TODO: what about here are multiple inherited fields with the same name?
+    SymbolTable sitbl = cn.getSuperInterfaceTable();
+    Iterator it_sifs = sitbl.getDescriptorsIterator();
+    if(state.MGC) {
+      while(it_sifs.hasNext()) {
+        ClassDescriptor si = (ClassDescriptor)it_sifs.next();
+        printClassStruct(si, classdefout, /*globaldefout*/null);
+      }
+    }
+    
+    Vector shadow_fields = null;
 
     if (!fieldorder.containsKey(cn)) {
       Vector fields=new Vector();
       fieldorder.put(cn,fields);
+      shadow_fields = new Vector();
+      cd2shadowfields.put(cn, shadow_fields);
+      
       Vector fieldvec=cn.getFieldVec();
       for(int i=0;i<fieldvec.size();i++) {
        FieldDescriptor fd=(FieldDescriptor)fieldvec.get(i);
-       if ((sp==null||!sp.getFieldTable().contains(fd.getSymbol())))
-         fields.add(fd);
+    if(state.MGC) {
+      if((sp != null) && sp.getFieldTable().contains(fd.getSymbol())) {
+        shadow_fields.add(fd);
+      } else {
+        it_sifs = sitbl.getDescriptorsIterator();
+        boolean hasprinted = false;
+        while(it_sifs.hasNext()) {
+          ClassDescriptor si = (ClassDescriptor)it_sifs.next();
+          if(si.getFieldTable().contains(fd.getSymbol())) {
+            hasprinted = true;
+            break;
+          }
+        }
+        if(hasprinted) {
+          // this field has been defined in the super class
+          shadow_fields.add(fd);
+        } else {
+          fields.add(fd);
+        }
+      }
+    } else {
+      if ((sp==null) || (!sp.getFieldTable().contains(fd.getSymbol())))
+        fields.add(fd);
+    }
       }
     }
     Vector fields=(Vector)fieldorder.get(cn);
+    shadow_fields=cd2shadowfields.get(cn);
 
     for(int i=0; i<fields.size(); i++) {
       FieldDescriptor fd=(FieldDescriptor)fields.get(i);
+      if(printedfieldstbl.containsKey(fd.getSymbol())) {
+        printedfieldstbl.put(fd.getSymbol(), cn);
+        continue;
+      } else {
+        printedfieldstbl.put(fd.getSymbol(), cn);
+      }
       if (state.MGC && fd.getType().isClass()
           && fd.getType().getClassDesc().isEnum()) {
         classdefout.println("  int " + fd.getSafeSymbol() + ";");
@@ -1517,16 +1569,20 @@ public class BuildCode {
         if ((state.MGC) && (fd.isStatic())) {
           // TODO add version for normal Java later
           // static field
-          if(fd.isVolatile()) {
-            globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
-          } else {
-            globaldefout.println("  struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          if(globaldefout != null) {
+            if(fd.isVolatile()) {
+              globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+            } else {
+              globaldefout.println("  struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+            }
           }
           classdefout.println("  struct "+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";");
         } else if ((state.MGC) && (fd.isVolatile())) {
           // TODO add version for normal Java later
           // static field
-          globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          if(globaldefout != null) {
+            globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          }
           classdefout.println("  struct"+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";");
         } else {
        classdefout.println("  struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
@@ -1534,20 +1590,61 @@ public class BuildCode {
       } else if ((state.MGC) && (fd.isStatic())) {
         // TODO add version for normal Java later
         // static field
-        if(fd.isVolatile()) {
-          globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
-        } else {
-          globaldefout.println("  "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        if(globaldefout != null) {
+          if(fd.isVolatile()) {
+            globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          } else {
+            globaldefout.println("  "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          }
         }
         classdefout.println("  "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
       } else if ((state.MGC) && (fd.isVolatile())) {
         // TODO add version for normal Java later
         // static field
-        globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        if(globaldefout != null) {
+          globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        }
         classdefout.println("  "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
       } else
        classdefout.println("  "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";");
     }
+    
+    // check the shadow fields, for those static shadow fields, need to add a 
+    // corresponding field in the global_defs_p structure
+    for(int i=0; i<shadow_fields.size(); i++) {
+      FieldDescriptor fd=(FieldDescriptor)shadow_fields.get(i);
+      if ((state.MGC) && (fd.isStatic()) && (globaldefout != null)) {
+        if (fd.getType().isClass()||fd.getType().isArray()) { 
+          // TODO add version for normal Java later
+          // static field
+          if(fd.isVolatile()) {
+            globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          } else {
+            globaldefout.println("  struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          }
+        } else {
+          // TODO add version for normal Java later
+          // static field
+          if(fd.isVolatile()) {
+            globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          } else {
+            globaldefout.println("  "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+          }
+        } 
+      } else if ((state.MGC) && (fd.isVolatile()) && (globaldefout != null)) {
+        // TODO add version for normal Java later
+        // static field
+        if (fd.getType().isClass()||fd.getType().isArray()) { 
+          // TODO add version for normal Java later
+          // static field
+          globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        } else {
+          // TODO add version for normal Java later
+          // static field
+          globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        } 
+      }
+    }
   }
 
 
@@ -1631,6 +1728,8 @@ public class BuildCode {
       }
     }
     printClassStruct(cn, classdefout, globaldefout);
+    cd2fieldstbl.put(cn, printedfieldstbl);
+    printedfieldstbl = new Hashtable<String, ClassDescriptor>();
     classdefout.println("};\n");
 
     if (state.DSM||state.SINGLETM) {
@@ -1682,7 +1781,11 @@ public class BuildCode {
       output.println("  void * next;");      
       for(int i=0; i<objectparams.numPointers(); i++) {
        TempDescriptor temp=objectparams.getPointer(i);
-       output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+    if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+      output.println("  int " + temp.getSafeSymbol() + ";");
+    } else {
+      output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+    }
       }
       output.println("};\n");
     }
@@ -1723,7 +1826,9 @@ public class BuildCode {
     }
     /* First the return type */
     if (md.getReturnType()!=null) {
-      if (md.getReturnType().isClass()||md.getReturnType().isArray())
+      if(state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+        headersout.println("  int ");
+      } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        headersout.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
       else
        headersout.print(md.getReturnType().getSafeSymbol()+" ");
@@ -1752,7 +1857,9 @@ public class BuildCode {
       if (printcomma)
        headersout.print(", ");
       printcomma=true;
-      if (temp.getType().isClass()||temp.getType().isArray())
+      if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+        headersout.print("int " + temp.getSafeSymbol());
+      } else if (temp.getType().isClass()||temp.getType().isArray())
        headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
       else
        headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
@@ -2014,13 +2121,18 @@ public class BuildCode {
       // is a constructor, check and output initialization of the static fields
       // here does not initialize the static fields of the class, instead it 
       // redirect the corresponding fields in the object to the global_defs_p
-      Vector fields=(Vector)fieldorder.get(cn);
+      Vector fields=cn.getFieldVec();
 
       for(int i=0; i<fields.size(); i++) {
         FieldDescriptor fd=(FieldDescriptor)fields.get(i);
         if(fd.isStatic()) {
           // static field
-          output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+cn.getSafeSymbol()+fd.getSafeSymbol()+");");
+          // decide the exact class/interface that defines the field
+          ClassDescriptor fdcn = 
+            cd2fieldstbl.get(cn).get(fd.getSymbol());
+
+          // static field
+          output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+fdcn.getSafeSymbol()+fd.getSafeSymbol()+");");
         }
       }
     }
@@ -3009,9 +3121,6 @@ public class BuildCode {
           // its static blocks have been executed
           output.println("#ifdef MGC_STATIC_INIT_CHECK");
           output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
-          if(cn.getNumStaticFields() != 0) {
-            // TODO add static field initialization here
-          }
           if(cn.getNumStaticBlocks() != 0) {
             MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
             output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
@@ -3084,7 +3193,9 @@ public class BuildCode {
     } else {
       //yes
       output.print("((");
-      if (md.getReturnType().isClass()||md.getReturnType().isArray())
+      if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+        output.print("int ");
+      } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
       else
        output.print(md.getReturnType().getSafeSymbol()+" ");
@@ -3105,7 +3216,9 @@ public class BuildCode {
        if (printcomma)
          output.print(", ");
        printcomma=true;
-       if (temp.getType().isClass()||temp.getType().isArray())
+    if (state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+      output.print("int ");
+    } else if (temp.getType().isClass()||temp.getType().isArray())
          output.print("struct " + temp.getType().getSafeSymbol()+" * ");
        else
          output.print(temp.getType().getSafeSymbol());
@@ -3136,7 +3249,9 @@ public class BuildCode {
     }
        if (needcomma)
          output.print(",");
-       if (ptd.isClass()&&!ptd.isArray())
+    if(state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
+      // do nothing 
+    } else if (ptd.isClass()&&!ptd.isArray())
          output.print("(struct "+ptd.getSafeSymbol()+" *) ");
        output.print(generateTemp(fm,fc.getThis(),lb));
        needcomma=true;
@@ -3152,7 +3267,9 @@ public class BuildCode {
          output.print(", ");
 
        TypeDescriptor ptd=md.getParamType(i);
-       if (ptd.isClass()&&!ptd.isArray())
+    if (state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
+      // do nothing
+    } else if (ptd.isClass()&&!ptd.isArray())
          output.print("(struct "+ptd.getSafeSymbol()+" *) ");
        output.print(generateTemp(fm, targ,lb));
        needcomma=true;
@@ -3283,13 +3400,16 @@ public class BuildCode {
           }
         }
         // redirect to the global_defs_p structure
-        if((ffn.getField().isStatic()) || (ffn.getSrc().getType().isStatic())) {
+        if((ffn.getField().isStatic()) || (ffn.getSrc().getType().isClassNameRef())) {
+          // decide the exact class/interface that defines the field
+          ClassDescriptor fdcn = 
+            cd2fieldstbl.get(ffn.getSrc().getType().getClassDesc()).get(ffn.getField().getSymbol());
+
           // reference to the static field with Class name
-          output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ ffn.getSrc().getType().getClassDesc().getSafeSymbol()+ffn.getField().getSafeSymbol()+";");
+          output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ fdcn.getSafeSymbol()+ffn.getField().getSafeSymbol()+";");
         } else {
           output.println(generateTemp(fm, ffn.getDst(),lb)+"=*"+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
         }
-        //output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ffn.getSrc().getType().getClassDesc().getSafeSymbol()+"->"+ ffn.getField().getSafeSymbol()+";");
       } else if (ffn.getField().isEnum()) {
           // an Enum value, directly replace the field access as int
           output.println(generateTemp(fm, ffn.getDst(), lb) + "=" + ffn.getField().enumValue() + ";");
@@ -3432,9 +3552,13 @@ public class BuildCode {
           }
         }
         // redirect to the global_defs_p structure
-        if(fsfn.getDst().getType().isStatic()) {
+        if(fsfn.getDst().getType().isClassNameRef()) {
           // reference to the static field with Class name
-          output.println("global_defs_p->" + fsfn.getDst().getType().getClassDesc().getSafeSymbol() + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
+          // decide the exact class/interface that defines the field
+          ClassDescriptor fdcn = 
+            cd2fieldstbl.get(fsfn.getDst().getType().getClassDesc()).get(fsfn.getField().getSymbol());
+          
+          output.println("global_defs_p->" + fdcn.getSafeSymbol() + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
         } else {
           output.println("*"+generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
         }
@@ -3451,7 +3575,9 @@ public class BuildCode {
     TypeDescriptor elementtype=fen.getSrc().getType().dereference();
     String type="";
 
-    if (elementtype.isArray()||elementtype.isClass())
+    if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
+      type="int ";
+    } else if (elementtype.isArray()||elementtype.isClass())
       type="void *";
     else
       type=elementtype.getSafeSymbol()+" ";
@@ -3516,7 +3642,9 @@ public class BuildCode {
     TypeDescriptor elementtype=fsen.getDst().getType().dereference();
     String type="";
 
-    if (elementtype.isArray()||elementtype.isClass())
+    if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
+      type="int ";
+    } else if (elementtype.isArray()||elementtype.isClass() || (state.MGC && elementtype.isNull()))
       type="void *";
     else
       type=elementtype.getSafeSymbol()+" ";
@@ -3724,6 +3852,8 @@ public class BuildCode {
     /* TODO: Do type check here */
     if (fcn.getType().isArray()) {
       output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
+    } else if (state.MGC && fcn.getType().isClass() && fcn.getType().getClassDesc().isEnum()) {
+      output.println(generateTemp(fm,fcn.getDst(),lb)+"=(int)"+generateTemp(fm,fcn.getSrc(),lb)+";");
     } else if (fcn.getType().isClass())
       output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
     else
@@ -3822,7 +3952,9 @@ public class BuildCode {
     ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
 
     if (md!=null&&md.getReturnType()!=null) {
-      if (md.getReturnType().isClass()||md.getReturnType().isArray())
+      if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+        output.print("int ");
+      } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
       else
        output.print(md.getReturnType().getSafeSymbol()+" ");
@@ -3856,7 +3988,9 @@ public class BuildCode {
        if (printcomma)
          output.print(", ");
        printcomma=true;
-       if (temp.getType().isClass()||temp.getType().isArray())
+    if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+      output.print("int " + temp.getSafeSymbol());
+    } else if (temp.getType().isClass()||temp.getType().isArray())
          output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
        else
          output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
@@ -3868,7 +4002,11 @@ public class BuildCode {
       /* Unpack variables */
       for(int i=0; i<objectparams.numPrimitives(); i++) {
        TempDescriptor temp=objectparams.getPrimitive(i);
-       output.println("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+"=parameterarray["+i+"];");
+    if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+      output.print("int " + temp.getSafeSymbol() + "=parameterarray["+i+"];");
+    } else {
+      output.println("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+"=parameterarray["+i+"];");
+    }
       }
       for(int i=0; i<fm.numTags(); i++) {
        TempDescriptor temp=fm.getTag(i);
index 0784becec9f4d60785e9b1f219c3ec02e23b9b61..77ca64e09dfcfdfbfe47208f35e255cc57f5063b 100644 (file)
@@ -177,9 +177,6 @@ public class BuildCodeMGC extends BuildCode {
       outmethod.println("#define MGC_STATIC_INIT_CHECK");
       while(it_sclasses.hasNext()) {
         ClassDescriptor t_cd = (ClassDescriptor)it_sclasses.next();
-        if(t_cd.getNumStaticFields() != 0) {
-          // TODO may need to invoke static field initialization here
-        }
         MethodDescriptor t_md = (MethodDescriptor)t_cd.getMethodTable().get("staticblocks");
         if(t_md != null) {
           outmethod.println("   {");
index d2d59b45b030cf0e2c295b88c50e604303844a43..6ca8e8b80cf67d791328c70f5c8d4ba7632747f1 100644 (file)
@@ -624,7 +624,9 @@ public class BuildCodeMultiCore extends BuildCode {
       TypeDescriptor type=td.getType();
       if (type.isNull())
        output.println("   void * "+td.getSafeSymbol()+";");
-      else if (type.isClass()||type.isArray())
+      else if (state.MGC && type.isClass() && type.getClassDesc().isEnum()) {
+        output.println("   int " + td.getSafeSymbol()+";");
+      } else if (type.isClass()||type.isArray())
        output.println("   struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
       else
        output.println("   "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
index 7cbb6100565099c9869a5da1a8df9735e2cfe840..e466fec38b5b4f58c3476e2c3d067ddab805f0b2 100644 (file)
@@ -450,7 +450,11 @@ public class BuildFlat {
     TempDescriptor thisarg=null;
 
     if (min.getExpression()!=null) {
-      thisarg=TempDescriptor.tempFactory("thisarg",min.getExpression().getType());
+      TypeDescriptor mtd = min.getExpression().getType();
+      if(state.MGC && mtd.isClass() && mtd.getClassDesc().isEnum()) {
+        mtd = new TypeDescriptor(TypeDescriptor.INT);
+      }
+      thisarg=TempDescriptor.tempFactory("thisarg", mtd);
       NodePair np=flattenExpressionNode(min.getExpression(),thisarg);
       first=np.getBegin();
       last=np.getEnd();
@@ -459,7 +463,11 @@ public class BuildFlat {
     //Build arguments
     for(int i=0; i<min.numArgs(); i++) {
       ExpressionNode en=min.getArg(i);
-      TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
+      TypeDescriptor etd = en.getType();
+      if(state.MGC && etd.isClass() && etd.getClassDesc().isEnum()) {
+        etd = new TypeDescriptor(TypeDescriptor.INT);
+      }
+      TempDescriptor td=TempDescriptor.tempFactory("arg", etd);
       temps[i]=td;
       NodePair np=flattenExpressionNode(en, td);
       if (first==null)
@@ -487,7 +495,7 @@ public class BuildFlat {
 
   private NodePair flattenFieldAccessNode(FieldAccessNode fan,TempDescriptor out_temp) {
     TempDescriptor tmp=null;
-    if(fan.getExpression().getType().isStatic()) {
+    if(fan.getExpression().getType().isClassNameRef()) {
       // static field dereference with class name
       tmp = new TempDescriptor(fan.getExpression().getType().getClassDesc().getSymbol(), fan.getExpression().getType());
       FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
@@ -561,7 +569,7 @@ public class BuildFlat {
       ExpressionNode en=fan.getExpression();
       TempDescriptor dst_tmp=null;
       NodePair np_baseexp=null;
-      if(en.getType().isStatic()) {
+      if(en.getType().isClassNameRef()) {
         // static field dereference with class name
         dst_tmp = new TempDescriptor(en.getType().getClassDesc().getSymbol(), en.getType());
         FlatNop nop=new FlatNop();
@@ -690,7 +698,7 @@ public class BuildFlat {
        ExpressionNode en=fan.getExpression();
     TempDescriptor dst_tmp=null;
     NodePair np_baseexp=null;
-    if(en.getType().isStatic()) {
+    if(en.getType().isClassNameRef()) {
       // static field dereference with class name
       dst_tmp = new TempDescriptor(en.getType().getClassDesc().getSymbol(), en.getType());
       FlatNop nop=new FlatNop();
@@ -751,8 +759,17 @@ public class BuildFlat {
            //If it is a preinc we need to store the initial value
            TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
            TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
+        
+        TempDescriptor ftmp= null;
+        if(state.MGC && (nn.getClassDesc() != null)) {
+          // this is a static field
+          ftmp = new TempDescriptor(nn.getClassDesc().getSymbol(), nn.getClassType());
+
+        } else {
+          ftmp=getTempforVar(nn.getVar());
+        }
+        FlatFieldNode ffn=new FlatFieldNode(nn.getField(), ftmp, src_tmp2);
 
-           FlatFieldNode ffn=new FlatFieldNode(nn.getField(), getTempforVar(nn.getVar()), src_tmp2);
            if (first==null)
              first=ffn;
            else {
@@ -1371,7 +1388,9 @@ public class BuildFlat {
       first = fcen;
     }
     fcen.addNext(npblock.getBegin());
-    npblock.getEnd().addNext(fcex);
+    if(npblock.getEnd() != null) {
+      npblock.getEnd().addNext(fcex);
+    }
     return new NodePair(first, fcex);
   }
 
index 7d7121e5390793897b017950173bedc7f2b9b959..a22eaaa906492b8cf56df2fa2f9491b0c29d6955 100644 (file)
@@ -583,7 +583,7 @@ public class BuildIR {
       TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
       Integer numdims=(Integer)nn.getChild("dims").getLiteral();
       for(int i=0; i<numdims.intValue(); i++)
-       td=td.makeArray(state);
+       td=td.makeArray(state, true);
       return td;
     } else {
       System.out.println(pn.PPrint(2, true));
@@ -634,7 +634,7 @@ public class BuildIR {
       ParseNode tmp=vardecl;
       TypeDescriptor arrayt=t;
       while (tmp.getChild("single")==null) {
-       arrayt=arrayt.makeArray(state);
+       arrayt=arrayt.makeArray(state, true);
        tmp=tmp.getChild("array");
       }
       String identifier=tmp.getChild("single").getTerminal();
@@ -765,7 +765,7 @@ public class BuildIR {
       if (pn.getChild("dims_opt").getLiteral()!=null)
        num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
       for(int i=0; i<(args.size()+num); i++)
-       td=td.makeArray(state);
+       td=td.makeArray(state, true);
       CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
       for(int i=0; i<args.size(); i++) {
        con.addArgument((ExpressionNode)args.get(i));
@@ -777,7 +777,7 @@ public class BuildIR {
       if (pn.getChild("dims_opt").getLiteral()!=null)
     num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
       for(int i=0; i<num; i++)
-    td=td.makeArray(state);
+    td=td.makeArray(state, true);
       CreateObjectNode con=new CreateObjectNode(td, false, null);
       // TODO array initializers
       ParseNode ipn = pn.getChild("initializer");     
@@ -1084,7 +1084,7 @@ public class BuildIR {
        ParseNode tmp=vardecl;
        TypeDescriptor arrayt=t;
        while (tmp.getChild("single")==null) {
-         arrayt=arrayt.makeArray(state);
+         arrayt=arrayt.makeArray(state, true);
          tmp=tmp.getChild("array");
        }
        String identifier=tmp.getChild("single").getTerminal();
@@ -1278,7 +1278,7 @@ public class BuildIR {
 
        ParseNode tmp=paramn;
        while (tmp.getChild("single")==null) {
-         type=type.makeArray(state);
+         type=type.makeArray(state, true);
          tmp=tmp.getChild("array");
        }
        String paramname=tmp.getChild("single").getTerminal();
index 0ace6405728b4a9191c3f4100dc649d81d9b2085..8c9bcd79a185cc3a745738a3be36227322fd25e9 100644 (file)
@@ -60,6 +60,10 @@ public class MethodInvokeNode extends ExpressionNode {
   public void addArgument(ExpressionNode en) {
     argumentlist.add(en);
   }
+  
+  public void setArgument(ExpressionNode en, int index) {
+    argumentlist.setElementAt(en, index);
+  }
 
   public int numArgs() {
     return argumentlist.size();
index 1785b23a6ea213ab3c59dac28fdbe5366672fd38..40487d0c996d3e2c72f622ca52d4d31e70dbcbe9 100644 (file)
@@ -69,18 +69,22 @@ public class NameNode extends ExpressionNode {
       return fd.getType();
     } else if (isTag())
       return new TypeDescriptor(TypeDescriptor.TAG);
-    else if(cd != null) {
+    else if(vd != null) {
+      return ((VarDescriptor)vd).getType();
+    } if(cd != null) {
       TypeDescriptor tp = new TypeDescriptor(cd);
-      tp.setStatic();
+      tp.setClassNameRef();
       return tp;
-    } else
-      return ((VarDescriptor)vd).getType();
+    } else {
+      return null;
+    }
+      
   }
   
   public TypeDescriptor getClassType() {
     if(cd != null) {
       TypeDescriptor tp = new TypeDescriptor(cd);
-      tp.setStatic();
+      tp.setClassNameRef();
       return tp;
     } else
       return null;
index 8c1b5cb04f07a3a69f23bc48b93dc5d4336ac3b3..0607af895a59ce282e7884cbc7af6d99c0e55edf 100644 (file)
@@ -33,6 +33,9 @@ public class SemanticCheck {
       //Set superclass link up
       if (cd.getSuper()!=null) {
        cd.setSuper(getClass(cd.getSuper()));
+    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
        cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
@@ -46,6 +49,9 @@ public class SemanticCheck {
         Vector<String> sifv = cd.getSuperInterface();
         for(int i = 0; i < sifv.size(); i++) {
           ClassDescriptor superif = getClass(sifv.elementAt(i));
+          if(!superif.isInterface()) {
+            throw new Error("Error! Class " + cd.getSymbol() + " implements non-interface " + superif.getSymbol());
+          }
           cd.addSuperInterfaces(superif);
           cd.getFieldTable().addParentIF(superif.getFieldTable());
           cd.getMethodTable().addParentIF(superif.getMethodTable());
@@ -64,7 +70,7 @@ public class SemanticCheck {
        checkMethod(cd,md);
     hasConstructor |= md.isConstructor();
       }
-      if(!hasConstructor) {
+      if((!hasConstructor) && (!cd.isEnum())) {
         // add a default constructor for this class
         MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
             cd.getSymbol(), false);
@@ -603,7 +609,7 @@ public class SemanticCheck {
       fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
     if(state.MGC) {
       // TODO add version for normal Java later
-    if(ltd.isStatic()) {
+    if(ltd.isClassNameRef()) {
       // the field access is using a class name directly
       if(ltd.getClassDesc().isEnum()) {
         int value = ltd.getClassDesc().getEnumConstant(fieldname);
@@ -890,8 +896,8 @@ public class SemanticCheck {
       }
     }
     if(out_type != null) {
-      out_type = out_type.makeArray(state);
-      out_type.setStatic();
+      out_type = out_type.makeArray(state, false);
+      //out_type.setStatic();
     }
     ain.setType(out_type);
   }
@@ -1228,7 +1234,12 @@ NextMethod:
        continue;
       for(int i=0; i<min.numArgs(); i++) {
        if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
-         continue NextMethod;
+      if(state.MGC && ((!tdarray[i].isArray() &&( tdarray[i].isInt() || tdarray[i].isLong())) 
+          && currmd.getParamType(i).isClass() && currmd.getParamType(i).getClassDesc().getSymbol().equals("Object"))) {
+        // primitive parameters vs object
+      } else {
+        continue NextMethod;
+      }
       }
       /* Method okay so far */
       if (bestmd==null)
@@ -1256,6 +1267,32 @@ NextMethod:
        checkExpressionNode(md, nametable, min.getExpression(), null);
       }
     }
+    
+    if(state.MGC) {
+      /* Check if we need to wrap primitive paratmeters to objects */
+      for(int i=0; i<min.numArgs(); i++) {
+        if(!tdarray[i].isArray() && (tdarray[i].isInt() || tdarray[i].isLong())
+            && min.getMethod().getParamType(i).isClass() && min.getMethod().getParamType(i).getClassDesc().getSymbol().equals("Object")) {
+          // Shall wrap this primitive parameter as a object
+          ExpressionNode exp = min.getArg(i);
+          TypeDescriptor ptd = null;
+          NameDescriptor nd=null;
+          if(exp.getType().isInt()) {
+            nd = new NameDescriptor("Integer");
+            ptd = state.getTypeDescriptor(nd);
+          } else if(exp.getType().isLong()) {
+            nd = new NameDescriptor("Long");
+            ptd = state.getTypeDescriptor(nd);
+          }
+          boolean isglobal = false;
+          String disjointId = null;
+          CreateObjectNode con=new CreateObjectNode(ptd, isglobal, disjointId);
+          con.addArgument(exp);
+          checkExpressionNode(md, nametable, con, null);
+          min.setArgument(con, i);
+        }
+      }
+    }
   }
 
 
@@ -1341,8 +1378,11 @@ NextMethod:
          throw new Error();
        righttype=lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
       } else if (ltd.isPtr()||rtd.isPtr()) {
-       if (!(ltd.isPtr()&&rtd.isPtr()))
-         throw new Error();
+       if (!(ltd.isPtr()&&rtd.isPtr())) {
+      if(!rtd.isEnum()) {
+        throw new Error();
+      }
+    }
        righttype=rtd;
        lefttype=ltd;
       } else if (ltd.isDouble()||rtd.isDouble())
index ff7efd91c48259a9615b98dedfc9266309aad4be..1ca436236593d1d1769a5684938ff2978c34a493 100644 (file)
@@ -25,7 +25,7 @@ public class TypeDescriptor extends Descriptor {
   int arraycount;
   private int type;
   ClassDescriptor class_desc;
-  boolean isStatic = false;
+  boolean isClassNameRef = false;
 
   public boolean equals(Object o) {
     if (o instanceof TypeDescriptor) {
@@ -36,6 +36,8 @@ public class TypeDescriptor extends Descriptor {
        return false;
       if (t.arraycount!=arraycount)
        return false;
+      if (t.isClassNameRef != this.isClassNameRef)
+        return false;
       return true;
     }
     return false;
@@ -51,12 +53,12 @@ public class TypeDescriptor extends Descriptor {
     return true;
   }
   
-  public boolean isStatic() {
-    return this.isStatic;
+  public boolean isClassNameRef() {
+    return this.isClassNameRef;
   }
   
-  public void setStatic() {
-    this.isStatic = true;
+  public void setClassNameRef() {
+    this.isClassNameRef = true;
   }
 
   public int hashCode() {
@@ -80,12 +82,14 @@ public class TypeDescriptor extends Descriptor {
            name.equals("Objectwrapper"));
   }
 
-  public TypeDescriptor makeArray(State state) {
+  public TypeDescriptor makeArray(State state, boolean addflag) {
     TypeDescriptor td=new TypeDescriptor(getSymbol());
     td.arraycount=arraycount+1;
     td.type=type;
     td.class_desc=class_desc;
-    state.addArrayType(td);
+    if(addflag) {
+      state.addArrayType(td);
+    }
     return td;
   }
 
@@ -117,9 +121,9 @@ public class TypeDescriptor extends Descriptor {
   public String getSafeSymbol() {
     if (isArray())
       return IR.Flat.BuildCode.arraytype;
-    else if (isClass())
+    else if (isClass()) {
       return class_desc.getSafeSymbol();
-    else if (isByte())
+    else if (isByte())
       return "char";
     else if (isChar())
       return "short";
@@ -145,9 +149,9 @@ public class TypeDescriptor extends Descriptor {
   public String getRepairSymbol() {
     if (isArray())
       return IR.Flat.BuildCode.arraytype;
-    else if (isClass())
+    else if (isClass()) {
       return class_desc.getSymbol();
-    else if (isByte())
+    else if (isByte())
       return "byte";
     else if (isChar())
       return "short";
@@ -235,11 +239,11 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPtr() {
-    return (isClass()||isNull()||isTag()||isArray());
+    return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
   }
 
   public boolean isIntegerType() {
-    return (isInt()||isLong()||isShort()||isChar()||isByte());
+    return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
   }
 
   public void setClassDescriptor(ClassDescriptor cd) {
@@ -250,6 +254,15 @@ public class TypeDescriptor extends Descriptor {
     return ((type>=BYTE)&&(type<=DOUBLE));
   }
 
+  public boolean isEnum() {
+    if(this.type != CLASS) {
+      return false;
+    } else if(this.class_desc != null){
+      return this.class_desc.isEnum();
+    }
+    return false;
+  }
+  
   public boolean isClass() {
     return type==CLASS;
   }
@@ -267,7 +280,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
-    this.isStatic =false;
+    this.isClassNameRef =false;
   }
 
   public TypeDescriptor(String st) {
@@ -275,7 +288,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
-    this.isStatic =false;
+    this.isClassNameRef =false;
   }
 
   public ClassDescriptor getClassDesc() {
@@ -287,14 +300,14 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=cd;
     this.arraycount=0;
-    this.isStatic =false;
+    this.isClassNameRef =false;
   }
 
   public TypeDescriptor(int t) {
     super(decodeInt(t));
     this.type=t;
     this.arraycount=0;
-    this.isStatic =false;
+    this.isClassNameRef =false;
   }
 
   public String toString() {
index 1eda9aa480a0967bafea88f0e3d86a2a529cb7b9..3cd80b8629233d276600d9e06dd1c2c08157035c 100644 (file)
@@ -149,8 +149,15 @@ public class TypeUtil {
     if (md1.numParameters()!=md2.numParameters())
       throw new Error();
     for(int i=0; i<md1.numParameters(); i++) {
-      if (!this.isSuperorType(md2.getParamType(i), md1.getParamType(i)))
-       return false;
+      if (!this.isSuperorType(md2.getParamType(i), md1.getParamType(i))) {
+        if(state.MGC && ((!md1.getParamType(i).isArray() && 
+            (md1.getParamType(i).isInt() || md1.getParamType(i).isLong() || md1.getParamType(i).isDouble() || md1.getParamType(i).isFloat()))
+            && md2.getParamType(i).isClass() && md2.getParamType(i).getClassDesc().getSymbol().equals("Object"))) {
+          // primitive parameters vs Object
+        } else {
+          return false;
+        }
+      }
     }
     if (md1.getReturnType()==null||md2.getReturnType()==null) {
        if (md1.getReturnType()!=md2.getReturnType())
index aa9f50e80aa74f0148ab6b137a6a6b1f172ffd95..514e0758bb1e0806e715973fa5e9811246a5c4bb 100644 (file)
@@ -17,7 +17,7 @@ public class EnumTest {
     System.out.println(howHot);
     
     EnumTest et = new EnumTest();
-    et.howHot = Spiciness1.MEDIUM;
+    et.howHot = Spiciness1.MEDIUM; // EnumTest.Spiciness1.MEDIUM;
     System.out.println(et.howHot);
   }
 } /* Output:
index 3cd43eebd7861adfa7ae8d2d97c20f424f6cb517..7e04cd9023eb15e7cd1eb4a267caae14e12a1712 100755 (executable)
@@ -732,6 +732,11 @@ fi
 
 # Setup class path
 
+if $MGCFLAG
+then
+#base multicore gc files
+JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/MGC/ -classlibrary $ROBUSTROOT/ClassLibrary/MGC/gnu/"
+else
 if $RECOVERFLAG
 then
 if $FASTCHECK
@@ -754,14 +759,11 @@ elif $THREADFLAG
 then
 #threading java stuff
 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaThread"
-elif $MGCFLAG
-then
-#base multicore gc files
-JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/MGC -classlibrary $ROBUSTROOT/ClassLibrary/MGC/gnu"
 fi
 #base java stuff
 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Java"
 fi
+fi
 
 # Build bristlecone/java sources