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) {
// 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 */
* 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
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);
}
}
- 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");
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
}
}
- printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+ printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs, outglobaldefsprim);
printedfieldstbl.clear();
printExtraArrayFields(outclassdefs);
if (state.ARRAYPAD) {
outclassdefs.println(" int * fses;");
}
}
- printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
+ printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs, outglobaldefsprim);
printedfieldstbl.clear();
outclassdefs.println("};\n");
}
/* 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(); ) {
/** 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)) {
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);
+ }
}
}
}
} 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) {
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()+";");
* 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;");
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;");
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);
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()+";");
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()+" * ");
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());
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()+";");
}
}
- 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);
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;");
}
// 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__={");
} 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()+" * ");
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()+" * ");
}
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()+" *) ");
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()+" *) ");
}
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()+";");
}
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 *";
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()+" ";
/* 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())+";");
}
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())+";");
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()+" * ");
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());
/* 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+"];");
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();
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());
}
}
} 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();
}
}
}
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) {
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())
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;
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)
} 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("---------------------");
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++) {
}
}
- } 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
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 */
}
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())
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()) {
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);
}
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
throw new Error("Name "+varname+" undefined in: "+md);
}
}
- } else {
- throw new Error("Name "+varname+" undefined in: "+md);
- }
}
if (d instanceof VarDescriptor) {
nn.setVar(d);
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);
}
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 */
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);
}
}
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();
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)
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 */
}
}
}
- 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);
}
}
}