llvm.org GIT mirror llvm / 37d42af
Simplify code. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141299 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
1 changed file(s) with 24 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
207207 tgtok::TokKind TGLexer::LexIdentifier() {
208208 // The first letter is [a-zA-Z_#].
209209 const char *IdentStart = TokStart;
210
210
211211 // Match the rest of the identifier regex: [0-9a-zA-Z_#]*
212212 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_' ||
213213 *CurPtr == '#')
214214 ++CurPtr;
215
216
215
217216 // Check to see if this identifier is a keyword.
218 unsigned Len = CurPtr-IdentStart;
219
220 if (Len == 3 && !memcmp(IdentStart, "int", 3)) return tgtok::Int;
221 if (Len == 3 && !memcmp(IdentStart, "bit", 3)) return tgtok::Bit;
222 if (Len == 4 && !memcmp(IdentStart, "bits", 4)) return tgtok::Bits;
223 if (Len == 6 && !memcmp(IdentStart, "string", 6)) return tgtok::String;
224 if (Len == 4 && !memcmp(IdentStart, "list", 4)) return tgtok::List;
225 if (Len == 4 && !memcmp(IdentStart, "code", 4)) return tgtok::Code;
226 if (Len == 3 && !memcmp(IdentStart, "dag", 3)) return tgtok::Dag;
227
228 if (Len == 5 && !memcmp(IdentStart, "class", 5)) return tgtok::Class;
229 if (Len == 3 && !memcmp(IdentStart, "def", 3)) return tgtok::Def;
230 if (Len == 8 && !memcmp(IdentStart, "multidef", 8)) return tgtok::MultiDef;
231 if (Len == 4 && !memcmp(IdentStart, "defm", 4)) return tgtok::Defm;
232 if (Len == 10 && !memcmp(IdentStart, "multiclass", 10))
233 return tgtok::MultiClass;
234 if (Len == 5 && !memcmp(IdentStart, "field", 5)) return tgtok::Field;
235 if (Len == 3 && !memcmp(IdentStart, "let", 3)) return tgtok::Let;
236 if (Len == 2 && !memcmp(IdentStart, "in", 2)) return tgtok::In;
237
238 if (Len == 7 && !memcmp(IdentStart, "include", 7)) {
217 StringRef Str(IdentStart, CurPtr-IdentStart);
218
219 if (Str == "int") return tgtok::Int;
220 if (Str == "bit") return tgtok::Bit;
221 if (Str == "bits") return tgtok::Bits;
222 if (Str == "string") return tgtok::String;
223 if (Str == "list") return tgtok::List;
224 if (Str == "code") return tgtok::Code;
225 if (Str == "dag") return tgtok::Dag;
226
227 if (Str == "class") return tgtok::Class;
228 if (Str == "def") return tgtok::Def;
229 if (Str == "multidef") return tgtok::MultiDef;
230 if (Str == "defm") return tgtok::Defm;
231 if (Str == "multiclass") return tgtok::MultiClass;
232 if (Str == "field") return tgtok::Field;
233 if (Str == "let") return tgtok::Let;
234 if (Str == "in") return tgtok::In;
235
236 if (Str == "include") {
239237 if (LexInclude()) return tgtok::Error;
240238 return Lex();
241239 }
242
243 CurStrVal.assign(IdentStart, CurPtr);
240
241 CurStrVal.assign(Str.begin(), Str.end());
244242 return tgtok::Id;
245243 }
246244