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