clang  14.0.0git
ASTTypeTraits.h
Go to the documentation of this file.
1 //===--- ASTTypeTraits.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Provides a dynamic type identifier and a dynamically typed node container
10 // that can be used to store an AST base node at runtime in the same storage in
11 // a type safe way.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_ASTTYPETRAITS_H
16 #define LLVM_CLANG_AST_ASTTYPETRAITS_H
17 
18 #include "clang/AST/ASTFwd.h"
19 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/TemplateBase.h"
22 #include "clang/AST/TypeLoc.h"
23 #include "clang/Basic/LLVM.h"
24 #include "llvm/ADT/DenseMapInfo.h"
25 #include "llvm/Support/AlignOf.h"
26 
27 namespace llvm {
28 class raw_ostream;
29 } // namespace llvm
30 
31 namespace clang {
32 
33 struct PrintingPolicy;
34 
35 /// Defines how we descend a level in the AST when we pass
36 /// through expressions.
38  /// Will traverse all child nodes.
40 
41  /// Ignore AST nodes not written in the source
43 };
44 
45 /// Kind identifier.
46 ///
47 /// It can be constructed from any node kind and allows for runtime type
48 /// hierarchy checks.
49 /// Use getFromNodeKind<T>() to construct them.
50 class ASTNodeKind {
51 public:
52  /// Empty identifier. It matches nothing.
53  ASTNodeKind() : KindId(NKI_None) {}
54 
55  /// Construct an identifier for T.
56  template <class T>
59  }
60 
61  /// \{
62  /// Construct an identifier for the dynamic type of the node
63  static ASTNodeKind getFromNode(const Decl &D);
64  static ASTNodeKind getFromNode(const Stmt &S);
65  static ASTNodeKind getFromNode(const Type &T);
66  static ASTNodeKind getFromNode(const TypeLoc &T);
67  static ASTNodeKind getFromNode(const OMPClause &C);
68  static ASTNodeKind getFromNode(const Attr &A);
69  /// \}
70 
71  /// Returns \c true if \c this and \c Other represent the same kind.
72  bool isSame(ASTNodeKind Other) const {
73  return KindId != NKI_None && KindId == Other.KindId;
74  }
75 
76  /// Returns \c true only for the default \c ASTNodeKind()
77  bool isNone() const { return KindId == NKI_None; }
78 
79  /// Returns \c true if \c this is a base kind of (or same as) \c Other.
80  /// \param Distance If non-null, used to return the distance between \c this
81  /// and \c Other in the class hierarchy.
82  bool isBaseOf(ASTNodeKind Other, unsigned *Distance = nullptr) const;
83 
84  /// String representation of the kind.
85  StringRef asStringRef() const;
86 
87  /// Strict weak ordering for ASTNodeKind.
88  bool operator<(const ASTNodeKind &Other) const {
89  return KindId < Other.KindId;
90  }
91 
92  /// Return the most derived type between \p Kind1 and \p Kind2.
93  ///
94  /// Return ASTNodeKind() if they are not related.
96 
97  /// Return the most derived common ancestor between Kind1 and Kind2.
98  ///
99  /// Return ASTNodeKind() if they are not related.
101  ASTNodeKind Kind2);
102 
103  ASTNodeKind getCladeKind() const;
104 
105  /// Hooks for using ASTNodeKind as a key in a DenseMap.
106  struct DenseMapInfo {
107  // ASTNodeKind() is a good empty key because it is represented as a 0.
108  static inline ASTNodeKind getEmptyKey() { return ASTNodeKind(); }
109  // NKI_NumberOfKinds is not a valid value, so it is good for a
110  // tombstone key.
111  static inline ASTNodeKind getTombstoneKey() {
112  return ASTNodeKind(NKI_NumberOfKinds);
113  }
114  static unsigned getHashValue(const ASTNodeKind &Val) { return Val.KindId; }
115  static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS) {
116  return LHS.KindId == RHS.KindId;
117  }
118  };
119 
120  /// Check if the given ASTNodeKind identifies a type that offers pointer
121  /// identity. This is useful for the fast path in DynTypedNode.
122  bool hasPointerIdentity() const {
123  return KindId > NKI_LastKindWithoutPointerIdentity;
124  }
125 
126 private:
127  /// Kind ids.
128  ///
129  /// Includes all possible base and derived kinds.
130  enum NodeKindId {
131  NKI_None,
132  NKI_TemplateArgument,
133  NKI_TemplateArgumentLoc,
134  NKI_TemplateName,
135  NKI_NestedNameSpecifierLoc,
136  NKI_QualType,
137 #define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
138 #include "clang/AST/TypeLocNodes.def"
139  NKI_TypeLoc,
140  NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
141  NKI_CXXBaseSpecifier,
142  NKI_CXXCtorInitializer,
143  NKI_NestedNameSpecifier,
144  NKI_Decl,
145 #define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
146 #include "clang/AST/DeclNodes.inc"
147  NKI_Stmt,
148 #define STMT(DERIVED, BASE) NKI_##DERIVED,
149 #include "clang/AST/StmtNodes.inc"
150  NKI_Type,
151 #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
152 #include "clang/AST/TypeNodes.inc"
153  NKI_OMPClause,
154 #define GEN_CLANG_CLAUSE_CLASS
155 #define CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
156 #include "llvm/Frontend/OpenMP/OMP.inc"
157  NKI_Attr,
158 #define ATTR(A) NKI_##A##Attr,
159 #include "clang/Basic/AttrList.inc"
160  NKI_NumberOfKinds
161  };
162 
163  /// Use getFromNodeKind<T>() to construct the kind.
164  ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
165 
166  /// Returns \c true if \c Base is a base kind of (or same as) \c
167  /// Derived.
168  /// \param Distance If non-null, used to return the distance between \c Base
169  /// and \c Derived in the class hierarchy.
170  static bool isBaseOf(NodeKindId Base, NodeKindId Derived, unsigned *Distance);
171 
172  /// Helper meta-function to convert a kind T to its enum value.
173  ///
174  /// This struct is specialized below for all known kinds.
175  template <class T> struct KindToKindId {
176  static const NodeKindId Id = NKI_None;
177  };
178  template <class T>
179  struct KindToKindId<const T> : KindToKindId<T> {};
180 
181  /// Per kind info.
182  struct KindInfo {
183  /// The id of the parent kind, or None if it has no parent.
184  NodeKindId ParentId;
185  /// Name of the kind.
186  const char *Name;
187  };
188  static const KindInfo AllKindInfo[NKI_NumberOfKinds];
189 
190  NodeKindId KindId;
191 };
192 
193 #define KIND_TO_KIND_ID(Class) \
194  template <> struct ASTNodeKind::KindToKindId<Class> { \
195  static const NodeKindId Id = NKI_##Class; \
196  };
197 KIND_TO_KIND_ID(CXXCtorInitializer)
198 KIND_TO_KIND_ID(TemplateArgument)
199 KIND_TO_KIND_ID(TemplateArgumentLoc)
200 KIND_TO_KIND_ID(TemplateName)
201 KIND_TO_KIND_ID(NestedNameSpecifier)
202 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
203 KIND_TO_KIND_ID(QualType)
204 #define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
205 #include "clang/AST/TypeLocNodes.def"
206 KIND_TO_KIND_ID(TypeLoc)
207 KIND_TO_KIND_ID(Decl)
208 KIND_TO_KIND_ID(Stmt)
209 KIND_TO_KIND_ID(Type)
210 KIND_TO_KIND_ID(OMPClause)
211 KIND_TO_KIND_ID(Attr)
212 KIND_TO_KIND_ID(CXXBaseSpecifier)
213 #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
214 #include "clang/AST/DeclNodes.inc"
215 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
216 #include "clang/AST/StmtNodes.inc"
217 #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
218 #include "clang/AST/TypeNodes.inc"
219 #define GEN_CLANG_CLAUSE_CLASS
220 #define CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
221 #include "llvm/Frontend/OpenMP/OMP.inc"
222 #define ATTR(A) KIND_TO_KIND_ID(A##Attr)
223 #include "clang/Basic/AttrList.inc"
224 #undef KIND_TO_KIND_ID
225 
226 inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) {
227  OS << K.asStringRef();
228  return OS;
229 }
230 
231 /// A dynamically typed AST node container.
232 ///
233 /// Stores an AST node in a type safe way. This allows writing code that
234 /// works with different kinds of AST nodes, despite the fact that they don't
235 /// have a common base class.
236 ///
237 /// Use \c create(Node) to create a \c DynTypedNode from an AST node,
238 /// and \c get<T>() to retrieve the node as type T if the types match.
239 ///
240 /// See \c ASTNodeKind for which node base types are currently supported;
241 /// You can create DynTypedNodes for all nodes in the inheritance hierarchy of
242 /// the supported base types.
244 public:
245  /// Creates a \c DynTypedNode from \c Node.
246  template <typename T>
247  static DynTypedNode create(const T &Node) {
249  }
250 
251  /// Retrieve the stored node as type \c T.
252  ///
253  /// Returns NULL if the stored node does not have a type that is
254  /// convertible to \c T.
255  ///
256  /// For types that have identity via their pointer in the AST
257  /// (like \c Stmt, \c Decl, \c Type and \c NestedNameSpecifier) the returned
258  /// pointer points to the referenced AST node.
259  /// For other types (like \c QualType) the value is stored directly
260  /// in the \c DynTypedNode, and the returned pointer points at
261  /// the storage inside DynTypedNode. For those nodes, do not
262  /// use the pointer outside the scope of the DynTypedNode.
263  template <typename T> const T *get() const {
264  return BaseConverter<T>::get(NodeKind, &Storage);
265  }
266 
267  /// Retrieve the stored node as type \c T.
268  ///
269  /// Similar to \c get(), but asserts that the type is what we are expecting.
270  template <typename T>
271  const T &getUnchecked() const {
272  return BaseConverter<T>::getUnchecked(NodeKind, &Storage);
273  }
274 
275  ASTNodeKind getNodeKind() const { return NodeKind; }
276 
277  /// Returns a pointer that identifies the stored AST node.
278  ///
279  /// Note that this is not supported by all AST nodes. For AST nodes
280  /// that don't have a pointer-defined identity inside the AST, this
281  /// method returns NULL.
282  const void *getMemoizationData() const {
283  return NodeKind.hasPointerIdentity()
284  ? *reinterpret_cast<void *const *>(&Storage)
285  : nullptr;
286  }
287 
288  /// Prints the node to the given output stream.
289  void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const;
290 
291  /// Dumps the node to the given output stream.
292  void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
293 
294  /// For nodes which represent textual entities in the source code,
295  /// return their SourceRange. For all other nodes, return SourceRange().
296  SourceRange getSourceRange() const;
297 
298  /// @{
299  /// Imposes an order on \c DynTypedNode.
300  ///
301  /// Supports comparison of nodes that support memoization.
302  /// FIXME: Implement comparison for other node types (currently
303  /// only Stmt, Decl, Type and NestedNameSpecifier return memoization data).
304  bool operator<(const DynTypedNode &Other) const {
305  if (!NodeKind.isSame(Other.NodeKind))
306  return NodeKind < Other.NodeKind;
307 
308  if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
309  return getUnchecked<QualType>().getAsOpaquePtr() <
310  Other.getUnchecked<QualType>().getAsOpaquePtr();
311 
312  if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind)) {
313  auto TLA = getUnchecked<TypeLoc>();
314  auto TLB = Other.getUnchecked<TypeLoc>();
315  return std::make_pair(TLA.getType().getAsOpaquePtr(),
316  TLA.getOpaqueData()) <
317  std::make_pair(TLB.getType().getAsOpaquePtr(),
318  TLB.getOpaqueData());
319  }
320 
321  if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
322  NodeKind)) {
323  auto NNSLA = getUnchecked<NestedNameSpecifierLoc>();
324  auto NNSLB = Other.getUnchecked<NestedNameSpecifierLoc>();
325  return std::make_pair(NNSLA.getNestedNameSpecifier(),
326  NNSLA.getOpaqueData()) <
327  std::make_pair(NNSLB.getNestedNameSpecifier(),
328  NNSLB.getOpaqueData());
329  }
330 
331  assert(getMemoizationData() && Other.getMemoizationData());
332  return getMemoizationData() < Other.getMemoizationData();
333  }
334  bool operator==(const DynTypedNode &Other) const {
335  // DynTypedNode::create() stores the exact kind of the node in NodeKind.
336  // If they contain the same node, their NodeKind must be the same.
337  if (!NodeKind.isSame(Other.NodeKind))
338  return false;
339 
340  // FIXME: Implement for other types.
341  if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
342  return getUnchecked<QualType>() == Other.getUnchecked<QualType>();
343 
344  if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind))
345  return getUnchecked<TypeLoc>() == Other.getUnchecked<TypeLoc>();
346 
347  if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(NodeKind))
348  return getUnchecked<NestedNameSpecifierLoc>() ==
350 
351  assert(getMemoizationData() && Other.getMemoizationData());
352  return getMemoizationData() == Other.getMemoizationData();
353  }
354  bool operator!=(const DynTypedNode &Other) const {
355  return !operator==(Other);
356  }
357  /// @}
358 
359  /// Hooks for using DynTypedNode as a key in a DenseMap.
360  struct DenseMapInfo {
361  static inline DynTypedNode getEmptyKey() {
364  return Node;
365  }
366  static inline DynTypedNode getTombstoneKey() {
369  return Node;
370  }
371  static unsigned getHashValue(const DynTypedNode &Val) {
372  // FIXME: Add hashing support for the remaining types.
373  if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(Val.NodeKind)) {
374  auto TL = Val.getUnchecked<TypeLoc>();
375  return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
376  TL.getOpaqueData());
377  }
378 
379  if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
380  Val.NodeKind)) {
381  auto NNSL = Val.getUnchecked<NestedNameSpecifierLoc>();
382  return llvm::hash_combine(NNSL.getNestedNameSpecifier(),
383  NNSL.getOpaqueData());
384  }
385 
386  assert(Val.getMemoizationData());
387  return llvm::hash_value(Val.getMemoizationData());
388  }
389  static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS) {
392  return (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, Empty) &&
393  ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, Empty)) ||
394  (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, TombStone) &&
395  ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, TombStone)) ||
396  LHS == RHS;
397  }
398  };
399 
400 private:
401  /// Takes care of converting from and to \c T.
402  template <typename T, typename EnablerT = void> struct BaseConverter;
403 
404  /// Converter that uses dyn_cast<T> from a stored BaseT*.
405  template <typename T, typename BaseT> struct DynCastPtrConverter {
406  static const T *get(ASTNodeKind NodeKind, const void *Storage) {
407  if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
408  return &getUnchecked(NodeKind, Storage);
409  return nullptr;
410  }
411  static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
412  assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
413  return *cast<T>(static_cast<const BaseT *>(
414  *reinterpret_cast<const void *const *>(Storage)));
415  }
416  static DynTypedNode create(const BaseT &Node) {
417  DynTypedNode Result;
418  Result.NodeKind = ASTNodeKind::getFromNode(Node);
419  new (&Result.Storage) const void *(&Node);
420  return Result;
421  }
422  };
423 
424  /// Converter that stores T* (by pointer).
425  template <typename T> struct PtrConverter {
426  static const T *get(ASTNodeKind NodeKind, const void *Storage) {
427  if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
428  return &getUnchecked(NodeKind, Storage);
429  return nullptr;
430  }
431  static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
432  assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
433  return *static_cast<const T *>(
434  *reinterpret_cast<const void *const *>(Storage));
435  }
436  static DynTypedNode create(const T &Node) {
437  DynTypedNode Result;
438  Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
439  new (&Result.Storage) const void *(&Node);
440  return Result;
441  }
442  };
443 
444  /// Converter that stores T (by value).
445  template <typename T> struct ValueConverter {
446  static const T *get(ASTNodeKind NodeKind, const void *Storage) {
447  if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
448  return reinterpret_cast<const T *>(Storage);
449  return nullptr;
450  }
451  static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
452  assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind));
453  return *reinterpret_cast<const T *>(Storage);
454  }
455  static DynTypedNode create(const T &Node) {
456  DynTypedNode Result;
457  Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
458  new (&Result.Storage) T(Node);
459  return Result;
460  }
461  };
462 
463  /// Converter that stores nodes by value. It must be possible to dynamically
464  /// cast the stored node within a type hierarchy without breaking (especially
465  /// through slicing).
466  template <typename T, typename BaseT,
467  typename = std::enable_if_t<(sizeof(T) == sizeof(BaseT))>>
468  struct DynCastValueConverter {
469  static const T *get(ASTNodeKind NodeKind, const void *Storage) {
470  if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
471  return &getUnchecked(NodeKind, Storage);
472  return nullptr;
473  }
474  static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
475  assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
476  return *static_cast<const T *>(reinterpret_cast<const BaseT *>(Storage));
477  }
478  static DynTypedNode create(const T &Node) {
479  DynTypedNode Result;
480  Result.NodeKind = ASTNodeKind::getFromNode(Node);
481  new (&Result.Storage) T(Node);
482  return Result;
483  }
484  };
485 
486  ASTNodeKind NodeKind;
487 
488  /// Stores the data of the node.
489  ///
490  /// Note that we can store \c Decls, \c Stmts, \c Types,
491  /// \c NestedNameSpecifiers and \c CXXCtorInitializer by pointer as they are
492  /// guaranteed to be unique pointers pointing to dedicated storage in the AST.
493  /// \c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs,
494  /// \c TemplateArguments and \c TemplateArgumentLocs on the other hand do not
495  /// have storage or unique pointers and thus need to be stored by value.
496  llvm::AlignedCharArrayUnion<const void *, TemplateArgument,
497  TemplateArgumentLoc, NestedNameSpecifierLoc,
498  QualType, TypeLoc>
499  Storage;
500 };
501 
502 template <typename T>
503 struct DynTypedNode::BaseConverter<
504  T, std::enable_if_t<std::is_base_of<Decl, T>::value>>
505  : public DynCastPtrConverter<T, Decl> {};
506 
507 template <typename T>
508 struct DynTypedNode::BaseConverter<
509  T, std::enable_if_t<std::is_base_of<Stmt, T>::value>>
510  : public DynCastPtrConverter<T, Stmt> {};
511 
512 template <typename T>
513 struct DynTypedNode::BaseConverter<
514  T, std::enable_if_t<std::is_base_of<Type, T>::value>>
515  : public DynCastPtrConverter<T, Type> {};
516 
517 template <typename T>
518 struct DynTypedNode::BaseConverter<
519  T, std::enable_if_t<std::is_base_of<OMPClause, T>::value>>
520  : public DynCastPtrConverter<T, OMPClause> {};
521 
522 template <typename T>
523 struct DynTypedNode::BaseConverter<
524  T, std::enable_if_t<std::is_base_of<Attr, T>::value>>
525  : public DynCastPtrConverter<T, Attr> {};
526 
527 template <>
528 struct DynTypedNode::BaseConverter<
529  NestedNameSpecifier, void> : public PtrConverter<NestedNameSpecifier> {};
530 
531 template <>
532 struct DynTypedNode::BaseConverter<
533  CXXCtorInitializer, void> : public PtrConverter<CXXCtorInitializer> {};
534 
535 template <>
536 struct DynTypedNode::BaseConverter<
537  TemplateArgument, void> : public ValueConverter<TemplateArgument> {};
538 
539 template <>
540 struct DynTypedNode::BaseConverter<TemplateArgumentLoc, void>
541  : public ValueConverter<TemplateArgumentLoc> {};
542 
543 template <>
544 struct DynTypedNode::BaseConverter<
545  TemplateName, void> : public ValueConverter<TemplateName> {};
546 
547 template <>
548 struct DynTypedNode::BaseConverter<
550  void> : public ValueConverter<NestedNameSpecifierLoc> {};
551 
552 template <>
553 struct DynTypedNode::BaseConverter<QualType,
554  void> : public ValueConverter<QualType> {};
555 
556 template <typename T>
557 struct DynTypedNode::BaseConverter<
558  T, std::enable_if_t<std::is_base_of<TypeLoc, T>::value>>
559  : public DynCastValueConverter<T, TypeLoc> {};
560 
561 template <>
562 struct DynTypedNode::BaseConverter<CXXBaseSpecifier, void>
563  : public PtrConverter<CXXBaseSpecifier> {};
564 
565 // The only operation we allow on unsupported types is \c get.
566 // This allows to conveniently use \c DynTypedNode when having an arbitrary
567 // AST node that is not supported, but prevents misuse - a user cannot create
568 // a DynTypedNode from arbitrary types.
569 template <typename T, typename EnablerT> struct DynTypedNode::BaseConverter {
570  static const T *get(ASTNodeKind NodeKind, const char Storage[]) {
571  return NULL;
572  }
573 };
574 
575 } // end namespace clang
576 
577 namespace llvm {
578 
579 template <>
581 
582 template <>
584 
585 } // end namespace llvm
586 
587 #endif
clang::DynTypedNode::getUnchecked
const T & getUnchecked() const
Retrieve the stored node as type T.
Definition: ASTTypeTraits.h:271
clang::TraversalKind
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
Definition: ASTTypeTraits.h:37
llvm
Definition: Dominators.h:30
clang::ASTNodeKind::isBaseOf
bool isBaseOf(ASTNodeKind Other, unsigned *Distance=nullptr) const
Returns true if this is a base kind of (or same as) Other.
Definition: ASTTypeTraits.cpp:56
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::DynTypedNode::DenseMapInfo::getHashValue
static unsigned getHashValue(const DynTypedNode &Val)
Definition: ASTTypeTraits.h:371
clang::DynTypedNode::dump
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const
Dumps the node to the given output stream.
Definition: ASTTypeTraits.cpp:199
clang::ASTNodeKind::getMostDerivedCommonAncestor
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived common ancestor between Kind1 and Kind2.
Definition: ASTTypeTraits.cpp:93
clang::DynTypedNode::operator<
bool operator<(const DynTypedNode &Other) const
Definition: ASTTypeTraits.h:304
NULL
#define NULL
Definition: stddef.h:89
clang::DynTypedNode::getSourceRange
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
Definition: ASTTypeTraits.cpp:211
clang::ASTNodeKind::hasPointerIdentity
bool hasPointerIdentity() const
Check if the given ASTNodeKind identifies a type that offers pointer identity.
Definition: ASTTypeTraits.h:122
clang::ASTNodeKind::DenseMapInfo::getHashValue
static unsigned getHashValue(const ASTNodeKind &Val)
Definition: ASTTypeTraits.h:114
clang::DynTypedNode::DenseMapInfo::getTombstoneKey
static DynTypedNode getTombstoneKey()
Definition: ASTTypeTraits.h:366
clang::DynTypedNode::create
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
Definition: ASTTypeTraits.h:247
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::NestedNameSpecifier
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Definition: NestedNameSpecifier.h:50
clang::DynTypedNode::DenseMapInfo::isEqual
static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS)
Definition: ASTTypeTraits.h:389
DeclCXX.h
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:59
clang::DynTypedNode::getMemoizationData
const void * getMemoizationData() const
Returns a pointer that identifies the stored AST node.
Definition: ASTTypeTraits.h:282
ASTFwd.h
clang::ASTNodeKind::ASTNodeKind
ASTNodeKind()
Empty identifier. It matches nothing.
Definition: ASTTypeTraits.h:53
clang::DynTypedNode::getNodeKind
ASTNodeKind getNodeKind() const
Definition: ASTTypeTraits.h:275
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
llvm::DenseMapInfo
Definition: TypeOrdering.h:37
clang::hash_value
llvm::hash_code hash_value(const clang::SanitizerMask &Arg)
Definition: Sanitizers.cpp:68
TemplateBase.h
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:67
clang::OMPClause
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:54
Id
int Id
Definition: ASTDiff.cpp:191
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
NestedNameSpecifier.h
clang::DynTypedNode::operator!=
bool operator!=(const DynTypedNode &Other) const
Definition: ASTTypeTraits.h:354
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:62
clang::TemplateArgumentLoc
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:458
clang::diff::DynTypedNode
DynTypedNode DynTypedNode
Definition: ASTDiffInternal.h:18
clang::ASTNodeKind::isNone
bool isNone() const
Returns true only for the default ASTNodeKind()
Definition: ASTTypeTraits.h:77
KIND_TO_KIND_ID
#define KIND_TO_KIND_ID(Class)
Definition: ASTTypeTraits.h:193
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
Base
clang::operator<<
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
Definition: ASTContext.cpp:11777
clang::ASTNodeKind::DenseMapInfo::getEmptyKey
static ASTNodeKind getEmptyKey()
Definition: ASTTypeTraits.h:108
clang::DynTypedNode::DenseMapInfo
Hooks for using DynTypedNode as a key in a DenseMap.
Definition: ASTTypeTraits.h:360
clang::format::hash_combine
static void hash_combine(std::size_t &seed, const T &v)
Definition: UnwrappedLineParser.cpp:579
clang::ASTNodeKind::operator<
bool operator<(const ASTNodeKind &Other) const
Strict weak ordering for ASTNodeKind.
Definition: ASTTypeTraits.h:88
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:302
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:192
clang::TK_AsIs
@ TK_AsIs
Will traverse all child nodes.
Definition: ASTTypeTraits.h:39
clang::DynTypedNode::print
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
Definition: ASTTypeTraits.cpp:168
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
LLVM.h
clang::TK_IgnoreUnlessSpelledInSource
@ TK_IgnoreUnlessSpelledInSource
Ignore AST nodes not written in the source.
Definition: ASTTypeTraits.h:42
std
Definition: Format.h:4034
clang::ASTNodeKind
Kind identifier.
Definition: ASTTypeTraits.h:50
clang::DynTypedNode::operator==
bool operator==(const DynTypedNode &Other) const
Definition: ASTTypeTraits.h:334
clang
Definition: CalledOnceCheck.h:17
clang::syntax::NodeKind
NodeKind
A kind of a syntax node, used for implementing casts.
Definition: Nodes.h:37
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::ASTNodeKind::getFromNodeKind
static ASTNodeKind getFromNodeKind()
Construct an identifier for T.
Definition: ASTTypeTraits.h:57
clang::CXXBaseSpecifier
Represents a base class of a C++ class.
Definition: DeclCXX.h:147
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:46
clang::DynTypedNode::get
const T * get() const
Retrieve the stored node as type T.
Definition: ASTTypeTraits.h:263
clang::DynTypedNode
A dynamically typed AST node container.
Definition: ASTTypeTraits.h:243
clang::ASTNodeKind::isSame
bool isSame(ASTNodeKind Other) const
Returns true if this and Other represent the same kind.
Definition: ASTTypeTraits.h:72
clang::DynTypedNode::DenseMapInfo::getEmptyKey
static DynTypedNode getEmptyKey()
Definition: ASTTypeTraits.h:361
clang::ASTNodeKind::getMostDerivedType
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
Definition: ASTTypeTraits.cpp:86
clang::CXXCtorInitializer
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2172
clang::ASTNodeKind::DenseMapInfo
Hooks for using ASTNodeKind as a key in a DenseMap.
Definition: ASTTypeTraits.h:106
clang::ASTNodeKind::getCladeKind
ASTNodeKind getCladeKind() const
Definition: ASTTypeTraits.cpp:73
clang::ASTNodeKind::DenseMapInfo::getTombstoneKey
static ASTNodeKind getTombstoneKey()
Definition: ASTTypeTraits.h:111
clang::ASTNodeKind::asStringRef
StringRef asStringRef() const
String representation of the kind.
Definition: ASTTypeTraits.cpp:84
clang::ASTNodeKind::getFromNode
static ASTNodeKind getFromNode(const Decl &D)
Definition: ASTTypeTraits.cpp:102
TypeLoc.h
clang::ASTNodeKind::DenseMapInfo::isEqual
static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS)
Definition: ASTTypeTraits.h:115