]> granicus.if.org Git - clang/commitdiff
Refactor to remove the assumption that we know the name of the module we're emitting...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Aug 2016 18:26:30 +0000 (18:26 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Aug 2016 18:26:30 +0000 (18:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279766 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTWriter.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/ChainedIncludesSource.cpp
lib/Frontend/FrontendActions.cpp
lib/Serialization/GeneratePCH.cpp

index b07b36cc1e3ff5a4fcec16052deb2ce10dec7f06..f247855f69150b6a8a541fd01023074a41122198 100644 (file)
@@ -909,7 +909,6 @@ public:
 class PCHGenerator : public SemaConsumer {
   const Preprocessor &PP;
   std::string OutputFile;
-  clang::Module *Module;
   std::string isysroot;
   Sema *SemaPtr;
   std::shared_ptr<PCHBuffer> Buffer;
@@ -925,7 +924,7 @@ protected:
 public:
   PCHGenerator(
     const Preprocessor &PP, StringRef OutputFile,
-    clang::Module *Module, StringRef isysroot,
+    StringRef isysroot,
     std::shared_ptr<PCHBuffer> Buffer,
     ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
     bool AllowASTWithErrors = false,
index 3a34f852d89d6476b2de1db8ae885281147cd432..f66ff140aab939e3ed8893d7e23b6a9a38597bca 100644 (file)
@@ -925,7 +925,7 @@ public:
   PrecompilePreambleConsumer(ASTUnit &Unit, PrecompilePreambleAction *Action,
                              const Preprocessor &PP, StringRef isysroot,
                              std::unique_ptr<raw_ostream> Out)
-      : PCHGenerator(PP, "", nullptr, isysroot, std::make_shared<PCHBuffer>(),
+      : PCHGenerator(PP, "", isysroot, std::make_shared<PCHBuffer>(),
                      ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>>(),
                      /*AllowASTWithErrors=*/true),
         Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action),
index 7687b24dda924ccd4101aa3358a94c843cb936b8..c5b77ee90e5647142ba24b0c08d4ec2af523d1e4 100644 (file)
@@ -161,7 +161,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
     auto Buffer = std::make_shared<PCHBuffer>();
     ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions;
     auto consumer = llvm::make_unique<PCHGenerator>(
-        Clang->getPreprocessor(), "-", nullptr, /*isysroot=*/"", Buffer,
+        Clang->getPreprocessor(), "-", /*isysroot=*/"", Buffer,
         Extensions, /*AllowASTWithErrors=*/true);
     Clang->getASTContext().setASTMutationListener(
                                             consumer->GetASTMutationListener());
index 706ccea59b8c6d9a5f10482e3af0784fa2035d26..d73d46984cca13c4ab9aeba484b3f437e9cf4e28 100644 (file)
@@ -91,7 +91,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   auto Buffer = std::make_shared<PCHBuffer>();
   std::vector<std::unique_ptr<ASTConsumer>> Consumers;
   Consumers.push_back(llvm::make_unique<PCHGenerator>(
-                        CI.getPreprocessor(), OutputFile, nullptr, Sysroot,
+                        CI.getPreprocessor(), OutputFile, Sysroot,
                         Buffer, CI.getFrontendOpts().ModuleFileExtensions,
                         /*AllowASTWithErrors*/false,
                         /*IncludeTimestamps*/
@@ -141,7 +141,7 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
   std::vector<std::unique_ptr<ASTConsumer>> Consumers;
 
   Consumers.push_back(llvm::make_unique<PCHGenerator>(
-                        CI.getPreprocessor(), OutputFile, Module, Sysroot,
+                        CI.getPreprocessor(), OutputFile, Sysroot,
                         Buffer, CI.getFrontendOpts().ModuleFileExtensions,
                         /*AllowASTWithErrors=*/false,
                         /*IncludeTimestamps=*/
index 47dce37ede15ed3d10621e89b856a82a29c1ad4b..b2d79a20871d47e5d055e5c1661b58af3e3d50fa 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/ASTContext.h"
+#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/SemaConsumer.h"
 #include "clang/Serialization/ASTWriter.h"
 using namespace clang;
 
 PCHGenerator::PCHGenerator(
-  const Preprocessor &PP, StringRef OutputFile,
-  clang::Module *Module, StringRef isysroot,
-  std::shared_ptr<PCHBuffer> Buffer,
-  ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
-  bool AllowASTWithErrors, bool IncludeTimestamps)
-    : PP(PP), OutputFile(OutputFile), Module(Module), isysroot(isysroot.str()),
+    const Preprocessor &PP, StringRef OutputFile, StringRef isysroot,
+    std::shared_ptr<PCHBuffer> Buffer,
+    ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
+    bool AllowASTWithErrors, bool IncludeTimestamps)
+    : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
       SemaPtr(nullptr), Buffer(Buffer), Stream(Buffer->Data),
       Writer(Stream, Extensions, IncludeTimestamps),
       AllowASTWithErrors(AllowASTWithErrors) {
@@ -45,6 +45,13 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
   if (hasErrors && !AllowASTWithErrors)
     return;
 
+  Module *Module = nullptr;
+  if (PP.getLangOpts().CompilingModule) {
+    Module = PP.getHeaderSearchInfo().lookupModule(
+        PP.getLangOpts().CurrentModule, /*AllowSearch*/ false);
+    assert(Module && "emitting module but current module doesn't exist");
+  }
+
   // Emit the PCH file to the Buffer.
   assert(SemaPtr && "No Sema?");
   Buffer->Signature =