Search in sources :

Example 41 with MethodInvocationNode

use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.

the class ValueTransfer method processConditionalPostconditions.

@Override
protected void processConditionalPostconditions(MethodInvocationNode n, ExecutableElement methodElement, Tree tree, CFStore thenStore, CFStore elseStore) {
    // For String.startsWith(String) and String.endsWith(String), refine the minimum length
    // of the receiver to the minimum length of the argument.
    ValueMethodIdentifier methodIdentifier = atypeFactory.getMethodIdentifier();
    if (methodIdentifier.isStartsWithMethod(methodElement) || methodIdentifier.isEndsWithMethod(methodElement)) {
        Node argumentNode = n.getArgument(0);
        AnnotationMirror argumentAnno = getArrayOrStringAnnotation(argumentNode);
        int minLength = atypeFactory.getMinLenValue(argumentAnno);
        // Update the annotation of the receiver
        if (minLength != 0) {
            JavaExpression receiver = JavaExpression.fromNode(n.getTarget().getReceiver());
            AnnotationMirror minLenAnno = atypeFactory.createArrayLenRangeAnnotation(minLength, Integer.MAX_VALUE);
            thenStore.insertValuePermitNondeterministic(receiver, minLenAnno);
        }
    }
    super.processConditionalPostconditions(n, methodElement, tree, thenStore, elseStore);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) NumericalMultiplicationNode(org.checkerframework.dataflow.cfg.node.NumericalMultiplicationNode) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) StringConversionNode(org.checkerframework.dataflow.cfg.node.StringConversionNode) UnsignedRightShiftNode(org.checkerframework.dataflow.cfg.node.UnsignedRightShiftNode) LeftShiftNode(org.checkerframework.dataflow.cfg.node.LeftShiftNode) FloatingRemainderNode(org.checkerframework.dataflow.cfg.node.FloatingRemainderNode) LessThanNode(org.checkerframework.dataflow.cfg.node.LessThanNode) BitwiseOrNode(org.checkerframework.dataflow.cfg.node.BitwiseOrNode) SignedRightShiftNode(org.checkerframework.dataflow.cfg.node.SignedRightShiftNode) EqualToNode(org.checkerframework.dataflow.cfg.node.EqualToNode) NumericalPlusNode(org.checkerframework.dataflow.cfg.node.NumericalPlusNode) ConditionalAndNode(org.checkerframework.dataflow.cfg.node.ConditionalAndNode) GreaterThanOrEqualNode(org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode) StringLiteralNode(org.checkerframework.dataflow.cfg.node.StringLiteralNode) BitwiseAndNode(org.checkerframework.dataflow.cfg.node.BitwiseAndNode) IntegerDivisionNode(org.checkerframework.dataflow.cfg.node.IntegerDivisionNode) IntegerRemainderNode(org.checkerframework.dataflow.cfg.node.IntegerRemainderNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ConditionalOrNode(org.checkerframework.dataflow.cfg.node.ConditionalOrNode) NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) NotEqualNode(org.checkerframework.dataflow.cfg.node.NotEqualNode) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode) BitwiseXorNode(org.checkerframework.dataflow.cfg.node.BitwiseXorNode) BitwiseComplementNode(org.checkerframework.dataflow.cfg.node.BitwiseComplementNode) ConditionalNotNode(org.checkerframework.dataflow.cfg.node.ConditionalNotNode) NumericalMinusNode(org.checkerframework.dataflow.cfg.node.NumericalMinusNode) StringConcatenateNode(org.checkerframework.dataflow.cfg.node.StringConcatenateNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) FloatingDivisionNode(org.checkerframework.dataflow.cfg.node.FloatingDivisionNode) GreaterThanNode(org.checkerframework.dataflow.cfg.node.GreaterThanNode) LessThanOrEqualNode(org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode) StringConcatenateAssignmentNode(org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node)

Example 42 with MethodInvocationNode

use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.

the class ValueTransfer method refineAtLengthInvocation.

/**
 * If length method is invoked for a sequence, transform its @IntVal annotation into an @ArrayLen
 * annotation.
 *
 * @param lengthNode the length method invocation node
 * @param store the Checker Framework store
 */
