Search in sources :

Example 11 with MethodInvocationNode

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

the class LiveVarTransfer method visitMethodInvocation.

@Override
public RegularTransferResult<LiveVarValue, LiveVarStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<LiveVarValue, LiveVarStore> p) {
    RegularTransferResult<LiveVarValue, LiveVarStore> transferResult = (RegularTransferResult<LiveVarValue, LiveVarStore>) super.visitMethodInvocation(n, p);
    LiveVarStore store = transferResult.getRegularStore();
    for (Node arg : n.getArguments()) {
        store.addUseInExpression(arg);
    }
    return transferResult;
}
Also used : ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) StringConcatenateAssignmentNode(org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 12 with MethodInvocationNode

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

the class ValueTransfer method addAnnotationToStore.

private void addAnnotationToStore(CFStore store, AnnotationMirror anno, Node node) {
    // If node is assignment, iterate over lhs and rhs; otherwise, iterator contains just node.
    for (Node internal : splitAssignments(node)) {
        JavaExpression je = JavaExpression.fromNode(internal);
        CFValue currentValueFromStore;
        if (CFAbstractStore.canInsertJavaExpression(je)) {
            currentValueFromStore = store.getValue(je);
        } else {
            // Don't just `continue;` which would skip the calls to refine{Array,String}...
            currentValueFromStore = null;
        }
        AnnotationMirror currentAnno = (currentValueFromStore == null ? atypeFactory.UNKNOWNVAL : getValueAnnotation(currentValueFromStore));
        // Combine the new annotations based on the results of the comparison with the existing type.
        AnnotationMirror newAnno = hierarchy.greatestLowerBound(anno, currentAnno);
        store.insertValue(je, newAnno);
        if (node instanceof FieldAccessNode) {
            refineArrayAtLengthAccess((FieldAccessNode) internal, store);
        } else if (node instanceof MethodInvocationNode) {
            MethodInvocationNode miNode = (MethodInvocationNode) node;
            refineAtLengthInvocation(miNode, store);
        }
    }
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) 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) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode)

Example 13 with MethodInvocationNode

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

the class AliasingTransfer method processPostconditions.

/**
 * Handling pseudo-assignments. Called by {@code CFAbstractTransfer.visitMethodInvocation()}.
 *
 * <p>Case 2: Given a method call, traverses all formal parameters of the method declaration, and
 * if it doesn't have the {@literal @}NonLeaked or {@literal @}LeakedToResult annotations, we
 * remove the node of the respective argument in the method call from the store. If parameter has
 * {@literal @}LeakedToResult, {@code visitMethodInvocation()} handles it.
 */
@Override
protected void processPostconditions(MethodInvocationNode n, CFStore store, ExecutableElement methodElement, Tree tree) {
    super.processPostconditions(n, store, methodElement, tree);
    if (TreeUtils.isEnumSuper(n.getTree())) {
        // Skipping the init() method for enums.
        return;
    }
    List<Node> args = n.getArguments();
    List<? extends VariableElement> params = methodElement.getParameters();
    assert (args.size() == params.size()) : "Number of arguments in " + "the method call " + n + " is different from the" + " number of parameters for the method declaration: " + methodElement.getSimpleName();
    AnnotatedExecutableType annotatedType = factory.getAnnotatedType(methodElement);
    List<AnnotatedTypeMirror> paramTypes = annotatedType.getParameterTypes();
    for (int i = 0; i < args.size(); i++) {
        Node arg = args.get(i);
        AnnotatedTypeMirror paramType = paramTypes.get(i);
        if (!paramType.hasAnnotation(NonLeaked.class) && !paramType.hasAnnotation(LeakedToResult.class)) {
            store.clearValue(JavaExpression.fromNode(arg));
        }
    }
    // Now, doing the same as above for the receiver parameter
    Node receiver = n.getTarget().getReceiver();
    AnnotatedDeclaredType receiverType = annotatedType.getReceiverType();
    if (receiverType != null && !receiverType.hasAnnotation(LeakedToResult.class) && !receiverType.hasAnnotation(NonLeaked.class)) {
        store.clearValue(JavaExpression.fromNode(receiver));
    }
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) LeakedToResult(org.checkerframework.common.aliasing.qual.LeakedToResult) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 14 with MethodInvocationNode

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

the class I18nFormatterTreeUtil method asFormatCallCategoriesLowLevel.

private I18nConversionCategory[] asFormatCallCategoriesLowLevel(MethodInvocationNode node) {
    Node vararg = node.getArgument(1);
    if (vararg instanceof ArrayCreationNode) {
        List<Node> convs = ((ArrayCreationNode) vararg).getInitializers();
        I18nConversionCategory[] res = new I18nConversionCategory[convs.size()];
        for (int i = 0; i < convs.size(); i++) {
            Node conv = convs.get(i);
            if (conv instanceof FieldAccessNode) {
                if (typeMirrorToClass(((FieldAccessNode) conv).getType()) == I18nConversionCategory.class) {
                    res[i] = I18nConversionCategory.valueOf(((FieldAccessNode) conv).getFieldName());
                    continue;
                /* avoid returning null */
                }
            }
            return null;
        }
        return res;
    }
    return null;
}
Also used : ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) Node(org.checkerframework.dataflow.cfg.node.Node) StringLiteralNode(org.checkerframework.dataflow.cfg.node.StringLiteralNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) I18nConversionCategory(org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory)

Example 15 with MethodInvocationNode

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

the class IndexMethodIdentifier method isLengthOfMethodInvocation.

/**
 * Returns true if {@code node} is an invocation of a method that returns the length of {@code
 * this}
 *
 * @param node a node
 * @return true if {@code node} is an invocation of a method that returns the length of {@code
 *     this}
 */
public boolean isLengthOfMethodInvocation(Node node) {
    if (node instanceof MethodInvocationNode) {
        MethodInvocationNode methodInvocationNode = (MethodInvocationNode) node;
        MethodAccessNode methodAccessNode = methodInvocationNode.getTarget();
        ExecutableElement ele = methodAccessNode.getMethod();
        return isLengthOfMethodInvocation(ele);
    }
    return false;
}
Also used : MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ExecutableElement(javax.lang.model.element.ExecutableElement)

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