Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java @ 18761:a665483c3881
Truffle-DSL: new node layout implementation.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Dec 2014 23:38:54 +0100 |
parents | 59bf50cc5a32 |
children | 15fe16c45d64 |
comparison
equal
deleted
inserted
replaced
18760:6fa3999631d8 | 18761:a665483c3881 |
---|---|
149 } | 149 } |
150 | 150 |
151 node.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, node).parse(elements))); | 151 node.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, node).parse(elements))); |
152 initializeChildren(node); | 152 initializeChildren(node); |
153 | 153 |
154 // ensure the processed element has at least one @Specialization annotation. | |
155 boolean foundSpecialization = false; | |
156 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { | |
157 if (ElementUtils.findAnnotationMirror(processingEnv, method, Specialization.class) != null) { | |
158 foundSpecialization = true; | |
159 break; | |
160 } | |
161 } | |
162 if (!foundSpecialization) { | |
163 return node; | |
164 } | |
165 | |
166 if (node.hasErrors()) { | |
167 return node; // error sync point | |
168 } | |
169 | |
154 node.getSpecializations().addAll(new SpecializationMethodParser(context, node).parse(elements)); | 170 node.getSpecializations().addAll(new SpecializationMethodParser(context, node).parse(elements)); |
155 node.getSpecializations().addAll(new GenericParser(context, node).parse(elements)); | 171 node.getSpecializations().addAll(new GenericParser(context, node).parse(elements)); |
156 node.getCasts().addAll(new CreateCastParser(context, node).parse(elements)); | 172 node.getCasts().addAll(new CreateCastParser(context, node).parse(elements)); |
157 node.getShortCircuits().addAll(new ShortCircuitParser(context, node).parse(elements)); | 173 node.getShortCircuits().addAll(new ShortCircuitParser(context, node).parse(elements)); |
158 | 174 |
222 | 238 |
223 TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value"); | 239 TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value"); |
224 final TypeSystemData typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true); | 240 final TypeSystemData typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true); |
225 if (typeSystem == null) { | 241 if (typeSystem == null) { |
226 NodeData nodeData = new NodeData(context, templateType); | 242 NodeData nodeData = new NodeData(context, templateType); |
227 nodeData.addError("The used type system '%s' is invalid or not a Node.", ElementUtils.getQualifiedName(typeSystemType)); | 243 nodeData.addError("The used type system '%s' is invalid. Fix errors in the type system first.", ElementUtils.getQualifiedName(typeSystemType)); |
228 return nodeData; | 244 return nodeData; |
229 } | 245 } |
230 | 246 |
231 List<String> assumptionsList = new ArrayList<>(); | 247 List<String> assumptionsList = new ArrayList<>(); |
232 for (int i = typeHierarchy.size() - 1; i >= 0; i--) { | 248 for (int i = typeHierarchy.size() - 1; i >= 0; i--) { |
563 initializeOrder(node); | 579 initializeOrder(node); |
564 initializePolymorphism(node); // requires specializations | 580 initializePolymorphism(node); // requires specializations |
565 initializeReachability(node); | 581 initializeReachability(node); |
566 initializeContains(node); | 582 initializeContains(node); |
567 | 583 |
568 if (!node.hasErrors()) { | 584 if (!node.hasErrors() && !node.getTypeSystem().getOptions().useNewLayout()) { |
569 initializeExceptions(node); | 585 initializeExceptions(node); |
570 } | 586 } |
571 resolveContains(node); | 587 resolveContains(node); |
588 | |
589 if (node.getTypeSystem().getOptions().useNewLayout()) { | |
590 List<SpecializationData> specializations = node.getSpecializations(); | |
591 for (SpecializationData cur : specializations) { | |
592 for (SpecializationData child : specializations) { | |
593 if (child != null && child != cur && child.getContains().contains(cur)) { | |
594 cur.getExcludedBy().add(child); | |
595 } | |
596 } | |
597 } | |
598 } | |
572 | 599 |
573 List<SpecializationData> needsId = new ArrayList<>(); | 600 List<SpecializationData> needsId = new ArrayList<>(); |
574 for (SpecializationData specialization : node.getSpecializations()) { | 601 for (SpecializationData specialization : node.getSpecializations()) { |
575 if (specialization.isGeneric()) { | 602 if (specialization.isFallback()) { |
576 specialization.setId("Generic"); | 603 specialization.setId("Generic"); |
577 } else if (specialization.isUninitialized()) { | 604 } else if (specialization.isUninitialized()) { |
578 specialization.setId("Uninitialized"); | 605 specialization.setId("Uninitialized"); |
579 } else if (specialization.isPolymorphic()) { | 606 } else if (specialization.isPolymorphic()) { |
580 specialization.setId("Polymorphic"); | 607 specialization.setId("Polymorphic"); |
641 } | 668 } |
642 } | 669 } |
643 | 670 |
644 private static void initializeExceptions(NodeData node) { | 671 private static void initializeExceptions(NodeData node) { |
645 List<SpecializationData> specializations = node.getSpecializations(); | 672 List<SpecializationData> specializations = node.getSpecializations(); |
673 | |
646 for (int i = 0; i < specializations.size(); i++) { | 674 for (int i = 0; i < specializations.size(); i++) { |
647 SpecializationData cur = specializations.get(i); | 675 SpecializationData cur = specializations.get(i); |
648 if (cur.getExceptions().isEmpty()) { | 676 if (cur.getExceptions().isEmpty()) { |
649 continue; | 677 continue; |
650 } | 678 } |
669 if (child != null && child != cur && child.getContains().contains(cur)) { | 697 if (child != null && child != cur && child.getContains().contains(cur)) { |
670 cur.getExcludedBy().add(child); | 698 cur.getExcludedBy().add(child); |
671 } | 699 } |
672 } | 700 } |
673 } | 701 } |
702 | |
674 } | 703 } |
675 | 704 |
676 private static void initializeContains(NodeData node) { | 705 private static void initializeContains(NodeData node) { |
677 for (SpecializationData specialization : node.getSpecializations()) { | 706 for (SpecializationData specialization : node.getSpecializations()) { |
678 Set<SpecializationData> resolvedSpecializations = specialization.getContains(); | 707 Set<SpecializationData> resolvedSpecializations = specialization.getContains(); |
769 for (SpecializationData shadowSpecialization : shadowedBy) { | 798 for (SpecializationData shadowSpecialization : shadowedBy) { |
770 name.append(sep); | 799 name.append(sep); |
771 name.append(shadowSpecialization.createReferenceName()); | 800 name.append(shadowSpecialization.createReferenceName()); |
772 sep = ", "; | 801 sep = ", "; |
773 } | 802 } |
774 current.addError("%s is not reachable. It is shadowed by %s.", current.isGeneric() ? "Generic" : "Specialization", name); | 803 current.addError("%s is not reachable. It is shadowed by %s.", current.isFallback() ? "Generic" : "Specialization", name); |
775 } | 804 } |
776 current.setReachable(shadowedBy == null); | 805 current.setReachable(shadowedBy == null); |
777 } | 806 } |
778 } | 807 } |
779 | 808 |
964 return; | 993 return; |
965 } | 994 } |
966 | 995 |
967 List<SpecializationData> generics = new ArrayList<>(); | 996 List<SpecializationData> generics = new ArrayList<>(); |
968 for (SpecializationData spec : node.getSpecializations()) { | 997 for (SpecializationData spec : node.getSpecializations()) { |
969 if (spec.isGeneric()) { | 998 if (spec.isFallback()) { |
970 generics.add(spec); | 999 generics.add(spec); |
971 } | 1000 } |
972 } | 1001 } |
973 | 1002 |
974 if (generics.size() == 1 && node.getSpecializations().size() == 1) { | 1003 if (generics.size() == 1 && node.getSpecializations().size() == 1) { |
1311 } | 1340 } |
1312 } | 1341 } |
1313 } | 1342 } |
1314 | 1343 |
1315 private void verifyConstructors(NodeData nodeData) { | 1344 private void verifyConstructors(NodeData nodeData) { |
1345 if (nodeData.getTypeSystem().getOptions().useNewLayout()) { | |
1346 List<ExecutableElement> constructors = ElementFilter.constructorsIn(nodeData.getTemplateType().getEnclosedElements()); | |
1347 if (constructors.isEmpty()) { | |
1348 return; | |
1349 } | |
1350 | |
1351 boolean oneNonPrivate = false; | |
1352 for (ExecutableElement constructor : constructors) { | |
1353 if (ElementUtils.getVisibility(constructor.getModifiers()) != Modifier.PRIVATE) { | |
1354 oneNonPrivate = true; | |
1355 break; | |
1356 } | |
1357 } | |
1358 if (!oneNonPrivate && !nodeData.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) { | |
1359 nodeData.addError("At least one constructor must be non-private."); | |
1360 } | |
1361 return; | |
1362 } | |
1316 if (!nodeData.needsRewrites(context)) { | 1363 if (!nodeData.needsRewrites(context)) { |
1317 // no specialization constructor is needed if the node never rewrites. | 1364 // no specialization constructor is needed if the node never rewrites. |
1318 return; | 1365 return; |
1319 } | 1366 } |
1320 | 1367 |