Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,55 @@

namespace clang {

inline CXXRecordDecl *Type::getAsCXXRecordDecl() const {
const auto *TT = dyn_cast<TagType>(CanonicalType);
if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
return nullptr;
auto *TD = TT->getOriginalDecl();
if (isa<RecordType>(TT) && !isa<CXXRecordDecl>(TD))
return nullptr;
return cast<CXXRecordDecl>(TD)->getDefinitionOrSelf();
}

inline CXXRecordDecl *Type::castAsCXXRecordDecl() const {
const auto *TT = cast<TagType>(CanonicalType);
return cast<CXXRecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

inline RecordDecl *Type::getAsRecordDecl() const {
const auto *TT = dyn_cast<TagType>(CanonicalType);
if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
return nullptr;
return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

inline RecordDecl *Type::castAsRecordDecl() const {
const auto *TT = cast<TagType>(CanonicalType);
return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

inline EnumDecl *Type::getAsEnumDecl() const {
if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
return TT->getOriginalDecl()->getDefinitionOrSelf();
return nullptr;
}

inline EnumDecl *Type::castAsEnumDecl() const {
return cast<EnumType>(CanonicalType)
->getOriginalDecl()
->getDefinitionOrSelf();
}

inline TagDecl *Type::getAsTagDecl() const {
if (const auto *TT = dyn_cast<TagType>(CanonicalType))
return TT->getOriginalDecl()->getDefinitionOrSelf();
return nullptr;
}

inline TagDecl *Type::castAsTagDecl() const {
return cast<TagType>(CanonicalType)->getOriginalDecl()->getDefinitionOrSelf();
}

inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
Expand Down
16 changes: 8 additions & 8 deletions clang/include/clang/AST/TypeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -2882,22 +2882,22 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// Retrieves the CXXRecordDecl that this type refers to, either
/// because the type is a RecordType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
CXXRecordDecl *getAsCXXRecordDecl() const;
CXXRecordDecl *castAsCXXRecordDecl() const;
inline CXXRecordDecl *getAsCXXRecordDecl() const;
inline CXXRecordDecl *castAsCXXRecordDecl() const;

/// Retrieves the RecordDecl this type refers to.
RecordDecl *getAsRecordDecl() const;
RecordDecl *castAsRecordDecl() const;
inline RecordDecl *getAsRecordDecl() const;
inline RecordDecl *castAsRecordDecl() const;

/// Retrieves the EnumDecl this type refers to.
EnumDecl *getAsEnumDecl() const;
EnumDecl *castAsEnumDecl() const;
inline EnumDecl *getAsEnumDecl() const;
inline EnumDecl *castAsEnumDecl() const;

/// Retrieves the TagDecl that this type refers to, either
/// because the type is a TagType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
TagDecl *getAsTagDecl() const;
TagDecl *castAsTagDecl() const;
inline TagDecl *getAsTagDecl() const;
inline TagDecl *castAsTagDecl() const;

/// If this is a pointer or reference to a RecordType, return the
/// CXXRecordDecl that the type refers to.
Expand Down
49 changes: 0 additions & 49 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,55 +1917,6 @@ const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const {
return PointeeType->getAsCXXRecordDecl();
}

CXXRecordDecl *Type::getAsCXXRecordDecl() const {
const auto *TT = dyn_cast<TagType>(CanonicalType);
if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
return nullptr;
auto *TD = TT->getOriginalDecl();
if (!isa<InjectedClassNameType>(TT) && !isa<CXXRecordDecl>(TD))
return nullptr;
return cast<CXXRecordDecl>(TD)->getDefinitionOrSelf();
}

CXXRecordDecl *Type::castAsCXXRecordDecl() const {
const auto *TT = cast<TagType>(CanonicalType);
return cast<CXXRecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

RecordDecl *Type::getAsRecordDecl() const {
const auto *TT = dyn_cast<TagType>(CanonicalType);
if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
return nullptr;
return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

RecordDecl *Type::castAsRecordDecl() const {
const auto *TT = cast<TagType>(CanonicalType);
return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
}

EnumDecl *Type::getAsEnumDecl() const {
if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
return TT->getOriginalDecl()->getDefinitionOrSelf();
return nullptr;
}

EnumDecl *Type::castAsEnumDecl() const {
return cast<EnumType>(CanonicalType)
->getOriginalDecl()
->getDefinitionOrSelf();
}

TagDecl *Type::getAsTagDecl() const {
if (const auto *TT = dyn_cast<TagType>(CanonicalType))
return TT->getOriginalDecl()->getDefinitionOrSelf();
return nullptr;
}

TagDecl *Type::castAsTagDecl() const {
return cast<TagType>(CanonicalType)->getOriginalDecl()->getDefinitionOrSelf();
}

const TemplateSpecializationType *
Type::getAsNonAliasTemplateSpecializationType() const {
const auto *TST = getAs<TemplateSpecializationType>();
Expand Down