private void refineAtLengthInvocation(MethodInvocationNode lengthNode, CFStore store) {
    if (atypeFactory.getMethodIdentifier().isStringLengthMethod(lengthNode.getTarget().getMethod())) {
        MethodAccessNode methodAccessNode = lengthNode.getTarget();
        refineAtLengthAccess(lengthNode, methodAccessNode.getReceiver(), store);
    } else if (atypeFactory.getMethodIdentifier().isArrayGetLengthMethod(lengthNode.getTarget().getMethod())) {
        Node node = lengthNode.getArguments().get(0);
        refineAtLengthAccess(lengthNode, node, store);
    }
}
Also used : MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) NumericalMultiplicationNode(org.checkerframework.dataflow.cfg.node.NumericalMultiplicationNode) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) StringConversionNode(org.checkerframework.dataflow.cfg.node.StringConversionNode) UnsignedRightShiftNode(org.checkerframework.dataflow.cfg.node.UnsignedRightShiftNode) LeftShiftNode(org.checkerframework.dataflow.cfg.node.LeftShiftNode) FloatingRemainderNode(org.checkerframework.dataflow.cfg.node.FloatingRemainderNode) LessThanNode(org.checkerframework.dataflow.cfg.node.LessThanNode) BitwiseOrNode(org.checkerframework.dataflow.cfg.node.BitwiseOrNode) SignedRightShiftNode(org.checkerframework.dataflow.cfg.node.SignedRightShiftNode) EqualToNode(org.checkerframework.dataflow.cfg.node.EqualToNode) NumericalPlusNode(org.checkerframework.dataflow.cfg.node.NumericalPlusNode) ConditionalAndNode(org.checkerframework.dataflow.cfg.node.ConditionalAndNode) GreaterThanOrEqualNode(org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode) StringLiteralNode(org.checkerframework.dataflow.cfg.node.StringLiteralNode) BitwiseAndNode(org.checkerframework.dataflow.cfg.node.BitwiseAndNode) IntegerDivisionNode(org.checkerframework.dataflow.cfg.node.IntegerDivisionNode) IntegerRemainderNode(org.checkerframework.dataflow.cfg.node.IntegerRemainderNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ConditionalOrNode(org.checkerframework.dataflow.cfg.node.ConditionalOrNode) NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) NotEqualNode(org.checkerframework.dataflow.cfg.node.NotEqualNode) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode) BitwiseXorNode(org.checkerframework.dataflow.cfg.node.BitwiseXorNode) BitwiseComplementNode(org.checkerframework.dataflow.cfg.node.BitwiseComplementNode) ConditionalNotNode(org.checkerframework.dataflow.cfg.node.ConditionalNotNode) NumericalMinusNode(org.checkerframework.dataflow.cfg.node.NumericalMinusNode) StringConcatenateNode(org.checkerframework.dataflow.cfg.node.StringConcatenateNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) FloatingDivisionNode(org.checkerframework.dataflow.cfg.node.FloatingDivisionNode) GreaterThanNode(org.checkerframework.dataflow.cfg.node.GreaterThanNode) LessThanOrEqualNode(org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode) StringConcatenateAssignmentNode(org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node)

Aggregations

MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)42 Node (org.checkerframework.dataflow.cfg.node.Node)38 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)21 ObjectCreationNode (org.checkerframework.dataflow.cfg.node.ObjectCreationNode)16 ExecutableElement (javax.lang.model.element.ExecutableElement)15 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)15 MethodAccessNode (org.checkerframework.dataflow.cfg.node.MethodAccessNode)14 LocalVariableNode (org.checkerframework.dataflow.cfg.node.LocalVariableNode)13 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)12 ReturnNode (org.checkerframework.dataflow.cfg.node.ReturnNode)12 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)11 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)11 GreaterThanOrEqualNode (org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode)11 LessThanNode (org.checkerframework.dataflow.cfg.node.LessThanNode)11 LessThanOrEqualNode (org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode)11 StringConversionNode (org.checkerframework.dataflow.cfg.node.StringConversionNode)11 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)10 ArrayAccessNode (org.checkerframework.dataflow.cfg.node.ArrayAccessNode)10 CFStore (org.checkerframework.framework.flow.CFStore)10 CFValue (org.checkerframework.framework.flow.CFValue)10