Mercurial > hg > truffle
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ExecutableTypeData.java @ 20984:6361fa2e3321
Truffle-DSL: further fixes for polymorphic execute signatures.
author | Christian Humer <christian.humer@oracle.com> |
---|---|
date | Wed, 15 Apr 2015 21:13:43 +0200 |
parents | 05a2b72c071f |
children | fdf55f1ffc59 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ExecutableTypeData.java Wed Apr 15 21:35:51 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ExecutableTypeData.java Wed Apr 15 21:13:43 2015 +0200 @@ -35,6 +35,7 @@ public class ExecutableTypeData extends MessageContainer implements Comparable<ExecutableTypeData> { + private final NodeData node; private final ExecutableElement method; private final TypeMirror returnType; private final TypeMirror frameParameter; @@ -44,7 +45,8 @@ private String uniqueName; - public ExecutableTypeData(TypeMirror returnType, String uniqueName, TypeMirror frameParameter, List<TypeMirror> evaluatedParameters) { + public ExecutableTypeData(NodeData node, TypeMirror returnType, String uniqueName, TypeMirror frameParameter, List<TypeMirror> evaluatedParameters) { + this.node = node; this.returnType = returnType; this.frameParameter = frameParameter; this.evaluatedParameters = evaluatedParameters; @@ -52,7 +54,8 @@ this.method = null; } - public ExecutableTypeData(ExecutableElement method, int signatureSize, List<TypeMirror> frameTypes) { + public ExecutableTypeData(NodeData node, ExecutableElement method, int signatureSize, List<TypeMirror> frameTypes) { + this.node = node; this.method = method; this.returnType = method.getReturnType(); TypeMirror foundFrameParameter = null; @@ -123,6 +126,21 @@ return evaluatedParameters; } + public List<TypeMirror> getSignatureParameters() { + List<TypeMirror> signaturetypes = new ArrayList<>(); + int index = 0; + for (NodeExecutionData execution : node.getChildExecutions()) { + if (execution.isShortCircuit()) { + index++; + } + if (index < getEvaluatedCount()) { + signaturetypes.add(getEvaluatedParameters().get(index)); + } + index++; + } + return signaturetypes; + } + public int getVarArgsIndex(int parameterIndex) { if (method.isVarArgs()) { int index = parameterIndex - (method.getParameters().size() - 1); @@ -159,7 +177,7 @@ return evaluatedParameters.size(); } - public boolean canDelegateTo(NodeData node, ExecutableTypeData to) { + public boolean canDelegateTo(ExecutableTypeData to) { ExecutableTypeData from = this; if (to.getEvaluatedCount() < from.getEvaluatedCount()) { return false; @@ -189,8 +207,10 @@ } } - for (int i = from.getEvaluatedCount(); i < to.getEvaluatedCount(); i++) { - TypeMirror delegateToParameter = to.getEvaluatedParameters().get(i); + List<TypeMirror> fromSignatureParameters = from.getSignatureParameters(); + List<TypeMirror> toSignatureParameters = to.getSignatureParameters(); + for (int i = fromSignatureParameters.size(); i < toSignatureParameters.size(); i++) { + TypeMirror delegateToParameter = toSignatureParameters.get(i); if (i < node.getChildExecutions().size()) { TypeMirror genericType = node.getGenericType(node.getChildExecutions().get(i)); if (!isSubtypeBoxed(context, genericType, delegateToParameter)) { @@ -206,6 +226,14 @@ ExecutableTypeData o1 = this; ProcessorContext context = ProcessorContext.getInstance(); + if (canDelegateTo(o2)) { + if (!o2.canDelegateTo(this)) { + return 1; + } + } else if (o2.canDelegateTo(this)) { + return -1; + } + int result = Integer.compare(o2.getEvaluatedCount(), o1.getEvaluatedCount()); if (result != 0) { return result; @@ -282,9 +310,22 @@ } } + public String getName() { + if (method != null) { + return method.getSimpleName().toString(); + } else { + return getUniqueName(); + } + + } + + private static String formatType(TypeMirror type) { + return type == null ? "null" : ElementUtils.getSimpleName(type); + } + @Override public String toString() { - return method != null ? ElementUtils.createReferenceName(method) : getUniqueName() + evaluatedParameters.toString(); + return String.format("%s %s(%s,%s)", formatType(getReturnType()), getName(), formatType(getFrameParameter()), getEvaluatedParameters()); } public boolean sameParameters(ExecutableTypeData other) {