use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class UpperBoundTransfer method createTransferResult.
private TransferResult<CFValue, CFStore> createTransferResult(Node n, TransferInput<CFValue, CFStore> in, UBQualifier qualifier) {
AnnotationMirror newAnno = atypeFactory.convertUBQualifierToAnnotation(qualifier);
CFValue value = analysis.createSingleAnnotationValue(newAnno, n.getType());
if (in.containsTwoStores()) {
CFStore thenStore = in.getThenStore();
CFStore elseStore = in.getElseStore();
return new ConditionalTransferResult<>(finishValue(value, thenStore, elseStore), thenStore, elseStore);
} else {
CFStore info = in.getRegularStore();
return new RegularTransferResult<>(finishValue(value, info), info);
}
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class UpperBoundTransfer method visitMethodInvocation.
/**
* If n is a String.length() method invocation, then the type of s.length() is the glb
* of @LTEqLengthOf("s") and the value of s.length() in the store. This is case 20.
*/
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
if (atypeFactory.getMethodIdentifier().isLengthOfMethodInvocation(n)) {
Receiver stringLength = FlowExpressions.internalReprOf(atypeFactory, n);
if (stringLength instanceof MethodCall) {
Receiver receiverRec = ((MethodCall) stringLength).getReceiver();
Tree receiverTree = n.getTarget().getReceiver().getTree();
// receiverTree is null when the receiver is implicit "this".
if (receiverTree != null) {
TransferResult<CFValue, CFStore> result = visitLengthAccess(n, in, receiverRec, receiverTree);
if (result != null) {
return result;
}
}
}
}
return super.visitMethodInvocation(n, in);
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class UpperBoundTransfer method strengthenAnnotationOfEqualTo.
/**
* Implements case 11.
*/
@Override
protected TransferResult<CFValue, CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> res, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) {
TransferResult<CFValue, CFStore> result = super.strengthenAnnotationOfEqualTo(res, firstNode, secondNode, firstValue, secondValue, notEqualTo);
IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, firstNode, secondNode);
if (rfi.leftAnno == null || rfi.rightAnno == null) {
return result;
}
CFStore equalsStore = notEqualTo ? rfi.elseStore : rfi.thenStore;
CFStore notEqualStore = notEqualTo ? rfi.thenStore : rfi.elseStore;
refineEq(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, equalsStore);
refineNeqSequenceLength(rfi.left, rfi.right, rfi.rightAnno, notEqualStore);
refineNeqSequenceLength(rfi.right, rfi.left, rfi.leftAnno, notEqualStore);
return rfi.newResult;
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class UpperBoundTransfer method visitAssignment.
/**
* Case 1: Refine the type of expressions used as an array dimension to be less than length of
* the array to which the new array is assigned. For example, in "int[] array = new int[expr];",
* the type of expr is @LTEqLength("array").
*/
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode node, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitAssignment(node, in);
Node expNode = node.getExpression();
// strip off typecast if any
Node expNodeSansCast = (expNode instanceof TypeCastNode) ? ((TypeCastNode) expNode).getOperand() : expNode;
// null if right-hand-side is not an array creation expression
ArrayCreationNode acNode = (expNodeSansCast instanceof ArrayCreationNode) ? acNode = (ArrayCreationNode) expNodeSansCast : null;
if (acNode != null) {
// Right-hand side of assignment is an array creation expression
List<Node> nodeList = acNode.getDimensions();
if (nodeList.size() < 1) {
return result;
}
Node dim = acNode.getDimension(0);
UBQualifier previousQualifier = getUBQualifier(dim, in);
Receiver arrayRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
String arrayString = arrayRec.toString();
LessThanLengthOf newInfo = (LessThanLengthOf) UBQualifier.createUBQualifier(arrayString, "-1");
UBQualifier combined = previousQualifier.glb(newInfo);
AnnotationMirror newAnno = atypeFactory.convertUBQualifierToAnnotation(combined);
Receiver dimRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), dim);
result.getRegularStore().insertValue(dimRec, newAnno);
propagateToOperands(newInfo, dim, in, result.getRegularStore());
}
return result;
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LockStore method insertValue.
@Override
public void insertValue(FlowExpressions.Receiver r, @Nullable CFValue value) {
if (value == null) {
// top and top is also the default value.
return;
}
// side effect the lock expression that has value @LockHeld.
if (hasLockHeld(value)) {
if (r instanceof FlowExpressions.FieldAccess) {
FlowExpressions.FieldAccess fieldAcc = (FlowExpressions.FieldAccess) r;
CFValue oldValue = fieldValues.get(fieldAcc);
CFValue newValue = value.mostSpecific(oldValue, null);
if (newValue != null) {
fieldValues.put(fieldAcc, newValue);
}
} else if (r instanceof FlowExpressions.MethodCall) {
FlowExpressions.MethodCall method = (FlowExpressions.MethodCall) r;
CFValue oldValue = methodValues.get(method);
CFValue newValue = value.mostSpecific(oldValue, null);
if (newValue != null) {
methodValues.put(method, newValue);
}
}
}
super.insertValue(r, value);
}
Aggregations