15 #ifndef LLVM_CLANG_AST_ASTTYPETRAITS_H 16 #define LLVM_CLANG_AST_ASTTYPETRAITS_H 23 #include "llvm/ADT/DenseMapInfo.h" 24 #include "llvm/Support/AlignOf.h" 34 struct PrintingPolicy;
36 namespace ast_type_traits {
78 return KindId != NKI_None && KindId == Other.KindId;
82 bool isNone()
const {
return KindId == NKI_None; }
87 bool isBaseOf(
ASTNodeKind Other,
unsigned *Distance =
nullptr)
const;
90 StringRef asStringRef()
const;
94 return KindId < Other.KindId;
119 return LHS.KindId == RHS.KindId;
126 return KindId > NKI_LastKindWithoutPointerIdentity;
135 NKI_TemplateArgument,
137 NKI_NestedNameSpecifierLoc,
140 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
141 NKI_CXXCtorInitializer,
142 NKI_NestedNameSpecifier,
144 #define DECL(DERIVED, BASE) NKI_##DERIVED##Decl, 145 #include "clang/AST/DeclNodes.inc" 147 #define STMT(DERIVED, BASE) NKI_##DERIVED, 148 #include "clang/AST/StmtNodes.inc" 150 #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type, 151 #include "clang/AST/TypeNodes.inc" 153 #define OPENMP_CLAUSE(TextualSpelling, Class) NKI_##Class, 154 #include "clang/Basic/OpenMPKinds.def" 165 static bool isBaseOf(NodeKindId
Base, NodeKindId Derived,
unsigned *Distance);
170 template <
class T>
struct KindToKindId {
171 static const NodeKindId
Id = NKI_None;
174 struct KindToKindId<const T> : KindToKindId<T> {};
183 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
188 #define KIND_TO_KIND_ID(Class) \ 189 template <> struct ASTNodeKind::KindToKindId<Class> { \ 190 static const NodeKindId Id = NKI_##Class; \ 203 #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl) 204 #include "clang/AST/DeclNodes.inc" 205 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED) 206 #include "clang/AST/StmtNodes.inc" 207 #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type) 208 #include "clang/AST/TypeNodes.inc" 209 #define OPENMP_CLAUSE(TextualSpelling, Class) KIND_TO_KIND_ID(Class) 210 #include "clang/Basic/OpenMPKinds.def" 211 #undef KIND_TO_KIND_ID 233 template <
typename T>
250 template <
typename T>
251 const T *
get()
const {
252 return BaseConverter<T>::get(
NodeKind, Storage.buffer);
258 template <
typename T>
260 return BaseConverter<T>::getUnchecked(
NodeKind, Storage.buffer);
271 return NodeKind.hasPointerIdentity()
272 ? *
reinterpret_cast<void *
const *
>(Storage.buffer)
293 if (!
NodeKind.isSame(Other.NodeKind))
296 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(
NodeKind))
297 return getUnchecked<QualType>().getAsOpaquePtr() <
300 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(
NodeKind)) {
301 auto TLA = getUnchecked<TypeLoc>();
303 return std::make_pair(TLA.getType().getAsOpaquePtr(),
304 TLA.getOpaqueData()) <
305 std::make_pair(TLB.getType().getAsOpaquePtr(),
306 TLB.getOpaqueData());
309 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
311 auto NNSLA = getUnchecked<NestedNameSpecifierLoc>();
313 return std::make_pair(NNSLA.getNestedNameSpecifier(),
314 NNSLA.getOpaqueData()) <
315 std::make_pair(NNSLB.getNestedNameSpecifier(),
316 NNSLB.getOpaqueData());
325 if (!
NodeKind.isSame(Other.NodeKind))
329 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(
NodeKind))
332 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(
NodeKind))
335 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
NodeKind))
336 return getUnchecked<NestedNameSpecifierLoc>() ==
351 Node.NodeKind = ASTNodeKind::DenseMapInfo::getEmptyKey();
356 Node.NodeKind = ASTNodeKind::DenseMapInfo::getTombstoneKey();
361 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isSame(Val.NodeKind)) {
367 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
371 NNSL.getOpaqueData());
378 auto Empty = ASTNodeKind::DenseMapInfo::getEmptyKey();
379 auto TombStone = ASTNodeKind::DenseMapInfo::getTombstoneKey();
380 return (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, Empty) &&
381 ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, Empty)) ||
382 (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, TombStone) &&
383 ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, TombStone)) ||
390 template <
typename T,
typename EnablerT =
void>
struct BaseConverter;
393 template <
typename T,
typename BaseT>
struct DynCastPtrConverter {
395 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
396 return &getUnchecked(NodeKind, Storage);
399 static const T &getUnchecked(
ASTNodeKind NodeKind,
const char Storage[]) {
400 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
401 return *cast<T>(
static_cast<const BaseT *
>(
402 *
reinterpret_cast<const void *
const *
>(Storage)));
406 Result.NodeKind = ASTNodeKind::getFromNode(Node);
407 new (Result.Storage.buffer)
const void *(&Node);
413 template <
typename T>
struct PtrConverter {
415 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
416 return &getUnchecked(NodeKind, Storage);
419 static const T &getUnchecked(
ASTNodeKind NodeKind,
const char Storage[]) {
420 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
421 return *
static_cast<const T *
>(
422 *
reinterpret_cast<const void *
const *
>(Storage));
426 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
427 new (Result.Storage.buffer)
const void *(&Node);
433 template <
typename T>
struct ValueConverter {
435 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
436 return reinterpret_cast<const T *>(Storage);
439 static const T &getUnchecked(
ASTNodeKind NodeKind,
const char Storage[]) {
440 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
441 return *
reinterpret_cast<const T *
>(Storage);
445 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
446 new (Result.Storage.buffer) T(Node);
466 template <
typename T>
467 struct DynTypedNode::BaseConverter<
468 T, typename
std::enable_if<std::is_base_of<Decl, T>::value>
::type>
469 :
public DynCastPtrConverter<T, Decl> {};
471 template <
typename T>
472 struct DynTypedNode::BaseConverter<
473 T, typename std::enable_if<std::is_base_of<Stmt, T>::value>
::type>
474 :
public DynCastPtrConverter<T, Stmt> {};
476 template <
typename T>
477 struct DynTypedNode::BaseConverter<
478 T, typename std::enable_if<std::is_base_of<Type, T>::value>
::type>
479 :
public DynCastPtrConverter<T, Type> {};
481 template <
typename T>
482 struct DynTypedNode::BaseConverter<
483 T, typename std::enable_if<std::is_base_of<OMPClause, T>::value>
::type>
484 :
public DynCastPtrConverter<T, OMPClause> {};
487 struct DynTypedNode::BaseConverter<
491 struct DynTypedNode::BaseConverter<
495 struct DynTypedNode::BaseConverter<
499 struct DynTypedNode::BaseConverter<
500 TemplateName, void> :
public ValueConverter<TemplateName> {};
503 struct DynTypedNode::BaseConverter<
505 void> :
public ValueConverter<NestedNameSpecifierLoc> {};
509 void> :
public ValueConverter<QualType> {};
512 struct DynTypedNode::BaseConverter<
513 TypeLoc, void> :
public ValueConverter<TypeLoc> {};
519 template <
typename T,
typename EnablerT>
struct DynTypedNode::BaseConverter {
bool operator<(const ASTNodeKind &Other) const
Strict weak ordering for ASTNodeKind.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
A (possibly-)qualified type.
bool operator==(CanQual< T > x, CanQual< U > y)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
static ASTNodeKind getTombstoneKey()
Stmt - This represents one statement.
static ASTNodeKind getEmptyKey()
StringRef asStringRef() const
String representation of the kind.
Decl - This represents one declaration (or definition), e.g.
bool operator==(const DynTypedNode &Other) const
The base class of the type hierarchy.
bool isSame(ASTNodeKind Other) const
Returns true if this and Other represent the same kind.
static DynTypedNode getTombstoneKey()
Describes how types, statements, expressions, and declarations should be printed. ...
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Base wrapper for a particular "section" of type source info.
A C++ nested-name-specifier augmented with source location information.
Will traverse all child nodes.
ASTNodeKind()
Empty identifier. It matches nothing.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Forward declaration of all AST node types.
ASTNodeKind getNodeKind() const
static unsigned getHashValue(const DynTypedNode &Val)
Hooks for using ASTNodeKind as a key in a DenseMap.
bool hasPointerIdentity() const
Check if the given ASTNodeKind identifies a type that offers pointer identity.
Will not traverse implicit casts and parentheses.
llvm::hash_code hash_value(const clang::SanitizerMask &Arg)
Ignore AST nodes not written in the source.
Represents a C++ template name within the type system.
Defines the clang::TypeLoc interface and its subclasses.
NodeKind
A kind of a syntax node, used for implementing casts.
#define KIND_TO_KIND_ID(Class)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This is a basic class for representing single OpenMP clause.
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
static unsigned getHashValue(const ASTNodeKind &Val)
ast_type_traits::DynTypedNode DynTypedNode
ast_type_traits::DynTypedNode Node
Represents a template argument.
Dataflow Directional Tag Classes.
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.
bool isNone() const
Returns true only for the default ASTNodeKind()
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
bool operator<(const DynTypedNode &Other) const
static raw_ostream & operator<<(raw_ostream &Out, BindingKey K)
const T & getUnchecked() const
Retrieve the stored node as type T.
static DynTypedNode getEmptyKey()
bool operator!=(const DynTypedNode &Other) const
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)
This class handles loading and caching of source files into memory.
const void * getMemoizationData() const
Returns a pointer that identifies the stored AST node.
static ASTNodeKind getFromNodeKind()
Construct an identifier for T.