diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -1147,6 +1147,9 @@ const clang::ClassTemplateSpecializationDecl * GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type); + bool IsTypeImpl(lldb::opaque_compiler_type_t type, + llvm::function_ref predicate) const; + // Classes that inherit from TypeSystemClang can see and modify these std::string m_target_triple; std::unique_ptr m_ast_up; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3050,28 +3050,11 @@ } bool TypeSystemClang::IsFunctionType(lldb::opaque_compiler_type_t type) { - if (type) { - clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type)); - - if (qual_type->isFunctionType()) { - return true; - } + auto isFunctionType = [&](clang::QualType qual_type) { + return qual_type->isFunctionType(); + }; - const clang::Type::TypeClass type_class = qual_type->getTypeClass(); - switch (type_class) { - default: - break; - case clang::Type::LValueReference: - case clang::Type::RValueReference: { - const clang::ReferenceType *reference_type = - llvm::cast(qual_type.getTypePtr()); - if (reference_type) - return IsFunctionType( - reference_type->getPointeeType().getAsOpaquePtr()); - } break; - } - } - return false; + return IsTypeImpl(type, isFunctionType); } // Used to detect "Homogeneous Floating-point Aggregates" @@ -3185,11 +3168,13 @@ return CompilerType(); } -bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { +bool TypeSystemClang::IsTypeImpl( + lldb::opaque_compiler_type_t type, + llvm::function_ref predicate) const { if (type) { clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type)); - if (qual_type->isFunctionPointerType()) + if (predicate(qual_type)) return true; const clang::Type::TypeClass type_class = qual_type->getTypeClass(); @@ -3202,20 +3187,25 @@ const clang::ReferenceType *reference_type = llvm::cast(qual_type.getTypePtr()); if (reference_type) - return IsFunctionPointerType( - reference_type->getPointeeType().getAsOpaquePtr()); + return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate); } break; } } return false; } +bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { + auto isFunctionPointerType = [](clang::QualType qual_type) { + return qual_type->isFunctionPointerType(); + }; + + return IsTypeImpl(type, isFunctionPointerType); +} + bool TypeSystemClang::IsBlockPointerType( lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) { - if (type) { - clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type)); - + auto isBlockPointerType = [&](clang::QualType qual_type) { if (qual_type->isBlockPointerType()) { if (function_pointer_type_ptr) { const clang::BlockPointerType *block_pointer_type = @@ -3228,23 +3218,10 @@ return true; } - const clang::Type::TypeClass type_class = qual_type->getTypeClass(); - switch (type_class) { - default: - break; + return false; + }; - case clang::Type::LValueReference: - case clang::Type::RValueReference: { - const clang::ReferenceType *reference_type = - llvm::cast(qual_type.getTypePtr()); - if (reference_type) - return IsBlockPointerType( - reference_type->getPointeeType().getAsOpaquePtr(), - function_pointer_type_ptr); - } break; - } - } - return false; + return IsTypeImpl(type, isBlockPointerType); } bool TypeSystemClang::IsIntegerType(lldb::opaque_compiler_type_t type,