[lldb][NFC] Simplify ClangASTContext::GetBasicTypes
static convenience methods that do the clang::ASTContext -> ClangASTContext
conversion and handle errors by simply ignoring them are not a good idea.
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index bbc0312..f8e448ff 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1724,17 +1724,15 @@
if (target == nullptr)
return;
- ASTContext *scratch_ast_context =
- target->GetScratchClangASTContext()->getASTContext();
+ ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext();
- TypeFromUser user_type(
- ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid)
- .GetPointerType()
- .GetLValueReferenceType());
- TypeFromParser parser_type(
- ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid)
- .GetPointerType()
- .GetLValueReferenceType());
+ 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)
+ .GetPointerType()
+ .GetLValueReferenceType());
NamedDecl *var_decl = context.AddVarDecl(parser_type);
std::string decl_name(context.m_decl_name.getAsString());
@@ -2024,8 +2022,9 @@
if (copied_clang_type.IsAggregateType() &&
copied_clang_type.GetCompleteType()) {
- CompilerType void_clang_type =
- ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid);
+ ClangASTContext *own_context =
+ ClangASTContext::GetASTContext(m_ast_context);
+ CompilerType void_clang_type = own_context->GetBasicType(eBasicTypeVoid);
CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
CompilerType method_type = ClangASTContext::CreateFunctionType(
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index fbf5bd4..bee72b2 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -987,13 +987,9 @@
return eBasicTypeInvalid;
}
-CompilerType ClangASTContext::GetBasicType(ASTContext *ast,
- ConstString name) {
- if (ast) {
- lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name);
- return ClangASTContext::GetBasicType(ast, basic_type);
- }
- return CompilerType();
+CompilerType ClangASTContext::GetBasicType(ConstString name) {
+ lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name);
+ return GetBasicType(basic_type);
}
uint32_t ClangASTContext::GetPointerByteSize() {
@@ -1006,13 +1002,8 @@
}
CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) {
- return GetBasicType(getASTContext(), basic_type);
-}
+ clang::ASTContext *ast = getASTContext();
-CompilerType ClangASTContext::GetBasicType(ASTContext *ast,
- lldb::BasicType basic_type) {
- if (!ast)
- return CompilerType();
lldb::opaque_compiler_type_t clang_type =
GetOpaqueCompilerType(ast, basic_type);
@@ -4907,7 +4898,7 @@
// Create related types using the current type's AST
CompilerType ClangASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) {
- return ClangASTContext::GetBasicType(getASTContext(), basic_type);
+ return ClangASTContext::GetBasicType(basic_type);
}
// Exploring the type