use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class ValueTransfer method calculateRangeUnaryOp.
/**
* Calculate the result range after a unary operation of a numerical type node.
*
* @param operand the node that represents the operand
* @param op the operator type
* @param p the transfer input
* @return the result annotation mirror
*/
private Range calculateRangeUnaryOp(Node operand, NumericalUnaryOps op, TransferInput<CFValue, CFStore> p) {
if (TypesUtils.isIntegralPrimitive(operand.getType())) {
Range range = getIntRange(operand, p);
Range resultRange;
switch(op) {
case PLUS:
resultRange = range.unaryPlus();
break;
case MINUS:
resultRange = range.unaryMinus();
break;
case BITWISE_COMPLEMENT:
resultRange = range.bitwiseComplement();
break;
default:
throw new TypeSystemError("ValueTransfer: unsupported operation: " + op);
}
// operations.
return operand.getType().getKind() == TypeKind.LONG ? resultRange : resultRange.intRange();
} else {
return Range.EVERYTHING;
}
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class ValueTransfer method calculateBinaryComparison.
private List<Boolean> calculateBinaryComparison(Node leftNode, CFValue leftValue, Node rightNode, CFValue rightValue, ComparisonOperators op, CFStore thenStore, CFStore elseStore) {
AnnotationMirror leftAnno = getValueAnnotation(leftValue);
AnnotationMirror rightAnno = getValueAnnotation(rightValue);
if (atypeFactory.isIntRange(leftAnno) || atypeFactory.isIntRange(rightAnno) || isIntegralUnknownVal(rightNode, rightAnno) || isIntegralUnknownVal(leftNode, leftAnno)) {
// of values to a range. (This could be implemented in the future.)
return refineIntRanges(leftNode, leftAnno, rightNode, rightAnno, op, thenStore, elseStore);
}
List<? extends Number> lefts = getNumericalValues(leftNode, leftAnno);
List<? extends Number> rights = getNumericalValues(rightNode, rightAnno);
if (lefts == null || rights == null) {
// Appropriately handle bottom when something is compared to bottom.
if (AnnotationUtils.areSame(leftAnno, atypeFactory.BOTTOMVAL) || AnnotationUtils.areSame(rightAnno, atypeFactory.BOTTOMVAL)) {
return Collections.emptyList();
}
return null;
}
// This is a list of all the values that the expression can evaluate to.
List<Boolean> resultValues = new ArrayList<>();
// These lists are used to refine the values in the store based on the results of the
// comparison.
List<Number> thenLeftVals = new ArrayList<>();
List<Number> elseLeftVals = new ArrayList<>();
List<Number> thenRightVals = new ArrayList<>();
List<Number> elseRightVals = new ArrayList<>();
for (Number left : lefts) {
NumberMath<?> nmLeft = NumberMath.getNumberMath(left);
for (Number right : rights) {
Boolean result;
switch(op) {
case EQUAL:
result = nmLeft.equalTo(right);
break;
case GREATER_THAN:
result = nmLeft.greaterThan(right);
break;
case GREATER_THAN_EQ:
result = nmLeft.greaterThanEq(right);
break;
case LESS_THAN:
result = nmLeft.lessThan(right);
break;
case LESS_THAN_EQ:
result = nmLeft.lessThanEq(right);
break;
case NOT_EQUAL:
result = nmLeft.notEqualTo(right);
break;
default:
throw new TypeSystemError("ValueTransfer: unsupported operation: " + op);
}
resultValues.add(result);
if (result) {
thenLeftVals.add(left);
thenRightVals.add(right);
} else {
elseLeftVals.add(left);
elseRightVals.add(right);
}
}
}
createAnnotationFromResultsAndAddToStore(thenStore, thenLeftVals, leftNode);
createAnnotationFromResultsAndAddToStore(elseStore, elseLeftVals, leftNode);
createAnnotationFromResultsAndAddToStore(thenStore, thenRightVals, rightNode);
createAnnotationFromResultsAndAddToStore(elseStore, elseRightVals, rightNode);
return resultValues;
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class ValueTransfer method calculateRangeBinaryOp.
/**
* Calculate the result range after a binary operation between two numerical type nodes.
*/
private Range calculateRangeBinaryOp(Node leftNode, Node rightNode, NumericalBinaryOps op, TransferInput<CFValue, CFStore> p) {
if (TypesUtils.isIntegralPrimitive(leftNode.getType()) && TypesUtils.isIntegralPrimitive(rightNode.getType())) {
Range leftRange = getIntRange(leftNode, p);
Range rightRange = getIntRange(rightNode, p);
Range resultRange;
switch(op) {
case ADDITION:
resultRange = leftRange.plus(rightRange);
break;
case SUBTRACTION:
resultRange = leftRange.minus(rightRange);
break;
case MULTIPLICATION:
resultRange = leftRange.times(rightRange);
break;
case DIVISION:
resultRange = leftRange.divide(rightRange);
break;
case REMAINDER:
resultRange = leftRange.remainder(rightRange);
break;
case SHIFT_LEFT:
resultRange = leftRange.shiftLeft(rightRange);
break;
case SIGNED_SHIFT_RIGHT:
resultRange = leftRange.signedShiftRight(rightRange);
break;
case UNSIGNED_SHIFT_RIGHT:
resultRange = leftRange.unsignedShiftRight(rightRange);
break;
case BITWISE_AND:
resultRange = leftRange.bitwiseAnd(rightRange);
break;
case BITWISE_OR:
resultRange = leftRange.bitwiseOr(rightRange);
break;
case BITWISE_XOR:
resultRange = leftRange.bitwiseXor(rightRange);
break;
default:
throw new TypeSystemError("ValueTransfer: unsupported operation: " + op);
}
// operations.
return leftNode.getType().getKind() == TypeKind.LONG || rightNode.getType().getKind() == TypeKind.LONG ? resultRange : resultRange.intRange();
} else {
return Range.EVERYTHING;
}
}
Aggregations