Search in sources :

Example 21 with Receiver

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

the class InitializationTransfer method visitAssignment.

@Override
public TransferResult<V, S> visitAssignment(AssignmentNode n, TransferInput<V, S> in) {
    TransferResult<V, S> result = super.visitAssignment(n, in);
    assert result instanceof RegularTransferResult;
    Receiver expr = FlowExpressions.internalReprOf(analysis.getTypeFactory(), n.getTarget());
    // initialized.
    if (!expr.containsUnknown()) {
        if (expr instanceof FieldAccess) {
            FieldAccess fa = (FieldAccess) expr;
            result.getRegularStore().addInitializedField(fa);
        }
    }
    return result;
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 22 with Receiver

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

the class LockTransfer method makeLockPossiblyHeld.

/**
 * Sets a given {@link Node} to @LockPossiblyHeld in the given {@code store}.
 */
protected void makeLockPossiblyHeld(LockStore store, Node node) {
    Receiver internalRepr = FlowExpressions.internalReprOf(atypeFactory, node);
    // insertValue cannot change an annotation to a less
    // specific type (e.g. LockHeld to LockPossiblyHeld),
    // so insertLockPossiblyHeld is called.
    store.insertLockPossiblyHeld(internalRepr);
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 23 with Receiver

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

the class LockTransfer method makeLockHeld.

/**
 * Sets a given {@link Node} to @LockHeld in the given {@code store}.
 */
protected void makeLockHeld(LockStore store, Node node) {
    Receiver internalRepr = FlowExpressions.internalReprOf(atypeFactory, node);
    store.insertValue(internalRepr, atypeFactory.LOCKHELD);
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 24 with Receiver

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

the class LockVisitor method getLockExpressions.

private List<LockExpression> getLockExpressions(boolean implicitThis, AnnotationMirror gbAnno, Tree tree) {
    List<String> expressions = AnnotationUtils.getElementValueArray(gbAnno, "value", String.class, true);
    if (expressions.isEmpty()) {
        return Collections.emptyList();
    }
    TreePath currentPath = getCurrentPath();
    List<Receiver> params = FlowExpressions.getParametersOfEnclosingMethod(atypeFactory, currentPath);
    TypeMirror enclosingType = TreeUtils.typeOf(TreeUtils.enclosingClass(currentPath));
    Receiver pseudoReceiver = FlowExpressions.internalReprOfPseudoReceiver(currentPath, enclosingType);
    FlowExpressionContext exprContext = new FlowExpressionContext(pseudoReceiver, params, atypeFactory.getContext());
    Receiver self;
    if (implicitThis) {
        self = pseudoReceiver;
    } else if (TreeUtils.isExpressionTree(tree)) {
        self = FlowExpressions.internalReprOf(atypeFactory, (ExpressionTree) tree);
    } else {
        self = new Unknown(TreeUtils.typeOf(tree));
    }
    List<LockExpression> lockExpressions = new ArrayList<>();
    for (String expression : expressions) {
        lockExpressions.add(parseExpressionString(expression, exprContext, currentPath, self));
    }
    return lockExpressions;
}
Also used : TreePath(com.sun.source.util.TreePath) Unknown(org.checkerframework.dataflow.analysis.FlowExpressions.Unknown) GuardedByUnknown(org.checkerframework.checker.lock.qual.GuardedByUnknown) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) ArrayList(java.util.ArrayList) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 25 with Receiver

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

the class KeyForTransfer method visitMethodInvocation.

/*
     * Provided that m is of a type that implements interface java.util.Map:
     * <ul>
     * <li>Given a call m.containsKey(k), ensures that k is @KeyFor("m") in the thenStore of the transfer result.
     * <li>Given a call m.put(k, ...), ensures that k is @KeyFor("m") in the thenStore and elseStore of the transfer result.
     * </ul>
     */
@Override
public TransferResult<KeyForValue, KeyForStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<KeyForValue, KeyForStore> in) {
    TransferResult<KeyForValue, KeyForStore> result = super.visitMethodInvocation(node, in);
    KeyForAnnotatedTypeFactory factory = (KeyForAnnotatedTypeFactory) analysis.getTypeFactory();
    if (factory.isInvocationOfMapMethod(node, "containsKey") || factory.isInvocationOfMapMethod(node, "put")) {
        Node receiver = node.getTarget().getReceiver();
        Receiver internalReceiver = FlowExpressions.internalReprOf(factory, receiver);
        String mapName = internalReceiver.toString();
        Receiver keyReceiver = FlowExpressions.internalReprOf(factory, node.getArgument(0));
        LinkedHashSet<String> keyForMaps = new LinkedHashSet<>();
        keyForMaps.add(mapName);
        final KeyForValue previousKeyValue = in.getValueOfSubNode(node.getArgument(0));
        if (previousKeyValue != null) {
            for (AnnotationMirror prevAm : previousKeyValue.getAnnotations()) {
                if (prevAm != null && AnnotationUtils.areSameByClass(prevAm, KeyFor.class)) {
                    keyForMaps.addAll(getKeys(prevAm));
                }
            }
        }
        AnnotationMirror am = factory.createKeyForAnnotationMirrorWithValue(keyForMaps);
        if (factory.getMethodName(node).equals("containsKey")) {
            result.getThenStore().insertValue(keyReceiver, am);
        } else {
            // method name is "put"
            result.getThenStore().insertValue(keyReceiver, am);
            result.getElseStore().insertValue(keyReceiver, am);
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotationMirror(javax.lang.model.element.AnnotationMirror) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) Node(org.checkerframework.dataflow.cfg.node.Node) KeyFor(org.checkerframework.checker.nullness.qual.KeyFor) 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