use of org.checkerframework.framework.flow.CFStore 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.CFStore in project checker-framework by typetools.
the class ValueTransfer method strengthenAnnotationOfEqualTo.
@Override
protected TransferResult<CFValue, CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> transferResult, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) {
if (firstValue == null) {
return transferResult;
}
if (TypesUtils.isNumeric(firstNode.getType()) || TypesUtils.isNumeric(secondNode.getType())) {
CFStore thenStore = transferResult.getThenStore();
CFStore elseStore = transferResult.getElseStore();
// At least one must be a primitive otherwise reference equality is used.
List<Boolean> resultValues = calculateBinaryComparison(firstNode, firstValue, secondNode, secondValue, notEqualTo ? ComparisonOperators.NOT_EQUAL : ComparisonOperators.EQUAL, thenStore, elseStore);
if (transferResult.getResultValue() == null) {
// Happens for case labels
return transferResult;
}
TypeMirror underlyingType = transferResult.getResultValue().getUnderlyingType();
return createNewResultBoolean(thenStore, elseStore, resultValues, underlyingType);
}
return super.strengthenAnnotationOfEqualTo(transferResult, firstNode, secondNode, firstValue, secondValue, notEqualTo);
}
use of org.checkerframework.framework.flow.CFStore 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.CFStore 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.CFStore 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