Search in sources :

Example 1 with TransferInput

use of org.checkerframework.dataflow.analysis.TransferInput in project checker-framework by typetools.

the class AbstractCFGVisualizer method visualizeBlockTransferInputHelper.

/**
 * Visualize the transfer input before or after the given block.
 *
 * @param where either BEFORE or AFTER
 * @param bb a block
 * @param analysis the current analysis
 * @param separator the line separator. Examples: "\\l" for left justification in {@link
 *     DOTCFGVisualizer} (which is actually a line TERMINATOR, not a separator!), "\n" to add a
 *     new line in {@link StringCFGVisualizer}
 * @return the visualization of the transfer input before or after the given block
 */
protected String visualizeBlockTransferInputHelper(VisualizeWhere where, Block bb, Analysis<V, S, T> analysis, String separator) {
    if (analysis == null) {
        throw new BugInCF("analysis must be non-null when visualizing the transfer input of a block.");
    }
    Direction analysisDirection = analysis.getDirection();
    S regularStore;
    S thenStore = null;
    S elseStore = null;
    boolean isTwoStores = false;
    UniqueId storesFrom;
    if (analysisDirection == Direction.FORWARD && where == VisualizeWhere.AFTER) {
        regularStore = analysis.getResult().getStoreAfter(bb);
        storesFrom = analysis.getResult();
    } else if (analysisDirection == Direction.BACKWARD && where == VisualizeWhere.BEFORE) {
        regularStore = analysis.getResult().getStoreBefore(bb);
        storesFrom = analysis.getResult();
    } else {
        TransferInput<V, S> input = analysis.getInput(bb);
        assert input != null : "@AssumeAssertion(nullness): invariant";
        storesFrom = input;
        isTwoStores = input.containsTwoStores();
        regularStore = input.getRegularStore();
        thenStore = input.getThenStore();
        elseStore = input.getElseStore();
    }
    StringBuilder sbStore = new StringBuilder();
    if (verbose) {
        sbStore.append(storesFrom.getClassAndUid() + separator);
    }
    sbStore.append(where == VisualizeWhere.BEFORE ? "Before: " : "After: ");
    if (!isTwoStores) {
        sbStore.append(visualizeStore(regularStore));
    } else {
        assert thenStore != null : "@AssumeAssertion(nullness): invariant";
        assert elseStore != null : "@AssumeAssertion(nullness): invariant";
        sbStore.append("then=");
        sbStore.append(visualizeStore(thenStore));
        sbStore.append(",");
        sbStore.append(separator);
        sbStore.append("else=");
        sbStore.append(visualizeStore(elseStore));
    }
    if (where == VisualizeWhere.BEFORE) {
        sbStore.append(separator + "~~~~~~~~~");
    } else {
        sbStore.insert(0, "~~~~~~~~~" + separator);
    }
    return sbStore.toString();
}
Also used : UniqueId(org.plumelib.util.UniqueId) TransferInput(org.checkerframework.dataflow.analysis.TransferInput) BugInCF(org.checkerframework.javacutil.BugInCF) Direction(org.checkerframework.dataflow.analysis.Analysis.Direction)

Aggregations

Direction (org.checkerframework.dataflow.analysis.Analysis.Direction)1 TransferInput (org.checkerframework.dataflow.analysis.TransferInput)1 BugInCF (org.checkerframework.javacutil.BugInCF)1 UniqueId (org.plumelib.util.UniqueId)1