Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java @ 8252:0905d796944a
Refactored codegen error model to make error redirection a lot easier.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 13 Mar 2013 19:58:28 +0100 |
parents | cb70ed101b5f |
children | cc83fc474fd5 |
comparison
equal
deleted
inserted
replaced
8251:cb70ed101b5f | 8252:0905d796944a |
---|---|
37 | 37 |
38 private final String nodeId; | 38 private final String nodeId; |
39 private NodeData declaringNode; | 39 private NodeData declaringNode; |
40 private List<NodeData> declaredChildren = new ArrayList<>(); | 40 private List<NodeData> declaredChildren = new ArrayList<>(); |
41 | 41 |
42 private final TypeSystemData typeSystem; | 42 private TypeSystemData typeSystem; |
43 private List<NodeFieldData> fields; | 43 private List<NodeFieldData> fields; |
44 private TypeMirror nodeType; | 44 private TypeMirror nodeType; |
45 private ParameterSpec instanceParameterSpec; | 45 private ParameterSpec instanceParameterSpec; |
46 | 46 |
47 private List<SpecializationData> specializations; | 47 private List<SpecializationData> specializations; |
48 private List<SpecializationListenerData> specializationListeners; | 48 private List<SpecializationListenerData> specializationListeners; |
49 private List<GuardData> guards; | 49 private List<GuardData> guards; |
50 private List<ExecutableTypeData> executableTypes; | 50 private List<ExecutableTypeData> executableTypes; |
51 private List<ShortCircuitData> shortCircuits; | 51 private List<ShortCircuitData> shortCircuits; |
52 | 52 |
53 public NodeData(TypeElement type, TypeSystemData typeSystem, String id) { | 53 public NodeData(TypeElement type, String id) { |
54 super(type, null, null); | 54 super(type, null, null); |
55 this.nodeId = id; | 55 this.nodeId = id; |
56 } | |
57 | |
58 public NodeData(NodeData splitSource, String templateMethodName, String nodeId) { | |
59 super(splitSource.getTemplateType(), templateMethodName, null); | |
60 this.nodeId = nodeId; | |
61 this.declaringNode = splitSource.declaringNode; | |
62 this.declaredChildren = splitSource.declaredChildren; | |
63 this.typeSystem = splitSource.typeSystem; | |
64 this.nodeType = splitSource.nodeType; | |
65 this.specializations = splitSource.specializations; | |
66 this.specializationListeners = splitSource.specializationListeners; | |
67 this.guards = splitSource.guards; | |
68 this.executableTypes = splitSource.executableTypes; | |
69 this.shortCircuits = splitSource.shortCircuits; | |
70 this.fields = splitSource.fields; | |
71 } | |
72 | |
73 void setTypeSystem(TypeSystemData typeSystem) { | |
56 this.typeSystem = typeSystem; | 74 this.typeSystem = typeSystem; |
57 } | 75 } |
58 | 76 |
59 public NodeData(NodeData copy, String templateMethodName, String nodeId) { | 77 @Override |
60 super(copy.getTemplateType(), templateMethodName, null); | 78 protected List<MessageContainer> findChildContainers() { |
61 this.nodeId = nodeId; | 79 List<MessageContainer> sinks = new ArrayList<>(); |
62 this.declaringNode = copy.declaringNode; | 80 if (declaredChildren != null) { |
63 this.declaredChildren = copy.declaredChildren; | 81 sinks.addAll(declaredChildren); |
64 this.typeSystem = copy.typeSystem; | 82 } |
65 this.nodeType = copy.nodeType; | 83 if (typeSystem != null) { |
66 this.specializations = copy.specializations; | 84 sinks.add(typeSystem); |
67 this.specializationListeners = copy.specializationListeners; | 85 } |
68 this.guards = copy.guards; | 86 if (specializations != null) { |
69 this.executableTypes = copy.executableTypes; | 87 sinks.addAll(specializations); |
70 this.shortCircuits = copy.shortCircuits; | 88 } |
71 this.fields = copy.fields; | 89 if (specializationListeners != null) { |
90 sinks.addAll(specializationListeners); | |
91 } | |
92 if (guards != null) { | |
93 sinks.addAll(guards); | |
94 } | |
95 if (executableTypes != null) { | |
96 sinks.addAll(executableTypes); | |
97 } | |
98 if (shortCircuits != null) { | |
99 sinks.addAll(shortCircuits); | |
100 } | |
101 if (fields != null) { | |
102 sinks.addAll(fields); | |
103 } | |
104 return sinks; | |
72 } | 105 } |
73 | 106 |
74 public ParameterSpec getInstanceParameterSpec() { | 107 public ParameterSpec getInstanceParameterSpec() { |
75 return instanceParameterSpec; | 108 return instanceParameterSpec; |
76 } | 109 } |
144 public List<TemplateMethod> getAllTemplateMethods() { | 177 public List<TemplateMethod> getAllTemplateMethods() { |
145 List<TemplateMethod> methods = new ArrayList<>(); | 178 List<TemplateMethod> methods = new ArrayList<>(); |
146 | 179 |
147 for (SpecializationData specialization : getSpecializations()) { | 180 for (SpecializationData specialization : getSpecializations()) { |
148 methods.add(specialization); | 181 methods.add(specialization); |
149 if (specialization.getShortCircuits() != null) { | |
150 methods.addAll(Arrays.asList(specialization.getShortCircuits())); | |
151 } | |
152 } | 182 } |
153 | 183 |
154 methods.addAll(getSpecializationListeners()); | 184 methods.addAll(getSpecializationListeners()); |
155 methods.addAll(getExecutableTypes()); | 185 methods.addAll(getExecutableTypes()); |
156 methods.addAll(getGuards()); | 186 methods.addAll(getGuards()); |
269 } | 299 } |
270 return null; | 300 return null; |
271 } | 301 } |
272 | 302 |
273 public TypeSystemData getTypeSystem() { | 303 public TypeSystemData getTypeSystem() { |
274 if (typeSystem != null) { | 304 return typeSystem; |
275 return typeSystem; | 305 } |
306 | |
307 public String dump() { | |
308 return dump(0); | |
309 } | |
310 | |
311 private String dump(int level) { | |
312 String indent = ""; | |
313 for (int i = 0; i < level; i++) { | |
314 indent += " "; | |
315 } | |
316 StringBuilder builder = new StringBuilder(); | |
317 | |
318 builder.append(String.format("%s%s {", indent, toString())); | |
319 | |
320 dumpProperty(builder, indent, "templateClass", Utils.getQualifiedName(getTemplateType())); | |
321 dumpProperty(builder, indent, "typeSystem", getTypeSystem()); | |
322 dumpProperty(builder, indent, "fields", getFields()); | |
323 dumpProperty(builder, indent, "executableTypes", getExecutableTypes()); | |
324 dumpProperty(builder, indent, "specializations", getSpecializations()); | |
325 dumpProperty(builder, indent, "guards", getGuards()); | |
326 dumpProperty(builder, indent, "messages", collectMessages()); | |
327 if (getDeclaredChildren().size() > 0) { | |
328 builder.append(String.format("\n%s children = [", indent)); | |
329 for (NodeData node : getDeclaredChildren()) { | |
330 builder.append("\n"); | |
331 builder.append(node.dump(level + 1)); | |
332 } | |
333 builder.append(String.format("\n%s ]", indent)); | |
334 } | |
335 builder.append(String.format("%s}", indent)); | |
336 return builder.toString(); | |
337 } | |
338 | |
339 private static void dumpProperty(StringBuilder b, String indent, String propertyName, Object value) { | |
340 if (value instanceof List) { | |
341 List<?> list = (List<?>) value; | |
342 if (!list.isEmpty()) { | |
343 b.append(String.format("\n%s %s = %s", indent, propertyName, dumpList((List<?>) value))); | |
344 } | |
276 } else { | 345 } else { |
277 return null; | 346 if (value != null) { |
278 } | 347 b.append(String.format("\n%s %s = %s", indent, propertyName, value)); |
279 } | 348 } |
280 | 349 } |
281 public String dump() { | |
282 StringBuilder b = new StringBuilder(); | |
283 b.append(String.format("[id = %s, name = %s\n typeSystem = %s\n fields = %s\n types = %s\n specializations = %s\n guards = %s\n enclosing = %s\n enclosed = %s\n]", getNodeId(), | |
284 Utils.getQualifiedName(getTemplateType()), getTypeSystem(), dumpList(fields), dumpList(getExecutableTypes()), dumpList(getSpecializations()), dumpList(guards), | |
285 dumpList(getDeclaredChildren()), getParent())); | |
286 return b.toString(); | |
287 } | 350 } |
288 | 351 |
289 private static String dumpList(List<?> array) { | 352 private static String dumpList(List<?> array) { |
290 if (array == null) { | 353 if (array == null) { |
291 return "null"; | 354 return "null"; |
355 } | |
356 | |
357 if (array.isEmpty()) { | |
358 return "[]"; | |
359 } else if (array.size() == 1) { | |
360 return "[" + array.get(0).toString() + "]"; | |
292 } | 361 } |
293 | 362 |
294 StringBuilder b = new StringBuilder(); | 363 StringBuilder b = new StringBuilder(); |
295 b.append("["); | 364 b.append("["); |
296 for (Object object : array) { | 365 for (Object object : array) { |