[cfe-commits] r61170 - in /cfe/trunk: include/clang/Lex/PTHLexer.h lib/Lex/PTHLexer.cpp

Ted Kremenek kremenek at apple.com
Wed Dec 17 15:36:33 PST 2008


Author: kremenek
Date: Wed Dec 17 17:36:32 2008
New Revision: 61170

URL: http://llvm.org/viewvc/llvm-project?rev=61170&view=rev
Log:
Change PTHLexer::getSourceLocation() to not call GetToken() and instead just read the file offset in the token data buffer directly.

Modified:
    cfe/trunk/include/clang/Lex/PTHLexer.h
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=61170&r1=61169&r2=61170&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Wed Dec 17 17:36:32 2008
@@ -90,8 +90,8 @@
   
   /// getSourceLocation - Return a source location for the token in
   /// the current file.
-  SourceLocation getSourceLocation() { return GetToken().getLocation(); }
-  
+  SourceLocation getSourceLocation();
+
   /// SkipBlock - Used by Preprocessor to skip the current conditional block.
   bool SkipBlock();
 

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=61170&r1=61169&r2=61170&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Dec 17 17:36:32 2008
@@ -262,6 +262,21 @@
   return isEndif;
 }
 
+SourceLocation PTHLexer::getSourceLocation() {
+  // getLocation is not on the hot path.  It is used to get the location of
+  // the next token when transitioning back to this lexer when done
+  // handling a #included file.  Just read the necessary data from the token
+  // data buffer to construct the SourceLocation object.
+  // NOTE: This is a virtual function; hence it is defined out-of-line.
+  const char* p = CurPtr + (1 + 1 + 4);
+  uint32_t offset = 
+       ((uint32_t) ((uint8_t) p[0]))
+    | (((uint32_t) ((uint8_t) p[1])) << 8)
+    | (((uint32_t) ((uint8_t) p[2])) << 16)
+    | (((uint32_t) ((uint8_t) p[3])) << 24);
+  return SourceLocation::getFileLoc(FileID, offset);
+}
+
 //===----------------------------------------------------------------------===//
 // Token reconstruction from the PTH file.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list