use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method refineGTE.
/**
* Case 9: if x ≤ y, and y has a type that is related to the length of an array, then x has the
* same type.
*/
@Override
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
UBQualifier leftQualifier = UBQualifier.createUBQualifier(leftAnno, (UpperBoundChecker) atypeFactory.getChecker());
UBQualifier rightQualifier = UBQualifier.createUBQualifier(rightAnno, (UpperBoundChecker) atypeFactory.getChecker());
UBQualifier refinedRight = rightQualifier.glb(leftQualifier);
if (leftQualifier.isLessThanLengthQualifier()) {
propagateToOperands((LessThanLengthOf) leftQualifier, right, in, store);
}
refineSubtrahendWithOffset(left, right, false, in, store);
JavaExpression rightJe = JavaExpression.fromNode(right);
store.insertValue(rightJe, atypeFactory.convertUBQualifierToAnnotation(refinedRight));
}
use of org.checkerframework.dataflow.expression.JavaExpression 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)) {
JavaExpression stringLength = JavaExpression.fromNode(n);
if (stringLength instanceof MethodCall) {
JavaExpression receiverJe = ((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, receiverJe, receiverTree);
if (result != null) {
return result;
}
}
}
}
return super.visitMethodInvocation(n, in);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method refineEq.
/**
* Refines the type of the left and right node to glb of the left and right annotation.
*/
private void refineEq(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store) {
UBQualifier leftQualifier = UBQualifier.createUBQualifier(leftAnno, (UpperBoundChecker) atypeFactory.getChecker());
UBQualifier rightQualifier = UBQualifier.createUBQualifier(rightAnno, (UpperBoundChecker) atypeFactory.getChecker());
UBQualifier glb = rightQualifier.glb(leftQualifier);
AnnotationMirror glbAnno = atypeFactory.convertUBQualifierToAnnotation(glb);
List<Node> internalsRight = splitAssignments(right);
for (Node internal : internalsRight) {
JavaExpression rightJe = JavaExpression.fromNode(internal);
store.insertValue(rightJe, glbAnno);
}
List<Node> internalsLeft = splitAssignments(left);
for (Node internal : internalsLeft) {
JavaExpression leftJe = JavaExpression.fromNode(internal);
store.insertValue(leftJe, glbAnno);
}
}
use of org.checkerframework.dataflow.expression.JavaExpression 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);
JavaExpression arrayExpr = JavaExpression.fromNode(node.getTarget());
String arrayString = arrayExpr.toString();
LessThanLengthOf newInfo = (LessThanLengthOf) UBQualifier.createUBQualifier(arrayString, "-1");
UBQualifier combined = previousQualifier.glb(newInfo);
AnnotationMirror newAnno = atypeFactory.convertUBQualifierToAnnotation(combined);
JavaExpression dimExpr = JavaExpression.fromNode(dim);
result.getRegularStore().insertValue(dimExpr, newAnno);
propagateToOperands(newInfo, dim, in, result.getRegularStore());
}
return result;
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method propagateToMultiplicationOperand.
/**
* {@code other} times {@code node} is known to be {@code typeOfMultiplication}.
*
* <p>This implies that if {@code other} is positive, then {@code node} is {@code
* typeOfMultiplication}. If {@code other} is greater than 1, then {@code node} is {@code
* typeOfMultiplication} plus 1. These are cases 2 and 3, respectively.
*/
private void propagateToMultiplicationOperand(LessThanLengthOf typeOfMultiplication, Node node, Node other, TransferInput<CFValue, CFStore> in, CFStore store) {
if (atypeFactory.hasLowerBoundTypeByClass(other, Positive.class)) {
Long minValue = ValueCheckerUtils.getMinValue(other.getTree(), atypeFactory.getValueAnnotatedTypeFactory());
if (minValue != null && minValue > 1) {
typeOfMultiplication = (LessThanLengthOf) typeOfMultiplication.plusOffset(1);
}
UBQualifier qual = getUBQualifier(node, in);
UBQualifier newQual = qual.glb(typeOfMultiplication);
JavaExpression je = JavaExpression.fromNode(node);
store.insertValue(je, atypeFactory.convertUBQualifierToAnnotation(newQual));
}
}
Aggregations