r373312 - [clang][lldb][NFC] Encapsulate ExternalASTMerger::ImporterSource

Raphael Isemann via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 1 02:02:05 PDT 2019


Author: teemperor
Date: Tue Oct  1 02:02:05 2019
New Revision: 373312

URL: http://llvm.org/viewvc/llvm-project?rev=373312&view=rev
Log:
[clang][lldb][NFC] Encapsulate ExternalASTMerger::ImporterSource

NFC preparation work for upcoming ExternalASTMerger patches.

Modified:
    cfe/trunk/include/clang/AST/ExternalASTMerger.h
    cfe/trunk/lib/AST/ExternalASTMerger.cpp
    cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/include/clang/AST/ExternalASTMerger.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTMerger.h?rev=373312&r1=373311&r2=373312&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTMerger.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTMerger.h Tue Oct  1 02:02:05 2019
@@ -80,10 +80,17 @@ public:
   /// import SourceLocations properly.  Additionally, when import occurs for
   /// a DeclContext whose origin has been overridden, then this
   /// ExternalASTMerger must be able to determine that.
-  struct ImporterSource {
+  class ImporterSource {
     ASTContext *
     FileManager &FM;
     const OriginMap &OM;
+
+  public:
+    ImporterSource(ASTContext &_AST, FileManager &_FM, const OriginMap &_OM)
+        : AST(_AST), FM(_FM), OM(_OM) {}
+    ASTContext &getASTContext() const { return AST; }
+    FileManager &getFileManager() const { return FM; }
+    const OriginMap &getOriginMap() const { return OM; }
   };
 
 private:

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=373312&r1=373311&r2=373312&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExternalASTMerger.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTMerger.cpp Tue Oct  1 02:02:05 2019
@@ -105,15 +105,16 @@ private:
   llvm::raw_ostream &logs() { return Parent.logs(); }
 public:
   LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
-                  FileManager &ToFileManager, ASTContext &FromContext,
-                  FileManager &FromFileManager,
-                  const ExternalASTMerger::OriginMap &_FromOrigins,
+                  FileManager &ToFileManager,
+                  const ExternalASTMerger::ImporterSource &_Source,
                   std::shared_ptr<ASTImporterSharedState> SharedState)
-      : ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager,
+      : ASTImporter(ToContext, ToFileManager, _Source.getASTContext(),
+                    _Source.getFileManager(),
                     /*MinimalImport=*/true, SharedState),
-        Parent(_Parent), Reverse(FromContext, FromFileManager, ToContext,
-                                 ToFileManager, /*MinimalImport=*/true),
-        FromOrigins(_FromOrigins) {}
+        Parent(_Parent),
+        Reverse(_Source.getASTContext(), _Source.getFileManager(), ToContext,
+                ToFileManager, /*MinimalImport=*/true),
+        FromOrigins(_Source.getOriginMap()) {}
 
   /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
   /// map is kept up to date.  Also set the appropriate flags.
@@ -323,23 +324,23 @@ ExternalASTMerger::ExternalASTMerger(con
 
 void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) {
   for (const ImporterSource &S : Sources) {
-    assert(&S.AST != &Target.AST);
+    assert(&S.getASTContext() != &Target.AST);
     Importers.push_back(std::make_unique<LazyASTImporter>(
-        *this, Target.AST, Target.FM, S.AST, S.FM, S.OM, SharedState));
+        *this, Target.AST, Target.FM, S, SharedState));
   }
 }
 
 void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
   if (LoggingEnabled())
     for (const ImporterSource &S : Sources)
-      logs() << "(ExternalASTMerger*)" << (void*)this
-             << " removing source (ASTContext*)" << (void*)&S.AST
+      logs() << "(ExternalASTMerger*)" << (void *)this
+             << " removing source (ASTContext*)" << (void *)&S.getASTContext()
              << "\n";
   Importers.erase(
       std::remove_if(Importers.begin(), Importers.end(),
                      [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool {
                        for (const ImporterSource &S : Sources) {
-                         if (&Importer->getFromContext() == &S.AST)
+                         if (&Importer->getFromContext() == &S.getASTContext())
                            return true;
                        }
                        return false;
@@ -349,7 +350,7 @@ void ExternalASTMerger::RemoveSources(ll
     std::pair<const DeclContext *, DCOrigin> Origin = *OI;
     bool Erase = false;
     for (const ImporterSource &S : Sources) {
-      if (&S.AST == Origin.second.AST) {
+      if (&S.getASTContext() == Origin.second.AST) {
         Erase = true;
         break;
       }

Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=373312&r1=373311&r2=373312&view=diff
==============================================================================
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Oct  1 02:02:05 2019
@@ -263,8 +263,8 @@ void AddExternalSource(CIAndOrigins &CI,
       {CI.getASTContext(), CI.getFileManager()});
   llvm::SmallVector<ExternalASTMerger::ImporterSource, 3> Sources;
   for (CIAndOrigins &Import : Imports)
-    Sources.push_back({Import.getASTContext(), Import.getFileManager(),
-                       Import.getOriginMap()});
+    Sources.emplace_back(Import.getASTContext(), Import.getFileManager(),
+                         Import.getOriginMap());
   auto ES = std::make_unique<ExternalASTMerger>(Target, Sources);
   CI.getASTContext().setExternalSource(ES.release());
   CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();




More information about the cfe-commits mailing list