# HG changeset patch # User Christian Humer # Date 1389128797 -3600 # Node ID e8ef44830b507bb0474cd784838bef9c06087149 # Parent dbc17f07cec625be0981b65e701e09d277f3ae01 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup. diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/ExecutableTypeMethodParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/ExecutableTypeMethodParser.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/ExecutableTypeMethodParser.java Tue Jan 07 22:06:37 2014 +0100 @@ -55,7 +55,9 @@ spec.setIgnoreAdditionalParameters(true); spec.setVariableRequiredParameters(true); // varargs - spec.addRequired(new ParameterSpec("other", allowedTypes)); + ParameterSpec otherParameters = new ParameterSpec("other", allowedTypes); + otherParameters.setSignature(true); + spec.addRequired(otherParameters); return spec; } diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/GenericParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/GenericParser.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/GenericParser.java Tue Jan 07 22:06:37 2014 +0100 @@ -46,7 +46,7 @@ @Override protected ParameterSpec createValueParameterSpec(NodeExecutionData execution) { - List execTypes = execution.getChild().getNodeData().findGenericExecutableTypes(getContext(), execution.getChild().getExecuteWith().size()); + List execTypes = execution.getChild().findGenericExecutableTypes(getContext()); List types = new ArrayList<>(); for (ExecutableTypeData type : execTypes) { types.add(type.getType().getPrimitiveType()); diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Tue Jan 07 22:06:37 2014 +0100 @@ -964,16 +964,16 @@ CodeTreeBuilder resetBuilder = builder.create(); for (ActualParameter param : getModel().getSignatureParameters()) { - NodeChildData child = param.getSpecification().getExecution().getChild(); + NodeExecutionData execution = param.getSpecification().getExecution(); CodeTreeBuilder access = builder.create(); - access.string("this.").string(child.getName()); - if (child.getCardinality().isMany()) { - access.string("[").string(String.valueOf(param.getSpecificationVarArgsIndex())).string("]"); + access.string("this.").string(execution.getChild().getName()); + if (execution.isIndexed()) { + access.string("[").string(String.valueOf(execution.getIndex())).string("]"); } String oldName = "old" + Utils.firstLetterUpperCase(param.getLocalName()); - oldBuilder.declaration(child.getNodeData().getNodeType(), oldName, access); + oldBuilder.declaration(execution.getChild().getNodeData().getNodeType(), oldName, access); nullBuilder.startStatement().tree(access.getRoot()).string(" = null").end(); resetBuilder.startStatement().tree(access.getRoot()).string(" = ").string(oldName).end(); } @@ -1111,7 +1111,7 @@ ExecutableTypeData sourceExecutableType = node.findExecutableType(polymorph.getReturnType().getTypeSystemType(), 0); boolean sourceThrowsUnexpected = sourceExecutableType != null && sourceExecutableType.hasUnexpectedValue(getContext()); - if (sourceExecutableType.getType().equals(node.getGenericSpecialization().getReturnType().getTypeSystemType())) { + if (sourceThrowsUnexpected && sourceExecutableType.getType().equals(node.getGenericSpecialization().getReturnType().getTypeSystemType())) { sourceThrowsUnexpected = false; } if (sourceThrowsUnexpected) { diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeData.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeData.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeData.java Tue Jan 07 22:06:37 2014 +0100 @@ -28,6 +28,7 @@ import javax.lang.model.type.*; import com.oracle.truffle.dsl.processor.*; +import com.oracle.truffle.dsl.processor.node.NodeChildData.*; import com.oracle.truffle.dsl.processor.template.*; import com.oracle.truffle.dsl.processor.typesystem.*; @@ -51,6 +52,8 @@ private final List casts = new ArrayList<>(); private Map> executableTypes; + private final NodeExecutionData thisExecution; + private int polymorphicDepth = -1; public NodeData(TypeElement type, String shortName, TypeSystemData typeSystem, List children, List executions, List fields, @@ -64,7 +67,8 @@ this.childExecutions = executions; this.assumptions = assumptions; this.polymorphicDepth = polymorphicDepth; - + this.thisExecution = new NodeExecutionData(new NodeChildData(null, null, "this", getNodeType(), getNodeType(), null, Cardinality.ONE), -1, false); + this.thisExecution.getChild().setNode(this); if (children != null) { for (NodeChildData child : children) { child.setParentNode(this); @@ -76,6 +80,10 @@ this(type, null, null, null, null, null, null, -1); } + public NodeExecutionData getThisExecution() { + return thisExecution; + } + public void addEnclosedNode(NodeData node) { this.enclosingNodes.add(node); node.declaringNode = this; diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeMethodParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeMethodParser.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeMethodParser.java Tue Jan 07 22:06:37 2014 +0100 @@ -59,7 +59,9 @@ } protected ParameterSpec createReturnParameterSpec() { - return new ParameterSpec("returnValue", nodeTypeMirrors(getNode())); + ParameterSpec returnValue = new ParameterSpec("returnValue", nodeTypeMirrors(getNode())); + returnValue.setExecution(getNode().getThisExecution()); + return returnValue; } @Override diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java Tue Jan 07 22:06:37 2014 +0100 @@ -34,7 +34,7 @@ import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.dsl.processor.*; import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality; -import com.oracle.truffle.dsl.processor.node.SpecializationData.*; +import com.oracle.truffle.dsl.processor.node.SpecializationData.SpecializationKind; import com.oracle.truffle.dsl.processor.template.*; import com.oracle.truffle.dsl.processor.template.TemplateMethod.TypeSignature; import com.oracle.truffle.dsl.processor.typesystem.*; @@ -761,10 +761,8 @@ } private SpecializationData createGenericSpecialization(final NodeData node) { - SpecializationData specialization = node.getSpecializations().get(0); GenericParser parser = new GenericParser(context, node); - MethodSpec specification = parser.createDefaultMethodSpec(specialization.getMethod(), null, true, null); - specification.getImplicitRequiredTypes().clear(); + MethodSpec specification = parser.createDefaultMethodSpec(node.getSpecializations().iterator().next().getMethod(), null, true, null); List parameterTypes = new ArrayList<>(); int signatureIndex = 1; @@ -774,8 +772,14 @@ signatureIndex++; } } + TypeMirror returnType = createGenericType(specification.getReturnType(), node.getSpecializations(), 0); - return parser.create("Generic", null, null, returnType, parameterTypes); + SpecializationData generic = parser.create("Generic", null, null, returnType, parameterTypes); + if (generic == null) { + throw new RuntimeException("Unable to create generic signature for node " + node.getNodeId() + " with " + parameterTypes + ". Specification " + specification + "."); + } + + return generic; } private TypeMirror createGenericType(ParameterSpec spec, List specializations, int signatureIndex) { @@ -793,11 +797,10 @@ } NodeChildData child = execution.getChild(); - TypeData genericType = null; if (types.size() == 1) { ExecutableTypeData executable = child.findExecutableType(context, types.iterator().next()); - if (executable != null && !executable.hasUnexpectedValue(context)) { + if (executable != null && (signatureIndex == 0 || !executable.hasUnexpectedValue(context))) { genericType = types.iterator().next(); } } diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/MethodSpec.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/MethodSpec.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/MethodSpec.java Tue Jan 07 22:06:37 2014 +0100 @@ -30,8 +30,6 @@ public class MethodSpec { - private final List implicitRequiredTypes = new ArrayList<>(); - private final ParameterSpec returnType; private final List optional = new ArrayList<>(); private final List required = new ArrayList<>(); @@ -54,10 +52,6 @@ return variableRequiredParameters; } - public void addImplicitRequiredType(TypeMirror type) { - this.implicitRequiredTypes.add(type); - } - public void setIgnoreAdditionalParameters(boolean ignoreAdditionalParameter) { this.ignoreAdditionalParameters = ignoreAdditionalParameter; } @@ -75,10 +69,6 @@ return spec; } - public List getImplicitRequiredTypes() { - return implicitRequiredTypes; - } - public ParameterSpec getReturnType() { return returnType; } diff -r dbc17f07cec6 -r e8ef44830b50 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/TemplateMethodParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/TemplateMethodParser.java Tue Jan 07 20:21:17 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/TemplateMethodParser.java Tue Jan 07 22:06:37 2014 +0100 @@ -169,9 +169,9 @@ List parameters = parseParameters(methodSpecification, parameterTypes, isUseVarArgs() && method != null ? method.isVarArgs() : false); if (parameters == null) { - if (isEmitErrors()) { + if (isEmitErrors() && method != null) { E invalidMethod = create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, Collections. emptyList()), true); - String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(methodSpecification, method), + String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(method), methodSpecification.toSignatureString(method.getSimpleName().toString())); invalidMethod.addError(message); return invalidMethod; @@ -183,18 +183,15 @@ return create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, parameters), false); } - private static String createActualSignature(MethodSpec spec, ExecutableElement method) { + private static String createActualSignature(ExecutableElement method) { StringBuilder b = new StringBuilder("("); String sep = ""; - for (TypeMirror implicitType : spec.getImplicitRequiredTypes()) { - b.append(sep); - b.append("implicit " + Utils.getSimpleName(implicitType)); - sep = ", "; - } - for (VariableElement var : method.getParameters()) { - b.append(sep); - b.append(Utils.getSimpleName(var.asType())); - sep = ", "; + if (method != null) { + for (VariableElement var : method.getParameters()) { + b.append(sep); + b.append(Utils.getSimpleName(var.asType())); + sep = ", "; + } } b.append(")"); return b.toString(); @@ -207,12 +204,10 @@ * ones are cut and used to parse the optional parameters. */ private List parseParameters(MethodSpec spec, List parameterTypes, boolean varArgs) { - List implicitTypes = spec.getImplicitRequiredTypes(); - List parsedRequired = null; int offset = 0; for (; offset <= parameterTypes.size(); offset++) { - List parameters = new ArrayList<>(implicitTypes); + List parameters = new ArrayList<>(); parameters.addAll(parameterTypes.subList(offset, parameterTypes.size())); parsedRequired = parseParametersRequired(spec, parameters, varArgs); if (parsedRequired != null) {