Skip to content

Commit e424787

Browse files
authored
[lldb] Add templated CompilerType::GetTypeSystem (NFC) (#140424)
Add an overloaded `GetTypeSystem` to specify the expected type system subclass. Changes code from `GetTypeSystem().dyn_cast_or_null<TypeSystemClang>()` to `GetTypeSystem<TypeSystemClang>()`.
1 parent 77c8d21 commit e424787

File tree

13 files changed

+36
-50
lines changed

13 files changed

+36
-50
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ class CompilerType {
276276
/// TypeSystem::TypeSystemSPWrapper can be compared for equality.
277277
TypeSystemSPWrapper GetTypeSystem() const;
278278

279+
template <typename TypeSystemType>
280+
std::shared_ptr<TypeSystemType> GetTypeSystem() const {
281+
return GetTypeSystem().dyn_cast_or_null<TypeSystemType>();
282+
}
283+
279284
ConstString GetTypeName(bool BaseOnly = false) const;
280285

281286
ConstString GetDisplayTypeName() const;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CompilerType ClangASTImporter::CopyType(TypeSystemClang &dst_ast,
3737
const CompilerType &src_type) {
3838
clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
3939

40-
auto src_ast = src_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
40+
auto src_ast = src_type.GetTypeSystem<TypeSystemClang>();
4141
if (!src_ast)
4242
return CompilerType();
4343

@@ -307,7 +307,7 @@ CompilerType ClangASTImporter::DeportType(TypeSystemClang &dst,
307307
const CompilerType &src_type) {
308308
Log *log = GetLog(LLDBLog::Expressions);
309309

310-
auto src_ctxt = src_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
310+
auto src_ctxt = src_type.GetTypeSystem<TypeSystemClang>();
311311
if (!src_ctxt)
312312
return {};
313313

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,8 +1477,7 @@ ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *de
14771477
}
14781478

14791479
CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
1480-
auto ts = src_type.GetTypeSystem();
1481-
auto src_ast = ts.dyn_cast_or_null<TypeSystemClang>();
1480+
auto src_ast = src_type.GetTypeSystem<TypeSystemClang>();
14821481
if (!src_ast)
14831482
return {};
14841483

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
219219
bool is_result,
220220
bool is_lvalue) {
221221
assert(m_parser_vars.get());
222-
auto ast = parser_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
222+
auto ast = parser_type.GetTypeSystem<TypeSystemClang>();
223223
if (ast == nullptr)
224224
return false;
225225

@@ -1486,8 +1486,8 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP &var,
14861486
return false;
14871487
}
14881488

1489-
auto ts = var_type->GetForwardCompilerType().GetTypeSystem();
1490-
auto clang_ast = ts.dyn_cast_or_null<TypeSystemClang>();
1489+
auto clang_ast =
1490+
var_type->GetForwardCompilerType().GetTypeSystem<TypeSystemClang>();
14911491

14921492
if (!clang_ast) {
14931493
LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
@@ -1606,8 +1606,7 @@ void ClangExpressionDeclMap::AddOneVariable(
16061606

16071607
TypeFromUser user_type = valobj->GetCompilerType();
16081608

1609-
auto clang_ast =
1610-
user_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1609+
auto clang_ast = user_type.GetTypeSystem<TypeSystemClang>();
16111610

16121611
if (!clang_ast) {
16131612
LLDB_LOG(log, "Skipped a definition because it has no Clang AST");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool ClangUtil::IsClangType(const CompilerType &ct) {
1919
if (!ct)
2020
return false;
2121

22-
if (!ct.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>())
22+
if (!ct.GetTypeSystem<TypeSystemClang>())
2323
return false;
2424

2525
if (!ct.GetOpaqueQualType())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
1919
if (!type.IsValid())
2020
return nullptr;
2121

22-
auto lldb_ast = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
22+
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
2323
if (!lldb_ast)
2424
return nullptr;
2525

@@ -45,7 +45,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
4545
if (m_function_types.count(type))
4646
return nullptr;
4747

48-
auto lldb_ast = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
48+
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
4949
if (!lldb_ast)
5050
return nullptr;
5151

lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
5050
return;
5151
}
5252

53-
auto ts = block_pointer_type.GetTypeSystem();
54-
auto clang_ast_context = ts.dyn_cast_or_null<TypeSystemClang>();
53+
auto clang_ast_context =
54+
block_pointer_type.GetTypeSystem<TypeSystemClang>();
5555
if (!clang_ast_context)
5656
return;
5757

lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
141141
if (frame_ptr_addr == 0 || frame_ptr_addr == LLDB_INVALID_ADDRESS)
142142
return lldb::ChildCacheState::eRefetch;
143143

144-
auto ts = valobj_sp->GetCompilerType().GetTypeSystem();
145-
auto ast_ctx = ts.dyn_cast_or_null<TypeSystemClang>();
144+
auto ast_ctx = valobj_sp->GetCompilerType().GetTypeSystem<TypeSystemClang>();
146145
if (!ast_ctx)
147146
return lldb::ChildCacheState::eRefetch;
148147

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,7 @@ void DWARFASTParserClang::ParseInheritance(
15311531
const lldb::ModuleSP &module_sp,
15321532
std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
15331533
ClangASTImporter::LayoutInfo &layout_info) {
1534-
auto ast =
1535-
class_clang_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1534+
auto ast = class_clang_type.GetTypeSystem<TypeSystemClang>();
15361535
if (ast == nullptr)
15371536
return;
15381537

@@ -2823,7 +2822,7 @@ llvm::Expected<llvm::APInt> DWARFASTParserClang::ExtractIntFromFormValue(
28232822
const CompilerType &int_type, const DWARFFormValue &form_value) const {
28242823
clang::QualType qt = ClangUtil::GetQualType(int_type);
28252824
assert(qt->isIntegralOrEnumerationType());
2826-
auto ts_ptr = int_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
2825+
auto ts_ptr = int_type.GetTypeSystem<TypeSystemClang>();
28272826
if (!ts_ptr)
28282827
return llvm::createStringError(llvm::inconvertibleErrorCode(),
28292828
"TypeSystem not clang");
@@ -3131,8 +3130,7 @@ bool DWARFASTParserClang::ParseChildMembers(
31313130
FieldInfo last_field_info;
31323131

31333132
ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
3134-
auto ts = class_clang_type.GetTypeSystem();
3135-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
3133+
auto ast = class_clang_type.GetTypeSystem<TypeSystemClang>();
31363134
if (ast == nullptr)
31373135
return false;
31383136

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,7 @@ bool SymbolFileDWARF::HasForwardDeclForCompilerType(
15381538
compiler_type_no_qualifiers.GetOpaqueQualType())) {
15391539
return true;
15401540
}
1541-
auto type_system = compiler_type.GetTypeSystem();
1542-
auto clang_type_system = type_system.dyn_cast_or_null<TypeSystemClang>();
1541+
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
15431542
if (!clang_type_system)
15441543
return false;
15451544
DWARFASTParserClang *ast_parser =
@@ -1549,8 +1548,7 @@ bool SymbolFileDWARF::HasForwardDeclForCompilerType(
15491548

15501549
bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
15511550
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1552-
auto clang_type_system =
1553-
compiler_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1551+
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
15541552
if (clang_type_system) {
15551553
DWARFASTParserClang *ast_parser =
15561554
static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,8 +2141,7 @@ SymbolFileNativePDB::GetDynamicArrayInfoForUID(
21412141

21422142
bool SymbolFileNativePDB::CompleteType(CompilerType &compiler_type) {
21432143
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2144-
auto ts = compiler_type.GetTypeSystem();
2145-
auto clang_type_system = ts.dyn_cast_or_null<TypeSystemClang>();
2144+
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
21462145
if (!clang_type_system)
21472146
return false;
21482147

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ CompilerType TypeSystemClang::GetCStringType(bool is_const) {
11351135

11361136
bool TypeSystemClang::AreTypesSame(CompilerType type1, CompilerType type2,
11371137
bool ignore_qualifiers) {
1138-
auto ast = type1.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1138+
auto ast = type1.GetTypeSystem<TypeSystemClang>();
11391139
if (!ast || type1.GetTypeSystem() != type2.GetTypeSystem())
11401140
return false;
11411141

@@ -7333,8 +7333,7 @@ clang::FieldDecl *TypeSystemClang::AddFieldToRecordType(
73337333
uint32_t bitfield_bit_size) {
73347334
if (!type.IsValid() || !field_clang_type.IsValid())
73357335
return nullptr;
7336-
auto ts = type.GetTypeSystem();
7337-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7336+
auto ast = type.GetTypeSystem<TypeSystemClang>();
73387337
if (!ast)
73397338
return nullptr;
73407339
clang::ASTContext &clang_ast = ast->getASTContext();
@@ -7437,8 +7436,7 @@ void TypeSystemClang::BuildIndirectFields(const CompilerType &type) {
74377436
if (!type)
74387437
return;
74397438

7440-
auto ts = type.GetTypeSystem();
7441-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7439+
auto ast = type.GetTypeSystem<TypeSystemClang>();
74427440
if (!ast)
74437441
return;
74447442

@@ -7544,8 +7542,7 @@ void TypeSystemClang::BuildIndirectFields(const CompilerType &type) {
75447542

75457543
void TypeSystemClang::SetIsPacked(const CompilerType &type) {
75467544
if (type) {
7547-
auto ts = type.GetTypeSystem();
7548-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7545+
auto ast = type.GetTypeSystem<TypeSystemClang>();
75497546
if (ast) {
75507547
clang::RecordDecl *record_decl = GetAsRecordDecl(type);
75517548

@@ -7564,8 +7561,7 @@ clang::VarDecl *TypeSystemClang::AddVariableToRecordType(
75647561
if (!type.IsValid() || !var_type.IsValid())
75657562
return nullptr;
75667563

7567-
auto ts = type.GetTypeSystem();
7568-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7564+
auto ast = type.GetTypeSystem<TypeSystemClang>();
75697565
if (!ast)
75707566
return nullptr;
75717567

@@ -7890,8 +7886,7 @@ bool TypeSystemClang::TransferBaseClasses(
78907886

78917887
bool TypeSystemClang::SetObjCSuperClass(
78927888
const CompilerType &type, const CompilerType &superclass_clang_type) {
7893-
auto ts = type.GetTypeSystem();
7894-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7889+
auto ast = type.GetTypeSystem<TypeSystemClang>();
78957890
if (!ast)
78967891
return false;
78977892
clang::ASTContext &clang_ast = ast->getASTContext();
@@ -7919,8 +7914,7 @@ bool TypeSystemClang::AddObjCClassProperty(
79197914
if (!type || !property_clang_type.IsValid() || property_name == nullptr ||
79207915
property_name[0] == '\0')
79217916
return false;
7922-
auto ts = type.GetTypeSystem();
7923-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
7917+
auto ast = type.GetTypeSystem<TypeSystemClang>();
79247918
if (!ast)
79257919
return false;
79267920
clang::ASTContext &clang_ast = ast->getASTContext();
@@ -8139,8 +8133,7 @@ clang::ObjCMethodDecl *TypeSystemClang::AddMethodToObjCObjectType(
81398133

81408134
if (class_interface_decl == nullptr)
81418135
return nullptr;
8142-
auto ts = type.GetTypeSystem();
8143-
auto lldb_ast = ts.dyn_cast_or_null<TypeSystemClang>();
8136+
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
81448137
if (lldb_ast == nullptr)
81458138
return nullptr;
81468139
clang::ASTContext &ast = lldb_ast->getASTContext();
@@ -8344,8 +8337,7 @@ bool TypeSystemClang::CompleteTagDeclarationDefinition(
83448337
if (qual_type.isNull())
83458338
return false;
83468339

8347-
auto ts = type.GetTypeSystem();
8348-
auto lldb_ast = ts.dyn_cast_or_null<TypeSystemClang>();
8340+
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
83498341
if (lldb_ast == nullptr)
83508342
return false;
83518343

@@ -8489,8 +8481,7 @@ TypeSystemClang::CreateMemberPointerType(const CompilerType &type,
84898481
const CompilerType &pointee_type) {
84908482
if (type && pointee_type.IsValid() &&
84918483
type.GetTypeSystem() == pointee_type.GetTypeSystem()) {
8492-
auto ts = type.GetTypeSystem();
8493-
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
8484+
auto ast = type.GetTypeSystem<TypeSystemClang>();
84948485
if (!ast)
84958486
return CompilerType();
84968487
return ast->GetType(ast->getASTContext().getMemberPointerType(
@@ -9554,7 +9545,7 @@ void TypeSystemClang::RequireCompleteType(CompilerType type) {
95549545
lldbassert(started && "Unable to start a class type definition.");
95559546
TypeSystemClang::CompleteTagDeclarationDefinition(type);
95569547
const clang::TagDecl *td = ClangUtil::GetAsTagDecl(type);
9557-
auto ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
9548+
auto ts = type.GetTypeSystem<TypeSystemClang>();
95589549
if (ts)
95599550
ts->SetDeclIsForcefullyCompleted(td);
95609551
}

lldb/unittests/ValueObject/DynamicValueObjectLocalBuffer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ struct MockLanguageRuntime : public LanguageRuntime {
5858
TypeAndOrName &class_type_or_name, Address &address,
5959
Value::ValueType &value_type,
6060
llvm::ArrayRef<uint8_t> &local_buffer) override {
61-
auto ast = in_value.GetCompilerType()
62-
.GetTypeSystem()
63-
.dyn_cast_or_null<TypeSystemClang>();
61+
auto ast = in_value.GetCompilerType().GetTypeSystem<TypeSystemClang>();
6462

6563
auto int_type = createRecordWithField(
6664
*ast, "TypeWitInt", ast->GetBasicType(lldb::BasicType::eBasicTypeInt),

0 commit comments

Comments
 (0)