diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index b765dfb3df36..8c5b0cae34b7 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -2466,12 +2466,34 @@ ClangASTContext::GetDeclContextForType(const CompilerType &type) { return GetDeclContextForType(ClangUtil::GetQualType(type)); } +/// Aggressively desugar the provided type, skipping past various kinds of +/// syntactic sugar and other constructs one typically wants to ignore. +/// The \p mask argument allows one to skip certain kinds of simplifications, +/// when one wishes to handle a certain kind of type directly. +static QualType Desugar(QualType type, + ArrayRef mask = {}) { + while (true) { + if (find(mask, type->getTypeClass()) != mask.end()) + return type; + switch (type->getTypeClass()) { + case clang::Type::Auto: + case clang::Type::Elaborated: + case clang::Type::Paren: + case clang::Type::Typedef: + type = type->getLocallyUnqualifiedSingleStepDesugaredType(); + break; + default: + return type; + } + } +} + clang::DeclContext * ClangASTContext::GetDeclContextForType(clang::QualType type) { if (type.isNull()) return nullptr; - clang::QualType qual_type = type.getCanonicalType(); + clang::QualType qual_type = Desugar(type.getCanonicalType()); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::ObjCInterface: @@ -2485,19 +2507,6 @@ ClangASTContext::GetDeclContextForType(clang::QualType type) { return llvm::cast(qual_type)->getDecl(); case clang::Type::Enum: return llvm::cast(qual_type)->getDecl(); - case clang::Type::Typedef: - return GetDeclContextForType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType()); - case clang::Type::Auto: - return GetDeclContextForType( - llvm::cast(qual_type)->getDeducedType()); - case clang::Type::Elaborated: - return GetDeclContextForType( - llvm::cast(qual_type)->getNamedType()); - case clang::Type::Paren: - return GetDeclContextForType( - llvm::cast(qual_type)->desugar()); default: break; } @@ -2508,6 +2517,7 @@ ClangASTContext::GetDeclContextForType(clang::QualType type) { static bool GetCompleteQualType(clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true) { + qual_type = Desugar(qual_type); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::ConstantArray: @@ -2609,27 +2619,6 @@ static bool GetCompleteQualType(clang::ASTContext *ast, } } break; - case clang::Type::Typedef: - return GetCompleteQualType(ast, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType(), - allow_completion); - - case clang::Type::Auto: - return GetCompleteQualType( - ast, llvm::cast(qual_type)->getDeducedType(), - allow_completion); - - case clang::Type::Elaborated: - return GetCompleteQualType( - ast, llvm::cast(qual_type)->getNamedType(), - allow_completion); - - case clang::Type::Paren: - return GetCompleteQualType( - ast, llvm::cast(qual_type)->desugar(), - allow_completion); - case clang::Type::Attributed: return GetCompleteQualType( ast, llvm::cast(qual_type)->getModifiedType(), @@ -2662,7 +2651,7 @@ ConvertAccessTypeToObjCIvarAccessControl(AccessType access) { // Tests bool ClangASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -2675,22 +2664,6 @@ bool ClangASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { case clang::Type::ObjCObject: case clang::Type::ObjCInterface: return true; - case clang::Type::Auto: - return IsAggregateType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - case clang::Type::Elaborated: - return IsAggregateType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - case clang::Type::Typedef: - return IsAggregateType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - case clang::Type::Paren: - return IsAggregateType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); default: break; } @@ -2699,7 +2672,7 @@ bool ClangASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { } bool ClangASTContext::IsAnonymousType(lldb::opaque_compiler_type_t type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -2713,22 +2686,6 @@ bool ClangASTContext::IsAnonymousType(lldb::opaque_compiler_type_t type) { } break; } - case clang::Type::Auto: - return IsAnonymousType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - case clang::Type::Elaborated: - return IsAnonymousType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - case clang::Type::Typedef: - return IsAnonymousType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - case clang::Type::Paren: - return IsAnonymousType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); default: break; } @@ -2739,7 +2696,7 @@ bool ClangASTContext::IsAnonymousType(lldb::opaque_compiler_type_t type) { bool ClangASTContext::IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type_ptr, uint64_t *size, bool *is_incomplete) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -2795,27 +2752,6 @@ bool ClangASTContext::IsArrayType(lldb::opaque_compiler_type_t type, if (is_incomplete) *is_incomplete = false; return true; - - case clang::Type::Typedef: - return IsArrayType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - element_type_ptr, size, is_incomplete); - case clang::Type::Auto: - return IsArrayType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - element_type_ptr, size, is_incomplete); - case clang::Type::Elaborated: - return IsArrayType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - element_type_ptr, size, is_incomplete); - case clang::Type::Paren: - return IsArrayType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - element_type_ptr, size, is_incomplete); } if (element_type_ptr) element_type_ptr->Clear(); @@ -2924,7 +2860,7 @@ bool ClangASTContext::IsCStringType(lldb::opaque_compiler_type_t type, bool ClangASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); if (qual_type->isFunctionType()) { if (is_variadic_ptr) { @@ -2942,26 +2878,6 @@ bool ClangASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, switch (type_class) { default: break; - case clang::Type::Typedef: - return IsFunctionType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - nullptr); - case clang::Type::Auto: - return IsFunctionType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - nullptr); - case clang::Type::Elaborated: - return IsFunctionType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - nullptr); - case clang::Type::Paren: - return IsFunctionType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - nullptr); case clang::Type::LValueReference: case clang::Type::RValueReference: { const clang::ReferenceType *reference_type = @@ -2982,7 +2898,7 @@ ClangASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, if (!type) return 0; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -3052,24 +2968,6 @@ ClangASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, } break; - case clang::Type::Typedef: - return IsHomogeneousAggregate(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - base_type_ptr); - - case clang::Type::Auto: - return IsHomogeneousAggregate(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - base_type_ptr); - - case clang::Type::Elaborated: - return IsHomogeneousAggregate(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - base_type_ptr); default: break; } @@ -3105,7 +3003,7 @@ ClangASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, bool ClangASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); if (qual_type->isFunctionPointerType()) return true; @@ -3114,22 +3012,6 @@ bool ClangASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { switch (type_class) { default: break; - case clang::Type::Typedef: - return IsFunctionPointerType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - case clang::Type::Auto: - return IsFunctionPointerType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - case clang::Type::Elaborated: - return IsFunctionPointerType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - case clang::Type::Paren: - return IsFunctionPointerType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); case clang::Type::LValueReference: case clang::Type::RValueReference: { @@ -3148,7 +3030,7 @@ bool ClangASTContext::IsBlockPointerType( lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); if (qual_type->isBlockPointerType()) { if (function_pointer_type_ptr) { @@ -3166,26 +3048,6 @@ bool ClangASTContext::IsBlockPointerType( switch (type_class) { default: break; - case clang::Type::Typedef: - return IsBlockPointerType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - function_pointer_type_ptr); - case clang::Type::Auto: - return IsBlockPointerType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - function_pointer_type_ptr); - case clang::Type::Elaborated: - return IsBlockPointerType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - function_pointer_type_ptr); - case clang::Type::Paren: - return IsBlockPointerType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - function_pointer_type_ptr); case clang::Type::LValueReference: case clang::Type::RValueReference: { @@ -3239,7 +3101,7 @@ bool ClangASTContext::IsEnumerationType(lldb::opaque_compiler_type_t type, bool ClangASTContext::IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Builtin: @@ -3279,26 +3141,6 @@ bool ClangASTContext::IsPointerType(lldb::opaque_compiler_type_t type, ->getPointeeType() .getAsOpaquePtr()); return true; - case clang::Type::Typedef: - return IsPointerType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Auto: - return IsPointerType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Elaborated: - return IsPointerType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Paren: - return IsPointerType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - pointee_type); default: break; } @@ -3311,7 +3153,7 @@ bool ClangASTContext::IsPointerType(lldb::opaque_compiler_type_t type, bool ClangASTContext::IsPointerOrReferenceType( lldb::opaque_compiler_type_t type, CompilerType *pointee_type) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Builtin: @@ -3364,27 +3206,6 @@ bool ClangASTContext::IsPointerOrReferenceType( ->desugar() .getAsOpaquePtr()); return true; - case clang::Type::Typedef: - return IsPointerOrReferenceType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Auto: - return IsPointerOrReferenceType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Elaborated: - return IsPointerOrReferenceType( - llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - pointee_type); - case clang::Type::Paren: - return IsPointerOrReferenceType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - pointee_type); default: break; } @@ -3398,7 +3219,7 @@ bool ClangASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) { if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -3420,26 +3241,6 @@ bool ClangASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, if (is_rvalue) *is_rvalue = true; return true; - case clang::Type::Typedef: - return IsReferenceType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - pointee_type, is_rvalue); - case clang::Type::Auto: - return IsReferenceType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - pointee_type, is_rvalue); - case clang::Type::Elaborated: - return IsReferenceType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - pointee_type, is_rvalue); - case clang::Type::Paren: - return IsReferenceType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - pointee_type, is_rvalue); default: break; @@ -3581,7 +3382,7 @@ bool ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, bool check_objc) { clang::QualType pointee_qual_type; if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); bool success = false; const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -3628,32 +3429,6 @@ bool ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, success = true; break; - case clang::Type::Typedef: - return IsPossibleDynamicType(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - dynamic_pointee_type, check_cplusplus, - check_objc); - - case clang::Type::Auto: - return IsPossibleDynamicType(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - dynamic_pointee_type, check_cplusplus, - check_objc); - - case clang::Type::Elaborated: - return IsPossibleDynamicType(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - dynamic_pointee_type, check_cplusplus, - check_objc); - - case clang::Type::Paren: - return IsPossibleDynamicType( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - dynamic_pointee_type, check_cplusplus, check_objc); default: break; } @@ -3863,7 +3638,8 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, if (pointee_or_element_clang_type) pointee_or_element_clang_type->Clear(); - clang::QualType qual_type(GetQualType(type)); + clang::QualType qual_type = + Desugar(GetQualType(type), {clang::Type::Typedef}); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -3982,22 +3758,6 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, .getAsOpaquePtr()); return eTypeIsEnumeration | eTypeHasValue; - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetTypeInfo(pointee_or_element_clang_type); - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetTypeInfo(pointee_or_element_clang_type); - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetTypeInfo(pointee_or_element_clang_type); - case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue; case clang::Type::FunctionNoProto: @@ -4183,9 +3943,14 @@ ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) { if (!type) return lldb::eTypeClassInvalid; - clang::QualType qual_type(GetQualType(type)); + clang::QualType qual_type = + Desugar(GetQualType(type), {clang::Type::Typedef}); switch (qual_type->getTypeClass()) { + case clang::Type::Auto: + case clang::Type::Elaborated: + case clang::Type::Paren: + llvm_unreachable("Handled in Desugar!"); case clang::Type::UnaryTransform: break; case clang::Type::FunctionNoProto: @@ -4248,21 +4013,6 @@ ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) { return lldb::eTypeClassTypedef; case clang::Type::UnresolvedUsing: break; - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetTypeClass(); - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetTypeClass(); - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetTypeClass(); case clang::Type::Attributed: break; @@ -4451,7 +4201,7 @@ size_t ClangASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) { size_t num_functions = 0; if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); switch (qual_type->getTypeClass()) { case clang::Type::Record: if (GetCompleteQualType(getASTContext(), qual_type)) { @@ -4500,31 +4250,6 @@ ClangASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) { } break; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetNumMemberFunctions(); - - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetNumMemberFunctions(); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetNumMemberFunctions(); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetNumMemberFunctions(); - default: break; } @@ -4540,7 +4265,7 @@ ClangASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, CompilerType clang_type; CompilerDecl clang_decl; if (type) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); switch (qual_type->getTypeClass()) { case clang::Type::Record: if (GetCompleteQualType(getASTContext(), qual_type)) { @@ -4639,31 +4364,6 @@ ClangASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, } break; - case clang::Type::Typedef: - return GetMemberFunctionAtIndex(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - idx); - - case clang::Type::Auto: - return GetMemberFunctionAtIndex(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - idx); - - case clang::Type::Elaborated: - return GetMemberFunctionAtIndex( - llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - idx); - - case clang::Type::Paren: - return GetMemberFunctionAtIndex( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - idx); - default: break; } @@ -4957,9 +4657,15 @@ lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type, return lldb::eEncodingInvalid; count = 1; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); switch (qual_type->getTypeClass()) { + case clang::Type::Auto: + case clang::Type::Elaborated: + case clang::Type::Paren: + case clang::Type::Typedef: + llvm_unreachable("Handled in Desugar!"); + case clang::Type::UnaryTransform: break; @@ -5165,30 +4871,6 @@ lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type, break; case clang::Type::Enum: return lldb::eEncodingSint; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetEncoding(count); - - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetEncoding(count); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetEncoding(count); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetEncoding(count); case clang::Type::TypeOfExpr: return CompilerType(this, llvm::cast(qual_type) ->getUnderlyingExpr() @@ -5244,9 +4926,14 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) { if (!type) return lldb::eFormatDefault; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); switch (qual_type->getTypeClass()) { + case clang::Type::Auto: + case clang::Type::Elaborated: + case clang::Type::Paren: + case clang::Type::Typedef: + llvm_unreachable("Handled in Desugar!"); case clang::Type::UnaryTransform: break; @@ -5339,27 +5026,6 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) { break; case clang::Type::Enum: return lldb::eFormatEnum; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetFormat(); - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetFormat(); - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetFormat(); - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetFormat(); case clang::Type::TypeOfExpr: return CompilerType(this, llvm::cast(qual_type) ->getUnderlyingExpr() @@ -5447,7 +5113,7 @@ uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, return 0; uint32_t num_children = 0; - clang::QualType qual_type(GetQualType(type)); + clang::QualType qual_type(Desugar(GetQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Builtin: @@ -5599,36 +5265,6 @@ uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, num_children = num_pointee_children; } break; - case clang::Type::Typedef: - num_children = CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetNumChildren(omit_empty_base_classes, exe_ctx); - break; - - case clang::Type::Auto: - num_children = CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetNumChildren(omit_empty_base_classes, exe_ctx); - break; - - case clang::Type::Elaborated: - num_children = - CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetNumChildren(omit_empty_base_classes, exe_ctx); - break; - - case clang::Type::Paren: - num_children = - CompilerType( - this, - llvm::cast(qual_type)->desugar().getAsOpaquePtr()) - .GetNumChildren(omit_empty_base_classes, exe_ctx); - break; default: break; } @@ -5744,7 +5380,7 @@ uint32_t ClangASTContext::GetNumFields(lldb::opaque_compiler_type_t type) { return 0; uint32_t count = 0; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -5766,36 +5402,6 @@ uint32_t ClangASTContext::GetNumFields(lldb::opaque_compiler_type_t type) { } break; - case clang::Type::Typedef: - count = CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetNumFields(); - break; - - case clang::Type::Auto: - count = CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetNumFields(); - break; - - case clang::Type::Elaborated: - count = CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetNumFields(); - break; - - case clang::Type::Paren: - count = - CompilerType( - this, - llvm::cast(qual_type)->desugar().getAsOpaquePtr()) - .GetNumFields(); - break; - case clang::Type::ObjCObjectPointer: { const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAs(); @@ -5894,7 +5500,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, if (!type) return CompilerType(); - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -5982,35 +5588,6 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, } break; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, - is_bitfield_ptr); - - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, - is_bitfield_ptr); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, - is_bitfield_ptr); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, - is_bitfield_ptr); - default: break; } @@ -6020,7 +5597,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, uint32_t ClangASTContext::GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) { uint32_t count = 0; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -6063,29 +5640,6 @@ ClangASTContext::GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) { } break; - case clang::Type::Typedef: - count = GetNumDirectBaseClasses(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - break; - - case clang::Type::Auto: - count = GetNumDirectBaseClasses(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - break; - - case clang::Type::Elaborated: - count = GetNumDirectBaseClasses(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - break; - - case clang::Type::Paren: - return GetNumDirectBaseClasses( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); - default: break; } @@ -6095,7 +5649,7 @@ ClangASTContext::GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) { uint32_t ClangASTContext::GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) { uint32_t count = 0; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -6107,31 +5661,6 @@ ClangASTContext::GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) { } break; - case clang::Type::Typedef: - count = GetNumVirtualBaseClasses(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - break; - - case clang::Type::Auto: - count = GetNumVirtualBaseClasses(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - break; - - case clang::Type::Elaborated: - count = - GetNumVirtualBaseClasses(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - break; - - case clang::Type::Paren: - count = GetNumVirtualBaseClasses( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); - break; - default: break; } @@ -6140,7 +5669,7 @@ ClangASTContext::GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) { CompilerType ClangASTContext::GetDirectBaseClassAtIndex( lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -6230,31 +5759,6 @@ CompilerType ClangASTContext::GetDirectBaseClassAtIndex( } break; - case clang::Type::Typedef: - return GetDirectBaseClassAtIndex(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Auto: - return GetDirectBaseClassAtIndex(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Elaborated: - return GetDirectBaseClassAtIndex( - llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Paren: - return GetDirectBaseClassAtIndex( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - idx, bit_offset_ptr); - default: break; } @@ -6263,7 +5767,7 @@ CompilerType ClangASTContext::GetDirectBaseClassAtIndex( CompilerType ClangASTContext::GetVirtualBaseClassAtIndex( lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -6298,31 +5802,6 @@ CompilerType ClangASTContext::GetVirtualBaseClassAtIndex( } break; - case clang::Type::Typedef: - return GetVirtualBaseClassAtIndex(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Auto: - return GetVirtualBaseClassAtIndex(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Elaborated: - return GetVirtualBaseClassAtIndex( - llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - idx, bit_offset_ptr); - - case clang::Type::Paren: - return GetVirtualBaseClassAtIndex( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - idx, bit_offset_ptr); - default: break; } @@ -6338,7 +5817,7 @@ uint32_t ClangASTContext::GetNumPointeeChildren(clang::QualType type) { if (type.isNull()) return 0; - clang::QualType qual_type(type.getCanonicalType()); + clang::QualType qual_type = Desugar(type.getCanonicalType()); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Builtin: @@ -6439,19 +5918,6 @@ uint32_t ClangASTContext::GetNumPointeeChildren(clang::QualType type) { return 0; // When we function pointers, they have no children... case clang::Type::UnresolvedUsing: return 0; - case clang::Type::Paren: - return GetNumPointeeChildren( - llvm::cast(qual_type)->desugar()); - case clang::Type::Typedef: - return GetNumPointeeChildren(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType()); - case clang::Type::Auto: - return GetNumPointeeChildren( - llvm::cast(qual_type)->getDeducedType()); - case clang::Type::Elaborated: - return GetNumPointeeChildren( - llvm::cast(qual_type)->getNamedType()); case clang::Type::TypeOfExpr: return GetNumPointeeChildren(llvm::cast(qual_type) ->getUnderlyingExpr() @@ -6505,7 +5971,7 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex( return exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr; }; - clang::QualType parent_qual_type(GetCanonicalQualType(type)); + clang::QualType parent_qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass(); child_bitfield_bit_size = 0; @@ -6931,55 +6397,6 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex( } break; - case clang::Type::Typedef: { - CompilerType typedefed_clang_type( - this, llvm::cast(parent_qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - return typedefed_clang_type.GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); - } break; - - case clang::Type::Auto: { - CompilerType elaborated_clang_type( - this, llvm::cast(parent_qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - return elaborated_clang_type.GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); - } - - case clang::Type::Elaborated: { - CompilerType elaborated_clang_type( - this, llvm::cast(parent_qual_type) - ->getNamedType() - .getAsOpaquePtr()); - return elaborated_clang_type.GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); - } - - case clang::Type::Paren: { - CompilerType paren_clang_type(this, - llvm::cast(parent_qual_type) - ->desugar() - .getAsOpaquePtr()); - return paren_clang_type.GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); - } - default: break; } @@ -7078,7 +6495,7 @@ size_t ClangASTContext::GetIndexOfChildMemberWithName( lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes, std::vector &child_indexes) { if (type && name && name[0]) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -7303,35 +6720,6 @@ size_t ClangASTContext::GetIndexOfChildMemberWithName( } } break; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, - child_indexes); - - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, - child_indexes); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, - child_indexes); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, - child_indexes); - default: break; } @@ -7348,7 +6736,7 @@ ClangASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes) { if (type && name && name[0]) { - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); @@ -7535,31 +6923,6 @@ ClangASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, } } break; - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetIndexOfChildWithName(name, omit_empty_base_classes); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetIndexOfChildWithName(name, omit_empty_base_classes); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetIndexOfChildWithName(name, omit_empty_base_classes); - - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetIndexOfChildWithName(name, omit_empty_base_classes); - default: break; } @@ -7572,7 +6935,7 @@ ClangASTContext::GetNumTemplateArguments(lldb::opaque_compiler_type_t type) { if (!type) return 0; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type = Desugar(GetCanonicalQualType(type)); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: @@ -7589,31 +6952,6 @@ ClangASTContext::GetNumTemplateArguments(lldb::opaque_compiler_type_t type) { } break; - case clang::Type::Typedef: - return CompilerType(this, llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()) - .GetNumTemplateArguments(); - - case clang::Type::Auto: - return CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .GetNumTemplateArguments(); - - case clang::Type::Elaborated: - return CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .GetNumTemplateArguments(); - - case clang::Type::Paren: - return CompilerType(this, llvm::cast(qual_type) - ->desugar() - .getAsOpaquePtr()) - .GetNumTemplateArguments(); - default: break; } @@ -7627,7 +6965,7 @@ ClangASTContext::GetAsTemplateSpecialization( if (!type) return nullptr; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { case clang::Type::Record: { @@ -7641,27 +6979,6 @@ ClangASTContext::GetAsTemplateSpecialization( cxx_record_decl); } - case clang::Type::Typedef: - return GetAsTemplateSpecialization(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr()); - - case clang::Type::Auto: - return GetAsTemplateSpecialization(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()); - - case clang::Type::Elaborated: - return GetAsTemplateSpecialization( - llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()); - - case clang::Type::Paren: - return GetAsTemplateSpecialization( - llvm::cast(qual_type)->desugar().getAsOpaquePtr()); - default: return nullptr; } @@ -8621,7 +7938,7 @@ bool ClangASTContext::SetHasExternalStorage(lldb::opaque_compiler_type_t type, if (!type) return false; - clang::QualType qual_type(GetCanonicalQualType(type)); + clang::QualType qual_type(Desugar(GetCanonicalQualType(type))); const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { @@ -8661,30 +7978,6 @@ bool ClangASTContext::SetHasExternalStorage(lldb::opaque_compiler_type_t type, } } break; - case clang::Type::Typedef: - return SetHasExternalStorage(llvm::cast(qual_type) - ->getDecl() - ->getUnderlyingType() - .getAsOpaquePtr(), - has_extern); - - case clang::Type::Auto: - return SetHasExternalStorage(llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr(), - has_extern); - - case clang::Type::Elaborated: - return SetHasExternalStorage(llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr(), - has_extern); - - case clang::Type::Paren: - return SetHasExternalStorage( - llvm::cast(qual_type)->desugar().getAsOpaquePtr(), - has_extern); - default: break; } @@ -9576,7 +8869,8 @@ void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) { void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stream *s) { if (type) { - clang::QualType qual_type(GetQualType(type)); + clang::QualType qual_type = + Desugar(GetQualType(type), {clang::Type::Typedef}); llvm::SmallVector buf; llvm::raw_svector_ostream llvm_ostrm(buf); @@ -9614,27 +8908,6 @@ void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, } } break; - case clang::Type::Auto: - CompilerType(this, llvm::cast(qual_type) - ->getDeducedType() - .getAsOpaquePtr()) - .DumpTypeDescription(s); - return; - - case clang::Type::Elaborated: - CompilerType(this, llvm::cast(qual_type) - ->getNamedType() - .getAsOpaquePtr()) - .DumpTypeDescription(s); - return; - - case clang::Type::Paren: - CompilerType( - this, - llvm::cast(qual_type)->desugar().getAsOpaquePtr()) - .DumpTypeDescription(s); - return; - case clang::Type::Record: { GetCompleteType(type);