private List<GuardExpression> findElseConnectableGuards() { if (!getTypeGuards().isEmpty()) { return Collections.emptyList(); } if (getGuards().isEmpty()) { return Collections.emptyList(); } List<GuardExpression> elseConnectableGuards = new ArrayList<>(); int guardIndex = 0; while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex)) != null) { elseConnectableGuards.add(getGuards().get(guardIndex)); guardIndex++; } return elseConnectableGuards; }
public List<GuardExpression> findElseConnectableGuards() { if (!getTypeGuards().isEmpty()) { return Collections.emptyList(); } if (getGuards().isEmpty()) { return Collections.emptyList(); } List<GuardExpression> elseConnectableGuards = new ArrayList<>(); int guardIndex = 0; while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex)) != null) { elseConnectableGuards.add(getGuards().get(guardIndex)); guardIndex++; } return elseConnectableGuards; }
private GuardExpression findNegatedGuardInPrevious(GuardExpression guard) { SpecializationGroup previous = this.getPreviousGroup(); if (previous == null) { return null; } List<GuardExpression> elseConnectedGuards = previous.findElseConnectableGuards(); if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) { return null; } /* Guard is else branch can be connected in previous specialization. */ if (elseConnectedGuards.contains(guard)) { return guard; } GuardExpression previousGuard = previous.getGuards().get(elseConnectedGuards.size()); if (guard.equalsNegated(previousGuard)) { return guard; } return null; }
private GuardExpression findNegatedGuardInPrevious(GuardExpression guard) { SpecializationGroup previous = this.getPreviousGroup(); if (previous == null) { return null; } List<GuardExpression> elseConnectedGuards = previous.findElseConnectableGuards(); if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) { return null; } /* Guard is else branch can be connected in previous specialization. */ if (elseConnectedGuards.contains(guard)) { return guard; } GuardExpression previousGuard = previous.getGuards().get(elseConnectedGuards.size()); if (guard.equalsNegated(previousGuard)) { return guard; } return null; }
private static boolean isReachableGroup(SpecializationGroup group, int ifCount) { if (ifCount != 0) { return true; } SpecializationGroup previous = group.getPreviousGroup(); if (previous == null || previous.findElseConnectableGuards().isEmpty()) { return true; } /* * Hacky else case. In this case the specialization is not reachable due to previous else * branch. This is only true if the minimum state is not checked. */ if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() && (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) { return false; } return true; }
private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard, boolean fastPath) { String localName = currentValues.getValue(typeGuard.getSignatureIndex()).getName(); SpecializationData specialization = group.getSpecialization(); for (GuardExpression guard : group.getGuards()) { if (isVariableBoundIn(specialization, guard.getExpression(), localName, currentValues)) { return true; } } if (!fastPath && specialization != null) { for (CacheExpression cache : specialization.getCaches()) { if (isVariableBoundIn(specialization, cache.getExpression(), localName, currentValues)) { return true; } } } for (SpecializationGroup child : group.getChildren()) { if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard, fastPath)) { return true; } } return false; }
List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards()); guardExpressions.removeAll(elseGuardExpressions); CodeTree[] methodGuardAndAssertions = createMethodGuardCheck(guardExpressions, specialization, currentValues, execution.isFastPath());
List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards());