use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class InitializationTransfer method visitAssignment.
@Override
public TransferResult<V, S> visitAssignment(AssignmentNode n, TransferInput<V, S> in) {
TransferResult<V, S> result = super.visitAssignment(n, in);
assert result instanceof RegularTransferResult;
Receiver expr = FlowExpressions.internalReprOf(analysis.getTypeFactory(), n.getTarget());
// initialized.
if (!expr.containsUnknown()) {
if (expr instanceof FieldAccess) {
FieldAccess fa = (FieldAccess) expr;
result.getRegularStore().addInitializedField(fa);
}
}
return result;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LockTransfer method makeLockPossiblyHeld.
/**
* Sets a given {@link Node} to @LockPossiblyHeld in the given {@code store}.
*/
protected void makeLockPossiblyHeld(LockStore store, Node node) {
Receiver internalRepr = FlowExpressions.internalReprOf(atypeFactory, node);
// insertValue cannot change an annotation to a less
// specific type (e.g. LockHeld to LockPossiblyHeld),
// so insertLockPossiblyHeld is called.
store.insertLockPossiblyHeld(internalRepr);
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LockTransfer method makeLockHeld.
/**
* Sets a given {@link Node} to @LockHeld in the given {@code store}.
*/
protected void makeLockHeld(LockStore store, Node node) {
Receiver internalRepr = FlowExpressions.internalReprOf(atypeFactory, node);
store.insertValue(internalRepr, atypeFactory.LOCKHELD);
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LockVisitor method getLockExpressions.
private List<LockExpression> getLockExpressions(boolean implicitThis, AnnotationMirror gbAnno, Tree tree) {
List<String> expressions = AnnotationUtils.getElementValueArray(gbAnno, "value", String.class, true);
if (expressions.isEmpty()) {
return Collections.emptyList();
}
TreePath currentPath = getCurrentPath();
List<Receiver> params = FlowExpressions.getParametersOfEnclosingMethod(atypeFactory, currentPath);
TypeMirror enclosingType = TreeUtils.typeOf(TreeUtils.enclosingClass(currentPath));
Receiver pseudoReceiver = FlowExpressions.internalReprOfPseudoReceiver(currentPath, enclosingType);
FlowExpressionContext exprContext = new FlowExpressionContext(pseudoReceiver, params, atypeFactory.getContext());
Receiver self;
if (implicitThis) {
self = pseudoReceiver;
} else if (TreeUtils.isExpressionTree(tree)) {
self = FlowExpressions.internalReprOf(atypeFactory, (ExpressionTree) tree);
} else {
self = new Unknown(TreeUtils.typeOf(tree));
}
List<LockExpression> lockExpressions = new ArrayList<>();
for (String expression : expressions) {
lockExpressions.add(parseExpressionString(expression, exprContext, currentPath, self));
}
return lockExpressions;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class KeyForTransfer method visitMethodInvocation.
/*
* Provided that m is of a type that implements interface java.util.Map:
* <ul>
* <li>Given a call m.containsKey(k), ensures that k is @KeyFor("m") in the thenStore of the transfer result.
* <li>Given a call m.put(k, ...), ensures that k is @KeyFor("m") in the thenStore and elseStore of the transfer result.
* </ul>
*/
@Override
public TransferResult<KeyForValue, KeyForStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<KeyForValue, KeyForStore> in) {
TransferResult<KeyForValue, KeyForStore> result = super.visitMethodInvocation(node, in);
KeyForAnnotatedTypeFactory factory = (KeyForAnnotatedTypeFactory) analysis.getTypeFactory();
if (factory.isInvocationOfMapMethod(node, "containsKey") || factory.isInvocationOfMapMethod(node, "put")) {
Node receiver = node.getTarget().getReceiver();
Receiver internalReceiver = FlowExpressions.internalReprOf(factory, receiver);
String mapName = internalReceiver.toString();
Receiver keyReceiver = FlowExpressions.internalReprOf(factory, node.getArgument(0));
LinkedHashSet<String> keyForMaps = new LinkedHashSet<>();
keyForMaps.add(mapName);
final KeyForValue previousKeyValue = in.getValueOfSubNode(node.getArgument(0));
if (previousKeyValue != null) {
for (AnnotationMirror prevAm : previousKeyValue.getAnnotations()) {
if (prevAm != null && AnnotationUtils.areSameByClass(prevAm, KeyFor.class)) {
keyForMaps.addAll(getKeys(prevAm));
}
}
}
AnnotationMirror am = factory.createKeyForAnnotationMirrorWithValue(keyForMaps);
if (factory.getMethodName(node).equals("containsKey")) {
result.getThenStore().insertValue(keyReceiver, am);
} else {
// method name is "put"
result.getThenStore().insertValue(keyReceiver, am);
result.getElseStore().insertValue(keyReceiver, am);
}
}
return result;
}
Aggregations