Search in sources :

Example 46 with CFValue

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

the class ValueTransfer method visitGreaterThanOrEqual.

@Override
public TransferResult<CFValue, CFStore> visitGreaterThanOrEqual(GreaterThanOrEqualNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitGreaterThanOrEqual(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.GREATER_THAN_EQ, 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 47 with CFValue

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

the class ValueTransfer method visitSignedRightShift.

@Override
public TransferResult<CFValue, CFStore> visitSignedRightShift(SignedRightShiftNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitSignedRightShift(n, p);
    AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.SIGNED_SHIFT_RIGHT, 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 48 with CFValue

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

the class ValueTransfer method visitLessThanOrEqual.

@Override
public TransferResult<CFValue, CFStore> visitLessThanOrEqual(LessThanOrEqualNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitLessThanOrEqual(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_EQ, 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 49 with CFValue

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

the class ValueTransfer method refineAtLengthAccess.

/**
 * Transform @IntVal or @IntRange annotations of a array or string length into an @ArrayLen
 * or @ArrayLenRange annotation for the array or string.
 */
private void refineAtLengthAccess(Node lengthNode, Node receiverNode, CFStore store) {
    Receiver lengthRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), lengthNode);
    // not marked @Pure, then do not refine.
    if (lengthRec instanceof FlowExpressions.Unknown) {
        return;
    }
    CFValue value = store.getValue(lengthRec);
    if (value == null) {
        return;
    }
    AnnotationMirror lengthAnno = getValueAnnotation(value);
    if (lengthAnno == null) {
        return;
    }
    if (AnnotationUtils.areSameByClass(lengthAnno, BottomVal.class)) {
        // If the length is bottom, then this is dead code, so the receiver type
        // should also be bottom.
        Receiver receiver = FlowExpressions.internalReprOf(atypefactory, receiverNode);
        store.insertValue(receiver, lengthAnno);
        return;
    }
    RangeOrListOfValues rolv;
    if (atypefactory.isIntRange(lengthAnno)) {
        rolv = new RangeOrListOfValues(ValueAnnotatedTypeFactory.getRange(lengthAnno));
    } else if (AnnotationUtils.areSameByClass(lengthAnno, IntVal.class)) {
        List<Long> lengthValues = ValueAnnotatedTypeFactory.getIntValues(lengthAnno);
        rolv = new RangeOrListOfValues(RangeOrListOfValues.convertLongsToInts(lengthValues));
    } else {
        return;
    }
    AnnotationMirror newRecAnno = rolv.createAnnotation(atypefactory);
    AnnotationMirror oldRecAnno = getArrayOrStringAnnotation(receiverNode);
    AnnotationMirror combinedRecAnno;
    // with the facts known about its length using GLB.
    if (oldRecAnno == null) {
        combinedRecAnno = newRecAnno;
    } else {
        combinedRecAnno = atypefactory.getQualifierHierarchy().greatestLowerBound(oldRecAnno, newRecAnno);
    }
    Receiver receiver = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiverNode);
    store.insertValue(receiver, combinedRecAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) IntVal(org.checkerframework.common.value.qual.IntVal) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) List(java.util.List) ArrayList(java.util.ArrayList)

Example 50 with CFValue

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

the class ValueTransfer method visitNumericalMultiplication.

@Override
public TransferResult<CFValue, CFStore> visitNumericalMultiplication(NumericalMultiplicationNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitNumericalMultiplication(n, p);
    AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.MULTIPLICATION, 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)

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