Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java @ 19282:ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 22 Jan 2015 20:44:24 +0100 |
parents | d2ec5f50dcd0 |
children | 08aa0372dad4 |
comparison
equal
deleted
inserted
replaced
19281:92880b0f7fed | 19282:ae81dd154fb6 |
---|---|
693 initializeOrder(node); | 693 initializeOrder(node); |
694 initializePolymorphism(node); // requires specializations | 694 initializePolymorphism(node); // requires specializations |
695 initializeReachability(node); | 695 initializeReachability(node); |
696 initializeContains(node); | 696 initializeContains(node); |
697 | 697 |
698 if (!node.hasErrors() && !node.getTypeSystem().getOptions().useNewLayout()) { | |
699 initializeExceptions(node); | |
700 } | |
701 resolveContains(node); | 698 resolveContains(node); |
702 | 699 |
703 if (node.getTypeSystem().getOptions().useNewLayout()) { | 700 List<SpecializationData> specializations = node.getSpecializations(); |
704 List<SpecializationData> specializations = node.getSpecializations(); | 701 for (SpecializationData cur : specializations) { |
705 for (SpecializationData cur : specializations) { | 702 for (SpecializationData child : specializations) { |
706 for (SpecializationData child : specializations) { | 703 if (child != null && child != cur && child.getContains().contains(cur)) { |
707 if (child != null && child != cur && child.getContains().contains(cur)) { | 704 cur.getExcludedBy().add(child); |
708 cur.getExcludedBy().add(child); | |
709 } | |
710 } | 705 } |
711 } | 706 } |
712 } | 707 } |
713 | 708 |
714 // verify specialization parameter length | 709 // verify specialization parameter length |
759 } | 754 } |
760 | 755 |
761 for (int i = 0; i < specializations.size(); i++) { | 756 for (int i = 0; i < specializations.size(); i++) { |
762 specializations.get(i).setIndex(i); | 757 specializations.get(i).setIndex(i); |
763 } | 758 } |
764 } | |
765 | |
766 private static void initializeExceptions(NodeData node) { | |
767 List<SpecializationData> specializations = node.getSpecializations(); | |
768 | |
769 for (int i = 0; i < specializations.size(); i++) { | |
770 SpecializationData cur = specializations.get(i); | |
771 if (cur.getExceptions().isEmpty()) { | |
772 continue; | |
773 } | |
774 SpecializationData next = i + 1 < specializations.size() ? specializations.get(i + 1) : null; | |
775 | |
776 if (!cur.isContainedBy(next)) { | |
777 next.addError("This specialiation is not a valid exceptional rewrite target for %s. To fix this make %s compatible to %s or remove the exceptional rewrite.", | |
778 cur.createReferenceName(), next != null ? next.createReferenceName() : "-", cur.createReferenceName()); | |
779 continue; | |
780 } | |
781 Set<SpecializationData> nextContains = next != null ? next.getContains() : Collections.<SpecializationData> emptySet(); | |
782 if (!nextContains.contains(cur)) { | |
783 nextContains.add(cur); | |
784 } | |
785 } | |
786 | |
787 for (SpecializationData cur : specializations) { | |
788 if (cur.getExceptions().isEmpty()) { | |
789 continue; | |
790 } | |
791 for (SpecializationData child : specializations) { | |
792 if (child != null && child != cur && child.getContains().contains(cur)) { | |
793 cur.getExcludedBy().add(child); | |
794 } | |
795 } | |
796 } | |
797 | |
798 } | 759 } |
799 | 760 |
800 private static void initializeContains(NodeData node) { | 761 private static void initializeContains(NodeData node) { |
801 for (SpecializationData specialization : node.getSpecializations()) { | 762 for (SpecializationData specialization : node.getSpecializations()) { |
802 Set<SpecializationData> resolvedSpecializations = specialization.getContains(); | 763 Set<SpecializationData> resolvedSpecializations = specialization.getContains(); |
1390 } | 1351 } |
1391 } | 1352 } |
1392 } | 1353 } |
1393 } | 1354 } |
1394 | 1355 |
1395 private void verifyConstructors(NodeData nodeData) { | 1356 private static void verifyConstructors(NodeData nodeData) { |
1396 if (nodeData.getTypeSystem().getOptions().useNewLayout()) { | 1357 List<ExecutableElement> constructors = ElementFilter.constructorsIn(nodeData.getTemplateType().getEnclosedElements()); |
1397 List<ExecutableElement> constructors = ElementFilter.constructorsIn(nodeData.getTemplateType().getEnclosedElements()); | 1358 if (constructors.isEmpty()) { |
1398 if (constructors.isEmpty()) { | |
1399 return; | |
1400 } | |
1401 | |
1402 boolean oneNonPrivate = false; | |
1403 for (ExecutableElement constructor : constructors) { | |
1404 if (ElementUtils.getVisibility(constructor.getModifiers()) != Modifier.PRIVATE) { | |
1405 oneNonPrivate = true; | |
1406 break; | |
1407 } | |
1408 } | |
1409 if (!oneNonPrivate && !nodeData.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) { | |
1410 nodeData.addError("At least one constructor must be non-private."); | |
1411 } | |
1412 return; | 1359 return; |
1413 } | 1360 } |
1414 if (!nodeData.needsRewrites(context)) { | 1361 |
1415 // no specialization constructor is needed if the node never rewrites. | 1362 boolean oneNonPrivate = false; |
1416 return; | |
1417 } | |
1418 | |
1419 TypeElement type = ElementUtils.fromTypeMirror(nodeData.getNodeType()); | |
1420 List<ExecutableElement> constructors = ElementFilter.constructorsIn(type.getEnclosedElements()); | |
1421 | |
1422 boolean parametersFound = false; | |
1423 for (ExecutableElement constructor : constructors) { | 1363 for (ExecutableElement constructor : constructors) { |
1424 if (!constructor.getParameters().isEmpty() && !isSourceSectionConstructor(context, constructor)) { | 1364 if (ElementUtils.getVisibility(constructor.getModifiers()) != Modifier.PRIVATE) { |
1425 parametersFound = true; | 1365 oneNonPrivate = true; |
1426 } | 1366 break; |
1427 } | 1367 } |
1428 if (!parametersFound) { | 1368 } |
1429 return; | 1369 if (!oneNonPrivate && !nodeData.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) { |
1430 } | 1370 nodeData.addError("At least one constructor must be non-private."); |
1431 for (ExecutableElement e : constructors) { | 1371 } |
1432 if (e.getParameters().size() == 1) { | |
1433 TypeMirror firstArg = e.getParameters().get(0).asType(); | |
1434 if (ElementUtils.typeEquals(firstArg, nodeData.getNodeType())) { | |
1435 if (e.getModifiers().contains(Modifier.PRIVATE)) { | |
1436 nodeData.addError("The specialization constructor must not be private."); | |
1437 } else if (constructors.size() <= 1) { | |
1438 nodeData.addError("The specialization constructor must not be the only constructor. The definition of an alternative constructor is required."); | |
1439 } | |
1440 return; | |
1441 } | |
1442 } | |
1443 } | |
1444 | |
1445 // not found | |
1446 nodeData.addError("Specialization constructor '%s(%s previousNode) { this(...); }' is required.", ElementUtils.getSimpleName(type), ElementUtils.getSimpleName(type)); | |
1447 } | |
1448 | |
1449 public static boolean isSourceSectionConstructor(ProcessorContext context, ExecutableElement constructor) { | |
1450 return constructor.getParameters().size() == 1 && ElementUtils.typeEquals(constructor.getParameters().get(0).asType(), context.getTruffleTypes().getSourceSection()); | |
1451 } | 1372 } |
1452 | 1373 |
1453 private AnnotationMirror findFirstAnnotation(List<? extends Element> elements, Class<? extends Annotation> annotation) { | 1374 private AnnotationMirror findFirstAnnotation(List<? extends Element> elements, Class<? extends Annotation> annotation) { |
1454 for (Element element : elements) { | 1375 for (Element element : elements) { |
1455 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, element, annotation); | 1376 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, element, annotation); |