diff options
| author | Jacques Pienaar <jpienaar@google.com> | 2018-07-31 17:15:15 -0700 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 12:51:12 -0700 |
| commit | 1015a0dded4d9dd2832ed962c1043f5bfbae4186 (patch) | |
| tree | 829d1c7e16422fef83c9f8f8171fd40d37427ed9 /mlir/lib/Parser/Token.cpp | |
| parent | ace4df1200bc38bafecf6dcf1d5c076a586fa193 (diff) | |
| download | bcm5719-llvm-1015a0dded4d9dd2832ed962c1043f5bfbae4186.tar.gz bcm5719-llvm-1015a0dded4d9dd2832ed962c1043f5bfbae4186.zip | |
Add parsing for floating point attributes.
This is doing it in a suboptimal manner by recombining [integer period literal] into a string literal and parsing that via to_float.
PiperOrigin-RevId: 206855106
Diffstat (limited to 'mlir/lib/Parser/Token.cpp')
| -rw-r--r-- | mlir/lib/Parser/Token.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/mlir/lib/Parser/Token.cpp b/mlir/lib/Parser/Token.cpp index 2d78168d83d..9fc2b2f40d1 100644 --- a/mlir/lib/Parser/Token.cpp +++ b/mlir/lib/Parser/Token.cpp @@ -58,6 +58,14 @@ Optional<uint64_t> Token::getUInt64IntegerValue() const { return result; } +/// For a floatliteral, return its value as a double. Return None if the value +/// underflows or overflows. +Optional<double> Token::getFloatingPointValue() const { + double result = 0; + if (spelling.getAsDouble(result)) + return None; + return result; +} /// For an inttype token, return its bitwidth. Optional<unsigned> Token::getIntTypeBitwidth() const { @@ -70,7 +78,6 @@ Optional<unsigned> Token::getIntTypeBitwidth() const { return result; } - /// Given a 'string' token, return its value, including removing the quote /// characters and unescaping the contents of the string. std::string Token::getStringValue() const { |

