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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60437 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp
index 5129d58..bb2536d 100644
--- a/lib/Lex/PPLexerChange.cpp
+++ b/lib/Lex/PPLexerChange.cpp
@@ -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.