Java: Autoformat Overflow.qll and add comment about imprecise float.

This commit is contained in:
Anders Schack-Mulligen
2018-10-11 17:04:23 +02:00
parent 0f5a3d3bb7
commit 11279d4c83

View File

@@ -2,14 +2,9 @@ import java
/** A subclass of `PrimitiveType` with width-based ordering methods. */
class OrdPrimitiveType extends PrimitiveType {
predicate widerThan(OrdPrimitiveType that) { getWidthRank() > that.getWidthRank() }
predicate widerThan(OrdPrimitiveType that) {
getWidthRank() > that.getWidthRank()
}
predicate widerThanOrEqualTo(OrdPrimitiveType that) {
getWidthRank() >= that.getWidthRank()
}
predicate widerThanOrEqualTo(OrdPrimitiveType that) { getWidthRank() >= that.getWidthRank() }
OrdPrimitiveType maxType(OrdPrimitiveType that) {
(this.widerThan(that) and result = this)
@@ -38,7 +33,8 @@ class OrdPrimitiveType extends PrimitiveType {
or
(this.getName() = "int" and result = 2147483647.0)
or
(this.getName() = "long" and result = 9223372036854775807.0)
// Long.MAX_VALUE is 9223372036854775807 but floating point only has 53 bits of precision.
(this.getName() = "long" and result = 9223372036854776000.0)
// don't try for floats and doubles
}
@@ -49,7 +45,8 @@ class OrdPrimitiveType extends PrimitiveType {
or
(this.getName() = "int" and result = -2147483648.0)
or
(this.getName() = "long" and result = -9223372036854775808.0)
// Long.MIN_VALUE is -9223372036854775808 but floating point only has 53 bits of precision.
(this.getName() = "long" and result = -9223372036854776000.0)
// don't try for floats and doubles
}
}
@@ -75,17 +72,17 @@ class NumType extends Type {
this.getOrdPrimitiveType().widerThanOrEqualTo(that.getOrdPrimitiveType())
}
int getWidthRank() {
result = this.getOrdPrimitiveType().getWidthRank()
}
int getWidthRank() { result = this.getOrdPrimitiveType().getWidthRank() }
}
class ArithExpr extends Expr {
ArithExpr() {
(
this instanceof UnaryAssignExpr or
this instanceof AddExpr or this instanceof MulExpr or
this instanceof SubExpr or this instanceof DivExpr
this instanceof AddExpr or
this instanceof MulExpr or
this instanceof SubExpr or
this instanceof DivExpr
) and
forall(Expr e | e = this.(BinaryExpr).getAnOperand() or e = this.(UnaryAssignExpr).getExpr() |
e.getType() instanceof NumType
@@ -112,9 +109,7 @@ class ArithExpr extends Expr {
/**
* Gets the right-hand operand if this is a binary expression.
*/
Expr getRightOperand() {
result = this.(BinaryExpr).getRightOperand()
}
Expr getRightOperand() { result = this.(BinaryExpr).getRightOperand() }
/** Gets an operand of this arithmetic expression. */
Expr getAnOperand() {