[cfe-commits] r64932 - /cfe/trunk/lib/Sema/SemaChecking.cpp
Chris Lattner
sabre at nondot.org
Wed Feb 18 10:40:21 PST 2009
Author: lattner
Date: Wed Feb 18 12:40:20 2009
New Revision: 64932
URL: http://llvm.org/viewvc/llvm-project?rev=64932&view=rev
Log:
only get the spelling of a token to get its length if
it needs cleaning.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=64932&r1=64931&r2=64932&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb 18 12:40:20 2009
@@ -63,13 +63,20 @@
Token TheTok;
TheLexer.LexFromRawLexer(TheTok);
- // Get the spelling of the token to remove trigraphs and escaped newlines.
- SpellingBuffer.resize(TheTok.getLength());
- const char *SpellingPtr = &SpellingBuffer[0];
- unsigned TokLen = PP.getSpelling(TheTok, SpellingPtr);
+ // We generally care about the length of the token, which is known by the
+ // lexer as long as we don't need to clean it (trigraphs/newlines).
+ unsigned TokNumBytes;
+ if (!TheTok.needsCleaning()) {
+ TokNumBytes = TheTok.getLength();
+ } else {
+ // Get the spelling of the token to remove trigraphs and escaped newlines.
+ SpellingBuffer.resize(TheTok.getLength());
+ const char *SpellingPtr = &SpellingBuffer[0];
+ TokNumBytes = PP.getSpelling(TheTok, SpellingPtr);
+ }
// The length of the string is the token length minus the two quotes.
- unsigned TokNumBytes = TokLen-2;
+ TokNumBytes -= 2;
// If we found the token we're looking for, return the location.
// FIXME: This should consider character escapes!
More information about the cfe-commits
mailing list