work towards turning MGC enhancements on all the time
authorbdemsky <bdemsky>
Mon, 28 Feb 2011 04:39:52 +0000 (04:39 +0000)
committerbdemsky <bdemsky>
Mon, 28 Feb 2011 04:39:52 +0000 (04:39 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildCodeMGC.java
Robust/src/IR/Flat/BuildCodeMultiCore.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java
Robust/src/IR/Virtual.java

index 91affcc3767aad75f6564bd45a0a3893d74de8d9..a3fc73255575a48f884dbb09829a94e7b7d503d4 100644 (file)
@@ -86,16 +86,15 @@ public class BuildCode {
     PrintWriter outoptionalarrays=null;
     PrintWriter optionalheaders=null;
     PrintWriter outglobaldefs=null;
+    PrintWriter outglobaldefsprim=null;
 
     try {
       buildCodeSetup(); //EXTENSION POINT
       outstructs=new CodePrinter(new FileOutputStream(PREFIX+"structdefs.h"), true);
       outmethodheader=new CodePrinter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
       outclassdefs=new CodePrinter(new FileOutputStream(PREFIX+"classdefs.h"), true);
-      if(state.MGC) {
-       // TODO add version for normal Java later
-       outglobaldefs=new CodePrinter(new FileOutputStream(PREFIX+"globaldefs.h"), true);
-      }
+      outglobaldefs=new CodePrinter(new FileOutputStream(PREFIX+"globaldefs.h"), true);
+      outglobaldefsprim=new CodePrinter(new FileOutputStream(PREFIX+"globaldefsprim.h"), true);
       outmethod=new CodePrinter(new FileOutputStream(PREFIX+"methods.c"), true);
       outvirtual=new CodePrinter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
       if (state.TASK) {
@@ -140,35 +139,44 @@ public class BuildCode {
     // Output the C class declarations
     // These could mutually reference each other
 
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      outglobaldefs.println("#ifndef __GLOBALDEF_H_");
-      outglobaldefs.println("#define __GLOBALDEF_H_");
-      outglobaldefs.println("");
-      outglobaldefs.println("struct global_defs_t {");
-    }
+    outglobaldefs.println("#ifndef __GLOBALDEF_H_");
+    outglobaldefs.println("#define __GLOBALDEF_H_");
+    outglobaldefs.println("");
+    outglobaldefs.println("struct global_defs_t {");
+    outglobaldefs.println("  int size;");
+    outglobaldefsprim.println("#ifndef __GLOBALDEFPRIM_H_");
+    outglobaldefsprim.println("#define __GLOBALDEFPRIM_H_");
+    outglobaldefsprim.println("");
+    outglobaldefsprim.println("struct global_defsprim_t {");
 
     outclassdefs.println("#ifndef __CLASSDEF_H_");
     outclassdefs.println("#define __CLASSDEF_H_");
-    outputClassDeclarations(outclassdefs, outglobaldefs);
+    outputClassDeclarations(outclassdefs, outglobaldefs, outglobaldefsprim);
 
     // Output function prototypes and structures for parameters
     Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
     while(it.hasNext()) {
       ClassDescriptor cn=(ClassDescriptor)it.next();
-      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs);
+      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs, outglobaldefsprim);
     }
+    outclassdefs.println("#include \"globaldefs.h\"");
+    outclassdefs.println("#include \"globaldefsprim.h\"");
     outclassdefs.println("#endif");
     outclassdefs.close();
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      outglobaldefs.println("};");
-      outglobaldefs.println("");
-      outglobaldefs.println("extern struct global_defs_t * global_defs_p;");
-      outglobaldefs.println("#endif");
-      outglobaldefs.flush();
-      outglobaldefs.close();
-    }
+    
+    outglobaldefs.println("};");
+    outglobaldefs.println("");
+    outglobaldefs.println("extern struct global_defs_t * global_defs_p;");
+    outglobaldefs.println("#endif");
+    outglobaldefs.flush();
+    outglobaldefs.close();
+
+    outglobaldefsprim.println("};");
+    outglobaldefsprim.println("");
+    outglobaldefsprim.println("extern struct global_defsprim_t * global_defsprim_p;");
+    outglobaldefsprim.println("#endif");
+    outglobaldefsprim.flush();
+    outglobaldefsprim.close();
 
     if (state.TASK) {
       /* Map flags to integers */
@@ -243,36 +251,34 @@ public class BuildCode {
    * invoked inside static blocks
    */
   protected void tagMethodInvokedByStaticBlock() {
-    if(state.MGC) {
-      Iterator it_sclasses = this.state.getSClassSymbolTable().getDescriptorsIterator();
-      MethodDescriptor current_md=null;
-      HashSet tovisit=new HashSet();
-      HashSet visited=new HashSet();
-
-      while(it_sclasses.hasNext()) {
-       ClassDescriptor cd = (ClassDescriptor)it_sclasses.next();
-       MethodDescriptor md = (MethodDescriptor)cd.getMethodTable().get("staticblocks");
-       if(md != null) {
-         tovisit.add(md);
-       }
+    Iterator it_sclasses = this.state.getSClassSymbolTable().getDescriptorsIterator();
+    MethodDescriptor current_md=null;
+    HashSet tovisit=new HashSet();
+    HashSet visited=new HashSet();
+    
+    while(it_sclasses.hasNext()) {
+      ClassDescriptor cd = (ClassDescriptor)it_sclasses.next();
+      MethodDescriptor md = (MethodDescriptor)cd.getMethodTable().get("staticblocks");
+      if(md != null) {
+       tovisit.add(md);
       }
-
-      while(!tovisit.isEmpty()) {
-       current_md=(MethodDescriptor)tovisit.iterator().next();
-       tovisit.remove(current_md);
-       visited.add(current_md);
-       Iterator it_callee = this.callgraph.getCalleeSet(current_md).iterator();
-       while(it_callee.hasNext()) {
-         Descriptor d = (Descriptor)it_callee.next();
-         if(d instanceof MethodDescriptor) {
-           if(!visited.contains(d)) {
-             ((MethodDescriptor)d).setIsInvokedByStatic(true);
-             tovisit.add(d);
-           }
+    }
+    
+    while(!tovisit.isEmpty()) {
+      current_md=(MethodDescriptor)tovisit.iterator().next();
+      tovisit.remove(current_md);
+      visited.add(current_md);
+      Iterator it_callee = this.callgraph.getCalleeSet(current_md).iterator();
+      while(it_callee.hasNext()) {
+       Descriptor d = (Descriptor)it_callee.next();
+       if(d instanceof MethodDescriptor) {
+         if(!visited.contains(d)) {
+           ((MethodDescriptor)d).setIsInvokedByStatic(true);
+           tovisit.add(d);
          }
        }
       }
-    } // TODO for normal Java version
+    }
   }
 
   /* This code generates code for each static block and static field
@@ -428,11 +434,8 @@ public class BuildCode {
 
     additionalIncludesMethodsImplementation(outmethod);
 
-
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      outmethod.println("struct global_defs_t * global_defs_p;");
-    }
+    outmethod.println("struct global_defs_t * global_defs_p;");
+    outmethod.println("struct global_defsprim_t * global_defsprim_p;");
     //Store the sizes of classes & array elements
     generateSizeArray(outmethod);
 
@@ -515,7 +518,7 @@ public class BuildCode {
     }
   }
 
-  protected void outputClassDeclarations(PrintWriter outclassdefs, PrintWriter outglobaldefs) {
+  protected void outputClassDeclarations(PrintWriter outclassdefs, PrintWriter outglobaldefs, PrintWriter outglobaldefsprim) {
     if (state.THREAD||state.DSM||state.SINGLETM)
       outclassdefs.println("#include <pthread.h>");
     outclassdefs.println("#ifndef INTPTR");
@@ -534,18 +537,15 @@ public class BuildCode {
       ClassDescriptor cn=(ClassDescriptor)it.next();
       outclassdefs.println("struct "+cn.getSafeSymbol()+";");
 
-      if(state.MGC) {
-       // TODO add version for normal Java later
-       if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
-         // this class has static fields/blocks, need to add a global flag to
-         // indicate if its static fields have been initialized and/or if its
-         // static blocks have been executed
-         outglobaldefs.println("  int "+cn.getSafeSymbol()+"static_block_exe_flag;");
-       }
-
-       // for each class, create a global object
-       outglobaldefs.println("  struct ___Object___ *"+cn.getSafeSymbol()+"classobj;");
+      if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+       // this class has static fields/blocks, need to add a global flag to
+       // indicate if its static fields have been initialized and/or if its
+       // static blocks have been executed
+       outglobaldefsprim.println("  int "+cn.getSafeSymbol()+"static_block_exe_flag;");
       }
+      
+      // for each class, create a global object
+      outglobaldefs.println("  struct ___Object___ *"+cn.getSafeSymbol()+"classobj;");
     }
     outclassdefs.println("");
     //Print out definition for array type
@@ -590,7 +590,7 @@ public class BuildCode {
       }
     }
 
-    printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+    printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs, outglobaldefsprim);
     printedfieldstbl.clear();
     printExtraArrayFields(outclassdefs);
     if (state.ARRAYPAD) {
@@ -644,7 +644,7 @@ public class BuildCode {
          outclassdefs.println("  int * fses;");
        }
       }
-      printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+      printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs, outglobaldefsprim);
       printedfieldstbl.clear();
       outclassdefs.println("};\n");
     }
@@ -870,13 +870,10 @@ public class BuildCode {
     /* Get inherited methods */
     if (cd.getSuperDesc()!=null)
       fillinRow(cd.getSuperDesc(), virtualtable, rownum);
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      Iterator it_sifs = cd.getSuperInterfaces();
-      while(it_sifs.hasNext()) {
-       ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
-       fillinRow(superif, virtualtable, rownum);
-      }
+    Iterator it_sifs = cd.getSuperInterfaces();
+    while(it_sifs.hasNext()) {
+      ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
+      fillinRow(superif, virtualtable, rownum);
     }
     /* Override them with our methods */
     for(Iterator it=cd.getMethods(); it.hasNext(); ) {
@@ -1224,19 +1221,17 @@ public class BuildCode {
 
   /** Force consistent field ordering between inherited classes. */
 
-  protected void printClassStruct(ClassDescriptor cn, PrintWriter classdefout, PrintWriter globaldefout) {
+  protected void printClassStruct(ClassDescriptor cn, PrintWriter classdefout, PrintWriter globaldefout, PrintWriter globaldefprimout) {
 
     ClassDescriptor sp=cn.getSuperDesc();
     if (sp!=null)
-      printClassStruct(sp, classdefout, /*globaldefout*/ null);
+      printClassStruct(sp, classdefout, /*globaldefout*/ null, null);
 
     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);
-      }
+    while(it_sifs.hasNext()) {
+      ClassDescriptor si = (ClassDescriptor)it_sifs.next();
+      printClassStruct(si, classdefout, /*globaldefout*/ null, null);
     }
 
     if (!fieldorder.containsKey(cn)) {
@@ -1246,28 +1241,23 @@ public class BuildCode {
       Vector fieldvec=cn.getFieldVec();
       for(int i=0; i<fieldvec.size(); i++) {
        FieldDescriptor fd=(FieldDescriptor)fieldvec.get(i);
-       if(state.MGC) {
-         if((sp != null) && sp.getFieldTable().contains(fd.getSymbol())) {
-           // a shadow field
-         } 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
-           } else {
-             fields.add(fd);
+       if((sp != null) && sp.getFieldTable().contains(fd.getSymbol())) {
+         // a shadow field
+       } 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;
            }
          }
-       } else {
-         if ((sp==null) || (!sp.getFieldTable().contains(fd.getSymbol())))
+         if(hasprinted) {
+           // this field has been defined in the super class
+         } else {
            fields.add(fd);
+         }
        }
       }
     }
@@ -1284,11 +1274,11 @@ public class BuildCode {
       } else {
         printedfieldstbl.put(fstring, cn);
       }
-      if (state.MGC && fd.getType().isClass()
+      if (fd.getType().isClass()
           && fd.getType().getClassDesc().isEnum()) {
        classdefout.println("  int " + fd.getSafeSymbol() + ";");
       } else if (fd.getType().isClass()||fd.getType().isArray()) {
-       if ((state.MGC) && (fd.isStatic())) {
+       if (fd.isStatic()) {
          // TODO add version for normal Java later
          // static field
          if(globaldefout != null) {
@@ -1298,30 +1288,26 @@ public class BuildCode {
              globaldefout.println("  struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
            }
          }
-       } else if ((state.MGC) && (fd.isVolatile())) {
-         // TODO add version for normal Java later
-         // static field
-         if(globaldefout != null) {
-           globaldefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
-         }
+       } else if (fd.isVolatile()) {
+         //volatile field
+         classdefout.println("  volatile struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
        } else {
          classdefout.println("  struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
        }
-      } else if ((state.MGC) && (fd.isStatic())) {
+      } else if (fd.isStatic()) {
        // TODO add version for normal Java later
        // static field
        if(globaldefout != null) {
          if(fd.isVolatile()) {
-           globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
+           globaldefprimout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
          } else {
-           globaldefout.println("  "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
+           globaldefprimout.println("  "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
          }
        }
-         } else if ((state.MGC) && (fd.isVolatile())) {
-       // TODO add version for normal Java later
-       // static field
+      } else if (fd.isVolatile()) {
+       //volatile field
        if(globaldefout != null) {
-         globaldefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
+         classdefout.println("  volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
        }
       } else
        classdefout.println("  "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";");
@@ -1366,7 +1352,7 @@ public class BuildCode {
    * passed in (when PRECISE GC is enabled) and (2) function
    * prototypes for the methods */
 
-  protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout, PrintWriter globaldefout) {
+  protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout, PrintWriter globaldefout, PrintWriter globaldefprimout) {
     /* Output class structure */
     classdefout.println("struct "+cn.getSafeSymbol()+" {");
     classdefout.println("  int type;");
@@ -1383,12 +1369,10 @@ public class BuildCode {
       classdefout.println("  void * lockentry;");
       classdefout.println("  int lockcount;");
     }
-    if(state.MGC) {
-      classdefout.println("  int mutex;");
-      classdefout.println("  int objlock;");
-      if(state.MULTICOREGC) {
-       classdefout.println("  int marked;");
-      }
+    classdefout.println("  int mutex;");
+    classdefout.println("  int objlock;");
+    if(state.MULTICOREGC) {
+      classdefout.println("  int marked;");
     }
     if (state.TASK) {
       classdefout.println("  int flag;");
@@ -1408,7 +1392,7 @@ public class BuildCode {
        classdefout.println("  int * fses;");
       }
     }
-    printClassStruct(cn, classdefout, globaldefout);
+    printClassStruct(cn, classdefout, globaldefout, globaldefprimout);
     printedfieldstbl.clear(); // = new Hashtable<String, ClassDescriptor>();
     classdefout.println("};\n");
     generateCallStructsMethods(cn, output, headersout);
@@ -1431,7 +1415,7 @@ public class BuildCode {
       output.println("  void * next;");
       for(int i=0; i<objectparams.numPointers(); i++) {
        TempDescriptor temp=objectparams.getPointer(i);
-       if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+       if(temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
          output.println("  int " + temp.getSafeSymbol() + ";");
        } else {
          output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
@@ -1469,7 +1453,7 @@ public class BuildCode {
     headersout.println("#define D"+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+" 1");
     /* First the return type */
     if (md.getReturnType()!=null) {
-      if(state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+      if(md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
        headersout.println("  int ");
       } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        headersout.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
@@ -1493,7 +1477,7 @@ public class BuildCode {
       if (printcomma)
        headersout.print(", ");
       printcomma=true;
-      if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+      if(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());
@@ -1594,7 +1578,7 @@ public class BuildCode {
       TypeDescriptor type=td.getType();
       if (type.isNull() && !type.isArray())
        output.println("   void * "+td.getSafeSymbol()+";");
-      else if (state.MGC && type.isClass() && type.getClassDesc().isEnum()) {
+      else if (type.isClass() && type.getClassDesc().isEnum()) {
        output.println("   int " + td.getSafeSymbol() + ";");
       } else if (type.isClass()||type.isArray())
        output.println("   struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
@@ -1619,15 +1603,12 @@ public class BuildCode {
       }
     }
 
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      if(fm.getMethod().isStaticBlock()) {
-       // a static block, check if it has been executed
-       output.println("  if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag != 0) {");
-       output.println("    return;");
-       output.println("  }");
-       output.println("");
-      }
+    if(fm.getMethod().isStaticBlock()) {
+      // a static block, check if it has been executed
+      output.println("  if(global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag != 0) {");
+      output.println("    return;");
+      output.println("  }");
+      output.println("");
     }
 
     generateCode(fm.getNext(0), fm, null, output);
@@ -1686,13 +1667,10 @@ public class BuildCode {
          assert fsxn.getFlatEnter().equals(fsen);
        }
        if (current_node.kind()!=FKind.FlatReturnNode) {
-         if(state.MGC) {
-           // TODO add version for normal Java later
-           if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
-             // a static block, check if it has been executed
-             output.println("  global_defs_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
-             output.println("");
-           }
+         if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
+           // a static block, check if it has been executed
+           output.println("  global_defsprim_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
+           output.println("");
          }
          output.println("   return;");
        }
@@ -2008,44 +1986,41 @@ public class BuildCode {
 
     // if the called method is a static block or a static method or a constructor
     // need to check if it can be invoked inside some static block
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      if((md.isStatic() || md.isStaticBlock() || md.isConstructor()) &&
-         ((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()))) {
-       if(!md.isInvokedByStatic()) {
-         System.err.println("Error: a method that is invoked inside a static block is not tagged!");
-       }
-       // is a static block or is invoked in some static block
-       ClassDescriptor cd = fm.getMethod().getClassDesc();
-       if(cd == cn) {
-         // the same class, do nothing
-         // TODO may want to invoke static field initialization here
-       } else {
-         if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
-           // need to check if the class' static fields have been initialized and/or
-           // 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.getNumStaticBlocks() != 0) {
-             MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
-             output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
-           } else {
-             output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
-           }
-           output.println("}");
-           output.println("#endif // MGC_STATIC_INIT_CHECK");
+    if((md.isStatic() || md.isStaticBlock() || md.isConstructor()) &&
+       ((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()))) {
+      if(!md.isInvokedByStatic()) {
+       System.err.println("Error: a method that is invoked inside a static block is not tagged!");
+      }
+      // is a static block or is invoked in some static block
+      ClassDescriptor cd = fm.getMethod().getClassDesc();
+      if(cd == cn) {
+       // the same class, do nothing
+       // TODO may want to invoke static field initialization here
+      } else {
+       if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+         // need to check if the class' static fields have been initialized and/or
+         // its static blocks have been executed
+         output.println("#ifdef MGC_STATIC_INIT_CHECK");
+         output.println("if(global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
+         if(cn.getNumStaticBlocks() != 0) {
+           MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
+           output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
+         } else {
+           output.println("  global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
          }
+         output.println("}");
+         output.println("#endif // MGC_STATIC_INIT_CHECK");
        }
       }
-      if((md.getSymbol().equals("MonitorEnter") || md.getSymbol().equals("MonitorExit")) && fc.getThis().getSymbol().equals("classobj")) {
-       // call MonitorEnter/MonitorExit on a class obj
-       output.println("       " + cn.getSafeSymbol()+md.getSafeSymbol()+"_"
-                      +md.getSafeMethodDescriptor() + "((struct ___Object___*)(global_defs_p->"
-                      + fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj));");
-       return;
-      }
     }
-
+    if((md.getSymbol().equals("MonitorEnter") || md.getSymbol().equals("MonitorExit")) && fc.getThis().getSymbol().equals("classobj")) {
+      // call MonitorEnter/MonitorExit on a class obj
+      output.println("       " + cn.getSafeSymbol()+md.getSafeSymbol()+"_"
+                    +md.getSafeMethodDescriptor() + "((struct ___Object___*)(global_defs_p->"
+                    + fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj));");
+      return;
+    }
+    
     output.println("{");
     if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       output.print("       struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
@@ -2089,7 +2064,7 @@ public class BuildCode {
     } else {
       //yes
       output.print("((");
-      if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+      if (md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
        output.print("int ");
       } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
@@ -2108,7 +2083,7 @@ public class BuildCode {
        if (printcomma)
          output.print(", ");
        printcomma=true;
-       if (state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+       if (temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
          output.print("int ");
        } else if (temp.getType().isClass()||temp.getType().isArray())
          output.print("struct " + temp.getType().getSafeSymbol()+" * ");
@@ -2137,7 +2112,7 @@ public class BuildCode {
        }
        if (needcomma)
          output.print(",");
-       if(state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
+       if(ptd.isClass() && ptd.getClassDesc().isEnum()) {
          // do nothing
        } else if (ptd.isClass()&&!ptd.isArray())
          output.print("(struct "+ptd.getSafeSymbol()+" *) ");
@@ -2155,7 +2130,7 @@ public class BuildCode {
          output.print(", ");
 
        TypeDescriptor ptd=md.getParamType(i);
-       if (state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
+       if (ptd.isClass() && ptd.getClassDesc().isEnum()) {
          // do nothing
        } else if (ptd.isClass()&&!ptd.isArray())
          output.print("(struct "+ptd.getSafeSymbol()+" *) ");
@@ -2184,47 +2159,45 @@ public class BuildCode {
   }
 
   protected void generateFlatFieldNode(FlatMethod fm, FlatFieldNode ffn, PrintWriter output) {
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      if(ffn.getField().isStatic() || ffn.getField().isVolatile()) {
-       // static field
-       if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
-         // is a static block or is invoked in some static block
-         ClassDescriptor cd = fm.getMethod().getClassDesc();
-         ClassDescriptor cn = ffn.getSrc().getType().getClassDesc();
-         if(cd == cn) {
-           // the same class, do nothing
-           // TODO may want to invoke static field initialization here
-         } else {
-           if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
-             // need to check if the class' static fields have been initialized and/or
-             // 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.getNumStaticBlocks() != 0) {
-               MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
-               output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
-             } else {
-               output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
-             }
-             output.println("}");
-             output.println("#endif // MGC_STATIC_INIT_CHECK");
+    if(ffn.getField().isStatic() || ffn.getField().isVolatile()) {
+      // static field
+      if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
+       // is a static block or is invoked in some static block
+       ClassDescriptor cd = fm.getMethod().getClassDesc();
+       ClassDescriptor cn = ffn.getSrc().getType().getClassDesc();
+       if(cd == cn) {
+         // the same class, do nothing
+         // TODO may want to invoke static field initialization here
+       } else {
+         if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+           // need to check if the class' static fields have been initialized and/or
+           // its static blocks have been executed
+           output.println("#ifdef MGC_STATIC_INIT_CHECK");
+           output.println("if(global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
+           if(cn.getNumStaticBlocks() != 0) {
+             MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
+             output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
+           } else {
+             output.println("  global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
            }
+           output.println("}");
+           output.println("#endif // MGC_STATIC_INIT_CHECK");
          }
        }
-       // redirect to the global_defs_p structure
-       if((ffn.getField().isStatic()) || (ffn.getField().isVolatile()) || (ffn.getSrc().getType().isClassNameRef())) {
-         // reference to the static field with Class name
+      }
+      // redirect to the global_defs_p structure
+      if((ffn.getField().isStatic()) || (ffn.getField().isVolatile()) || (ffn.getSrc().getType().isClassNameRef())) {
+       // reference to the static field with Class name
+       if (ffn.getField().getType().isPtr())
          output.println(generateTemp(fm, ffn.getDst())+"=global_defs_p->"+ffn.getField().getSafeSymbol()+";");
-       } else {
-         output.println(generateTemp(fm, ffn.getDst())+"=*"+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
-       }
-      } else if (ffn.getField().isEnum()) {
-       // an Enum value, directly replace the field access as int
-       output.println(generateTemp(fm, ffn.getDst()) + "=" + ffn.getField().enumValue() + ";");
+       else
+         output.println(generateTemp(fm, ffn.getDst())+"=global_defsprim_p->"+ffn.getField().getSafeSymbol()+";");
       } else {
-       output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
+       output.println(generateTemp(fm, ffn.getDst())+"=*"+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
       }
+    } else if (ffn.getField().isEnum()) {
+      // an Enum value, directly replace the field access as int
+      output.println(generateTemp(fm, ffn.getDst()) + "=" + ffn.getField().enumValue() + ";");
     } else {
       output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
     }
@@ -2246,61 +2219,61 @@ public class BuildCode {
       output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
       output.println("}");
     }
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      if(fsfn.getField().isStatic()) {
-       // static field
-       if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
-         // is a static block or is invoked in some static block
-         ClassDescriptor cd = fm.getMethod().getClassDesc();
-         ClassDescriptor cn = fsfn.getDst().getType().getClassDesc();
-         if(cd == cn) {
-           // the same class, do nothing
-           // TODO may want to invoke static field initialization here
-         } else {
-           if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
-             // need to check if the class' static fields have been initialized and/or
-             // 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()+"();");
-             } else {
-               output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
-             }
-             output.println("}");
-             output.println("#endif // MGC_STATIC_INIT_CHECK");
+
+    if(fsfn.getField().isStatic()) {
+      // static field
+      if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
+       // is a static block or is invoked in some static block
+       ClassDescriptor cd = fm.getMethod().getClassDesc();
+       ClassDescriptor cn = fsfn.getDst().getType().getClassDesc();
+       if(cd == cn) {
+         // the same class, do nothing
+         // TODO may want to invoke static field initialization here
+       } else {
+         if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+           // need to check if the class' static fields have been initialized and/or
+           // its static blocks have been executed
+           output.println("#ifdef MGC_STATIC_INIT_CHECK");
+           output.println("if(global_defsprim_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()+"();");
+           } else {
+             output.println("  global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
+           }
+           output.println("}");
+           output.println("#endif // MGC_STATIC_INIT_CHECK");
          }
        }
-       // redirect to the global_defs_p structure
-       if((fsfn.getDst().getType().isClassNameRef()) || (fsfn.getField().isStatic()) || (fsfn.getField().isVolatile())) {
-         // reference to the static field with Class name
+      }
+      // redirect to the global_defs_p structure
+      if((fsfn.getDst().getType().isClassNameRef()) || (fsfn.getField().isStatic()) || (fsfn.getField().isVolatile())) {
+       // reference to the static field with Class name
+       if (fsfn.getField().getType().isPtr())
          output.println("global_defs_p->" +
-                        fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
-       } else {
-         output.println("*"+generateTemp(fm, fsfn.getDst())+"->"+
-                        fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
-       }
+                        fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
+       else
+         output.println("global_defsprim_p->" +
+                        fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
       } else {
-       output.println(generateTemp(fm, fsfn.getDst())+"->"+
-                      fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
+       output.println("*"+generateTemp(fm, fsfn.getDst())+"->"+
+                      fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
       }
     } else {
       output.println(generateTemp(fm, fsfn.getDst())+"->"+
-                     fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
+                    fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";");
     }
   }
 
+
   protected void generateFlatElementNode(FlatMethod fm, FlatElementNode fen, PrintWriter output) {
     TypeDescriptor elementtype=fen.getSrc().getType().dereference();
     String type="";
 
-    if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
+    if (elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
       type="int ";
     } else if (elementtype.isArray()||elementtype.isClass())
       type="void *";
@@ -2321,9 +2294,9 @@ public class BuildCode {
     TypeDescriptor elementtype=fsen.getDst().getType().dereference();
     String type="";
 
-    if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
+    if (elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
       type="int ";
-    } else if (elementtype.isArray()||elementtype.isClass() || (state.MGC && elementtype.isNull()))
+    } else if (elementtype.isArray()||elementtype.isClass() || (elementtype.isNull()))
       type="void *";
     else
       type=elementtype.getSafeSymbol()+" ";
@@ -2409,7 +2382,7 @@ public class BuildCode {
     /* TODO: Do type check here */
     if (fcn.getType().isArray()) {
       output.println(generateTemp(fm,fcn.getDst())+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc())+";");
-    } else if (state.MGC && fcn.getType().isClass() && fcn.getType().getClassDesc().isEnum()) {
+    } else if (fcn.getType().isClass() && fcn.getType().getClassDesc().isEnum()) {
       output.println(generateTemp(fm,fcn.getDst())+"=(int)"+generateTemp(fm,fcn.getSrc())+";");
     } else if (fcn.getType().isClass())
       output.println(generateTemp(fm,fcn.getDst())+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc())+";");
@@ -2441,14 +2414,12 @@ public class BuildCode {
   }
 
   protected void generateFlatReturnNode(FlatMethod fm, FlatReturnNode frn, PrintWriter output) {
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
-       // a static block, check if it has been executed
-       output.println("  global_defs_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
-       output.println("");
-      }
+    if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
+      // a static block, check if it has been executed
+      output.println("  global_defsprim_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
+      output.println("");
     }
+    
     if (frn.getReturnTemp()!=null) {
       if (frn.getReturnTemp().getType().isPtr())
        output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp())+";");
@@ -2482,7 +2453,7 @@ public class BuildCode {
     ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
 
     if (md!=null&&md.getReturnType()!=null) {
-      if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
+      if (md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
        output.print("int ");
       } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
        output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
@@ -2512,7 +2483,7 @@ public class BuildCode {
        if (printcomma)
          output.print(", ");
        printcomma=true;
-       if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+       if(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());
@@ -2526,7 +2497,7 @@ public class BuildCode {
       /* Unpack variables */
       for(int i=0; i<objectparams.numPrimitives(); i++) {
        TempDescriptor temp=objectparams.getPrimitive(i);
-       if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
+       if(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+"];");
index 9d09dd1a63d1db493b0b499f799ae82c84193a25..3384a86a8b1da0b38fbff6d3f6acf157a3eaf6af 100644 (file)
@@ -37,6 +37,7 @@ public class BuildCodeMGC extends BuildCode {
     /* Create output streams to write to */
     PrintWriter outclassdefs=null;
     PrintWriter outglobaldefs=null;
+    PrintWriter outglobaldefsprim=null;
     PrintWriter outstructs=null;
     PrintWriter outmethodheader=null;
     PrintWriter outmethod=null;
@@ -47,6 +48,7 @@ public class BuildCodeMGC extends BuildCode {
       outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
       outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
       outglobaldefs=new PrintWriter(new FileOutputStream(PREFIX+"globaldefs.h"), true);
+      outglobaldefsprim=new PrintWriter(new FileOutputStream(PREFIX+"globaldefsprim.h"), true);
       outvirtual=new PrintWriter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
       outmethod=new PrintWriter(new FileOutputStream(PREFIX+"methods.c"), true);
     } catch (Exception e) {
@@ -75,22 +77,28 @@ public class BuildCodeMGC extends BuildCode {
     outglobaldefs.println("#define __GLOBALDEF_H_");
     outglobaldefs.println("");
     outglobaldefs.println("struct global_defs_t {");
+
+    outglobaldefsprim.println("#ifndef __GLOBALDEFPRIM_H_");
+    outglobaldefsprim.println("#define __GLOBALDEFPRIM_H_");
+    outglobaldefsprim.println("");
+    outglobaldefsprim.println("struct global_defsprim_t {");
     
     // Output the C class declarations
     // These could mutually reference each other    
     outclassdefs.println("#ifndef __CLASSDEF_H_");
     outclassdefs.println("#define __CLASSDEF_H_");
-    super.outputClassDeclarations(outclassdefs, outglobaldefs);
+    super.outputClassDeclarations(outclassdefs, outglobaldefs, outglobaldefsprim);
 
     // Output function prototypes and structures for parameters
     Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
     int numclasses = this.state.numClasses();
     while(it.hasNext()) {
       ClassDescriptor cn=(ClassDescriptor)it.next();
-      super.generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs);
+      super.generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs, outglobaldefsprim);
     }
     // TODO add version for normal Java later
     outclassdefs.println("#include \"globaldefs.h\"");
+    outclassdefs.println("#include \"globaldefsprim.h\"");
     outclassdefs.println("#endif");
     outclassdefs.close();
     outglobaldefs.println("};");
@@ -100,6 +108,13 @@ public class BuildCodeMGC extends BuildCode {
     outglobaldefs.flush();
     outglobaldefs.close();
 
+    outglobaldefsprim.println("};");
+    outglobaldefsprim.println("");
+    outglobaldefsprim.println("extern struct global_defsprim_t * global_defsprim_p;");
+    outglobaldefsprim.println("#endif");
+    outglobaldefsprim.flush();
+    outglobaldefsprim.close();
+
     /* Build the actual methods */
     super.outputMethods(outmethod);
 
index de2a62385a2076f8094aedb49376daade024dfc2..7d67c3f0eac1bc933b51119231efb26784c0f92d 100644 (file)
@@ -96,6 +96,7 @@ public class BuildCodeMultiCore extends BuildCode {
     /* Create output streams to write to */
     PrintWriter outclassdefs=null;
     PrintWriter outglobaldefs=null;
+    PrintWriter outglobaldefsprim=null;
     PrintWriter outstructs=null;
     PrintWriter outmethodheader=null;
     PrintWriter outmethod=null;
@@ -109,7 +110,7 @@ public class BuildCodeMultiCore extends BuildCode {
       outstructs=new PrintWriter(new FileOutputStream(PREFIX+"structdefs.h"), true);
       outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
       outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
-      outglobaldefs=new PrintWriter(new FileOutputStream(PREFIX+"globaldefs.h"), true);
+      outglobaldefsprim=new PrintWriter(new FileOutputStream(PREFIX+"globaldefsprim.h"), true);
       outvirtual=new PrintWriter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
       outmethod=new PrintWriter(new FileOutputStream(PREFIX+"methods.c"), true);
       if (state.TASK) {
@@ -153,14 +154,14 @@ public class BuildCodeMultiCore extends BuildCode {
     // These could mutually reference each other
     outclassdefs.println("#ifndef __CLASSDEF_H_");
     outclassdefs.println("#define __CLASSDEF_H_");
-    outputClassDeclarations(outclassdefs, outglobaldefs);
+    outputClassDeclarations(outclassdefs, outglobaldefs, outglobaldefsprim);
 
     // Output function prototypes and structures for parameters
     Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
     int numclasses = this.state.numClasses();
     while(it.hasNext()) {
       ClassDescriptor cn=(ClassDescriptor)it.next();
-      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs);
+      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs, outglobaldefsprim);
     }
     outclassdefs.println("#endif");
     outclassdefs.close();
index 4e9c36e3c6835861afa49c2204040b51e850cc09..100b5e2f0a4e8ebf3bb05865c51450f6226c0ee1 100644 (file)
@@ -26,7 +26,7 @@ public class BuildIR {
   public void parseFile(ParseNode pn, Set toanalyze) {
     singleimports=new Vector();
     multiimports=new Vector();
-
+    
     ParseNode ipn=pn.getChild("imports").getChild("import_decls_list");
     if (ipn!=null) {
       ParseNodeVector pnv=ipn.getChildren();
@@ -56,79 +56,73 @@ public class BuildIR {
          if (toanalyze!=null)
            toanalyze.add(cn);
          state.addClass(cn);
-      // for inner classes/enum
-      if(state.MGC) {
-        // TODO add version for normal Java later
-        HashSet tovisit = new HashSet();
-        Iterator it_icds = cn.getInnerClasses();
-        while(it_icds.hasNext()) {
-          tovisit.add(it_icds.next());
-        }
-        
-        while(!tovisit.isEmpty()) {
-          ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
-          tovisit.remove(cd);
-         parseInitializers(cd);
-          if(toanalyze != null) {
-            toanalyze.add(cd);
-          }
-          state.addClass(cd);
-          
-          Iterator it_ics = cd.getInnerClasses();
-          while(it_ics.hasNext()) {
-            tovisit.add(it_ics.next());
-          }
-          
-          Iterator it_ienums = cd.getEnum();
-          while(it_ienums.hasNext()) {
-            ClassDescriptor iecd = (ClassDescriptor)it_ienums.next();
-            if(toanalyze != null) {
-              toanalyze.add(iecd);
-            }
-            state.addClass(iecd);
-          }
-        }
-        
-        Iterator it_enums = cn.getEnum();
-        while(it_enums.hasNext()) {
-          ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
-          if(toanalyze != null) {
-            toanalyze.add(ecd);
-          }
-          state.addClass(ecd);
-        }
-      }
+         // for inner classes/enum
+         HashSet tovisit = new HashSet();
+         Iterator it_icds = cn.getInnerClasses();
+         while(it_icds.hasNext()) {
+           tovisit.add(it_icds.next());
+         }
+         
+         while(!tovisit.isEmpty()) {
+           ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
+           tovisit.remove(cd);
+           parseInitializers(cd);
+           if(toanalyze != null) {
+             toanalyze.add(cd);
+           }
+           state.addClass(cd);
+           
+           Iterator it_ics = cd.getInnerClasses();
+           while(it_ics.hasNext()) {
+             tovisit.add(it_ics.next());
+           }
+           
+           Iterator it_ienums = cd.getEnum();
+           while(it_ienums.hasNext()) {
+             ClassDescriptor iecd = (ClassDescriptor)it_ienums.next();
+             if(toanalyze != null) {
+               toanalyze.add(iecd);
+             }
+             state.addClass(iecd);
+           }
+         }
+         
+         Iterator it_enums = cn.getEnum();
+         while(it_enums.hasNext()) {
+           ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
+           if(toanalyze != null) {
+             toanalyze.add(ecd);
+           }
+           state.addClass(ecd);
+         }
        } else if (isNode(type_pn,"task_declaration")) {
          TaskDescriptor td=parseTaskDecl(type_pn);
          if (toanalyze!=null)
            toanalyze.add(td);
          state.addTask(td);
-       } else if ((state.MGC) && isNode(type_pn,"interface_declaration")) {
-      // TODO add version for normal Java later
-      ClassDescriptor cn = parseInterfaceDecl(type_pn);
-      if (toanalyze!=null)
-        toanalyze.add(cn);
-      state.addClass(cn);
-      
-      // for enum
-      if(state.MGC) {
-        // TODO add version for normal Java later        
-        Iterator it_enums = cn.getEnum();
-        while(it_enums.hasNext()) {
-          ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
-          if(toanalyze != null) {
-            toanalyze.add(ecd);
-          }
-          state.addClass(ecd);
-        }
-      }
-    } else if ((state.MGC) && isNode(type_pn,"enum_declaration")) {
-      // TODO add version for normal Java later
-      ClassDescriptor cn = parseEnumDecl(null, type_pn);
-      if (toanalyze!=null)
-        toanalyze.add(cn);
-      state.addClass(cn);
-    } else {
+       } else if (isNode(type_pn,"interface_declaration")) {
+         // TODO add version for normal Java later
+         ClassDescriptor cn = parseInterfaceDecl(type_pn);
+         if (toanalyze!=null)
+           toanalyze.add(cn);
+         state.addClass(cn);
+         
+         // for enum
+         Iterator it_enums = cn.getEnum();
+         while(it_enums.hasNext()) {
+           ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
+           if(toanalyze != null) {
+             toanalyze.add(ecd);
+           }
+           state.addClass(ecd);
+         }
+       } else if (isNode(type_pn,"enum_declaration")) {
+         // TODO add version for normal Java later
+         ClassDescriptor cn = parseEnumDecl(null, type_pn);
+         if (toanalyze!=null)
+           toanalyze.add(cn);
+         state.addClass(cn);
+       } else {
          throw new Error(type_pn.getLabel());
        }
       }
@@ -477,13 +471,8 @@ public class BuildIR {
        } else if (isNode(decl,"constructor")) {
          parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
        } else if (isNode(decl, "static_block")) {
-      if(state.MGC) {
-        // TODO add version for normal Java later
-      parseStaticBlockDecl(cn, decl.getChild("static_block_declaration"));
-      } else {
-        throw new Error("Static blocks not implemented");
-      }
-    } else if (isNode(decl,"block")) {
+         parseStaticBlockDecl(cn, decl.getChild("static_block_declaration"));
+       } else if (isNode(decl,"block")) {
        } else throw new Error();
       }
     }
@@ -502,23 +491,12 @@ public class BuildIR {
     }
     ParseNode innerclassnode=pn.getChild("inner_class_declaration");
     if (innerclassnode!=null) {
-      if(state.MGC){
-        parseInnerClassDecl(cn,innerclassnode);
-        return;
-      } else {
-        // TODO add version for noraml Java later
-        throw new Error("Error: inner class in Class " + cn.getSymbol() + " is not supported yet");
-      }
+      parseInnerClassDecl(cn,innerclassnode);
+      return;
     }
     ParseNode enumnode=pn.getChild("enum_declaration");
     if (enumnode!=null) {
-      if(state.MGC){
-        parseEnumDecl(cn,enumnode);
-        return;
-      } else {
-        // TODO add version for noraml Java later
-        throw new Error("Error: enumerated type in Class " + cn.getSymbol() + " is not supported yet");
-      }
+      parseEnumDecl(cn,enumnode);
     }
     ParseNode flagnode=pn.getChild("flag");
     if (flagnode!=null) {
@@ -626,7 +604,7 @@ public class BuildIR {
   private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
     ParseNode mn=pn.getChild("modifier");
     Modifiers m=parseModifiersList(mn);
-    if((state.MGC) && cn.isInterface()) {
+    if(cn.isInterface()) {
       // TODO add version for normal Java later
       // Can only be PUBLIC or STATIC or FINAL
       if((m.isAbstract()) || (m.isAtomic()) || (m.isNative()) 
@@ -658,7 +636,7 @@ public class BuildIR {
       ExpressionNode en=null;
       if (epn!=null) {
         en=parseExpression(epn.getFirstChild());
-        if(state.MGC && m.isStatic()) {
+        if(m.isStatic()) {
           // for static field, the initializer should be considered as a 
           // static block
           boolean isfirst = false;
@@ -786,7 +764,7 @@ public class BuildIR {
        con.addArgument((ExpressionNode)args.get(i));
       }
       return con;
-    } if (isNode(pn,"createarray2") && state.MGC) {
+    } if (isNode(pn,"createarray2")) {
       TypeDescriptor td=parseTypeDescriptor(pn);
       int num=0;
       if (pn.getChild("dims_opt").getLiteral()!=null)
@@ -860,10 +838,10 @@ public class BuildIR {
     } else if (isNode(pn, "array_initializer")) {  
       Vector initializers=parseVariableInitializerList(pn);
       return new ArrayInitializerNode(initializers);
-    } else if (isNode(pn, "class_type") && state.MGC) {
+    } else if (isNode(pn, "class_type")) {
       TypeDescriptor td=parseTypeDescriptor(pn);
       return new ClassTypeNode(td);
-    } else if (isNode(pn, "empty") && state.MGC) {
+    } else if (isNode(pn, "empty")) {
       return null;
     } else {
       System.out.println("---------------------");
@@ -1121,11 +1099,11 @@ public class BuildIR {
       blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
                                               parseSingleBlock(pn.getChild("statement").getFirstChild()),
                                               pn.getChild("else_statement")!=null ? parseSingleBlock(pn.getChild("else_statement").getFirstChild()) : null));
-    } else if ((state.MGC) && (isNode(pn,"switch_statement"))) {
+    } else if (isNode(pn,"switch_statement")) {
       // TODO add version for normal Java later
       blockstatements.add(new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
           parseSingleBlock(pn.getChild("statement").getFirstChild())));
-    } else if ((state.MGC) && (isNode(pn,"switch_block_list"))) {
+    } else if (isNode(pn,"switch_block_list")) {
       // TODO add version for normal Java later
       ParseNodeVector pnv=pn.getChildren();
       for(int i=0; i<pnv.size(); i++) {
@@ -1149,7 +1127,7 @@ public class BuildIR {
           
         }
       }
-    } else if (state.MGC && isNode(pn, "trycatchstatement")) {
+    } else if (isNode(pn, "trycatchstatement")) {
       // TODO add version for normal Java later
       // Do not fully support exceptions now. Only make sure that if there are no
       // exceptions thrown, the execution is right
index 97dec032ed97e272bbe94ef97fb2fa0174f78ea5..b9021ab23811727d70f6c72a8f1adf053c3e28e6 100644 (file)
@@ -42,20 +42,17 @@ public class SemanticCheck {
        cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
        cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
       }
-      if(state.MGC) {
-        // TODO add version for normal Java later
-        // Link together Field, Method tables do classes inherit these from 
-        // their ancestor interfaces
-        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());
-        }
+      // Link together Field, Method tables do classes inherit these from 
+      // their ancestor interfaces
+      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());
       }
       
       /* Check to see that fields are well typed */
@@ -244,15 +241,13 @@ public class SemanticCheck {
   }
 
   public void checkMethod(ClassDescriptor cd, MethodDescriptor md) {
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      /* Check for abstract methods */
-      if(md.isAbstract()) {
-        if(!cd.isAbstract() && !cd.isInterface()) {
-          throw new Error("Error! The non-abstract Class " + cd.getSymbol() + " contains an abstract method " + md.getSymbol());
-        }
+    /* Check for abstract methods */
+    if(md.isAbstract()) {
+      if(!cd.isAbstract() && !cd.isInterface()) {
+       throw new Error("Error! The non-abstract Class " + cd.getSymbol() + " contains an abstract method " + md.getSymbol());
       }
     }
+
     /* Check return type */
     if (!md.isConstructor() && !md.isStaticBlock())
       if (!md.getReturnType().isVoid())
@@ -604,8 +599,7 @@ public class SemanticCheck {
       fd=FieldDescriptor.arrayLength;
     else
       fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
-    if(state.MGC) {
-      // TODO add version for normal Java later
+
     if(ltd.isClassNameRef()) {
       // the field access is using a class name directly
       if(ltd.getClassDesc().isEnum()) {
@@ -626,7 +620,7 @@ public class SemanticCheck {
         throw new Error("Dereference of the non-static field "+ fieldname + " in "+fan.printNode(0)+" in "+md);
       }
     } 
-    }
+
     if (fd==null)
       throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
 
@@ -727,8 +721,6 @@ public class SemanticCheck {
       }
       Descriptor d=(Descriptor)nametable.get(varname);
       if (d==null) {
-        if(state.MGC) {
-          // TODO add version for normal Java later
         ClassDescriptor cd = null;
         if(((MethodDescriptor)md).isStaticBlock()) {
           // this is a static block, all the accessed fields should be static field
@@ -779,9 +771,6 @@ public class SemanticCheck {
             throw new Error("Name "+varname+" undefined in: "+md);
           }
         }
-        } else {
-          throw new Error("Name "+varname+" undefined in: "+md);
-        }
       }
       if (d instanceof VarDescriptor) {
        nn.setVar(d);
@@ -1016,7 +1005,7 @@ public class SemanticCheck {
       throw new Error(typetolookin + " isn't a "+td);
     
     /* Check Array Initializers */
-    if(state.MGC && (con.getArrayInitializer() != null)) {
+    if((con.getArrayInitializer() != null)) {
       checkArrayInitializerNode(md, nametable, con.getArrayInitializer(), td);
     }
 
@@ -1084,7 +1073,7 @@ NextMethod:
            else if (currmd.isGlobal()&&bestmd.isGlobal())
              throw new Error();
          } else if (!typeutil.isMoreSpecific(bestmd, currmd)) {
-           throw new Error("No method is most specific");
+           throw new Error("No method is most specific:"+bestmd+" and "+currmd);
          }
 
          /* Is this more specific than bestmd */
@@ -1133,17 +1122,15 @@ NextMethod:
        and get types for expressions*/
 
     boolean isstatic = false;
-    if(state.MGC) {
-      if((md instanceof MethodDescriptor) && ((MethodDescriptor)md).isStatic()) {
-        isstatic = true;
-      }
+    if((md instanceof MethodDescriptor) && ((MethodDescriptor)md).isStatic()) {
+      isstatic = true;
     }
     TypeDescriptor[] tdarray=new TypeDescriptor[min.numArgs()];
     for(int i=0; i<min.numArgs(); i++) {
       ExpressionNode en=min.getArg(i);
       checkExpressionNode(md,nametable,en,null);
       tdarray[i]=en.getType();
-      if(state.MGC && en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
+      if(en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
         tdarray[i] = new TypeDescriptor(TypeDescriptor.INT);
       }
     }
@@ -1171,40 +1158,27 @@ NextMethod:
        checkExpressionNode(md, nametable, min.getExpression(), null);
        typetolookin=min.getExpression().getType();
       } else {
-        if(state.MGC) {
-          if(!min.getBaseName().getSymbol().equals("System.out")) {
-            ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName());
-            checkExpressionNode(md, nametable, nn, null);
-            typetolookin = nn.getType();
-            if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
-                && (((NameNode)nn).getVar() == null) && (((NameNode)nn).getExpression() == null))) {
-              // this is not a pure class name, need to add to 
-              min.setExpression(nn);
-            }
-          } else {
-            //we have a type
-            ClassDescriptor cd = null;
-            //if (min.getBaseName().getSymbol().equals("System.out"))
-            cd=getClass("System");
-            /*else {
-            cd=getClass(min.getBaseName().getSymbol());
-          }*/
-            if (cd==null)
-              throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
-            typetolookin=new TypeDescriptor(cd);
-          }
-        } else {
-          // we have a type
-          ClassDescriptor cd = null;
-          if (min.getBaseName().getSymbol().equals("System.out"))
-            cd=getClass("System");
-          else {
+       if(!min.getBaseName().getSymbol().equals("System.out")) {
+         ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName());
+         checkExpressionNode(md, nametable, nn, null);
+         typetolookin = nn.getType();
+         if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
+              && (((NameNode)nn).getVar() == null) && (((NameNode)nn).getExpression() == null))) {
+           // this is not a pure class name, need to add to 
+           min.setExpression(nn);
+         }
+       } else {
+         //we have a type
+         ClassDescriptor cd = null;
+         //if (min.getBaseName().getSymbol().equals("System.out"))
+         cd=getClass("System");
+         /*else {
             cd=getClass(min.getBaseName().getSymbol());
-          }
-          if (cd==null)
-            throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
-          typetolookin=new TypeDescriptor(cd);
-        }
+           }*/
+         if (cd==null)
+           throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
+         typetolookin=new TypeDescriptor(cd);
+       }
       }
     } else if ((md instanceof MethodDescriptor)&&min.getMethodName().equals("super")) {
       ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
@@ -1231,12 +1205,12 @@ NextMethod:
        continue;
       for(int i=0; i<min.numArgs(); i++) {
        if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
-      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;
-      }
+         if(((!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)
@@ -1245,7 +1219,7 @@ NextMethod:
        if (typeutil.isMoreSpecific(currmd,bestmd)) {
          bestmd=currmd;
        } else if (!typeutil.isMoreSpecific(bestmd, currmd))
-         throw new Error("No method is most specific");
+         throw new Error("No method is most specific:"+bestmd+" and "+currmd);
 
        /* Is this more specific than bestmd */
       }
@@ -1265,29 +1239,27 @@ NextMethod:
       }
     }
     
-    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);
-        }
+    /* 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);
       }
     }
   }
index 3cd80b8629233d276600d9e06dd1c2c08157035c..c55768f0e570467193c492e495b8893007e7cae7 100644 (file)
@@ -150,7 +150,7 @@ public class TypeUtil {
       throw new Error();
     for(int i=0; i<md1.numParameters(); i++) {
       if (!this.isSuperorType(md2.getParamType(i), md1.getParamType(i))) {
-        if(state.MGC && ((!md1.getParamType(i).isArray() && 
+        if(((!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
@@ -214,16 +214,15 @@ NextMethod:
       ClassDescriptor cd=(ClassDescriptor)classit.next();
       ClassDescriptor tmp=cd.getSuperDesc();
       
-      if(state.MGC) {
-        // TODO add version for normal Java later
-        // check tmp's interface ancestors
-        Iterator it_sifs = cd.getSuperInterfaces();
-        while(it_sifs.hasNext()) {
-          ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
-          if(!tovisit.contains(cdt)){
-            tovisit.add(cdt);
-          }
-        }
+      // check tmp's interface ancestors
+      {
+       Iterator it_sifs = cd.getSuperInterfaces();
+       while(it_sifs.hasNext()) {
+         ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
+         if(!tovisit.contains(cdt)){
+           tovisit.add(cdt);
+         }
+       }
       }
 
       while(tmp!=null) {
@@ -231,43 +230,38 @@ NextMethod:
           subclasstable.put(tmp,new HashSet());
         HashSet hs=(HashSet)subclasstable.get(tmp);
         hs.add(cd);
-        if(state.MGC) {
-          // TODO add version for normal Java later
-          // check tmp's interface ancestors
-          Iterator it_sifs = tmp.getSuperInterfaces();
-          while(it_sifs.hasNext()) {
-            ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
-            if(!tovisit.contains(cdt)){
-              tovisit.add(cdt);
-            }
-          }
-        }
+       // check tmp's interface ancestors
+       Iterator it_sifs = tmp.getSuperInterfaces();
+       while(it_sifs.hasNext()) {
+         ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
+         if(!tovisit.contains(cdt)){
+           tovisit.add(cdt);
+         }
+       }
+       
         tmp=tmp.getSuperDesc();
       }
       
-      if(state.MGC) {
-        // TODO add version for normal Java later
-        while(!tovisit.isEmpty()) {
-          ClassDescriptor sif = (ClassDescriptor)tovisit.iterator().next();
-          tovisit.remove(sif);
+      while(!tovisit.isEmpty()) {
+       ClassDescriptor sif = (ClassDescriptor)tovisit.iterator().next();
+       tovisit.remove(sif);
+        
+       if(!visited.contains(sif)) {
+         if(!this.subclasstable.containsKey(sif)) {
+           this.subclasstable.put(sif, new HashSet());
+         }
+         HashSet hs = (HashSet)this.subclasstable/*subIFclasstable*/.get(sif);
+         hs.add(cd);
           
-          if(!visited.contains(sif)) {
-            if(!this.subclasstable.containsKey(sif)) {
-              this.subclasstable.put(sif, new HashSet());
-            }
-            HashSet hs = (HashSet)this.subclasstable/*subIFclasstable*/.get(sif);
-            hs.add(cd);
-            
-            Iterator it_sifs = sif.getSuperInterfaces();
-            while(it_sifs.hasNext()) {
-              ClassDescriptor siftmp = (ClassDescriptor)it_sifs.next();
-              if(!tovisit.contains(siftmp)){
-                tovisit.add(siftmp);
-              }
-            }
-            visited.add(sif);
-          }
-        }
+         Iterator it_sifs = sif.getSuperInterfaces();
+         while(it_sifs.hasNext()) {
+           ClassDescriptor siftmp = (ClassDescriptor)it_sifs.next();
+           if(!tovisit.contains(siftmp)){
+             tovisit.add(siftmp);
+           }
+         }
+         visited.add(sif);
+       }
       }
     }
   }
@@ -303,11 +297,10 @@ NextMethod:
   }
 
   public boolean isSuperorType(TypeDescriptor possiblesuper, TypeDescriptor cd2) {
-    if(state.MGC) {
-      if(possiblesuper.isClass() && possiblesuper.class_desc.isEnum() && cd2.isInt()) {
-        return true;
-      }
+    if(possiblesuper.isClass() && possiblesuper.class_desc.isEnum() && cd2.isInt()) {
+      return true;
     }
+
     if (possiblesuper.isOffset() || cd2.isOffset()) return true;
     //Matching type are always okay
     if (possiblesuper.equals(cd2))
@@ -414,17 +407,16 @@ NextMethod:
     HashSet tovisit=new HashSet();
     HashSet visited=new HashSet();
     
-    if(state.MGC) {
-      // TODO add version for normal Java later
+    {
       // check cd2's interface ancestors
       Iterator it_sifs = getSuperIFs(cd2).iterator();
       while(it_sifs.hasNext()) {
-        ClassDescriptor cd = (ClassDescriptor)it_sifs.next();
-        if(cd == possiblesuper) {
-          return true;
-        } else if(!tovisit.contains(cd)){
-          tovisit.add(cd);
-        }
+       ClassDescriptor cd = (ClassDescriptor)it_sifs.next();
+       if(cd == possiblesuper) {
+         return true;
+       } else if(!tovisit.contains(cd)){
+         tovisit.add(cd);
+       }
       }
     }
 
@@ -433,43 +425,36 @@ NextMethod:
       if (cd2==possiblesuper)
        return true;
       
-      if(state.MGC) {
-        // TODO add version for normal Java later
-        // check cd2's interface ancestors
-        if(cd2 != null) {
-          Iterator it_sifs = getSuperIFs(cd2).iterator();
-          while(it_sifs.hasNext()) {
-            ClassDescriptor cd = (ClassDescriptor)it_sifs.next();
-            if(cd == possiblesuper) {
-              return true;
-            } else if(!tovisit.contains(cd)){
-              tovisit.add(cd);
-            }
-          }
-        }
+      // check cd2's interface ancestors
+      if(cd2 != null) {
+       Iterator it_sifs = getSuperIFs(cd2).iterator();
+       while(it_sifs.hasNext()) {
+         ClassDescriptor cd = (ClassDescriptor)it_sifs.next();
+         if(cd == possiblesuper) {
+           return true;
+         } else if(!tovisit.contains(cd)){
+           tovisit.add(cd);
+         }
+       }
       }
     }
     
-    if(state.MGC) {
-      // TODO add version for normal Java later
-      while(!tovisit.isEmpty()) {
-        ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
-        tovisit.remove(cd);
-        
-        if(!visited.contains(cd)) {
-          Iterator it_sifs = getSuperIFs(cd).iterator();
-          while(it_sifs.hasNext()) {
-            ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
-            if(cdt == possiblesuper) {
-              return true;
-            } else if(!tovisit.contains(cdt)){
-              tovisit.add(cdt);
-            }
-          }
-          visited.add(cd);
-        }
+    while(!tovisit.isEmpty()) {
+      ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
+      tovisit.remove(cd);
+      
+      if(!visited.contains(cd)) {
+       Iterator it_sifs = getSuperIFs(cd).iterator();
+       while(it_sifs.hasNext()) {
+         ClassDescriptor cdt = (ClassDescriptor)it_sifs.next();
+         if(cdt == possiblesuper) {
+           return true;
+         } else if(!tovisit.contains(cdt)){
+           tovisit.add(cdt);
+         }
+       }
+       visited.add(cd);
       }
-        
     }
     return false;
   }
index 87abaaecc7a54fca7be52867443583df5a0a0740..efcf2c2d4303c96553037e865f972c9abf1609ab 100644 (file)
@@ -97,8 +97,7 @@ public class Virtual {
     int start=0;
     if (superdesc!=null)
       start=numberMethods(superdesc);
-    if(state.MGC) {
-      // TODO add version for normal Java later
+    {
       // check the inherited interfaces
       Iterator it_sifs = cd.getSuperInterfaces();
       while(it_sifs.hasNext()) {
@@ -122,8 +121,7 @@ public class Virtual {
             break;
           }
         }
-        if(state.MGC) {
-          // TODO add version for normal Java later
+       {
           if(!foundmatch) {
             // check if there is a matched method in inherited interfaces
             Iterator it_sifs = cd.getSuperInterfaces();