use of org.checkerframework.framework.flow.CFStore 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.CFStore 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.CFStore 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.CFStore 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.CFStore in project checker-framework by typetools.
the class RegexTransfer method visitMethodInvocation.
// TODO: These are special cases for isRegex(String, int) and asRegex(String, int).
// They should be replaced by adding an @EnsuresQualifierIf annotation that supports
// specifying attributes.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(n, in);
// refine result for some helper methods
MethodAccessNode target = n.getTarget();
ExecutableElement method = target.getMethod();
Node receiver = target.getReceiver();
if (receiver instanceof ClassNameNode) {
ClassNameNode cnn = (ClassNameNode) receiver;
String receiverName = cnn.getElement().toString();
if (isRegexUtil(receiverName)) {
result = handleRegexUtil(n, method, result);
}
}
return result;
}
Aggregations