Search in sources :

Example 11 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 12 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 13 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 14 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 15 with CFStore

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

the class RegexTransfer method visitMethodInvocation.

// TODO: These are special cases for isRegex(String, int) and asRegex(String, int).
// They should be replaced by adding an @EnsuresQualifierIf annotation that supports
// specifying attributes.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
    TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(n, in);
    // refine result for some helper methods
    MethodAccessNode target = n.getTarget();
    ExecutableElement method = target.getMethod();
    Node receiver = target.getReceiver();
    if (receiver instanceof ClassNameNode) {
        ClassNameNode cnn = (ClassNameNode) receiver;
        String receiverName = cnn.getElement().toString();
        if (isRegexUtil(receiverName)) {
            result = handleRegexUtil(n, method, result);
        }
    }
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) ExecutableElement(javax.lang.model.element.ExecutableElement) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) ClassNameNode(org.checkerframework.dataflow.cfg.node.ClassNameNode) LessThanNode(org.checkerframework.dataflow.cfg.node.LessThanNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode) GreaterThanNode(org.checkerframework.dataflow.cfg.node.GreaterThanNode) LessThanOrEqualNode(org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode) GreaterThanOrEqualNode(org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode) Node(org.checkerframework.dataflow.cfg.node.Node) ClassNameNode(org.checkerframework.dataflow.cfg.node.ClassNameNode)

Aggregations

CFStore (org.checkerframework.framework.flow.CFStore)45 CFValue (org.checkerframework.framework.flow.CFValue)41 AnnotationMirror (javax.lang.model.element.AnnotationMirror)31 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)8 Node (org.checkerframework.dataflow.cfg.node.Node)8 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)7 TypeMirror (javax.lang.model.type.TypeMirror)5 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)5 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)5 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)4 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)4 Tree (com.sun.source.tree.Tree)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)3 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)3 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)3 GreaterThanOrEqualNode (org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode)3 IntegerLiteralNode (org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)3 LessThanNode (org.checkerframework.dataflow.cfg.node.LessThanNode)3 LessThanOrEqualNode (org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode)3