Skip to content

Commit c502bae

Browse files
committed
[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.
1 parent 82800df commit c502bae

File tree

4 files changed

+19
-34
lines changed

4 files changed

+19
-34
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ class ClangASTContext : public TypeSystem {
153153

154154
CompilerType GetBasicType(lldb::BasicType type);
155155

156-
static CompilerType GetBasicType(clang::ASTContext *ast,
157-
lldb::BasicType type);
158-
159-
static CompilerType GetBasicType(clang::ASTContext *ast,
160-
ConstString name);
156+
CompilerType GetBasicType(ConstString name);
161157

162158
static lldb::BasicType GetBasicTypeEnumeration(ConstString name);
163159

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,17 +1724,15 @@ void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
17241724
if (target == nullptr)
17251725
return;
17261726

1727-
ASTContext *scratch_ast_context =
1728-
target->GetScratchClangASTContext()->getASTContext();
1729-
1730-
TypeFromUser user_type(
1731-
ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid)
1732-
.GetPointerType()
1733-
.GetLValueReferenceType());
1734-
TypeFromParser parser_type(
1735-
ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid)
1736-
.GetPointerType()
1737-
.GetLValueReferenceType());
1727+
ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext();
1728+
1729+
TypeFromUser user_type(scratch_ast_context->GetBasicType(eBasicTypeVoid)
1730+
.GetPointerType()
1731+
.GetLValueReferenceType());
1732+
ClangASTContext *own_context = ClangASTContext::GetASTContext(m_ast_context);
1733+
TypeFromParser parser_type(own_context->GetBasicType(eBasicTypeVoid)
1734+
.GetPointerType()
1735+
.GetLValueReferenceType());
17381736
NamedDecl *var_decl = context.AddVarDecl(parser_type);
17391737

17401738
std::string decl_name(context.m_decl_name.getAsString());
@@ -2024,8 +2022,9 @@ void ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
20242022

20252023
if (copied_clang_type.IsAggregateType() &&
20262024
copied_clang_type.GetCompleteType()) {
2027-
CompilerType void_clang_type =
2028-
ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid);
2025+
ClangASTContext *own_context =
2026+
ClangASTContext::GetASTContext(m_ast_context);
2027+
CompilerType void_clang_type = own_context->GetBasicType(eBasicTypeVoid);
20292028
CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
20302029

20312030
CompilerType method_type = ClangASTContext::CreateFunctionType(

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,9 @@ ClangASTContext::GetBasicTypeEnumeration(ConstString name) {
987987
return eBasicTypeInvalid;
988988
}
989989

990-
CompilerType ClangASTContext::GetBasicType(ASTContext *ast,
991-
ConstString name) {
992-
if (ast) {
993-
lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name);
994-
return ClangASTContext::GetBasicType(ast, basic_type);
995-
}
996-
return CompilerType();
990+
CompilerType ClangASTContext::GetBasicType(ConstString name) {
991+
lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name);
992+
return GetBasicType(basic_type);
997993
}
998994

999995
uint32_t ClangASTContext::GetPointerByteSize() {
@@ -1006,13 +1002,8 @@ uint32_t ClangASTContext::GetPointerByteSize() {
10061002
}
10071003

10081004
CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) {
1009-
return GetBasicType(getASTContext(), basic_type);
1010-
}
1005+
clang::ASTContext *ast = getASTContext();
10111006

1012-
CompilerType ClangASTContext::GetBasicType(ASTContext *ast,
1013-
lldb::BasicType basic_type) {
1014-
if (!ast)
1015-
return CompilerType();
10161007
lldb::opaque_compiler_type_t clang_type =
10171008
GetOpaqueCompilerType(ast, basic_type);
10181009

@@ -4907,7 +4898,7 @@ ClangASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) {
49074898
// Create related types using the current type's AST
49084899

49094900
CompilerType ClangASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) {
4910-
return ClangASTContext::GetBasicType(getASTContext(), basic_type);
4901+
return ClangASTContext::GetBasicType(basic_type);
49114902
}
49124903
// Exploring the type
49134904

lldb/unittests/Symbol/TestClangASTContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ TEST_F(TestClangASTContext, TestUnifyAccessSpecifiers) {
317317
}
318318

319319
TEST_F(TestClangASTContext, TestRecordHasFields) {
320-
CompilerType int_type =
321-
ClangASTContext::GetBasicType(m_ast->getASTContext(), eBasicTypeInt);
320+
CompilerType int_type = m_ast->GetBasicType(eBasicTypeInt);
322321

323322
// Test that a record with no fields returns false
324323
CompilerType empty_base = m_ast->CreateRecordType(

0 commit comments

Comments
 (0)