Search in sources :

Example 21 with FieldAccess

use of org.checkerframework.dataflow.expression.FieldAccess in project checker-framework by typetools.

the class LockStore method insertValue.

@Override
public void insertValue(JavaExpression je, @Nullable CFValue value, boolean permitNondeterministic) {
    if (!shouldInsert(je, value, permitNondeterministic)) {
        return;
    }
    // side effect the lock expression that has value @LockHeld.
    if (hasLockHeld(value)) {
        if (je instanceof FieldAccess) {
            FieldAccess fieldAcc = (FieldAccess) je;
            CFValue oldValue = fieldValues.get(fieldAcc);
            CFValue newValue = value.mostSpecific(oldValue, null);
            if (newValue != null) {
                fieldValues.put(fieldAcc, newValue);
            }
        } else if (je instanceof MethodCall) {
            MethodCall method = (MethodCall) je;
            CFValue oldValue = methodValues.get(method);
            CFValue newValue = value.mostSpecific(oldValue, null);
            if (newValue != null) {
                methodValues.put(method, newValue);
            }
        }
    }
    super.insertValue(je, value, permitNondeterministic);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) FieldAccess(org.checkerframework.dataflow.expression.FieldAccess) MethodCall(org.checkerframework.dataflow.expression.MethodCall)

Example 22 with FieldAccess

use of org.checkerframework.dataflow.expression.FieldAccess in project checker-framework by typetools.

the class InitializationStore method leastUpperBound.

@Override
public S leastUpperBound(S other) {
    // Remove invariant annotated fields to avoid performance issue reported in #1438.
    Map<FieldAccess, V> removedFieldValues = new HashMap<>(invariantFields.size());
    Map<FieldAccess, V> removedOtherFieldValues = new HashMap<>(other.invariantFields.size());
    for (FieldAccess invariantField : invariantFields.keySet()) {
        V v = fieldValues.remove(invariantField);
        removedFieldValues.put(invariantField, v);
    }
    for (FieldAccess invariantField : other.invariantFields.keySet()) {
        V v = other.fieldValues.remove(invariantField);
        removedOtherFieldValues.put(invariantField, v);
    }
    S result = super.leastUpperBound(other);
    // Restore removed values.
    fieldValues.putAll(removedFieldValues);
    other.fieldValues.putAll(removedOtherFieldValues);
    // Set intersection for initializedFields.
    result.initializedFields.addAll(other.initializedFields);
    result.initializedFields.retainAll(initializedFields);
    // Set intersection for invariantFields.
    for (Map.Entry<FieldAccess, V> e : invariantFields.entrySet()) {
        FieldAccess key = e.getKey();
        if (other.invariantFields.containsKey(key)) {
            // TODO: Is the value other.invariantFields.get(key) the same as e.getValue()?  Should the
            // two values be lubbed?
            result.invariantFields.put(key, e.getValue());
        }
    }
    // Add invariant annotation.
    result.fieldValues.putAll(result.invariantFields);
    return result;
}
Also used : HashMap(java.util.HashMap) FieldAccess(org.checkerframework.dataflow.expression.FieldAccess) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with FieldAccess

use of org.checkerframework.dataflow.expression.FieldAccess in project checker-framework by typetools.

the class InitializationStore method updateForMethodCall.

/**
 * {@inheritDoc}
 *
 * <p>Additionally, the {@link InitializationStore} keeps all field values for fields that have
 * the 'invariant' annotation.
 */
@Override
public void updateForMethodCall(MethodInvocationNode n, AnnotatedTypeFactory atypeFactory, V val) {
    // Remove invariant annotated fields to avoid performance issue reported in #1438.
    for (FieldAccess invariantField : invariantFields.keySet()) {
        fieldValues.remove(invariantField);
    }
    super.updateForMethodCall(n, atypeFactory, val);
    // Add invariant annotation again.
    fieldValues.putAll(invariantFields);
}
Also used : FieldAccess(org.checkerframework.dataflow.expression.FieldAccess)

Example 24 with FieldAccess

use of org.checkerframework.dataflow.expression.FieldAccess 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 = (FieldAccess) JavaExpression.fromNodeFieldAccess(n);
        JavaExpression arrayJe = arrayLength.getReceiver();
        Tree arrayTree = n.getReceiver().getTree();
        TransferResult<CFValue, CFStore> result = visitLengthAccess(n, in, arrayJe, 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) JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) Tree(com.sun.source.tree.Tree) FieldAccess(org.checkerframework.dataflow.expression.FieldAccess)

Example 25 with FieldAccess

use of org.checkerframework.dataflow.expression.FieldAccess in project checker-framework by typetools.

the class Subsequence method getSubsequenceFromReceiver.

/**
 * Returns a Subsequence representing the {@link HasSubsequence} annotation on the declaration of
 * {@code rec} or null if there is not such annotation.
 *
 * @param expr some tree
 * @param factory an AnnotatedTypeFactory
 * @return null or a new Subsequence from the declaration of {@code varTree}
 */
public static Subsequence getSubsequenceFromReceiver(JavaExpression expr, BaseAnnotatedTypeFactoryForIndexChecker factory) {
    if (!(expr instanceof FieldAccess)) {
        return null;
    }
    FieldAccess fa = (FieldAccess) expr;
    VariableElement element = fa.getField();
    AnnotationMirror hasSub = factory.getDeclAnnotation(element, HasSubsequence.class);
    if (hasSub == null) {
        return null;
    }
    String array = standardizeAndViewpointAdapt(factory.hasSubsequenceSubsequenceValue(hasSub), fa, factory.getChecker());
    String from = standardizeAndViewpointAdapt(factory.hasSubsequenceFromValue(hasSub), fa, factory.getChecker());
    String to = standardizeAndViewpointAdapt(factory.hasSubsequenceToValue(hasSub), fa, factory.getChecker());
    return new Subsequence(array, from, to);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) HasSubsequence(org.checkerframework.checker.index.qual.HasSubsequence) VariableElement(javax.lang.model.element.VariableElement) FieldAccess(org.checkerframework.dataflow.expression.FieldAccess)

Aggregations

FieldAccess (org.checkerframework.dataflow.expression.FieldAccess)26 LocalVariable (org.checkerframework.dataflow.expression.LocalVariable)11 ClassName (org.checkerframework.dataflow.expression.ClassName)10 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)9 MethodCall (org.checkerframework.dataflow.expression.MethodCall)9 HashMap (java.util.HashMap)8 ArrayAccess (org.checkerframework.dataflow.expression.ArrayAccess)8 Map (java.util.Map)7 ThisReference (org.checkerframework.dataflow.expression.ThisReference)7 AnnotationMirror (javax.lang.model.element.AnnotationMirror)5 CFValue (org.checkerframework.framework.flow.CFValue)5 Element (javax.lang.model.element.Element)4 ExecutableElement (javax.lang.model.element.ExecutableElement)4 VariableElement (javax.lang.model.element.VariableElement)4 JavaExpressionParseException (org.checkerframework.framework.util.JavaExpressionParseUtil.JavaExpressionParseException)3 MethodTree (com.sun.source.tree.MethodTree)2 Tree (com.sun.source.tree.Tree)2 ArrayList (java.util.ArrayList)2 TypeElement (javax.lang.model.element.TypeElement)2 CFStore (org.checkerframework.framework.flow.CFStore)2