16 #ifndef LLVM_CLANG_AST_ASTTYPETRAITS_H
17 #define LLVM_CLANG_AST_ASTTYPETRAITS_H
26 #include "llvm/ADT/DenseMapInfo.h"
27 #include "llvm/Support/AlignOf.h"
37 struct PrintingPolicy;
39 namespace ast_type_traits {
68 bool isNone()
const {
return KindId == NKI_None; }
80 return KindId < Other.KindId;
105 return LHS.KindId == RHS.KindId;
112 return KindId > NKI_LastKindWithoutPointerIdentity;
121 NKI_TemplateArgument,
122 NKI_NestedNameSpecifierLoc,
125 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
126 NKI_CXXCtorInitializer,
127 NKI_NestedNameSpecifier,
129 #define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
130 #include "clang/AST/DeclNodes.inc"
132 #define STMT(DERIVED, BASE) NKI_##DERIVED,
133 #include "clang/AST/StmtNodes.inc"
135 #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
136 #include "clang/AST/TypeNodes.def"
147 static bool isBaseOf(NodeKindId
Base, NodeKindId Derived,
unsigned *Distance);
152 template <
class T>
struct KindToKindId {
153 static const NodeKindId Id = NKI_None;
156 struct KindToKindId<const T> : KindToKindId<T> {};
165 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
170 #define KIND_TO_KIND_ID(Class) \
171 template <> struct ASTNodeKind::KindToKindId<Class> { \
172 static const NodeKindId Id = NKI_##Class; \
183 #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
184 #include "clang/AST/DeclNodes.inc"
185 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
186 #include "clang/AST/StmtNodes.inc"
187 #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
188 #include "clang/AST/TypeNodes.def"
189 #undef KIND_TO_KIND_ID
211 template <
typename T>
228 template <
typename T>
229 const T *
get()
const {
230 return BaseConverter<T>::get(NodeKind, Storage.buffer);
236 template <
typename T>
238 return BaseConverter<T>::getUnchecked(NodeKind, Storage.buffer);
250 ? *
reinterpret_cast<void *
const *
>(Storage.buffer)
271 if (!NodeKind.
isSame(Other.NodeKind))
272 return NodeKind < Other.NodeKind;
274 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
275 return getUnchecked<QualType>().getAsOpaquePtr() <
278 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(NodeKind)) {
279 auto TLA = getUnchecked<TypeLoc>();
281 return std::make_pair(TLA.getType().getAsOpaquePtr(),
282 TLA.getOpaqueData()) <
283 std::make_pair(TLB.getType().getAsOpaquePtr(),
284 TLB.getOpaqueData());
287 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
289 auto NNSLA = getUnchecked<NestedNameSpecifierLoc>();
291 return std::make_pair(NNSLA.getNestedNameSpecifier(),
292 NNSLA.getOpaqueData()) <
293 std::make_pair(NNSLB.getNestedNameSpecifier(),
294 NNSLB.getOpaqueData());
303 if (!NodeKind.
isSame(Other.NodeKind))
307 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
310 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(NodeKind))
313 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(NodeKind))
314 return getUnchecked<NestedNameSpecifierLoc>() ==
339 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(Val.NodeKind)) {
341 return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
345 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
348 return llvm::hash_combine(NNSL.getNestedNameSpecifier(),
349 NNSL.getOpaqueData());
368 template <
typename T,
typename EnablerT =
void>
struct BaseConverter;
371 template <
typename T,
typename BaseT>
struct DynCastPtrConverter {
372 static const T *
get(
ASTNodeKind NodeKind,
const char Storage[]) {
373 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
377 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
378 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
379 return *cast<T>(
static_cast<const BaseT *
>(
380 *
reinterpret_cast<const void *
const *
>(Storage)));
382 static DynTypedNode
create(
const BaseT &
Node) {
385 new (Result.Storage.buffer)
const void *(&Node);
391 template <
typename T>
struct PtrConverter {
392 static const T *
get(ASTNodeKind NodeKind,
const char Storage[]) {
393 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
397 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
398 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
399 return *
static_cast<const T *
>(
400 *
reinterpret_cast<const void *
const *
>(Storage));
404 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
405 new (Result.Storage.buffer)
const void *(&Node);
411 template <
typename T>
struct ValueConverter {
412 static const T *
get(ASTNodeKind NodeKind,
const char Storage[]) {
413 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
414 return reinterpret_cast<const T *>(Storage);
417 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
418 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
419 return *
reinterpret_cast<const T *
>(Storage);
423 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
424 new (Result.Storage.buffer) T(Node);
429 ASTNodeKind NodeKind;
439 llvm::AlignedCharArrayUnion<
const void *, TemplateArgument,
440 NestedNameSpecifierLoc, QualType,
444 template <
typename T>
445 struct DynTypedNode::BaseConverter<
446 T, typename std::enable_if<std::is_base_of<Decl, T>::value>
::type>
447 :
public DynCastPtrConverter<T, Decl> {};
449 template <
typename T>
450 struct DynTypedNode::BaseConverter<
451 T, typename std::enable_if<std::is_base_of<Stmt, T>::value>
::type>
452 :
public DynCastPtrConverter<T, Stmt> {};
454 template <
typename T>
455 struct DynTypedNode::BaseConverter<
456 T, typename std::enable_if<std::is_base_of<Type, T>::value>
::type>
457 :
public DynCastPtrConverter<T, Type> {};
460 struct DynTypedNode::BaseConverter<
464 struct DynTypedNode::BaseConverter<
468 struct DynTypedNode::BaseConverter<
472 struct DynTypedNode::BaseConverter<
474 void> :
public ValueConverter<NestedNameSpecifierLoc> {};
478 void> :
public ValueConverter<QualType> {};
481 struct DynTypedNode::BaseConverter<
482 TypeLoc, void> :
public ValueConverter<TypeLoc> {};
488 template <
typename T,
typename EnablerT>
struct DynTypedNode::BaseConverter {
489 static const T *
get(
ASTNodeKind NodeKind,
const char Storage[]) {
bool operator!=(const DynTypedNode &Other) const
A (possibly-)qualified type.
static ASTNodeKind getFromNode(const Decl &D)
Construct an identifier for the dynamic type of the node.
static ASTNodeKind getTombstoneKey()
static ASTNodeKind getEmptyKey()
Decl - This represents one declaration (or definition), e.g.
The base class of the type hierarchy.
static DynTypedNode getTombstoneKey()
Describes how types, statements, expressions, and declarations should be printed. ...
bool operator<(const ASTNodeKind &Other) const
Strict weak ordering for ASTNodeKind.
Base wrapper for a particular "section" of type source info.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
A C++ nested-name-specifier augmented with source location information.
bool isNone() const
Returns true only for the default ASTNodeKind()
bool isBaseOf(ASTNodeKind Other, unsigned *Distance=nullptr) const
Returns true if this is a base kind of (or same as) Other.
ASTNodeKind()
Empty identifier. It matches nothing.
const T & getUnchecked() const
Retrieve the stored node as type T.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool hasPointerIdentity() const
Check if the given ASTNodeKind identifies a type that offers pointer identity.
Forward declaration of all AST node types.
static unsigned getHashValue(const DynTypedNode &Val)
Hooks for using ASTNodeKind as a key in a DenseMap.
void dump(llvm::raw_ostream &OS, SourceManager &SM) const
Dumps the node to the given output stream.
Defines the clang::TypeLoc interface and its subclasses.
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
The result type of a method or function.
#define KIND_TO_KIND_ID(Class)
const void * getMemoizationData() const
Returns a pointer that identifies the stored AST node.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
StringRef asStringRef() const
String representation of the kind.
ASTNodeKind getNodeKind() const
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
static unsigned getHashValue(const ASTNodeKind &Val)
ast_type_traits::DynTypedNode Node
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
Represents a template argument.
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived common ancestor between Kind1 and Kind2.
bool isSame(ASTNodeKind Other) const
Returns true if this and Other represent the same kind.
bool operator<(const DynTypedNode &Other) const
Imposes an order on DynTypedNode.
bool operator==(const DynTypedNode &Other) const
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Hooks for using DynTypedNode as a key in a DenseMap.
A dynamically typed AST node container.
Represents a C++ base or member initializer.
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
static DynTypedNode getEmptyKey()
raw_ostream & operator<<(raw_ostream &OS, ASTNodeKind K)
A trivial tuple used to represent a source range.
static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS)
static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS)
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
This class handles loading and caching of source files into memory.
static ASTNodeKind getFromNodeKind()
Construct an identifier for T.