]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/AST/RecursiveASTVisitor.h
Vendor import of clang trunk r290819:
[FreeBSD/FreeBSD.git] / include / clang / AST / RecursiveASTVisitor.h
1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the RecursiveASTVisitor interface, which recursively
11 //  traverses the entire AST.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
16
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclarationName.h"
20 #include "clang/AST/DeclBase.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclFriend.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/DeclTemplate.h"
26 #include "clang/AST/Expr.h"
27 #include "clang/AST/ExprCXX.h"
28 #include "clang/AST/ExprObjC.h"
29 #include "clang/AST/ExprOpenMP.h"
30 #include "clang/AST/LambdaCapture.h"
31 #include "clang/AST/NestedNameSpecifier.h"
32 #include "clang/AST/OpenMPClause.h"
33 #include "clang/AST/Stmt.h"
34 #include "clang/AST/StmtCXX.h"
35 #include "clang/AST/StmtObjC.h"
36 #include "clang/AST/StmtOpenMP.h"
37 #include "clang/AST/TemplateBase.h"
38 #include "clang/AST/TemplateName.h"
39 #include "clang/AST/Type.h"
40 #include "clang/AST/TypeLoc.h"
41 #include "clang/Basic/LLVM.h"
42 #include "clang/Basic/OpenMPKinds.h"
43 #include "clang/Basic/Specifiers.h"
44 #include "llvm/ADT/PointerIntPair.h"
45 #include "llvm/ADT/SmallVector.h"
46 #include "llvm/Support/Casting.h"
47 #include <algorithm>
48 #include <cstddef>
49 #include <type_traits>
50
51 // The following three macros are used for meta programming.  The code
52 // using them is responsible for defining macro OPERATOR().
53
54 // All unary operators.
55 #define UNARYOP_LIST()                                                         \
56   OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec)        \
57       OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus)          \
58       OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag)               \
59       OPERATOR(Extension) OPERATOR(Coawait)
60
61 // All binary operators (excluding compound assign operators).
62 #define BINOP_LIST()                                                           \
63   OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div)              \
64       OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr)    \
65       OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ)         \
66       OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd)     \
67       OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
68
69 // All compound assign operators.
70 #define CAO_LIST()                                                             \
71   OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub)        \
72       OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
73
74 namespace clang {
75
76 // A helper macro to implement short-circuiting when recursing.  It
77 // invokes CALL_EXPR, which must be a method call, on the derived
78 // object (s.t. a user of RecursiveASTVisitor can override the method
79 // in CALL_EXPR).
80 #define TRY_TO(CALL_EXPR)                                                      \
81   do {                                                                         \
82     if (!getDerived().CALL_EXPR)                                               \
83       return false;                                                            \
84   } while (false)
85
86 /// \brief A class that does preordor or postorder
87 /// depth-first traversal on the entire Clang AST and visits each node.
88 ///
89 /// This class performs three distinct tasks:
90 ///   1. traverse the AST (i.e. go to each node);
91 ///   2. at a given node, walk up the class hierarchy, starting from
92 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
93 ///      Decl, or Type) is reached.
94 ///   3. given a (node, class) combination, where 'class' is some base
95 ///      class of the dynamic type of 'node', call a user-overridable
96 ///      function to actually visit the node.
97 ///
98 /// These tasks are done by three groups of methods, respectively:
99 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
100 ///      for traversing an AST rooted at x.  This method simply
101 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
102 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
103 ///      then recursively visits the child nodes of x.
104 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
105 ///      similarly.
106 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
107 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
108 ///      where Bar is the direct parent class of Foo (unless Foo has
109 ///      no parent), and then calls VisitFoo(x) (see the next list item).
110 ///   3. VisitFoo(Foo *x) does task #3.
111 ///
112 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
113 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
114 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
115 /// It may not call methods from a higher tier.
116 ///
117 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
118 /// is Foo's super class) before calling VisitFoo(), the result is
119 /// that the Visit*() methods for a given node are called in the
120 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
121 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
122 ///
123 /// This scheme guarantees that all Visit*() calls for the same AST
124 /// node are grouped together.  In other words, Visit*() methods for
125 /// different nodes are never interleaved.
126 ///
127 /// Clients of this visitor should subclass the visitor (providing
128 /// themselves as the template argument, using the curiously recurring
129 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
130 /// and Visit* methods for declarations, types, statements,
131 /// expressions, or other AST nodes where the visitor should customize
132 /// behavior.  Most users only need to override Visit*.  Advanced
133 /// users may override Traverse* and WalkUpFrom* to implement custom
134 /// traversal strategies.  Returning false from one of these overridden
135 /// functions will abort the entire traversal.
136 ///
137 /// By default, this visitor tries to visit every part of the explicit
138 /// source code exactly once.  The default policy towards templates
139 /// is to descend into the 'pattern' class or function body, not any
140 /// explicit or implicit instantiations.  Explicit specializations
141 /// are still visited, and the patterns of partial specializations
142 /// are visited separately.  This behavior can be changed by
143 /// overriding shouldVisitTemplateInstantiations() in the derived class
144 /// to return true, in which case all known implicit and explicit
145 /// instantiations will be visited at the same time as the pattern
146 /// from which they were produced.
147 ///
148 /// By default, this visitor preorder traverses the AST. If postorder traversal
149 /// is needed, the \c shouldTraversePostOrder method needs to be overriden
150 /// to return \c true.
151 template <typename Derived> class RecursiveASTVisitor {
152 public:
153   /// A queue used for performing data recursion over statements.
154   /// Parameters involving this type are used to implement data
155   /// recursion over Stmts and Exprs within this class, and should
156   /// typically not be explicitly specified by derived classes.
157   /// The bool bit indicates whether the statement has been traversed or not.
158   typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
159     DataRecursionQueue;
160
161   /// \brief Return a reference to the derived class.
162   Derived &getDerived() { return *static_cast<Derived *>(this); }
163
164   /// \brief Return whether this visitor should recurse into
165   /// template instantiations.
166   bool shouldVisitTemplateInstantiations() const { return false; }
167
168   /// \brief Return whether this visitor should recurse into the types of
169   /// TypeLocs.
170   bool shouldWalkTypesOfTypeLocs() const { return true; }
171
172   /// \brief Return whether this visitor should recurse into implicit
173   /// code, e.g., implicit constructors and destructors.
174   bool shouldVisitImplicitCode() const { return false; }
175
176   /// \brief Return whether this visitor should traverse post-order.
177   bool shouldTraversePostOrder() const { return false; }
178
179   /// \brief Recursively visit a statement or expression, by
180   /// dispatching to Traverse*() based on the argument's dynamic type.
181   ///
182   /// \returns false if the visitation was terminated early, true
183   /// otherwise (including when the argument is nullptr).
184   bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
185
186   /// Invoked before visiting a statement or expression via data recursion.
187   ///
188   /// \returns false to skip visiting the node, true otherwise.
189   bool dataTraverseStmtPre(Stmt *S) { return true; }
190
191   /// Invoked after visiting a statement or expression via data recursion.
192   /// This is not invoked if the previously invoked \c dataTraverseStmtPre
193   /// returned false.
194   ///
195   /// \returns false if the visitation was terminated early, true otherwise.
196   bool dataTraverseStmtPost(Stmt *S) { return true; }
197
198   /// \brief Recursively visit a type, by dispatching to
199   /// Traverse*Type() based on the argument's getTypeClass() property.
200   ///
201   /// \returns false if the visitation was terminated early, true
202   /// otherwise (including when the argument is a Null type).
203   bool TraverseType(QualType T);
204
205   /// \brief Recursively visit a type with location, by dispatching to
206   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
207   ///
208   /// \returns false if the visitation was terminated early, true
209   /// otherwise (including when the argument is a Null type location).
210   bool TraverseTypeLoc(TypeLoc TL);
211
212   /// \brief Recursively visit an attribute, by dispatching to
213   /// Traverse*Attr() based on the argument's dynamic type.
214   ///
215   /// \returns false if the visitation was terminated early, true
216   /// otherwise (including when the argument is a Null type location).
217   bool TraverseAttr(Attr *At);
218
219   /// \brief Recursively visit a declaration, by dispatching to
220   /// Traverse*Decl() based on the argument's dynamic type.
221   ///
222   /// \returns false if the visitation was terminated early, true
223   /// otherwise (including when the argument is NULL).
224   bool TraverseDecl(Decl *D);
225
226   /// \brief Recursively visit a C++ nested-name-specifier.
227   ///
228   /// \returns false if the visitation was terminated early, true otherwise.
229   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
230
231   /// \brief Recursively visit a C++ nested-name-specifier with location
232   /// information.
233   ///
234   /// \returns false if the visitation was terminated early, true otherwise.
235   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
236
237   /// \brief Recursively visit a name with its location information.
238   ///
239   /// \returns false if the visitation was terminated early, true otherwise.
240   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
241
242   /// \brief Recursively visit a template name and dispatch to the
243   /// appropriate method.
244   ///
245   /// \returns false if the visitation was terminated early, true otherwise.
246   bool TraverseTemplateName(TemplateName Template);
247
248   /// \brief Recursively visit a template argument and dispatch to the
249   /// appropriate method for the argument type.
250   ///
251   /// \returns false if the visitation was terminated early, true otherwise.
252   // FIXME: migrate callers to TemplateArgumentLoc instead.
253   bool TraverseTemplateArgument(const TemplateArgument &Arg);
254
255   /// \brief Recursively visit a template argument location and dispatch to the
256   /// appropriate method for the argument type.
257   ///
258   /// \returns false if the visitation was terminated early, true otherwise.
259   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
260
261   /// \brief Recursively visit a set of template arguments.
262   /// This can be overridden by a subclass, but it's not expected that
263   /// will be needed -- this visitor always dispatches to another.
264   ///
265   /// \returns false if the visitation was terminated early, true otherwise.
266   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
267   bool TraverseTemplateArguments(const TemplateArgument *Args,
268                                  unsigned NumArgs);
269
270   /// \brief Recursively visit a constructor initializer.  This
271   /// automatically dispatches to another visitor for the initializer
272   /// expression, but not for the name of the initializer, so may
273   /// be overridden for clients that need access to the name.
274   ///
275   /// \returns false if the visitation was terminated early, true otherwise.
276   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
277
278   /// \brief Recursively visit a lambda capture. \c Init is the expression that
279   /// will be used to initialize the capture.
280   ///
281   /// \returns false if the visitation was terminated early, true otherwise.
282   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
283                              Expr *Init);
284
285   /// \brief Recursively visit the body of a lambda expression.
286   ///
287   /// This provides a hook for visitors that need more context when visiting
288   /// \c LE->getBody().
289   ///
290   /// \returns false if the visitation was terminated early, true otherwise.
291   bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue = nullptr);
292
293   /// \brief Recursively visit the syntactic or semantic form of an
294   /// initialization list.
295   ///
296   /// \returns false if the visitation was terminated early, true otherwise.
297   bool TraverseSynOrSemInitListExpr(InitListExpr *S,
298                                     DataRecursionQueue *Queue = nullptr);
299
300   // ---- Methods on Attrs ----
301
302   // \brief Visit an attribute.
303   bool VisitAttr(Attr *A) { return true; }
304
305 // Declare Traverse* and empty Visit* for all Attr classes.
306 #define ATTR_VISITOR_DECLS_ONLY
307 #include "clang/AST/AttrVisitor.inc"
308 #undef ATTR_VISITOR_DECLS_ONLY
309
310 // ---- Methods on Stmts ----
311
312 private:
313   template<typename T, typename U>
314   struct has_same_member_pointer_type : std::false_type {};
315   template<typename T, typename U, typename R, typename... P>
316   struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
317       : std::true_type {};
318
319   // Traverse the given statement. If the most-derived traverse function takes a
320   // data recursion queue, pass it on; otherwise, discard it. Note that the
321   // first branch of this conditional must compile whether or not the derived
322   // class can take a queue, so if we're taking the second arm, make the first
323   // arm call our function rather than the derived class version.
324 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)                            \
325   (has_same_member_pointer_type<decltype(                                      \
326                                     &RecursiveASTVisitor::Traverse##NAME),     \
327                                 decltype(&Derived::Traverse##NAME)>::value     \
328        ? static_cast<typename std::conditional<                                \
329              has_same_member_pointer_type<                                     \
330                  decltype(&RecursiveASTVisitor::Traverse##NAME),               \
331                  decltype(&Derived::Traverse##NAME)>::value,                   \
332              Derived &, RecursiveASTVisitor &>::type>(*this)                   \
333              .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE)                 \
334        : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
335
336 // Try to traverse the given statement, or enqueue it if we're performing data
337 // recursion in the middle of traversing another statement. Can only be called
338 // from within a DEF_TRAVERSE_STMT body or similar context.
339 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S)                                     \
340   do {                                                                         \
341     if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue))                             \
342       return false;                                                            \
343   } while (false)
344
345 public:
346 // Declare Traverse*() for all concrete Stmt classes.
347 #define ABSTRACT_STMT(STMT)
348 #define STMT(CLASS, PARENT) \
349   bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
350 #include "clang/AST/StmtNodes.inc"
351   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
352
353   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
354   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
355   bool VisitStmt(Stmt *S) { return true; }
356 #define STMT(CLASS, PARENT)                                                    \
357   bool WalkUpFrom##CLASS(CLASS *S) {                                           \
358     TRY_TO(WalkUpFrom##PARENT(S));                                             \
359     TRY_TO(Visit##CLASS(S));                                                   \
360     return true;                                                               \
361   }                                                                            \
362   bool Visit##CLASS(CLASS *S) { return true; }
363 #include "clang/AST/StmtNodes.inc"
364
365 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
366 // operator methods.  Unary operators are not classes in themselves
367 // (they're all opcodes in UnaryOperator) but do have visitors.
368 #define OPERATOR(NAME)                                                         \
369   bool TraverseUnary##NAME(UnaryOperator *S,                                   \
370                            DataRecursionQueue *Queue = nullptr) {              \
371     if (!getDerived().shouldTraversePostOrder())                               \
372       TRY_TO(WalkUpFromUnary##NAME(S));                                        \
373     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());                          \
374     return true;                                                               \
375   }                                                                            \
376   bool WalkUpFromUnary##NAME(UnaryOperator *S) {                               \
377     TRY_TO(WalkUpFromUnaryOperator(S));                                        \
378     TRY_TO(VisitUnary##NAME(S));                                               \
379     return true;                                                               \
380   }                                                                            \
381   bool VisitUnary##NAME(UnaryOperator *S) { return true; }
382
383   UNARYOP_LIST()
384 #undef OPERATOR
385
386 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
387 // operator methods.  Binary operators are not classes in themselves
388 // (they're all opcodes in BinaryOperator) but do have visitors.
389 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE)                               \
390   bool TraverseBin##NAME(BINOP_TYPE *S, DataRecursionQueue *Queue = nullptr) { \
391     if (!getDerived().shouldTraversePostOrder())                               \
392       TRY_TO(WalkUpFromBin##NAME(S));                                          \
393     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS());                              \
394     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS());                              \
395     return true;                                                               \
396   }                                                                            \
397   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {                                    \
398     TRY_TO(WalkUpFrom##BINOP_TYPE(S));                                         \
399     TRY_TO(VisitBin##NAME(S));                                                 \
400     return true;                                                               \
401   }                                                                            \
402   bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
403
404 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
405   BINOP_LIST()
406 #undef OPERATOR
407
408 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
409 // assignment methods.  Compound assignment operators are not
410 // classes in themselves (they're all opcodes in
411 // CompoundAssignOperator) but do have visitors.
412 #define OPERATOR(NAME)                                                         \
413   GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
414
415   CAO_LIST()
416 #undef OPERATOR
417 #undef GENERAL_BINOP_FALLBACK
418
419 // ---- Methods on Types ----
420 // FIXME: revamp to take TypeLoc's rather than Types.
421
422 // Declare Traverse*() for all concrete Type classes.
423 #define ABSTRACT_TYPE(CLASS, BASE)
424 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
425 #include "clang/AST/TypeNodes.def"
426   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
427
428   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
429   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
430   bool VisitType(Type *T) { return true; }
431 #define TYPE(CLASS, BASE)                                                      \
432   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                               \
433     TRY_TO(WalkUpFrom##BASE(T));                                               \
434     TRY_TO(Visit##CLASS##Type(T));                                             \
435     return true;                                                               \
436   }                                                                            \
437   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
438 #include "clang/AST/TypeNodes.def"
439
440 // ---- Methods on TypeLocs ----
441 // FIXME: this currently just calls the matching Type methods
442
443 // Declare Traverse*() for all concrete TypeLoc classes.
444 #define ABSTRACT_TYPELOC(CLASS, BASE)
445 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
446 #include "clang/AST/TypeLocNodes.def"
447   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
448
449   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
450   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
451   bool VisitTypeLoc(TypeLoc TL) { return true; }
452
453   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
454   // TypeNodes.def and thus need to be handled specially.
455   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
456     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
457   }
458   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
459   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
460     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
461   }
462   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
463
464 // Note that BASE includes trailing 'Type' which CLASS doesn't.
465 #define TYPE(CLASS, BASE)                                                      \
466   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {                         \
467     TRY_TO(WalkUpFrom##BASE##Loc(TL));                                         \
468     TRY_TO(Visit##CLASS##TypeLoc(TL));                                         \
469     return true;                                                               \
470   }                                                                            \
471   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
472 #include "clang/AST/TypeNodes.def"
473
474 // ---- Methods on Decls ----
475
476 // Declare Traverse*() for all concrete Decl classes.
477 #define ABSTRACT_DECL(DECL)
478 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
479 #include "clang/AST/DeclNodes.inc"
480   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
481
482   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
483   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
484   bool VisitDecl(Decl *D) { return true; }
485 #define DECL(CLASS, BASE)                                                      \
486   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                               \
487     TRY_TO(WalkUpFrom##BASE(D));                                               \
488     TRY_TO(Visit##CLASS##Decl(D));                                             \
489     return true;                                                               \
490   }                                                                            \
491   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
492 #include "clang/AST/DeclNodes.inc"
493
494 private:
495   // These are helper methods used by more than one Traverse* method.
496   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
497
498   // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
499   template <typename T>
500   bool TraverseDeclTemplateParameterLists(T *D);
501
502 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)                                   \
503   bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
504   DEF_TRAVERSE_TMPL_INST(Class)
505   DEF_TRAVERSE_TMPL_INST(Var)
506   DEF_TRAVERSE_TMPL_INST(Function)
507 #undef DEF_TRAVERSE_TMPL_INST
508   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
509                                           unsigned Count);
510   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
511   bool TraverseRecordHelper(RecordDecl *D);
512   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
513   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
514   bool TraverseDeclContextHelper(DeclContext *DC);
515   bool TraverseFunctionHelper(FunctionDecl *D);
516   bool TraverseVarHelper(VarDecl *D);
517   bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
518   bool TraverseOMPLoopDirective(OMPLoopDirective *S);
519   bool TraverseOMPClause(OMPClause *C);
520 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
521 #include "clang/Basic/OpenMPKinds.def"
522   /// \brief Process clauses with list of variables.
523   template <typename T> bool VisitOMPClauseList(T *Node);
524   /// Process clauses with pre-initis.
525   bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
526   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
527
528   bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
529   bool PostVisitStmt(Stmt *S);
530 };
531
532 template <typename Derived>
533 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
534                                                     DataRecursionQueue *Queue) {
535 #define DISPATCH_STMT(NAME, CLASS, VAR)                                        \
536   return TRAVERSE_STMT_BASE(NAME, CLASS, VAR, Queue);
537
538   // If we have a binary expr, dispatch to the subcode of the binop.  A smart
539   // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
540   // below.
541   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
542     switch (BinOp->getOpcode()) {
543 #define OPERATOR(NAME)                                                         \
544   case BO_##NAME:                                                              \
545     DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
546
547       BINOP_LIST()
548 #undef OPERATOR
549 #undef BINOP_LIST
550
551 #define OPERATOR(NAME)                                                         \
552   case BO_##NAME##Assign:                                                      \
553     DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
554
555       CAO_LIST()
556 #undef OPERATOR
557 #undef CAO_LIST
558     }
559   } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
560     switch (UnOp->getOpcode()) {
561 #define OPERATOR(NAME)                                                         \
562   case UO_##NAME:                                                              \
563     DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
564
565       UNARYOP_LIST()
566 #undef OPERATOR
567 #undef UNARYOP_LIST
568     }
569   }
570
571   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
572   switch (S->getStmtClass()) {
573   case Stmt::NoStmtClass:
574     break;
575 #define ABSTRACT_STMT(STMT)
576 #define STMT(CLASS, PARENT)                                                    \
577   case Stmt::CLASS##Class:                                                     \
578     DISPATCH_STMT(CLASS, CLASS, S);
579 #include "clang/AST/StmtNodes.inc"
580   }
581
582   return true;
583 }
584
585 #undef DISPATCH_STMT
586
587 template <typename Derived>
588 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
589   switch (S->getStmtClass()) {
590   case Stmt::NoStmtClass:
591     break;
592 #define ABSTRACT_STMT(STMT)
593 #define STMT(CLASS, PARENT)                                                    \
594   case Stmt::CLASS##Class:                                                     \
595     TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); break;
596 #include "clang/AST/StmtNodes.inc"
597   }
598
599   return true;
600 }
601
602 #undef DISPATCH_STMT
603
604 template <typename Derived>
605 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
606                                                 DataRecursionQueue *Queue) {
607   if (!S)
608     return true;
609
610   if (Queue) {
611     Queue->push_back({S, false});
612     return true;
613   }
614
615   SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
616   LocalQueue.push_back({S, false});
617
618   while (!LocalQueue.empty()) {
619     auto &CurrSAndVisited = LocalQueue.back();
620     Stmt *CurrS = CurrSAndVisited.getPointer();
621     bool Visited = CurrSAndVisited.getInt();
622     if (Visited) {
623       LocalQueue.pop_back();
624       TRY_TO(dataTraverseStmtPost(CurrS));
625       if (getDerived().shouldTraversePostOrder()) {
626         TRY_TO(PostVisitStmt(CurrS));
627       }
628       continue;
629     }
630
631     if (getDerived().dataTraverseStmtPre(CurrS)) {
632       CurrSAndVisited.setInt(true);
633       size_t N = LocalQueue.size();
634       TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
635       // Process new children in the order they were added.
636       std::reverse(LocalQueue.begin() + N, LocalQueue.end());
637     } else {
638       LocalQueue.pop_back();
639     }
640   }
641
642   return true;
643 }
644
645 #define DISPATCH(NAME, CLASS, VAR)                                             \
646   return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
647
648 template <typename Derived>
649 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
650   if (T.isNull())
651     return true;
652
653   switch (T->getTypeClass()) {
654 #define ABSTRACT_TYPE(CLASS, BASE)
655 #define TYPE(CLASS, BASE)                                                      \
656   case Type::CLASS:                                                            \
657     DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
658 #include "clang/AST/TypeNodes.def"
659   }
660
661   return true;
662 }
663
664 template <typename Derived>
665 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
666   if (TL.isNull())
667     return true;
668
669   switch (TL.getTypeLocClass()) {
670 #define ABSTRACT_TYPELOC(CLASS, BASE)
671 #define TYPELOC(CLASS, BASE)                                                   \
672   case TypeLoc::CLASS:                                                         \
673     return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
674 #include "clang/AST/TypeLocNodes.def"
675   }
676
677   return true;
678 }
679
680 // Define the Traverse*Attr(Attr* A) methods
681 #define VISITORCLASS RecursiveASTVisitor
682 #include "clang/AST/AttrVisitor.inc"
683 #undef VISITORCLASS
684
685 template <typename Derived>
686 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
687   if (!D)
688     return true;
689
690   // As a syntax visitor, by default we want to ignore declarations for
691   // implicit declarations (ones not typed explicitly by the user).
692   if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
693     return true;
694
695   switch (D->getKind()) {
696 #define ABSTRACT_DECL(DECL)
697 #define DECL(CLASS, BASE)                                                      \
698   case Decl::CLASS:                                                            \
699     if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D)))    \
700       return false;                                                            \
701     break;
702 #include "clang/AST/DeclNodes.inc"
703   }
704
705   // Visit any attributes attached to this declaration.
706   for (auto *I : D->attrs()) {
707     if (!getDerived().TraverseAttr(I))
708       return false;
709   }
710   return true;
711 }
712
713 #undef DISPATCH
714
715 template <typename Derived>
716 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
717     NestedNameSpecifier *NNS) {
718   if (!NNS)
719     return true;
720
721   if (NNS->getPrefix())
722     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
723
724   switch (NNS->getKind()) {
725   case NestedNameSpecifier::Identifier:
726   case NestedNameSpecifier::Namespace:
727   case NestedNameSpecifier::NamespaceAlias:
728   case NestedNameSpecifier::Global:
729   case NestedNameSpecifier::Super:
730     return true;
731
732   case NestedNameSpecifier::TypeSpec:
733   case NestedNameSpecifier::TypeSpecWithTemplate:
734     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
735   }
736
737   return true;
738 }
739
740 template <typename Derived>
741 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
742     NestedNameSpecifierLoc NNS) {
743   if (!NNS)
744     return true;
745
746   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
747     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
748
749   switch (NNS.getNestedNameSpecifier()->getKind()) {
750   case NestedNameSpecifier::Identifier:
751   case NestedNameSpecifier::Namespace:
752   case NestedNameSpecifier::NamespaceAlias:
753   case NestedNameSpecifier::Global:
754   case NestedNameSpecifier::Super:
755     return true;
756
757   case NestedNameSpecifier::TypeSpec:
758   case NestedNameSpecifier::TypeSpecWithTemplate:
759     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
760     break;
761   }
762
763   return true;
764 }
765
766 template <typename Derived>
767 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
768     DeclarationNameInfo NameInfo) {
769   switch (NameInfo.getName().getNameKind()) {
770   case DeclarationName::CXXConstructorName:
771   case DeclarationName::CXXDestructorName:
772   case DeclarationName::CXXConversionFunctionName:
773     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
774       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
775     break;
776
777   case DeclarationName::Identifier:
778   case DeclarationName::ObjCZeroArgSelector:
779   case DeclarationName::ObjCOneArgSelector:
780   case DeclarationName::ObjCMultiArgSelector:
781   case DeclarationName::CXXOperatorName:
782   case DeclarationName::CXXLiteralOperatorName:
783   case DeclarationName::CXXUsingDirective:
784     break;
785   }
786
787   return true;
788 }
789
790 template <typename Derived>
791 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
792   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
793     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
794   else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
795     TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
796
797   return true;
798 }
799
800 template <typename Derived>
801 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
802     const TemplateArgument &Arg) {
803   switch (Arg.getKind()) {
804   case TemplateArgument::Null:
805   case TemplateArgument::Declaration:
806   case TemplateArgument::Integral:
807   case TemplateArgument::NullPtr:
808     return true;
809
810   case TemplateArgument::Type:
811     return getDerived().TraverseType(Arg.getAsType());
812
813   case TemplateArgument::Template:
814   case TemplateArgument::TemplateExpansion:
815     return getDerived().TraverseTemplateName(
816         Arg.getAsTemplateOrTemplatePattern());
817
818   case TemplateArgument::Expression:
819     return getDerived().TraverseStmt(Arg.getAsExpr());
820
821   case TemplateArgument::Pack:
822     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
823                                                   Arg.pack_size());
824   }
825
826   return true;
827 }
828
829 // FIXME: no template name location?
830 // FIXME: no source locations for a template argument pack?
831 template <typename Derived>
832 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
833     const TemplateArgumentLoc &ArgLoc) {
834   const TemplateArgument &Arg = ArgLoc.getArgument();
835
836   switch (Arg.getKind()) {
837   case TemplateArgument::Null:
838   case TemplateArgument::Declaration:
839   case TemplateArgument::Integral:
840   case TemplateArgument::NullPtr:
841     return true;
842
843   case TemplateArgument::Type: {
844     // FIXME: how can TSI ever be NULL?
845     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
846       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
847     else
848       return getDerived().TraverseType(Arg.getAsType());
849   }
850
851   case TemplateArgument::Template:
852   case TemplateArgument::TemplateExpansion:
853     if (ArgLoc.getTemplateQualifierLoc())
854       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
855           ArgLoc.getTemplateQualifierLoc()));
856     return getDerived().TraverseTemplateName(
857         Arg.getAsTemplateOrTemplatePattern());
858
859   case TemplateArgument::Expression:
860     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
861
862   case TemplateArgument::Pack:
863     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
864                                                   Arg.pack_size());
865   }
866
867   return true;
868 }
869
870 template <typename Derived>
871 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
872     const TemplateArgument *Args, unsigned NumArgs) {
873   for (unsigned I = 0; I != NumArgs; ++I) {
874     TRY_TO(TraverseTemplateArgument(Args[I]));
875   }
876
877   return true;
878 }
879
880 template <typename Derived>
881 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
882     CXXCtorInitializer *Init) {
883   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
884     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
885
886   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
887     TRY_TO(TraverseStmt(Init->getInit()));
888
889   return true;
890 }
891
892 template <typename Derived>
893 bool
894 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
895                                                     const LambdaCapture *C,
896                                                     Expr *Init) {
897   if (LE->isInitCapture(C))
898     TRY_TO(TraverseDecl(C->getCapturedVar()));
899   else
900     TRY_TO(TraverseStmt(Init));
901   return true;
902 }
903
904 template <typename Derived>
905 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(
906     LambdaExpr *LE, DataRecursionQueue *Queue) {
907   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(LE->getBody());
908   return true;
909 }
910
911 // ----------------- Type traversal -----------------
912
913 // This macro makes available a variable T, the passed-in type.
914 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
915   template <typename Derived>                                                  \
916   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
917     if (!getDerived().shouldTraversePostOrder())                               \
918       TRY_TO(WalkUpFrom##TYPE(T));                                             \
919     { CODE; }                                                                  \
920     if (getDerived().shouldTraversePostOrder())                                \
921       TRY_TO(WalkUpFrom##TYPE(T));                                             \
922     return true;                                                               \
923   }
924
925 DEF_TRAVERSE_TYPE(BuiltinType, {})
926
927 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
928
929 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
930
931 DEF_TRAVERSE_TYPE(BlockPointerType,
932                   { TRY_TO(TraverseType(T->getPointeeType())); })
933
934 DEF_TRAVERSE_TYPE(LValueReferenceType,
935                   { TRY_TO(TraverseType(T->getPointeeType())); })
936
937 DEF_TRAVERSE_TYPE(RValueReferenceType,
938                   { TRY_TO(TraverseType(T->getPointeeType())); })
939
940 DEF_TRAVERSE_TYPE(MemberPointerType, {
941   TRY_TO(TraverseType(QualType(T->getClass(), 0)));
942   TRY_TO(TraverseType(T->getPointeeType()));
943 })
944
945 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
946
947 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
948
949 DEF_TRAVERSE_TYPE(ConstantArrayType,
950                   { TRY_TO(TraverseType(T->getElementType())); })
951
952 DEF_TRAVERSE_TYPE(IncompleteArrayType,
953                   { TRY_TO(TraverseType(T->getElementType())); })
954
955 DEF_TRAVERSE_TYPE(VariableArrayType, {
956   TRY_TO(TraverseType(T->getElementType()));
957   TRY_TO(TraverseStmt(T->getSizeExpr()));
958 })
959
960 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
961   TRY_TO(TraverseType(T->getElementType()));
962   if (T->getSizeExpr())
963     TRY_TO(TraverseStmt(T->getSizeExpr()));
964 })
965
966 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
967   if (T->getSizeExpr())
968     TRY_TO(TraverseStmt(T->getSizeExpr()));
969   TRY_TO(TraverseType(T->getElementType()));
970 })
971
972 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
973
974 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
975
976 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
977                   { TRY_TO(TraverseType(T->getReturnType())); })
978
979 DEF_TRAVERSE_TYPE(FunctionProtoType, {
980   TRY_TO(TraverseType(T->getReturnType()));
981
982   for (const auto &A : T->param_types()) {
983     TRY_TO(TraverseType(A));
984   }
985
986   for (const auto &E : T->exceptions()) {
987     TRY_TO(TraverseType(E));
988   }
989
990   if (Expr *NE = T->getNoexceptExpr())
991     TRY_TO(TraverseStmt(NE));
992 })
993
994 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
995 DEF_TRAVERSE_TYPE(TypedefType, {})
996
997 DEF_TRAVERSE_TYPE(TypeOfExprType,
998                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
999
1000 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
1001
1002 DEF_TRAVERSE_TYPE(DecltypeType,
1003                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1004
1005 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1006   TRY_TO(TraverseType(T->getBaseType()));
1007   TRY_TO(TraverseType(T->getUnderlyingType()));
1008 })
1009
1010 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1011
1012 DEF_TRAVERSE_TYPE(RecordType, {})
1013 DEF_TRAVERSE_TYPE(EnumType, {})
1014 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1015 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
1016 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
1017
1018 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1019   TRY_TO(TraverseTemplateName(T->getTemplateName()));
1020   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1021 })
1022
1023 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1024
1025 DEF_TRAVERSE_TYPE(AttributedType,
1026                   { TRY_TO(TraverseType(T->getModifiedType())); })
1027
1028 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1029
1030 DEF_TRAVERSE_TYPE(ElaboratedType, {
1031   if (T->getQualifier()) {
1032     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1033   }
1034   TRY_TO(TraverseType(T->getNamedType()));
1035 })
1036
1037 DEF_TRAVERSE_TYPE(DependentNameType,
1038                   { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1039
1040 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1041   TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1042   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1043 })
1044
1045 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1046
1047 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1048
1049 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1050
1051 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1052   // We have to watch out here because an ObjCInterfaceType's base
1053   // type is itself.
1054   if (T->getBaseType().getTypePtr() != T)
1055     TRY_TO(TraverseType(T->getBaseType()));
1056   for (auto typeArg : T->getTypeArgsAsWritten()) {
1057     TRY_TO(TraverseType(typeArg));
1058   }
1059 })
1060
1061 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1062                   { TRY_TO(TraverseType(T->getPointeeType())); })
1063
1064 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1065
1066 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1067
1068 #undef DEF_TRAVERSE_TYPE
1069
1070 // ----------------- TypeLoc traversal -----------------
1071
1072 // This macro makes available a variable TL, the passed-in TypeLoc.
1073 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1074 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1075 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1076 // continue to work.
1077 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                       \
1078   template <typename Derived>                                                  \
1079   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) {       \
1080     if (getDerived().shouldWalkTypesOfTypeLocs())                              \
1081       TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));           \
1082     TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                         \
1083     { CODE; }                                                                  \
1084     return true;                                                               \
1085   }
1086
1087 template <typename Derived>
1088 bool
1089 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1090   // Move this over to the 'main' typeloc tree.  Note that this is a
1091   // move -- we pretend that we were really looking at the unqualified
1092   // typeloc all along -- rather than a recursion, so we don't follow
1093   // the normal CRTP plan of going through
1094   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
1095   // twice for the same type (once as a QualifiedTypeLoc version of
1096   // the type, once as an UnqualifiedTypeLoc version of the type),
1097   // which in effect means we'd call VisitTypeLoc twice with the
1098   // 'same' type.  This solves that problem, at the cost of never
1099   // seeing the qualified version of the type (unless the client
1100   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
1101   // perfect solution.  A perfect solution probably requires making
1102   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1103   // wrapper around Type* -- rather than being its own class in the
1104   // type hierarchy.
1105   return TraverseTypeLoc(TL.getUnqualifiedLoc());
1106 }
1107
1108 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1109
1110 // FIXME: ComplexTypeLoc is unfinished
1111 DEF_TRAVERSE_TYPELOC(ComplexType, {
1112   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1113 })
1114
1115 DEF_TRAVERSE_TYPELOC(PointerType,
1116                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1117
1118 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1119                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1120
1121 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1122                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1123
1124 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1125                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1126
1127 // FIXME: location of base class?
1128 // We traverse this in the type case as well, but how is it not reached through
1129 // the pointee type?
1130 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1131   TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1132   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1133 })
1134
1135 DEF_TRAVERSE_TYPELOC(AdjustedType,
1136                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1137
1138 DEF_TRAVERSE_TYPELOC(DecayedType,
1139                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1140
1141 template <typename Derived>
1142 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1143   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1144   TRY_TO(TraverseStmt(TL.getSizeExpr()));
1145   return true;
1146 }
1147
1148 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1149   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1150   return TraverseArrayTypeLocHelper(TL);
1151 })
1152
1153 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1154   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1155   return TraverseArrayTypeLocHelper(TL);
1156 })
1157
1158 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1159   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1160   return TraverseArrayTypeLocHelper(TL);
1161 })
1162
1163 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1164   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1165   return TraverseArrayTypeLocHelper(TL);
1166 })
1167
1168 // FIXME: order? why not size expr first?
1169 // FIXME: base VectorTypeLoc is unfinished
1170 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1171   if (TL.getTypePtr()->getSizeExpr())
1172     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1173   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1174 })
1175
1176 // FIXME: VectorTypeLoc is unfinished
1177 DEF_TRAVERSE_TYPELOC(VectorType, {
1178   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1179 })
1180
1181 // FIXME: size and attributes
1182 // FIXME: base VectorTypeLoc is unfinished
1183 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1184   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1185 })
1186
1187 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1188                      { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1189
1190 // FIXME: location of exception specifications (attributes?)
1191 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1192   TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1193
1194   const FunctionProtoType *T = TL.getTypePtr();
1195
1196   for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1197     if (TL.getParam(I)) {
1198       TRY_TO(TraverseDecl(TL.getParam(I)));
1199     } else if (I < T->getNumParams()) {
1200       TRY_TO(TraverseType(T->getParamType(I)));
1201     }
1202   }
1203
1204   for (const auto &E : T->exceptions()) {
1205     TRY_TO(TraverseType(E));
1206   }
1207
1208   if (Expr *NE = T->getNoexceptExpr())
1209     TRY_TO(TraverseStmt(NE));
1210 })
1211
1212 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1213 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1214
1215 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1216                      { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1217
1218 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1219   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1220 })
1221
1222 // FIXME: location of underlying expr
1223 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1224   TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1225 })
1226
1227 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1228   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1229 })
1230
1231 DEF_TRAVERSE_TYPELOC(AutoType, {
1232   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1233 })
1234
1235 DEF_TRAVERSE_TYPELOC(RecordType, {})
1236 DEF_TRAVERSE_TYPELOC(EnumType, {})
1237 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1238 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
1239 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
1240
1241 // FIXME: use the loc for the template name?
1242 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1243   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1244   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1245     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1246   }
1247 })
1248
1249 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1250
1251 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1252
1253 DEF_TRAVERSE_TYPELOC(AttributedType,
1254                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1255
1256 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1257   if (TL.getQualifierLoc()) {
1258     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1259   }
1260   TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1261 })
1262
1263 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1264   TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1265 })
1266
1267 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1268   if (TL.getQualifierLoc()) {
1269     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1270   }
1271
1272   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1273     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1274   }
1275 })
1276
1277 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1278                      { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1279
1280 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
1281
1282 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1283
1284 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1285   // We have to watch out here because an ObjCInterfaceType's base
1286   // type is itself.
1287   if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1288     TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1289   for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1290     TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1291 })
1292
1293 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1294                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1295
1296 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1297
1298 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1299
1300 #undef DEF_TRAVERSE_TYPELOC
1301
1302 // ----------------- Decl traversal -----------------
1303 //
1304 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1305 // the children that come from the DeclContext associated with it.
1306 // Therefore each Traverse* only needs to worry about children other
1307 // than those.
1308
1309 template <typename Derived>
1310 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1311   if (!DC)
1312     return true;
1313
1314   for (auto *Child : DC->decls()) {
1315     // BlockDecls and CapturedDecls are traversed through BlockExprs and
1316     // CapturedStmts respectively.
1317     if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1318       TRY_TO(TraverseDecl(Child));
1319   }
1320
1321   return true;
1322 }
1323
1324 // This macro makes available a variable D, the passed-in decl.
1325 #define DEF_TRAVERSE_DECL(DECL, CODE)                                          \
1326   template <typename Derived>                                                  \
1327   bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) {                 \
1328     bool ShouldVisitChildren = true;                                           \
1329     bool ReturnValue = true;                                                   \
1330     if (!getDerived().shouldTraversePostOrder())                               \
1331       TRY_TO(WalkUpFrom##DECL(D));                                             \
1332     { CODE; }                                                                  \
1333     if (ReturnValue && ShouldVisitChildren)                                    \
1334       TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));             \
1335     if (ReturnValue && getDerived().shouldTraversePostOrder())                 \
1336       TRY_TO(WalkUpFrom##DECL(D));                                             \
1337     return ReturnValue;                                                        \
1338   }
1339
1340 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1341
1342 DEF_TRAVERSE_DECL(BlockDecl, {
1343   if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1344     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1345   TRY_TO(TraverseStmt(D->getBody()));
1346   for (const auto &I : D->captures()) {
1347     if (I.hasCopyExpr()) {
1348       TRY_TO(TraverseStmt(I.getCopyExpr()));
1349     }
1350   }
1351   ShouldVisitChildren = false;
1352 })
1353
1354 DEF_TRAVERSE_DECL(CapturedDecl, {
1355   TRY_TO(TraverseStmt(D->getBody()));
1356   ShouldVisitChildren = false;
1357 })
1358
1359 DEF_TRAVERSE_DECL(EmptyDecl, {})
1360
1361 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1362                   { TRY_TO(TraverseStmt(D->getAsmString())); })
1363
1364 DEF_TRAVERSE_DECL(ImportDecl, {})
1365
1366 DEF_TRAVERSE_DECL(FriendDecl, {
1367   // Friend is either decl or a type.
1368   if (D->getFriendType())
1369     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1370   else
1371     TRY_TO(TraverseDecl(D->getFriendDecl()));
1372 })
1373
1374 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1375   if (D->getFriendType())
1376     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1377   else
1378     TRY_TO(TraverseDecl(D->getFriendDecl()));
1379   for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1380     TemplateParameterList *TPL = D->getTemplateParameterList(I);
1381     for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1382          ITPL != ETPL; ++ITPL) {
1383       TRY_TO(TraverseDecl(*ITPL));
1384     }
1385   }
1386 })
1387
1388 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1389   TRY_TO(TraverseDecl(D->getSpecialization()));
1390
1391   if (D->hasExplicitTemplateArgs()) {
1392     const TemplateArgumentListInfo &args = D->templateArgs();
1393     TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1394                                               args.size()));
1395   }
1396 })
1397
1398 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1399
1400 DEF_TRAVERSE_DECL(ExportDecl, {})
1401
1402 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1403                                         })
1404
1405 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1406   TRY_TO(TraverseStmt(D->getAssertExpr()));
1407   TRY_TO(TraverseStmt(D->getMessage()));
1408 })
1409
1410 DEF_TRAVERSE_DECL(
1411     TranslationUnitDecl,
1412     {// Code in an unnamed namespace shows up automatically in
1413      // decls_begin()/decls_end().  Thus we don't need to recurse on
1414      // D->getAnonymousNamespace().
1415     })
1416
1417 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1418
1419 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1420
1421 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1422
1423 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1424   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1425
1426   // We shouldn't traverse an aliased namespace, since it will be
1427   // defined (and, therefore, traversed) somewhere else.
1428   ShouldVisitChildren = false;
1429 })
1430
1431 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1432                              })
1433
1434 DEF_TRAVERSE_DECL(
1435     NamespaceDecl,
1436     {// Code in an unnamed namespace shows up automatically in
1437      // decls_begin()/decls_end().  Thus we don't need to recurse on
1438      // D->getAnonymousNamespace().
1439     })
1440
1441 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1442                                            })
1443
1444 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1445   if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1446     for (auto typeParam : *typeParamList) {
1447       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1448     }
1449   }
1450 })
1451
1452 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1453                                         })
1454
1455 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1456                                           })
1457
1458 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1459   if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1460     for (auto typeParam : *typeParamList) {
1461       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1462     }
1463   }
1464
1465   if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1466     TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1467   }
1468 })
1469
1470 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1471                                     })
1472
1473 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1474   if (D->getReturnTypeSourceInfo()) {
1475     TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1476   }
1477   for (ParmVarDecl *Parameter : D->parameters()) {
1478     TRY_TO(TraverseDecl(Parameter));
1479   }
1480   if (D->isThisDeclarationADefinition()) {
1481     TRY_TO(TraverseStmt(D->getBody()));
1482   }
1483   ShouldVisitChildren = false;
1484 })
1485
1486 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1487   if (D->hasExplicitBound()) {
1488     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1489     // We shouldn't traverse D->getTypeForDecl(); it's a result of
1490     // declaring the type alias, not something that was written in the
1491     // source.
1492   }
1493 })
1494
1495 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1496   if (D->getTypeSourceInfo())
1497     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1498   else
1499     TRY_TO(TraverseType(D->getType()));
1500   ShouldVisitChildren = false;
1501 })
1502
1503 DEF_TRAVERSE_DECL(UsingDecl, {
1504   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1505   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1506 })
1507
1508 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1509
1510 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1511   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1512 })
1513
1514 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1515
1516 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1517
1518 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1519   for (auto *I : D->varlists()) {
1520     TRY_TO(TraverseStmt(I));
1521   }
1522 })
1523
1524 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1525   TRY_TO(TraverseStmt(D->getCombiner()));
1526   if (auto *Initializer = D->getInitializer())
1527     TRY_TO(TraverseStmt(Initializer));
1528   TRY_TO(TraverseType(D->getType()));
1529   return true;
1530 })
1531
1532 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1533
1534 // A helper method for TemplateDecl's children.
1535 template <typename Derived>
1536 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1537     TemplateParameterList *TPL) {
1538   if (TPL) {
1539     for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1540          I != E; ++I) {
1541       TRY_TO(TraverseDecl(*I));
1542     }
1543   }
1544   return true;
1545 }
1546
1547 template <typename Derived>
1548 template <typename T>
1549 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1550   for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1551     TemplateParameterList *TPL = D->getTemplateParameterList(i);
1552     TraverseTemplateParameterListHelper(TPL);
1553   }
1554   return true;
1555 }
1556
1557 template <typename Derived>
1558 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1559     ClassTemplateDecl *D) {
1560   for (auto *SD : D->specializations()) {
1561     for (auto *RD : SD->redecls()) {
1562       // We don't want to visit injected-class-names in this traversal.
1563       if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1564         continue;
1565
1566       switch (
1567           cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1568       // Visit the implicit instantiations with the requested pattern.
1569       case TSK_Undeclared:
1570       case TSK_ImplicitInstantiation:
1571         TRY_TO(TraverseDecl(RD));
1572         break;
1573
1574       // We don't need to do anything on an explicit instantiation
1575       // or explicit specialization because there will be an explicit
1576       // node for it elsewhere.
1577       case TSK_ExplicitInstantiationDeclaration:
1578       case TSK_ExplicitInstantiationDefinition:
1579       case TSK_ExplicitSpecialization:
1580         break;
1581       }
1582     }
1583   }
1584
1585   return true;
1586 }
1587
1588 template <typename Derived>
1589 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1590     VarTemplateDecl *D) {
1591   for (auto *SD : D->specializations()) {
1592     for (auto *RD : SD->redecls()) {
1593       switch (
1594           cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1595       case TSK_Undeclared:
1596       case TSK_ImplicitInstantiation:
1597         TRY_TO(TraverseDecl(RD));
1598         break;
1599
1600       case TSK_ExplicitInstantiationDeclaration:
1601       case TSK_ExplicitInstantiationDefinition:
1602       case TSK_ExplicitSpecialization:
1603         break;
1604       }
1605     }
1606   }
1607
1608   return true;
1609 }
1610
1611 // A helper method for traversing the instantiations of a
1612 // function while skipping its specializations.
1613 template <typename Derived>
1614 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1615     FunctionTemplateDecl *D) {
1616   for (auto *FD : D->specializations()) {
1617     for (auto *RD : FD->redecls()) {
1618       switch (RD->getTemplateSpecializationKind()) {
1619       case TSK_Undeclared:
1620       case TSK_ImplicitInstantiation:
1621         // We don't know what kind of FunctionDecl this is.
1622         TRY_TO(TraverseDecl(RD));
1623         break;
1624
1625       // FIXME: For now traverse explicit instantiations here. Change that
1626       // once they are represented as dedicated nodes in the AST.
1627       case TSK_ExplicitInstantiationDeclaration:
1628       case TSK_ExplicitInstantiationDefinition:
1629         TRY_TO(TraverseDecl(RD));
1630         break;
1631
1632       case TSK_ExplicitSpecialization:
1633         break;
1634       }
1635     }
1636   }
1637
1638   return true;
1639 }
1640
1641 // This macro unifies the traversal of class, variable and function
1642 // template declarations.
1643 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)                                   \
1644   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, {                              \
1645     TRY_TO(TraverseDecl(D->getTemplatedDecl()));                               \
1646     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
1647                                                                                \
1648     /* By default, we do not traverse the instantiations of                    \
1649        class templates since they do not appear in the user code. The          \
1650        following code optionally traverses them.                               \
1651                                                                                \
1652        We only traverse the class instantiations when we see the canonical     \
1653        declaration of the template, to ensure we only visit them once. */      \
1654     if (getDerived().shouldVisitTemplateInstantiations() &&                    \
1655         D == D->getCanonicalDecl())                                            \
1656       TRY_TO(TraverseTemplateInstantiations(D));                               \
1657                                                                                \
1658     /* Note that getInstantiatedFromMemberTemplate() is just a link            \
1659        from a template instantiation back to the template from which           \
1660        it was instantiated, and thus should not be traversed. */               \
1661   })
1662
1663 DEF_TRAVERSE_TMPL_DECL(Class)
1664 DEF_TRAVERSE_TMPL_DECL(Var)
1665 DEF_TRAVERSE_TMPL_DECL(Function)
1666
1667 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1668   // D is the "T" in something like
1669   //   template <template <typename> class T> class container { };
1670   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1671   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1672     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1673   }
1674   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1675 })
1676
1677 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1678   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1679 })
1680
1681 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1682   // D is the "T" in something like "template<typename T> class vector;"
1683   if (D->getTypeForDecl())
1684     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1685   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1686     TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1687 })
1688
1689 DEF_TRAVERSE_DECL(TypedefDecl, {
1690   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1691   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1692   // declaring the typedef, not something that was written in the
1693   // source.
1694 })
1695
1696 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1697   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1698   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1699   // declaring the type alias, not something that was written in the
1700   // source.
1701 })
1702
1703 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1704   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1705   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1706 })
1707
1708 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1709   // A dependent using declaration which was marked with 'typename'.
1710   //   template<class T> class A : public B<T> { using typename B<T>::foo; };
1711   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1712   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1713   // declaring the type, not something that was written in the
1714   // source.
1715 })
1716
1717 DEF_TRAVERSE_DECL(EnumDecl, {
1718   TRY_TO(TraverseDeclTemplateParameterLists(D));
1719
1720   if (D->getTypeForDecl())
1721     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1722
1723   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1724   // The enumerators are already traversed by
1725   // decls_begin()/decls_end().
1726 })
1727
1728 // Helper methods for RecordDecl and its children.
1729 template <typename Derived>
1730 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1731   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1732   // declaring the type, not something that was written in the source.
1733
1734   TRY_TO(TraverseDeclTemplateParameterLists(D));
1735   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1736   return true;
1737 }
1738
1739 template <typename Derived>
1740 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1741   if (!TraverseRecordHelper(D))
1742     return false;
1743   if (D->isCompleteDefinition()) {
1744     for (const auto &I : D->bases()) {
1745       TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1746     }
1747     // We don't traverse the friends or the conversions, as they are
1748     // already in decls_begin()/decls_end().
1749   }
1750   return true;
1751 }
1752
1753 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1754
1755 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1756
1757 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND)                              \
1758   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
1759     /* For implicit instantiations ("set<int> x;"), we don't want to           \
1760        recurse at all, since the instatiated template isn't written in         \
1761        the source code anywhere.  (Note the instatiated *type* --              \
1762        set<int> -- is written, and will still get a callback of                \
1763        TemplateSpecializationType).  For explicit instantiations               \
1764        ("template set<int>;"), we do need a callback, since this               \
1765        is the only callback that's made for this instantiation.                \
1766        We use getTypeAsWritten() to distinguish. */                            \
1767     if (TypeSourceInfo *TSI = D->getTypeAsWritten())                           \
1768       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));                              \
1769                                                                                \
1770     if (!getDerived().shouldVisitTemplateInstantiations() &&                   \
1771         D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)      \
1772       /* Returning from here skips traversing the                              \
1773          declaration context of the *TemplateSpecializationDecl                \
1774          (embedded in the DEF_TRAVERSE_DECL() macro)                           \
1775          which contains the instantiated members of the template. */           \
1776       return true;                                                             \
1777   })
1778
1779 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
1780 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
1781
1782 template <typename Derived>
1783 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1784     const TemplateArgumentLoc *TAL, unsigned Count) {
1785   for (unsigned I = 0; I < Count; ++I) {
1786     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1787   }
1788   return true;
1789 }
1790
1791 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)               \
1792   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, {         \
1793     /* The partial specialization. */                                          \
1794     if (TemplateParameterList *TPL = D->getTemplateParameters()) {             \
1795       for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();   \
1796            I != E; ++I) {                                                      \
1797         TRY_TO(TraverseDecl(*I));                                              \
1798       }                                                                        \
1799     }                                                                          \
1800     /* The args that remains unspecialized. */                                 \
1801     TRY_TO(TraverseTemplateArgumentLocsHelper(                                 \
1802         D->getTemplateArgsAsWritten()->getTemplateArgs(),                      \
1803         D->getTemplateArgsAsWritten()->NumTemplateArgs));                      \
1804                                                                                \
1805     /* Don't need the *TemplatePartialSpecializationHelper, even               \
1806        though that's our parent class -- we already visit all the              \
1807        template args here. */                                                  \
1808     TRY_TO(Traverse##DECLKIND##Helper(D));                                     \
1809                                                                                \
1810     /* Instantiations will have been visited with the primary template. */     \
1811   })
1812
1813 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1814 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
1815
1816 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1817
1818 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1819   // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1820   //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
1821   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1822   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1823 })
1824
1825 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1826
1827 template <typename Derived>
1828 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1829   TRY_TO(TraverseDeclTemplateParameterLists(D));
1830   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1831   if (D->getTypeSourceInfo())
1832     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1833   else
1834     TRY_TO(TraverseType(D->getType()));
1835   return true;
1836 }
1837
1838 DEF_TRAVERSE_DECL(DecompositionDecl, {
1839   TRY_TO(TraverseVarHelper(D));
1840   for (auto *Binding : D->bindings()) {
1841     TRY_TO(TraverseDecl(Binding));
1842   }
1843 })
1844
1845 DEF_TRAVERSE_DECL(BindingDecl, {
1846   if (getDerived().shouldVisitImplicitCode())
1847     TRY_TO(TraverseStmt(D->getBinding()));
1848 })
1849
1850 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1851
1852 DEF_TRAVERSE_DECL(FieldDecl, {
1853   TRY_TO(TraverseDeclaratorHelper(D));
1854   if (D->isBitField())
1855     TRY_TO(TraverseStmt(D->getBitWidth()));
1856   else if (D->hasInClassInitializer())
1857     TRY_TO(TraverseStmt(D->getInClassInitializer()));
1858 })
1859
1860 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1861   TRY_TO(TraverseDeclaratorHelper(D));
1862   if (D->isBitField())
1863     TRY_TO(TraverseStmt(D->getBitWidth()));
1864   // FIXME: implement the rest.
1865 })
1866
1867 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1868   TRY_TO(TraverseDeclaratorHelper(D));
1869   if (D->isBitField())
1870     TRY_TO(TraverseStmt(D->getBitWidth()));
1871   // FIXME: implement the rest.
1872 })
1873
1874 template <typename Derived>
1875 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1876   TRY_TO(TraverseDeclTemplateParameterLists(D));
1877   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1878   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1879
1880   // If we're an explicit template specialization, iterate over the
1881   // template args that were explicitly specified.  If we were doing
1882   // this in typing order, we'd do it between the return type and
1883   // the function args, but both are handled by the FunctionTypeLoc
1884   // above, so we have to choose one side.  I've decided to do before.
1885   if (const FunctionTemplateSpecializationInfo *FTSI =
1886           D->getTemplateSpecializationInfo()) {
1887     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1888         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1889       // A specialization might not have explicit template arguments if it has
1890       // a templated return type and concrete arguments.
1891       if (const ASTTemplateArgumentListInfo *TALI =
1892               FTSI->TemplateArgumentsAsWritten) {
1893         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1894                                                   TALI->NumTemplateArgs));
1895       }
1896     }
1897   }
1898
1899   // Visit the function type itself, which can be either
1900   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
1901   // also covers the return type and the function parameters,
1902   // including exception specifications.
1903   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1904     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1905   } else if (getDerived().shouldVisitImplicitCode()) {
1906     // Visit parameter variable declarations of the implicit function
1907     // if the traverser is visiting implicit code. Parameter variable
1908     // declarations do not have valid TypeSourceInfo, so to visit them
1909     // we need to traverse the declarations explicitly.
1910     for (ParmVarDecl *Parameter : D->parameters()) {
1911       TRY_TO(TraverseDecl(Parameter));
1912     }
1913   }
1914
1915   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1916     // Constructor initializers.
1917     for (auto *I : Ctor->inits()) {
1918       TRY_TO(TraverseConstructorInitializer(I));
1919     }
1920   }
1921
1922   if (D->isThisDeclarationADefinition()) {
1923     TRY_TO(TraverseStmt(D->getBody())); // Function body.
1924   }
1925   return true;
1926 }
1927
1928 DEF_TRAVERSE_DECL(FunctionDecl, {
1929   // We skip decls_begin/decls_end, which are already covered by
1930   // TraverseFunctionHelper().
1931   ShouldVisitChildren = false;
1932   ReturnValue = TraverseFunctionHelper(D);
1933 })
1934
1935 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1936   // We skip decls_begin/decls_end, which are already covered by
1937   // TraverseFunctionHelper().
1938   ShouldVisitChildren = false;
1939   ReturnValue = TraverseFunctionHelper(D);
1940 })
1941
1942 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1943   // We skip decls_begin/decls_end, which are already covered by
1944   // TraverseFunctionHelper().
1945   ShouldVisitChildren = false;
1946   ReturnValue = TraverseFunctionHelper(D);
1947 })
1948
1949 // CXXConversionDecl is the declaration of a type conversion operator.
1950 // It's not a cast expression.
1951 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1952   // We skip decls_begin/decls_end, which are already covered by
1953   // TraverseFunctionHelper().
1954   ShouldVisitChildren = false;
1955   ReturnValue = TraverseFunctionHelper(D);
1956 })
1957
1958 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1959   // We skip decls_begin/decls_end, which are already covered by
1960   // TraverseFunctionHelper().
1961   ShouldVisitChildren = false;
1962   ReturnValue = TraverseFunctionHelper(D);
1963 })
1964
1965 template <typename Derived>
1966 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1967   TRY_TO(TraverseDeclaratorHelper(D));
1968   // Default params are taken care of when we traverse the ParmVarDecl.
1969   if (!isa<ParmVarDecl>(D) &&
1970       (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
1971     TRY_TO(TraverseStmt(D->getInit()));
1972   return true;
1973 }
1974
1975 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
1976
1977 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
1978
1979 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
1980   // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1981   TRY_TO(TraverseDeclaratorHelper(D));
1982   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1983     TRY_TO(TraverseStmt(D->getDefaultArgument()));
1984 })
1985
1986 DEF_TRAVERSE_DECL(ParmVarDecl, {
1987   TRY_TO(TraverseVarHelper(D));
1988
1989   if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
1990       !D->hasUnparsedDefaultArg())
1991     TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
1992
1993   if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
1994       !D->hasUnparsedDefaultArg())
1995     TRY_TO(TraverseStmt(D->getDefaultArg()));
1996 })
1997
1998 #undef DEF_TRAVERSE_DECL
1999
2000 // ----------------- Stmt traversal -----------------
2001 //
2002 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2003 // over the children defined in children() (every stmt defines these,
2004 // though sometimes the range is empty).  Each individual Traverse*
2005 // method only needs to worry about children other than those.  To see
2006 // what children() does for a given class, see, e.g.,
2007 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2008
2009 // This macro makes available a variable S, the passed-in stmt.
2010 #define DEF_TRAVERSE_STMT(STMT, CODE)                                          \
2011   template <typename Derived>                                                  \
2012   bool RecursiveASTVisitor<Derived>::Traverse##STMT(                           \
2013       STMT *S, DataRecursionQueue *Queue) {                                    \
2014     bool ShouldVisitChildren = true;                                           \
2015     bool ReturnValue = true;                                                   \
2016     if (!getDerived().shouldTraversePostOrder())                               \
2017       TRY_TO(WalkUpFrom##STMT(S));                                             \
2018     { CODE; }                                                                  \
2019     if (ShouldVisitChildren) {                                                 \
2020       for (Stmt *SubStmt : S->children()) {                                    \
2021         TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);                              \
2022       }                                                                        \
2023     }                                                                          \
2024     if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder())       \
2025       TRY_TO(WalkUpFrom##STMT(S));                                             \
2026     return ReturnValue;                                                        \
2027   }
2028
2029 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2030   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2031   for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2032     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2033   }
2034   for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2035     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2036   }
2037   for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2038     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2039   }
2040   // children() iterates over inputExpr and outputExpr.
2041 })
2042
2043 DEF_TRAVERSE_STMT(
2044     MSAsmStmt,
2045     {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
2046      // added this needs to be implemented.
2047     })
2048
2049 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2050   TRY_TO(TraverseDecl(S->getExceptionDecl()));
2051   // children() iterates over the handler block.
2052 })
2053
2054 DEF_TRAVERSE_STMT(DeclStmt, {
2055   for (auto *I : S->decls()) {
2056     TRY_TO(TraverseDecl(I));
2057   }
2058   // Suppress the default iteration over children() by
2059   // returning.  Here's why: A DeclStmt looks like 'type var [=
2060   // initializer]'.  The decls above already traverse over the
2061   // initializers, so we don't have to do it again (which
2062   // children() would do).
2063   ShouldVisitChildren = false;
2064 })
2065
2066 // These non-expr stmts (most of them), do not need any action except
2067 // iterating over the children.
2068 DEF_TRAVERSE_STMT(BreakStmt, {})
2069 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2070 DEF_TRAVERSE_STMT(CaseStmt, {})
2071 DEF_TRAVERSE_STMT(CompoundStmt, {})
2072 DEF_TRAVERSE_STMT(ContinueStmt, {})
2073 DEF_TRAVERSE_STMT(DefaultStmt, {})
2074 DEF_TRAVERSE_STMT(DoStmt, {})
2075 DEF_TRAVERSE_STMT(ForStmt, {})
2076 DEF_TRAVERSE_STMT(GotoStmt, {})
2077 DEF_TRAVERSE_STMT(IfStmt, {})
2078 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2079 DEF_TRAVERSE_STMT(LabelStmt, {})
2080 DEF_TRAVERSE_STMT(AttributedStmt, {})
2081 DEF_TRAVERSE_STMT(NullStmt, {})
2082 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2083 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2084 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2085 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2086 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2087 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2088 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2089
2090 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2091   if (!getDerived().shouldVisitImplicitCode()) {
2092     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2093     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2094     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2095     // Visit everything else only if shouldVisitImplicitCode().
2096     ShouldVisitChildren = false;
2097   }
2098 })
2099
2100 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2101   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2102   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2103 })
2104
2105 DEF_TRAVERSE_STMT(ReturnStmt, {})
2106 DEF_TRAVERSE_STMT(SwitchStmt, {})
2107 DEF_TRAVERSE_STMT(WhileStmt, {})
2108
2109 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2110   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2111   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2112   if (S->hasExplicitTemplateArgs()) {
2113     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2114                                               S->getNumTemplateArgs()));
2115   }
2116 })
2117
2118 DEF_TRAVERSE_STMT(DeclRefExpr, {
2119   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2120   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2121   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2122                                             S->getNumTemplateArgs()));
2123 })
2124
2125 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2126   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2127   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2128   if (S->hasExplicitTemplateArgs()) {
2129     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2130                                               S->getNumTemplateArgs()));
2131   }
2132 })
2133
2134 DEF_TRAVERSE_STMT(MemberExpr, {
2135   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2136   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2137   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2138                                             S->getNumTemplateArgs()));
2139 })
2140
2141 DEF_TRAVERSE_STMT(
2142     ImplicitCastExpr,
2143     {// We don't traverse the cast type, as it's not written in the
2144      // source code.
2145     })
2146
2147 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2148   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2149 })
2150
2151 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2152   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2153 })
2154
2155 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2156   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2157 })
2158
2159 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2160   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2161 })
2162
2163 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2164   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2165 })
2166
2167 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2168   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2169 })
2170
2171 template <typename Derived>
2172 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2173     InitListExpr *S, DataRecursionQueue *Queue) {
2174   if (S) {
2175     // Skip this if we traverse postorder. We will visit it later
2176     // in PostVisitStmt.
2177     if (!getDerived().shouldTraversePostOrder())
2178       TRY_TO(WalkUpFromInitListExpr(S));
2179
2180     // All we need are the default actions.  FIXME: use a helper function.
2181     for (Stmt *SubStmt : S->children()) {
2182       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2183     }
2184   }
2185   return true;
2186 }
2187
2188 // This method is called once for each pair of syntactic and semantic
2189 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2190 // may cause some of the children to be visited twice, if they appear both in
2191 // the syntactic and the semantic form.
2192 //
2193 // There is no guarantee about which form \p S takes when this method is called.
2194 DEF_TRAVERSE_STMT(InitListExpr, {
2195   TRY_TO(TraverseSynOrSemInitListExpr(
2196       S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2197   TRY_TO(TraverseSynOrSemInitListExpr(
2198       S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2199   ShouldVisitChildren = false;
2200 })
2201
2202 // GenericSelectionExpr is a special case because the types and expressions
2203 // are interleaved.  We also need to watch out for null types (default
2204 // generic associations).
2205 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2206   TRY_TO(TraverseStmt(S->getControllingExpr()));
2207   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2208     if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2209       TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2210     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2211   }
2212   ShouldVisitChildren = false;
2213 })
2214
2215 // PseudoObjectExpr is a special case because of the weirdness with
2216 // syntactic expressions and opaque values.
2217 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2218   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2219   for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2220                                             e = S->semantics_end();
2221        i != e; ++i) {
2222     Expr *sub = *i;
2223     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2224       sub = OVE->getSourceExpr();
2225     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2226   }
2227   ShouldVisitChildren = false;
2228 })
2229
2230 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2231   // This is called for code like 'return T()' where T is a built-in
2232   // (i.e. non-class) type.
2233   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2234 })
2235
2236 DEF_TRAVERSE_STMT(CXXNewExpr, {
2237   // The child-iterator will pick up the other arguments.
2238   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2239 })
2240
2241 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2242   // The child-iterator will pick up the expression representing
2243   // the field.
2244   // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2245   // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2246   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2247 })
2248
2249 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2250   // The child-iterator will pick up the arg if it's an expression,
2251   // but not if it's a type.
2252   if (S->isArgumentType())
2253     TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2254 })
2255
2256 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2257   // The child-iterator will pick up the arg if it's an expression,
2258   // but not if it's a type.
2259   if (S->isTypeOperand())
2260     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2261 })
2262
2263 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2264   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2265 })
2266
2267 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2268
2269 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2270   // The child-iterator will pick up the arg if it's an expression,
2271   // but not if it's a type.
2272   if (S->isTypeOperand())
2273     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2274 })
2275
2276 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2277   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2278     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2279 })
2280
2281 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2282   TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2283 })
2284
2285 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2286                   { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2287
2288 DEF_TRAVERSE_STMT(VAArgExpr, {
2289   // The child-iterator will pick up the expression argument.
2290   TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2291 })
2292
2293 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2294   // This is called for code like 'return T()' where T is a class type.
2295   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2296 })
2297
2298 // Walk only the visible parts of lambda expressions.
2299 DEF_TRAVERSE_STMT(LambdaExpr, {
2300   for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2301     const LambdaCapture *C = S->capture_begin() + I;
2302     if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2303       TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2304     }
2305   }
2306
2307   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2308   FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
2309
2310   if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2311     // Visit the whole type.
2312     TRY_TO(TraverseTypeLoc(TL));
2313   } else {
2314     if (S->hasExplicitParameters()) {
2315       // Visit parameters.
2316       for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2317         TRY_TO(TraverseDecl(Proto.getParam(I)));
2318       }
2319     } else if (S->hasExplicitResultType()) {
2320       TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2321     }
2322
2323     auto *T = Proto.getTypePtr();
2324     for (const auto &E : T->exceptions()) {
2325       TRY_TO(TraverseType(E));
2326     }
2327
2328     if (Expr *NE = T->getNoexceptExpr())
2329       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2330   }
2331
2332   ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2333   ShouldVisitChildren = false;
2334 })
2335
2336 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2337   // This is called for code like 'T()', where T is a template argument.
2338   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2339 })
2340
2341 // These expressions all might take explicit template arguments.
2342 // We traverse those if so.  FIXME: implement these.
2343 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2344 DEF_TRAVERSE_STMT(CallExpr, {})
2345 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2346
2347 // These exprs (most of them), do not need any action except iterating
2348 // over the children.
2349 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2350 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2351 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2352
2353 DEF_TRAVERSE_STMT(BlockExpr, {
2354   TRY_TO(TraverseDecl(S->getBlockDecl()));
2355   return true; // no child statements to loop through.
2356 })
2357
2358 DEF_TRAVERSE_STMT(ChooseExpr, {})
2359 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2360   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2361 })
2362 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2363 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2364
2365 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2366   if (getDerived().shouldVisitImplicitCode())
2367     TRY_TO(TraverseStmt(S->getExpr()));
2368 })
2369
2370 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2371 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2372 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2373 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2374 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2375 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2376
2377 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2378   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2379   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2380     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2381   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2382     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2383 })
2384
2385 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2386 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2387 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2388 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2389 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2390 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2391 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2392 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2393 DEF_TRAVERSE_STMT(NoInitExpr, {})
2394 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2395   // FIXME: The source expression of the OVE should be listed as
2396   // a child of the ArrayInitLoopExpr.
2397   if (OpaqueValueExpr *OVE = S->getCommonExpr())
2398     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2399 })
2400 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2401 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2402
2403 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2404   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2405     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2406 })
2407
2408 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2409 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2410
2411 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2412   if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2413     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2414 })
2415
2416 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2417 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2418 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2419 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2420 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2421
2422 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2423   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2424 })
2425
2426 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2427 DEF_TRAVERSE_STMT(ParenExpr, {})
2428 DEF_TRAVERSE_STMT(ParenListExpr, {})
2429 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2430 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2431 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2432 DEF_TRAVERSE_STMT(StmtExpr, {})
2433 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2434   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2435   if (S->hasExplicitTemplateArgs()) {
2436     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2437                                               S->getNumTemplateArgs()));
2438   }
2439 })
2440
2441 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2442   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2443   if (S->hasExplicitTemplateArgs()) {
2444     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2445                                               S->getNumTemplateArgs()));
2446   }
2447 })
2448
2449 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2450 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2451 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2452 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2453 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2454
2455 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2456 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2457 DEF_TRAVERSE_STMT(TypoExpr, {})
2458 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2459
2460 // These operators (all of them) do not need any action except
2461 // iterating over the children.
2462 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2463 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2464 DEF_TRAVERSE_STMT(UnaryOperator, {})
2465 DEF_TRAVERSE_STMT(BinaryOperator, {})
2466 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2467 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2468 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2469 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2470 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2471 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2472 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2473 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2474 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2475 DEF_TRAVERSE_STMT(AtomicExpr, {})
2476
2477 // For coroutines expressions, traverse either the operand
2478 // as written or the implied calls, depending on what the
2479 // derived class requests.
2480 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2481   if (!getDerived().shouldVisitImplicitCode()) {
2482     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2483     ShouldVisitChildren = false;
2484   }
2485 })
2486 DEF_TRAVERSE_STMT(CoreturnStmt, {
2487   if (!getDerived().shouldVisitImplicitCode()) {
2488     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2489     ShouldVisitChildren = false;
2490   }
2491 })
2492 DEF_TRAVERSE_STMT(CoawaitExpr, {
2493   if (!getDerived().shouldVisitImplicitCode()) {
2494     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2495     ShouldVisitChildren = false;
2496   }
2497 })
2498 DEF_TRAVERSE_STMT(CoyieldExpr, {
2499   if (!getDerived().shouldVisitImplicitCode()) {
2500     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2501     ShouldVisitChildren = false;
2502   }
2503 })
2504
2505 // These literals (all of them) do not need any action.
2506 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2507 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2508 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2509 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2510 DEF_TRAVERSE_STMT(StringLiteral, {})
2511 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2512 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2513 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2514 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2515
2516 // Traverse OpenCL: AsType, Convert.
2517 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2518
2519 // OpenMP directives.
2520 template <typename Derived>
2521 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2522     OMPExecutableDirective *S) {
2523   for (auto *C : S->clauses()) {
2524     TRY_TO(TraverseOMPClause(C));
2525   }
2526   return true;
2527 }
2528
2529 template <typename Derived>
2530 bool
2531 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2532   return TraverseOMPExecutableDirective(S);
2533 }
2534
2535 DEF_TRAVERSE_STMT(OMPParallelDirective,
2536                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2537
2538 DEF_TRAVERSE_STMT(OMPSimdDirective,
2539                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2540
2541 DEF_TRAVERSE_STMT(OMPForDirective,
2542                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2543
2544 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2545                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2546
2547 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2548                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2549
2550 DEF_TRAVERSE_STMT(OMPSectionDirective,
2551                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2552
2553 DEF_TRAVERSE_STMT(OMPSingleDirective,
2554                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2555
2556 DEF_TRAVERSE_STMT(OMPMasterDirective,
2557                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2558
2559 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2560   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2561   TRY_TO(TraverseOMPExecutableDirective(S));
2562 })
2563
2564 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2565                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2566
2567 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2568                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2569
2570 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2571                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2572
2573 DEF_TRAVERSE_STMT(OMPTaskDirective,
2574                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2575
2576 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2577                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2578
2579 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2580                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2581
2582 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2583                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2584
2585 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2586                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2587
2588 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2589                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2590
2591 DEF_TRAVERSE_STMT(OMPCancelDirective,
2592                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2593
2594 DEF_TRAVERSE_STMT(OMPFlushDirective,
2595                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2596
2597 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2598                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2599
2600 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2601                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2602
2603 DEF_TRAVERSE_STMT(OMPTargetDirective,
2604                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2605
2606 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2607                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2608
2609 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2610                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2611
2612 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2613                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2614
2615 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2616                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2617
2618 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2619                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2620
2621 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2622                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2623
2624 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2625                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2626
2627 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2628                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2629
2630 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2631                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2632
2633 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2634                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2635
2636 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2637                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2638
2639 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2640                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2641
2642 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2643                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2644
2645 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2646                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2647
2648 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
2649                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2650
2651 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
2652                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2653
2654 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
2655                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2656
2657 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
2658                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2659
2660 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
2661                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2662
2663 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
2664                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2665
2666 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
2667                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2668
2669 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
2670                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2671
2672 // OpenMP clauses.
2673 template <typename Derived>
2674 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2675   if (!C)
2676     return true;
2677   switch (C->getClauseKind()) {
2678 #define OPENMP_CLAUSE(Name, Class)                                             \
2679   case OMPC_##Name:                                                            \
2680     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
2681     break;
2682 #include "clang/Basic/OpenMPKinds.def"
2683   case OMPC_threadprivate:
2684   case OMPC_uniform:
2685   case OMPC_unknown:
2686     break;
2687   }
2688   return true;
2689 }
2690
2691 template <typename Derived>
2692 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2693     OMPClauseWithPreInit *Node) {
2694   TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2695   return true;
2696 }
2697
2698 template <typename Derived>
2699 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2700     OMPClauseWithPostUpdate *Node) {
2701   TRY_TO(VisitOMPClauseWithPreInit(Node));
2702   TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2703   return true;
2704 }
2705
2706 template <typename Derived>
2707 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2708   TRY_TO(TraverseStmt(C->getCondition()));
2709   return true;
2710 }
2711
2712 template <typename Derived>
2713 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2714   TRY_TO(TraverseStmt(C->getCondition()));
2715   return true;
2716 }
2717
2718 template <typename Derived>
2719 bool
2720 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2721   TRY_TO(TraverseStmt(C->getNumThreads()));
2722   return true;
2723 }
2724
2725 template <typename Derived>
2726 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2727   TRY_TO(TraverseStmt(C->getSafelen()));
2728   return true;
2729 }
2730
2731 template <typename Derived>
2732 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2733   TRY_TO(TraverseStmt(C->getSimdlen()));
2734   return true;
2735 }
2736
2737 template <typename Derived>
2738 bool
2739 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2740   TRY_TO(TraverseStmt(C->getNumForLoops()));
2741   return true;
2742 }
2743
2744 template <typename Derived>
2745 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2746   return true;
2747 }
2748
2749 template <typename Derived>
2750 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2751   return true;
2752 }
2753
2754 template <typename Derived>
2755 bool
2756 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2757   TRY_TO(VisitOMPClauseWithPreInit(C));
2758   TRY_TO(TraverseStmt(C->getChunkSize()));
2759   return true;
2760 }
2761
2762 template <typename Derived>
2763 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2764   TRY_TO(TraverseStmt(C->getNumForLoops()));
2765   return true;
2766 }
2767
2768 template <typename Derived>
2769 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2770   return true;
2771 }
2772
2773 template <typename Derived>
2774 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2775   return true;
2776 }
2777
2778 template <typename Derived>
2779 bool
2780 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2781   return true;
2782 }
2783
2784 template <typename Derived>
2785 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2786   return true;
2787 }
2788
2789 template <typename Derived>
2790 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2791   return true;
2792 }
2793
2794 template <typename Derived>
2795 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2796   return true;
2797 }
2798
2799 template <typename Derived>
2800 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2801   return true;
2802 }
2803
2804 template <typename Derived>
2805 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2806   return true;
2807 }
2808
2809 template <typename Derived>
2810 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2811   return true;
2812 }
2813
2814 template <typename Derived>
2815 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2816   return true;
2817 }
2818
2819 template <typename Derived>
2820 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2821   return true;
2822 }
2823
2824 template <typename Derived>
2825 template <typename T>
2826 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2827   for (auto *E : Node->varlists()) {
2828     TRY_TO(TraverseStmt(E));
2829   }
2830   return true;
2831 }
2832
2833 template <typename Derived>
2834 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2835   TRY_TO(VisitOMPClauseList(C));
2836   for (auto *E : C->private_copies()) {
2837     TRY_TO(TraverseStmt(E));
2838   }
2839   return true;
2840 }
2841
2842 template <typename Derived>
2843 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2844     OMPFirstprivateClause *C) {
2845   TRY_TO(VisitOMPClauseList(C));
2846   TRY_TO(VisitOMPClauseWithPreInit(C));
2847   for (auto *E : C->private_copies()) {
2848     TRY_TO(TraverseStmt(E));
2849   }
2850   for (auto *E : C->inits()) {
2851     TRY_TO(TraverseStmt(E));
2852   }
2853   return true;
2854 }
2855
2856 template <typename Derived>
2857 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2858     OMPLastprivateClause *C) {
2859   TRY_TO(VisitOMPClauseList(C));
2860   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2861   for (auto *E : C->private_copies()) {
2862     TRY_TO(TraverseStmt(E));
2863   }
2864   for (auto *E : C->source_exprs()) {
2865     TRY_TO(TraverseStmt(E));
2866   }
2867   for (auto *E : C->destination_exprs()) {
2868     TRY_TO(TraverseStmt(E));
2869   }
2870   for (auto *E : C->assignment_ops()) {
2871     TRY_TO(TraverseStmt(E));
2872   }
2873   return true;
2874 }
2875
2876 template <typename Derived>
2877 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2878   TRY_TO(VisitOMPClauseList(C));
2879   return true;
2880 }
2881
2882 template <typename Derived>
2883 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2884   TRY_TO(TraverseStmt(C->getStep()));
2885   TRY_TO(TraverseStmt(C->getCalcStep()));
2886   TRY_TO(VisitOMPClauseList(C));
2887   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2888   for (auto *E : C->privates()) {
2889     TRY_TO(TraverseStmt(E));
2890   }
2891   for (auto *E : C->inits()) {
2892     TRY_TO(TraverseStmt(E));
2893   }
2894   for (auto *E : C->updates()) {
2895     TRY_TO(TraverseStmt(E));
2896   }
2897   for (auto *E : C->finals()) {
2898     TRY_TO(TraverseStmt(E));
2899   }
2900   return true;
2901 }
2902
2903 template <typename Derived>
2904 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2905   TRY_TO(TraverseStmt(C->getAlignment()));
2906   TRY_TO(VisitOMPClauseList(C));
2907   return true;
2908 }
2909
2910 template <typename Derived>
2911 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2912   TRY_TO(VisitOMPClauseList(C));
2913   for (auto *E : C->source_exprs()) {
2914     TRY_TO(TraverseStmt(E));
2915   }
2916   for (auto *E : C->destination_exprs()) {
2917     TRY_TO(TraverseStmt(E));
2918   }
2919   for (auto *E : C->assignment_ops()) {
2920     TRY_TO(TraverseStmt(E));
2921   }
2922   return true;
2923 }
2924
2925 template <typename Derived>
2926 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2927     OMPCopyprivateClause *C) {
2928   TRY_TO(VisitOMPClauseList(C));
2929   for (auto *E : C->source_exprs()) {
2930     TRY_TO(TraverseStmt(E));
2931   }
2932   for (auto *E : C->destination_exprs()) {
2933     TRY_TO(TraverseStmt(E));
2934   }
2935   for (auto *E : C->assignment_ops()) {
2936     TRY_TO(TraverseStmt(E));
2937   }
2938   return true;
2939 }
2940
2941 template <typename Derived>
2942 bool
2943 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
2944   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
2945   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
2946   TRY_TO(VisitOMPClauseList(C));
2947   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2948   for (auto *E : C->privates()) {
2949     TRY_TO(TraverseStmt(E));
2950   }
2951   for (auto *E : C->lhs_exprs()) {
2952     TRY_TO(TraverseStmt(E));
2953   }
2954   for (auto *E : C->rhs_exprs()) {
2955     TRY_TO(TraverseStmt(E));
2956   }
2957   for (auto *E : C->reduction_ops()) {
2958     TRY_TO(TraverseStmt(E));
2959   }
2960   return true;
2961 }
2962
2963 template <typename Derived>
2964 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
2965   TRY_TO(VisitOMPClauseList(C));
2966   return true;
2967 }
2968
2969 template <typename Derived>
2970 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
2971   TRY_TO(VisitOMPClauseList(C));
2972   return true;
2973 }
2974
2975 template <typename Derived>
2976 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
2977   TRY_TO(TraverseStmt(C->getDevice()));
2978   return true;
2979 }
2980
2981 template <typename Derived>
2982 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
2983   TRY_TO(VisitOMPClauseList(C));
2984   return true;
2985 }
2986
2987 template <typename Derived>
2988 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
2989     OMPNumTeamsClause *C) {
2990   TRY_TO(TraverseStmt(C->getNumTeams()));
2991   return true;
2992 }
2993
2994 template <typename Derived>
2995 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
2996     OMPThreadLimitClause *C) {
2997   TRY_TO(TraverseStmt(C->getThreadLimit()));
2998   return true;
2999 }
3000
3001 template <typename Derived>
3002 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3003     OMPPriorityClause *C) {
3004   TRY_TO(TraverseStmt(C->getPriority()));
3005   return true;
3006 }
3007
3008 template <typename Derived>
3009 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3010     OMPGrainsizeClause *C) {
3011   TRY_TO(TraverseStmt(C->getGrainsize()));
3012   return true;
3013 }
3014
3015 template <typename Derived>
3016 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3017     OMPNumTasksClause *C) {
3018   TRY_TO(TraverseStmt(C->getNumTasks()));
3019   return true;
3020 }
3021
3022 template <typename Derived>
3023 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3024   TRY_TO(TraverseStmt(C->getHint()));
3025   return true;
3026 }
3027
3028 template <typename Derived>
3029 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3030     OMPDistScheduleClause *C) {
3031   TRY_TO(VisitOMPClauseWithPreInit(C));
3032   TRY_TO(TraverseStmt(C->getChunkSize()));
3033   return true;
3034 }
3035
3036 template <typename Derived>
3037 bool
3038 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3039   return true;
3040 }
3041
3042 template <typename Derived>
3043 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3044   TRY_TO(VisitOMPClauseList(C));
3045   return true;
3046 }
3047
3048 template <typename Derived>
3049 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3050   TRY_TO(VisitOMPClauseList(C));
3051   return true;
3052 }
3053
3054 template <typename Derived>
3055 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3056     OMPUseDevicePtrClause *C) {
3057   TRY_TO(VisitOMPClauseList(C));
3058   return true;
3059 }
3060
3061 template <typename Derived>
3062 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3063     OMPIsDevicePtrClause *C) {
3064   TRY_TO(VisitOMPClauseList(C));
3065   return true;
3066 }
3067
3068 // FIXME: look at the following tricky-seeming exprs to see if we
3069 // need to recurse on anything.  These are ones that have methods
3070 // returning decls or qualtypes or nestednamespecifier -- though I'm
3071 // not sure if they own them -- or just seemed very complicated, or
3072 // had lots of sub-types to explore.
3073 //
3074 // VisitOverloadExpr and its children: recurse on template args? etc?
3075
3076 // FIXME: go through all the stmts and exprs again, and see which of them
3077 // create new types, and recurse on the types (TypeLocs?) of those.
3078 // Candidates:
3079 //
3080 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
3081 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
3082 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
3083 //    Every class that has getQualifier.
3084
3085 #undef DEF_TRAVERSE_STMT
3086 #undef TRAVERSE_STMT
3087 #undef TRAVERSE_STMT_BASE
3088
3089 #undef TRY_TO
3090
3091 } // end namespace clang
3092
3093 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H