Search in sources :

Example 11 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class ValueTransfer method visitLessThan.

@Override
public TransferResult<CFValue, CFStore> visitLessThan(LessThanNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitLessThan(n, p);
    CFStore thenStore = transferResult.getThenStore();
    CFStore elseStore = transferResult.getElseStore();
    List<Boolean> resultValues = calculateBinaryComparison(n.getLeftOperand(), p.getValueOfSubNode(n.getLeftOperand()), n.getRightOperand(), p.getValueOfSubNode(n.getRightOperand()), ComparisonOperators.LESS_THAN, thenStore, elseStore);
    TypeMirror underlyingType = transferResult.getResultValue().getUnderlyingType();
    return createNewResultBoolean(thenStore, elseStore, resultValues, underlyingType);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) TypeMirror(javax.lang.model.type.TypeMirror)

Example 12 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class ValueTransfer method visitBitwiseXor.

@Override
public TransferResult<CFValue, CFStore> visitBitwiseXor(BitwiseXorNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitBitwiseXor(n, p);
    AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.BITWISE_XOR, p);
    return createNewResult(transferResult, resultAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore)

Example 13 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class SameLenTransfer method visitAssignment.

/**
 * Handles case 1
 */
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode node, TransferInput<CFValue, CFStore> in) {
    TransferResult<CFValue, CFStore> result = super.visitAssignment(node, in);
    // Handle b = new T[a.length]
    if (node.getExpression() instanceof ArrayCreationNode) {
        ArrayCreationNode acNode = (ArrayCreationNode) node.getExpression();
        if (acNode.getDimensions().size() == 1) {
            Node lengthNode = acNode.getDimension(0);
            Node lengthNodeReceiver = getLengthNodeReceiver(lengthNode);
            if (lengthNodeReceiver != null) {
                // "new T[a.length]" or "new T[s.length()]" is the right hand side of the
                // assignment.  lengthNode is known to be "lengthNodeReceiver.length" or
                // "lengthNodeReceiver.length()"
                // targetRec is the receiver for the left hand side of the assignment.
                Receiver targetRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
                Receiver otherRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), lengthNodeReceiver);
                AnnotationMirror lengthNodeAnnotation = aTypeFactory.getAnnotatedType(lengthNodeReceiver.getTree()).getAnnotationInHierarchy(UNKNOWN);
                AnnotationMirror combinedSameLen = aTypeFactory.createCombinedSameLen(targetRec, otherRec, UNKNOWN, lengthNodeAnnotation);
                propagateCombinedSameLen(combinedSameLen, node, result.getRegularStore());
                return result;
            }
        }
    }
    AnnotationMirror rightAnno = aTypeFactory.getAnnotatedType(node.getExpression().getTree()).getAnnotationInHierarchy(UNKNOWN);
    // If the left side of the assignment is an array or a string, then have both the right and
    // left side be SameLen of each other.
    Receiver targetRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
    Receiver exprRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getExpression());
    if (IndexUtil.isSequenceType(node.getTarget().getType()) || (rightAnno != null && AnnotationUtils.areSameByClass(rightAnno, SameLen.class))) {
        AnnotationMirror rightAnnoOrUnknown = rightAnno == null ? UNKNOWN : rightAnno;
        AnnotationMirror combinedSameLen = aTypeFactory.createCombinedSameLen(targetRec, exprRec, UNKNOWN, rightAnnoOrUnknown);
        propagateCombinedSameLen(combinedSameLen, node, result.getRegularStore());
    }
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) SameLen(org.checkerframework.checker.index.qual.SameLen) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) Node(org.checkerframework.dataflow.cfg.node.Node) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode)

Example 14 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method getUBQualifier.

/**
 * Returns the UBQualifier for node. It does this by finding a {@link CFValue} for node. First
 * it checks the store in the transfer input. If one isn't there, the analysis is checked. If
 * the UNKNOWN qualifier is returned, then the AnnotatedTypeMirror from the type factory is
 * used.
 *
 * @param n node
 * @param in transfer input
 * @return the UBQualifier for node
 */
private UBQualifier getUBQualifier(Node n, TransferInput<CFValue, CFStore> in) {
    QualifierHierarchy hierarchy = analysis.getTypeFactory().getQualifierHierarchy();
    Receiver rec = FlowExpressions.internalReprOf(atypeFactory, n);
    CFValue value = null;
    if (CFAbstractStore.canInsertReceiver(rec)) {
        value = in.getRegularStore().getValue(rec);
    }
    if (value == null) {
        value = analysis.getValue(n);
    }
    UBQualifier qualifier = getUBQualifier(hierarchy, value);
    if (qualifier.isUnknown()) {
        // The qualifier from the store or analysis might be UNKNOWN if there was some error.
        // For example,
        // @LTLength("a") int i = 4;  // error
        // The type of i in the store is @UpperBoundUnknown, but the type of i as computed by
        // the type factory is @LTLength("a"), so use that type.
        CFValue valueFromFactory = getValueFromFactory(n.getTree(), n);
        return getUBQualifier(hierarchy, valueFromFactory);
    }
    return qualifier;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 15 with CFValue

use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.

the class UpperBoundTransfer method visitCase.

@Override
public TransferResult<CFValue, CFStore> visitCase(CaseNode n, TransferInput<CFValue, CFStore> in) {
    TransferResult<CFValue, CFStore> result = super.visitCase(n, in);
    // Refines subtrahend in the switch expression
    // TODO: this cannot be done in strengthenAnnotationOfEqualTo, because that does not provide transfer input
    Node caseNode = n.getCaseOperand();
    AssignmentNode assign = (AssignmentNode) n.getSwitchOperand();
    Node switchNode = assign.getExpression();
    refineSubtrahendWithOffset(switchNode, caseNode, false, in, result.getThenStore());
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) TypeCastNode(org.checkerframework.dataflow.cfg.node.TypeCastNode) NumericalMultiplicationNode(org.checkerframework.dataflow.cfg.node.NumericalMultiplicationNode) ArrayCreationNode(org.checkerframework.dataflow.cfg.node.ArrayCreationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) CaseNode(org.checkerframework.dataflow.cfg.node.CaseNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) Node(org.checkerframework.dataflow.cfg.node.Node)

Aggregations

CFValue (org.checkerframework.framework.flow.CFValue)54 CFStore (org.checkerframework.framework.flow.CFStore)41 AnnotationMirror (javax.lang.model.element.AnnotationMirror)39 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)9 ArrayList (java.util.ArrayList)6 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)6 Node (org.checkerframework.dataflow.cfg.node.Node)6 TypeMirror (javax.lang.model.type.TypeMirror)5 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)5 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)5 ArrayLenRange (org.checkerframework.common.value.qual.ArrayLenRange)4 Range (org.checkerframework.common.value.util.Range)4 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)3 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)3 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)3 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)3 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)3 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)3