[cfe-commits] r60437 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/PPLexerChange.cpp

Ted Kremenek kremenek at apple.com
Tue Dec 2 11:46:32 PST 2008


Author: kremenek
Date: Tue Dec  2 13:46:31 2008
New Revision: 60437

URL: http://llvm.org/viewvc/llvm-project?rev=60437&view=rev
Log:
Preprocessor:
- Added method "setPTHManager" that will be called by the driver to install
  a PTHManager for the Preprocessor.
- Fixed some comments.
- Added EnterSourceFileWithPTH to mirror EnterSourceFileWithLexer.

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

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Dec  2 13:46:31 2008
@@ -18,6 +18,7 @@
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/TokenLexer.h"
+#include "clang/Lex/PTHManager.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
@@ -36,7 +37,7 @@
 class TargetInfo;
 class PPCallbacks;
 class DirectoryLookup;
-
+  
 /// Preprocessor - This object engages in a tight little dance with the lexer to
 /// efficiently preprocess tokens.  Lexers know only about tokens within a
 /// single source file, and don't know anything about preprocessor-level issues
@@ -50,6 +51,10 @@
   SourceManager     &SourceMgr;
   ScratchBuffer     *ScratchBuf;
   HeaderSearch      &HeaderInfo;
+  
+  /// PTH - An optional PTHManager object used for getting tokens from
+  ///  a token cache rather than lexing the original source file.
+  llvm::OwningPtr<PTHManager> PTH;
     
   /// Identifiers for builtin macros and other builtins.
   IdentifierInfo *Ident__LINE__, *Ident__FILE__;   // __LINE__, __FILE__
@@ -189,6 +194,8 @@
 
   IdentifierTable &getIdentifierTable() { return Identifiers; }
   SelectorTable &getSelectorTable() { return Selectors; }
+  
+  void setPTHManager(PTHManager* pm) { PTH.reset(pm); }
 
   /// SetCommentRetentionState - Control whether or not the preprocessor retains
   /// comments in output.
@@ -591,10 +598,13 @@
   /// been read into 'Tok'.
   void Handle_Pragma(Token &Tok);
   
-  
   /// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and
   /// start lexing tokens from it instead of the current buffer.
   void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
+
+  /// EnterSourceFileWithPTH - Add a lexer to the top of the include stack and
+  /// start getting tokens from it using the PTH cache.
+  void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir);
   
   /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
   /// checked and spelled filename, e.g. as an operand of #include. This returns

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

==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Tue Dec  2 13:46:31 2008
@@ -75,6 +75,16 @@
     MaxIncludeStackDepth = IncludeMacroStack.size();
 
 #if 1
+  if (PTH) {
+    PTHLexer* PL =
+      PTH->CreateLexer(FileID, getSourceManager().getFileEntryForID(FileID));
+
+    if (PL) {
+      EnterSourceFileWithPTH(PL, CurDir);
+      return;
+    }
+  }
+  
   Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
   EnterSourceFileWithLexer(TheLexer, CurDir);
 #else
@@ -149,8 +159,8 @@
 #endif
 }  
 
-/// EnterSourceFile - Add a source file to the top of the include stack and
-/// start lexing tokens from it instead of the current buffer.
+/// EnterSourceFileWithLexer - Add a source file to the top of the include stack
+///  and start lexing tokens from it instead of the current buffer.
 void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer, 
                                             const DirectoryLookup *CurDir) {
     
@@ -172,7 +182,27 @@
   }
 }
 
+/// EnterSourceFileWithPTH - Add a source file to the top of the include stack
+/// and start getting tokens from it using the PTH cache.
+void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL, 
+                                          const DirectoryLookup *CurDir) {
+  
+  if (CurPPLexer || CurTokenLexer)
+    PushIncludeMacroStack();
 
+  CurDirLookup = CurDir;
+  CurPTHLexer.reset(PL);
+  CurPPLexer = CurPTHLexer.get();
+
+  // Notify the client, if desired, that we are in a new source file.
+  if (Callbacks) {
+    unsigned FileID = CurPPLexer->getFileID();
+    SrcMgr::CharacteristicKind FileType =
+      SourceMgr.getFileCharacteristic(CurPPLexer->getFileID());    
+    Callbacks->FileChanged(SourceLocation::getFileLoc(FileID, 0),
+                           PPCallbacks::EnterFile, FileType);
+  }
+}
 
 /// EnterMacro - Add a Macro to the top of the include stack and start lexing
 /// tokens from it instead of the current buffer.





More information about the cfe-commits mailing list