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;
115 NKI_CXXCtorInitializer,
116 NKI_TemplateArgument,
117 NKI_NestedNameSpecifier,
118 NKI_NestedNameSpecifierLoc,
122 #define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
123 #include "clang/AST/DeclNodes.inc"
125 #define STMT(DERIVED, BASE) NKI_##DERIVED,
126 #include "clang/AST/StmtNodes.inc"
128 #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
129 #include "clang/AST/TypeNodes.def"
140 static bool isBaseOf(NodeKindId
Base, NodeKindId Derived,
unsigned *Distance);
145 template <
class T>
struct KindToKindId {
146 static const NodeKindId Id = NKI_None;
149 struct KindToKindId<const T> : KindToKindId<T> {};
158 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
163 #define KIND_TO_KIND_ID(Class) \
164 template <> struct ASTNodeKind::KindToKindId<Class> { \
165 static const NodeKindId Id = NKI_##Class; \
176 #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
177 #include "clang/AST/DeclNodes.inc"
178 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
179 #include "clang/AST/StmtNodes.inc"
180 #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
181 #include "clang/AST/TypeNodes.def"
182 #undef KIND_TO_KIND_ID
204 template <
typename T>
221 template <
typename T>
222 const T *
get()
const {
223 return BaseConverter<T>::get(NodeKind, Storage.buffer);
229 template <
typename T>
231 return BaseConverter<T>::getUnchecked(NodeKind, Storage.buffer);
266 if (!NodeKind.
isSame(Other.NodeKind))
270 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
283 template <
typename T,
typename EnablerT =
void>
struct BaseConverter;
286 template <
typename T,
typename BaseT>
struct DynCastPtrConverter {
287 static const T *
get(
ASTNodeKind NodeKind,
const char Storage[]) {
288 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
289 return cast<T>(*reinterpret_cast<BaseT *const *>(Storage));
292 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
293 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
294 return *cast<T>(*
reinterpret_cast<BaseT *
const *
>(Storage));
296 static DynTypedNode
create(
const BaseT &
Node) {
299 Result.MemoizationData = &
Node;
300 new (Result.Storage.buffer)
const BaseT * (&Node);
306 template <
typename T>
struct PtrConverter {
307 static const T *
get(ASTNodeKind NodeKind,
const char Storage[]) {
308 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
309 return *reinterpret_cast<T *const *>(Storage);
312 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
313 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
314 return **
reinterpret_cast<T *
const *
>(Storage);
318 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
319 Result.MemoizationData = &
Node;
320 new (Result.Storage.buffer)
const T * (&Node);
326 template <
typename T>
struct ValueConverter {
327 static const T *
get(ASTNodeKind NodeKind,
const char Storage[]) {
328 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
329 return reinterpret_cast<const T *>(Storage);
332 static const T &
getUnchecked(ASTNodeKind NodeKind,
const char Storage[]) {
333 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
334 return *
reinterpret_cast<const T *
>(Storage);
338 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
339 Result.MemoizationData =
nullptr;
340 new (Result.Storage.buffer) T(Node);
345 ASTNodeKind NodeKind;
346 const void *MemoizationData;
356 typedef llvm::AlignedCharArrayUnion<
357 Decl *,
Stmt *, Type *, NestedNameSpecifier *, CXXCtorInitializer *>
359 llvm::AlignedCharArrayUnion<KindsByPointer, TemplateArgument,
360 NestedNameSpecifierLoc, QualType, TypeLoc>
364 template <
typename T>
365 struct DynTypedNode::BaseConverter<
366 T, typename std::enable_if<std::is_base_of<Decl, T>::value>
::type>
367 :
public DynCastPtrConverter<T, Decl> {};
369 template <
typename T>
370 struct DynTypedNode::BaseConverter<
371 T, typename std::enable_if<std::is_base_of<Stmt, T>::value>
::type>
372 :
public DynCastPtrConverter<T, Stmt> {};
374 template <
typename T>
375 struct DynTypedNode::BaseConverter<
376 T, typename std::enable_if<std::is_base_of<Type, T>::value>
::type>
377 :
public DynCastPtrConverter<T, Type> {};
380 struct DynTypedNode::BaseConverter<
384 struct DynTypedNode::BaseConverter<
388 struct DynTypedNode::BaseConverter<
392 struct DynTypedNode::BaseConverter<
394 void> :
public ValueConverter<NestedNameSpecifierLoc> {};
398 void> :
public ValueConverter<QualType> {};
401 struct DynTypedNode::BaseConverter<
402 TypeLoc, void> :
public ValueConverter<TypeLoc> {};
408 template <
typename T,
typename EnablerT>
struct DynTypedNode::BaseConverter {
409 static const T *
get(
ASTNodeKind NodeKind,
const char Storage[]) {
bool operator!=(const DynTypedNode &Other) const
static ASTNodeKind getFromNode(const Decl &D)
Construct an identifier for the dynamic type of the node.
static ASTNodeKind getTombstoneKey()
static ASTNodeKind getEmptyKey()
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.
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...
Forward declaration of all AST node types.
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
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.
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. For all other nodes, return SourceRange().
raw_ostream & operator<<(raw_ostream &OS, ASTNodeKind K)
A trivial tuple used to represent a source range.
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.