@@ -266,21 +266,23 @@ unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
266
266
const SourceManager &SourceMgr,
267
267
const LangOptions &Features, bool *Invalid) {
268
268
assert ((int )Tok.getLength () >= 0 && " Token character range is bogus!" );
269
-
270
- // If this token is an identifier, just return the string from the identifier
271
- // table, which is very quick.
272
- if (const IdentifierInfo *II = Tok.getIdentifierInfo ()) {
269
+
270
+ const char *TokStart = 0 ;
271
+ // NOTE: this has to be checked *before* testing for an IdentifierInfo.
272
+ if (Tok.is (tok::raw_identifier))
273
+ TokStart = Tok.getRawIdentifierData ();
274
+ else if (const IdentifierInfo *II = Tok.getIdentifierInfo ()) {
275
+ // Just return the string from the identifier table, which is very quick.
273
276
Buffer = II->getNameStart ();
274
277
return II->getLength ();
275
278
}
276
-
277
- // Otherwise, compute the start of the token in the input lexer buffer.
278
- const char *TokStart = 0 ;
279
-
279
+
280
+ // NOTE: this can be checked even after testing for an IdentifierInfo.
280
281
if (Tok.isLiteral ())
281
282
TokStart = Tok.getLiteralData ();
282
-
283
+
283
284
if (TokStart == 0 ) {
285
+ // Compute the start of the token in the input lexer buffer.
284
286
bool CharDataInvalid = false ;
285
287
TokStart = SourceMgr.getCharacterData (Tok.getLocation (), &CharDataInvalid);
286
288
if (Invalid)
@@ -290,13 +292,13 @@ unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
290
292
return 0 ;
291
293
}
292
294
}
293
-
295
+
294
296
// If this token contains nothing interesting, return it directly.
295
297
if (!Tok.needsCleaning ()) {
296
298
Buffer = TokStart;
297
299
return Tok.getLength ();
298
300
}
299
-
301
+
300
302
// Otherwise, hard case, relex the characters into the string.
301
303
char *OutBuf = const_cast <char *>(Buffer);
302
304
for (const char *Ptr = TokStart, *End = TokStart+Tok.getLength ();
@@ -307,7 +309,7 @@ unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
307
309
}
308
310
assert (unsigned (OutBuf-Buffer) != Tok.getLength () &&
309
311
" NeedsCleaning flag set on something that didn't need cleaning!" );
310
-
312
+
311
313
return OutBuf-Buffer;
312
314
}
313
315
@@ -473,10 +475,9 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer, unsigned MaxLines) {
473
475
// we don't have an identifier table available. Instead, just look at
474
476
// the raw identifier to recognize and categorize preprocessor directives.
475
477
TheLexer.LexFromRawLexer (TheTok);
476
- if (TheTok.getKind () == tok::identifier && !TheTok.needsCleaning ()) {
477
- const char *IdStart = Buffer->getBufferStart ()
478
- + TheTok.getLocation ().getRawEncoding () - 1 ;
479
- llvm::StringRef Keyword (IdStart, TheTok.getLength ());
478
+ if (TheTok.getKind () == tok::raw_identifier && !TheTok.needsCleaning ()) {
479
+ llvm::StringRef Keyword (TheTok.getRawIdentifierData (),
480
+ TheTok.getLength ());
480
481
PreambleDirectiveKind PDK
481
482
= llvm::StringSwitch<PreambleDirectiveKind>(Keyword)
482
483
.Case (" include" , PDK_Skipped)
@@ -1046,19 +1047,17 @@ void Lexer::LexIdentifier(Token &Result, const char *CurPtr) {
1046
1047
if (C != ' \\ ' && C != ' ?' && (C != ' $' || !Features.DollarIdents )) {
1047
1048
FinishIdentifier:
1048
1049
const char *IdStart = BufferPtr;
1049
- FormTokenWithChars (Result, CurPtr, tok::identifier);
1050
+ FormTokenWithChars (Result, CurPtr, tok::raw_identifier);
1051
+ Result.setRawIdentifierData (IdStart);
1050
1052
1051
1053
// If we are in raw mode, return this identifier raw. There is no need to
1052
1054
// look up identifier information or attempt to macro expand it.
1053
- if (LexingRawMode) return ;
1054
-
1055
- // Fill in Result.IdentifierInfo, looking up the identifier in the
1056
- // identifier table.
1057
- IdentifierInfo *II = PP->LookUpIdentifierInfo (Result, IdStart);
1055
+ if (LexingRawMode)
1056
+ return ;
1058
1057
1059
- // Change the kind of this identifier to the appropriate token kind, e.g.
1060
- // turning "for" into a keyword .
1061
- Result. setKind (II-> getTokenID () );
1058
+ // Fill in Result.IdentifierInfo and update the token kind,
1059
+ // looking up the identifier in the identifier table .
1060
+ IdentifierInfo *II = PP-> LookUpIdentifierInfo (Result );
1062
1061
1063
1062
// Finally, now that we know we have an identifier, pass this off to the
1064
1063
// preprocessor, which may macro expand it or something.
0 commit comments