Search in sources :

Example 31 with CFValue

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

the class LockStore method updateForMethodCall.

@Override
public void updateForMethodCall(MethodInvocationNode n, AnnotatedTypeFactory atypeFactory, CFValue val) {
    super.updateForMethodCall(n, atypeFactory, val);
    ExecutableElement method = n.getTarget().getMethod();
    if (!isSideEffectFree(atypeFactory, method)) {
        // the GuardedBy hierarchy should not be changed.
        for (FieldAccess field : new ArrayList<>(fieldValues.keySet())) {
            fieldValues.put(field, changeLockAnnoToTop(field, fieldValues.get(field)));
        }
        // Local variables could also be unlocked via an alias
        for (LocalVariable var : new ArrayList<>(localVariableValues.keySet())) {
            CFValue newValue = changeLockAnnoToTop(var, localVariableValues.get(var));
            localVariableValues.put(var, newValue);
        }
        if (thisValue != null) {
            thisValue = changeLockAnnoToTop(null, thisValue);
        }
    }
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)

Example 32 with CFValue

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

the class LockStore method insertLockPossiblyHeld.

/*
     * Insert an annotation exactly, without regard to whether an annotation was already present.
     * This is only done for @LockPossiblyHeld. This is not sound for other type qualifiers.
     */
public void insertLockPossiblyHeld(FlowExpressions.Receiver r) {
    if (r.containsUnknown()) {
        // Expressions containing unknown expressions are not stored.
        return;
    }
    if (r instanceof FlowExpressions.LocalVariable) {
        FlowExpressions.LocalVariable localVar = (FlowExpressions.LocalVariable) r;
        CFValue current = localVariableValues.get(localVar);
        CFValue value = changeLockAnnoToTop(r, current);
        localVariableValues.put(localVar, value);
    } else if (r instanceof FlowExpressions.FieldAccess) {
        FlowExpressions.FieldAccess fieldAcc = (FlowExpressions.FieldAccess) r;
        CFValue current = fieldValues.get(fieldAcc);
        CFValue value = changeLockAnnoToTop(r, current);
        fieldValues.put(fieldAcc, value);
    } else if (r instanceof FlowExpressions.MethodCall) {
        FlowExpressions.MethodCall method = (FlowExpressions.MethodCall) r;
        CFValue current = methodValues.get(method);
        CFValue value = changeLockAnnoToTop(r, current);
        methodValues.put(method, value);
    } else if (r instanceof FlowExpressions.ArrayAccess) {
        FlowExpressions.ArrayAccess arrayAccess = (ArrayAccess) r;
        CFValue current = arrayValues.get(arrayAccess);
        CFValue value = changeLockAnnoToTop(r, current);
        arrayValues.put(arrayAccess, value);
    } else if (r instanceof FlowExpressions.ThisReference) {
        thisValue = changeLockAnnoToTop(r, thisValue);
    } else if (r instanceof FlowExpressions.ClassName) {
        FlowExpressions.ClassName className = (FlowExpressions.ClassName) r;
        CFValue current = classValues.get(className);
        CFValue value = changeLockAnnoToTop(r, current);
        classValues.put(className, value);
    } else {
    // No other types of expressions need to be stored.
    }
}
Also used : ArrayAccess(org.checkerframework.dataflow.analysis.FlowExpressions.ArrayAccess) LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) CFValue(org.checkerframework.framework.flow.CFValue) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) ArrayAccess(org.checkerframework.dataflow.analysis.FlowExpressions.ArrayAccess) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)

Example 33 with CFValue

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

Example 34 with CFValue

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

the class FormatterTransfer method visitMethodInvocation.

/**
 * Makes it so that the {@link FormatUtil#asFormat} method returns a correctly annotated String.
 */
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
    FormatterAnnotatedTypeFactory atypeFactory = (FormatterAnnotatedTypeFactory) analysis.getTypeFactory();
    TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
    FormatterTreeUtil tu = atypeFactory.treeUtil;
    if (tu.isAsFormatCall(node, atypeFactory)) {
        Result<ConversionCategory[]> cats = tu.asFormatCallCategories(node);
        if (cats.value() == null) {
            tu.failure(cats, "format.asformat.indirect.arguments");
        } else {
            AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
            CFValue newResultValue = analysis.createSingleAnnotationValue(anno, result.getResultValue().getUnderlyingType());
            return new RegularTransferResult<>(newResultValue, result.getRegularStore());
        }
    }
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 35 with CFValue

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

the class LowerBoundTransfer method visitIntegerDivision.

@Override
public TransferResult<CFValue, CFStore> visitIntegerDivision(IntegerDivisionNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> result = super.visitIntegerDivision(n, p);
    AnnotationMirror newAnno = getAnnotationForDivide(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)

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