diff options
| author | Darren Wihandi <65404740+fairywreath@users.noreply.github.com> | 2024-12-03 16:40:09 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 13:40:09 -0800 |
| commit | 98cab6fa86c9e594fb69571cf1d864294b0aae45 (patch) | |
| tree | 37528d00b3d280c6ea68f26657aafa539c7b5636 /source/compiler-core | |
| parent | 600cce28606ba36b31756bf0422d892d0e242b63 (diff) | |
Conform non-suffixed integer literals (#5717)
* Make non-suffixed integer literal type resolution conform to C
* Update integer literal tests
* Clean up integer literal implementation a bit
* Update docs on integer literals
* Clean up docs update
* Clean up docs update
* Add comment on INT64_MIN edge case
* Fixed failing test, fixed formatting and cleaned up code
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/compiler-core')
| -rw-r--r-- | source/compiler-core/slang-lexer.cpp | 10 | ||||
| -rw-r--r-- | source/compiler-core/slang-lexer.h | 5 |
2 files changed, 13 insertions, 2 deletions
diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp index bf109e7fb..84a4df93b 100644 --- a/source/compiler-core/slang-lexer.cpp +++ b/source/compiler-core/slang-lexer.cpp @@ -673,7 +673,10 @@ static int _readOptionalBase(char const** ioCursor) } -IntegerLiteralValue getIntegerLiteralValue(Token const& token, UnownedStringSlice* outSuffix) +IntegerLiteralValue getIntegerLiteralValue( + Token const& token, + UnownedStringSlice* outSuffix, + bool* outIsDecimalBase) { IntegerLiteralValue value = 0; @@ -698,6 +701,11 @@ IntegerLiteralValue getIntegerLiteralValue(Token const& token, UnownedStringSlic *outSuffix = UnownedStringSlice(cursor, end); } + if (outIsDecimalBase) + { + *outIsDecimalBase = (base == 10); + } + return value; } diff --git a/source/compiler-core/slang-lexer.h b/source/compiler-core/slang-lexer.h index a9883ced6..a36719ab7 100644 --- a/source/compiler-core/slang-lexer.h +++ b/source/compiler-core/slang-lexer.h @@ -172,7 +172,10 @@ String getFileNameTokenValue(Token const& token); typedef int64_t IntegerLiteralValue; typedef double FloatingPointLiteralValue; -IntegerLiteralValue getIntegerLiteralValue(Token const& token, UnownedStringSlice* outSuffix = 0); +IntegerLiteralValue getIntegerLiteralValue( + Token const& token, + UnownedStringSlice* outSuffix = 0, + bool* outIsDecimalBase = 0); FloatingPointLiteralValue getFloatingPointLiteralValue( Token const& token, UnownedStringSlice* outSuffix = 0); |
