Search in sources :

Example 1 with CFValue

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

the class GenericAnnotatedTypeFactory method createFlowAnalysis.

/**
 * Returns the appropriate flow analysis class that is used for the
 * org.checkerframework.dataflow analysis.
 *
 * <p>This implementation uses the checker naming convention to create the appropriate analysis.
 * If no transfer function is found, it returns an instance of {@link CFAnalysis}.
 *
 * <p>Subclasses have to override this method to create the appropriate analysis if they do not
 * follow the checker naming convention.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected FlowAnalysis createFlowAnalysis(List<Pair<VariableElement, Value>> fieldValues) {
    // Try to reflectively load the visitor.
    Class<?> checkerClass = checker.getClass();
    while (checkerClass != BaseTypeChecker.class) {
        final String classToLoad = checkerClass.getName().replace("Checker", "Analysis").replace("Subchecker", "Analysis");
        FlowAnalysis result = BaseTypeChecker.invokeConstructorFor(classToLoad, new Class<?>[] { BaseTypeChecker.class, this.getClass(), List.class }, new Object[] { checker, this, fieldValues });
        if (result != null) {
            return result;
        }
        checkerClass = checkerClass.getSuperclass();
    }
    // If an analysis couldn't be loaded reflectively, return the
    // default.
    List<Pair<VariableElement, CFValue>> tmp = new ArrayList<>();
    for (Pair<VariableElement, Value> fieldVal : fieldValues) {
        assert fieldVal.second instanceof CFValue;
        tmp.add(Pair.of(fieldVal.first, (CFValue) fieldVal.second));
    }
    return (FlowAnalysis) new CFAnalysis(checker, (GenericAnnotatedTypeFactory) this, tmp);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFAnalysis(org.checkerframework.framework.flow.CFAnalysis) ArrayList(java.util.ArrayList) CFAbstractValue(org.checkerframework.framework.flow.CFAbstractValue) CFValue(org.checkerframework.framework.flow.CFValue) VariableElement(javax.lang.model.element.VariableElement) Pair(org.checkerframework.javacutil.Pair)

Example 2 with CFValue

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

the class ValueTransfer method visitBitwiseComplement.

@Override
public TransferResult<CFValue, CFStore> visitBitwiseComplement(BitwiseComplementNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitBitwiseComplement(n, p);
    AnnotationMirror resultAnno = calculateNumericalUnaryOp(n.getOperand(), NumericalUnaryOps.BITWISE_COMPLEMENT, 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 3 with CFValue

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

the class ValueTransfer method visitNumericalSubtraction.

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

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

the class ValueTransfer method visitNumericalMinus.

@Override
public TransferResult<CFValue, CFStore> visitNumericalMinus(NumericalMinusNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitNumericalMinus(n, p);
    AnnotationMirror resultAnno = calculateNumericalUnaryOp(n.getOperand(), NumericalUnaryOps.MINUS, 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 5 with CFValue

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

the class ValueTransfer method createNewResultBoolean.

/**
 * Create a boolean transfer result.
 */
private TransferResult<CFValue, CFStore> createNewResultBoolean(CFStore thenStore, CFStore elseStore, List<Boolean> resultValues, TypeMirror underlyingType) {
    AnnotationMirror boolVal = atypefactory.createBooleanAnnotation(resultValues);
    CFValue newResultValue = analysis.createSingleAnnotationValue(boolVal, underlyingType);
    if (elseStore != null) {
        return new ConditionalTransferResult<>(newResultValue, thenStore, elseStore);
    } else {
        return new RegularTransferResult<>(newResultValue, thenStore);
    }
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

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