AsmParser: Use StringRef for keyword comparisons, NFC

Leverage `StringRef` inside keyword comparison macros.  There's no
reason to be so low-level here, and I'm about to add another
`startswith()` use, so let's make it easy to read.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230100 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-21 00:18:40 +00:00
parent 7ef23e62b2
commit 8ab90d412e

View File

@ -486,11 +486,11 @@ lltok::Kind LLLexer::LexIdentifier() {
if (!KeywordEnd) KeywordEnd = CurPtr; if (!KeywordEnd) KeywordEnd = CurPtr;
CurPtr = KeywordEnd; CurPtr = KeywordEnd;
--StartChar; --StartChar;
unsigned Len = CurPtr-StartChar; StringRef Keyword(StartChar, CurPtr - StartChar);
#define KEYWORD(STR) \ #define KEYWORD(STR) \
do { \ do { \
if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \ if (Keyword == #STR) \
return lltok::kw_##STR; \ return lltok::kw_##STR; \
} while (0) } while (0)
KEYWORD(true); KEYWORD(false); KEYWORD(true); KEYWORD(false);
@ -670,7 +670,7 @@ lltok::Kind LLLexer::LexIdentifier() {
// Keywords for types. // Keywords for types.
#define TYPEKEYWORD(STR, LLVMTY) \ #define TYPEKEYWORD(STR, LLVMTY) \
do { \ do { \
if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \ if (Keyword == STR) { \
TyVal = LLVMTY; \ TyVal = LLVMTY; \
return lltok::Type; \ return lltok::Type; \
} \ } \
@ -690,7 +690,7 @@ lltok::Kind LLLexer::LexIdentifier() {
// Keywords for instructions. // Keywords for instructions.
#define INSTKEYWORD(STR, Enum) \ #define INSTKEYWORD(STR, Enum) \
do { \ do { \
if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \ if (Keyword == #STR) { \
UIntVal = Instruction::Enum; \ UIntVal = Instruction::Enum; \
return lltok::kw_##STR; \ return lltok::kw_##STR; \
} \ } \
@ -748,9 +748,8 @@ lltok::Kind LLLexer::LexIdentifier() {
#define DWKEYWORD(TYPE, TOKEN) \ #define DWKEYWORD(TYPE, TOKEN) \
do { \ do { \
if (Len >= strlen("DW_" #TYPE "_") && \ if (Keyword.startswith("DW_" #TYPE "_")) { \
!memcmp(StartChar, "DW_" #TYPE "_", strlen("DW_" #TYPE "_"))) { \ StrVal.assign(Keyword.begin(), Keyword.end()); \
StrVal.assign(StartChar, CurPtr); \
return lltok::TOKEN; \ return lltok::TOKEN; \
} \ } \
} while (false) } while (false)