public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) { assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded."; Node cur = findRoot(currentNode); while (cur != null) { Class<?> curClass = cur.getClass(); if (curClass == otherMetadata.getSpecializationClass()) { return true; } else if (containsClass(otherMetadata.getExcludedBy(), cur)) { return true; } cur = getNext(cur); } return false; }
private static Class<?>[] mergeTypes(DSLNode node, Class<?>[] types) { Class<?>[] specializedTypes = node.getMetadata0().getSpecializedTypes(); if (specializedTypes.length == 0) { return null; } else if (types == null) { return Arrays.copyOf(specializedTypes, specializedTypes.length); } else { for (int i = 0; i < specializedTypes.length; i++) { if (specializedTypes[i] != types[i]) { types[i] = Object.class; } } return types; } }
private static boolean includes(Node oldNode, DSLNode newNode) { return containsClass(newNode.getMetadata0().getIncludes(), oldNode); }
private static <T extends Node & DSLNode> T appendPolymorphic(Node uninitialized, T newNode) { Class<?>[] includes = newNode.getMetadata0().getIncludes(); Node cur = getPrevious(uninitialized); Node prev = uninitialized; int depth = 0; Class<?>[] types = null; while (cur != null) { if (containsClass(includes, cur)) { cur.replace(prev, "Included in other specialization"); cur = prev; } else { depth++; types = mergeTypes((DSLNode) cur, types); } prev = cur; cur = getPrevious(cur); } assert prev.getCost() == NodeCost.POLYMORPHIC; updateSourceSection(prev, newNode); if (depth <= 1) { newNode.adoptChildren0(prev, null); return prev.replace(newNode, "Polymorphic to monomorphic."); } else { newNode.adoptChildren0(null, uninitialized); ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); return uninitialized.replace(newNode, "Appended polymorphic"); } }