Introduce the notion of a SemaConsumer, which is an ASTConsumer that
also gets access to the Sema object performing semantic analysis. This
will be used by the PCH writer to serialize Sema state.

No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69595 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/GeneratePCH.cpp b/tools/clang-cc/GeneratePCH.cpp
index 9b86514..4265c81 100644
--- a/tools/clang-cc/GeneratePCH.cpp
+++ b/tools/clang-cc/GeneratePCH.cpp
@@ -14,6 +14,7 @@
 
 #include "ASTConsumers.h"
 #include "clang/Frontend/PCHWriter.h"
+#include "clang/Sema/SemaConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/Lex/Preprocessor.h"
@@ -28,14 +29,16 @@
 using namespace llvm;
 
 namespace {
-  class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
+  class VISIBILITY_HIDDEN PCHGenerator : public SemaConsumer {
     const Preprocessor &PP;
     std::string OutFile;
+    Sema *SemaPtr;
 
   public:
     explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
-      : PP(PP), OutFile(OutFile) { }
+      : PP(PP), OutFile(OutFile), SemaPtr(0) { }
 
+    virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
     virtual void HandleTranslationUnit(ASTContext &Ctx);
   };
 }
@@ -50,7 +53,8 @@
   PCHWriter Writer(Stream);
 
   // Emit the PCH file
-  Writer.WritePCH(Ctx, PP);
+  assert(SemaPtr && "No Sema?");
+  Writer.WritePCH(*SemaPtr);
 
   // Open up the PCH file.
   std::string ErrMsg;