use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method propagateToSubtractionOperands.
/**
* The subtraction node, {@code node}, is known to be {@code typeOfSubtraction}.
*
* <p>This means that the left node is less than or equal to the length of the array when the
* right node is subtracted from the left node. Note that unlike {@link
* #propagateToAdditionOperand(LessThanLengthOf, Node, Node, TransferInput, CFStore)} and {@link
* #propagateToMultiplicationOperand(LessThanLengthOf, Node, Node, TransferInput, CFStore)}, this
* method takes the NumericalSubtractionNode instead of the two operand nodes. This implements
* case 4.
*
* @param typeOfSubtraction type of node
* @param node subtraction node that has typeOfSubtraction
* @param in a TransferInput
* @param store location to store the refined type
*/
private void propagateToSubtractionOperands(LessThanLengthOf typeOfSubtraction, NumericalSubtractionNode node, TransferInput<CFValue, CFStore> in, CFStore store) {
UBQualifier left = getUBQualifier(node.getLeftOperand(), in);
UBQualifier newInfo = typeOfSubtraction.minusOffset(node.getRightOperand(), atypeFactory);
UBQualifier newLeft = left.glb(newInfo);
JavaExpression leftJe = JavaExpression.fromNode(node.getLeftOperand());
store.insertValue(leftJe, atypeFactory.convertUBQualifierToAnnotation(newLeft));
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method refineSubtrahendWithOffset.
/**
* Refines 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. This is
* case 10.
*
* <p>This is based on the fact that if {@code (minuend - subtrahend) >= offset}, and {@code
* minuend + o < l}, then {@code subtrahend + o + offset < l}.
*
* <p>If {@code gtNode} is not a {@link NumericalSubtractionNode}, the method does nothing.
*
* @param gtNode the node that is greater or equal to the offset
* @param offsetNode a node part of the offset
* @param offsetAddOne whether to add one to the offset
* @param in input of the transfer function
* @param store location to store the refined types
*/
private void refineSubtrahendWithOffset(Node gtNode, Node offsetNode, boolean offsetAddOne, TransferInput<CFValue, CFStore> in, CFStore store) {
if (gtNode instanceof NumericalSubtractionNode) {
NumericalSubtractionNode subtractionNode = (NumericalSubtractionNode) gtNode;
Node minuend = subtractionNode.getLeftOperand();
UBQualifier minuendQual = getUBQualifier(minuend, in);
Node subtrahend = subtractionNode.getRightOperand();
UBQualifier subtrahendQual = getUBQualifier(subtrahend, in);
UBQualifier newQual = subtrahendQual.glb(minuendQual.plusOffset(offsetNode, atypeFactory).plusOffset(offsetAddOne ? 1 : 0));
JavaExpression subtrahendJe = JavaExpression.fromNode(subtrahend);
store.insertValue(subtrahendJe, atypeFactory.convertUBQualifierToAnnotation(newQual));
}
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundTransfer method getUBQualifier.
/**
* Returns the UBQualifier for node. It does this by finding a {@link CFValue} for node. First it
* checks the store in the transfer input. If one isn't there, the analysis is checked. If the
* UNKNOWN qualifier is returned, then the AnnotatedTypeMirror from the type factory is used.
*
* @param n node
* @param in transfer input
* @return the UBQualifier for node
*/
private UBQualifier getUBQualifier(Node n, TransferInput<CFValue, CFStore> in) {
QualifierHierarchy hierarchy = analysis.getTypeFactory().getQualifierHierarchy();
JavaExpression je = JavaExpression.fromNode(n);
CFValue value = null;
if (CFAbstractStore.canInsertJavaExpression(je)) {
value = in.getRegularStore().getValue(je);
}
if (value == null) {
value = analysis.getValue(n);
}
UBQualifier qualifier = getUBQualifier(hierarchy, value);
if (qualifier.isUnknown()) {
// The qualifier from the store or analysis might be UNKNOWN if there was some error.
// For example,
// @LTLength("a") int i = 4; // error
// The type of i in the store is @UpperBoundUnknown, but the type of i as computed by
// the type factory is @LTLength("a"), so use that type.
CFValue valueFromFactory = getValueFromFactory(n.getTree(), n);
return getUBQualifier(hierarchy, valueFromFactory);
}
return qualifier;
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class LowerBoundTransfer method refineGTE.
/**
* Refines left to exactly the level of right, since in the worst case they're equal. Modifies an
* existing type in the store, but has to be careful not to overwrite a more precise existing
* type.
*
* <p>This implements parts of cases 1, 2, 3, and 4 using the decomposition strategy described in
* this class's Javadoc.
*/
@Override
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
if (rightAnno == null || leftAnno == null) {
return;
}
JavaExpression leftJe = JavaExpression.fromNode(left);
AnnotationMirror newLBType = aTypeFactory.getQualifierHierarchy().greatestLowerBound(rightAnno, leftAnno);
store.insertValue(leftJe, newLBType);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class UpperBoundVisitor method processSubsequenceForLHS.
/* Returns the new value of the left hand side after processing the arrays named in the lhs.
* Iff varLtlQual includes LTL(lhsSeq),
* lhsSeq has HSS, and expQual includes LTL(a, -from), then the LTL(lhsSeq) will be removed from varLtlQual
*/
private UBQualifier processSubsequenceForLHS(LessThanLengthOf varLtlQual, UBQualifier expQual) {
UBQualifier newLHS = varLtlQual;
for (String lhsSeq : varLtlQual.getSequences()) {
// check is lhsSeq is an actual LTL
if (varLtlQual.hasSequenceWithOffset(lhsSeq, 0)) {
JavaExpression lhsSeqExpr = parseJavaExpressionString(lhsSeq, atypeFactory, getCurrentPath());
Subsequence subSeq = Subsequence.getSubsequenceFromReceiver(lhsSeqExpr, atypeFactory);
if (subSeq != null) {
String from = subSeq.from;
String a = subSeq.array;
if (expQual.hasSequenceWithOffset(a, Subsequence.negateString(from))) {
// This cast is safe because LTLs cannot contain duplicates.
// Note that this updates newLHS on each iteration from its old value,
// so even if there are multiple HSS arrays the result will be correct.
newLHS = ((LessThanLengthOf) newLHS).removeOffset(lhsSeq, 0);
}
}
}
}
return newLHS;
}
Aggregations