Search in sources :

Example 36 with Receiver

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

the class SameLenVisitor method commonAssignmentCheck.

/**
 * Modifies the common assignment checks to ensure that SameLen annotations are always merged.
 * The check is not relaxed in any way.
 */
@Override
protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey) {
    if (IndexUtil.isSequenceType(valueType.getUnderlyingType()) && TreeUtils.isExpressionTree(valueTree) && !(valueType.hasAnnotation(PolySameLen.class) && varType.hasAnnotation(PolySameLen.class))) {
        AnnotationMirror am = valueType.getAnnotation(SameLen.class);
        List<String> arraysInAnno = am == null ? new ArrayList<>() : IndexUtil.getValueOfAnnotationWithStringArgument(am);
        Receiver rec = FlowExpressions.internalReprOf(atypeFactory, (ExpressionTree) valueTree);
        if (rec != null && SameLenAnnotatedTypeFactory.shouldUseInAnnotation(rec)) {
            List<String> names = new ArrayList<>();
            names.add(rec.toString());
            AnnotationMirror newSameLen = atypeFactory.getCombinedSameLen(arraysInAnno, names);
            valueType.replaceAnnotation(newSameLen);
        }
    }
    super.commonAssignmentCheck(varType, valueType, valueTree, errorKey);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 37 with Receiver

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

the class OffsetEquation method createOffsetFromNode.

private static void createOffsetFromNode(Node node, AnnotationProvider factory, OffsetEquation eq, char op) {
    Receiver r = FlowExpressions.internalReprOf(factory, node);
    if (r instanceof Unknown || r == null) {
        if (node instanceof NumericalAdditionNode) {
            createOffsetFromNode(((NumericalAdditionNode) node).getLeftOperand(), factory, eq, op);
            createOffsetFromNode(((NumericalAdditionNode) node).getRightOperand(), factory, eq, op);
        } else if (node instanceof NumericalSubtractionNode) {
            createOffsetFromNode(((NumericalSubtractionNode) node).getLeftOperand(), factory, eq, op);
            char other = op == '+' ? '-' : '+';
            createOffsetFromNode(((NumericalSubtractionNode) node).getRightOperand(), factory, eq, other);
        } else {
            eq.error = node.toString();
        }
    } else {
        eq.addTerm(op, r.toString());
    }
}
Also used : NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) Unknown(org.checkerframework.dataflow.analysis.FlowExpressions.Unknown) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode)

Example 38 with Receiver

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

the class UpperBoundTransfer method visitFieldAccess.

/**
 * If n is an array length field access, then the type of a.length is the glb
 * of @LTEqLengthOf("a") and the value of a.length in the store. This is case 19.
 */
@Override
public TransferResult<CFValue, CFStore> visitFieldAccess(FieldAccessNode n, TransferInput<CFValue, CFStore> in) {
    if (NodeUtils.isArrayLengthFieldAccess(n)) {
        FieldAccess arrayLength = FlowExpressions.internalReprOfFieldAccess(atypeFactory, n);
        Receiver arrayRec = arrayLength.getReceiver();
        Tree arrayTree = n.getReceiver().getTree();
        TransferResult<CFValue, CFStore> result = visitLengthAccess(n, in, arrayRec, arrayTree);
        if (result != null) {
            return result;
        }
    }
    return super.visitFieldAccess(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) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)

Example 39 with Receiver

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

the class UpperBoundTransfer method refineGT.

/**
 * Case 8: if x &lt; y, and y has a type that is related to the length of an array, then x has
 * the same type, with an offset that is one less.
 */
@Override
protected void refineGT(Node larger, AnnotationMirror largerAnno, Node smaller, AnnotationMirror smallerAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
    // larger > smaller
    UBQualifier largerQual = UBQualifier.createUBQualifier(largerAnno);
    // larger + 1 >= smaller
    UBQualifier largerQualPlus1 = largerQual.plusOffset(1);
    UBQualifier rightQualifier = UBQualifier.createUBQualifier(smallerAnno);
    UBQualifier refinedRight = rightQualifier.glb(largerQualPlus1);
    if (largerQualPlus1.isLessThanLengthQualifier()) {
        propagateToOperands((LessThanLengthOf) largerQualPlus1, smaller, in, store);
    }
    refineSubtrahendWithOffset(larger, smaller, true, in, store);
    Receiver rightRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), smaller);
    store.insertValue(rightRec, atypeFactory.convertUBQualifierToAnnotation(refinedRight));
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 40 with Receiver

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

the class LockAnnotatedTypeFactory method isExpressionEffectivelyFinal.

/**
 * Returns whether or not the expression is effectively final.
 *
 * <p>This method returns true in the following cases when expr is:
 *
 * <p>1. a field access and the field is final and the field access expression is effectively
 * final as specified by this method.
 *
 * <p>2. an effectively final local variable.
 *
 * <p>3. a deterministic method call whose arguments and receiver expression are effectively
 * final as specified by this method.
 *
 * <p>4. a this reference or a class literal
 *
 * @param expr expression
 * @return whether or not the expression is effectively final
 */
boolean isExpressionEffectivelyFinal(Receiver expr) {
    if (expr instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) expr;
        Receiver recv = fieldAccess.getReceiver();
        // Don't call fieldAccess
        return fieldAccess.isFinal() && isExpressionEffectivelyFinal(recv);
    } else if (expr instanceof LocalVariable) {
        return ElementUtils.isEffectivelyFinal(((LocalVariable) expr).getElement());
    } else if (expr instanceof MethodCall) {
        MethodCall methodCall = (MethodCall) expr;
        for (Receiver param : methodCall.getParameters()) {
            if (!isExpressionEffectivelyFinal(param)) {
                return false;
            }
        }
        return PurityUtils.isDeterministic(this, methodCall.getElement()) && isExpressionEffectivelyFinal(methodCall.getReceiver());
    } else if (expr instanceof ThisReference || expr instanceof ClassName) {
        // final too.
        return true;
    } else {
        // type of 'expr' is not supported in @GuardedBy(...) lock expressions
        return false;
    }
}
Also used : LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) ClassName(org.checkerframework.dataflow.analysis.FlowExpressions.ClassName) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) ThisReference(org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference) MethodCall(org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)

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