Revision: 10875
http://x10.svn.sourceforge.net/x10/?rev=10875&view=rev
Author: vj0
Date: 2009-07-26 14:00:44 +0000 (Sun, 26 Jul 2009)
Log Message:
-----------
Factored out Emitter from X10PrettyPrinter. (I remember doing the same thing for the C++ code generator, so this must not have been propagated back to the Java code generator.)
X10PrettyPrinterVisitor now simply has visitors for each of the Nodes. If the code to be generated for a node is simple, it can be generated directly in the body of the visit method. Otherwise methods on Emitter should be called. Emitter provides two kinds of services (perhaps these should be factored out). First it provides auxiliary routines on Nodes to determine if they possess certain properties which are of interest when generating code. Second, they contain various kinds of emitters (pieces of code which emit code to the printer). So emitters are the lowest layer of the code generator.
Modified Paths:
--------------
trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10Loop.java
trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java
Added Paths:
-----------
trunk/x10.compiler.p3/src/x10/emitter/
trunk/x10.compiler.p3/src/x10/emitter/Emitter.java
trunk/x10.compiler.p3/src/x10/emitter/Expander.java
trunk/x10.compiler.p3/src/x10/emitter/Inline.java
trunk/x10.compiler.p3/src/x10/emitter/Join.java
trunk/x10.compiler.p3/src/x10/emitter/Loop.java
trunk/x10.compiler.p3/src/x10/emitter/RuntimeTypeExpander.java
trunk/x10.compiler.p3/src/x10/emitter/Template.java
trunk/x10.compiler.p3/src/x10/emitter/TypeExpander.java
Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10Loop.java
===================================================================
--- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10Loop.java 2009-07-25 01:16:39 UTC (rev 10874)
+++ trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10Loop.java 2009-07-26 14:00:44 UTC (rev 10875)
@@ -28,7 +28,7 @@
X10Loop formal(Formal formal);
Expr domain();
X10Loop domain(Expr domain);
- List/*<Stmt>*/ locals();
- X10Loop locals(List/*<Stmt>*/ locals);
+ List<Stmt> locals();
+ X10Loop locals(List<Stmt> locals);
}
Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java
===================================================================
--- trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java 2009-07-25 01:16:39 UTC (rev 10874)
+++ trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java 2009-07-26 14:00:44 UTC (rev 10875)
@@ -15,7 +15,6 @@
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -106,7 +105,6 @@
import polyglot.ext.x10.extension.X10Ext;
import polyglot.ext.x10.query.QueryEngine;
import polyglot.ext.x10.types.ClosureType;
-import polyglot.ext.x10.types.ConstrainedType;
import polyglot.ext.x10.types.MacroType;
import polyglot.ext.x10.types.ParameterType;
import polyglot.ext.x10.types.X10ArraysMixin;
@@ -160,6 +158,14 @@
import x10.constraint.XNot_c;
import x10.constraint.XTerm;
import x10.constraint.XTerms;
+import x10.emitter.Emitter;
+import x10.emitter.Expander;
+import x10.emitter.Inline;
+import x10.emitter.Join;
+import x10.emitter.Loop;
+import x10.emitter.RuntimeTypeExpander;
+import x10.emitter.Template;
+import x10.emitter.TypeExpander;
/**
@@ -170,20 +176,27 @@
* @author Christian Grothoff
* @author Igor Peshansky (template classes)
* @author Rajkishore Barik 26th Aug 2006 (added loop optimizations)
+ * @author vj Refactored Emitter out.
*/
public class X10PrettyPrinterVisitor extends X10DelegatingVisitor {
- public static final String X10_RUNTIME_TYPE_CLASS = "x10.types.Type";
- public static final String X10_FUN_CLASS_PREFIX = "x10.core.fun.Fun";
- public static final String X10_RUNTIME_CLASS = "x10.runtime.impl.java.Runtime";
+ public static final String X10_RUNTIME_TYPE_CLASS = "x10.types.Type";
+ public static final String X10_FUN_CLASS_PREFIX = "x10.core.fun.Fun";
+ public static final String X10_RUNTIME_CLASS = "x10.runtime.impl.java.Runtime";
- protected static final boolean serialize_runtime_constraints = false;
-
- private final CodeWriter w;
- private final Translator tr;
+ public static final int PRINT_TYPE_PARAMS = 1;
+ public static final int BOX_PRIMITIVES = 2;
+ public static final int NO_VARIANCE = 4;
+ public static final int NO_QUALIFIER = 8;
+ public static final boolean serialize_runtime_constraints = false;
+
+ final public CodeWriter w;
+ final public Translator tr;
+ final public Emitter er;
+
private static int nextId_;
/* to provide a unique name for local variables introduce in the templates */
- private static Integer getUniqueId_() {
+ public static Integer getUniqueId_() {
return new Integer(nextId_++);
}
@@ -194,1783 +207,707 @@
public X10PrettyPrinterVisitor(CodeWriter w, Translator tr) {
this.w = w;
this.tr = tr;
+ this.er = new Emitter(w,tr);
}
public void visit(Node n) {
- // Don't call through del; that would be recursive.
+ // Don't call through del; that would be recursive.
n.translate(w, tr);
}
-
- public static String mangleIdentifier(String n) {
- // Workaround an assertion failure in Name.make.
- if (! StringUtil.isNameShort(n))
- return n;
- return mangleIdentifier(Name.make(n)).toString();
- }
-
- public static Name mangleIdentifier(Name n) {
- Map<Name,Name> map = new HashMap<Name,Name>();
- map.put(X10Cast_c.operator_as, Name.make("$convert"));
- map.put(X10Cast_c.implicit_operator_as, Name.make("$implicit_convert"));
- map.put(Name.make("set"), Name.make("set"));
- map.put(Name.make("apply"), Name.make("apply"));
- map.put(Name.make("operator+"), Name.make("$plus"));
- map.put(Name.make("operator-"), Name.make("$minus"));
- map.put(Name.make("operator*"), Name.make("$times"));
- map.put(Name.make("operator/"), Name.make("$over"));
- map.put(Name.make("operator%"), Name.make("$percent"));
- map.put(Name.make("operator<"), Name.make("$lt"));
- map.put(Name.make("operator>"), Name.make("$gt"));
- map.put(Name.make("operator<="), Name.make("$le"));
- map.put(Name.make("operator>="), Name.make("$ge"));
- map.put(Name.make("operator<<"), Name.make("$left"));
- map.put(Name.make("operator>>"), Name.make("$right"));
- map.put(Name.make("operator>>>"), Name.make("$unsigned_right"));
- map.put(Name.make("operator&"), Name.make("$ampersand"));
- map.put(Name.make("operator|"), Name.make("$bar"));
- map.put(Name.make("operator^"), Name.make("$caret"));
- map.put(Name.make("operator~"), Name.make("$tilde"));
- map.put(Name.make("operator&&"), Name.make("$and"));
- map.put(Name.make("operator||"), Name.make("$or"));
- map.put(Name.make("operator!"), Name.make("$not"));
- map.put(Name.make("operator=="), Name.make("$equalsequals"));
- map.put(Name.make("operator!="), Name.make("$ne"));
- map.put(Name.make("inverse_operator+"), Name.make("$inv_plus"));
- map.put(Name.make("inverse_operator-"), Name.make("$inv_minus"));
- map.put(Name.make("inverse_operator*"), Name.make("$inv_times"));
- map.put(Name.make("inverse_operator/"), Name.make("$inv_over"));
- map.put(Name.make("inverse_operator%"), Name.make("$inv_percent"));
- map.put(Name.make("inverse_operator<"), Name.make("$inv_lt"));
- map.put(Name.make("inverse_operator>"), Name.make("$inv_gt"));
- map.put(Name.make("inverse_operator<="), Name.make("$inv_le"));
- map.put(Name.make("inverse_operator>="), Name.make("$inv_ge"));
- map.put(Name.make("inverse_operator<<"), Name.make("$inv_left"));
- map.put(Name.make("inverse_operator>>"), Name.make("$inv_right"));
- map.put(Name.make("inverse_operator>>>"), Name.make("$inv_unsigned_right"));
- map.put(Name.make("inverse_operator&"), Name.make("$inv_ampersand"));
- map.put(Name.make("inverse_operator|"), Name.make("$inv_bar"));
- map.put(Name.make("inverse_operator^"), Name.make("$inv_caret"));
- map.put(Name.make("inverse_operator~"), Name.make("$inv_tilde"));
- map.put(Name.make("inverse_operator&&"), Name.make("$inv_and"));
- map.put(Name.make("inverse_operator||"), Name.make("$inv_or"));
- map.put(Name.make("inverse_operator!"), Name.make("$inv_not"));
- map.put(Name.make("inverse_operator=="), Name.make("$inv_equalsequals"));
- map.put(Name.make("inverse_operator!="), Name.make("$inv_ne"));
- Name o = map.get(n);
- if (o != null)
- return o;
- return n;
- }
-
public void visit(LocalAssign_c n) {
- Local l = n.local();
- TypeSystem ts = tr.typeSystem();
- if (n.operator() == Assign.ASSIGN || l.type().isNumeric() || l.type().isBoolean() || l.type().isSubtype(ts.String(), tr.context())) {
- tr.print(n, l, w);
- w.write(" ");
- w.write(n.operator().toString());
- w.write(" ");
- coerce(n, n.right(), l.type());
- }
- else {
- Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
- Name methodName = X10Binary_c.binaryMethodName(op);
- tr.print(n, l, w);
- w.write(" = ");
- tr.print(n, l, w);
- w.write(".");
- w.write(mangleIdentifier(methodName).toString());
- w.write("(");
- tr.print(n, n.right(), w);
- w.write(")");
- }
+ Local l = n.local();
+ TypeSystem ts = tr.typeSystem();
+ if (n.operator() == Assign.ASSIGN || l.type().isNumeric() || l.type().isBoolean() || l.type().isSubtype(ts.String(), tr.context())) {
+ tr.print(n, l, w);
+ w.write(" ");
+ w.write(n.operator().toString());
+ w.write(" ");
+ er.coerce(n, n.right(), l.type());
+ }
+ else {
+ Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
+ Name methodName = X10Binary_c.binaryMethodName(op);
+ tr.print(n, l, w);
+ w.write(" = ");
+ tr.print(n, l, w);
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(methodName).toString());
+ w.write("(");
+ tr.print(n, n.right(), w);
+ w.write(")");
+ }
}
- public void visit(FieldAssign_c n) {
- Type t = n.fieldInstance().type();
+ public void visit(FieldAssign_c n) {
+ Type t = n.fieldInstance().type();
- TypeSystem ts = tr.typeSystem();
- if (n.operator() == Assign.ASSIGN || t.isNumeric() || t.isBoolean() || t.isSubtype(ts.String(), tr.context())) {
- tr.print(n, n.target(), w);
- w.write(".");
- w.write(mangleIdentifier(n.name().id()).toString());
- w.write(" ");
- w.write(n.operator().toString());
- w.write(" ");
- coerce(n, n.right(), n.fieldInstance().type());
- }
- else if (n.target() instanceof TypeNode || n.target() instanceof Local || n.target() instanceof Lit) {
- // target has no side effects--evaluate it more than once
- Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
- Name methodName = X10Binary_c.binaryMethodName(op);
- tr.print(n, n.target(), w);
- w.write(".");
- w.write(mangleIdentifier(n.name().id()).toString());
- w.write(" ");
- w.write(" = ");
- tr.print(n, n.target(), w);
- w.write(".");
- w.write(mangleIdentifier(n.name().id()).toString());
- w.write(".");
- w.write(mangleIdentifier(methodName).toString());
- w.write("(");
- tr.print(n, n.right(), w);
- w.write(")");
- }
- else {
- // x.f += e
- // -->
- // new Object() { T eval(R target, T right) { return (target.f = target.f.add(right)); } }.eval(x, e)
- Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
- Name methodName = X10Binary_c.binaryMethodName(op);
- w.write("new java.lang.Object() {");
- w.allowBreak(0, " ");
- w.write("final ");
- printType(n.type(), PRINT_TYPE_PARAMS);
- w.write(" eval(");
- printType(n.target().type(), PRINT_TYPE_PARAMS);
- w.write(" target, ");
- printType(n.right().type(), PRINT_TYPE_PARAMS);
- w.write(" right) {");
- w.allowBreak(0, " ");
- w.write("return (target.");
- w.write(mangleIdentifier(n.name().id()).toString());
- w.write(" = ");
- w.write("target.");
- w.write(mangleIdentifier(n.name().id()).toString());
- w.write(".");
- w.write(mangleIdentifier(methodName).toString());
- w.write("(right));");
- w.allowBreak(0, " ");
- w.write("} }.eval(");
- tr.print(n, n.target(), w);
- w.write(", ");
- tr.print(n, n.right(), w);
- w.write(")");
- }
+ TypeSystem ts = tr.typeSystem();
+ if (n.operator() == Assign.ASSIGN || t.isNumeric() || t.isBoolean() || t.isSubtype(ts.String(), tr.context())) {
+ tr.print(n, n.target(), w);
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(n.name().id()).toString());
+ w.write(" ");
+ w.write(n.operator().toString());
+ w.write(" ");
+ er.coerce(n, n.right(), n.fieldInstance().type());
+ }
+ else if (n.target() instanceof TypeNode || n.target() instanceof Local || n.target() instanceof Lit) {
+ // target has no side effects--evaluate it more than once
+ Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
+ Name methodName = X10Binary_c.binaryMethodName(op);
+ tr.print(n, n.target(), w);
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(n.name().id()).toString());
+ w.write(" ");
+ w.write(" = ");
+ tr.print(n, n.target(), w);
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(n.name().id()).toString());
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(methodName).toString());
+ w.write("(");
+ tr.print(n, n.right(), w);
+ w.write(")");
+ }
+ else {
+ // x.f += e
+ // -->
+ // new Object() { T eval(R target, T right) { return (target.f = target.f.add(right)); } }.eval(x, e)
+ Binary.Operator op = SettableAssign_c.binaryOp(n.operator());
+ Name methodName = X10Binary_c.binaryMethodName(op);
+ w.write("new java.lang.Object() {");
+ w.allowBreak(0, " ");
+ w.write("final ");
+ er.printType(n.type(), PRINT_TYPE_PARAMS);
+ w.write(" eval(");
+ er.printType(n.target().type(), PRINT_TYPE_PARAMS);
+ w.write(" target, ");
+ er.printType(n.right().type(), PRINT_TYPE_PARAMS);
+ w.write(" right) {");
+ w.allowBreak(0, " ");
+ w.write("return (target.");
+ w.write(Emitter.mangleIdentifier(n.name().id()).toString());
+ w.write(" = ");
+ w.write("target.");
+ w.write(Emitter.mangleIdentifier(n.name().id()).toString());
+ w.write(".");
+ w.write(Emitter.mangleIdentifier(methodName).toString());
+ w.write("(right));");
+ w.allowBreak(0, " ");
+ w.write("} }.eval(");
+ tr.print(n, n.target(), w);
+ w.write(", ");
+ tr.print(n, n.right(), w);
+ w.write(")");
+ }
}
- public void coerce(Node parent, Expr e, Type expected) {
- Type actual = e.type();
- if (expected == actual) {
- tr.print(parent, e, w);
- return;
- }
-
- w.write("((");
- printType(expected, PRINT_TYPE_PARAMS);
- w.write(") ");
- tr.print(parent, e, w);
- w.write(")");
-
-// w.write("x10.types.Types.<");
-// printType(expected, PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
-// w.write(">javacast(");
-// tr.print(parent, e, w);
-// w.write(") ");
- }
-
- public void generateDispatchers(X10ClassDef cd) {
- if (true) return;
- if (cd.flags().isInterface() || cd.flags().isAbstract()) {
- return;
- }
-
- X10ClassType ct = (X10ClassType) cd.asType();
-
- Collection<MethodInstance> seen = new ArrayList<MethodInstance>();
-
- // Remove methods where we generate the dispatcher directly.
- for (MethodDef md : cd.methods()) {
- MethodInstance mi = md.asInstance();
- mi = (MethodInstance) mi.container(ct);
- if (methodUsesClassParameter(mi.def()) && ! md.flags().isStatic())
- seen.add(mi);
- }
-
- List<MethodInstance> methods = new ArrayList<MethodInstance>();
- getInheritedVirtualMethods(ct, methods);
-
- // Remove abstract or overridden methods.
- for (ListIterator<MethodInstance> i = methods.listIterator(); i.hasNext(); ) {
- MethodInstance mi = i.next();
- if (mi.flags().isAbstract()) {
- i.remove();
- continue;
- }
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
- MethodInstance mj = ts.findImplementingMethod(cd.asType(), mi, tr.context());
- if (mj != null && mj.def() != mi.def())
- i.remove();
- }
-
- // Remove methods that don't need dispatchers
- // and reset containers.
- for (ListIterator<MethodInstance> i = methods.listIterator(); i.hasNext(); ) {
- MethodInstance mi = i.next();
- mi = (MethodInstance) mi.container(ct);
- if (!overridesMethodThatUsesClassParameter(mi))
- i.remove();
- else if (methodUsesClassParameter(mi.def()))
- i.remove();
- else
- i.set(mi);
- }
-
- // Remove seen methods.
- for (ListIterator<MethodInstance> i = methods.listIterator(); i.hasNext(); ) {
- MethodInstance mi = i.next();
- if (seen(seen, mi))
- i.remove();
- }
-
- for (MethodInstance mi : methods) {
- generateDispatcher((X10MethodInstance) mi, methodUsesClassParameter(mi.def()));
- }
- }
-
- private boolean seen(Collection<MethodInstance> seen, MethodInstance mi) {
- for (MethodInstance mj : seen) {
- if (mi.name().equals(mj.name()) && mj.hasFormals(mi.formalTypes(), tr.context()))
- return true;
- }
- seen.add(mi);
- return false;
- }
-
- public void getInheritedVirtualMethods(X10ClassType ct, List<MethodInstance> methods) {
- for (MethodInstance mi : ct.methods()) {
- if (! mi.flags().isStatic())
- methods.add(mi);
- }
- Type sup = ct.superClass();
- if (sup instanceof X10ClassType) {
- getInheritedVirtualMethods((X10ClassType) sup, methods);
- }
- for (Type t : ct.interfaces()) {
- if (t instanceof X10ClassType) {
- getInheritedVirtualMethods((X10ClassType) t, methods);
- }
- }
- }
-
- public void generateDispatcher(X10MethodInstance md, boolean usesClassParam) {
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
- Flags flags = md.flags();
- flags = X10Flags.toX10Flags(flags).clearExtern();
- flags = flags.clearNative();
+ public void visit(X10MethodDecl_c n) {
+ X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
- // Hack to ensure that X10Flags are not printed out .. javac will
- // not know what to do with them.
- flags = X10Flags.toX10Flags(flags);
+ Flags flags = n.flags().flags();
- w.begin(0);
- w.write(flags.translate());
+ if (n.name().id().toString().equals("main") &&
+ flags.isPublic() &&
+ flags.isStatic() &&
+ n.returnType().type().isVoid() &&
+ n.formals().size() == 1 &&
+ n.formals().get(0).declType().typeEquals(ts.Rail(ts.String()), tr.context()))
+ {
+ Expander throwsClause = new Inline(er, "");
+ if (n.throwTypes().size() > 0) {
+ List<Expander> l = new ArrayList<Expander>();
+ for (TypeNode tn : n.throwTypes()) {
+ l.add(new TypeExpander(er, tn.type(), PRINT_TYPE_PARAMS));
+ }
+ throwsClause = new Join(er, "", "throws ", new Join(er, ", ", l));
+ }
- String sep = "<";
- for (int i = 0; i < md.typeParameters().size(); i++) {
- w.write(sep);
- sep = ", ";
- printType(md.typeParameters().get(i), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- }
- if (md.typeParameters().size() > 0)
- w.write("> ");
-
- printType(md.returnType(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- w.allowBreak(2, 2, " ", 1);
- w.write(mangleIdentifier(md.name()).toString());
-
- w.write("(");
-
- w.allowBreak(2, 2, "", 0);
- w.begin(0);
- boolean first = true;
-
- // Add a formal parameter of type Type for each type parameters.
- for (Type p : md.typeParameters()) {
- if (! first) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- first = false;
- w.write("final ");
- w.write(X10_RUNTIME_TYPE_CLASS);
- w.write(" ");
- Type pt = p;
- assert pt instanceof ParameterType;
- w.write(mangleIdentifier(((ParameterType) pt).name()).toString());
- }
-
- List<Expander> dispatchArgs = new ArrayList<Expander>();
-
- for (Type pt : md.typeParameters()) {
- dispatchArgs.add(new Inline(mangleIdentifier(((ParameterType) pt).name()).toString()));
- }
-
- for (int i = 0; i < md.formalTypes().size(); i++) {
- Type f = md.formalTypes().get(i);
- if (! first) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- first = false;
-
- w.write(Flags.FINAL.translate());
- printType(f, PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- w.write(" ");
-
- Name name = Name.make("a" + (i+1));
- w.write(name.toString());
-
- dispatchArgs.add(new Join("", CollectionUtil.list("(", new TypeExpander(f, true, true, false), ") ", name.toString())));
- }
-
- w.end();
- w.write(")");
-
- if (! md.throwTypes().isEmpty()) {
- w.allowBreak(6);
- w.write("throws ");
-
- for (Iterator<Type> i = md.throwTypes().iterator(); i.hasNext(); ) {
- Type t = i.next();
- printType(t, PRINT_TYPE_PARAMS);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(4, " ");
- }
- }
- }
-
- w.end();
-
- if (isAbstract(md)) {
- w.write(";");
- return;
- }
-
- w.write(" ");
- w.write("{");
- w.allowBreak(4);
-
- if (! md.returnType().isVoid()) {
- w.write(" return ");
- }
-
- String pat = getJavaImplForDef(md.x10Def());
- if (pat != null) {
- String target = "this";
- emitNativeAnnotation(pat, target, md.typeParameters(), dispatchArgs);
- w.write("; }");
+ new Template(er, "Main", n.formals().get(0), n.body(), tr.context().currentClass().name(), throwsClause).expand();
return;
}
- w.write("this");
- w.write(".");
-
+ X10MethodInstance mi = (X10MethodInstance) n.methodDef().asInstance();
- sep = "<";
- for (int i = 0; i < md.typeParameters().size(); i++) {
- w.write(sep);
- sep = ", ";
- printType(md.typeParameters().get(i), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- }
- if (md.typeParameters().size() > 0)
- w.write("> ");
+ boolean boxPrimitives = true;
- w.write(mangleIdentifier(md.name()).toString());
- w.write("(");
- w.begin(0);
+ if (mi.name() == Name.make("hashCode") && mi.formalTypes().size() == 0)
+ boxPrimitives = false;
+ if (mi.name() == Name.make("equals") && mi.formalTypes().size() == 1)
+ boxPrimitives = false;
+ if (mi.name() == Name.make("hasNext") && mi.formalTypes().size() == 0)
+ boxPrimitives = false;
- for (int i = 0; i < dispatchArgs.size(); i++) {
- if (i != 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- dispatchArgs.get(i).expand(tr);
- }
-
- w.end();
- w.write(");");
- w.allowBreak(0, " ");
- w.write("}");
+ // Olivier: uncomment hack below to generate java code with unboxed primitives
+ // if (mi.name() != Name.make("apply") && mi.name() != Name.make("write") && mi.name() != Name.make("read") && mi.name() != Name.make("set"))
+ // boxPrimitives = false;
+ er.generateMethodDecl(n, boxPrimitives);
}
- boolean isAbstract(MemberInstance mi) {
- if (mi.flags().isAbstract())
- return true;
- Type t = X10TypeMixin.baseType(mi.container());
- if (t instanceof ClassType) {
- ClassType ct = (ClassType) t;
- if (ct.flags().isInterface())
- return true;
- }
- return false;
- }
-
- public void visit(X10MethodDecl_c n) {
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
-
- Flags flags = n.flags().flags();
- if (n.name().id().toString().equals("main") &&
- flags.isPublic() &&
- flags.isStatic() &&
- n.returnType().type().isVoid() &&
- n.formals().size() == 1 &&
- n.formals().get(0).declType().typeEquals(ts.Rail(ts.String()), tr.context()))
- {
- Expander throwsClause = new Inline("");
- if (n.throwTypes().size() > 0) {
- List<Expander> l = new ArrayList<Expander>();
- for (TypeNode tn : n.throwTypes()) {
- l.add(new TypeExpander(tn.type(), PRINT_TYPE_PARAMS));
- }
- throwsClause = new Join("", "throws ", new Join(", ", l));
- }
-
- new Template("Main", n.formals().get(0), n.body(), tr.context().currentClass().name(), throwsClause).expand();
- return;
- }
- X10MethodInstance mi = (X10MethodInstance) n.methodDef().asInstance();
-
- boolean boxPrimitives = true;
-
- if (mi.name() == Name.make("hashCode") && mi.formalTypes().size() == 0)
- boxPrimitives = false;
- if (mi.name() == Name.make("equals") && mi.formalTypes().size() == 1)
- boxPrimitives = false;
- if (mi.name() == Name.make("hasNext") && mi.formalTypes().size() == 0)
- boxPrimitives = false;
-
-// Olivier: uncomment hack below to generate java code with unboxed primitives
-// if (mi.name() != Name.make("apply") && mi.name() != Name.make("write") && mi.name() != Name.make("read") && mi.name() != Name.make("set"))
-// boxPrimitives = false;
- generateMethodDecl(n, boxPrimitives);
+ public void visit(Id_c n) {
+ w.write(Emitter.mangleIdentifier(n.id()).toString());
}
- private boolean overridesMethodThatUsesClassParameter(MethodInstance mi) {
- if (methodUsesClassParameter(mi.def()))
- return true;
- for (MethodInstance mj : mi.implemented(tr.context())) {
- boolean usesParameter = methodUsesClassParameter(mj.def());
- if (usesParameter)
- return true;
- }
-
- return false;
- }
-
- private boolean methodUsesClassParameter(MethodDef md) {
- Type container = Types.get(md.container());
- container = X10TypeMixin.baseType(container);
- if (container instanceof X10ClassType) {
- X10ClassDef cd = ((X10ClassType) container).x10Def();
-
- if (cd.typeParameters().size() == 0)
- return false;
-
- if (getJavaRep(cd) != null)
- return false;
-
- for (Ref<? extends Type> tref : md.formalTypes()) {
- Type t = Types.get(tref);
- if (t instanceof ParameterType) {
- ParameterType pt = (ParameterType) t;
- Def d = Types.get(pt.def());
- if (d == cd) {
- return true;
- }
- }
- }
- Type t = Types.get(md.returnType());
- if (t instanceof ParameterType) {
- ParameterType pt = (ParameterType) t;
- Def d = Types.get(pt.def());
- if (d == cd) {
- return true;
- }
- }
- }
-
- return false;
- }
-
-
- public void visit(Id_c n) {
- w.write(mangleIdentifier(n.id()).toString());
- }
-
- private void generateMethodDecl(X10MethodDecl_c n, boolean boxPrimitives) {
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
-
- Flags flags = n.flags().flags();
-
- Context c = tr.context();
-
- if (c.currentClass().flags().isInterface()) {
- flags = flags.clearPublic();
- flags = flags.clearAbstract();
- }
-
- // Hack to ensure that X10Flags are not printed out .. javac will
- // not know what to do with them.
- flags = X10Flags.toX10Flags(flags);
-
- w.begin(0);
- w.write(flags.translate());
-
- String sep = "<";
- for (int i = 0; i < n.typeParameters().size(); i++) {
- w.write(sep);
- sep = ", ";
- printType(n.typeParameters().get(i).type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- }
- if (n.typeParameters().size() > 0)
- w.write("> ");
-
- printType(n.returnType().type(), PRINT_TYPE_PARAMS | (boxPrimitives ? BOX_PRIMITIVES : 0));
- w.allowBreak(2, 2, " ", 1);
- tr.print(n, n.name(), w);
-
- w.write("(");
-
- w.allowBreak(2, 2, "", 0);
- w.begin(0);
- boolean first = true;
-
- // Add a formal parameter of type Type for each type parameters.
- for (TypeParamNode p : n.typeParameters()) {
- if (! first) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- first = false;
-
- w.write("final ");
- w.write(X10_RUNTIME_TYPE_CLASS);
- w.write(" ");
- w.write(mangleIdentifier(p.name().id()).toString());
- }
-
- for (int i = 0; i < n.formals().size(); i++) {
- Formal f = n.formals().get(i);
- if (! first) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- first = false;
-
- tr.print(n, f.flags(), w);
- printType(f.type().type(), PRINT_TYPE_PARAMS | (boxPrimitives ? BOX_PRIMITIVES : 0));
- w.write(" ");
-
- Name name = f.name().id();
- if (name.toString().equals("")) {
- name = Name.makeFresh("a");
- }
- tr.print(n, f.name().id(name), w);
- }
-
- w.end();
- w.write(")");
-
- if (! n.throwTypes().isEmpty()) {
- w.allowBreak(6);
- w.write("throws ");
-
-
- for (Iterator<TypeNode> i = n.throwTypes().iterator(); i.hasNext(); ) {
- TypeNode tn = (TypeNode) i.next();
- // vj 09/26/08: Changed to print out translated version of throw type
- // tr.print(n, tn, w);
- // TODO: Nate to check.
- printType(tn.type(), PRINT_TYPE_PARAMS);
-
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(4, " ");
- }
- }
- }
-
- w.end();
-
- if (n.body() != null) {
-
- // if (! unboxFormals.isEmpty()) {
- // for (Map.Entry<Name,Formal> e : unboxFormals.entrySet()) {
- // Name newName = e.getKey();
- // Formal f = e.getValue();
- // tr.print(n, f.flags(), w);
- // printType(f.type().type(), true, false, false); // don't box
- // w.write(" ");
- // tr.print(n, f.name(), w);
- // w.write(" = ");
- // w.write(newName.toString());
- // w.write(";");
- // }
- // w.allowBreak(0, " ");
-
- tr.print(n, n.body(), w);
- }
- else {
- w.write(";");
- }
- }
-
public void visit(X10ConstructorDecl_c n) {
w.begin(0);
-
+
tr.print(n, n.flags(), w);
tr.print(n, n.name(), w);
w.write("(");
-
+
w.begin(0);
-
+
X10ConstructorDef ci = (X10ConstructorDef) n.constructorDef();
X10ClassType ct = (X10ClassType) Types.get(ci.container());
List<String> typeAssignments = new ArrayList<String>();
-
-
-
- for (Iterator i = ct.x10Def().typeParameters().iterator(); i.hasNext(); ) {
- ParameterType p = (ParameterType) i.next();
- w.write("final ");
- w.write(X10_RUNTIME_TYPE_CLASS);
- w.write(" ");
- w.write(mangleIdentifier(p.name()).toString());
-
- typeAssignments.add("this." + p.name() + " = " + p.name() + ";");
-
- if (i.hasNext() || n.formals().size() > 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
+
+ for (Iterator<ParameterType> i = ct.x10Def().typeParameters().iterator(); i.hasNext(); ) {
+ ParameterType p = (ParameterType) i.next();
+ w.write("final ");
+ w.write(X10_RUNTIME_TYPE_CLASS);
+ w.write(" ");
+ w.write(Emitter.mangleIdentifier(p.name()).toString());
+
+ typeAssignments.add("this." + p.name() + " = " + p.name() + ";");
+
+ if (i.hasNext() || n.formals().size() > 0) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
}
-
- for (Iterator i = n.formals().iterator(); i.hasNext(); ) {
- Formal f = (Formal) i.next();
- n.print(f, w, tr);
-
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
+
+ for (Iterator<Formal> i = n.formals().iterator(); i.hasNext(); ) {
+ Formal f = (Formal) i.next();
+ n.print(f, w, tr);
+
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
}
-
+
w.end();
w.write(")");
-
+
if (! n.throwTypes().isEmpty()) {
- w.allowBreak(6);
- w.write("throws ");
-
- for (Iterator i = n.throwTypes().iterator(); i.hasNext(); ) {
- TypeNode tn = (TypeNode) i.next();
- printType(tn.type(), PRINT_TYPE_PARAMS);
-
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(4, " ");
- }
- }
+ w.allowBreak(6);
+ w.write("throws ");
+
+ for (Iterator<TypeNode> i = n.throwTypes().iterator(); i.hasNext(); ) {
+ TypeNode tn = (TypeNode) i.next();
+ er.printType(tn.type(), PRINT_TYPE_PARAMS);
+
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(4, " ");
+ }
+ }
}
-
+
w.end();
-
+
if (n.body() != null) {
- if (typeAssignments.size() > 0) {
- w.write(" {");
- w.begin(4);
- if (n.body().statements().size() > 0) {
- if (n.body().statements().get(0) instanceof ConstructorCall) {
- ConstructorCall cc = (ConstructorCall) n.body().statements().get(0);
- n.printSubStmt(cc, w, tr);
- w.allowBreak(0, " ");
- if (cc.kind() == ConstructorCall.THIS)
- typeAssignments.clear();
- }
- }
- for (String s : typeAssignments) {
- w.write(s);
- w.allowBreak(0, " ");
- }
- if (n.body().statements().size() > 0) {
- if (n.body().statements().get(0) instanceof ConstructorCall)
- n.printSubStmt(n.body().statements(n.body().statements().subList(1, n.body().statements().size())), w, tr);
- // vj: the main body was not being written. Added next two lines.
- else
- n.printSubStmt(n.body(), w, tr);
- }
- else
- n.printSubStmt(n.body(), w, tr);
- w.write("}");
- w.end();
- }
- else {
- n.printSubStmt(n.body(), w, tr);
- }
+ if (typeAssignments.size() > 0) {
+ w.write(" {");
+ w.begin(4);
+ if (n.body().statements().size() > 0) {
+ if (n.body().statements().get(0) instanceof ConstructorCall) {
+ ConstructorCall cc = (ConstructorCall) n.body().statements().get(0);
+ n.printSubStmt(cc, w, tr);
+ w.allowBreak(0, " ");
+ if (cc.kind() == ConstructorCall.THIS)
+ typeAssignments.clear();
+ }
+ }
+ for (String s : typeAssignments) {
+ w.write(s);
+ w.allowBreak(0, " ");
+ }
+ if (n.body().statements().size() > 0) {
+ if (n.body().statements().get(0) instanceof ConstructorCall)
+ n.printSubStmt(n.body().statements(n.body().statements().subList(1, n.body().statements().size())), w, tr);
+ // vj: the main body was not being written. Added next two lines.
+ else
+ n.printSubStmt(n.body(), w, tr);
+ }
+ else
+ n.printSubStmt(n.body(), w, tr);
+ w.write("}");
+ w.end();
+ }
+ else {
+ n.printSubStmt(n.body(), w, tr);
+ }
}
else {
- w.write(";");
+ w.write(";");
}
}
-
+
public void visit(Contains_c n) {
- assert false;
+ assert false;
}
-
+
public void visit(TypeDecl_c n) {
- // Do not write anything.
- return;
+ // Do not write anything.
+ return;
}
-
- public String getJavaRep(X10ClassDef def) {
- return getJavaRepParam(def, 1);
- }
- public String getJavaRTTRep(X10ClassDef def) {
- return getJavaRepParam(def, 3);
- }
-
- public String getJavaRepParam(X10ClassDef def, int i) {
- try {
- X10TypeSystem xts = (X10TypeSystem) tr.typeSystem();
- Type rep = (Type) xts.systemResolver().find(QName.make("x10.compiler.NativeRep"));
- List<Type> as = def.annotationsMatching(rep);
- for (Type at : as) {
- assertNumberOfInitializers(at, 4);
- String lang = getPropertyInit(at, 0);
- if (lang != null && lang.equals("java")) {
- return getPropertyInit(at, i);
- }
- }
- }
- catch (SemanticException e) {}
- return null;
- }
+
+
public void visit(X10ClassDecl_c n) {
X10TypeSystem xts = (X10TypeSystem) tr.typeSystem();
X10Context context = (X10Context) tr.context();
X10ClassDef def = (X10ClassDef) n.classDef();
-
- // Do not generate code if the class is represented natively.
- if (getJavaRep(def) != null) {
- w.write(";");
- w.newline();
- return;
- }
-// StringBuilder sb = new StringBuilder();
-// for (TypeParamNode t : n.typeParameters()) {
-// if (sb.length() > 0) {
-// sb.append(", ");
-// }
-// sb.append("\"");
-// sb.append(t.name().id());
-// sb.append("\"");
-// }
-
-// if (sb.length() > 0) {
-// w.write("@x10.generics.Parameters({");
-// w.write(sb.toString());
-// w.write("})");
-// w.allowBreak(0);
-// }
-
-// @Parameters({"T"})
-// public class List implements Runnable {
-// public class T {};
-// public List() { }
-// @Synthetic public List(Class T) { this(); }
-// @Synthetic public static boolean instanceof$(Object o, String constraint) { assert(false); return true; }
-// public static boolean instanceof$(Object o, String constraint, boolean b) { /*check constraint*/; return b; }
-// public static Object cast$(Object o, String constraint) { /*check constraint*/; return (List)o; }
-// T x;
-
+ // Do not generate code if the class is represented natively.
+ if (er.getJavaRep(def) != null) {
+ w.write(";");
+ w.newline();
+ return;
+ }
+
+ // StringBuilder sb = new StringBuilder();
+ // for (TypeParamNode t : n.typeParameters()) {
+ // if (sb.length() > 0) {
+ // sb.append(", ");
+ // }
+ // sb.append("\"");
+ // sb.append(t.name().id());
+ // sb.append("\"");
+ // }
+
+ // if (sb.length() > 0) {
+ // w.write("@x10.generics.Parameters({");
+ // w.write(sb.toString());
+ // w.write("})");
+ // w.allowBreak(0);
+ // }
+
+ // @Parameters({"T"})
+ // public class List implements Runnable {
+ // public class T {};
+ // public List() { }
+ // @Synthetic public List(Class T) { this(); }
+ // @Synthetic public static boolean instanceof$(Object o, String constraint) { assert(false); return true; }
+ // public static boolean instanceof$(Object o, String constraint, boolean b) { /*check constraint*/; return b; }
+ // public static Object cast$(Object o, String constraint) { /*check constraint*/; return (List)o; }
+ // T x;
+
X10Flags flags = X10Flags.toX10Flags( n.flags().flags());
-
+
w.begin(0);
if (flags.isInterface()) {
- w.write(X10Flags.toX10Flags(flags.clearInterface().clearAbstract()).translate());
+ w.write(X10Flags.toX10Flags(flags.clearInterface().clearAbstract()).translate());
}
else {
- w.write(X10Flags.toX10Flags(flags).translate());
+ w.write(X10Flags.toX10Flags(flags).translate());
}
-
+
if (flags.isInterface()) {
- w.write("interface ");
+ w.write("interface ");
}
else {
- w.write("class ");
+ w.write("class ");
}
-
+
tr.print(n, n.name(), w);
-
- if (n.typeParameters().size() > 0) {
- w.write("<");
- w.begin(0);
- String sep = "";
- for (TypeParamNode tp : n.typeParameters()) {
- w.write(sep);
- n.print(tp, w, tr);
- sep = ", ";
- }
- w.end();
- w.write(">");
- }
-
+
+ if (n.typeParameters().size() > 0) {
+ w.write("<");
+ w.begin(0);
+ String sep = "";
+ for (TypeParamNode tp : n.typeParameters()) {
+ w.write(sep);
+ n.print(tp, w, tr);
+ sep = ", ";
+ }
+ w.end();
+ w.write(">");
+ }
+
if (n.superClass() != null) {
- w.allowBreak(0);
- w.write("extends ");
- printType(n.superClass().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES | NO_VARIANCE);
+ w.allowBreak(0);
+ w.write("extends ");
+ er.printType(n.superClass().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES | NO_VARIANCE);
}
-
+
// Filter out x10.lang.Object from the interfaces.
List<TypeNode> interfaces = new ArrayList<TypeNode>();
-
+
for (TypeNode tn: n.interfaces()) {
- Type sup = tn.type();
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
- if (! ts.typeBaseEquals(sup, ts.Object(), tr.context()))
- interfaces.add(tn);
+ Type sup = tn.type();
+ X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
+ if (! ts.typeBaseEquals(sup, ts.Object(), tr.context()))
+ interfaces.add(tn);
}
-
+
if (! interfaces.isEmpty()) {
- w.allowBreak(2);
- if (flags.isInterface()) {
- w.write("extends ");
- }
- else {
- w.write("implements ");
- }
-
- w.begin(0);
- for (Iterator<TypeNode> i = interfaces.iterator(); i.hasNext(); ) {
- TypeNode tn = (TypeNode) i.next();
- printType(tn.type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES | NO_VARIANCE);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0);
- }
- }
- w.end();
+ w.allowBreak(2);
+ if (flags.isInterface()) {
+ w.write("extends ");
+ }
+ else {
+ w.write("implements ");
+ }
+
+ w.begin(0);
+ for (Iterator<TypeNode> i = interfaces.iterator(); i.hasNext(); ) {
+ TypeNode tn = (TypeNode) i.next();
+ er.printType(tn.type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES | NO_VARIANCE);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0);
+ }
+ }
+ w.end();
}
w.unifiedBreak(0);
w.end();
w.write("{");
-
+
// Generate the run-time type. We have to wrap in a class since n might be an interface
// and interfaces can't have static methods.
-
- generateRTTMethods(def);
-
+
+ er.generateRTTMethods(def);
+
boolean isValueType = xts.isValueType(def.asType(), (X10Context) tr.context());
if (def.isTopLevel()) {
- generateRTType(def);
+ er.generateRTType(def);
}
// Generate dispatcher methods.
- generateDispatchers(def);
-
+ er.generateDispatchers(def);
+
if (n.typeParameters().size() > 0) {
- w.newline(4);
- w.begin(0);
- if (! n.flags().flags().isInterface()) {
- for (TypeParamNode tp : n.typeParameters()) {
- w.write("private final ");
- w.write(X10_RUNTIME_TYPE_CLASS);
- w.write(" ");
- n.print(tp.name(), w, tr);
- w.write(";");
- w.newline();
- }
- }
- w.end();
+ w.newline(4);
+ w.begin(0);
+ if (! n.flags().flags().isInterface()) {
+ for (TypeParamNode tp : n.typeParameters()) {
+ w.write("private final ");
+ w.write(X10_RUNTIME_TYPE_CLASS);
+ w.write(" ");
+ n.print(tp.name(), w, tr);
+ w.write(";");
+ w.newline();
+ }
+ }
+ w.end();
}
-
+
if (! n.flags().flags().isInterface()) {
- if (n.properties().size() > 0) {
- w.newline(4);
- w.begin(0);
- for (PropertyDecl pd : n.properties()) {
- n.print(pd, w, tr);
- w.newline();
- }
- w.end();
- }
+ if (n.properties().size() > 0) {
+ w.newline(4);
+ w.begin(0);
+ for (PropertyDecl pd : n.properties()) {
+ n.print(pd, w, tr);
+ w.newline();
+ }
+ w.end();
+ }
}
-
+
n.print(n.body(), w, tr);
w.write("}");
w.newline(0);
-
+
if (def.isLocal()) {
- generateRTType(def);
+ er.generateRTType(def);
}
}
-
- private String mangle(QName name) {
- String mangle = name.toString().replace(".", "$");
- return mangle;
- }
-
- private void javacast(Node parent, Type t, int flags, Expr e) {
- w.write("((");
- printType(t, flags);
- w.write(") ");
- tr.print(parent, e, w);
- w.write(")");
-
-// w.write("x10.types.Types.<");
-// printType(t, flags | BOX_PRIMITIVES);
-// w.write(">javacast(");
-// tr.print(parent, e, w);
-// w.write(")");
- }
- private void javacast(Type t, int flags, Expander e) {
- w.write("((");
- printType(t, flags);
- w.write(") ");
- e.expand(tr);
- w.write(")");
-// w.write("x10.types.Types.<");
-// printType(t, flags | BOX_PRIMITIVES);
-// w.write(">javacast(");
-// e.expand(tr);
-// w.write(")");
- }
- private void javacast(Type t, int flags, String e) {
- w.write("((");
- printType(t, flags);
- w.write(") ");
- w.write(e);
- w.write(")");
-// w.write("x10.types.Types.<");
-// printType(t, flags | BOX_PRIMITIVES);
-// w.write(">javacast(");
-// w.write(e);
-// w.write(")");
- }
-
- private void generateRTType(X10ClassDef def) {
- w.newline();
- String mangle = mangle(def.fullName());
- boolean isConstrained = def.classInvariant() != null && !def.classInvariant().get().valid();
- String superClass = "x10.types.RuntimeType";
- if (serialize_runtime_constraints && isConstrained) { // constrained type; treat specially
- superClass = "x10.types.ConstrainedType";
- }
- if (def.asType().isGloballyAccessible()) {
- w.write("public static ");
- }
- w.write("class ");
-
- Expander rttShortName;
- if (def.typeParameters().size() == 0) {
- rttShortName = new Join("", rttShortName(def), "");
- }
- else {
- X10ClassType ct = (X10ClassType) def.asType();
- rttShortName = new Join(", ", ct.typeArguments());
- List args = new ArrayList();
- for (int i = 0; i < ct.typeArguments().size(); i++) {
- Type a = ct.typeArguments().get(i);
- args.add(new TypeExpander(a, PRINT_TYPE_PARAMS | BOX_PRIMITIVES));
- }
- rttShortName = new Join("", rttShortName(def), "<", new Join(", ", args), ">");
- }
+ public void visit(X10Cast_c c) {
+ TypeNode tn = c.castType();
+ assert tn instanceof CanonicalTypeNode;
+ Expr expr = c.expr();
+ Type type = expr.type();
- rttShortName.expand(tr);
-
- w.write(" extends ");
- w.write(superClass);
- w.write("<");
- printType(def.asType(), BOX_PRIMITIVES | PRINT_TYPE_PARAMS | NO_VARIANCE);
- w.write("> {");
- w.newline();
- w.begin(4);
- if (def.asType().isGloballyAccessible() && def.typeParameters().size() == 0) {
- w.write("public static final ");
- rttShortName.expand(tr);
- w.write(" it = new ");
- rttShortName.expand(tr);
- w.write("();");
- w.newline();
- w.newline();
- }
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- w.write("public final x10.types.Type ");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(";");
- w.newline();
- }
- w.newline();
- w.write("public " + rttShortName(def) + "(");
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- if (i != 0)
- w.write(", ");
- w.write("final x10.types.Type ");
- w.write(mangleIdentifier(pt.name()).toString());
- }
+ switch (c.conversionType()) {
+ case CHECKED:
+ case PRIMITIVE:
+ case SUBTYPE:
+ if (tn instanceof X10CanonicalTypeNode) {
+ X10CanonicalTypeNode xtn = (X10CanonicalTypeNode) tn;
- w.write(") {");
- w.begin(4);
- w.write("super(");
-
- if (serialize_runtime_constraints && isConstrained) { // constrained type; treat specially
- w.write("new x10.types.RuntimeType<");
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(">(");
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(".class");
- w.write(")");
-// new RuntimeTypeExpander(def.asType()).expand(tr); // Cannot do this, because we are *defining* T.it here
- w.write(", ");
- w.write("null, "); // TODO
- XConstraint constraint = def.classInvariant().get();
- assert (constraint != null);
- serializeConstraint(constraint);
- }
- else {
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(".class");
- }
- w.write(");");
- w.newline();
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- w.write("this.");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(" = ");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(";");
- w.newline();
- }
- w.end();
- w.write("}");
- w.newline();
- w.write("public boolean instanceof$(java.lang.Object o) {");
- w.newline();
- w.begin(4);
- if (def.asType().isInnerClass()) {
- w.write("try { ");
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(" zzz = (");
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(") o; } catch (ClassCastException xyzzy) { return false; }");
- }
- else {
- w.write("if (! (o instanceof ");
- printType(def.asType(), BOX_PRIMITIVES);
- w.write(")) return false;");
- }
- w.newline();
- // w.write("RTT ro = (RTT) new RTT(this, o);");
- // w.newline();
- // w.write("if (ro == null) return false;");
- // w.newline();
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- ParameterType.Variance var = def.variances().get(i);
- w.write("if (! ");
- switch (var) {
- case INVARIANT:
- w.write("this.");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(".equals(");
- javacast(def.asType(), BOX_PRIMITIVES, "o");
- w.write("." + "rtt_" + mangle(def.fullName()) + "_");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("()");
- w.write(")");
- break;
- case COVARIANT:
- w.write("this.");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(".isSubtype(");
- javacast(def.asType(), BOX_PRIMITIVES, "o");
- w.write("." + "rtt_" + mangle(def.fullName()) + "_");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("()");
- w.write(")");
- break;
- case CONTRAVARIANT:
- javacast(def.asType(), BOX_PRIMITIVES, "o");
- w.write("." + "rtt_" + mangle(def.fullName()) + "_");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("()");
- w.write(".isSubtype(");
- w.write("this.");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write(")");
- break;
- }
- w.write(") return false;");
- w.newline();
- }
- w.write("return true;");
- w.end();
- w.newline();
- w.write("}");
- w.newline();
-
- for (Ref<? extends ClassType> mtref : def.memberClasses()) {
- X10ClassType mt = (X10ClassType) Types.get(mtref);
- generateRTType(mt.x10Def());
- }
-
- w.write("public java.util.List<x10.types.Type<?>> getTypeParameters() {");
- w.newline();
- w.begin(4);
- if (def.typeParameters().isEmpty())
- w.write("return null;");
- else {
- w.write("return java.util.Arrays.asList(new x10.types.Type<?>[] { ");
- w.newline();
- w.begin(4);
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- if (i != 0)
- w.write(", ");
- w.write(mangleIdentifier(pt.name()).toString());
- }
- w.end();
- w.newline();
- w.write(" });");
- }
- w.end();
- w.newline();
- w.write("}");
- w.end();
- w.newline();
-
- w.write("}");
- w.newline();
- }
+ Type t = X10TypeMixin.baseType(xtn.type());
+ Expander ex = new TypeExpander(er, t, PRINT_TYPE_PARAMS);
- private void serializeConstraint(XConstraint constraint) {
-// String serializedConstraint = serializedForm(constraint);
-// StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, serializedConstraint);
-// tr.print(null, lit, w);
- w.write("new x10.constraint.XConstraint_c() {{");
- w.newline(4);
- w.begin(0);
- w.write("try {");
- w.newline(4);
- w.begin(0);
- List<XTerm> terms = constraint.constraints();
- for (XTerm term : terms) {
- w.write("addTerm(");
- w.begin(0);
- serializeTerm(term, constraint);
- w.end();
- w.write(");");
- w.newline();
- //XConstraint_c c = new XConstraint_c(); c.addTerm(XTerms.makeEquals(XTerms.makeField(c.self(), XTerms.makeName("p")), XTerms.makeLit(2)))
- }
- w.end();
- w.newline();
- w.write("} catch (x10.constraint.XFailure f) {");
- w.newline(4);
- w.begin(0);
- w.write("setInconsistent();");
- w.end();
- w.newline();
- w.write("}");
- w.end();
- w.newline();
- w.write("}}");
- }
-
- private static final String XTERMS = "x10.constraint.XTerms";
- private void serializeTerm(XTerm term, XConstraint parent) {
- if (term.equals(parent.self())) {
- w.write("self()");
- } else
- if (term == XTerms.OPERATOR) {
- w.write(XTERMS+".OPERATOR");
- } else
- if (term instanceof XAnd_c) {
- w.write(XTERMS+".makeAnd(");
- w.begin(0);
- serializeTerm(((XAnd_c)term).left(), parent);
- w.write(",");
- w.allowBreak(0, " ");
- serializeTerm(((XAnd_c)term).right(), parent);
- w.end();
- w.write(")");
- } else
- if (term instanceof XEquals_c) {
- w.write(XTERMS+".makeEquals(");
- w.begin(0);
- serializeTerm(((XEquals_c)term).left(), parent);
- w.write(",");
- w.allowBreak(0, " ");
- serializeTerm(((XEquals_c)term).right(), parent);
- w.end();
- w.write(")");
- } else
- if (term instanceof XNot_c) {
- w.write(XTERMS+".makeNot(");
- w.begin(0);
- serializeTerm(((XNot_c)term).unaryArg(), parent);
- w.end();
- w.write(")");
- } else
- if (term instanceof XFormula_c) {
- if (!((XFormula_c)term).isAtomicFormula())
- throw new RuntimeException("Non-atomic formula encountered: "+term);
- w.write(XTERMS+".makeAtom(");
- w.begin(0);
- serializeName(((XFormula_c)term).operator());
- List<XTerm> arguments = ((XFormula_c)term).arguments();
- for (XTerm arg : arguments) {
- w.write(",");
- w.allowBreak(0, " ");
- serializeTerm(arg, parent);
- }
- w.end();
- w.write(")");
- } else
- if (term instanceof XTypeLit_c) {
- w.write("new x10.types.ConstrainedType.XTypeLit_c(");
- w.begin(0);
- new RuntimeTypeExpander(((XTypeLit_c)term).type()).expand(tr);
- w.end();
- w.write(")");
- } else
- if (term instanceof XLit_c) {
- Object val = ((XLit_c)term).val();
- w.write(XTERMS+".makeLit(");
- w.begin(0);
- if (val == null) {
- w.write("null");
- } else
- if (val instanceof Boolean || val instanceof Number) {
- w.write(val.toString());
- } else
- if (val instanceof Character) {
- CharLit lit = tr.nodeFactory().CharLit(Position.COMPILER_GENERATED, ((Character) val).charValue());
- tr.print(null, lit, w);
- } else
- if (val instanceof String) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, (String) val);
- tr.print(null, lit, w);
- } else
- if (val instanceof QName) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, ((QName) val).toString());
- tr.print(null, lit, w);
- } else
- if (val instanceof XName) {
- serializeName((XName) val);
- } else
- if (val.getClass() == Object.class) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- {
- throw new RuntimeException("Unknown value type "+val.getClass());
- }
- w.end();
- w.write(")");
- } else
- if (term instanceof XField_c) {
- w.write(XTERMS+".makeField((x10.constraint.XVar)");
- w.begin(0);
- serializeTerm(((XField_c)term).receiver(), parent);
- w.write(",");
- w.allowBreak(0, " ");
- serializeName(((XField_c)term).field());
- w.end();
- w.write(")");
- } else
- if (term instanceof XEQV_c) {
- w.write("genEQV(");
- w.begin(0);
- serializeName(((XEQV_c)term).name());
- w.write(",");
- w.allowBreak(0, " ");
- w.write(""+((XEQV_c)term).isEQV());
- w.end();
- w.write(")");
- } else
- if (term instanceof XLocal_c) {
- w.write(XTERMS+".makeLocal(");
- w.begin(0);
- serializeName(((XLocal_c)term).name());
- w.end();
- w.write(")");
- } else
- {
- throw new RuntimeException("Unknown term type "+term.getClass()+": "+term);
- }
- }
-
- private void serializeName(XName n) {
- assert (n instanceof XNameWrapper);
- XNameWrapper name = (XNameWrapper) n;
- w.write(XTERMS+".makeName(");
- w.begin(0);
- Object val = name.val();
- if (val == null) {
- w.write("null");
- } else
- if (val instanceof Def) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- if (val instanceof ParameterType) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- if (val instanceof Binary.Operator) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- if (val instanceof Unary.Operator) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- if (val instanceof String) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- if (val.getClass() == Object.class) {
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, val.toString());
- tr.print(null, lit, w);
- } else
- {
- throw new RuntimeException("Unknown value type "+val.getClass());
- }
- w.write(",");
- w.allowBreak(0, " ");
- StringLit lit = tr.nodeFactory().StringLit(Position.COMPILER_GENERATED, name.toString());
- tr.print(null, lit, w);
- w.end();
- w.write(")");
- }
+ Expander bex = (type.isBoolean() || type.isNumeric() || type.isChar())
+ ? new TypeExpander(er, type, PRINT_TYPE_PARAMS | BOX_PRIMITIVES)
+ : null;
+ Expander uex = (type.isBoolean() || type.isNumeric() || type.isChar())
+ ? new TypeExpander(er, type, PRINT_TYPE_PARAMS)
+ : null;
+ Expander rt = new RuntimeTypeExpander(er, t);
- void generateRTTMethods(X10ClassDef def) {
- generateRTTMethods(def, false);
- }
-
- void generateRTTMethods(X10ClassDef def, boolean boxed) {
- Set<ClassDef> visited = new HashSet<ClassDef>();
- visited.add(def);
+ String template= t.isBoolean() || t.isNumeric() || t.isChar() ? "primitive_cast_deptype" : "cast_deptype";
- // Generate RTTI methods, one for each parameter.
- for (int i = 0; i < def.typeParameters().size(); i++) {
- ParameterType pt = def.typeParameters().get(i);
- ParameterType.Variance var = def.variances().get(i);
-
- w.write("public x10.types.Type<?> " + "rtt_" + mangle(def.fullName()) + "_");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("()");
+ DepParameterExpr dep = xtn.constraintExpr();
+ if (dep != null) {
+ new Template(er, template, ex, expr, rt, new Join(er, " && ", dep.condition())).expand();
+ }
+ else if (t.isBoolean() || t.isNumeric() || t.isChar() || type.isSubtype(t, tr.context())) {
+ w.begin(0);
+ w.write("("); // put "(Type) expr" in parentheses.
+ w.write("(");
+ ex.expand(tr);
+ w.write(")");
+ if (bex != null) {
+ w.write(" ");
+ w.write("(");
+ uex.expand(tr);
+ w.write(")");
+ w.write(" ");
+ w.write("(");
+ bex.expand(tr);
+ w.write(")");
+ }
+ w.allowBreak(2, " ");
+ // HACK: (java.lang.Integer) -1
+ // doesn't parse correctly, but
+ // (java.lang.Integer) (-1)
+ // does
+ if (expr instanceof Unary || expr instanceof Lit)
+ w.write("(");
+ c.printSubExpr(expr, w, tr);
+ if (expr instanceof Unary || expr instanceof Lit)
+ w.write(")");
+ w.write(")");
+ w.end();
+ }
+ else {
+ new Template(er, template, ex, expr, rt, "true").expand();
+ }
+ }
+ else {
+ throw new InternalCompilerError("Ambiguous TypeNode survived type-checking.", tn.position());
+ }
+ break;
+ case UNBOXING:
+ throw new InternalCompilerError("Unboxing conversions not yet supported.", tn.position());
+ case UNKNOWN_IMPLICIT_CONVERSION:
+ throw new InternalCompilerError("Unknown implicit conversion type after type-checking.", c.position());
+ case UNKNOWN_CONVERSION:
+ throw new InternalCompilerError("Unknown conversion type after type-checking.", c.position());
+ case BOXING:
+ throw new InternalCompilerError("Boxing conversion should have been rewritten.", c.position());
+ }
+ }
- if (def.flags().isInterface()) {
- w.write(";");
- }
- else if (! boxed) {
- w.write(" { return this.");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("; }");
- }
- else {
- w.write(" { throw new java.lang.RuntimeException(); }");
- }
- w.newline();
- }
+ public void visit(X10Instanceof_c c) {
+ TypeNode tn = c.compareType();
- // Generate RTTI methods for each interface instantiation.
- if (! def.flags().isInterface()) {
- LinkedList<Type> worklist = new LinkedList<Type>();
-
- for (Type t : def.asType().interfaces()) {
- Type it = X10TypeMixin.baseType(t);
- worklist.add(it);
- }
-
- while (! worklist.isEmpty()) {
- Type it = worklist.removeFirst();
-
- if (it instanceof X10ClassType) {
- X10ClassType ct = (X10ClassType) it;
- X10ClassDef idef = ct.x10Def();
-
- if (visited.contains(idef))
- continue;
- visited.add(idef);
-
- for (Type t : ct.interfaces()) {
- Type it2 = X10TypeMixin.baseType(t);
- worklist.add(it2);
- }
+ if (tn instanceof X10CanonicalTypeNode) {
+ X10CanonicalTypeNode xtn = (X10CanonicalTypeNode) tn;
+ Type t = X10TypeMixin.baseType(xtn.type());
+ DepParameterExpr dep = xtn.constraintExpr();
+ if (dep != null) {
+ if (t.isBoolean() || t.isNumeric() || t.isChar()) {
+ new Template(er, "instanceof_primitive_deptype", xtn.typeRef(Types.ref(t)), c.expr(), new Join(er, " && ", dep.condition())).expand();
+ }
+ else {
+ new Template(er, "instanceof_deptype", xtn.typeRef(Types.ref(t)), c.expr(), new Join(er, " && ", dep.condition())).expand();
+ }
+ return;
+ }
+ }
- for (int i = 0; i < idef.typeParameters().size(); i++) {
- ParameterType pt = idef.typeParameters().get(i);
- w.write("public x10.types.Type<?> " + "rtt_" + mangle(idef.fullName()) + "_");
- w.write(mangleIdentifier(pt.name()).toString());
- w.write("() { ");
-
- if (! boxed) {
- w.write("return ");
- Type at = ct.typeArguments().get(i);
- new RuntimeTypeExpander(at).expand();
- }
- else {
- w.write("throw new java.lang.RuntimeException()");
- }
-
- w.write("; }");
- w.newline();
- }
- }
- }
- }
- }
-
-
- public void visit(X10Cast_c c) {
- TypeNode tn = c.castType();
- assert tn instanceof CanonicalTypeNode;
-
- switch (c.conversionType()) {
- case CHECKED:
- case PRIMITIVE:
- case SUBTYPE:
- if (tn instanceof X10CanonicalTypeNode) {
- X10CanonicalTypeNode xtn = (X10CanonicalTypeNode) tn;
-
- Type t = X10TypeMixin.baseType(xtn.type());
- Expander ex = new TypeExpander(t, PRINT_TYPE_PARAMS);
- Expander bex = (c.expr().type().isBoolean() || c.expr().type().isNumeric() || c.expr().type().isChar()) ? new TypeExpander(c.expr().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES) : null;
- Expander uex = (c.expr().type().isBoolean() || c.expr().type().isNumeric() || c.expr().type().isChar()) ? new TypeExpander(c.expr().type(), PRINT_TYPE_PARAMS) : null;
- Expander rt = new RuntimeTypeExpander(t);
-
- String template;
- if (t.isBoolean() || t.isNumeric() || t.isChar()) {
- template = "primitive_cast_deptype";
- }
- else {
- template = "cast_deptype";
- }
-
- DepParameterExpr dep = xtn.constraintExpr();
- if (dep != null) {
- new Template(template, ex, c.expr(), rt, new Join(" && ", dep.condition())).expand();
- }
- else if (t.isBoolean() || t.isNumeric() || t.isChar() || c.expr().type().isSubtype(t, tr.context())) {
- w.begin(0);
- w.write("("); // put "(Type) expr" in parentheses.
- w.write("(");
- ex.expand(tr);
- w.write(")");
- if (bex != null) {
- w.write(" ");
- w.write("(");
- uex.expand(tr);
- w.write(")");
- w.write(" ");
- w.write("(");
- bex.expand(tr);
- w.write(")");
- }
- w.allowBreak(2, " ");
- // HACK: (java.lang.Integer) -1
- // doesn't parse correctly, but
- // (java.lang.Integer) (-1)
- // does
- if (c.expr() instanceof Unary || c.expr() instanceof Lit)
- w.write("(");
- c.printSubExpr(c.expr(), w, tr);
- if (c.expr() instanceof Unary || c.expr() instanceof Lit)
- w.write(")");
- w.write(")");
- w.end();
- }
- else {
- new Template(template, ex, c.expr(), rt, "true").expand();
- }
- }
- else {
- throw new InternalCompilerError("Ambiguous TypeNode survived type-checking.", tn.position());
- }
- break;
- case UNBOXING:
- throw new InternalCompilerError("Unboxing conversions not yet supported.", tn.position());
- case UNKNOWN_IMPLICIT_CONVERSION:
- throw new InternalCompilerError("Unknown implicit conversion type after type-checking.", c.position());
- case UNKNOWN_CONVERSION:
- throw new InternalCompilerError("Unknown conversion type after type-checking.", c.position());
- case BOXING:
- throw new InternalCompilerError("Boxing conversion should have been rewritten.", c.position());
- }
+ Type t = tn.type();
+ new RuntimeTypeExpander(er, t).expand(tr);
+ w.write(".");
+ w.write("instanceof$(");
+ tr.print(c, c.expr(), w);
+ w.write(")");
}
-
- public void visit(X10Instanceof_c c) {
- TypeNode tn = c.compareType();
-
- if (tn instanceof X10CanonicalTypeNode) {
- X10CanonicalTypeNode xtn = (X10CanonicalTypeNode) tn;
- Type t = X10TypeMixin.baseType(xtn.type());
- DepParameterExpr dep = xtn.constraintExpr();
- if (dep != null) {
- if (t.isBoolean() || t.isNumeric() || t.isChar()) {
- new Template("instanceof_primitive_deptype", xtn.typeRef(Types.ref(t)), c.expr(), new Join(" && ", dep.condition())).expand();
- }
- else {
- new Template("instanceof_deptype", xtn.typeRef(Types.ref(t)), c.expr(), new Join(" && ", dep.condition())).expand();
- }
- return;
- }
- }
-
- Type t = tn.type();
- new RuntimeTypeExpander(t).expand(tr);
- w.write(".");
- w.write("instanceof$(");
- tr.print(c, c.expr(), w);
- w.write(")");
- }
public void visit(Special_c n) {
polyglot.types.Context c = tr.context();
if (((X10Translator) tr).inInnerClass() && n.qualifier() == null && n.kind() != X10Special.SELF) {
- printType(n.type(), 0);
+ er.printType(n.type(), 0);
w.write(".");
}
else if (n.qualifier() != null) {
- printType(n.qualifier().type(), 0);
- w.write(".");
+ er.printType(n.qualifier().type(), 0);
+ w.write(".");
}
w.write(n.kind().toString());
}
-
- String getJavaImplForDef(X10Def o) {
- X10TypeSystem xts = (X10TypeSystem) o.typeSystem();
- try {
- Type java = (Type) xts.systemResolver().find(QName.make("x10.compiler.Native"));
- List<Type> as = o.annotationsMatching(java);
- for (Type at : as) {
- assertNumberOfInitializers(at, 2);
- String lang = getPropertyInit(at, 0);
- if (lang != null && lang.equals("java")) {
- String lit = getPropertyInit(at, 1);
- return lit;
- }
- }
- }
- catch (SemanticException e) {}
- return null;
- }
-
+
+
+
public void visit(X10ConstructorCall_c c) {
- X10ConstructorCall_c n = c;
-
- if (n.qualifier() != null) {
- tr.print(c, n.qualifier(), w);
- w.write(".");
- }
-
- w.write(c.kind() == ConstructorCall.THIS ? "this" : "super");
-
- w.write("(");
- w.begin(0);
-
- X10ConstructorInstance mi = (X10ConstructorInstance) n.constructorInstance();
- X10ClassType ct = (X10ClassType) mi.container();
-
- for (Iterator<Type> i = ct.typeArguments().iterator(); i.hasNext(); ) {
- final Type at = i.next();
- new RuntimeTypeExpander(at).expand(tr);
- if (i.hasNext() || c.arguments().size() > 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
-
- List l = c.arguments();
- for (Iterator i = l.iterator(); i.hasNext(); ) {
- Expr e = (Expr) i.next();
- c.print(e, w, tr);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
-
- w.end();
- w.write(");");
+ X10ConstructorCall_c n = c;
+
+ if (n.qualifier() != null) {
+ tr.print(c, n.qualifier(), w);
+ w.write(".");
+ }
+
+ w.write(c.kind() == ConstructorCall.THIS ? "this" : "super");
+
+ w.write("(");
+ w.begin(0);
+
+ X10ConstructorInstance mi = (X10ConstructorInstance) n.constructorInstance();
+ X10ClassType ct = (X10ClassType) mi.container();
+
+ for (Iterator<Type> i = ct.typeArguments().iterator(); i.hasNext(); ) {
+ final Type at = i.next();
+ new RuntimeTypeExpander(er, at).expand(tr);
+ if (i.hasNext() || c.arguments().size() > 0) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+
+ List<Expr> l = c.arguments();
+ for (Iterator<Expr> i = l.iterator(); i.hasNext(); ) {
+ Expr e = (Expr) i.next();
+ c.print(e, w, tr);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+
+ w.end();
+ w.write(");");
}
public void visit(X10New_c c) {
- X10New_c n = c;
- if (n.qualifier() != null) {
-
- tr.print(c, n.qualifier(), w);
- w.write(".");
- }
+ X10New_c n = c;
+ if (n.qualifier() != null) {
- w.write("new ");
-
- if (n.qualifier() == null) {
- printType(n.objectType().type(), PRINT_TYPE_PARAMS | NO_VARIANCE);
- }
- else {
- printType(n.objectType().type(), PRINT_TYPE_PARAMS | NO_VARIANCE | NO_QUALIFIER);
- }
-
- w.write("(");
- w.begin(0);
+ tr.print(c, n.qualifier(), w);
+ w.write(".");
+ }
- X10ConstructorInstance mi = (X10ConstructorInstance) n.constructorInstance();
- X10ClassType ct = (X10ClassType) mi.container();
-
- for (Iterator<Type> i = ct.typeArguments().iterator(); i.hasNext(); ) {
- final Type at = i.next();
- new RuntimeTypeExpander(at).expand(tr);
- if (i.hasNext() || c.arguments().size() > 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
+ w.write("new ");
- List l = c.arguments();
- for (Iterator i = l.iterator(); i.hasNext(); ) {
- Expr e = (Expr) i.next();
- c.print(e, w, tr);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
- w.end();
- w.write(")");
-
- if (c.body() != null) {
- w.write("{");
- tr.print(c, c.body(), w);
- w.write("}");
- }
+ if (n.qualifier() == null) {
+ er.printType(n.objectType().type(), PRINT_TYPE_PARAMS | NO_VARIANCE);
+ }
+ else {
+ er.printType(n.objectType().type(), PRINT_TYPE_PARAMS | NO_VARIANCE | NO_QUALIFIER);
+ }
+
+ w.write("(");
+ w.begin(0);
+
+ X10ConstructorInstance mi = (X10ConstructorInstance) n.constructorInstance();
+ X10ClassType ct = (X10ClassType) mi.container();
+
+ for (Iterator<Type> i = ct.typeArguments().iterator(); i.hasNext(); ) {
+ final Type at = i.next();
+ new RuntimeTypeExpander(er, at).expand(tr);
+ if (i.hasNext() || c.arguments().size() > 0) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+
+ List<Expr> l = c.arguments();
+ for (Iterator<Expr> i = l.iterator(); i.hasNext(); ) {
+ Expr e = (Expr) i.next();
+ c.print(e, w, tr);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+ w.end();
+ w.write(")");
+
+ if (c.body() != null) {
+ w.write("{");
+ tr.print(c, c.body(), w);
+ w.write("}");
+ }
}
-
+
public void visit(Import_c c) {
- // don't generate any code at all--we should fully qualify all type names
+ // don't generate any code at all--we should fully qualify all type names
}
public void visit(ClosureCall_c c) {
- Expr target = c.target();
- Type t = target.type();
- boolean base = false;
-
- X10TypeSystem xts = (X10TypeSystem) t.typeSystem();
+ Expr target = c.target();
+ Type t = target.type();
+ boolean base = false;
- X10MethodInstance mi = c.closureInstance();
+ X10TypeSystem xts = (X10TypeSystem) t.typeSystem();
- c.printSubExpr(target, w, tr);
- w.write(".");
- w.write("apply");
- w.write("(");
- w.begin(0);
+ X10MethodInstance mi = c.closureInstance();
- for (Iterator<Type> i = mi.typeParameters().iterator(); i.hasNext(); ) {
- final Type at = i.next();
- new RuntimeTypeExpander(at).expand(tr);
- if (i.hasNext() || c.arguments().size() > 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
+ c.printSubExpr(target, w, tr);
+ w.write(".");
+ w.write("apply");
+ w.write("(");
+ w.begin(0);
- List l = c.arguments();
- for (Iterator i = l.iterator(); i.hasNext(); ) {
- Expr e = (Expr) i.next();
- c.print(e, w, tr);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
- w.end();
- w.write(")");
+ for (Iterator<Type> i = mi.typeParameters().iterator(); i.hasNext(); ) {
+ final Type at = i.next();
+ new RuntimeTypeExpander(er, at).expand(tr);
+ if (i.hasNext() || c.arguments().size() > 0) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+
+ List<Expr> l = c.arguments();
+ for (Iterator<Expr> i = l.iterator(); i.hasNext(); ) {
+ Expr e = (Expr) i.next();
+ c.print(e, w, tr);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+ w.end();
+ w.write(")");
}
-
+
public void visit(Tuple_c c) {
- Type t = X10TypeMixin.getParameterType(c.type(), 0);
- new Template("tuple",
- new TypeExpander(t, true, true, false),
- new RuntimeTypeExpander(t),
- new TypeExpander(t, true, false, false),
- new Join(",", c.arguments())).expand();
+ Type t = X10TypeMixin.getParameterType(c.type(), 0);
+ new Template(er, "tuple",
+ new TypeExpander(er, t, true, true, false),
+ new RuntimeTypeExpander(er, t),
+ new TypeExpander(er, t, true, false, false),
+ new Join(er, ",", c.arguments())).expand();
}
- /*
- * For "java" annotations:
- *
- * Given a method with signature:
- * def m[X, Y](x, y);
- * and a call
- * o.m[A, B](a, b);
- * #0 = o
- * #1 = A
- * #2 = boxed representation of A
- * #3 = run-time Type object for A
- * #4 = B
- * #5 = boxed representation of B
- * #6 = run-time Type object for B
- * #7 = a
- * #8 = b
- */
- private void emitNativeAnnotation(String pat, Object target, List<Type> types, List<? extends Object> args) {
- Object[] components = new Object[1 + types.size() * 3 + args.size()];
- int i = 0;
- components[i++] = target;
- for (Type at : types) {
- components[i++] = new TypeExpander(at, true, false, false);
- components[i++] = new TypeExpander(at, true, true, false);
- components[i++] = new RuntimeTypeExpander(at);
- }
- for (Object e : args) {
- components[i++] = e;
- }
- dumpRegex("Native", components, tr, pat);
- }
-
+
+
public void visit(X10Call_c c) {
- X10Context context = (X10Context) tr.context();
+ X10Context context = (X10Context) tr.context();
Receiver target = c.target();
Type t = target.type();
boolean base = false;
-
+
X10TypeSystem xts = (X10TypeSystem) t.typeSystem();
-
+
X10MethodInstance mi = (X10MethodInstance) c.methodInstance();
-
- String pat = getJavaImplForDef(mi.x10Def());
+
+ String pat = er.getJavaImplForDef(mi.x10Def());
if (pat != null) {
- boolean needsHereCheck = needsHereCheck(target, context);
+ boolean needsHereCheck = er.needsHereCheck(target, context);
Template tmp = null;
if (needsHereCheck && ! (target instanceof TypeNode || target instanceof New)) {
- tmp = new Template("place-check", new TypeExpander(target.type(), true, false, false), target);
+ tmp = new Template(er, "place-check", new TypeExpander(er, target.type(), true, false, false), target);
}
- emitNativeAnnotation(pat, null == tmp ? target : tmp, mi.typeParameters(), c.arguments());
+ er.emitNativeAnnotation(pat, null == tmp ? target : tmp, mi.typeParameters(), c.arguments());
return;
}
@@ -1978,286 +915,232 @@
if (X10Flags.toX10Flags(mi.flags()).isProperty() && mi.formalTypes().size() == 0 && mi.typeParameters().size() == 0) {
X10FieldInstance fi = (X10FieldInstance) mi.container().fieldNamed(mi.name());
if (fi != null) {
- String pat2 = getJavaImplForDef(fi.x10Def());
+ String pat2 = er.getJavaImplForDef(fi.x10Def());
if (pat2 != null) {
- Object[] components = new Object[] { target };
- dumpRegex("Native", components, tr, pat2);
+ Object[] components = new Object[] { target };
+ er.dumpRegex("Native", components, tr, pat2);
return;
}
}
}
if (target instanceof TypeNode) {
- printType(t, 0);
+ er.printType(t, 0);
}
- else {
-
- // add a check that verifies if the target of the call is in place 'here'
- // This is not needed for:
+ else {
- boolean needsHereCheck = needsHereCheck((Expr) target, context);
+ // add a check that verifies if the target of the call is in place 'here'
+ // This is not needed for:
- if (! (target instanceof Special || target instanceof New)) {
- w.write("(");
+ boolean needsHereCheck = er.needsHereCheck((Expr) target, context);
- if (needsHereCheck) {
- // don't annotate calls with implicit target, or this and super
- // the template file only emits the target
- new Template("place-check", new TypeExpander(t, true, false, false), target).expand();
- }
- else {
- tr.print(c, target, w);
- }
+ if (! (target instanceof Special || target instanceof New)) {
+ w.write("(");
- w.write(")");
- }
- else {
- tr.print(c, target, w);
- }
- }
-
+ if (needsHereCheck) {
+ // don't annotate calls with implicit target, or this and super
+ // the template file only emits the target
+ new Template(er, "place-check", new TypeExpander(er, t, true, false, false), target).expand();
+ }
+ else {
+ tr.print(c, target, w);
+ }
+
+ w.write(")");
+ }
+ else {
+ tr.print(c, target, w);
+ }
+ }
+
w.write(".");
if (mi.typeParameters().size() > 0) {
- w.write("<");
- for (Iterator<Type> i = mi.typeParameters().iterator(); i.hasNext(); ) {
- final Type at = i.next();
- new TypeExpander(at, PRINT_TYPE_PARAMS | BOX_PRIMITIVES).expand(tr);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
- }
- w.write(">");
+ w.write("<");
+ for (Iterator<Type> i = mi.typeParameters().iterator(); i.hasNext(); ) {
+ final Type at = i.next();
+ new TypeExpander(er, at, PRINT_TYPE_PARAMS | BOX_PRIMITIVES).expand(tr);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
+ }
+ w.write(">");
}
- w.write(mangleIdentifier(c.name().id()).toString());
+ w.write(Emitter.mangleIdentifier(c.name().id()).toString());
w.write("(");
w.begin(0);
for (Iterator<Type> i = mi.typeParameters().iterator(); i.hasNext(); ) {
- final Type at = i.next();
- new RuntimeTypeExpander(at).expand(tr);
- if (i.hasNext() || c.arguments().size() > 0) {
- w.write(",");
- w.allowBreak(0, " ");
- }
+ final Type at = i.next();
+ new RuntimeTypeExpander(er, at).expand(tr);
+ if (i.hasNext() || c.arguments().size() > 0) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
}
- List l = c.arguments();
- for (Iterator i = l.iterator(); i.hasNext(); ) {
- Expr e = (Expr) i.next();
- c.print(e, w, tr);
- if (i.hasNext()) {
- w.write(",");
- w.allowBreak(0, " ");
- }
+ List<Expr> l = c.arguments();
+ for (Iterator<Expr> i = l.iterator(); i.hasNext(); ) {
+ Expr e = i.next();
+ c.print(e, w, tr);
+ if (i.hasNext()) {
+ w.write(",");
+ w.allowBreak(0, " ");
+ }
}
w.end();
w.write(")");
}
-
- public void printFormal(Translator tr, Node n, Formal f, boolean mustBox) {
- tr.print(n, f.flags(), w);
- printType(f.type().type(), PRINT_TYPE_PARAMS | (mustBox ? BOX_PRIMITIVES : 0));
- w.write(" ");
- Name name = f.name().id();
- if (name.toString().equals(""))
- tr.print(n, f.name().id(Name.makeFresh("a")), w);
- else {
- tr.print(n, f.name(), w);
- }
- }
+
public void visit(final Closure_c n) {
Translator tr2 = ((X10Translator) tr).inInnerClass(true);
tr2 = tr2.context(n.enterScope(tr2.context()));
- List<Expander> formals = new ArrayList();
- List<Expander> typeArgs = new ArrayList();
+ List<Expander> formals = new ArrayList<Expander>();
+ List<Expander> typeArgs = new ArrayList<Expander>();
for (final Formal f : n.formals()) {
- TypeExpander ft = new TypeExpander(f.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
- typeArgs.add(ft); // must box formals
- formals.add(new Expander() {
- public void expand(Translator tr) {
- printFormal(tr, n, f, true);
- }
- });
- }
+ TypeExpander ft = new TypeExpander(er, f.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES);
+ typeArgs.add(ft); // must box formals
+ formals.add(new Expander(er) {
+ public void expand(Translator tr) {
+ er.printFormal(tr, n, f, true);
+ }
+ });
+ }
- TypeExpander ret = new TypeExpander(n.returnType().type(), true, true, false);
+ TypeExpander ret = new TypeExpander(er, n.returnType().type(), true, true, false);
if (!n.returnType().type().isVoid()) {
- typeArgs.add(ret);
- w.write("new x10.core.fun.Fun_0_" + n.formals().size());
+ typeArgs.add(ret);
+ w.write("new x10.core.fun.Fun_0_" + n.formals().size());
}
else {
- w.write("new x10.core.fun.VoidFun_0_" + n.formals().size());
+ w.write("new x10.core.fun.VoidFun_0_" + n.formals().size());
}
-
+
if (typeArgs.size() > 0) {
- w.write("<");
- new Join(", ", typeArgs).expand(tr2);
- w.write(">");
+ w.write("<");
+ new Join(er, ", ", typeArgs).expand(tr2);
+ w.write(">");
}
-
+
w.write("() {");
w.write("public final ");
ret.expand(tr2);
w.write(" apply(");
- new Join(", ", formals).expand(tr2);
+ new Join(er, ", ", formals).expand(tr2);
w.write(") { ");
tr2.print(n, n.body(), w);
w.write("}");
w.newline();
-
+
Type t = n.type();
t = X10TypeMixin.baseType(t);
if (t instanceof X10ClassType) {
- X10ClassType ct = (X10ClassType) t;
- generateRTTMethods(ct.x10Def());
+ X10ClassType ct = (X10ClassType) t;
+ er.generateRTTMethods(ct.x10Def());
}
-
+
w.write("}");
- }
+}
- X10ClassType annotationNamed(TypeSystem ts, Node o, QName name) throws SemanticException {
- // Nate's code. This one.
- if (o.ext() instanceof X10Ext) {
- X10Ext ext = (X10Ext) o.ext();
- X10ClassType baseType = (X10ClassType) ts.systemResolver().find(name);
- List<X10ClassType> ats = ext.annotationMatching(baseType);
- if (ats.size() > 1) {
- throw new SemanticException("Expression has more than one " + name + " annotation.", o.position());
- }
- if (!ats.isEmpty()) {
- X10ClassType at = ats.get(0);
- return at;
- }
- }
- return null;
- }
- private boolean hasAnnotation(Node dec, QName name) {
- try {
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
- if (annotationNamed(ts, dec, name) != null)
- return true;
- } catch (NoClassException e) {
- if (!e.getClassName().equals(name.toString()))
- throw new InternalCompilerError("Something went terribly wrong", e);
- } catch (SemanticException e) {
- throw new InternalCompilerError("Something is terribly wrong", e);
- }
- return false;
- }
-
+
public void visit(FieldDecl_c n) {
- if (hasAnnotation(n, QName.make("x10.lang.shared"))) {
+ if (er.hasAnnotation(n, QName.make("x10.lang.shared"))) {
w.write ("volatile ");
}
visit((Node) n);
}
public void visit(PropertyDecl_c dec) {
-// polyglot.types.Context c = tr.context();
+ // polyglot.types.Context c = tr.context();
// Don't generate property declarations for fields.
-// if (c.currentClass().flags().isInterface()) {
-// return;
-// }
+ // if (c.currentClass().flags().isInterface()) {
+ // return;
+ // }
super.visit(dec);
}
- private Template processClocks(Clocked c) {
- assert (null != c.clocks());
- Template clocks = null;
-// if (c.clocks().isEmpty())
-// clocks = null;
-// else if (c.clocks().size() == 1)
-// clocks = new Template("clock", c.clocks().get(0));
-// else {
- Integer id = getUniqueId_();
- clocks = new Template("clocked",
- new Loop("clocked-loop", c.clocks(), new CircularList(id)),
- id);
-// }
- return clocks;
- }
+
public void visit(Async_c a) {
- assert false;
-// Translator tr2 = ((X10Translator) tr).inInnerClass(true);
-// new Template("Async",
-// a.place(),
-// processClocks(a),
-// a.body(),
-// a.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
+ assert false;
+ // Translator tr2 = ((X10Translator) tr).inInnerClass(true);
+ // new Template("Async",
+ // a.place(),
+ // processClocks(a),
+ // a.body(),
+ // a.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
}
-
+
public void visit(AtStmt_c a) {
- assert false;
-// Translator tr2 = ((X10Translator) tr).inInnerClass(true);
-// new Template("At",
-// a.place(),
-// a.body(),
-// getUniqueId_(),
-// a.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
+ assert false;
+ // Translator tr2 = ((X10Translator) tr).inInnerClass(true);
+ // new Template("At",
+ // a.place(),
+ // a.body(),
+ // getUniqueId_(),
+ // a.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
}
public void visit(Atomic_c a) {
- assert false;
-// new Template("Atomic", a.body(), getUniqueId_()).expand();
+ assert false;
+ // new Template("Atomic", a.body(), getUniqueId_()).expand();
}
public void visit(Here_c a) {
- assert false;
-// new Template("here").expand();
+ assert false;
+ // new Template("here").expand();
}
public void visit(Await_c c) {
- assert false;
-// new Template("await", c.expr(), getUniqueId_()).expand();
+ assert false;
+ // new Template("await", c.expr(), getUniqueId_()).expand();
}
public void visit(Next_c d) {
- assert false;
-// new Template("next").expand();
+ assert false;
+ // new Template("next").expand();
}
public void visit(Future_c f) {
- assert false;
-// Translator tr2 = ((X10Translator) tr).inInnerClass(true);
-// new Template("Future", f.place(), new TypeExpander(f.returnType().type(), true, true, false, false), f.body(), new RuntimeTypeExpander(f.returnType().type()), f.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
+ assert false;
+ // Translator tr2 = ((X10Translator) tr).inInnerClass(true);
+ // new Template("Future", f.place(), new TypeExpander(f.returnType().type(), true, true, false, false), f.body(), new RuntimeTypeExpander(f.returnType().type()), f.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
}
-
+
public void visit(AtExpr_c f) {
- assert false;
-// Translator tr2 = ((X10Translator) tr).inInnerClass(true);
-// new Template("AtExpr", f.place(), new TypeExpander(f.returnType().type(), true, true, false, false), f.body(), new RuntimeTypeExpander(f.returnType().type()), f.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
+ assert false;
+ // Translator tr2 = ((X10Translator) tr).inInnerClass(true);
+ // new Template("AtExpr", f.place(), new TypeExpander(f.returnType().type(), true, true, false, false), f.body(), new RuntimeTypeExpander(f.returnType().type()), f.position().nameAndLineString().replace("\\", "\\\\")).expand(tr2);
}
-
+
public void visit(Formal_c f) {
- if (f.name().id().toString().equals(""))
- f = (Formal_c) f.name(f.name().id(Name.makeFresh("a")));
- visit((Node) f);
+ if (f.name().id().toString().equals(""))
+ f = (Formal_c) f.name(f.name().id(Name.makeFresh("a")));
+ visit((Node) f);
}
public void visit(ForLoop_c f) {
- X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
-
- X10Formal form = (X10Formal) f.formal();
-
- X10Context context = (X10Context) tr.context();
+ X10TypeSystem ts = (X10TypeSystem) tr.typeSystem();
+ X10Formal form = (X10Formal) f.formal();
+
+ X10Context context = (X10Context) tr.context();
+
/* TODO: case: for (point p:D) -- discuss with vj */
/* handled cases: exploded syntax like: for (point p[i,j]:D) and for (point [i,j]:D) */
if (Configuration.LOOP_OPTIMIZATIONS && form.hasExplodedVars() && (ts.isSubtype(f.domain().type(), ts.Region(), context) || ts.isSubtype(f.domain().type(), ts.Dist(), context)) && X10ArraysMixin.isRect(f.domain().type(), context)) {
String regVar = getId().toString();
- List idxs = new ArrayList();
- List lims = new ArrayList();
- List idx_vars = new ArrayList();
- List vals = new ArrayList();
+ List<Name> idxs = new ArrayList<Name>();
+ List<Name> lims = new ArrayList<Name>();
+ List<Name> idx_vars = new ArrayList<Name>();
+ List<Object> vals = new ArrayList<Object>();
LocalDef[] lis = form.localInstances();
int rank = lis.length;
@@ -2271,94 +1154,65 @@
Object body = f.body();
if (!form.isUnnamed())
- body = new Join("\n",
- new Template("point-create",
- form.flags(),
- form.type(),
- form.name(),
- new Join(",", idxs)
- ),
- body);
+ body = new Join(er, "\n",
+ new Template(er, "point-create",
+ form.flags(),
+ form.type(),
+ form.name(),
+ new Join(er, ",", idxs)
+ ),
+ body);
- body = new Join("\n",
- new Loop("final-var-assign", new CircularList<String>("int"), idx_vars, idxs),
- body);
+ body = new Join(er, "\n",
+ new Loop(er, "final-var-assign", new CircularList<String>("int"), idx_vars, idxs),
+ body);
- new Template("forloop-mult",
- f.domain(),
- regVar,
- new Loop("forloop-mult-each", idxs, new CircularList<String>(regVar), vals, lims),
- body,
-// new Template("forloop",
-// form.flags(),
-// form.type(),
-// form.name(),
-// regVar,
-// new Join("\n", new Join("\n", f.locals()), f.body()),
-// new TypeExpander(form.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES)
-// )
- new Inline("assert false;")
- ).expand();
+ new Template(er, "forloop-mult",
+ f.domain(),
+ regVar,
+ new Loop(er, "forloop-mult-each", idxs, new CircularList<String>(regVar), vals, lims),
+ body,
+ // new Template("forloop",
+ // form.flags(),
+ // form.type(),
+ // form.name(),
+ // regVar,
+ // new Join("\n", new Join("\n", f.locals()), f.body()),
+ // new TypeExpander(form.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES)
+ // )
+ new Inline(er, "assert false;")
+ ).expand();
} else
- new Template("forloop",
- form.flags(),
- form.type(),
- form.name(),
- f.domain(),
- new Join("\n", new Join("\n", f.locals()), f.body()),
- new TypeExpander(form.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES)
- ).expand();
+ new Template(er, "forloop",
+ form.flags(),
+ form.type(),
+ form.name(),
+ f.domain(),
+ new Join(er, "\n", new Join(er, "\n", f.locals()), f.body()),
+ new TypeExpander(er, form.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES)
+ ).expand();
}
- private void processClockedLoop(String template, X10ClockedLoop l) {
- Translator tr2 = ((X10Translator) tr).inInnerClass(true);
- new Template(template,
- /* #0 */ l.formal().flags(),
- /* #1 */ l.formal().type(),
- /* #2 */ l.formal().name(),
- /* #3 */ l.domain(),
- /* #4 */ new Join("\n", new Join("\n", l.locals()), l.body()),
- /* #5 */ processClocks(l),
- /* #6 */ new Join("\n", l.locals()),
- /* #7 */ new TypeExpander(l.formal().type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES),
- /* #8 */ l.position().nameAndLineString().replace("\\", "\\\\")
- ).expand(tr2);
- }
+
public void visit(ForEach_c f) {
- assert (false);
+ assert (false);
// System.out.println("X10PrettyPrinter.visit(ForEach c): |" + f.formal().flags().translate() + "|");
- processClockedLoop("foreach", f);
+ er.processClockedLoop("foreach", f);
}
public void visit(AtEach_c f) {
- assert (false);
- processClockedLoop("ateach", f);
+ assert (false);
+ er.processClockedLoop("ateach", f);
}
public void visit(Now_c n) {
Translator tr2 = ((X10Translator) tr).inInnerClass(true);
- new Template("Now", n.clock(), n.body()).expand(tr2);
+ new Template(er, "Now", n.clock(), n.body()).expand(tr2);
}
-
- boolean needsHereCheck( Receiver target, X10Context context) {
- boolean needsHereCheck = true;
- // calls on new objects
- needsHereCheck &= ! (target instanceof New);
- // others...
- needsHereCheck &= QueryEngine.INSTANCE().needsHereCheck(target.type(), context);
- if (needsHereCheck) {
- if (target instanceof X10Cast) {
- X10Cast c = (X10Cast) target;
- if (c.conversionType() == X10Cast.ConversionType.CHECKED) {
- return needsHereCheck(c.expr(), context);
- }
- }
- }
- return needsHereCheck;
- }
+
/*
* Field access -- this includes FieldAssign (because the left node of
* FieldAssign is a Field node!
@@ -2366,540 +1220,273 @@
public void visit(Field_c n) {
Receiver target = n.target();
Type t = target.type();
-
+
X10TypeSystem xts = (X10TypeSystem) t.typeSystem();
- X10Context context = (X10Context) tr.context();
+ X10Context context = (X10Context) tr.context();
X10FieldInstance fi = (X10FieldInstance) n.fieldInstance();
-
+
if (target instanceof TypeNode) {
- TypeNode tn = (TypeNode) target;
- if (t instanceof ParameterType) {
- // Rewrite to the class declaring the field.
- FieldDef fd = fi.def();
- t = Types.get(fd.container());
- target = tn.typeRef(fd.container());
- n = (Field_c) n.target(target);
- }
+ TypeNode tn = (TypeNode) target;
+ if (t instanceof ParameterType) {
+ // Rewrite to the class declaring the field.
+ FieldDef fd = fi.def();
+ t = Types.get(fd.container());
+ target = tn.typeRef(fd.container());
+ n = (Field_c) n.target(target);
+ }
}
- String pat = getJavaImplForDef(fi.x10Def());
+ String pat = er.getJavaImplForDef(fi.x10Def());
if (pat != null) {
- Object[] components = new Object[] { target };
- dumpRegex("Native", components, tr, pat);
- return;
+ Object[] components = new Object[] { target };
+ er.dumpRegex("Native", components, tr, pat);
+ return;
}
if (target instanceof TypeNode) {
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|