[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.
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 4966ac1..b335475 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1076,12 +1076,9 @@
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 @@
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 @@
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 @@
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 "