15#ifndef LLVM_CLANG_AST_ASTTYPETRAITS_H
16#define LLVM_CLANG_AST_ASTTYPETRAITS_H
25#include "llvm/ADT/DenseMapInfo.h"
26#include "llvm/Support/AlignOf.h"
74 return KindId != NKI_None && KindId == Other.KindId;
78 constexpr bool isNone()
const {
return KindId == NKI_None; }
93 return KindId < Other.KindId;
120 return LHS.KindId == RHS.KindId;
127 return KindId > NKI_LastKindWithoutPointerIdentity;
136 NKI_TemplateArgument,
137 NKI_TemplateArgumentLoc,
140 NKI_NestedNameSpecifierLoc,
142#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
143#include "clang/AST/TypeLocNodes.def"
145 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
146 NKI_CXXBaseSpecifier,
147 NKI_CXXCtorInitializer,
148 NKI_NestedNameSpecifier,
150#define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
151#include "clang/AST/DeclNodes.inc"
153#define STMT(DERIVED, BASE) NKI_##DERIVED,
154#include "clang/AST/StmtNodes.inc"
156#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
157#include "clang/AST/TypeNodes.inc"
159#define GEN_CLANG_CLAUSE_CLASS
160#define CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
161#include "llvm/Frontend/OpenMP/OMP.inc"
163#define ATTR(A) NKI_##A##Attr,
164#include "clang/Basic/AttrList.inc"
170 constexpr ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
174 static bool isBaseOf(NodeKindId
Base, NodeKindId Derived);
180 static bool isBaseOf(NodeKindId
Base, NodeKindId Derived,
unsigned *Distance);
185 template <
class T>
struct KindToKindId {
186 static const NodeKindId
Id = NKI_None;
189 struct KindToKindId<const T> : KindToKindId<T> {};
198 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
203#define KIND_TO_KIND_ID(Class) \
204 template <> struct ASTNodeKind::KindToKindId<Class> { \
205 static const NodeKindId Id = NKI_##Class; \
215#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
216#include "clang/AST/TypeLocNodes.def"
225#define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
226#include "clang/AST/DeclNodes.inc"
227#define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
228#include "clang/AST/StmtNodes.inc"
229#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
230#include "clang/AST/TypeNodes.inc"
231#define GEN_CLANG_CLAUSE_CLASS
232#define CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
233#include "llvm/Frontend/OpenMP/OMP.inc"
234#define ATTR(A) KIND_TO_KIND_ID(A##Attr)
235#include "clang/Basic/AttrList.inc"
236#undef KIND_TO_KIND_ID
258 template <
typename T>
260 return BaseConverter<T>::create(
Node);
275 template <
typename T>
const T *
get()
const {
276 return BaseConverter<T>::get(NodeKind, &Storage);
282 template <
typename T>
284 return BaseConverter<T>::getUnchecked(NodeKind, &Storage);
296 ? *
reinterpret_cast<void *
const *
>(&Storage)
304 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
317 if (!NodeKind.
isSame(Other.NodeKind))
318 return NodeKind < Other.NodeKind;
320 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
321 return getUnchecked<QualType>().getAsOpaquePtr() <
322 Other.getUnchecked<
QualType>().getAsOpaquePtr();
324 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind)) {
325 auto TLA = getUnchecked<TypeLoc>();
326 auto TLB = Other.getUnchecked<
TypeLoc>();
327 return std::make_pair(TLA.getType().getAsOpaquePtr(),
328 TLA.getOpaqueData()) <
329 std::make_pair(TLB.getType().getAsOpaquePtr(),
330 TLB.getOpaqueData());
333 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
335 auto NNSLA = getUnchecked<NestedNameSpecifierLoc>();
337 return std::make_pair(NNSLA.getNestedNameSpecifier(),
338 NNSLA.getOpaqueData()) <
339 std::make_pair(NNSLB.getNestedNameSpecifier(),
340 NNSLB.getOpaqueData());
349 if (!NodeKind.
isSame(Other.NodeKind))
353 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
354 return getUnchecked<QualType>() == Other.getUnchecked<
QualType>();
356 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind))
357 return getUnchecked<TypeLoc>() == Other.getUnchecked<
TypeLoc>();
359 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(NodeKind))
360 return getUnchecked<NestedNameSpecifierLoc>() ==
385 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(Val.NodeKind)) {
387 return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
391 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
394 return llvm::hash_combine(NNSL.getNestedNameSpecifier(),
395 NNSL.getOpaqueData());
414 template <
typename T,
typename EnablerT =
void>
struct BaseConverter;
417 template <
typename T,
typename BaseT>
struct DynCastPtrConverter {
419 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
423 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
424 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
425 return *cast<T>(
static_cast<const BaseT *
>(
426 *
reinterpret_cast<const void *
const *
>(Storage)));
437 template <
typename T>
struct PtrConverter {
438 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
439 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
443 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
444 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
445 return *
static_cast<const T *
>(
446 *
reinterpret_cast<const void *
const *
>(Storage));
450 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
457 template <
typename T>
struct ValueConverter {
458 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
459 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
460 return reinterpret_cast<const T *
>(Storage);
463 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
464 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
465 return *
reinterpret_cast<const T *
>(Storage);
469 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
478 template <
typename T,
typename BaseT,
479 typename = std::enable_if_t<(
sizeof(T) ==
sizeof(BaseT))>>
480 struct DynCastValueConverter {
481 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
482 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
486 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
487 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
488 return *
static_cast<const T *
>(
reinterpret_cast<const BaseT *
>(Storage));
508 llvm::AlignedCharArrayUnion<
const void *, TemplateArgument,
509 TemplateArgumentLoc, NestedNameSpecifierLoc,
510 QualType, TypeLoc, ObjCProtocolLoc>
515struct DynTypedNode::BaseConverter<
516 T, std::enable_if_t<std::is_base_of<Decl, T>::value>>
517 :
public DynCastPtrConverter<T, Decl> {};
520struct DynTypedNode::BaseConverter<
521 T,
std::enable_if_t<std::is_base_of<Stmt, T>::value>>
522 :
public DynCastPtrConverter<T, Stmt> {};
525struct DynTypedNode::BaseConverter<
526 T,
std::enable_if_t<std::is_base_of<Type, T>::value>>
527 :
public DynCastPtrConverter<T, Type> {};
530struct DynTypedNode::BaseConverter<
531 T,
std::enable_if_t<std::is_base_of<OMPClause, T>::value>>
532 :
public DynCastPtrConverter<T, OMPClause> {};
535struct DynTypedNode::BaseConverter<
536 T,
std::enable_if_t<std::is_base_of<Attr, T>::value>>
537 :
public DynCastPtrConverter<T, Attr> {};
540struct DynTypedNode::BaseConverter<
544struct DynTypedNode::BaseConverter<
548struct DynTypedNode::BaseConverter<
553 :
public ValueConverter<TemplateArgumentLoc> {};
557 :
public ValueConverter<LambdaCapture> {};
560struct DynTypedNode::BaseConverter<
561 TemplateName, void> :
public ValueConverter<TemplateName> {};
564struct DynTypedNode::BaseConverter<
566 void> :
public ValueConverter<NestedNameSpecifierLoc> {};
570 void> :
public ValueConverter<QualType> {};
573struct DynTypedNode::BaseConverter<
574 T,
std::enable_if_t<std::is_base_of<TypeLoc, T>::value>>
575 :
public DynCastValueConverter<T, TypeLoc> {};
579 :
public PtrConverter<CXXBaseSpecifier> {};
583 :
public ValueConverter<ObjCProtocolLoc> {};
589template <
typename T,
typename EnablerT>
struct DynTypedNode::BaseConverter {
Forward declaration of all AST node types.
#define KIND_TO_KIND_ID(Class)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::TypeLoc interface and its subclasses.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static ASTNodeKind getFromNode(const LambdaCapture &L)
StringRef asStringRef() const
String representation of the kind.
bool isBaseOf(ASTNodeKind Other) const
Returns true if this is a base kind of (or same as) Other.
constexpr ASTNodeKind()
Empty identifier. It matches nothing.
ASTNodeKind getCladeKind() const
constexpr bool hasPointerIdentity() const
Check if the given ASTNodeKind identifies a type that offers pointer identity.
constexpr bool operator<(const ASTNodeKind &Other) const
Strict weak ordering for ASTNodeKind.
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived common ancestor between Kind1 and Kind2.
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
static ASTNodeKind getFromNode(const Decl &D)
constexpr bool isSame(ASTNodeKind Other) const
Returns true if this and Other represent the same kind.
constexpr bool isNone() const
Returns true only for the default ASTNodeKind()
static constexpr ASTNodeKind getFromNodeKind()
Construct an identifier for T.
Attr - This represents one attribute.
Represents a base class of a C++ class.
Represents a C++ base or member initializer.
Decl - This represents one declaration (or definition), e.g.
A dynamically typed AST node container.
bool operator<(const DynTypedNode &Other) const
ASTNodeKind getNodeKind() const
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
bool operator==(const DynTypedNode &Other) const
bool operator!=(const DynTypedNode &Other) const
const T * get() const
Retrieve the stored node as type T.
const T & getUnchecked() const
Retrieve the stored node as type T.
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
const void * getMemoizationData() const
Returns a pointer that identifies the stored AST node.
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const
Dumps the node to the given output stream.
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
Describes the capture of a variable or of this, or of a C++1y init-capture.
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This is a basic class for representing single OpenMP clause.
A (possibly-)qualified type.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Location wrapper for a TemplateArgument.
Represents a template argument.
Represents a C++ template name within the type system.
Base wrapper for a particular "section" of type source info.
The base class of the type hierarchy.
DynTypedNode DynTypedNode
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
NodeKind
A kind of a syntax node, used for implementing casts.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
@ TK_AsIs
Will traverse all child nodes.
@ TK_IgnoreUnlessSpelledInSource
Ignore AST nodes not written in the source.
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
YAML serialization mapping.
Hooks for using ASTNodeKind as a key in a DenseMap.
static ASTNodeKind getEmptyKey()
static unsigned getHashValue(const ASTNodeKind &Val)
static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS)
static ASTNodeKind getTombstoneKey()
Hooks for using DynTypedNode as a key in a DenseMap.
static unsigned getHashValue(const DynTypedNode &Val)
static DynTypedNode getEmptyKey()
static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS)
static DynTypedNode getTombstoneKey()
Describes how types, statements, expressions, and declarations should be printed.