teemperor created this revision. teemperor added reviewers: aprantl, shafik. Herald added a reviewer: martong. Herald added a reviewer: a.sidorin. Herald added subscribers: lldb-commits, abidh. Herald added a project: LLDB.
I think there universal agreement that Minion isn't the best name for this class. This patch renames the class to ASTImporterDelegate to better reflect it's goal of monitoring and extending the ASTImporter. Repository: rLLDB LLDB https://reviews.llvm.org/D61299 Files: lldb/include/lldb/Symbol/ClangASTImporter.h lldb/source/Symbol/ClangASTImporter.cpp
Index: lldb/source/Symbol/ClangASTImporter.cpp =================================================================== --- lldb/source/Symbol/ClangASTImporter.cpp +++ lldb/source/Symbol/ClangASTImporter.cpp @@ -58,12 +58,12 @@ clang::QualType ClangASTImporter::CopyType(clang::ASTContext *dst_ast, clang::ASTContext *src_ast, clang::QualType type) { - MinionSP minion_sp(GetMinion(dst_ast, src_ast)); + ImporterDelegateSP delegate_sp(GetDelegate(dst_ast, src_ast)); - Minion::CxxModuleScope std_scope(*minion_sp, dst_ast); + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); - if (minion_sp) - return minion_sp->Import(type); + if (delegate_sp) + return delegate_sp->Import(type); return QualType(); } @@ -99,14 +99,14 @@ clang::Decl *ClangASTImporter::CopyDecl(clang::ASTContext *dst_ast, clang::ASTContext *src_ast, clang::Decl *decl) { - MinionSP minion_sp; + ImporterDelegateSP delegate_sp; - minion_sp = GetMinion(dst_ast, src_ast); + delegate_sp = GetDelegate(dst_ast, src_ast); - Minion::CxxModuleScope std_scope(*minion_sp, dst_ast); + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); - if (minion_sp) { - clang::Decl *result = minion_sp->Import(decl); + if (delegate_sp) { + clang::Decl *result = delegate_sp->Import(decl); if (!result) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); @@ -254,9 +254,9 @@ (unsigned long long)type, static_cast<void *>(src_ctx), static_cast<void *>(dst_ctx)); - MinionSP minion_sp(GetMinion(dst_ctx, src_ctx)); + ImporterDelegateSP delegate_sp(GetDelegate(dst_ctx, src_ctx)); - if (!minion_sp) + if (!delegate_sp) return nullptr; std::set<NamedDecl *> decls_to_deport; @@ -270,11 +270,11 @@ tag_type->getDecl()); } - minion_sp->InitDeportWorkQueues(&decls_to_deport, &decls_already_deported); + delegate_sp->InitDeportWorkQueues(&decls_to_deport, &decls_already_deported); lldb::opaque_compiler_type_t result = CopyType(dst_ctx, src_ctx, type); - minion_sp->ExecuteDeportWorkQueues(); + delegate_sp->ExecuteDeportWorkQueues(); if (!result) return nullptr; @@ -293,9 +293,9 @@ decl->getDeclKindName(), static_cast<void *>(decl), static_cast<void *>(src_ctx), static_cast<void *>(dst_ctx)); - MinionSP minion_sp(GetMinion(dst_ctx, src_ctx)); + ImporterDelegateSP delegate_sp(GetDelegate(dst_ctx, src_ctx)); - if (!minion_sp) + if (!delegate_sp) return nullptr; std::set<NamedDecl *> decls_to_deport; @@ -305,11 +305,11 @@ decl_context_override.OverrideAllDeclsFromContainingFunction(decl); - minion_sp->InitDeportWorkQueues(&decls_to_deport, &decls_already_deported); + delegate_sp->InitDeportWorkQueues(&decls_to_deport, &decls_already_deported); clang::Decl *result = CopyDecl(dst_ctx, src_ctx, decl); - minion_sp->ExecuteDeportWorkQueues(); + delegate_sp->ExecuteDeportWorkQueues(); if (!result) return nullptr; @@ -561,11 +561,13 @@ if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) return false; - MinionSP minion_sp(GetMinion(&decl->getASTContext(), decl_origin.ctx)); + ImporterDelegateSP delegate_sp( + GetDelegate(&decl->getASTContext(), decl_origin.ctx)); - Minion::CxxModuleScope std_scope(*minion_sp, &decl->getASTContext()); - if (minion_sp) - minion_sp->ImportDefinitionTo(decl, decl_origin.decl); + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, + &decl->getASTContext()); + if (delegate_sp) + delegate_sp->ImportDefinitionTo(decl, decl_origin.decl); return true; } @@ -579,10 +581,11 @@ if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl)) return false; - MinionSP minion_sp(GetMinion(&decl->getASTContext(), origin_ast_ctx)); + ImporterDelegateSP delegate_sp( + GetDelegate(&decl->getASTContext(), origin_ast_ctx)); - if (minion_sp) - minion_sp->ImportDefinitionTo(decl, origin_decl); + if (delegate_sp) + delegate_sp->ImportDefinitionTo(decl, origin_decl); ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); @@ -605,11 +608,11 @@ if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) return false; - MinionSP minion_sp( - GetMinion(&interface_decl->getASTContext(), decl_origin.ctx)); + ImporterDelegateSP delegate_sp( + GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx)); - if (minion_sp) - minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); + if (delegate_sp) + delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass()) RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0)); @@ -629,14 +632,16 @@ if (!decl_origin.Valid()) return false; - MinionSP minion_sp(GetMinion(&tag_decl->getASTContext(), decl_origin.ctx)); + ImporterDelegateSP delegate_sp( + GetDelegate(&tag_decl->getASTContext(), decl_origin.ctx)); - Minion::CxxModuleScope std_scope(*minion_sp, &tag_decl->getASTContext()); + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, + &tag_decl->getASTContext()); TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl); for (Decl *origin_child_decl : origin_tag_decl->decls()) { - minion_sp->Import(origin_child_decl); + delegate_sp->Import(origin_child_decl); } if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl)) { @@ -654,14 +659,14 @@ if (!decl_origin.Valid()) return false; - MinionSP minion_sp( - GetMinion(&objc_interface_decl->getASTContext(), decl_origin.ctx)); + ImporterDelegateSP delegate_sp( + GetDelegate(&objc_interface_decl->getASTContext(), decl_origin.ctx)); ObjCInterfaceDecl *origin_interface_decl = llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl); for (Decl *origin_child_decl : origin_interface_decl->decls()) { - minion_sp->Import(origin_child_decl); + delegate_sp->Import(origin_child_decl); } return true; @@ -825,7 +830,8 @@ ClangASTImporter::MapCompleter::~MapCompleter() { return; } -llvm::Expected<Decl *> ClangASTImporter::Minion::ImportImpl(Decl *From) { +llvm::Expected<Decl *> +ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) { if (m_std_handler) { llvm::Optional<Decl *> D = m_std_handler->Import(From); if (D) { @@ -842,7 +848,7 @@ return ASTImporter::ImportImpl(From); } -void ClangASTImporter::Minion::InitDeportWorkQueues( +void ClangASTImporter::ASTImporterDelegate::InitDeportWorkQueues( std::set<clang::NamedDecl *> *decls_to_deport, std::set<clang::NamedDecl *> *decls_already_deported) { assert(!m_decls_to_deport); @@ -852,7 +858,7 @@ m_decls_already_deported = decls_already_deported; } -void ClangASTImporter::Minion::ExecuteDeportWorkQueues() { +void ClangASTImporter::ASTImporterDelegate::ExecuteDeportWorkQueues() { assert(m_decls_to_deport); assert(m_decls_already_deported); @@ -899,8 +905,8 @@ m_decls_already_deported = nullptr; } -void ClangASTImporter::Minion::ImportDefinitionTo(clang::Decl *to, - clang::Decl *from) { +void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo( + clang::Decl *to, clang::Decl *from) { ASTImporter::Imported(from, to); /* @@ -963,8 +969,8 @@ } } -void ClangASTImporter::Minion::Imported(clang::Decl *from, - clang::Decl *to) { +void ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from, + clang::Decl *to) { ClangASTMetrics::RegisterClangImport(); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); @@ -1015,8 +1021,8 @@ to_context_md->m_origins[to] = origin_iter->second; } - MinionSP direct_completer = - m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx); + ImporterDelegateSP direct_completer = + m_master.GetDelegate(&to->getASTContext(), origin_iter->second.ctx); if (direct_completer.get() != this) direct_completer->ASTImporter::Imported(origin_iter->second.decl, to); @@ -1129,7 +1135,8 @@ } } -clang::Decl *ClangASTImporter::Minion::GetOriginalDecl(clang::Decl *To) { +clang::Decl * +ClangASTImporter::ASTImporterDelegate::GetOriginalDecl(clang::Decl *To) { ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&To->getASTContext()); Index: lldb/include/lldb/Symbol/ClangASTImporter.h =================================================================== --- lldb/include/lldb/Symbol/ClangASTImporter.h +++ lldb/include/lldb/Symbol/ClangASTImporter.h @@ -235,10 +235,10 @@ typedef std::map<const clang::Decl *, DeclOrigin> OriginMap; - class Minion : public clang::ASTImporter { + class ASTImporterDelegate : public clang::ASTImporter { public: - Minion(ClangASTImporter &master, clang::ASTContext *target_ctx, - clang::ASTContext *source_ctx) + ASTImporterDelegate(ClangASTImporter &master, clang::ASTContext *target_ctx, + clang::ASTContext *source_ctx) : clang::ASTImporter(*target_ctx, master.m_file_manager, *source_ctx, master.m_file_manager, true /*minimal*/), m_decls_to_deport(nullptr), m_decls_already_deported(nullptr), @@ -246,17 +246,17 @@ /// Scope guard that attaches a CxxModuleHandler to a Minion and deattaches /// it at the end of the scope. Supports being used multiple times on the - /// same Minion instance in nested scopes. + /// same ASTImporterDelegate instance in nested scopes. class CxxModuleScope { /// The handler we attach to the Minion. CxxModuleHandler m_handler; /// The Minion we are supposed to attach the handler to. - Minion &m_minion; + ASTImporterDelegate &m_minion; /// True iff we attached the handler to the Minion. bool m_valid = false; public: - CxxModuleScope(Minion &minion, clang::ASTContext *dst_ctx) + CxxModuleScope(ASTImporterDelegate &minion, clang::ASTContext *dst_ctx) : m_minion(minion) { // If the minion doesn't have a CxxModuleHandler yet, create one // and attach it. @@ -314,8 +314,8 @@ CxxModuleHandler *m_std_handler = nullptr; }; - typedef std::shared_ptr<Minion> MinionSP; - typedef std::map<clang::ASTContext *, MinionSP> MinionMap; + typedef std::shared_ptr<ASTImporterDelegate> ImporterDelegateSP; + typedef std::map<clang::ASTContext *, ImporterDelegateSP> DelegateMap; typedef std::map<const clang::NamespaceDecl *, NamespaceMapSP> NamespaceMetaMap; @@ -325,7 +325,7 @@ m_map_completer(nullptr) {} clang::ASTContext *m_dst_ctx; - MinionMap m_minions; + DelegateMap m_minions; OriginMap m_origins; NamespaceMetaMap m_namespace_maps; @@ -360,14 +360,16 @@ return ASTContextMetadataSP(); } - MinionSP GetMinion(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx) { + ImporterDelegateSP GetDelegate(clang::ASTContext *dst_ctx, + clang::ASTContext *src_ctx) { ASTContextMetadataSP context_md = GetContextMetadata(dst_ctx); - MinionMap &minions = context_md->m_minions; - MinionMap::iterator minion_iter = minions.find(src_ctx); + DelegateMap &minions = context_md->m_minions; + DelegateMap::iterator minion_iter = minions.find(src_ctx); if (minion_iter == minions.end()) { - MinionSP minion = MinionSP(new Minion(*this, dst_ctx, src_ctx)); + ImporterDelegateSP minion = + ImporterDelegateSP(new ASTImporterDelegate(*this, dst_ctx, src_ctx)); minions[src_ctx] = minion; return minion; } else {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits