]> granicus.if.org Git - clang/commitdiff
only get the spelling of a token to get its length if
authorChris Lattner <sabre@nondot.org>
Wed, 18 Feb 2009 18:40:20 +0000 (18:40 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 18 Feb 2009 18:40:20 +0000 (18:40 +0000)
it needs cleaning.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64932 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp

index 6ffca1b7b8724cda84841083337fdfa386cc5eb6..818a892617e1ce48a278b9748897b9312160f07b 100644 (file)
@@ -63,13 +63,20 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
     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!