clang 22.0.0git
Type.h
Go to the documentation of this file.
1//===- Type.h - C Language Family Type Representation -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// C Language Family Type Representation
11///
12/// This file defines some inline methods for clang::Type which depend on
13/// Decl.h, avoiding a circular dependency.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CLANG_AST_TYPE_H
18#define LLVM_CLANG_AST_TYPE_H
19
20#include "clang/AST/Decl.h"
21#include "clang/AST/DeclCXX.h"
22#include "clang/AST/TypeBase.h"
23
24namespace clang {
25
27 const auto *TT = dyn_cast<TagType>(CanonicalType);
28 if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
29 return nullptr;
30 auto *TD = TT->getOriginalDecl();
31 if (isa<RecordType>(TT) && !isa<CXXRecordDecl>(TD))
32 return nullptr;
33 return cast<CXXRecordDecl>(TD)->getDefinitionOrSelf();
34}
35
37 const auto *TT = cast<TagType>(CanonicalType);
38 return cast<CXXRecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
39}
40
42 const auto *TT = dyn_cast<TagType>(CanonicalType);
43 if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
44 return nullptr;
45 return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
46}
47
49 const auto *TT = cast<TagType>(CanonicalType);
50 return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
51}
52
54 if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
55 return TT->getOriginalDecl()->getDefinitionOrSelf();
56 return nullptr;
57}
58
60 return cast<EnumType>(CanonicalType)
61 ->getOriginalDecl()
63}
64
65inline TagDecl *Type::getAsTagDecl() const {
66 if (const auto *TT = dyn_cast<TagType>(CanonicalType))
67 return TT->getOriginalDecl()->getDefinitionOrSelf();
68 return nullptr;
69}
70
72 return cast<TagType>(CanonicalType)->getOriginalDecl()->getDefinitionOrSelf();
73}
74
76 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
78 return false;
79}
80
82 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
84 return false;
85}
86
88 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
90 return false;
91}
92
93} // namespace clang
94
95#endif // LLVM_CLANG_AST_TYPE_H
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static RecordDecl * getAsRecordDecl(QualType BaseType, HeuristicResolver &Resolver)
C Language Family Type Representation.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents an enum.
Definition: Decl.h:4004
EnumDecl * getDefinitionOrSelf() const
Definition: Decl.h:4111
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
Definition: Type.h:87
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: TypeBase.h:8343
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Definition: Type.h:81
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
Definition: Type.h:75
Represents a struct/union/class.
Definition: Decl.h:4309
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3714
TagDecl * getDefinitionOrSelf() const
Definition: Decl.h:3891
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.h:26
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.h:41
CXXRecordDecl * castAsCXXRecordDecl() const
Definition: Type.h:36
TagDecl * castAsTagDecl() const
Definition: Type.h:71
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.h:65
RecordDecl * castAsRecordDecl() const
Definition: Type.h:48
EnumDecl * castAsEnumDecl() const
Definition: Type.h:59
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
Definition: Type.h:53
The JSON file list parser is used to communicate input to InstallAPI.