Search in sources :

Example 16 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method createTransferResult.

private TransferResult<CFValue, CFStore> createTransferResult(Node n, TransferInput<CFValue, CFStore> in, UBQualifier qualifier) {
    AnnotationMirror newAnno = atypeFactory.convertUBQualifierToAnnotation(qualifier);
    CFValue value = analysis.createSingleAnnotationValue(newAnno, n.getType());
    if (in.containsTwoStores()) {
        CFStore thenStore = in.getThenStore();
        CFStore elseStore = in.getElseStore();
        return new ConditionalTransferResult<>(finishValue(value, thenStore, elseStore), thenStore, elseStore);
    } else {
        CFStore info = in.getRegularStore();
        return new RegularTransferResult<>(finishValue(value, info), info);
    }
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 17 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method visitMethodInvocation.

/**
 * If n is a String.length() method invocation, then the type of s.length() is the glb
 * of @LTEqLengthOf("s") and the value of s.length() in the store. This is case 20.
 */
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
    if (atypeFactory.getMethodIdentifier().isLengthOfMethodInvocation(n)) {
        Receiver stringLength = FlowExpressions.internalReprOf(atypeFactory, n);
        if (stringLength instanceof MethodCall) {
            Receiver receiverRec = ((MethodCall) stringLength).getReceiver();
            Tree receiverTree = n.getTarget().getReceiver().getTree();
            // receiverTree is null when the receiver is implicit "this".
            if (receiverTree != null) {
                TransferResult<CFValue, CFStore> result = visitLengthAccess(n, in, receiverRec, receiverTree);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    return super.visitMethodInvocation(n, in);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) Tree(com.sun.source.tree.Tree) MethodCall(org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)

Example 18 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method strengthenAnnotationOfEqualTo.

/**
 * Implements case 11.
 */
@Override
protected TransferResult<CFValue, CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> res, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) {
    TransferResult<CFValue, CFStore> result = super.strengthenAnnotationOfEqualTo(res, firstNode, secondNode, firstValue, secondValue, notEqualTo);
    IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, firstNode, secondNode);
    if (rfi.leftAnno == null || rfi.rightAnno == null) {
        return result;
    }
    CFStore equalsStore = notEqualTo ? rfi.elseStore : rfi.thenStore;
    CFStore notEqualStore = notEqualTo ? rfi.thenStore : rfi.elseStore;
    refineEq(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, equalsStore);
    refineNeqSequenceLength(rfi.left, rfi.right, rfi.rightAnno, notEqualStore);
    refineNeqSequenceLength(rfi.right, rfi.left, rfi.leftAnno, notEqualStore);
    return rfi.newResult;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) IndexRefinementInfo(org.checkerframework.checker.index.IndexRefinementInfo)

Example 19 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method visitAssignment.

/**
 * Case 1: Refine the type of expressions used as an array dimension to be less than length of
 * the array to which the new array is assigned. For example, in "int[] array = new int[expr];",
 * the type of expr is @LTEqLength("array").
 */
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode node, TransferInput<CFValue, CFStore> in) {
    TransferResult<CFValue, CFStore> result = super.visitAssignment(node, in);
    Node expNode = node.getExpression();
    // strip off typecast if any
    Node expNodeSansCast = (expNode instanceof TypeCastNode) ? ((TypeCastNode) expNode).getOperand() : expNode;
    // null if right-hand-side is not an array creation expression
    ArrayCreationNode acNode = (expNodeSansCast instanceof ArrayCreationNode) ? acNode = (ArrayCreationNode) expNodeSansCast : null;
    if (acNode != null) {
        // Right-hand side of assignment is an array creation expression
        List<Node> nodeList = acNode.getDimensions();
        if (nodeList.size() < 1) {
            return result;
        }
        Node dim = acNode.getDimension(0);
        UBQualifier previousQualifier = getUBQualifier(dim, in);
        Receiver arrayRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
        String arrayString = arrayRec.toString();
        LessThanLengthOf newInfo = (LessThanLengthOf) UBQualifier.createUBQualifier(arrayString, "-1");
        UBQualifier combined = previousQualifier.glb(newInfo);
        AnnotationMirror newAnno = atypeFactory.convertUBQualifierToAnnotation(combined);
        Receiver dimRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), dim);
        result.getRegularStore().insertValue(dimRec, newAnno);
        propagateToOperands(newInfo, dim, in, result.getRegularStore());
    }
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) TypeCastNode(org.checkerframework.dataflow.cfg.node.TypeCastNode) NumericalMultiplicationNode(org.checkerframework.dataflow.cfg.node.NumericalMultiplicationNode) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) CaseNode(org.checkerframework.dataflow.cfg.node.CaseNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) Node(org.checkerframework.dataflow.cfg.node.Node) LessThanLengthOf(org.checkerframework.checker.index.upperbound.UBQualifier.LessThanLengthOf) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) TypeCastNode(org.checkerframework.dataflow.cfg.node.TypeCastNode)

Example 20 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class LockStore method insertValue.

@Override
public void insertValue(FlowExpressions.Receiver r, @Nullable CFValue value) {
    if (value == null) {
        // top and top is also the default value.
        return;
    }
    // side effect the lock expression that has value @LockHeld.
    if (hasLockHeld(value)) {
        if (r instanceof FlowExpressions.FieldAccess) {
            FlowExpressions.FieldAccess fieldAcc = (FlowExpressions.FieldAccess) r;
            CFValue oldValue = fieldValues.get(fieldAcc);
            CFValue newValue = value.mostSpecific(oldValue, null);
            if (newValue != null) {
                fieldValues.put(fieldAcc, newValue);
            }
        } else if (r instanceof FlowExpressions.MethodCall) {
            FlowExpressions.MethodCall method = (FlowExpressions.MethodCall) r;
            CFValue oldValue = methodValues.get(method);
            CFValue newValue = value.mostSpecific(oldValue, null);
            if (newValue != null) {
                methodValues.put(method, newValue);
            }
        }
    }
    super.insertValue(r, value);
}
Also used : FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) CFValue(org.checkerframework.framework.flow.CFValue) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)

Aggregations

CFValue (org.checkerframework.framework.flow.CFValue)54 CFStore (org.checkerframework.framework.flow.CFStore)41 AnnotationMirror (javax.lang.model.element.AnnotationMirror)39 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)9 ArrayList (java.util.ArrayList)6 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)6 Node (org.checkerframework.dataflow.cfg.node.Node)6 TypeMirror (javax.lang.model.type.TypeMirror)5 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)5 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)5 ArrayLenRange (org.checkerframework.common.value.qual.ArrayLenRange)4 Range (org.checkerframework.common.value.util.Range)4 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)3 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)3 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)3 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)3 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)3 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)3