use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class ValueTransfer method visitLessThan.
@Override
public TransferResult<CFValue, CFStore> visitLessThan(LessThanNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitLessThan(n, p);
CFStore thenStore = transferResult.getThenStore();
CFStore elseStore = transferResult.getElseStore();
List<Boolean> resultValues = calculateBinaryComparison(n.getLeftOperand(), p.getValueOfSubNode(n.getLeftOperand()), n.getRightOperand(), p.getValueOfSubNode(n.getRightOperand()), ComparisonOperators.LESS_THAN, thenStore, elseStore);
TypeMirror underlyingType = transferResult.getResultValue().getUnderlyingType();
return createNewResultBoolean(thenStore, elseStore, resultValues, underlyingType);
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class ValueTransfer method visitBitwiseXor.
@Override
public TransferResult<CFValue, CFStore> visitBitwiseXor(BitwiseXorNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitBitwiseXor(n, p);
AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.BITWISE_XOR, p);
return createNewResult(transferResult, resultAnno);
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class SameLenTransfer method visitAssignment.
/**
* Handles case 1
*/
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode node, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitAssignment(node, in);
// Handle b = new T[a.length]
if (node.getExpression() instanceof ArrayCreationNode) {
ArrayCreationNode acNode = (ArrayCreationNode) node.getExpression();
if (acNode.getDimensions().size() == 1) {
Node lengthNode = acNode.getDimension(0);
Node lengthNodeReceiver = getLengthNodeReceiver(lengthNode);
if (lengthNodeReceiver != null) {
// "new T[a.length]" or "new T[s.length()]" is the right hand side of the
// assignment. lengthNode is known to be "lengthNodeReceiver.length" or
// "lengthNodeReceiver.length()"
// targetRec is the receiver for the left hand side of the assignment.
Receiver targetRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
Receiver otherRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), lengthNodeReceiver);
AnnotationMirror lengthNodeAnnotation = aTypeFactory.getAnnotatedType(lengthNodeReceiver.getTree()).getAnnotationInHierarchy(UNKNOWN);
AnnotationMirror combinedSameLen = aTypeFactory.createCombinedSameLen(targetRec, otherRec, UNKNOWN, lengthNodeAnnotation);
propagateCombinedSameLen(combinedSameLen, node, result.getRegularStore());
return result;
}
}
}
AnnotationMirror rightAnno = aTypeFactory.getAnnotatedType(node.getExpression().getTree()).getAnnotationInHierarchy(UNKNOWN);
// If the left side of the assignment is an array or a string, then have both the right and
// left side be SameLen of each other.
Receiver targetRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getTarget());
Receiver exprRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node.getExpression());
if (IndexUtil.isSequenceType(node.getTarget().getType()) || (rightAnno != null && AnnotationUtils.areSameByClass(rightAnno, SameLen.class))) {
AnnotationMirror rightAnnoOrUnknown = rightAnno == null ? UNKNOWN : rightAnno;
AnnotationMirror combinedSameLen = aTypeFactory.createCombinedSameLen(targetRec, exprRec, UNKNOWN, rightAnnoOrUnknown);
propagateCombinedSameLen(combinedSameLen, node, result.getRegularStore());
}
return result;
}
use of org.checkerframework.framework.flow.CFValue 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();
Receiver rec = FlowExpressions.internalReprOf(atypeFactory, n);
CFValue value = null;
if (CFAbstractStore.canInsertReceiver(rec)) {
value = in.getRegularStore().getValue(rec);
}
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.framework.flow.CFValue in project checker-framework by typetools.
the class UpperBoundTransfer method visitCase.
@Override
public TransferResult<CFValue, CFStore> visitCase(CaseNode n, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitCase(n, in);
// Refines subtrahend in the switch expression
// TODO: this cannot be done in strengthenAnnotationOfEqualTo, because that does not provide transfer input
Node caseNode = n.getCaseOperand();
AssignmentNode assign = (AssignmentNode) n.getSwitchOperand();
Node switchNode = assign.getExpression();
refineSubtrahendWithOffset(switchNode, caseNode, false, in, result.getThenStore());
return result;
}
Aggregations