mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Java: Rename FloatingPointLiteral to FloatLiteral
"Floating point" refers to both `double` and `float`, and is also used by the JLS in this way. Therefore the old CodeQL class name for `float` literals was misleading.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: deprecated
|
||||
---
|
||||
* The QL class `FloatingPointLiteral` has been renamed to `FloatLiteral`.
|
||||
@@ -716,20 +716,23 @@ class LongLiteral extends Literal, @longliteral {
|
||||
override string getAPrimaryQlClass() { result = "LongLiteral" }
|
||||
}
|
||||
|
||||
/** DEPRECATED: Alias for FloatLiteral */
|
||||
deprecated class FloatingPointLiteral = FloatLiteral;
|
||||
|
||||
/**
|
||||
* A float literal. For example, `4.2f`.
|
||||
*
|
||||
* A float literal is never negative; a preceding minus, if any, will always
|
||||
* be modeled as separate `MinusExpr`.
|
||||
*/
|
||||
class FloatingPointLiteral extends Literal, @floatingpointliteral {
|
||||
class FloatLiteral extends Literal, @floatingpointliteral {
|
||||
/**
|
||||
* Gets the value of this literal as CodeQL 64-bit `float`. The value will
|
||||
* be parsed as Java 32-bit `float` and then converted to a CodeQL `float`.
|
||||
*/
|
||||
float getFloatValue() { result = this.getValue().toFloat() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "FloatingPointLiteral" }
|
||||
override string getAPrimaryQlClass() { result = "FloatLiteral" }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ module Private {
|
||||
/** Class to represent float and double literals. */
|
||||
class RealLiteral extends J::Literal {
|
||||
RealLiteral() {
|
||||
this instanceof J::FloatingPointLiteral or
|
||||
this instanceof J::FloatLiteral or
|
||||
this instanceof J::DoubleLiteral
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ private module Impl {
|
||||
/** Gets the constant `float` value of non-`ConstantIntegerExpr` expressions. */
|
||||
float getNonIntegerValue(Expr e) {
|
||||
result = e.(LongLiteral).getValue().toFloat() or
|
||||
result = e.(FloatingPointLiteral).getValue().toFloat() or
|
||||
result = e.(FloatLiteral).getValue().toFloat() or
|
||||
result = e.(DoubleLiteral).getValue().toFloat()
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,6 @@
|
||||
import semmle.code.java.Type
|
||||
import semmle.code.java.Expr
|
||||
|
||||
// Either `float`, `double`, `Float`, or `Double`.
|
||||
class Floating extends Type {
|
||||
Floating() {
|
||||
exists(string s | s = this.getName().toLowerCase() |
|
||||
s = "float" or
|
||||
s = "double"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
predicate trivialLiteral(Literal e) {
|
||||
e.getValue() = "0.0" or
|
||||
e.getValue() = "0" or
|
||||
@@ -61,7 +51,7 @@ predicate similarVarComparison(EqualityTest e) {
|
||||
|
||||
from EqualityTest ee
|
||||
where
|
||||
ee.getAnOperand().getType() instanceof Floating and
|
||||
ee.getAnOperand().getType() instanceof FloatingPointType and
|
||||
not ee.getAnOperand() instanceof NullLiteral and
|
||||
not trivialLiteral(ee.getAnOperand()) and
|
||||
not definedConstant(ee.getAnOperand()) and
|
||||
|
||||
@@ -55,7 +55,7 @@ private predicate powerOfTen(float f) {
|
||||
}
|
||||
|
||||
private predicate floatTrivial(Literal lit) {
|
||||
(lit instanceof FloatingPointLiteral or lit instanceof DoubleLiteral) and
|
||||
(lit instanceof FloatLiteral or lit instanceof DoubleLiteral) and
|
||||
exists(float f |
|
||||
f = lit.getValue().toFloat() and
|
||||
(f.abs() <= 20.0 or powerOfTen(f))
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
| literals.kt:17:30:17:33 | 15 | LongLiteral |
|
||||
| literals.kt:18:30:18:39 | 11 | LongLiteral |
|
||||
| literals.kt:19:30:19:38 | 1234567 | LongLiteral |
|
||||
| literals.kt:20:32:20:35 | 0.0 | FloatingPointLiteral |
|
||||
| literals.kt:21:32:21:37 | 123.4 | FloatingPointLiteral |
|
||||
| literals.kt:22:32:22:38 | -123.4 | FloatingPointLiteral |
|
||||
| literals.kt:20:32:20:35 | 0.0 | FloatLiteral |
|
||||
| literals.kt:21:32:21:37 | 123.4 | FloatLiteral |
|
||||
| literals.kt:22:32:22:38 | -123.4 | FloatLiteral |
|
||||
| literals.kt:23:34:23:36 | 0.0 | DoubleLiteral |
|
||||
| literals.kt:24:34:24:38 | 123.4 | DoubleLiteral |
|
||||
| literals.kt:25:34:25:39 | -123.4 | DoubleLiteral |
|
||||
|
||||
@@ -3,7 +3,7 @@ fields/FieldTest.java:
|
||||
# 3| 1: [Class] FieldTest
|
||||
# 4| 4: [FieldDeclaration] float ff, ...;
|
||||
# 4| -1: [TypeAccess] float
|
||||
# 4| 1: [FloatingPointLiteral] 2.3f
|
||||
# 4| 1: [FloatLiteral] 2.3f
|
||||
# 5| 5: [FieldDeclaration] Object obj, ...;
|
||||
# 5| -1: [TypeAccess] Object
|
||||
# 5| 0: [NullLiteral] null
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import semmle.code.java.Expr
|
||||
|
||||
from FloatingPointLiteral lit
|
||||
from FloatLiteral lit
|
||||
select lit, lit.getValue(), lit.getFloatValue()
|
||||
|
||||
@@ -4,6 +4,6 @@ from Literal l
|
||||
where
|
||||
l instanceof IntegerLiteral or
|
||||
l instanceof LongLiteral or
|
||||
l instanceof FloatingPointLiteral or
|
||||
l instanceof FloatLiteral or
|
||||
l instanceof DoubleLiteral
|
||||
select l, l.getValue(), l.getParent()
|
||||
|
||||
Reference in New Issue
Block a user