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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations