[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>()`.
This commit is contained in:
@@ -276,6 +276,11 @@ public:
|
||||
/// TypeSystem::TypeSystemSPWrapper can be compared for equality.
|
||||
TypeSystemSPWrapper GetTypeSystem() const;
|
||||
|
||||
template <typename TypeSystemType>
|
||||
std::shared_ptr<TypeSystemType> GetTypeSystem() const {
|
||||
return GetTypeSystem().dyn_cast_or_null<TypeSystemType>();
|
||||
}
|
||||
|
||||
ConstString GetTypeName(bool BaseOnly = false) const;
|
||||
|
||||
ConstString GetDisplayTypeName() const;
|
||||
|
||||
@@ -37,7 +37,7 @@ CompilerType ClangASTImporter::CopyType(TypeSystemClang &dst_ast,
|
||||
const CompilerType &src_type) {
|
||||
clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
|
||||
|
||||
auto src_ast = src_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto src_ast = src_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!src_ast)
|
||||
return CompilerType();
|
||||
|
||||
@@ -307,7 +307,7 @@ CompilerType ClangASTImporter::DeportType(TypeSystemClang &dst,
|
||||
const CompilerType &src_type) {
|
||||
Log *log = GetLog(LLDBLog::Expressions);
|
||||
|
||||
auto src_ctxt = src_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto src_ctxt = src_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!src_ctxt)
|
||||
return {};
|
||||
|
||||
|
||||
@@ -1477,8 +1477,7 @@ ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *de
|
||||
}
|
||||
|
||||
CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
|
||||
auto ts = src_type.GetTypeSystem();
|
||||
auto src_ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto src_ast = src_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!src_ast)
|
||||
return {};
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
|
||||
bool is_result,
|
||||
bool is_lvalue) {
|
||||
assert(m_parser_vars.get());
|
||||
auto ast = parser_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = parser_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (ast == nullptr)
|
||||
return false;
|
||||
|
||||
@@ -1486,8 +1486,8 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP &var,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ts = var_type->GetForwardCompilerType().GetTypeSystem();
|
||||
auto clang_ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_ast =
|
||||
var_type->GetForwardCompilerType().GetTypeSystem<TypeSystemClang>();
|
||||
|
||||
if (!clang_ast) {
|
||||
LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
|
||||
@@ -1606,8 +1606,7 @@ void ClangExpressionDeclMap::AddOneVariable(
|
||||
|
||||
TypeFromUser user_type = valobj->GetCompilerType();
|
||||
|
||||
auto clang_ast =
|
||||
user_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_ast = user_type.GetTypeSystem<TypeSystemClang>();
|
||||
|
||||
if (!clang_ast) {
|
||||
LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
|
||||
|
||||
@@ -19,7 +19,7 @@ bool ClangUtil::IsClangType(const CompilerType &ct) {
|
||||
if (!ct)
|
||||
return false;
|
||||
|
||||
if (!ct.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>())
|
||||
if (!ct.GetTypeSystem<TypeSystemClang>())
|
||||
return false;
|
||||
|
||||
if (!ct.GetOpaqueQualType())
|
||||
|
||||
@@ -19,7 +19,7 @@ clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
|
||||
if (!type.IsValid())
|
||||
return nullptr;
|
||||
|
||||
auto lldb_ast = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!lldb_ast)
|
||||
return nullptr;
|
||||
|
||||
@@ -45,7 +45,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
|
||||
if (m_function_types.count(type))
|
||||
return nullptr;
|
||||
|
||||
auto lldb_ast = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!lldb_ast)
|
||||
return nullptr;
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
auto ts = block_pointer_type.GetTypeSystem();
|
||||
auto clang_ast_context = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_ast_context =
|
||||
block_pointer_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!clang_ast_context)
|
||||
return;
|
||||
|
||||
|
||||
@@ -141,8 +141,7 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
|
||||
if (frame_ptr_addr == 0 || frame_ptr_addr == LLDB_INVALID_ADDRESS)
|
||||
return lldb::ChildCacheState::eRefetch;
|
||||
|
||||
auto ts = valobj_sp->GetCompilerType().GetTypeSystem();
|
||||
auto ast_ctx = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast_ctx = valobj_sp->GetCompilerType().GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast_ctx)
|
||||
return lldb::ChildCacheState::eRefetch;
|
||||
|
||||
|
||||
@@ -1531,8 +1531,7 @@ void DWARFASTParserClang::ParseInheritance(
|
||||
const lldb::ModuleSP &module_sp,
|
||||
std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
|
||||
ClangASTImporter::LayoutInfo &layout_info) {
|
||||
auto ast =
|
||||
class_clang_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = class_clang_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (ast == nullptr)
|
||||
return;
|
||||
|
||||
@@ -2823,7 +2822,7 @@ llvm::Expected<llvm::APInt> DWARFASTParserClang::ExtractIntFromFormValue(
|
||||
const CompilerType &int_type, const DWARFFormValue &form_value) const {
|
||||
clang::QualType qt = ClangUtil::GetQualType(int_type);
|
||||
assert(qt->isIntegralOrEnumerationType());
|
||||
auto ts_ptr = int_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ts_ptr = int_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ts_ptr)
|
||||
return llvm::createStringError(llvm::inconvertibleErrorCode(),
|
||||
"TypeSystem not clang");
|
||||
@@ -3131,8 +3130,7 @@ bool DWARFASTParserClang::ParseChildMembers(
|
||||
FieldInfo last_field_info;
|
||||
|
||||
ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
|
||||
auto ts = class_clang_type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = class_clang_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (ast == nullptr)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1538,8 +1538,7 @@ bool SymbolFileDWARF::HasForwardDeclForCompilerType(
|
||||
compiler_type_no_qualifiers.GetOpaqueQualType())) {
|
||||
return true;
|
||||
}
|
||||
auto type_system = compiler_type.GetTypeSystem();
|
||||
auto clang_type_system = type_system.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!clang_type_system)
|
||||
return false;
|
||||
DWARFASTParserClang *ast_parser =
|
||||
@@ -1549,8 +1548,7 @@ bool SymbolFileDWARF::HasForwardDeclForCompilerType(
|
||||
|
||||
bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
|
||||
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
|
||||
auto clang_type_system =
|
||||
compiler_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (clang_type_system) {
|
||||
DWARFASTParserClang *ast_parser =
|
||||
static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
|
||||
|
||||
@@ -2141,8 +2141,7 @@ SymbolFileNativePDB::GetDynamicArrayInfoForUID(
|
||||
|
||||
bool SymbolFileNativePDB::CompleteType(CompilerType &compiler_type) {
|
||||
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
|
||||
auto ts = compiler_type.GetTypeSystem();
|
||||
auto clang_type_system = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!clang_type_system)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1135,7 +1135,7 @@ CompilerType TypeSystemClang::GetCStringType(bool is_const) {
|
||||
|
||||
bool TypeSystemClang::AreTypesSame(CompilerType type1, CompilerType type2,
|
||||
bool ignore_qualifiers) {
|
||||
auto ast = type1.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type1.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast || type1.GetTypeSystem() != type2.GetTypeSystem())
|
||||
return false;
|
||||
|
||||
@@ -7333,8 +7333,7 @@ clang::FieldDecl *TypeSystemClang::AddFieldToRecordType(
|
||||
uint32_t bitfield_bit_size) {
|
||||
if (!type.IsValid() || !field_clang_type.IsValid())
|
||||
return nullptr;
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return nullptr;
|
||||
clang::ASTContext &clang_ast = ast->getASTContext();
|
||||
@@ -7437,8 +7436,7 @@ void TypeSystemClang::BuildIndirectFields(const CompilerType &type) {
|
||||
if (!type)
|
||||
return;
|
||||
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return;
|
||||
|
||||
@@ -7544,8 +7542,7 @@ void TypeSystemClang::BuildIndirectFields(const CompilerType &type) {
|
||||
|
||||
void TypeSystemClang::SetIsPacked(const CompilerType &type) {
|
||||
if (type) {
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (ast) {
|
||||
clang::RecordDecl *record_decl = GetAsRecordDecl(type);
|
||||
|
||||
@@ -7564,8 +7561,7 @@ clang::VarDecl *TypeSystemClang::AddVariableToRecordType(
|
||||
if (!type.IsValid() || !var_type.IsValid())
|
||||
return nullptr;
|
||||
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return nullptr;
|
||||
|
||||
@@ -7890,8 +7886,7 @@ bool TypeSystemClang::TransferBaseClasses(
|
||||
|
||||
bool TypeSystemClang::SetObjCSuperClass(
|
||||
const CompilerType &type, const CompilerType &superclass_clang_type) {
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return false;
|
||||
clang::ASTContext &clang_ast = ast->getASTContext();
|
||||
@@ -7919,8 +7914,7 @@ bool TypeSystemClang::AddObjCClassProperty(
|
||||
if (!type || !property_clang_type.IsValid() || property_name == nullptr ||
|
||||
property_name[0] == '\0')
|
||||
return false;
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return false;
|
||||
clang::ASTContext &clang_ast = ast->getASTContext();
|
||||
@@ -8139,8 +8133,7 @@ clang::ObjCMethodDecl *TypeSystemClang::AddMethodToObjCObjectType(
|
||||
|
||||
if (class_interface_decl == nullptr)
|
||||
return nullptr;
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto lldb_ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (lldb_ast == nullptr)
|
||||
return nullptr;
|
||||
clang::ASTContext &ast = lldb_ast->getASTContext();
|
||||
@@ -8344,8 +8337,7 @@ bool TypeSystemClang::CompleteTagDeclarationDefinition(
|
||||
if (qual_type.isNull())
|
||||
return false;
|
||||
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto lldb_ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto lldb_ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (lldb_ast == nullptr)
|
||||
return false;
|
||||
|
||||
@@ -8489,8 +8481,7 @@ TypeSystemClang::CreateMemberPointerType(const CompilerType &type,
|
||||
const CompilerType &pointee_type) {
|
||||
if (type && pointee_type.IsValid() &&
|
||||
type.GetTypeSystem() == pointee_type.GetTypeSystem()) {
|
||||
auto ts = type.GetTypeSystem();
|
||||
auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (!ast)
|
||||
return CompilerType();
|
||||
return ast->GetType(ast->getASTContext().getMemberPointerType(
|
||||
@@ -9554,7 +9545,7 @@ void TypeSystemClang::RequireCompleteType(CompilerType type) {
|
||||
lldbassert(started && "Unable to start a class type definition.");
|
||||
TypeSystemClang::CompleteTagDeclarationDefinition(type);
|
||||
const clang::TagDecl *td = ClangUtil::GetAsTagDecl(type);
|
||||
auto ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ts = type.GetTypeSystem<TypeSystemClang>();
|
||||
if (ts)
|
||||
ts->SetDeclIsForcefullyCompleted(td);
|
||||
}
|
||||
|
||||
@@ -58,9 +58,7 @@ struct MockLanguageRuntime : public LanguageRuntime {
|
||||
TypeAndOrName &class_type_or_name, Address &address,
|
||||
Value::ValueType &value_type,
|
||||
llvm::ArrayRef<uint8_t> &local_buffer) override {
|
||||
auto ast = in_value.GetCompilerType()
|
||||
.GetTypeSystem()
|
||||
.dyn_cast_or_null<TypeSystemClang>();
|
||||
auto ast = in_value.GetCompilerType().GetTypeSystem<TypeSystemClang>();
|
||||
|
||||
auto int_type = createRecordWithField(
|
||||
*ast, "TypeWitInt", ast->GetBasicType(lldb::BasicType::eBasicTypeInt),
|
||||
|
||||
Reference in New Issue
Block a user