use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class ResourceLeakTransfer method updateStoreWithTempVar.
/**
* This method either creates or looks up the temp var t for node, and then updates the store to
* give t the same type as node. Temporary variables are supported for expressions throughout this
* checker (and the Must Call Checker) to enable refinement of their types. See the documentation
* of {@link MustCallConsistencyAnalyzer} for more details.
*
* @param node the node to be assigned to a temporary variable
* @param result the transfer result containing the store to be modified
*/
public void updateStoreWithTempVar(TransferResult<CFValue, CFStore> result, Node node) {
// Must-call obligations on primitives are not supported.
if (!TypesUtils.isPrimitiveOrBoxed(node.getType())) {
MustCallAnnotatedTypeFactory mcAtf = rlTypeFactory.getTypeFactoryOfSubchecker(MustCallChecker.class);
LocalVariableNode temp = mcAtf.getTempVar(node);
if (temp != null) {
rlTypeFactory.addTempVar(temp, node.getTree());
JavaExpression localExp = JavaExpression.fromNode(temp);
AnnotationMirror anm = rlTypeFactory.getAnnotatedType(node.getTree()).getAnnotationInHierarchy(rlTypeFactory.top);
insertIntoStores(result, localExp, anm == null ? rlTypeFactory.top : anm);
}
}
}
use of org.checkerframework.dataflow.expression.JavaExpression 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.isMapContainsKey(node) || factory.isMapPut(node)) {
Node receiver = node.getTarget().getReceiver();
JavaExpression receiverJe = JavaExpression.fromNode(receiver);
String mapName = receiverJe.toString();
JavaExpression keyExpr = JavaExpression.fromNode(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 && factory.areSameByClass(prevAm, KeyFor.class)) {
keyForMaps.addAll(getKeys(prevAm));
}
}
}
AnnotationMirror am = factory.createKeyForAnnotationMirrorWithValue(keyForMaps);
if (factory.isMapContainsKey(node)) {
// method is Map.containsKey
result.getThenStore().insertValue(keyExpr, am);
} else {
// method is Map.put
result.getThenStore().insertValue(keyExpr, am);
result.getElseStore().insertValue(keyExpr, am);
}
}
return result;
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class MustCallTransfer method visitAssignment.
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode n, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitAssignment(n, in);
// resource variables are closed.
if (atypeFactory.isResourceVariable(TreeUtils.elementFromTree(n.getTarget().getTree()))) {
CFStore store = result.getRegularStore();
JavaExpression expr = JavaExpression.fromNode(n.getTarget());
CFValue value = store.getValue(expr);
AnnotationMirror withClose = atypeFactory.getAnnotationByClass(value.getAnnotations(), MustCall.class);
if (withClose == null) {
return result;
}
AnnotationMirror withoutClose = atypeFactory.withoutClose(withClose);
insertIntoStores(result, expr, withoutClose);
}
return result;
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class LockTransfer method makeLockHeld.
/**
* Sets a given {@link Node} to @LockHeld in the given {@code store}.
*
* @param store the store to update
* @param node the node that should be @LockHeld
*/
protected void makeLockHeld(LockStore store, Node node) {
JavaExpression internalRepr = JavaExpression.fromNode(node);
store.insertValue(internalRepr, atypeFactory.LOCKHELD);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class NullnessTransfer method makeNonNull.
/**
* Sets a given {@link Node} to non-null in the given {@code store}. Calls to this method
* implement case 2.
*
* @param store the store to update
* @param node the node that should be non-null
*/
protected void makeNonNull(NullnessStore store, Node node) {
JavaExpression internalRepr = JavaExpression.fromNode(node);
store.insertValue(internalRepr, NONNULL);
}
Aggregations