Java Code Examples for com.sun.tools.javac.code.Type#containsAny()

The following examples show how to use com.sun.tools.javac.code.Type#containsAny() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Properties dependencyAttributes(Node sink, GraphUtils.DependencyKind dk) {
    Properties p = new Properties();
    p.put("style", ((DependencyKind)dk).dotSyle);
    StringBuilder buf = new StringBuilder();
    String sep = "";
    for (Type from : data) {
        UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
        for (Type bound : uv.getBounds(InferenceBound.values())) {
            if (bound.containsAny(List.from(sink.data))) {
                buf.append(sep);
                buf.append(bound);
                sep = ",";
            }
        }
    }
    p.put("label", "\"" + buf.toString() + "\"");
    return p;
}
 
Example 2
Source File: InferenceContext.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void notifyChange(List<Type> inferredVars) {
    InferenceException thrownEx = null;
    for (Map.Entry<FreeTypeListener, List<Type>> entry :
            new LinkedHashMap<>(freeTypeListeners).entrySet()) {
        if (!Type.containsAny(entry.getValue(), inferencevars.diff(inferredVars))) {
            try {
                entry.getKey().typesInferred(this);
                freeTypeListeners.remove(entry.getKey());
            } catch (InferenceException ex) {
                if (thrownEx == null) {
                    thrownEx = ex;
                }
            }
        }
    }
    //inference exception multiplexing - present any inference exception
    //thrown when processing listeners as a single one
    if (thrownEx != null) {
        throw thrownEx;
    }
}
 
Example 3
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void notifyChange(List<Type> inferredVars) {
    InferenceException thrownEx = null;
    for (Map.Entry<FreeTypeListener, List<Type>> entry :
            new LinkedHashMap<>(freeTypeListeners).entrySet()) {
        if (!Type.containsAny(entry.getValue(), inferencevars.diff(inferredVars))) {
            try {
                entry.getKey().typesInferred(this);
                freeTypeListeners.remove(entry.getKey());
            } catch (InferenceException ex) {
                if (thrownEx == null) {
                    thrownEx = ex;
                }
            }
        }
    }
    //inference exception multiplexing - present any inference exception
    //thrown when processing listeners as a single one
    if (thrownEx != null) {
        throw thrownEx;
    }
}
 
Example 4
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Solve variables in a given inference context. The amount of variables
 * to be solved, and the way in which the underlying acyclic graph is explored
 * depends on the selected solver strategy.
 */
void solve(GraphStrategy sstrategy) {
    doIncorporation(inferenceContext, warn); //initial propagation of bounds
    InferenceGraph inferenceGraph = new InferenceGraph();
    while (!sstrategy.done()) {
        if (dependenciesFolder != null) {
            //add this graph to the pending queue
            pendingGraphs = pendingGraphs.prepend(inferenceGraph.toDot());
        }
        InferenceGraph.Node nodeToSolve = sstrategy.pickNode(inferenceGraph);
        List<Type> varsToSolve = List.from(nodeToSolve.data);
        List<Type> saved_undet = inferenceContext.save();
        try {
            //repeat until all variables are solved
            outer: while (Type.containsAny(inferenceContext.restvars(), varsToSolve)) {
                //for each inference phase
                for (GraphInferenceSteps step : GraphInferenceSteps.values()) {
                    if (inferenceContext.solveBasic(varsToSolve, step.steps).nonEmpty()) {
                        doIncorporation(inferenceContext, warn);
                        continue outer;
                    }
                }
                //no progress
                throw inferenceException.setMessage();
            }
        }
        catch (InferenceException ex) {
            //did we fail because of interdependent ivars?
            inferenceContext.rollback(saved_undet);
            instantiateAsUninferredVars(varsToSolve, inferenceContext);
            doIncorporation(inferenceContext, warn);
        }
        inferenceGraph.deleteNode(nodeToSolve);
    }
}
 
Example 5
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create the graph nodes. First a simple node is created for every inference
 * variables to be solved. Then Tarjan is used to found all connected components
 * in the graph. For each component containing more than one node, a super node is
 * created, effectively replacing the original cyclic nodes.
 */
void initNodes() {
    //add nodes
    nodes = new ArrayList<>();
    for (Type t : inferenceContext.restvars()) {
        nodes.add(new Node(t));
    }
    //add dependencies
    for (Node n_i : nodes) {
        Type i = n_i.data.first();
        for (Node n_j : nodes) {
            Type j = n_j.data.first();
            // don't compare a variable to itself
            if (i != j) {
                UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i);
                if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
                    //update i's bound dependencies
                    n_i.addDependency(n_j);
                }
            }
        }
    }
    //merge cyclic nodes
    ArrayList<Node> acyclicNodes = new ArrayList<>();
    for (List<? extends Node> conSubGraph : GraphUtils.tarjan(nodes)) {
        if (conSubGraph.length() > 1) {
            Node root = conSubGraph.head;
            root.mergeWith(conSubGraph.tail);
            for (Node n : conSubGraph) {
                notifyUpdate(n, root);
            }
        }
        acyclicNodes.add(conSubGraph.head);
    }
    nodes = acyclicNodes;
}
 
Example 6
Source File: VarTypePrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Type mapTypeArgument(Type t, boolean upward) {
    if (!t.containsAny(vars)) {
        return t;
    } else if (!t.hasTag(WILDCARD) && !upward) {
        //not defined
        return syms.botType;
    } else {
        Type upper = t.map(this, upward);
        Type lower = t.map(this, !upward);
        return makeWildcard(upper, lower);
    }
}
 
Example 7
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Process a deferred attribution node.
 * Invariant: a stuck node cannot be processed.
 */
@SuppressWarnings("fallthrough")
boolean process(final DeferredAttrContext deferredAttrContext) {
    switch (deferredAttrContext.mode) {
        case SPECULATIVE:
            if (deferredStuckPolicy.isStuck()) {
                dt.check(resultInfo, dummyStuckPolicy, new StructuralStuckChecker());
                return true;
            } else {
                Assert.error("Cannot get here");
            }
        case CHECK:
            if (deferredStuckPolicy.isStuck()) {
                //stuck expression - see if we can propagate
                if (deferredAttrContext.parent != emptyDeferredAttrContext &&
                        Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars,
                                List.from(deferredStuckPolicy.stuckVars()))) {
                    deferredAttrContext.parent.addDeferredAttrNode(dt,
                            resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) {
                        @Override
                        public InferenceContext inferenceContext() {
                            return deferredAttrContext.parent.inferenceContext;
                        }
                        @Override
                        public DeferredAttrContext deferredAttrContext() {
                            return deferredAttrContext.parent;
                        }
                    }), deferredStuckPolicy);
                    dt.tree.type = Type.stuckType;
                    return true;
                } else {
                    return false;
                }
            } else {
                Assert.check(!deferredAttrContext.insideOverloadPhase(),
                        "attribution shouldn't be happening here");
                ResultInfo instResultInfo =
                        resultInfo.dup(deferredAttrContext.inferenceContext.asInstType(resultInfo.pt));
                dt.check(instResultInfo, dummyStuckPolicy, basicCompleter);
                return true;
            }
        default:
            throw new AssertionError("Bad mode");
    }
}
 
Example 8
Source File: InferenceContext.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * is this type free?
 */
final boolean free(Type t) {
    return t.containsAny(inferencevars);
}
 
Example 9
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * is this type free?
 */
final boolean free(Type t) {
    return t.containsAny(inferencevars);
}