Search in sources :

Example 6 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 7 with CFStore

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

the class ValueTransfer method strengthenAnnotationOfEqualTo.

@Override
protected TransferResult<CFValue, CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> transferResult, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) {
    if (firstValue == null) {
        return transferResult;
    }
    if (TypesUtils.isNumeric(firstNode.getType()) || TypesUtils.isNumeric(secondNode.getType())) {
        CFStore thenStore = transferResult.getThenStore();
        CFStore elseStore = transferResult.getElseStore();
        // At least one must be a primitive otherwise reference equality is used.
        List<Boolean> resultValues = calculateBinaryComparison(firstNode, firstValue, secondNode, secondValue, notEqualTo ? ComparisonOperators.NOT_EQUAL : ComparisonOperators.EQUAL, thenStore, elseStore);
        if (transferResult.getResultValue() == null) {
            // Happens for case labels
            return transferResult;
        }
        TypeMirror underlyingType = transferResult.getResultValue().getUnderlyingType();
        return createNewResultBoolean(thenStore, elseStore, resultValues, underlyingType);
    }
    return super.strengthenAnnotationOfEqualTo(transferResult, firstNode, secondNode, firstValue, secondValue, notEqualTo);
}
Also used : CFStore(org.checkerframework.framework.flow.CFStore) TypeMirror(javax.lang.model.type.TypeMirror)

Example 8 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 9 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 10 with CFStore

use of org.checkerframework.framework.flow.CFStore 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

CFStore (org.checkerframework.framework.flow.CFStore)45 CFValue (org.checkerframework.framework.flow.CFValue)41 AnnotationMirror (javax.lang.model.element.AnnotationMirror)31 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)8 Node (org.checkerframework.dataflow.cfg.node.Node)8 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)7 TypeMirror (javax.lang.model.type.TypeMirror)5 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)5 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)5 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)4 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)4 Tree (com.sun.source.tree.Tree)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)3 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)3 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)3 GreaterThanOrEqualNode (org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode)3 IntegerLiteralNode (org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)3 LessThanNode (org.checkerframework.dataflow.cfg.node.LessThanNode)3 LessThanOrEqualNode (org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode)3