Search in sources :

Example 1 with AFReducer

use of org.checkerframework.framework.util.typeinference.constraint.AFReducer in project checker-framework by typetools.

the class DefaultTypeArgumentInference method reduceAfConstraints.

/**
 * Given a set of AFConstraints, remove all constraints that are not relevant to inference and
 * return a set of AFConstraints in which the F is a use of one of the type parameters to infer.
 */
protected void reduceAfConstraints(final AnnotatedTypeFactory typeFactory, final Set<AFConstraint> outgoing, final Queue<AFConstraint> toProcess, final Set<TypeVariable> targets) {
    final Set<AFConstraint> visited = new HashSet<>();
    List<AFReducer> reducers = new ArrayList<>();
    reducers.add(new A2FReducer(typeFactory));
    reducers.add(new F2AReducer(typeFactory));
    reducers.add(new FIsAReducer(typeFactory));
    Set<AFConstraint> newConstraints = new HashSet<>(10);
    while (!toProcess.isEmpty()) {
        newConstraints.clear();
        AFConstraint constraint = toProcess.remove();
        if (!visited.contains(constraint)) {
            if (constraint.isIrreducible(targets)) {
                outgoing.add(constraint);
            } else {
                final Iterator<AFReducer> reducerIterator = reducers.iterator();
                boolean handled = false;
                while (!handled && reducerIterator.hasNext()) {
                    handled = reducerIterator.next().reduce(constraint, newConstraints);
                }
                if (!handled) {
                    ErrorReporter.errorAbort("Unhandled constraint type: " + constraint.toString());
                }
                toProcess.addAll(newConstraints);
            }
            visited.add(constraint);
        }
    }
}
Also used : A2FReducer(org.checkerframework.framework.util.typeinference.constraint.A2FReducer) AFReducer(org.checkerframework.framework.util.typeinference.constraint.AFReducer) ArrayList(java.util.ArrayList) F2AReducer(org.checkerframework.framework.util.typeinference.constraint.F2AReducer) AFConstraint(org.checkerframework.framework.util.typeinference.constraint.AFConstraint) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FIsAReducer(org.checkerframework.framework.util.typeinference.constraint.FIsAReducer)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 A2FReducer (org.checkerframework.framework.util.typeinference.constraint.A2FReducer)1 AFConstraint (org.checkerframework.framework.util.typeinference.constraint.AFConstraint)1 AFReducer (org.checkerframework.framework.util.typeinference.constraint.AFReducer)1 F2AReducer (org.checkerframework.framework.util.typeinference.constraint.F2AReducer)1 FIsAReducer (org.checkerframework.framework.util.typeinference.constraint.FIsAReducer)1