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;
114 return LHS.KindId == RHS.KindId;
121 return KindId > NKI_LastKindWithoutPointerIdentity;
130 NKI_TemplateArgument,
131 NKI_TemplateArgumentLoc,
134 NKI_NestedNameSpecifier,
135 NKI_NestedNameSpecifierLoc,
138#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
139#include "clang/AST/TypeLocNodes.def"
141 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
142 NKI_CXXBaseSpecifier,
143 NKI_CXXCtorInitializer,
145#define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
146#include "clang/AST/DeclNodes.inc"
148#define STMT(DERIVED, BASE) NKI_##DERIVED,
149#include "clang/AST/StmtNodes.inc"
151#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
152#include "clang/AST/TypeNodes.inc"
154#define GEN_CLANG_CLAUSE_CLASS
155#define CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
156#include "llvm/Frontend/OpenMP/OMP.inc"
158#define ATTR(A) NKI_##A##Attr,
159#include "clang/Basic/AttrList.inc"
160 NKI_ConceptReference,
166 constexpr ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
170 static bool isBaseOf(NodeKindId Base, NodeKindId Derived);
176 static bool isBaseOf(NodeKindId Base, NodeKindId Derived,
unsigned *Distance);
181 template <
class T>
struct KindToKindId {
182 static const NodeKindId Id = NKI_None;
185 struct KindToKindId<const
T> : KindToKindId<T> {};
194 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
199#define KIND_TO_KIND_ID(Class) \
200 template <> struct ASTNodeKind::KindToKindId<Class> { \
201 static const NodeKindId Id = NKI_##Class; \
211#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
212#include "clang/AST/TypeLocNodes.def"
223#define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
224#include "clang/AST/DeclNodes.inc"
225#define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
226#include "clang/AST/StmtNodes.inc"
227#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
228#include "clang/AST/TypeNodes.inc"
229#define GEN_CLANG_CLAUSE_CLASS
230#define CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
231#include "llvm/Frontend/OpenMP/OMP.inc"
232#define ATTR(A) KIND_TO_KIND_ID(A##Attr)
233#include "clang/Basic/AttrList.inc"
234#undef KIND_TO_KIND_ID
257 using Converter = BaseConverter<T>;
259 Converter::StoresPointer ==
262 "hasPointerIdentity() must agree with whether DynTypedNode "
263 "stores a node by pointer");
264 return Converter::create(Node);
279 template <
typename T>
const T *
get()
const {
280 return BaseConverter<T>::get(NodeKind, &Storage);
286 template <
typename T>
288 return BaseConverter<T>::getUnchecked(NodeKind, &Storage);
299 return NodeKind.hasPointerIdentity()
300 ? *
reinterpret_cast<void *
const *
>(&Storage)
308 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
320 if (!NodeKind.isSame(
Other.NodeKind))
321 return NodeKind <
Other.NodeKind;
330 return std::make_pair(TLA.getType().getAsOpaquePtr(),
331 TLA.getOpaqueData()) <
332 std::make_pair(TLB.getType().getAsOpaquePtr(),
333 TLB.getOpaqueData());
340 return std::make_pair(NNSLA.getNestedNameSpecifier().getAsVoidPointer(),
341 NNSLA.getOpaqueData()) <
342 std::make_pair(NNSLB.getNestedNameSpecifier().getAsVoidPointer(),
343 NNSLB.getOpaqueData());
353 return std::make_pair(PLA.getProtocol(), PLA.getLocation()) <
354 std::make_pair(PLB.getProtocol(), PLB.getLocation());
363 if (!NodeKind.isSame(
Other.NodeKind))
402 return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
409 return llvm::hash_combine(
410 NNSL.getNestedNameSpecifier().getAsVoidPointer(),
411 NNSL.getOpaqueData());
416 return llvm::DenseMapInfo<NestedNameSpecifier>::getHashValue(
422 return llvm::hash_combine(PL.getProtocol(),
423 PL.getLocation().getRawEncoding());
436 template <
typename T,
typename EnablerT =
void>
struct BaseConverter;
439 template <
typename T,
typename BaseT>
struct DynCastPtrConverter {
440 static constexpr bool StoresPointer =
true;
441 using BaseType = BaseT;
447 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
449 return *
cast<T>(
static_cast<const BaseT *
>(
450 *
reinterpret_cast<const void *
const *
>(Storage)));
455 new (&
Result.Storage)
const void *(&Node);
461 template <
typename T>
struct PtrConverter {
462 static constexpr bool StoresPointer =
true;
464 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
469 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
471 return *
static_cast<const T *
>(
472 *
reinterpret_cast<const void *
const *
>(
Storage));
477 new (&
Result.Storage)
const void *(&Node);
483 template <
typename T>
struct ValueConverter {
484 static constexpr bool StoresPointer =
false;
486 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
488 return reinterpret_cast<const T *
>(
Storage);
491 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
493 return *
reinterpret_cast<const T *
>(
Storage);
506 template <
typename T,
typename BaseT,
507 typename = std::enable_if_t<(
sizeof(
T) ==
sizeof(BaseT))>>
508 struct DynCastValueConverter {
509 static constexpr bool StoresPointer =
false;
510 using BaseType = BaseT;
511 static const T *
get(ASTNodeKind NodeKind,
const void *Storage) {
516 static const T &
getUnchecked(ASTNodeKind NodeKind,
const void *Storage) {
518 return *
static_cast<const T *
>(
reinterpret_cast<const BaseT *
>(Storage));
528 ASTNodeKind NodeKind;
539 llvm::AlignedCharArrayUnion<
540 const void *, TemplateArgument, TemplateArgumentLoc, NestedNameSpecifier,
541 NestedNameSpecifierLoc, QualType, TypeLoc, ObjCProtocolLoc>
546struct DynTypedNode::BaseConverter<
547 T, std::enable_if_t<std::is_base_of<Decl, T>::value>>
548 :
public DynCastPtrConverter<T, Decl> {};
551struct DynTypedNode::BaseConverter<
552 T,
std::enable_if_t<std::is_base_of<Stmt, T>::value>>
553 :
public DynCastPtrConverter<T, Stmt> {};
556struct DynTypedNode::BaseConverter<
557 T,
std::enable_if_t<std::is_base_of<Type, T>::value>>
558 :
public DynCastPtrConverter<T, Type> {};
561struct DynTypedNode::BaseConverter<
562 T,
std::enable_if_t<std::is_base_of<OMPClause, T>::value>>
563 :
public DynCastPtrConverter<T, OMPClause> {};
566struct DynTypedNode::BaseConverter<
567 T,
std::enable_if_t<std::is_base_of<Attr, T>::value>>
568 :
public DynCastPtrConverter<T, Attr> {};
572 :
public ValueConverter<NestedNameSpecifier> {};
575struct DynTypedNode::BaseConverter<
579struct DynTypedNode::BaseConverter<
584 :
public ValueConverter<TemplateArgumentLoc> {};
588 :
public ValueConverter<LambdaCapture> {};
591struct DynTypedNode::BaseConverter<
592 TemplateName, void> :
public ValueConverter<TemplateName> {};
595struct DynTypedNode::BaseConverter<
597 void> :
public ValueConverter<NestedNameSpecifierLoc> {};
601 void> :
public ValueConverter<QualType> {};
604struct DynTypedNode::BaseConverter<
605 T,
std::enable_if_t<std::is_base_of<TypeLoc, T>::value>>
606 :
public DynCastValueConverter<T, TypeLoc> {};
610 :
public PtrConverter<CXXBaseSpecifier> {};
614 :
public ValueConverter<ObjCProtocolLoc> {};
618 :
public PtrConverter<ConceptReference> {};
622 :
public PtrConverter<OffsetOfNode> {};
628template <
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.
A reference to a concept and its template args, as it appears in the code.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
A dynamically typed AST node container.
bool operator<(const DynTypedNode &Other) const
ASTNodeKind getNodeKind() const
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.
SourceRange getSourceRange(bool IncludeQualifier=false) const
For nodes which represent textual entities in the source code, return their SourceRange.
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.
ObjCProtocolDecl * getProtocol() const
Helper class for OffsetOfExpr.
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
Top level wrappers for InstallAPI frontend operations.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
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.
@ Result
The result type of a method or function.
const FunctionProtoType * T
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
U cast(CodeGen::Address addr)
Diagnostic wrappers for TextAPI types for error reporting.
hash_code hash_value(const clang::dependencies::ModuleID &ID)
Hooks for using ASTNodeKind as a key in a DenseMap.
static unsigned getHashValue(const ASTNodeKind &Val)
static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS)
Hooks for using DynTypedNode as a key in a DenseMap.
static unsigned getHashValue(const DynTypedNode &Val)
static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS)
Describes how types, statements, expressions, and declarations should be printed.