Class UpperBoundTransfer
java.lang.Object
org.checkerframework.dataflow.cfg.node.AbstractNodeVisitor<TransferResult<V,S>,TransferInput<V,S>>
org.checkerframework.framework.flow.CFAbstractTransfer<CFValue,CFStore,CFTransfer>
org.checkerframework.framework.flow.CFTransfer
org.checkerframework.checker.index.IndexAbstractTransfer
org.checkerframework.checker.index.upperbound.UpperBoundTransfer
- All Implemented Interfaces:
ForwardTransferFunction<CFValue,
,CFStore> TransferFunction<CFValue,
,CFStore> NodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>>
Contains the transfer functions for the upper bound type system, a part of the Index Checker.
This class implements the following refinement rules:
- 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")
. - 2. If
other * node
has typetypeOfMultiplication
, then ifother
is positive, thennode
istypeOfMultiplication
. - 3. If
other * node
has typetypeOfMultiplication
, ifother
is greater than 1, thennode
istypeOfMultiplication
plus 1. - 4. Given a subtraction node,
node
, that is known to have typetypeOfSubtraction
. An offset can be applied to the left node (i.e. the left node has the same type, but with an offset based on the right node). - 5. In an addition expression, refine the two operands based on the type of the whole expression with appropriate offsets.
- 6. If an addition expression has a type that is less than length of an array, and one of the operands is non-negative, then the other is less than or equal to the length of the array.
- 7. If an addition expression has a type that is less than length of an array, and one of the operands is positive, then the other is also less than the length of the array.
- 8. if x < y, and y has a type that is related to the length of an array, then x has the same type, with an offset that is one less.
- 9. if x ≤ y, and y has a type that is related to the length of an array, then x has the same type.
- 10. refine the subtrahend in a subtraction which is greater than or equal to a certain offset. The type of the subtrahend is refined to the type of the minuend with the offset added.
- 11. if two variables are equal, they have the same type
- 12. If one node in a != expression is an sequence length field or method access (optionally with a constant offset subtracted) and the other node is less than or equal to that sequence length (minus the offset), then refine the other node's type to less than the sequence length (minus the offset).
- 13. If some Node a is known to be less than the length of some array, x, then, the type of
a + b, is
@LTLengthOf(value="x", offset="-b")
. If b is known to be less than the length of some other array, y, then the type of a + b is@LTLengthOf(value={"x", "y"}, offset={"-b", "-a"})
. - 14. If a is known to be less than the length of x when some offset, o, is added to a (the
type of a is
@LTLengthOf(value="x", offset="o"))
, then the type of a + b is@LTLengthOf(value="x",offset="o - b")
. (Note, if "o - b" can be computed, then it is and the result is used in the annotation.) - 15. If expression i has type
@LTLengthOf(value = "f2", offset = "f1.length")
int and expression j is less than or equal to the length of f1, then the type of i + j is@LTLengthOf("f2")
. - 16. If some Node a is known to be less than the length of some sequence x, then the type of
a - b is
@LTLengthOf(value="x", offset="b")
. - 17. If some Node a is known to be less than the length of some sequence x, and if b is non-negative or positive, then a - b should keep the types of a.
- 18. The type of a sequence length access (i.e. array.length) is
@LTLength(value={"array"...}, offset="-1")
where "array"... is the set of all sequences that are the same length (via the SameLen checker) as "array" - 19. If n is an array length field access, then the type of a.length is the glb of
@LTEqLengthOf("a")
and the value of a.length in the store. - 20. 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.
-
Field Summary
Fields inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
analysis, sequentialSemantics
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
refineGT
(Node larger, AnnotationMirror largerAnno, Node smaller, AnnotationMirror smallerAnno, CFStore store, TransferInput<CFValue, CFStore> in) Case 8: if x < y, and y has a type that is related to the length of an array, then x has the same type, with an offset that is one less.protected void
refineGTE
(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) 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.protected TransferResult<CFValue,
CFStore> strengthenAnnotationOfEqualTo
(TransferResult<CFValue, CFStore> res, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) Implements case 11.visitAssignment
(AssignmentNode node, TransferInput<CFValue, CFStore> in) 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.visitCase
(CaseNode n, TransferInput<CFValue, CFStore> in) A case produces no value, but it may imply some facts about switch selector expression.If n is an array length field access, then the type of a.length is the glb of @LTEqLengthOf("a") and the value of a.length in the store.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.If some Node a is known to be less than the length of some array, x, then, the type of a + b, is @LTLengthOf(value="x", offset="-b").If some Node a is known to be less than the length of some sequence x, then the type of a - b is @LTLengthOf(value="x", offset="b").Methods inherited from class org.checkerframework.checker.index.IndexAbstractTransfer
visitGreaterThan, visitGreaterThanOrEqual, visitLessThan, visitLessThanOrEqual
Methods inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
addInformationFromPreconditions, createTransferResult, finishValue, finishValue, getNarrowedValue, getValueFromFactory, getWidenedValue, initialStore, insertIntoStores, isNotFullyInitializedReceiver, moreSpecificValue, processCommonAssignment, processConditionalPostconditions, processPostconditions, recreateTransferResult, setFixedInitialStore, splitAssignments, usesSequentialSemantics, visitArrayAccess, visitClassName, visitConditionalNot, visitEqualTo, visitExpressionStatement, visitInstanceOf, visitLambdaResultExpression, visitLocalVariable, visitNarrowingConversion, visitNode, visitNotEqual, visitObjectCreation, visitReturn, visitStringConversion, visitSwitchExpressionNode, visitTernaryExpression, visitThis, visitVariableDeclaration, visitWideningConversion
Methods inherited from class org.checkerframework.dataflow.cfg.node.AbstractNodeVisitor
visitArrayCreation, visitArrayType, visitAssertionError, visitBitwiseAnd, visitBitwiseComplement, visitBitwiseOr, visitBitwiseXor, visitBooleanLiteral, visitCharacterLiteral, visitClassDeclaration, visitConditionalAnd, visitConditionalOr, visitDoubleLiteral, visitExplicitThis, visitFloatingDivision, visitFloatingRemainder, visitFloatLiteral, visitImplicitThis, visitIntegerDivision, visitIntegerRemainder, visitLeftShift, visitLongLiteral, visitMarker, visitMemberReference, visitMethodAccess, visitNullChk, visitNullLiteral, visitNumericalMinus, visitNumericalMultiplication, visitNumericalPlus, visitPackageName, visitParameterizedType, visitPrimitiveType, visitShortLiteral, visitSignedRightShift, visitStringConcatenate, visitStringLiteral, visitSuper, visitSynchronized, visitThrow, visitTypeCast, visitUnsignedRightShift, visitValueLiteral
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.checkerframework.dataflow.cfg.node.NodeVisitor
visitArrayCreation, visitArrayType, visitAssertionError, visitBitwiseAnd, visitBitwiseComplement, visitBitwiseOr, visitBitwiseXor, visitBooleanLiteral, visitCharacterLiteral, visitClassDeclaration, visitConditionalAnd, visitConditionalOr, visitDoubleLiteral, visitExplicitThis, visitFloatingDivision, visitFloatingRemainder, visitFloatLiteral, visitImplicitThis, visitIntegerDivision, visitIntegerRemainder, visitLeftShift, visitLongLiteral, visitMarker, visitMemberReference, visitMethodAccess, visitNullChk, visitNullLiteral, visitNumericalMinus, visitNumericalMultiplication, visitNumericalPlus, visitPackageName, visitParameterizedType, visitPrimitiveType, visitShortLiteral, visitSignedRightShift, visitStringConcatenate, visitStringLiteral, visitSuper, visitSynchronized, visitThrow, visitTypeCast, visitUnsignedRightShift
-
Constructor Details
-
UpperBoundTransfer
Creates a new UpperBoundTransfer.- Parameters:
analysis
- the analysis for this transfer function
-
-
Method Details
-
visitAssignment
public TransferResult<CFValue,CFStore> visitAssignment(AssignmentNode node, TransferInput<CFValue, CFStore> in) 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").- Specified by:
visitAssignment
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitAssignment
in classCFAbstractTransfer<CFValue,
CFStore, CFTransfer>
-
refineGT
protected void refineGT(Node larger, AnnotationMirror largerAnno, Node smaller, AnnotationMirror smallerAnno, CFStore store, TransferInput<CFValue, CFStore> in) Case 8: if x < y, and y has a type that is related to the length of an array, then x has the same type, with an offset that is one less.- Specified by:
refineGT
in classIndexAbstractTransfer
-
refineGTE
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) 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.- Specified by:
refineGTE
in classIndexAbstractTransfer
-
strengthenAnnotationOfEqualTo
protected TransferResult<CFValue,CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> res, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) Implements case 11.- Overrides:
strengthenAnnotationOfEqualTo
in classCFAbstractTransfer<CFValue,
CFStore, CFTransfer> - Parameters:
res
- the previous resultfirstNode
- the node that might be more precisesecondNode
- the node whose type to possibly refinefirstValue
- the abstract value that might be more precisesecondValue
- the abstract value that might be less precisenotEqualTo
- if true, indicates that the logic is flipped (i.e., the information is added to theelseStore
instead of thethenStore
) for a not-equal comparison.- Returns:
- the conditional transfer result (if information has been added), or
res
-
visitNumericalAddition
public TransferResult<CFValue,CFStore> visitNumericalAddition(NumericalAdditionNode n, TransferInput<CFValue, CFStore> in) If some Node a is known to be less than the length of some array, x, then, the type of a + b, is @LTLengthOf(value="x", offset="-b"). If b is known to be less than the length of some other array, y, then the type of a + b is @LTLengthOf(value={"x", "y"}, offset={"-b", "-a"}).Alternatively, if a is known to be less than the length of x when some offset, o, is added to a (the type of a is @LTLengthOf(value="x", offset="o")), then the type of a + b is @LTLengthOf(value="x",offset="o - b"). (Note, if "o - b" can be computed, then it is and the result is used in the annotation.)
In addition, If expression i has type @LTLengthOf(value = "f2", offset = "f1.length") int and expression j is less than or equal to the length of f1, then the type of i + j is .@LTLengthOf("f2").
These three cases correspond to cases 13-15.
- Specified by:
visitNumericalAddition
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitNumericalAddition
in classAbstractNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>>
-
visitNumericalSubtraction
public TransferResult<CFValue,CFStore> visitNumericalSubtraction(NumericalSubtractionNode n, TransferInput<CFValue, CFStore> in) If some Node a is known to be less than the length of some sequence x, then the type of a - b is @LTLengthOf(value="x", offset="b"). If b is known to be less than the length of some other sequence, this doesn't add any information about the type of a - b. But, if b is non-negative or positive, then a - b should keep the types of a. This corresponds to cases 16 and 17.- Specified by:
visitNumericalSubtraction
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitNumericalSubtraction
in classAbstractNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>>
-
visitFieldAccess
public TransferResult<CFValue,CFStore> visitFieldAccess(FieldAccessNode n, TransferInput<CFValue, CFStore> in) If n is an array length field access, then the type of a.length is the glb of @LTEqLengthOf("a") and the value of a.length in the store. This is case 19.- Specified by:
visitFieldAccess
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitFieldAccess
in classCFAbstractTransfer<CFValue,
CFStore, CFTransfer>
-
visitMethodInvocation
public TransferResult<CFValue,CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) 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.- Specified by:
visitMethodInvocation
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitMethodInvocation
in classCFAbstractTransfer<CFValue,
CFStore, CFTransfer>
-
visitCase
Description copied from class:CFAbstractTransfer
A case produces no value, but it may imply some facts about switch selector expression.- Specified by:
visitCase
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitCase
in classCFAbstractTransfer<CFValue,
CFStore, CFTransfer>
-
visitIntegerLiteral
public TransferResult<CFValue,CFStore> visitIntegerLiteral(IntegerLiteralNode n, TransferInput<CFValue, CFStore> pi) - Specified by:
visitIntegerLiteral
in interfaceNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>> - Overrides:
visitIntegerLiteral
in classAbstractNodeVisitor<TransferResult<CFValue,
CFStore>, TransferInput<CFValue, CFStore>>
-