Skip to content

Conversation

Marcono1234
Copy link
Contributor

Adds the predicates:

  • FloatingPointLiteral.getFloatValue()
  • DoubleLiteral.getDoubleValue()

Improves existing literal tests.

@Marcono1234 Marcono1234 requested a review from a team as a code owner March 21, 2021 17:08
@github-actions github-actions bot added the Java label Mar 21, 2021
@@ -653,11 +653,23 @@ class LongLiteral extends Literal, @longliteral {

/** A floating point literal. For example, `4.2f`. */
class FloatingPointLiteral 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`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this clarify how a value which is not a precise Java float, e.g. 1.55555555555f, will be parsed.
That is, it will have the value 1.5555556 and not 1.55555555555 (which could be represented using CodeQL's float).

override string getAPrimaryQlClass() { result = "FloatingPointLiteral" }
}

/** A double literal. For example, `4.2`. */
class DoubleLiteral extends Literal, @doubleliteral {
/**
* Gets the value of this literal as CodeQL 64-bit `float`. The result will
* have the same effective value as the Java `double` literal.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to clarify how values which are not precise Java doubles respectively CodeQL floats will be parsed.
That is, for example 1.55555555555555555555d which is effectively 1.5555555555555556d will also have that as result of this predicate.

};

String[] strings = {
"hello" + "world", // two separate literals
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently erroneously detected as one StringLiteral, see #5469.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Mar 22, 2021
@aschackmull aschackmull merged commit 36962b8 into github:main Mar 22, 2021
@Marcono1234 Marcono1234 deleted the marcono1234/floating-point-literal-value branch March 22, 2021 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants