Search in sources :

Example 6 with LocalVariable

use of org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable in project checker-framework by typetools.

the class LockAnnotatedTypeFactory method isExpressionEffectivelyFinal.

/**
 * Returns whether or not the expression is effectively final.
 *
 * <p>This method returns true in the following cases when expr is:
 *
 * <p>1. a field access and the field is final and the field access expression is effectively
 * final as specified by this method.
 *
 * <p>2. an effectively final local variable.
 *
 * <p>3. a deterministic method call whose arguments and receiver expression are effectively
 * final as specified by this method.
 *
 * <p>4. a this reference or a class literal
 *
 * @param expr expression
 * @return whether or not the expression is effectively final
 */
boolean isExpressionEffectivelyFinal(Receiver expr) {
    if (expr instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) expr;
        Receiver recv = fieldAccess.getReceiver();
        // Don't call fieldAccess
        return fieldAccess.isFinal() && isExpressionEffectivelyFinal(recv);
    } else if (expr instanceof LocalVariable) {
        return ElementUtils.isEffectivelyFinal(((LocalVariable) expr).getElement());
    } else if (expr instanceof MethodCall) {
        MethodCall methodCall = (MethodCall) expr;
        for (Receiver param : methodCall.getParameters()) {
            if (!isExpressionEffectivelyFinal(param)) {
                return false;
            }
        }
        return PurityUtils.isDeterministic(this, methodCall.getElement()) && isExpressionEffectivelyFinal(methodCall.getReceiver());
    } else if (expr instanceof ThisReference || expr instanceof ClassName) {
        // final too.
        return true;
    } else {
        // type of 'expr' is not supported in @GuardedBy(...) lock expressions
        return false;
    }
}
Also used : LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) ClassName(org.checkerframework.dataflow.analysis.FlowExpressions.ClassName) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) ThisReference(org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference) MethodCall(org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)

Example 7 with LocalVariable

use of org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable 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)

Aggregations

LocalVariable (org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable)7 Element (javax.lang.model.element.Element)5 VariableElement (javax.lang.model.element.VariableElement)5 ExecutableElement (javax.lang.model.element.ExecutableElement)4 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)4 TypeElement (javax.lang.model.element.TypeElement)3 ClassName (org.checkerframework.dataflow.analysis.FlowExpressions.ClassName)3 ThisReference (org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference)3 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)2 CFAbstractStore (org.checkerframework.framework.flow.CFAbstractStore)2 CFAbstractValue (org.checkerframework.framework.flow.CFAbstractValue)2 CFValue (org.checkerframework.framework.flow.CFValue)2 ArrayList (java.util.ArrayList)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 MethodCall (org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)1 CFStore (org.checkerframework.framework.flow.CFStore)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 Resolver (org.checkerframework.javacutil.Resolver)1