Search in sources :

Example 21 with CFStore

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

the class LowerBoundTransfer method visitNumericalAddition.

@Override
public TransferResult<CFValue, CFStore> visitNumericalAddition(NumericalAdditionNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> result = super.visitNumericalAddition(n, p);
    AnnotationMirror newAnno = getAnnotationForPlus(n, p);
    return createNewResult(result, newAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore)

Example 22 with CFStore

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

the class LowerBoundTransfer method visitBitwiseAnd.

@Override
public TransferResult<CFValue, CFStore> visitBitwiseAnd(BitwiseAndNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitBitwiseAnd(n, p);
    AnnotationMirror resultAnno = getAnnotationForAnd(n, 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 23 with CFStore

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

the class UpperBoundAnnotatedTypeFactory method fromLessThanOrEqual.

private UBQualifier fromLessThanOrEqual(Tree tree, TreePath treePath, List<String> lessThanExpressions) {
    UBQualifier ubQualifier = null;
    for (String expression : lessThanExpressions) {
        FlowExpressions.Receiver receiver;
        try {
            receiver = getReceiverFromJavaExpressionString(expression, treePath);
        } catch (FlowExpressionParseException e) {
            receiver = null;
        }
        if (receiver == null || !CFAbstractStore.canInsertReceiver(receiver)) {
            continue;
        }
        CFStore store = getStoreBefore(tree);
        if (store != null) {
            CFValue value = store.getValue(receiver);
            if (value != null && value.getAnnotations().size() == 1) {
                UBQualifier newUBQ = UBQualifier.createUBQualifier(value.getAnnotations().iterator().next());
                if (ubQualifier == null) {
                    ubQualifier = newUBQ;
                } else {
                    ubQualifier = ubQualifier.glb(newUBQ);
                }
            }
        }
    }
    return ubQualifier;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) FlowExpressionParseException(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException)

Example 24 with CFStore

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

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

the class RegexTransfer method handleMatcherGroupCount.

/**
 * See whether possibleMatcher is a call of groupCount on a Matcher and possibleConstant is a
 * constant. If so, annotate the matcher as constant + 1 if !isAlsoEqual constant if isAlsoEqual
 *
 * @param possibleMatcher the Node that might be a call of Matcher.groupCount()
 * @param possibleConstant the Node that might be a constant
 * @param isAlsoEqual whether the comparison operation is strict or reflexive
 * @param in the TransferInput
 * @param resultIn TransferResult
 * @return the possibly refined output TransferResult
 */
private TransferResult<CFValue, CFStore> handleMatcherGroupCount(Node possibleMatcher, Node possibleConstant, boolean isAlsoEqual, TransferInput<CFValue, CFStore> in, TransferResult<CFValue, CFStore> resultIn) {
    if (!(possibleMatcher instanceof MethodInvocationNode)) {
        return resultIn;
    }
    if (!(possibleConstant instanceof IntegerLiteralNode)) {
        return resultIn;
    }
    MethodAccessNode methodAccessNode = ((MethodInvocationNode) possibleMatcher).getTarget();
    ExecutableElement method = methodAccessNode.getMethod();
    Node receiver = methodAccessNode.getReceiver();
    if (!isMatcherGroupCountMethod(method, receiver)) {
        return resultIn;
    }
    Receiver matcherReceiver = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiver);
    IntegerLiteralNode iln = (IntegerLiteralNode) possibleConstant;
    int groupCount;
    if (isAlsoEqual) {
        groupCount = iln.getValue();
    } else {
        groupCount = iln.getValue() + 1;
    }
    CFStore thenStore = resultIn.getRegularStore();
    CFStore elseStore = thenStore.copy();
    ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(resultIn.getResultValue(), thenStore, elseStore);
    RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
    AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
    thenStore.insertValue(matcherReceiver, regexAnnotation);
    return newResult;
}
Also used : CFStore(org.checkerframework.framework.flow.CFStore) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) ExecutableElement(javax.lang.model.element.ExecutableElement) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) ClassNameNode(org.checkerframework.dataflow.cfg.node.ClassNameNode) LessThanNode(org.checkerframework.dataflow.cfg.node.LessThanNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode) GreaterThanNode(org.checkerframework.dataflow.cfg.node.GreaterThanNode) LessThanOrEqualNode(org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode) GreaterThanOrEqualNode(org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode) Node(org.checkerframework.dataflow.cfg.node.Node) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)

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