]> granicus.if.org Git - clang/commitdiff
Preprocessor:
authorTed Kremenek <kremenek@apple.com>
Tue, 2 Dec 2008 19:46:31 +0000 (19:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 2 Dec 2008 19:46:31 +0000 (19:46 +0000)
- 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.

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

include/clang/Lex/Preprocessor.h
lib/Lex/PPLexerChange.cpp

index bb7e8c7cfb8186d29b1980e7117fbe33a338674c..55be0d5766f0925e52a1e739c3d44d416e38e719 100644 (file)
@@ -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 ScratchBuffer;
 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 @@ class Preprocessor {
   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 @@ public:
 
   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 @@ private:
   /// 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
index 5129d58bd7fc9fc3da31587151b1ce01a1effa74..bb2536d1e6098b3802006c6d5dcaff06b612bc89 100644 (file)
@@ -75,6 +75,16 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
     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 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
 #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 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
   }
 }
 
+/// 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.