From: <spa...@us...> - 2009-03-14 18:02:41
|
Revision: 7933 http://x10.svn.sourceforge.net/x10/?rev=7933&view=rev Author: sparksparkspark Date: 2009-03-14 18:02:38 +0000 (Sat, 14 Mar 2009) Log Message: ----------- Aggressive refactoring of c++ backend: - drop dead code - consign SPMD support to svn history Add wildcard to X10Context_c.java function to suppress warning. Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -342,7 +342,7 @@ /** * Gets a local or field of a particular name. */ - public VarInstance findVariableSilent(Name name) { + public VarInstance<?> findVariableSilent(Name name) { return super.findVariableSilent(name); } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -66,7 +66,7 @@ return new TD() { public Context enterScope(Context c) { X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - context.setinClosure(true); + context.setInClosure(); return context; } }; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -14,6 +14,7 @@ * @author igor * @author pvarma * @author nvk + * @author Dave Cunningham * @see X10Context_c */ import static polyglot.ext.x10cpp.visit.Emitter.mangled_non_method_name; @@ -25,10 +26,10 @@ import polyglot.ast.ClassMember; import polyglot.ast.Stmt; +import polyglot.ext.x10.ast.PropertyDecl; import polyglot.ext.x10.types.X10ClassDef; import polyglot.ext.x10.types.X10Context; import polyglot.ext.x10.types.X10MethodDef; -import polyglot.types.Context_c; import polyglot.types.LocalInstance; import polyglot.types.Name; import polyglot.types.TypeSystem; @@ -37,14 +38,73 @@ public class X10CPPContext_c extends polyglot.ext.x10.types.X10Context_c implements X10Context { - public X10CPPContext_c(TypeSystem ts) { - super(ts); - finish_depth = 0; - ateach_depth = 0; - inprocess = false; - mainMethod = false; - } + // The global object is fresh for each brand new instance of the context, + // but is aliased for each clone of the context (cloned via copy()). + // The only thing that belongs in here is primitive data that needs a level + // of indirection to allow aliasing after cloning. + protected static class Global { + public int closureId; + } + protected Global g = new Global(); + + public void advanceClosureId() { g.closureId++; } + public int closureId() { return g.closureId; } + protected void resetClosureId() { g.closureId = -1; } + + protected ArrayList<ClassMember> pendingStaticDecls; + protected ArrayList<PropertyDecl> classProperties; + + public List<PropertyDecl> classProperties() { return classProperties; } + public List<ClassMember> pendingStaticDecls() { return pendingStaticDecls; } + + // Here, for each new class we reset the above structures, ready for fresh accumulation of data. + public void resetStateForClass(List<PropertyDecl> props) { + assert kind == SOURCE; + pendingStaticDecls = new ArrayList<ClassMember>(); + classProperties = new ArrayList<PropertyDecl>(props); + resetClosureId(); + } + + + private String label; + public String getLabel() { return label; } + + private Stmt stmt; + public Stmt getLabeledStatement() { return stmt; } + + public void setLabel(String label, Stmt stmt) { + this.label = label; + this.stmt = stmt; + } + + + private String excVar; + public void setExceptionVar(String var) { this.excVar = var; } + public String getExceptionVar() { return excVar; } + + // used internally, shallow + protected boolean inClosure; + public void setInClosure() { inClosure = true; } + + // used externally, deep + protected boolean insideClosure; + public boolean isInsideClosure() { return insideClosure; } + public void setInsideClosure(boolean b) { insideClosure = b; } + + + public boolean hasInits = false; + + + public ClassifiedStream templateFunctions = null; + + public ArrayList<VarInstance> variables = new ArrayList<VarInstance>(); + + + public X10CPPContext_c(TypeSystem ts) { + super(ts); + } + public boolean inTemplate() { X10ClassDef cd = (X10ClassDef)currentClassDef(); // following 2 lines are needed for constraints @@ -60,226 +120,39 @@ return (!staticMethod && genericClass) || genericMethod; } - public boolean inClosure; - public boolean insideClosure; - - public ArrayList variables = new ArrayList(); - public ArrayList SPMDVars = new ArrayList(); - public ArrayList GlobalVars = new ArrayList(); - public HashSet Unbroadcastable = new HashSet(); - - public HashMap InlineMap = new HashMap(); - public HashMap RenameMap = new HashMap(); - public HashMap duplicateId = new HashMap(); - public boolean inlining; - public static String returnLabel; - public static String returnVar; - public static String lastReturnVar; - public boolean canInline; - - public static ArrayList<ClassMember> pendingStaticDecls = new ArrayList<ClassMember>(); - public static HashMap classesWithAsyncSwitches = new HashMap(); - public static HashMap classesWithArrayCopySwitches = new HashMap(); - public ArrayList classProperties = new ArrayList(); - - public HashSet warnedAbout = new HashSet(); - - public void setinClosure(boolean b) { - inClosure = b; - } - - public void setinsideClosure(boolean b) { - insideClosure = b; - } - - protected Context_c push() { - X10CPPContext_c v = (X10CPPContext_c) super.push(); - return v; - } - - static int closureId = -1; - public void incClosureId() { closureId++; } - public int closureId() { return closureId; } public void saveEnvVariableInfo(String name) { VarInstance vi = findVariableInThisScope(Name.make(name)); if (vi != null) { // found declaration - return; // local variable + // local variable (do nothing) } else if (inClosure) { - addVar(name); - return; // local variable + addVar(name); // local variable } else { // Captured Variable ((X10CPPContext_c) outer).saveEnvVariableInfo(name); } } - public void addVar(String name) { + + private VarInstance lookup(String name) { + VarInstance vi = findVariableInThisScope(Name.make(name)); + if (vi != null) return vi; + else if (outer != null) return ((X10CPPContext_c) outer).lookup(name); + else return null; + } + + private void addVar(String name) { VarInstance vi = lookup(name); boolean contains = false; - for (int i = 0; i < variables.size(); i++) { - if (((VarInstance) variables.get(i)).name().toString().equals(vi.name().toString())) { - contains = true; - break; - } - } + for (VarInstance vi2 : variables) { + // [DC]: what is wrong with vi2.equals(vi)? + if (vi2.name().toString().equals(vi.name().toString())) { + contains = true; + break; + } + } if (!contains) variables.add(vi); } - - private boolean listContains(ArrayList list, Object val) { - for (int i = 0; i < list.size(); i++) - if (val == list.get(i)) - return true; - return false; - } - - public boolean isSPMDVar(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - if (var instanceof LocalInstance && isInlineMapped(var)) - var = getInlineMapping(var); - if (listContains(SPMDVars, var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isSPMDVar(var); - return false; - } - - public void addSPMDVar(VarInstance var) { - if (isSPMDVar(var)) - return; - assert (!isSPMDVar(var)); - assert (mainMethod); - SPMDVars.add(var); - } - - public void addGlobalVar(VarInstance var, Integer id) { - if (isGlobalVar(var)) //if it is the exact same instance, then don't add. - return; - assert (mainMethod); - assert (!isGlobalVar(var)); - X10CPPContext_c outer = (X10CPPContext_c) this.outer; - // [IP] The condition below is too strict. - // We can also have global vars inside conditionals. -// assert (outer.isCode()); - assert (outer.isMainMethod()); - - // If it is a different varInstance but same name then - // rename. - if (findGlobalVarSilent(var.name().toString()) != null) { - duplicateId.put(var,id); - } - GlobalVars.add(var); - } - - public boolean isGlobalVar(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - // TODO: should we go via the inline mapping here as well? - if (GlobalVars.contains(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isGlobalVar(var); - return false; - } - - public ArrayList getGlobals() { - return GlobalVars; - } - - public VarInstance findGlobalVarSilent(String name) { - for (int i = 0; i < GlobalVars.size(); i++) { - VarInstance var = (VarInstance)GlobalVars.get(i); - if (var.name().toString().equals(name)) - return var; - } - return null; - } - - public void addUnbroadcastable(VarInstance var) { - if (isUnbroadcastable(var)) - return; - assert (mainMethod); - assert (!isUnbroadcastable(var)); - Unbroadcastable.add(var); - } - - public boolean isUnbroadcastable(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - // TODO: should we go via the inline mapping here as well? - if (Unbroadcastable.contains(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isUnbroadcastable(var); - return false; - } - - public void addInlineMapping(LocalInstance alias, LocalInstance var) { - if (isInlineMapped(alias)) - return; - assert (!isInlineMapped(alias)); - X10CPPContext_c outer = (X10CPPContext_c) this.outer; - assert (outer.isMainMethod()); - InlineMap.put(alias, var); - } - - public boolean isInlineMapped(VarInstance var) { - if (InlineMap.containsKey(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isInlineMapped(var); - return false; - } - - public LocalInstance getInlineMapping(VarInstance var) { - assert (var instanceof LocalInstance); - LocalInstance result = (LocalInstance) InlineMap.get(var); - if (result == null && outer != null) { - result = ((X10CPPContext_c) outer).getInlineMapping(var); - } - return result; - } - public Object getDuplicateId(VarInstance var) { - return duplicateId.get(var); - } - - public void addRenameMapping(VarInstance var, String newName) { - assert (inlining); - List names = (List) RenameMap.get(var); - if (names == null) - RenameMap.put(var, names = new ArrayList()); - names.add(newName); - } - - public String getCurrentName(VarInstance var) { - String D = ""; - if (insideClosure && isGlobalVar(var) && getDuplicateId(var) != null) { - D = getDuplicateId(var).toString(); - } - if (!inlining) - return mangled_non_method_name(var.name().toString() + D); - List names = getRenameMapping(var); - if (names == null) - return mangled_non_method_name(var.name().toString() + D); - return mangled_non_method_name((String) names.get(names.size()-1) + D); - } - - public List getRenameMapping(VarInstance var) { - return (List) RenameMap.get(var); - } - - public void removeRenameMapping(VarInstance var) { - RenameMap.remove(var); - } - - private VarInstance lookup(String name) { - VarInstance vi = findVariableInThisScope(Name.make(name)); - if (vi != null) return vi; - else if (outer != null) return ((X10CPPContext_c) outer).lookup(name); - else return null; - } - public void finalizeClosureInstance() { // remove all from current context. Move those pertinent to an outer // closure to the outer closure. @@ -294,117 +167,16 @@ ((X10CPPContext_c) outer).saveEnvVariableInfo(v.name().toString()); } } + + + public Object copy() { X10CPPContext_c res = (X10CPPContext_c) super.copy(); - res.variables = new ArrayList(); // or whatever the initial value is + res.variables = new ArrayList<VarInstance>(); // or whatever the initial value is res.inClosure = false; - res.InlineMap = new HashMap(); return res; } - private boolean mainMethod; - - public boolean isMainMethod() { - return mainMethod; - } - - public void setMainMethod() { - mainMethod = true; - } - - public void resetMainMethod() { - mainMethod = false; - } - - private boolean asyncInlinable; - - // this variable is set, if we are inside a loop structure or - // nested asyncs, throw statement, or conditional atomics. Q: How - // to detect if there are messages that are being initiated? - // -Krishna. - public boolean inlinableAsyncsOnly() { - return asyncInlinable; - } - - public void setInlinableAsyncsOnly() { - asyncInlinable = true; - } - - public void resetInlinableAsyncsOnly() { - asyncInlinable = false; - } - - private boolean seqCode; - - public boolean noAtEachCode() { - return seqCode; - } - - public void setAtEachCode() { - seqCode = true; - } - - public void resetAtEachCode() { - seqCode = false; - } - - public static int async_depth = 0; - - public static int finish_cnt = 0; - - public int finish_depth; - - public int ateach_depth; - - public boolean inprocess; - - public static boolean inplace0; - - // I would think that we do not need static here. - // But someone is overwriting the context and I am - // ending up having wrong labels. - // -Krishna. TODO: Fixit. - public static int nextLabel; - - private String label; - - private Stmt stmt; - - public void setLabel(String label, Stmt stmt) { - this.label = label; - this.stmt = stmt; - } - - public String getLabel() { - return label; - } - - public Stmt getLabeledStatement() { - return stmt; - } - - private String excVar; - - public boolean hasInits = false; - - public void setExceptionVar(String var) { - this.excVar = var; - } - - public String getExceptionVar() { - return excVar; - } - private static int localClassDepth; - public boolean inLocalClass(){ return localClassDepth != 0; } - public void pushInLocalClass(){ localClassDepth ++ ; } - public void popInLocalClass(){ localClassDepth--; } - - private static String selfStr; - public void setSelf(String str){ selfStr = str; }; - public void resetSelf() { selfStr = null; }; - public String Self() { return selfStr; }; - - public ClassifiedStream templateFunctions = null; } //vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -63,31 +63,7 @@ public ASTQuery(Translator tr) { this.tr = tr; } - - static final HashMap<String,String> arrayRuntimeNameToType = new HashMap<String,String>(); - static { - arrayRuntimeNameToType.put("booleanArray", "boolean"); - arrayRuntimeNameToType.put("BooleanReferenceArray", "boolean"); - arrayRuntimeNameToType.put("byteArray", "byte"); - arrayRuntimeNameToType.put("ByteReferenceArray", "byte"); - arrayRuntimeNameToType.put("charArray", "char"); - arrayRuntimeNameToType.put("CharReferenceArray", "char"); - arrayRuntimeNameToType.put("shortArray", "short"); - arrayRuntimeNameToType.put("ShortReferenceArray", "short"); - arrayRuntimeNameToType.put("intArray", "int"); - arrayRuntimeNameToType.put("IntReferenceArray", "int"); - arrayRuntimeNameToType.put("longArray", "long"); - arrayRuntimeNameToType.put("LongReferenceArray", "long"); - arrayRuntimeNameToType.put("floatArray", "float"); - arrayRuntimeNameToType.put("FloatReferenceArray", "float"); - arrayRuntimeNameToType.put("doubleArray", "double"); - arrayRuntimeNameToType.put("DoubleReferenceArray", "double"); - } - boolean isMainMethod(X10CPPContext_c context) { - return context.isMainMethod() && !context.insideClosure; - } - boolean isSyntheticField(String name) { if (name.startsWith("jlc$")) return true; return false; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -310,12 +310,6 @@ VarInstance var = (VarInstance)c.variables.get(i); if (!omitType) { Type t = var.type(); - if (c.isSPMDVar(var)) { - assert (t.isClass()); - X10ClassType ct = (X10ClassType) t; - assert (ct.typeArguments().size() == 1); - t = ct.typeArguments().get(0); - } String type = translateType(t, true); w.write(type + " "); } @@ -740,7 +734,7 @@ } void enterClosure(X10CPPContext_c c) { - c.incClosureId(); + c.advanceClosureId(); } void exitClosure(X10CPPContext_c c) { } @@ -748,10 +742,10 @@ void printExplicitTarget(Call_c n, Receiver target, X10CPPContext_c context, CodeWriter w) { if (target instanceof X10Special_c && ((X10Special_c)target).kind().equals(X10Special_c.THIS) && - (context.inlining || context.insideClosure)) + context.isInsideClosure()) { w.write(SAVED_THIS); - if (context.insideClosure) + if (context.isInsideClosure()) context.saveEnvVariableInfo(THIS); } else if (target instanceof Expr) { @@ -773,36 +767,19 @@ for (int i = 0; i < vars.size(); i++) { VarInstance var = (VarInstance)vars.get(i); Type t = var.type(); - if (c.isSPMDVar(var)) { - assert (t.isClass()); - X10ClassType ct = (X10ClassType) t; - assert (ct.typeArguments().size() == 1); - t = ct.typeArguments().get(0); - } String type = translateType(t, true); if (writable && !var.name().toString().equals(THIS)) // this is a temporary ref type = type + "&"; // FIXME: Hack to get writable args in finally closures - List names = c.getRenameMapping(var); - if (names == null) { - String name = var.name().toString(); - if (saved_this_mechanism && name.equals(THIS)) { - assert (c.inlining || c.insideClosure); // FIXME: Krishna, why did you add this test? - name = SAVED_THIS; - } - else { - if (c.isGlobalVar(var) && c.getDuplicateId(var) != null) - name += c.getDuplicateId(var); - name = mangled_non_method_name(name); - } - w.write(type + " " + name + ";"); - w.newline(); - } else { - for (Iterator n = names.iterator(); n.hasNext(); ) { - String name = (String) n.next(); - w.write(type + " " + name + ";"); - w.newline(); - } + String name = var.name().toString(); + if (saved_this_mechanism && name.equals(THIS)) { + assert (c.isInsideClosure()); // FIXME: Krishna, why did you add this test? + name = SAVED_THIS; } + else { + name = mangled_non_method_name(name); + } + w.write(type + " " + name + ";"); + w.newline(); } } @@ -1038,10 +1015,7 @@ private void prettyPrint(Object o, Translator tr, CodeWriter w) { if (o instanceof Node) { Node n = (Node) o; - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - ((X10CPPTranslator) tr).setContext(n.del().enterScope(context)); - n.del().translate(w, tr); - ((X10CPPTranslator) tr).setContext(context); + tr.print(null, n, w); } else if (o instanceof Type) { w.write(translateType((Type)o, true)); } else if (o != null) { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -136,6 +136,7 @@ import polyglot.ext.x10.ast.LocalTypeDef_c; import polyglot.ext.x10.ast.Next_c; import polyglot.ext.x10.ast.ParExpr_c; +import polyglot.ext.x10.ast.PropertyDecl; import polyglot.ext.x10.ast.PropertyDecl_c; import polyglot.ext.x10.ast.RegionMaker_c; import polyglot.ext.x10.ast.SettableAssign_c; @@ -280,7 +281,7 @@ private boolean extractGenericStaticDecls(X10ClassDef cd, ClassifiedStream w) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); - if (context.pendingStaticDecls.size() == 0) + if (context.pendingStaticDecls().size() == 0) return false; boolean hasInits = false; w.write("template <> class "); @@ -291,7 +292,7 @@ w.newline(4); w.begin(0); w.write("public:"); w.newline(); // First process all classes - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof ClassDecl_c) { assert false : "nested class alert! "+cd.position(); ClassDecl_c cdecl = (ClassDecl_c) dec; @@ -310,7 +311,7 @@ } } // Then process all fields and methods - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof FieldDecl_c) { FieldDecl_c fd = (FieldDecl_c) dec; ((X10CPPTranslator)tr).setContext(fd.enterScope(context)); // FIXME @@ -360,7 +361,7 @@ X10CPPContext_c context = (X10CPPContext_c) tr.context(); ArrayList<FieldDecl_c> inits = new ArrayList<FieldDecl_c>(); String container = translate_mangled_FQN(cd.fullName().toString())+voidTemplateInstantiation(cd.typeParameters().size()); - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof FieldDecl_c) { FieldDecl_c fd = (FieldDecl_c) dec; ((X10CPPTranslator)tr).setContext(fd.enterScope(context)); // FIXME @@ -422,45 +423,6 @@ } else if (dec instanceof X10ClassDecl_c) { assert (false) : ("Nested class alert!"); - X10ClassDecl_c cdecl = (X10ClassDecl_c) dec; - ((X10CPPTranslator)tr).setContext(cdecl.enterScope(context)); // FIXME - - X10ClassDef def = (X10ClassDef) cdecl.classDef(); - if (getCppRep(def) != null) { - // emit no c++ code as this is a native rep class - continue; - } - ClassifiedStream h = sw.header(); - emitter.printTemplateSignature(((X10ClassType)def.asType()).typeArguments(), h); - h.write("class "+container+"::"+Emitter.mangled_non_method_name(def.name().toString())); - h.allowBreak(0, " "); - // [DC]: the following function adds the : public B, public C etc - emitter.printInheritance(cdecl, h ,tr); - h.allowBreak(0, " "); - - context.setinsideClosure(false); - context.hasInits = false; - - assert (def.isNested()); - if (!def.flags().isStatic()) - throw new InternalCompilerError("Instance Inner classes not supported"); - - ArrayList<ClassMember> opsd = context.pendingStaticDecls; - context.pendingStaticDecls = new ArrayList<ClassMember>(); - - cdecl.print(cdecl.body(), sw, tr); - - processNestedClasses(cdecl); - - if (extractGenericStaticDecls((X10ClassDef)cdecl.classDef(), h)) { - extractGenericStaticInits((X10ClassDef)cdecl.classDef()); - } - - context.pendingStaticDecls = opsd; - - h.newline(); - - ((X10CPPTranslator)tr).setContext(context); // FIXME } } if (inits.size() > 0) { @@ -584,23 +546,6 @@ return false; } - private void processNestedClasses(X10ClassDecl_c n) { - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - boolean generic = ((X10ClassDef)n.classDef()).typeParameters().size() != 0; - for (Iterator i = n.body().members().iterator(); i.hasNext(); ) { - ClassMember member = (ClassMember) i.next(); - if (member instanceof ClassDecl_c) { - X10ClassDecl_c cd = (X10ClassDecl_c) member; - if (generic && cd.flags().flags().isStatic()) { - context.pendingStaticDecls.add(cd); - continue; - } - processClass(cd); - } - } - } - - private void extractAllClassTypes(Type t, List<ClassType> types, Set<ClassType> dupes) { X10TypeSystem xts = (X10TypeSystem) t.typeSystem(); t = xts.expandMacros(t); @@ -654,8 +599,6 @@ void processClass(X10ClassDecl_c n) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); - assert (!context.inLocalClass()) : ("Local classes should have been removed earlier"); - X10ClassDef def = (X10ClassDef) n.classDef(); if (getCppRep(def) != null) { @@ -682,7 +625,7 @@ ClassifiedStream z = sw.getNewStream(StreamWrapper.Header, false); sw.set(h, w); - context.setinsideClosure(false); + context.setInsideClosure(false); context.hasInits = false; // Write the header for the class @@ -842,9 +785,21 @@ w.forceNewline(0); } + /* [DC] since we don't have nested classes anymore, processClass is never called from + * inside processClass, so this stack device is no-longer needed. ArrayList<ClassMember> opsd = context.pendingStaticDecls; - context.pendingStaticDecls = new ArrayList<ClassMember>(); + assert opsd.isEmpty() : "Should not occur without nested classes"; + */ + /* + * Ideally, classProperties would be added to the child context + * that will be created for processing the classBody, but there + * is no way to do that. So instead we add and remove the properties + * in the global context, for each class. + */ + context.resetStateForClass(n.properties()); + + if (def.typeParameters().size() != 0) { // Pre-declare the void specialization for statics emitter.printTemplateSignature(((X10ClassType)def.asType()).typeArguments(), h); @@ -862,28 +817,20 @@ emitter.printHeader(n, h, tr, false); h.allowBreak(0, " "); - /* - * Ideally, classProperties would be added to the child context - * that will be created for processing the classBody, but there - * is no way to do that. So instead we add and remove the properties - * around the call to visiting the class body. - */ - context.classProperties.addAll(n.properties()); n.print(n.body(), sw, tr); - context.classProperties.clear(); ((X10CPPTranslator)tr).setContext(n.enterChildScope(n.body(), context)); // FIXME /* * TODO: [IP] Add comment about dependences between the method calls. */ - processNestedClasses(n); if (extractGenericStaticDecls(def, h)) { extractGenericStaticInits(def); } ((X10CPPTranslator)tr).setContext(context); // FIXME - context.pendingStaticDecls = opsd; + // [DC] disabled, see (commented out) definition of opsd above for details + // context.pendingStaticDecls = opsd; h.newline(); @@ -1032,11 +979,11 @@ h.write("public:"); h.newline(); emitter.printRTT(currentClass, h); sw.begin(0); - for (Iterator pi = context.classProperties.iterator(); pi.hasNext();) { - PropertyDecl_c p = (PropertyDecl_c) pi.next(); + for (PropertyDecl p : context.classProperties()) { n.print(p, sw, tr); } - context.classProperties = new ArrayList(); + // [DC] without inner classes i see no reason to reset this here + //context.classProperties = new ArrayList(); List<ClassMember> members = n.members(); if (!members.isEmpty()) { @@ -1244,7 +1191,6 @@ emitter.generateSerializationMethods(currentClass, sw); } - context.resetMainMethod(); } h.end(); @@ -1296,7 +1242,7 @@ X10MethodInstance mi = (X10MethodInstance) def.asInstance(); X10ClassType container = (X10ClassType) mi.container(); if ((container.x10Def().typeParameters().size() != 0) && flags.isStatic()) { - context.pendingStaticDecls.add(dec); + context.pendingStaticDecls().add(dec); return; } if (query.isMainMethod(dec)) @@ -1489,7 +1435,7 @@ if ((((X10ClassDef)((X10ClassType)dec.fieldDef().asInstance().container()).def()).typeParameters().size() != 0) && dec.flags().flags().isStatic()) { - context.pendingStaticDecls.add(dec); + context.pendingStaticDecls().add(dec); return; } @@ -1948,7 +1894,7 @@ Position pos = a.position(); a = nf.X10Cast(pos, nf.CanonicalTypeNode(pos, fType), a, X10Cast.ConversionType.CHECKED).type(fType); - } + } return a; } @@ -2200,9 +2146,9 @@ public void visit(Local_c n) { X10CPPContext_c c = (X10CPPContext_c) tr.context(); LocalInstance var = n.localInstance(); - if (c.insideClosure) + if (c.isInsideClosure()) c.saveEnvVariableInfo(n.name().toString()); - sw.write(c.getCurrentName(var)); + sw.write(mangled_non_method_name(var.name().toString())); } public void visit(New_c n) { @@ -2382,7 +2328,7 @@ X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); X10CPPContext_c c = (X10CPPContext_c) context.pushBlock(); - c.setinClosure(true); + c.setInClosure(); ((X10CPPTranslator)tr).setContext(c); // FIXME emitter.enterClosure(c); @@ -2411,7 +2357,7 @@ String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); - c.setinsideClosure(true); + c.setInsideClosure(true); int id = getConstructorId(c); @@ -2861,7 +2807,7 @@ // n.qualifier()+" "+n.kind()+" "+n.position().nameAndLineString(); if (n.kind().equals(X10Special_c.THIS)) { - if (context.insideClosure) { + if (context.isInsideClosure()) { sw.write(SAVED_THIS); context.saveEnvVariableInfo(THIS); } else { @@ -2870,9 +2816,10 @@ } else if (n.kind().equals(X10Special_c.SUPER)) { sw.write(emitter.translateType(context.currentClass().superClass())); } else if (n.isSelf()) { + assert false: "I do not believe we ever visit over constraints."; // FIXME: Why are we printing the string "self"? // Confirm with Igor. [Krishna] - sw.write((context.Self() == null)? "self":context.Self()); + //sw.write((context.Self() == null)? "self":context.Self()); } else assert (false) : n.kind(); } @@ -2915,7 +2862,7 @@ String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); - c.setinsideClosure(true); + c.setInsideClosure(true); int id = getConstructorId(c); @@ -3116,7 +3063,7 @@ String name = var.name().toString(); if (!name.equals(THIS)) name = mangled_non_method_name(name); - else if (((X10CPPContext_c)c.pop()).insideClosure) // FIXME: hack + else if (((X10CPPContext_c)c.pop()).isInsideClosure()) // FIXME: hack name = SAVED_THIS; sw.write(name); } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -287,6 +287,8 @@ sw.getNewStream(StreamWrapper.Closures, true); // [IP] FIXME: This hack is to ensure the .cc is always generated. sw.getNewStream(StreamWrapper.CC, true); + // [DC] TODO: This hack is to ensure the .h is always generated. + sw.getNewStream(StreamWrapper.Header, true); opfPath = tf.outputName(pkg, decl.name().toString()); assert (!opfPath.endsWith("$")); if (!opfPath.endsWith("$")) outputFiles.add(opfPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |