diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-24 01:59:31 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-24 01:59:31 +0000 |
commit | 54f0a625b0eb9afeece652a8462755010d237c78 (patch) | |
tree | cf57c4e7444e1aad1388654f5a48d5d6ac630e72 /lib/MC/MCParser/AsmLexer.cpp | |
parent | 75413b146443f4ee2d495969127dc1fc1ddb87c1 (diff) | |
download | llvm-54f0a625b0eb9afeece652a8462755010d237c78.tar.gz llvm-54f0a625b0eb9afeece652a8462755010d237c78.tar.bz2 llvm-54f0a625b0eb9afeece652a8462755010d237c78.tar.xz |
MC/Lexer: Add 'Real' token type for floating point literals.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114718 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCParser/AsmLexer.cpp')
-rw-r--r-- | lib/MC/MCParser/AsmLexer.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp index 086df081a9..59da3817c1 100644 --- a/lib/MC/MCParser/AsmLexer.cpp +++ b/lib/MC/MCParser/AsmLexer.cpp @@ -65,9 +65,21 @@ int AsmLexer::getNextChar() { } /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* +static bool IsIdentifierChar(char c) { + return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@'; +} AsmToken AsmLexer::LexIdentifier() { - while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || - *CurPtr == '.' || *CurPtr == '@') + // Check for floating point literals. + if (CurPtr[-1] == '.' && isdigit(*CurPtr)) { + while (isdigit(*CurPtr)) + ++CurPtr; + if (!IsIdentifierChar(*CurPtr)) { + return AsmToken(AsmToken::Real, + StringRef(TokStart, CurPtr - TokStart)); + } + } + + while (IsIdentifierChar(*CurPtr)) ++CurPtr; // Handle . as a special case. @@ -124,7 +136,6 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { CurPtr += 3; } - /// LexDigit: First character is [0-9]. /// Local Label: [0-9][:] /// Forward/Backward Label: [0-9][fb] @@ -132,13 +143,21 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { /// Octal integer: 0[0-7]+ /// Hex integer: 0x[0-9a-fA-F]+ /// Decimal integer: [1-9][0-9]* -/// TODO: FP literal. AsmToken AsmLexer::LexDigit() { // Decimal integer: [1-9][0-9]* if (CurPtr[-1] != '0') { while (isdigit(*CurPtr)) ++CurPtr; - + + // Check for floating point literals. + if (*CurPtr == '.') { + ++CurPtr; + while (isdigit(*CurPtr)) + ++CurPtr; + + return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart)); + } + StringRef Result(TokStart, CurPtr - TokStart); long long Value; |