comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java @ 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 5a0c694ef735
children bd28da642eea
comparison
equal deleted inserted replaced
13534:dbc17f07cec6 13535:e8ef44830b50
32 32
33 import com.oracle.truffle.api.dsl.*; 33 import com.oracle.truffle.api.dsl.*;
34 import com.oracle.truffle.api.nodes.*; 34 import com.oracle.truffle.api.nodes.*;
35 import com.oracle.truffle.dsl.processor.*; 35 import com.oracle.truffle.dsl.processor.*;
36 import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality; 36 import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality;
37 import com.oracle.truffle.dsl.processor.node.SpecializationData.*; 37 import com.oracle.truffle.dsl.processor.node.SpecializationData.SpecializationKind;
38 import com.oracle.truffle.dsl.processor.template.*; 38 import com.oracle.truffle.dsl.processor.template.*;
39 import com.oracle.truffle.dsl.processor.template.TemplateMethod.TypeSignature; 39 import com.oracle.truffle.dsl.processor.template.TemplateMethod.TypeSignature;
40 import com.oracle.truffle.dsl.processor.typesystem.*; 40 import com.oracle.truffle.dsl.processor.typesystem.*;
41 41
42 public class NodeParser extends AbstractParser<NodeData> { 42 public class NodeParser extends AbstractParser<NodeData> {
759 } 759 }
760 } 760 }
761 } 761 }
762 762
763 private SpecializationData createGenericSpecialization(final NodeData node) { 763 private SpecializationData createGenericSpecialization(final NodeData node) {
764 SpecializationData specialization = node.getSpecializations().get(0);
765 GenericParser parser = new GenericParser(context, node); 764 GenericParser parser = new GenericParser(context, node);
766 MethodSpec specification = parser.createDefaultMethodSpec(specialization.getMethod(), null, true, null); 765 MethodSpec specification = parser.createDefaultMethodSpec(node.getSpecializations().iterator().next().getMethod(), null, true, null);
767 specification.getImplicitRequiredTypes().clear();
768 766
769 List<TypeMirror> parameterTypes = new ArrayList<>(); 767 List<TypeMirror> parameterTypes = new ArrayList<>();
770 int signatureIndex = 1; 768 int signatureIndex = 1;
771 for (ParameterSpec spec : specification.getRequired()) { 769 for (ParameterSpec spec : specification.getRequired()) {
772 parameterTypes.add(createGenericType(spec, node.getSpecializations(), signatureIndex)); 770 parameterTypes.add(createGenericType(spec, node.getSpecializations(), signatureIndex));
773 if (spec.isSignature()) { 771 if (spec.isSignature()) {
774 signatureIndex++; 772 signatureIndex++;
775 } 773 }
776 } 774 }
775
777 TypeMirror returnType = createGenericType(specification.getReturnType(), node.getSpecializations(), 0); 776 TypeMirror returnType = createGenericType(specification.getReturnType(), node.getSpecializations(), 0);
778 return parser.create("Generic", null, null, returnType, parameterTypes); 777 SpecializationData generic = parser.create("Generic", null, null, returnType, parameterTypes);
778 if (generic == null) {
779 throw new RuntimeException("Unable to create generic signature for node " + node.getNodeId() + " with " + parameterTypes + ". Specification " + specification + ".");
780 }
781
782 return generic;
779 } 783 }
780 784
781 private TypeMirror createGenericType(ParameterSpec spec, List<SpecializationData> specializations, int signatureIndex) { 785 private TypeMirror createGenericType(ParameterSpec spec, List<SpecializationData> specializations, int signatureIndex) {
782 NodeExecutionData execution = spec.getExecution(); 786 NodeExecutionData execution = spec.getExecution();
783 if (execution == null) { 787 if (execution == null) {
791 for (SpecializationData specialization : specializations) { 795 for (SpecializationData specialization : specializations) {
792 types.add(specialization.getTypeSignature().get(signatureIndex)); 796 types.add(specialization.getTypeSignature().get(signatureIndex));
793 } 797 }
794 798
795 NodeChildData child = execution.getChild(); 799 NodeChildData child = execution.getChild();
796
797 TypeData genericType = null; 800 TypeData genericType = null;
798 if (types.size() == 1) { 801 if (types.size() == 1) {
799 ExecutableTypeData executable = child.findExecutableType(context, types.iterator().next()); 802 ExecutableTypeData executable = child.findExecutableType(context, types.iterator().next());
800 if (executable != null && !executable.hasUnexpectedValue(context)) { 803 if (executable != null && (signatureIndex == 0 || !executable.hasUnexpectedValue(context))) {
801 genericType = types.iterator().next(); 804 genericType = types.iterator().next();
802 } 805 }
803 } 806 }
804 if (genericType == null) { 807 if (genericType == null) {
805 genericType = child.findAnyGenericExecutableType(context).getType(); 808 genericType = child.findAnyGenericExecutableType(context).getType();