Эх сурвалжийг харах

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

NFC preparation work for upcoming ExternalASTMerger patches.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373312 91177308-0d34-0410-b5e6-96231b3b80d8
Raphael Isemann 5 жил өмнө
parent
commit
5dd8fd3019

+ 8 - 1
include/clang/AST/ExternalASTMerger.h

@@ -80,10 +80,17 @@ public:
   /// import SourceLocations properly.  Additionally, when import occurs for
   /// import SourceLocations properly.  Additionally, when import occurs for
   /// a DeclContext whose origin has been overridden, then this
   /// a DeclContext whose origin has been overridden, then this
   /// ExternalASTMerger must be able to determine that.
   /// ExternalASTMerger must be able to determine that.
-  struct ImporterSource {
+  class ImporterSource {
     ASTContext *
     ASTContext *
     FileManager &FM;
     FileManager &FM;
     const OriginMap &OM;
     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:
 private:

+ 14 - 13
lib/AST/ExternalASTMerger.cpp

@@ -105,15 +105,16 @@ private:
   llvm::raw_ostream &logs() { return Parent.logs(); }
   llvm::raw_ostream &logs() { return Parent.logs(); }
 public:
 public:
   LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
   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)
                   std::shared_ptr<ASTImporterSharedState> SharedState)
-      : ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager,
+      : ASTImporter(ToContext, ToFileManager, _Source.getASTContext(),
+                    _Source.getFileManager(),
                     /*MinimalImport=*/true, SharedState),
                     /*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
   /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
   /// map is kept up to date.  Also set the appropriate flags.
   /// map is kept up to date.  Also set the appropriate flags.
@@ -323,23 +324,23 @@ ExternalASTMerger::ExternalASTMerger(const ImporterTarget &Target,
 
 
 void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) {
 void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) {
   for (const ImporterSource &S : Sources) {
   for (const ImporterSource &S : Sources) {
-    assert(&S.AST != &Target.AST);
+    assert(&S.getASTContext() != &Target.AST);
     Importers.push_back(std::make_unique<LazyASTImporter>(
     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) {
 void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
   if (LoggingEnabled())
   if (LoggingEnabled())
     for (const ImporterSource &S : Sources)
     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";
              << "\n";
   Importers.erase(
   Importers.erase(
       std::remove_if(Importers.begin(), Importers.end(),
       std::remove_if(Importers.begin(), Importers.end(),
                      [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool {
                      [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool {
                        for (const ImporterSource &S : Sources) {
                        for (const ImporterSource &S : Sources) {
-                         if (&Importer->getFromContext() == &S.AST)
+                         if (&Importer->getFromContext() == &S.getASTContext())
                            return true;
                            return true;
                        }
                        }
                        return false;
                        return false;
@@ -349,7 +350,7 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
     std::pair<const DeclContext *, DCOrigin> Origin = *OI;
     std::pair<const DeclContext *, DCOrigin> Origin = *OI;
     bool Erase = false;
     bool Erase = false;
     for (const ImporterSource &S : Sources) {
     for (const ImporterSource &S : Sources) {
-      if (&S.AST == Origin.second.AST) {
+      if (&S.getASTContext() == Origin.second.AST) {
         Erase = true;
         Erase = true;
         break;
         break;
       }
       }

+ 2 - 2
tools/clang-import-test/clang-import-test.cpp

@@ -263,8 +263,8 @@ void AddExternalSource(CIAndOrigins &CI,
       {CI.getASTContext(), CI.getFileManager()});
       {CI.getASTContext(), CI.getFileManager()});
   llvm::SmallVector<ExternalASTMerger::ImporterSource, 3> Sources;
   llvm::SmallVector<ExternalASTMerger::ImporterSource, 3> Sources;
   for (CIAndOrigins &Import : Imports)
   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);
   auto ES = std::make_unique<ExternalASTMerger>(Target, Sources);
   CI.getASTContext().setExternalSource(ES.release());
   CI.getASTContext().setExternalSource(ES.release());
   CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();
   CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();