Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/PolymorphicNodeFactory.java @ 18753:f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Dec 2014 23:38:21 +0100 |
parents | 1acaa69ff61b |
children | 59bf50cc5a32 |
comparison
equal
deleted
inserted
replaced
18752:1acaa69ff61b | 18753:f6b8787dc113 |
---|---|
28 import java.util.*; | 28 import java.util.*; |
29 | 29 |
30 import javax.lang.model.type.*; | 30 import javax.lang.model.type.*; |
31 | 31 |
32 import com.oracle.truffle.api.nodes.*; | 32 import com.oracle.truffle.api.nodes.*; |
33 import com.oracle.truffle.dsl.processor.*; | |
33 import com.oracle.truffle.dsl.processor.java.model.*; | 34 import com.oracle.truffle.dsl.processor.java.model.*; |
34 import com.oracle.truffle.dsl.processor.model.*; | 35 import com.oracle.truffle.dsl.processor.model.*; |
35 | 36 |
36 class PolymorphicNodeFactory extends SpecializedNodeFactory { | 37 class PolymorphicNodeFactory extends SpecializedNodeFactory { |
37 | 38 |
38 public PolymorphicNodeFactory(CodeTypeElement nodeGen) { | 39 public PolymorphicNodeFactory(ProcessorContext context, NodeData node, SpecializationData specialization, CodeTypeElement nodeGen) { |
39 super(nodeGen); | 40 super(context, node, specialization, nodeGen); |
40 } | 41 } |
41 | 42 |
42 @Override | 43 @Override |
43 public CodeTypeElement create(SpecializationData polymorph) { | 44 public CodeTypeElement create() { |
44 NodeData node = polymorph.getNode(); | |
45 TypeMirror baseType = node.getNodeType(); | 45 TypeMirror baseType = node.getNodeType(); |
46 if (nodeGen != null) { | 46 if (nodeGen != null) { |
47 baseType = nodeGen.asType(); | 47 baseType = nodeGen.asType(); |
48 } | 48 } |
49 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false); | 49 CodeTypeElement clazz = GeneratorUtils.createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false); |
50 | 50 |
51 clazz.getAnnotationMirrors().add(createNodeInfo(node, NodeCost.POLYMORPHIC)); | 51 clazz.getAnnotationMirrors().add(createNodeInfo(NodeCost.POLYMORPHIC)); |
52 | 52 |
53 for (Parameter polymorphParameter : polymorph.getSignatureParameters()) { | 53 for (Parameter polymorphParameter : specialization.getSignatureParameters()) { |
54 if (!polymorphParameter.getTypeSystemType().isGeneric()) { | 54 if (!polymorphParameter.getTypeSystemType().isGeneric()) { |
55 continue; | 55 continue; |
56 } | 56 } |
57 Set<TypeData> types = new HashSet<>(); | 57 Set<TypeData> types = new HashSet<>(); |
58 for (SpecializationData specialization : node.getSpecializations()) { | 58 for (SpecializationData otherSpecialization : node.getSpecializations()) { |
59 if (!specialization.isSpecialized()) { | 59 if (!otherSpecialization.isSpecialized()) { |
60 continue; | 60 continue; |
61 } | 61 } |
62 Parameter parameter = specialization.findParameter(polymorphParameter.getLocalName()); | 62 Parameter parameter = otherSpecialization.findParameter(polymorphParameter.getLocalName()); |
63 assert parameter != null; | 63 assert parameter != null; |
64 types.add(parameter.getTypeSystemType()); | 64 types.add(parameter.getTypeSystemType()); |
65 } | 65 } |
66 | 66 |
67 } | 67 } |
68 | 68 |
69 for (NodeExecutionData execution : getModel().getNode().getChildExecutions()) { | 69 for (NodeExecutionData execution : node.getChildExecutions()) { |
70 String fieldName = polymorphicTypeName(execution); | 70 String fieldName = polymorphicTypeName(execution); |
71 CodeVariableElement var = new CodeVariableElement(modifiers(PRIVATE), getContext().getType(Class.class), fieldName); | 71 CodeVariableElement var = new CodeVariableElement(modifiers(PRIVATE), context.getType(Class.class), fieldName); |
72 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getCompilationFinal())); | 72 var.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getTruffleTypes().getCompilationFinal())); |
73 clazz.add(var); | 73 clazz.add(var); |
74 } | 74 } |
75 | |
76 createConstructors(clazz); | |
77 createExecuteMethods(clazz); | |
78 | |
79 clazz.add(createUpdateTypes0()); | |
80 createCachedExecuteMethods(clazz); | |
75 | 81 |
76 return clazz; | 82 return clazz; |
77 } | 83 } |
78 | 84 |
79 @Override | |
80 protected void createChildren(SpecializationData specialization) { | |
81 CodeTypeElement clazz = getElement(); | |
82 | |
83 createConstructors(clazz); | |
84 createExecuteMethods(specialization); | |
85 | |
86 clazz.add(createUpdateTypes0()); | |
87 createCachedExecuteMethods(specialization); | |
88 } | |
89 | |
90 } | 85 } |