try {
if (state.SANDBOX) {
- outsandbox=new CodePrinter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true);
+ outsandbox=new CodePrinter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true);
}
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);
}
outmethod=new CodePrinter(new FileOutputStream(PREFIX+"methods.c"), true);
outvirtual=new CodePrinter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
if (state.TASK) {
- outtask=new CodePrinter(new FileOutputStream(PREFIX+"task.h"), true);
- outtaskdefs=new CodePrinter(new FileOutputStream(PREFIX+"taskdefs.c"), true);
- if (state.OPTIONAL) {
- outoptionalarrays=new CodePrinter(new FileOutputStream(PREFIX+"optionalarrays.c"), true);
- optionalheaders=new CodePrinter(new FileOutputStream(PREFIX+"optionalstruct.h"), true);
- }
+ outtask=new CodePrinter(new FileOutputStream(PREFIX+"task.h"), true);
+ outtaskdefs=new CodePrinter(new FileOutputStream(PREFIX+"taskdefs.c"), true);
+ if (state.OPTIONAL) {
+ outoptionalarrays=new CodePrinter(new FileOutputStream(PREFIX+"optionalarrays.c"), true);
+ optionalheaders=new CodePrinter(new FileOutputStream(PREFIX+"optionalstruct.h"), true);
+ }
}
if (state.structfile!=null) {
- outrepairstructs=new CodePrinter(new FileOutputStream(PREFIX+state.structfile+".struct"), true);
+ outrepairstructs=new CodePrinter(new FileOutputStream(PREFIX+state.structfile+".struct"), true);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
+
+ /* Fix field safe symbols due to shadowing */
+ FieldShadow.handleFieldShadow(state);
/* Build the virtual dispatch tables */
buildVirtualTables(outvirtual);
if (type.isPtr()) {
output.println(",");
output.print("((unsigned INTPTR)&(((struct "+cn.getSafeSymbol() +" *)0)->"+
- (fd.getClassDescriptor()==null?"":fd.getClassDescriptor().getSafeSymbol())+fd.getSafeSymbol()+"))");
+ fd.getSafeSymbol()+"))");
}
}
output.println("};");
}
if (state.MGC && fd.getType().isClass()
&& fd.getType().getClassDesc().isEnum()) {
- classdefout.println(" int " + cn.getSafeSymbol() + fd.getSafeSymbol() + ";");
+ classdefout.println(" int " + fd.getSafeSymbol() + ";");
} else if (fd.getType().isClass()||fd.getType().isArray()) {
if ((state.MGC) && (fd.isStatic())) {
// TODO add version for normal Java later
// static field
if(globaldefout != null) {
if(fd.isVolatile()) {
- globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
} else {
- globaldefout.println(" struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
}
}
- classdefout.println(" struct "+fd.getType().getSafeSymbol()+" ** "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" struct "+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";");
} else if ((state.MGC) && (fd.isVolatile())) {
// TODO add version for normal Java later
// static field
if(globaldefout != null) {
- globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+fd.getSafeSymbol()+";");
}
- classdefout.println(" struct"+fd.getType().getSafeSymbol()+" ** "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" struct"+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";");
} else {
- classdefout.println(" struct "+fd.getType().getSafeSymbol()+" * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
}
} else if ((state.MGC) && (fd.isStatic())) {
// TODO add version for normal Java later
// static field
if(globaldefout != null) {
if(fd.isVolatile()) {
- globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
} else {
- globaldefout.println(" "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
}
}
- classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
} else if ((state.MGC) && (fd.isVolatile())) {
// TODO add version for normal Java later
// static field
if(globaldefout != null) {
- globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+fd.getSafeSymbol()+";");
}
- classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
} else
- classdefout.println(" "+fd.getType().getSafeSymbol()+" "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+ classdefout.println(" "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";");
}
}
FieldDescriptor fd=(FieldDescriptor)fields.get(i);
if(fd.isStatic()) {
// static field
- output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+cn.getSafeSymbol()+fd.getSafeSymbol()+"=&(global_defs_p->"+fd.getClassDescriptor().getSafeSymbol()+fd.getSafeSymbol()+");");
+ output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+fd.getSafeSymbol()+");");
}
}
}
output.println("/* FlatOffsetNode */");
FieldDescriptor fd=fofn.getField();
output.println(generateTemp(fm, fofn.getDst(),lb)+ " = (short)(int) (&((struct "+fofn.getClassType().getSafeSymbol() +" *)0)->"+
- (fd.getClassDescriptor()==null?"":fd.getClassDescriptor().getSafeSymbol()) + fd.getSafeSymbol()+");");
+ fd.getSafeSymbol()+");");
output.println("/* offset */");
}
teststr+="&&";
teststr+="((prefptr="+basestr+")!=NULL)";
basestr="((struct "+lasttype.getSafeSymbol()+" *)prefptr)->"+
- (fd.getClassDescriptor()==null?"":fd.getClassDescriptor().getSafeSymbol())+fd.getSafeSymbol();
+ fd.getSafeSymbol();
} else {
basestr=basestr+"->"+
- (fd.getClassDescriptor()==null?"":fd.getClassDescriptor().getSafeSymbol())+fd.getSafeSymbol();
+ fd.getSafeSymbol();
maybenull=true;
}
lasttype=fd.getType();
Object desc = pp.getDescAt(i);
if(desc instanceof FieldDescriptor) {
FieldDescriptor fd=(FieldDescriptor)desc;
- newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+
- (fd.getClassDescriptor()==null?"":fd.getClassDescriptor().getSafeSymbol()) + fd.getSafeSymbol()+ "))");
+ newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+ fd.getSafeSymbol()+ "))");
lasttype=fd.getType();
} else {
newfieldoffset = "";
--- /dev/null
+package IR.Flat;
+import IR.*;
+import java.util.*;
+
+public class FieldShadow {
+ public static void handleFieldShadow(State state) {
+ Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+ HashMap<ClassDescriptor, HashMap<String,Integer>> namemap=new HashMap<ClassDescriptor,HashMap<String, Integer>>();
+ while(classit.hasNext()) {
+ ClassDescriptor cd=(ClassDescriptor)classit.next();
+ handleClass(cd, state, namemap);
+ }
+ }
+
+ private static void handleClass(ClassDescriptor cd, State state, HashMap<ClassDescriptor, HashMap<String, Integer>> namemap) {
+ if (cd.getSuperDesc()!=null&&!namemap.containsKey(cd.getSuperDesc()))
+ handleClass(cd.getSuperDesc(), state, namemap);
+ HashMap<String, Integer> supermap=cd.getSuperDesc()!=null?namemap.get(cd.getSuperDesc()):new HashMap<String, Integer>();
+
+ HashMap<String, Integer> fieldmap=new HashMap<String, Integer>();
+ namemap.put(cd, fieldmap);
+
+ for(Iterator fieldit=cd.getFields();fieldit.hasNext();) {
+ FieldDescriptor fd=(FieldDescriptor)fieldit.next();
+ if (supermap.containsKey(fd.getSymbol())) {
+ Integer oldint=supermap.get(fd.getSymbol());
+ int newint=oldint.intValue()+1;
+ supermap.put(fd.getSymbol(), new Integer(newint));
+ fd.changeSafeSymbol(newint);
+ } else {
+ supermap.put(fd.getSymbol(), new Integer(0));
+ }
+ }
+ }
+}
\ No newline at end of file