[Lldb-commits] [lldb] r359777 - Rename Minion to ASTImporterDelegate
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Thu May 2 03:58:33 PDT 2019
Author: teemperor
Date: Thu May 2 03:58:33 2019
New Revision: 359777
URL: http://llvm.org/viewvc/llvm-project?rev=359777&view=rev
Log:
Rename Minion to ASTImporterDelegate
Summary:
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.
Reviewers: aprantl, shafik, martong, a.sidorin, davide
Reviewed By: aprantl, shafik, davide
Subscribers: rnkovacs, davide, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61299
Modified:
lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
lldb/trunk/source/Symbol/ClangASTImporter.cpp
Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=359777&r1=359776&r2=359777&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Thu May 2 03:58:33 2019
@@ -235,42 +235,52 @@ private:
typedef std::map<const clang::Decl *, DeclOrigin> OriginMap;
- class Minion : public clang::ASTImporter {
+ /// ASTImporter that intercepts and records the import process of the
+ /// underlying ASTImporter.
+ ///
+ /// This class updates the map from declarations to their original
+ /// declarations and can record and complete declarations that have been
+ /// imported in a certain interval.
+ ///
+ /// When intercepting a declaration import, the ASTImporterDelegate uses the
+ /// CxxModuleHandler to replace any missing or malformed declarations with
+ /// their counterpart from a C++ module.
+ 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),
m_master(master), m_source_ctx(source_ctx) {}
- /// 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.
+ /// Scope guard that attaches a CxxModuleHandler to an ASTImporterDelegate
+ /// and deattaches it at the end of the scope. Supports being used multiple
+ /// times on the same ASTImporterDelegate instance in nested scopes.
class CxxModuleScope {
- /// The handler we attach to the Minion.
+ /// The handler we attach to the ASTImporterDelegate.
CxxModuleHandler m_handler;
- /// The Minion we are supposed to attach the handler to.
- Minion &m_minion;
- /// True iff we attached the handler to the Minion.
+ /// The ASTImporterDelegate we are supposed to attach the handler to.
+ ASTImporterDelegate &m_delegate;
+ /// True iff we attached the handler to the ASTImporterDelegate.
bool m_valid = false;
public:
- CxxModuleScope(Minion &minion, clang::ASTContext *dst_ctx)
- : m_minion(minion) {
- // If the minion doesn't have a CxxModuleHandler yet, create one
+ CxxModuleScope(ASTImporterDelegate &delegate, clang::ASTContext *dst_ctx)
+ : m_delegate(delegate) {
+ // If the delegate doesn't have a CxxModuleHandler yet, create one
// and attach it.
- if (!minion.m_std_handler) {
- m_handler = CxxModuleHandler(minion, dst_ctx);
+ if (!delegate.m_std_handler) {
+ m_handler = CxxModuleHandler(delegate, dst_ctx);
m_valid = true;
- minion.m_std_handler = &m_handler;
+ delegate.m_std_handler = &m_handler;
}
}
~CxxModuleScope() {
if (m_valid) {
// Make sure no one messed with the handler we placed.
- assert(m_minion.m_std_handler == &m_handler);
- m_minion.m_std_handler = nullptr;
+ assert(m_delegate.m_std_handler == &m_handler);
+ m_delegate.m_std_handler = nullptr;
}
}
};
@@ -279,7 +289,7 @@ private:
llvm::Expected<clang::Decl *> ImportImpl(clang::Decl *From) override;
public:
- // A call to "InitDeportWorkQueues" puts the minion into deport mode.
+ // A call to "InitDeportWorkQueues" puts the delegate into deport mode.
// In deport mode, every copied Decl that could require completion is
// recorded and placed into the decls_to_deport set.
//
@@ -287,8 +297,8 @@ private:
// are in decls_to_deport, adding any Decls it sees along the way that it
// hasn't already deported. It proceeds until decls_to_deport is empty.
//
- // These calls must be paired. Leaving a minion in deport mode or trying
- // to start deport minion with a new pair of queues will result in an
+ // These calls must be paired. Leaving a delegate in deport mode or trying
+ // to start deport delegate with a new pair of queues will result in an
// assertion failure.
void
@@ -314,18 +324,18 @@ private:
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;
struct ASTContextMetadata {
ASTContextMetadata(clang::ASTContext *dst_ctx)
- : m_dst_ctx(dst_ctx), m_minions(), m_origins(), m_namespace_maps(),
+ : m_dst_ctx(dst_ctx), m_delegates(), m_origins(), m_namespace_maps(),
m_map_completer(nullptr) {}
clang::ASTContext *m_dst_ctx;
- MinionMap m_minions;
+ DelegateMap m_delegates;
OriginMap m_origins;
NamespaceMetaMap m_namespace_maps;
@@ -360,18 +370,20 @@ private:
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 &delegates = context_md->m_delegates;
+ DelegateMap::iterator delegate_iter = delegates.find(src_ctx);
- if (minion_iter == minions.end()) {
- MinionSP minion = MinionSP(new Minion(*this, dst_ctx, src_ctx));
- minions[src_ctx] = minion;
- return minion;
+ if (delegate_iter == delegates.end()) {
+ ImporterDelegateSP delegate =
+ ImporterDelegateSP(new ASTImporterDelegate(*this, dst_ctx, src_ctx));
+ delegates[src_ctx] = delegate;
+ return delegate;
} else {
- return minion_iter->second;
+ return delegate_iter->second;
}
}
Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=359777&r1=359776&r2=359777&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Thu May 2 03:58:33 2019
@@ -58,12 +58,12 @@ void ClangASTMetrics::DumpCounters(Log *
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 @@ CompilerType ClangASTImporter::CopyType(
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 @@ ClangASTImporter::DeportType(clang::ASTC
(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 @@ ClangASTImporter::DeportType(clang::ASTC
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 @@ clang::Decl *ClangASTImporter::DeportDec
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 @@ clang::Decl *ClangASTImporter::DeportDec
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 @@ bool ClangASTImporter::CompleteTagDecl(c
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 @@ bool ClangASTImporter::CompleteTagDeclWi
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 @@ bool ClangASTImporter::CompleteObjCInter
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 @@ bool ClangASTImporter::CompleteAndFetchC
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 @@ bool ClangASTImporter::CompleteAndFetchC
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;
@@ -812,7 +817,7 @@ void ClangASTImporter::ForgetSource(clan
if (!md)
return;
- md->m_minions.erase(src_ast);
+ md->m_delegates.erase(src_ast);
for (OriginMap::iterator iter = md->m_origins.begin();
iter != md->m_origins.end();) {
@@ -825,7 +830,8 @@ void ClangASTImporter::ForgetSource(clan
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 @@ llvm::Expected<Decl *> ClangASTImporter:
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 @@ void ClangASTImporter::Minion::InitDepor
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 @@ void ClangASTImporter::Minion::ExecuteDe
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::ImportDef
}
}
-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 @@ void ClangASTImporter::Minion::Imported(
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 @@ void ClangASTImporter::Minion::Imported(
}
}
-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());
More information about the lldb-commits
mailing list