changeset 13535:e8ef44830b50

Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
author Christian Humer <christian.humer@gmail.com>
date Tue, 07 Jan 2014 22:06:37 +0100
parents dbc17f07cec6
children 419b3ea1bdd1
files graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/ExecutableTypeMethodParser.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/GenericParser.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeData.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeMethodParser.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/MethodSpec.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/TemplateMethodParser.java
diffstat 8 files changed, 42 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }
 
--- 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<ExecutableTypeData> execTypes = execution.getChild().getNodeData().findGenericExecutableTypes(getContext(), execution.getChild().getExecuteWith().size());
+        List<ExecutableTypeData> execTypes = execution.getChild().findGenericExecutableTypes(getContext());
         List<TypeMirror> types = new ArrayList<>();
         for (ExecutableTypeData type : execTypes) {
             types.add(type.getType().getPrimitiveType());
--- 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) {
--- 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<CreateCastData> casts = new ArrayList<>();
     private Map<Integer, List<ExecutableTypeData>> executableTypes;
 
+    private final NodeExecutionData thisExecution;
+
     private int polymorphicDepth = -1;
 
     public NodeData(TypeElement type, String shortName, TypeSystemData typeSystem, List<NodeChildData> children, List<NodeExecutionData> executions, List<NodeFieldData> 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;
--- 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
--- 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<TypeMirror> 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<SpecializationData> 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();
                 }
             }
--- 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<TypeMirror> implicitRequiredTypes = new ArrayList<>();
-
     private final ParameterSpec returnType;
     private final List<ParameterSpec> optional = new ArrayList<>();
     private final List<ParameterSpec> 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<TypeMirror> getImplicitRequiredTypes() {
-        return implicitRequiredTypes;
-    }
-
     public ParameterSpec getReturnType() {
         return returnType;
     }
--- 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<ActualParameter> 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.<ActualParameter> 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<ActualParameter> parseParameters(MethodSpec spec, List<TypeMirror> parameterTypes, boolean varArgs) {
-        List<TypeMirror> implicitTypes = spec.getImplicitRequiredTypes();
-
         List<ActualParameter> parsedRequired = null;
         int offset = 0;
         for (; offset <= parameterTypes.size(); offset++) {
-            List<TypeMirror> parameters = new ArrayList<>(implicitTypes);
+            List<TypeMirror> parameters = new ArrayList<>();
             parameters.addAll(parameterTypes.subList(offset, parameterTypes.size()));
             parsedRequired = parseParametersRequired(spec, parameters, varArgs);
             if (parsedRequired != null) {