forked from OSchip/llvm-project
[lldb][NFC] Explicitly ask for a ClangASTContext in ClangASTSource
ClangASTSource currently takes a clang::ASTContext and keeps that around, but a lot of LLDB's functionality for doing operations on a clang::ASTContext is in its ClangASTContext twin class. We currently constantly recompute the respective ClangASTContext from the clang::ASTContext while we instead could just pass and store a ClangASTContext in the ClangASTSource. This also allows us to get rid of a bunch of unreachable error checking for cases where recomputation fails for some reason.
This commit is contained in:
parent
363cbcc590
commit
bc7f1df6b6
|
@ -57,10 +57,11 @@ ClangASTSource::ClangASTSource(const lldb::TargetSP &target)
|
|||
}
|
||||
}
|
||||
|
||||
void ClangASTSource::InstallASTContext(clang::ASTContext &ast_context,
|
||||
void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context,
|
||||
clang::FileManager &file_manager,
|
||||
bool is_shared_context) {
|
||||
m_ast_context = &ast_context;
|
||||
m_ast_context = clang_ast_context.getASTContext();
|
||||
m_clang_ast_context = &clang_ast_context;
|
||||
m_file_manager = &file_manager;
|
||||
if (m_target->GetUseModernTypeLookup()) {
|
||||
// Configure the ExternalASTMerger. The merger needs to be able to import
|
||||
|
@ -69,7 +70,7 @@ void ClangASTSource::InstallASTContext(clang::ASTContext &ast_context,
|
|||
// AST contexts.
|
||||
|
||||
lldbassert(!m_merger_up);
|
||||
clang::ExternalASTMerger::ImporterTarget target = {ast_context,
|
||||
clang::ExternalASTMerger::ImporterTarget target = {*m_ast_context,
|
||||
file_manager};
|
||||
std::vector<clang::ExternalASTMerger::ImporterSource> sources;
|
||||
for (lldb::ModuleSP module_sp : m_target->GetImages().Modules()) {
|
||||
|
@ -132,7 +133,7 @@ void ClangASTSource::InstallASTContext(clang::ASTContext &ast_context,
|
|||
m_merger_up =
|
||||
std::make_unique<clang::ExternalASTMerger>(target, sources);
|
||||
} else {
|
||||
m_ast_importer_sp->InstallMapCompleter(&ast_context, *this);
|
||||
m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -775,7 +776,7 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) {
|
|||
}
|
||||
|
||||
clang::Sema *ClangASTSource::getSema() {
|
||||
return ClangASTContext::GetASTContext(m_ast_context)->getSema();
|
||||
return m_clang_ast_context->getSema();
|
||||
}
|
||||
|
||||
bool ClangASTSource::IgnoreName(const ConstString name,
|
||||
|
@ -2058,8 +2059,7 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
|
|||
// seems to be generating bad types on occasion.
|
||||
return CompilerType();
|
||||
|
||||
return CompilerType(ClangASTContext::GetASTContext(m_ast_context),
|
||||
copied_qual_type.getAsOpaquePtr());
|
||||
return CompilerType(m_clang_ast_context, copied_qual_type.getAsOpaquePtr());
|
||||
}
|
||||
|
||||
clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
|
||||
|
@ -2186,10 +2186,9 @@ clang::NamedDecl *NameSearchContext::AddGenericFunDecl() {
|
|||
ArrayRef<QualType>(), // argument types
|
||||
proto_info));
|
||||
|
||||
return AddFunDecl(
|
||||
CompilerType(ClangASTContext::GetASTContext(m_ast_source.m_ast_context),
|
||||
generic_function_type.getAsOpaquePtr()),
|
||||
true);
|
||||
return AddFunDecl(CompilerType(m_ast_source.m_clang_ast_context,
|
||||
generic_function_type.getAsOpaquePtr()),
|
||||
true);
|
||||
}
|
||||
|
||||
clang::NamedDecl *
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
}
|
||||
void MaterializeVisibleDecls(const clang::DeclContext *DC) { return; }
|
||||
|
||||
void InstallASTContext(clang::ASTContext &ast_context,
|
||||
void InstallASTContext(ClangASTContext &ast_context,
|
||||
clang::FileManager &file_manager,
|
||||
bool is_shared_context = false);
|
||||
|
||||
|
@ -408,6 +408,8 @@ protected:
|
|||
const lldb::TargetSP m_target;
|
||||
/// The AST context requests are coming in for.
|
||||
clang::ASTContext *m_ast_context;
|
||||
/// The ClangASTContext for m_ast_context.
|
||||
ClangASTContext *m_clang_ast_context;
|
||||
/// The file manager paired with the AST context.
|
||||
clang::FileManager *m_file_manager;
|
||||
/// The target's AST importer.
|
||||
|
|
|
@ -1076,12 +1076,9 @@ void ClangExpressionDeclMap::LookupLocalVarNamespace(
|
|||
if (!frame_ast)
|
||||
return;
|
||||
|
||||
ClangASTContext *map_ast = ClangASTContext::GetASTContext(m_ast_context);
|
||||
if (!map_ast)
|
||||
return;
|
||||
|
||||
clang::NamespaceDecl *namespace_decl = map_ast->GetUniqueNamespaceDeclaration(
|
||||
g_lldb_local_vars_namespace_cstr, nullptr);
|
||||
clang::NamespaceDecl *namespace_decl =
|
||||
m_clang_ast_context->GetUniqueNamespaceDeclaration(
|
||||
g_lldb_local_vars_namespace_cstr, nullptr);
|
||||
if (!namespace_decl)
|
||||
return;
|
||||
|
||||
|
@ -1724,8 +1721,7 @@ void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
|
|||
TypeFromUser user_type(scratch_ast_context->GetBasicType(eBasicTypeVoid)
|
||||
.GetPointerType()
|
||||
.GetLValueReferenceType());
|
||||
ClangASTContext *own_context = ClangASTContext::GetASTContext(m_ast_context);
|
||||
TypeFromParser parser_type(own_context->GetBasicType(eBasicTypeVoid)
|
||||
TypeFromParser parser_type(m_clang_ast_context->GetBasicType(eBasicTypeVoid)
|
||||
.GetPointerType()
|
||||
.GetLValueReferenceType());
|
||||
NamedDecl *var_decl = context.AddVarDecl(parser_type);
|
||||
|
@ -2003,9 +1999,8 @@ void ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
|
|||
|
||||
if (copied_clang_type.IsAggregateType() &&
|
||||
copied_clang_type.GetCompleteType()) {
|
||||
ClangASTContext *own_context =
|
||||
ClangASTContext::GetASTContext(m_ast_context);
|
||||
CompilerType void_clang_type = own_context->GetBasicType(eBasicTypeVoid);
|
||||
CompilerType void_clang_type =
|
||||
m_clang_ast_context->GetBasicType(eBasicTypeVoid);
|
||||
CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
|
||||
|
||||
CompilerType method_type = ClangASTContext::CreateFunctionType(
|
||||
|
@ -2018,12 +2013,10 @@ void ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
|
|||
const bool is_attr_used = true;
|
||||
const bool is_artificial = false;
|
||||
|
||||
CXXMethodDecl *method_decl =
|
||||
ClangASTContext::GetASTContext(m_ast_context)
|
||||
->AddMethodToCXXRecordType(
|
||||
copied_clang_type.GetOpaqueQualType(), "$__lldb_expr", nullptr,
|
||||
method_type, lldb::eAccessPublic, is_virtual, is_static,
|
||||
is_inline, is_explicit, is_attr_used, is_artificial);
|
||||
CXXMethodDecl *method_decl = m_clang_ast_context->AddMethodToCXXRecordType(
|
||||
copied_clang_type.GetOpaqueQualType(), "$__lldb_expr", nullptr,
|
||||
method_type, lldb::eAccessPublic, is_virtual, is_static, is_inline,
|
||||
is_explicit, is_attr_used, is_artificial);
|
||||
|
||||
LLDB_LOG(log,
|
||||
" CEDM::AddThisType Added function $__lldb_expr "
|
||||
|
|
|
@ -997,7 +997,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
|
|||
} else {
|
||||
ast_context.setExternalSource(ast_source);
|
||||
}
|
||||
decl_map->InstallASTContext(ast_context, m_compiler->getFileManager());
|
||||
decl_map->InstallASTContext(*m_ast_context, m_compiler->getFileManager());
|
||||
}
|
||||
|
||||
// Check that the ASTReader is properly attached to ASTContext and Sema.
|
||||
|
|
|
@ -598,7 +598,7 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
|
|||
new ClangASTSource(target->shared_from_this()));
|
||||
lldbassert(ast_sp->getFileManager());
|
||||
ast_sp->m_scratch_ast_source_up->InstallASTContext(
|
||||
*ast_sp->getASTContext(), *ast_sp->getFileManager(), true);
|
||||
*ast_sp, *ast_sp->getFileManager(), true);
|
||||
llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
|
||||
ast_sp->m_scratch_ast_source_up->CreateProxy());
|
||||
ast_sp->SetExternalSource(proxy_ast_source);
|
||||
|
|
Loading…
Reference in New Issue