Search in sources :

Example 46 with Receiver

use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.

the class SameLenAnnotatedTypeFactory method getAnnotatedTypeLhs.

/**
 * Handles case 2.
 */
@Override
public AnnotatedTypeMirror getAnnotatedTypeLhs(Tree tree) {
    AnnotatedTypeMirror atm = super.getAnnotatedTypeLhs(tree);
    if (tree.getKind() == Tree.Kind.VARIABLE) {
        Receiver r;
        try {
            r = FlowExpressionParseUtil.internalReprOfVariable(this, (VariableTree) tree);
        } catch (FlowExpressionParseException ex) {
            r = null;
        }
        if (r != null) {
            String varName = r.toString();
            AnnotationMirror anm = atm.getAnnotation(SameLen.class);
            if (anm != null) {
                List<String> slArrays = IndexUtil.getValueOfAnnotationWithStringArgument(anm);
                if (slArrays.contains(varName)) {
                    slArrays.remove(varName);
                }
                if (slArrays.size() == 0) {
                    atm.replaceAnnotation(UNKNOWN);
                } else {
                    atm.replaceAnnotation(createSameLen(slArrays.toArray(new String[0])));
                }
            }
        }
    }
    return atm;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) VariableTree(com.sun.source.tree.VariableTree) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) FlowExpressionParseException(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 47 with Receiver

use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.

the class SameLenTransfer method propagateCombinedSameLen.

/**
 * Insert combinedSameLen into the store as the SameLen type of each array listed in
 * combinedSameLen.
 *
 * @param combinedSameLen a Samelen annotation. Not just an annotation in the SameLen hierarchy;
 *     this annotation MUST be @SameLen().
 * @param node the node in the tree where the combination is happening. Used for context.
 * @param store the store to modify
 */
private void propagateCombinedSameLen(AnnotationMirror combinedSameLen, Node node, CFStore store) {
    TreePath currentPath = aTypeFactory.getPath(node.getTree());
    if (currentPath == null) {
        return;
    }
    for (String s : IndexUtil.getValueOfAnnotationWithStringArgument(combinedSameLen)) {
        Receiver recS;
        try {
            recS = aTypeFactory.getReceiverFromJavaExpressionString(s, currentPath);
        } catch (FlowExpressionParseUtil.FlowExpressionParseException e) {
            continue;
        }
        store.clearValue(recS);
        store.insertValue(recS, combinedSameLen);
    }
}
Also used : FlowExpressionParseUtil(org.checkerframework.framework.util.FlowExpressionParseUtil) TreePath(com.sun.source.util.TreePath) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 48 with Receiver

use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.

the class AliasingTransfer method visitAssignment.

/**
 * Case 1: For every assignment, the LHS is refined if the RHS has type {@literal @}Unique and
 * is a method invocation or a new class instance.
 */
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode n, TransferInput<CFValue, CFStore> in) {
    Node rhs = n.getExpression();
    Tree treeRhs = rhs.getTree();
    AnnotatedTypeMirror rhsType = factory.getAnnotatedType(treeRhs);
    if (rhsType.hasAnnotation(Unique.class) && (rhs instanceof MethodInvocationNode || rhs instanceof ObjectCreationNode)) {
        // Do normal refinement.
        return super.visitAssignment(n, in);
    }
    // Widen the type of the rhs if the RHS's declared type wasn't @Unique.
    Receiver r = FlowExpressions.internalReprOf(factory, rhs);
    in.getRegularStore().clearValue(r);
    return new RegularTransferResult<>(null, in.getRegularStore());
}
Also used : MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) Node(org.checkerframework.dataflow.cfg.node.Node) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) Tree(com.sun.source.tree.Tree) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) Unique(org.checkerframework.common.aliasing.qual.Unique) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 49 with Receiver

use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.

the class DependentTypesHelper method standardizeExpression.

public void standardizeExpression(ExpressionTree tree, AnnotatedTypeMirror annotatedType) {
    if (!hasDependentType(annotatedType)) {
        return;
    }
    TreePath path = factory.getPath(tree);
    if (path == null) {
        return;
    }
    Tree enclosingClass = TreeUtils.enclosingClass(path);
    if (enclosingClass == null) {
        return;
    }
    TypeMirror enclosingType = TreeUtils.typeOf(enclosingClass);
    FlowExpressions.Receiver receiver = FlowExpressions.internalReprOfPseudoReceiver(path, enclosingType);
    FlowExpressionContext localContext = new FlowExpressionContext(receiver, FlowExpressions.getParametersOfEnclosingMethod(factory, path), factory.getContext());
    standardizeUseLocals(localContext, path, annotatedType);
}
Also used : TreePath(com.sun.source.util.TreePath) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) IdentifierTree(com.sun.source.tree.IdentifierTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) ModifiersTree(com.sun.source.tree.ModifiersTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) NewClassTree(com.sun.source.tree.NewClassTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 50 with Receiver

use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.

the class DependentTypesHelper method standardizeFieldAccess.

public void standardizeFieldAccess(MemberSelectTree node, AnnotatedTypeMirror type) {
    if (!hasDependentType(type)) {
        return;
    }
    if (TreeUtils.isClassLiteral(node)) {
        return;
    }
    Element ele = TreeUtils.elementFromUse(node);
    if (ele.getKind() != ElementKind.FIELD) {
        return;
    }
    FlowExpressions.Receiver receiver = FlowExpressions.internalReprOf(factory, node.getExpression());
    FlowExpressionContext context = new FlowExpressionContext(receiver, null, factory.getContext());
    standardizeDoNotUseLocals(context, factory.getPath(node), type);
}
Also used : FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Aggregations

Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)55 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Node (org.checkerframework.dataflow.cfg.node.Node)15 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)14 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)10 CFValue (org.checkerframework.framework.flow.CFValue)9 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)8 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)8 NumericalAdditionNode (org.checkerframework.dataflow.cfg.node.NumericalAdditionNode)8 NumericalSubtractionNode (org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode)8 ArrayList (java.util.ArrayList)7 TypeMirror (javax.lang.model.type.TypeMirror)7 ClassName (org.checkerframework.dataflow.analysis.FlowExpressions.ClassName)7 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)7 Tree (com.sun.source.tree.Tree)6 TreePath (com.sun.source.util.TreePath)6 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)6 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)6 MethodTree (com.sun.source.tree.MethodTree)5 CaseNode (org.checkerframework.dataflow.cfg.node.CaseNode)5