Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeData.java @ 13528:5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 07 Jan 2014 18:52:32 +0100 |
parents | 25ecb47a6d0e |
children | e8ef44830b50 |
comparison
equal
deleted
inserted
replaced
13527:25ecb47a6d0e | 13528:5a0c694ef735 |
---|---|
32 import com.oracle.truffle.dsl.processor.typesystem.*; | 32 import com.oracle.truffle.dsl.processor.typesystem.*; |
33 | 33 |
34 public class NodeData extends Template implements Comparable<NodeData> { | 34 public class NodeData extends Template implements Comparable<NodeData> { |
35 | 35 |
36 private final String nodeId; | 36 private final String nodeId; |
37 private final String shortName; | |
38 private final List<NodeData> enclosingNodes = new ArrayList<>(); | |
37 private NodeData declaringNode; | 39 private NodeData declaringNode; |
38 private List<NodeData> declaredNodes = new ArrayList<>(); | 40 |
39 private boolean nodeContainer; | 41 private final TypeSystemData typeSystem; |
40 | 42 private final List<NodeChildData> children; |
41 private TypeSystemData typeSystem; | 43 private final List<NodeExecutionData> childExecutions; |
42 private List<NodeChildData> children; | 44 private final List<NodeFieldData> fields; |
43 private List<NodeExecutionData> childExecutions; | 45 private final List<String> assumptions; |
44 private List<NodeFieldData> fields; | 46 |
45 private TypeMirror nodeType; | |
46 private ParameterSpec instanceParameterSpec; | 47 private ParameterSpec instanceParameterSpec; |
47 | 48 |
48 private List<SpecializationData> specializations; | 49 private final List<SpecializationData> specializations = new ArrayList<>(); |
49 private List<SpecializationData> polymorphicSpecializations; | 50 private final List<ShortCircuitData> shortCircuits = new ArrayList<>(); |
50 private SpecializationData genericPolymorphicSpecialization; | 51 private final List<CreateCastData> casts = new ArrayList<>(); |
51 private List<SpecializationListenerData> specializationListeners; | |
52 private Map<Integer, List<ExecutableTypeData>> executableTypes; | 52 private Map<Integer, List<ExecutableTypeData>> executableTypes; |
53 private List<ShortCircuitData> shortCircuits; | |
54 private List<String> assumptions; | |
55 private List<CreateCastData> casts; | |
56 | 53 |
57 private int polymorphicDepth = -1; | 54 private int polymorphicDepth = -1; |
58 private String shortName; | 55 |
59 | 56 public NodeData(TypeElement type, String shortName, TypeSystemData typeSystem, List<NodeChildData> children, List<NodeExecutionData> executions, List<NodeFieldData> fields, |
60 public NodeData(TypeElement type, String id) { | 57 List<String> assumptions, int polymorphicDepth) { |
61 super(type, null, null); | 58 super(type, null, null); |
62 this.nodeId = id; | 59 this.nodeId = type.getSimpleName().toString(); |
63 } | 60 this.shortName = shortName; |
64 | 61 this.typeSystem = typeSystem; |
65 public NodeData(NodeData splitSource, String templateMethodName, String nodeId) { | 62 this.fields = fields; |
66 super(splitSource.getTemplateType(), templateMethodName, null); | 63 this.children = children; |
67 this.nodeId = nodeId; | 64 this.childExecutions = executions; |
68 this.declaringNode = splitSource.declaringNode; | 65 this.assumptions = assumptions; |
69 this.declaredNodes = splitSource.declaredNodes; | 66 this.polymorphicDepth = polymorphicDepth; |
70 this.typeSystem = splitSource.typeSystem; | 67 |
71 this.nodeType = splitSource.nodeType; | 68 if (children != null) { |
72 this.specializations = splitSource.specializations; | 69 for (NodeChildData child : children) { |
73 this.specializationListeners = splitSource.specializationListeners; | 70 child.setParentNode(this); |
74 this.executableTypes = splitSource.executableTypes; | 71 } |
75 this.shortCircuits = splitSource.shortCircuits; | 72 } |
76 this.fields = splitSource.fields; | 73 } |
77 this.children = splitSource.children; | 74 |
78 this.assumptions = splitSource.assumptions; | 75 public NodeData(TypeElement type) { |
76 this(type, null, null, null, null, null, null, -1); | |
77 } | |
78 | |
79 public void addEnclosedNode(NodeData node) { | |
80 this.enclosingNodes.add(node); | |
81 node.declaringNode = this; | |
79 } | 82 } |
80 | 83 |
81 public List<NodeExecutionData> getChildExecutions() { | 84 public List<NodeExecutionData> getChildExecutions() { |
82 return childExecutions; | 85 return childExecutions; |
83 } | |
84 | |
85 void setChildExecutions(List<NodeExecutionData> signature) { | |
86 this.childExecutions = signature; | |
87 } | 86 } |
88 | 87 |
89 public int getSignatureSize() { | 88 public int getSignatureSize() { |
90 if (getSpecializations() != null && !getSpecializations().isEmpty()) { | 89 if (getSpecializations() != null && !getSpecializations().isEmpty()) { |
91 return getSpecializations().get(0).getSignatureSize(); | 90 return getSpecializations().get(0).getSignatureSize(); |
120 | 119 |
121 public boolean isPolymorphic() { | 120 public boolean isPolymorphic() { |
122 return polymorphicDepth > 1; | 121 return polymorphicDepth > 1; |
123 } | 122 } |
124 | 123 |
125 void setPolymorphicDepth(int polymorphicDepth) { | 124 public void setPolymorphicDepth(int polymorphicDepth) { |
126 this.polymorphicDepth = polymorphicDepth; | 125 this.polymorphicDepth = polymorphicDepth; |
127 } | 126 } |
128 | 127 |
129 public List<CreateCastData> getCasts() { | 128 public List<CreateCastData> getCasts() { |
130 return casts; | 129 return casts; |
131 } | 130 } |
132 | 131 |
133 void setCasts(List<CreateCastData> casts) { | |
134 this.casts = casts; | |
135 } | |
136 | |
137 void setShortName(String shortName) { | |
138 this.shortName = shortName; | |
139 } | |
140 | |
141 public String getShortName() { | 132 public String getShortName() { |
142 return shortName; | 133 return shortName; |
143 } | 134 } |
144 | 135 |
145 public boolean isNodeContainer() { | |
146 return nodeContainer; | |
147 } | |
148 | |
149 void setTypeSystem(TypeSystemData typeSystem) { | |
150 this.typeSystem = typeSystem; | |
151 } | |
152 | |
153 void setFields(List<NodeFieldData> fields) { | |
154 this.fields = fields; | |
155 } | |
156 | |
157 public List<NodeFieldData> getFields() { | 136 public List<NodeFieldData> getFields() { |
158 return fields; | 137 return fields; |
159 } | |
160 | |
161 void setNodeContainer(boolean splitByMethodName) { | |
162 this.nodeContainer = splitByMethodName; | |
163 } | 138 } |
164 | 139 |
165 @Override | 140 @Override |
166 protected List<MessageContainer> findChildContainers() { | 141 protected List<MessageContainer> findChildContainers() { |
167 List<MessageContainer> containerChildren = new ArrayList<>(); | 142 List<MessageContainer> containerChildren = new ArrayList<>(); |
168 if (declaredNodes != null) { | 143 if (enclosingNodes != null) { |
169 containerChildren.addAll(declaredNodes); | 144 containerChildren.addAll(enclosingNodes); |
170 } | 145 } |
171 if (typeSystem != null) { | 146 if (typeSystem != null) { |
172 containerChildren.add(typeSystem); | 147 containerChildren.add(typeSystem); |
173 } | 148 } |
174 if (specializations != null) { | 149 if (specializations != null) { |
176 if (specialization.getMessageElement() != null) { | 151 if (specialization.getMessageElement() != null) { |
177 containerChildren.add(specialization); | 152 containerChildren.add(specialization); |
178 } | 153 } |
179 } | 154 } |
180 } | 155 } |
181 if (specializationListeners != null) { | |
182 containerChildren.addAll(specializationListeners); | |
183 } | |
184 if (executableTypes != null) { | 156 if (executableTypes != null) { |
185 containerChildren.addAll(getExecutableTypes()); | 157 containerChildren.addAll(getExecutableTypes()); |
186 } | 158 } |
187 if (shortCircuits != null) { | 159 if (shortCircuits != null) { |
188 containerChildren.addAll(shortCircuits); | 160 containerChildren.addAll(shortCircuits); |
210 public String getNodeId() { | 182 public String getNodeId() { |
211 return nodeId; | 183 return nodeId; |
212 } | 184 } |
213 | 185 |
214 public TypeMirror getNodeType() { | 186 public TypeMirror getNodeType() { |
215 if (nodeType != null) { | |
216 return nodeType; | |
217 } | |
218 return getTemplateType().asType(); | 187 return getTemplateType().asType(); |
219 } | |
220 | |
221 void setAssumptions(List<String> assumptions) { | |
222 this.assumptions = assumptions; | |
223 } | 188 } |
224 | 189 |
225 public List<String> getAssumptions() { | 190 public List<String> getAssumptions() { |
226 return assumptions; | 191 return assumptions; |
227 } | 192 } |
234 return false; | 199 return false; |
235 } | 200 } |
236 | 201 |
237 boolean noSpecialization = true; | 202 boolean noSpecialization = true; |
238 for (SpecializationData specialization : specializations) { | 203 for (SpecializationData specialization : specializations) { |
239 noSpecialization = noSpecialization && specialization.isGeneric() || specialization.isUninitialized(); | 204 noSpecialization = noSpecialization && !specialization.isSpecialized(); |
240 } | 205 } |
241 return !noSpecialization; | 206 return !noSpecialization; |
242 } | 207 } |
243 | 208 |
244 public boolean supportsFrame() { | 209 public boolean supportsFrame() { |
252 return true; | 217 return true; |
253 } | 218 } |
254 | 219 |
255 public List<NodeData> getNodeDeclaringChildren() { | 220 public List<NodeData> getNodeDeclaringChildren() { |
256 List<NodeData> nodeChildren = new ArrayList<>(); | 221 List<NodeData> nodeChildren = new ArrayList<>(); |
257 for (NodeData child : getDeclaredNodes()) { | 222 for (NodeData child : getEnclosingNodes()) { |
258 if (child.needsFactory()) { | 223 if (child.needsFactory()) { |
259 nodeChildren.add(child); | 224 nodeChildren.add(child); |
260 } | 225 } |
261 nodeChildren.addAll(child.getNodeDeclaringChildren()); | 226 nodeChildren.addAll(child.getNodeDeclaringChildren()); |
262 } | 227 } |
263 return nodeChildren; | 228 return nodeChildren; |
264 } | 229 } |
265 | 230 |
266 void setDeclaredNodes(List<NodeData> declaredChildren) { | 231 public NodeData getDeclaringNode() { |
267 this.declaredNodes = declaredChildren; | |
268 | |
269 for (NodeData child : declaredChildren) { | |
270 child.declaringNode = this; | |
271 } | |
272 } | |
273 | |
274 public NodeData getParent() { | |
275 return declaringNode; | 232 return declaringNode; |
276 } | 233 } |
277 | 234 |
278 public List<NodeData> getDeclaredNodes() { | 235 public List<NodeData> getEnclosingNodes() { |
279 return declaredNodes; | 236 return enclosingNodes; |
280 } | |
281 | |
282 public void setNodeType(TypeMirror nodeType) { | |
283 this.nodeType = nodeType; | |
284 } | 237 } |
285 | 238 |
286 public List<TemplateMethod> getAllTemplateMethods() { | 239 public List<TemplateMethod> getAllTemplateMethods() { |
287 List<TemplateMethod> methods = new ArrayList<>(); | 240 List<TemplateMethod> methods = new ArrayList<>(); |
288 | 241 |
289 for (SpecializationData specialization : getSpecializations()) { | 242 for (SpecializationData specialization : getSpecializations()) { |
290 methods.add(specialization); | 243 methods.add(specialization); |
291 } | 244 } |
292 | 245 |
293 methods.addAll(getSpecializationListeners()); | |
294 methods.addAll(getExecutableTypes()); | 246 methods.addAll(getExecutableTypes()); |
295 methods.addAll(getShortCircuits()); | 247 methods.addAll(getShortCircuits()); |
296 if (getCasts() != null) { | 248 if (getCasts() != null) { |
297 methods.addAll(getCasts()); | 249 methods.addAll(getCasts()); |
298 } | 250 } |
392 } | 344 } |
393 } | 345 } |
394 return needsRewrites || getSpecializations().size() > 1; | 346 return needsRewrites || getSpecializations().size() > 1; |
395 } | 347 } |
396 | 348 |
349 public SpecializationData getPolymorphicSpecialization() { | |
350 for (SpecializationData specialization : specializations) { | |
351 if (specialization.isPolymorphic()) { | |
352 return specialization; | |
353 } | |
354 } | |
355 return null; | |
356 } | |
357 | |
397 public SpecializationData getGenericSpecialization() { | 358 public SpecializationData getGenericSpecialization() { |
398 for (SpecializationData specialization : specializations) { | 359 for (SpecializationData specialization : specializations) { |
399 if (specialization.isGeneric()) { | 360 if (specialization.isGeneric()) { |
400 return specialization; | 361 return specialization; |
401 } | 362 } |
434 dumpProperty(builder, indent, "typeSystem", getTypeSystem()); | 395 dumpProperty(builder, indent, "typeSystem", getTypeSystem()); |
435 dumpProperty(builder, indent, "fields", getChildren()); | 396 dumpProperty(builder, indent, "fields", getChildren()); |
436 dumpProperty(builder, indent, "executableTypes", getExecutableTypes()); | 397 dumpProperty(builder, indent, "executableTypes", getExecutableTypes()); |
437 dumpProperty(builder, indent, "specializations", getSpecializations()); | 398 dumpProperty(builder, indent, "specializations", getSpecializations()); |
438 dumpProperty(builder, indent, "polymorphicDepth", getPolymorphicDepth()); | 399 dumpProperty(builder, indent, "polymorphicDepth", getPolymorphicDepth()); |
439 dumpProperty(builder, indent, "polymorphic", getPolymorphicSpecializations()); | |
440 dumpProperty(builder, indent, "assumptions", getAssumptions()); | 400 dumpProperty(builder, indent, "assumptions", getAssumptions()); |
441 dumpProperty(builder, indent, "casts", getCasts()); | 401 dumpProperty(builder, indent, "casts", getCasts()); |
442 dumpProperty(builder, indent, "messages", collectMessages()); | 402 dumpProperty(builder, indent, "messages", collectMessages()); |
443 if (getDeclaredNodes().size() > 0) { | 403 if (getEnclosingNodes().size() > 0) { |
444 builder.append(String.format("\n%s children = [", indent)); | 404 builder.append(String.format("\n%s children = [", indent)); |
445 for (NodeData node : getDeclaredNodes()) { | 405 for (NodeData node : getEnclosingNodes()) { |
446 builder.append("\n"); | 406 builder.append("\n"); |
447 builder.append(node.dump(level + 1)); | 407 builder.append(node.dump(level + 1)); |
448 } | 408 } |
449 builder.append(String.format("\n%s ]", indent)); | 409 builder.append(String.format("\n%s ]", indent)); |
450 } | 410 } |
511 | 471 |
512 public List<NodeChildData> getChildren() { | 472 public List<NodeChildData> getChildren() { |
513 return children; | 473 return children; |
514 } | 474 } |
515 | 475 |
516 void setChildren(List<NodeChildData> fields) { | |
517 this.children = fields; | |
518 } | |
519 | |
520 public List<SpecializationData> getSpecializations() { | 476 public List<SpecializationData> getSpecializations() { |
521 return getSpecializations(false); | 477 return specializations; |
522 } | |
523 | |
524 public List<SpecializationData> getSpecializations(boolean userDefinedOnly) { | |
525 if (userDefinedOnly) { | |
526 List<SpecializationData> specs = new ArrayList<>(); | |
527 for (SpecializationData spec : specializations) { | |
528 if (spec.getMethod() != null) { | |
529 specs.add(spec); | |
530 } | |
531 } | |
532 return specs; | |
533 } else { | |
534 return specializations; | |
535 } | |
536 } | |
537 | |
538 public List<SpecializationListenerData> getSpecializationListeners() { | |
539 return specializationListeners; | |
540 } | 478 } |
541 | 479 |
542 public List<ExecutableTypeData> getExecutableTypes() { | 480 public List<ExecutableTypeData> getExecutableTypes() { |
543 return getExecutableTypes(-1); | 481 return getExecutableTypes(-1); |
544 } | 482 } |
545 | 483 |
546 public List<ShortCircuitData> getShortCircuits() { | 484 public List<ShortCircuitData> getShortCircuits() { |
547 return shortCircuits; | 485 return shortCircuits; |
548 } | 486 } |
549 | 487 |
550 void setSpecializations(List<SpecializationData> specializations) { | 488 public void setExecutableTypes(Map<Integer, List<ExecutableTypeData>> executableTypes) { |
551 this.specializations = specializations; | |
552 if (this.specializations != null) { | |
553 for (SpecializationData specialization : specializations) { | |
554 specialization.setNode(this); | |
555 } | |
556 } | |
557 } | |
558 | |
559 void setPolymorphicSpecializations(List<SpecializationData> polymorphicSpecializations) { | |
560 this.polymorphicSpecializations = polymorphicSpecializations; | |
561 } | |
562 | |
563 public List<SpecializationData> getPolymorphicSpecializations() { | |
564 return polymorphicSpecializations; | |
565 } | |
566 | |
567 void setGenericPolymorphicSpecialization(SpecializationData genericPolymoprhicSpecialization) { | |
568 this.genericPolymorphicSpecialization = genericPolymoprhicSpecialization; | |
569 } | |
570 | |
571 public SpecializationData getGenericPolymorphicSpecialization() { | |
572 return genericPolymorphicSpecialization; | |
573 } | |
574 | |
575 void setSpecializationListeners(List<SpecializationListenerData> specializationListeners) { | |
576 this.specializationListeners = specializationListeners; | |
577 } | |
578 | |
579 void setExecutableTypes(Map<Integer, List<ExecutableTypeData>> executableTypes) { | |
580 this.executableTypes = executableTypes; | 489 this.executableTypes = executableTypes; |
581 } | |
582 | |
583 void setShortCircuits(List<ShortCircuitData> shortCircuits) { | |
584 this.shortCircuits = shortCircuits; | |
585 } | 490 } |
586 | 491 |
587 @Override | 492 @Override |
588 public String toString() { | 493 public String toString() { |
589 return getClass().getSimpleName() + "[" + getNodeId() + "]"; | 494 return getClass().getSimpleName() + "[" + getNodeId() + "]"; |