Search in sources :

Example 1 with AssignmentNode

use of org.checkerframework.dataflow.cfg.node.AssignmentNode in project bazel by bazelbuild.

the class Analysis method callTransferFunction.

/**
     * Call the transfer function for node {@code node}, and set that node as
     * current node first.
     */
protected TransferResult<A, S> callTransferFunction(Node node, TransferInput<A, S> store) {
    if (node.isLValue()) {
        // store.hasTwoStores()), or is the following correct?
        return new RegularTransferResult<A, S>(null, store.getRegularStore());
    }
    store.node = node;
    currentNode = node;
    TransferResult<A, S> transferResult = node.accept(transferFunction, store);
    currentNode = null;
    if (node instanceof ReturnNode) {
        // save a copy of the store to later check if some property held at
        // a given return statement
        storesAtReturnStatements.put((ReturnNode) node, transferResult);
    }
    if (node instanceof AssignmentNode) {
        // store the flow-refined value for effectively final local variables
        AssignmentNode assignment = (AssignmentNode) node;
        Node lhst = assignment.getTarget();
        if (lhst instanceof LocalVariableNode) {
            LocalVariableNode lhs = (LocalVariableNode) lhst;
            Element elem = lhs.getElement();
            if (ElementUtils.isEffectivelyFinal(elem)) {
                finalLocalValues.put(elem, transferResult.getResultValue());
            }
        }
    }
    return transferResult;
}
Also used : ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) Node(org.checkerframework.dataflow.cfg.node.Node) Element(javax.lang.model.element.Element) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode)

Example 2 with AssignmentNode

use of org.checkerframework.dataflow.cfg.node.AssignmentNode in project bazel by bazelbuild.

the class ConstantPropagationTransfer method visitAssignment.

@Override
public TransferResult<Constant, ConstantPropagationStore> visitAssignment(AssignmentNode n, TransferInput<Constant, ConstantPropagationStore> pi) {
    ConstantPropagationStore p = pi.getRegularStore();
    Node target = n.getTarget();
    Constant info = null;
    if (target instanceof LocalVariableNode) {
        LocalVariableNode t = (LocalVariableNode) target;
        info = p.getInformation(n.getExpression());
        p.setInformation(t, info);
    }
    return new RegularTransferResult<>(info, p);
}
Also used : IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) EqualToNode(org.checkerframework.dataflow.cfg.node.EqualToNode) Node(org.checkerframework.dataflow.cfg.node.Node) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 3 with AssignmentNode

use of org.checkerframework.dataflow.cfg.node.AssignmentNode in project error-prone by google.

the class NullnessPropagationTransfer method visitAssignment.

@Override
Nullness visitAssignment(AssignmentNode node, SubNodeValues inputs, LocalVariableUpdates updates) {
    Nullness value = inputs.valueOfSubNode(node.getExpression());
    Node target = node.getTarget();
    if (target instanceof LocalVariableNode) {
        updates.set((LocalVariableNode) target, value);
    }
    if (target instanceof ArrayAccessNode) {
        setNonnullIfLocalVariable(updates, ((ArrayAccessNode) target).getArray());
    }
    if (target instanceof FieldAccessNode) {
        FieldAccessNode fieldAccess = (FieldAccessNode) target;
        ClassAndField targetField = tryGetFieldSymbol(target.getTree());
        setReceiverNonnull(updates, fieldAccess.getReceiver(), targetField);
    }
    /*
     * We propagate the value of the target to the value of the assignment expressions as a whole.
     * We do this regardless of whether the target is a local variable. For example:
     *
     * String s = object.field = "foo"; // Now |s| is non-null.
     *
     * It's not clear to me that this is technically correct, but it works in practice with the
     * bytecode generated by both javac and ecj.
     *
     * http://stackoverflow.com/q/12850676/28465
     */
    return value;
}
Also used : TypeCastNode(org.checkerframework.dataflow.cfg.node.TypeCastNode) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) EqualToNode(org.checkerframework.dataflow.cfg.node.EqualToNode) VariableDeclarationNode(org.checkerframework.dataflow.cfg.node.VariableDeclarationNode) InstanceOfNode(org.checkerframework.dataflow.cfg.node.InstanceOfNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) NotEqualNode(org.checkerframework.dataflow.cfg.node.NotEqualNode) ArrayAccessNode(org.checkerframework.dataflow.cfg.node.ArrayAccessNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) FunctionalInterfaceNode(org.checkerframework.dataflow.cfg.node.FunctionalInterfaceNode) Node(org.checkerframework.dataflow.cfg.node.Node) ArrayAccessNode(org.checkerframework.dataflow.cfg.node.ArrayAccessNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode)

Aggregations

AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)3 LocalVariableNode (org.checkerframework.dataflow.cfg.node.LocalVariableNode)3 Node (org.checkerframework.dataflow.cfg.node.Node)3 EqualToNode (org.checkerframework.dataflow.cfg.node.EqualToNode)2 Element (javax.lang.model.element.Element)1 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)1 ArrayAccessNode (org.checkerframework.dataflow.cfg.node.ArrayAccessNode)1 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)1 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)1 FunctionalInterfaceNode (org.checkerframework.dataflow.cfg.node.FunctionalInterfaceNode)1 InstanceOfNode (org.checkerframework.dataflow.cfg.node.InstanceOfNode)1 IntegerLiteralNode (org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)1 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)1 NotEqualNode (org.checkerframework.dataflow.cfg.node.NotEqualNode)1 ReturnNode (org.checkerframework.dataflow.cfg.node.ReturnNode)1 TypeCastNode (org.checkerframework.dataflow.cfg.node.TypeCastNode)1 VariableDeclarationNode (org.checkerframework.dataflow.cfg.node.VariableDeclarationNode)1