Skip to content

Commit 5bc6123

Browse files
committed
Add '0xe+1' case to lexing
1 parent b21e95a commit 5bc6123

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

lldb/source/ValueObject/DILLexer.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,18 @@ static std::optional<llvm::StringRef> IsNumber(llvm::StringRef &remainder,
8888
return std::nullopt;
8989
if (IsDigit(body.front()) || (body[0] == '.' && IsDigit(body[1]))) {
9090
isFloat = dots == 1;
91-
char last = body.back();
9291
tail = tail.drop_front(body.size());
93-
if (last == 'e' || last == 'E' || last == 'p' || last == 'P') {
94-
if (tail.consume_front("+") || tail.consume_front("-")) {
95-
tail = tail.drop_while(IsNumberBodyChar);
96-
isFloat = true;
97-
}
92+
bool isHex = body.contains_insensitive('x');
93+
bool hasExp = !isHex && body.contains_insensitive('e');
94+
bool hasHexExp = isHex && body.contains_insensitive('p');
95+
if (hasExp || hasHexExp) {
96+
isFloat = true; // This marks numbers like 0x1p1 and 1e1 as float
97+
if (body.ends_with_insensitive("e") || body.ends_with_insensitive("p"))
98+
if (tail.consume_front("+") || tail.consume_front("-"))
99+
tail = tail.drop_while(IsNumberBodyChar);
98100
}
99101
size_t number_length = remainder.size() - tail.size();
100102
llvm::StringRef number = remainder.take_front(number_length);
101-
if (!isFloat) {
102-
isFloat = number.contains('p') || // 0x1p1 = 2.0
103-
(!number.contains('x') && number.contains('e')); // 1e1 = 10.0
104-
}
105103
remainder = remainder.drop_front(number_length);
106104
return number;
107105
}

lldb/unittests/ValueObject/DILLexerTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ TEST(DILLexerTests, NumbersTest) {
160160
std::vector<std::string> valid_integers = {"123", "0x123", "0123", "0b101"};
161161
std::vector<std::string> valid_floats = {
162162
"1.2", ".2", "2.f", "0x1.2", "0x.2", ".2e1f",
163-
"2.e+1f", "0x1.f", "0x1.2p1", "0x1.p-1f", "0x1.2p+3f", "1e1",
164-
"1e+1", "0x1p1", "0x1p+1", "0xf.fp1f"};
163+
"2.e+1f", "0x1.f", "0x1.2P1", "0x1.p-1f", "0x1.2P+3f", "1E1",
164+
"1E+1", "0x1p1", "0x1p+1", "0xf.fp1f"};
165165

166166
// The lexer can lex these strings, but they should not be numbers.
167167
std::vector<std::string> invalid_numbers = {"", "x123", "b123", "a.b"};
@@ -192,7 +192,7 @@ TEST(DILLexerTests, NumbersTest) {
192192
// Verify that '-' and '+' are not lexed if they're not part of a number
193193
std::vector<std::string> expressions = {"1+e", "0x1+p", "1.1+e",
194194
"1.1e1+e", "0x1.1p-1-p", "1e-1+e",
195-
"1e1+e", "0x1p-1-p"};
195+
"1e1+e", "0x1p-1-p", "0xe+e"};
196196
for (auto &str : expressions) {
197197
SCOPED_TRACE(str);
198198
llvm::Expected<DILLexer> maybe_lexer = DILLexer::Create(str);

0 commit comments

Comments
 (0)