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" // IWYU pragma: export
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->getDecl();
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->getDecl())->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->getDecl())->getDefinitionOrSelf();
46}
47
49 const auto *TT = cast<TagType>(CanonicalType);
50 return cast<RecordDecl>(TT->getDecl())->getDefinitionOrSelf();
51}
52
54 if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
55 return TT->getDecl()->getDefinitionOrSelf();
56 return nullptr;
57}
58
60 return cast<EnumType>(CanonicalType)->getDecl()->getDefinitionOrSelf();
61}
62
63inline TagDecl *Type::getAsTagDecl() const {
64 if (const auto *TT = dyn_cast<TagType>(CanonicalType))
65 return TT->getDecl()->getDefinitionOrSelf();
66 return nullptr;
67}
68
70 return cast<TagType>(CanonicalType)->getDecl()->getDefinitionOrSelf();
71}
72
74 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
76 return false;
77}
78
80 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
82 return false;
83}
84
86 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
88 return false;
89}
90
91} // namespace clang
92
93#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:4007
EnumDecl * getDefinitionOrSelf() const
Definition Decl.h:4114
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:85
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8278
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:79
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:73
Represents a struct/union/class.
Definition Decl.h:4312
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
TagDecl * getDefinitionOrSelf() const
Definition Decl.h:3894
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:69
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:63
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.
bool isa(CodeGen::Address addr)
Definition Address.h:330
U cast(CodeGen::Address addr)
Definition Address.h:327