]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h
Merge ^/head r316992 through r317215.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / 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::CXXDeductionGuideName:
778     TRY_TO(TraverseTemplateName(
779         TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
780     break;
781
782   case DeclarationName::Identifier:
783   case DeclarationName::ObjCZeroArgSelector:
784   case DeclarationName::ObjCOneArgSelector:
785   case DeclarationName::ObjCMultiArgSelector:
786   case DeclarationName::CXXOperatorName:
787   case DeclarationName::CXXLiteralOperatorName:
788   case DeclarationName::CXXUsingDirective:
789     break;
790   }
791
792   return true;
793 }
794
795 template <typename Derived>
796 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
797   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
798     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
799   else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
800     TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
801
802   return true;
803 }
804
805 template <typename Derived>
806 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
807     const TemplateArgument &Arg) {
808   switch (Arg.getKind()) {
809   case TemplateArgument::Null:
810   case TemplateArgument::Declaration:
811   case TemplateArgument::Integral:
812   case TemplateArgument::NullPtr:
813     return true;
814
815   case TemplateArgument::Type:
816     return getDerived().TraverseType(Arg.getAsType());
817
818   case TemplateArgument::Template:
819   case TemplateArgument::TemplateExpansion:
820     return getDerived().TraverseTemplateName(
821         Arg.getAsTemplateOrTemplatePattern());
822
823   case TemplateArgument::Expression:
824     return getDerived().TraverseStmt(Arg.getAsExpr());
825
826   case TemplateArgument::Pack:
827     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
828                                                   Arg.pack_size());
829   }
830
831   return true;
832 }
833
834 // FIXME: no template name location?
835 // FIXME: no source locations for a template argument pack?
836 template <typename Derived>
837 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
838     const TemplateArgumentLoc &ArgLoc) {
839   const TemplateArgument &Arg = ArgLoc.getArgument();
840
841   switch (Arg.getKind()) {
842   case TemplateArgument::Null:
843   case TemplateArgument::Declaration:
844   case TemplateArgument::Integral:
845   case TemplateArgument::NullPtr:
846     return true;
847
848   case TemplateArgument::Type: {
849     // FIXME: how can TSI ever be NULL?
850     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
851       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
852     else
853       return getDerived().TraverseType(Arg.getAsType());
854   }
855
856   case TemplateArgument::Template:
857   case TemplateArgument::TemplateExpansion:
858     if (ArgLoc.getTemplateQualifierLoc())
859       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
860           ArgLoc.getTemplateQualifierLoc()));
861     return getDerived().TraverseTemplateName(
862         Arg.getAsTemplateOrTemplatePattern());
863
864   case TemplateArgument::Expression:
865     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
866
867   case TemplateArgument::Pack:
868     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
869                                                   Arg.pack_size());
870   }
871
872   return true;
873 }
874
875 template <typename Derived>
876 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
877     const TemplateArgument *Args, unsigned NumArgs) {
878   for (unsigned I = 0; I != NumArgs; ++I) {
879     TRY_TO(TraverseTemplateArgument(Args[I]));
880   }
881
882   return true;
883 }
884
885 template <typename Derived>
886 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
887     CXXCtorInitializer *Init) {
888   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
889     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
890
891   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
892     TRY_TO(TraverseStmt(Init->getInit()));
893
894   return true;
895 }
896
897 template <typename Derived>
898 bool
899 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
900                                                     const LambdaCapture *C,
901                                                     Expr *Init) {
902   if (LE->isInitCapture(C))
903     TRY_TO(TraverseDecl(C->getCapturedVar()));
904   else
905     TRY_TO(TraverseStmt(Init));
906   return true;
907 }
908
909 template <typename Derived>
910 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(
911     LambdaExpr *LE, DataRecursionQueue *Queue) {
912   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(LE->getBody());
913   return true;
914 }
915
916 // ----------------- Type traversal -----------------
917
918 // This macro makes available a variable T, the passed-in type.
919 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
920   template <typename Derived>                                                  \
921   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
922     if (!getDerived().shouldTraversePostOrder())                               \
923       TRY_TO(WalkUpFrom##TYPE(T));                                             \
924     { CODE; }                                                                  \
925     if (getDerived().shouldTraversePostOrder())                                \
926       TRY_TO(WalkUpFrom##TYPE(T));                                             \
927     return true;                                                               \
928   }
929
930 DEF_TRAVERSE_TYPE(BuiltinType, {})
931
932 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
933
934 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
935
936 DEF_TRAVERSE_TYPE(BlockPointerType,
937                   { TRY_TO(TraverseType(T->getPointeeType())); })
938
939 DEF_TRAVERSE_TYPE(LValueReferenceType,
940                   { TRY_TO(TraverseType(T->getPointeeType())); })
941
942 DEF_TRAVERSE_TYPE(RValueReferenceType,
943                   { TRY_TO(TraverseType(T->getPointeeType())); })
944
945 DEF_TRAVERSE_TYPE(MemberPointerType, {
946   TRY_TO(TraverseType(QualType(T->getClass(), 0)));
947   TRY_TO(TraverseType(T->getPointeeType()));
948 })
949
950 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
951
952 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
953
954 DEF_TRAVERSE_TYPE(ConstantArrayType,
955                   { TRY_TO(TraverseType(T->getElementType())); })
956
957 DEF_TRAVERSE_TYPE(IncompleteArrayType,
958                   { TRY_TO(TraverseType(T->getElementType())); })
959
960 DEF_TRAVERSE_TYPE(VariableArrayType, {
961   TRY_TO(TraverseType(T->getElementType()));
962   TRY_TO(TraverseStmt(T->getSizeExpr()));
963 })
964
965 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
966   TRY_TO(TraverseType(T->getElementType()));
967   if (T->getSizeExpr())
968     TRY_TO(TraverseStmt(T->getSizeExpr()));
969 })
970
971 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
972   if (T->getSizeExpr())
973     TRY_TO(TraverseStmt(T->getSizeExpr()));
974   TRY_TO(TraverseType(T->getElementType()));
975 })
976
977 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
978
979 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
980
981 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
982                   { TRY_TO(TraverseType(T->getReturnType())); })
983
984 DEF_TRAVERSE_TYPE(FunctionProtoType, {
985   TRY_TO(TraverseType(T->getReturnType()));
986
987   for (const auto &A : T->param_types()) {
988     TRY_TO(TraverseType(A));
989   }
990
991   for (const auto &E : T->exceptions()) {
992     TRY_TO(TraverseType(E));
993   }
994
995   if (Expr *NE = T->getNoexceptExpr())
996     TRY_TO(TraverseStmt(NE));
997 })
998
999 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
1000 DEF_TRAVERSE_TYPE(TypedefType, {})
1001
1002 DEF_TRAVERSE_TYPE(TypeOfExprType,
1003                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1004
1005 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
1006
1007 DEF_TRAVERSE_TYPE(DecltypeType,
1008                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1009
1010 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1011   TRY_TO(TraverseType(T->getBaseType()));
1012   TRY_TO(TraverseType(T->getUnderlyingType()));
1013 })
1014
1015 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1016 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
1017   TRY_TO(TraverseTemplateName(T->getTemplateName()));
1018   TRY_TO(TraverseType(T->getDeducedType()));
1019 })
1020
1021 DEF_TRAVERSE_TYPE(RecordType, {})
1022 DEF_TRAVERSE_TYPE(EnumType, {})
1023 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1024 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
1025 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
1026
1027 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1028   TRY_TO(TraverseTemplateName(T->getTemplateName()));
1029   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1030 })
1031
1032 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1033
1034 DEF_TRAVERSE_TYPE(AttributedType,
1035                   { TRY_TO(TraverseType(T->getModifiedType())); })
1036
1037 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1038
1039 DEF_TRAVERSE_TYPE(ElaboratedType, {
1040   if (T->getQualifier()) {
1041     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1042   }
1043   TRY_TO(TraverseType(T->getNamedType()));
1044 })
1045
1046 DEF_TRAVERSE_TYPE(DependentNameType,
1047                   { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1048
1049 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1050   TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1051   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1052 })
1053
1054 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1055
1056 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1057
1058 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1059
1060 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1061   // We have to watch out here because an ObjCInterfaceType's base
1062   // type is itself.
1063   if (T->getBaseType().getTypePtr() != T)
1064     TRY_TO(TraverseType(T->getBaseType()));
1065   for (auto typeArg : T->getTypeArgsAsWritten()) {
1066     TRY_TO(TraverseType(typeArg));
1067   }
1068 })
1069
1070 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1071                   { TRY_TO(TraverseType(T->getPointeeType())); })
1072
1073 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1074
1075 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1076
1077 #undef DEF_TRAVERSE_TYPE
1078
1079 // ----------------- TypeLoc traversal -----------------
1080
1081 // This macro makes available a variable TL, the passed-in TypeLoc.
1082 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1083 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1084 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1085 // continue to work.
1086 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                       \
1087   template <typename Derived>                                                  \
1088   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) {       \
1089     if (getDerived().shouldWalkTypesOfTypeLocs())                              \
1090       TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));           \
1091     TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                         \
1092     { CODE; }                                                                  \
1093     return true;                                                               \
1094   }
1095
1096 template <typename Derived>
1097 bool
1098 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1099   // Move this over to the 'main' typeloc tree.  Note that this is a
1100   // move -- we pretend that we were really looking at the unqualified
1101   // typeloc all along -- rather than a recursion, so we don't follow
1102   // the normal CRTP plan of going through
1103   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
1104   // twice for the same type (once as a QualifiedTypeLoc version of
1105   // the type, once as an UnqualifiedTypeLoc version of the type),
1106   // which in effect means we'd call VisitTypeLoc twice with the
1107   // 'same' type.  This solves that problem, at the cost of never
1108   // seeing the qualified version of the type (unless the client
1109   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
1110   // perfect solution.  A perfect solution probably requires making
1111   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1112   // wrapper around Type* -- rather than being its own class in the
1113   // type hierarchy.
1114   return TraverseTypeLoc(TL.getUnqualifiedLoc());
1115 }
1116
1117 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1118
1119 // FIXME: ComplexTypeLoc is unfinished
1120 DEF_TRAVERSE_TYPELOC(ComplexType, {
1121   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1122 })
1123
1124 DEF_TRAVERSE_TYPELOC(PointerType,
1125                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1126
1127 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1128                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1129
1130 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1131                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1132
1133 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1134                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1135
1136 // FIXME: location of base class?
1137 // We traverse this in the type case as well, but how is it not reached through
1138 // the pointee type?
1139 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1140   TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1141   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1142 })
1143
1144 DEF_TRAVERSE_TYPELOC(AdjustedType,
1145                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1146
1147 DEF_TRAVERSE_TYPELOC(DecayedType,
1148                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1149
1150 template <typename Derived>
1151 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1152   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1153   TRY_TO(TraverseStmt(TL.getSizeExpr()));
1154   return true;
1155 }
1156
1157 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1158   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1159   return TraverseArrayTypeLocHelper(TL);
1160 })
1161
1162 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1163   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1164   return TraverseArrayTypeLocHelper(TL);
1165 })
1166
1167 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1168   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1169   return TraverseArrayTypeLocHelper(TL);
1170 })
1171
1172 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1173   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1174   return TraverseArrayTypeLocHelper(TL);
1175 })
1176
1177 // FIXME: order? why not size expr first?
1178 // FIXME: base VectorTypeLoc is unfinished
1179 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1180   if (TL.getTypePtr()->getSizeExpr())
1181     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1182   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1183 })
1184
1185 // FIXME: VectorTypeLoc is unfinished
1186 DEF_TRAVERSE_TYPELOC(VectorType, {
1187   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1188 })
1189
1190 // FIXME: size and attributes
1191 // FIXME: base VectorTypeLoc is unfinished
1192 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1193   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1194 })
1195
1196 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1197                      { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1198
1199 // FIXME: location of exception specifications (attributes?)
1200 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1201   TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1202
1203   const FunctionProtoType *T = TL.getTypePtr();
1204
1205   for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1206     if (TL.getParam(I)) {
1207       TRY_TO(TraverseDecl(TL.getParam(I)));
1208     } else if (I < T->getNumParams()) {
1209       TRY_TO(TraverseType(T->getParamType(I)));
1210     }
1211   }
1212
1213   for (const auto &E : T->exceptions()) {
1214     TRY_TO(TraverseType(E));
1215   }
1216
1217   if (Expr *NE = T->getNoexceptExpr())
1218     TRY_TO(TraverseStmt(NE));
1219 })
1220
1221 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1222 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1223
1224 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1225                      { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1226
1227 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1228   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1229 })
1230
1231 // FIXME: location of underlying expr
1232 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1233   TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1234 })
1235
1236 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1237   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1238 })
1239
1240 DEF_TRAVERSE_TYPELOC(AutoType, {
1241   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1242 })
1243
1244 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
1245   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1246   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1247 })
1248
1249 DEF_TRAVERSE_TYPELOC(RecordType, {})
1250 DEF_TRAVERSE_TYPELOC(EnumType, {})
1251 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1252 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
1253 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
1254
1255 // FIXME: use the loc for the template name?
1256 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1257   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1258   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1259     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1260   }
1261 })
1262
1263 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1264
1265 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1266
1267 DEF_TRAVERSE_TYPELOC(AttributedType,
1268                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1269
1270 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1271   if (TL.getQualifierLoc()) {
1272     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1273   }
1274   TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1275 })
1276
1277 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1278   TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1279 })
1280
1281 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1282   if (TL.getQualifierLoc()) {
1283     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1284   }
1285
1286   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1287     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1288   }
1289 })
1290
1291 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1292                      { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1293
1294 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
1295
1296 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1297
1298 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1299   // We have to watch out here because an ObjCInterfaceType's base
1300   // type is itself.
1301   if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1302     TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1303   for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1304     TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1305 })
1306
1307 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1308                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1309
1310 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1311
1312 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1313
1314 #undef DEF_TRAVERSE_TYPELOC
1315
1316 // ----------------- Decl traversal -----------------
1317 //
1318 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1319 // the children that come from the DeclContext associated with it.
1320 // Therefore each Traverse* only needs to worry about children other
1321 // than those.
1322
1323 template <typename Derived>
1324 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1325   if (!DC)
1326     return true;
1327
1328   for (auto *Child : DC->decls()) {
1329     // BlockDecls and CapturedDecls are traversed through BlockExprs and
1330     // CapturedStmts respectively.
1331     if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1332       TRY_TO(TraverseDecl(Child));
1333   }
1334
1335   return true;
1336 }
1337
1338 // This macro makes available a variable D, the passed-in decl.
1339 #define DEF_TRAVERSE_DECL(DECL, CODE)                                          \
1340   template <typename Derived>                                                  \
1341   bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) {                 \
1342     bool ShouldVisitChildren = true;                                           \
1343     bool ReturnValue = true;                                                   \
1344     if (!getDerived().shouldTraversePostOrder())                               \
1345       TRY_TO(WalkUpFrom##DECL(D));                                             \
1346     { CODE; }                                                                  \
1347     if (ReturnValue && ShouldVisitChildren)                                    \
1348       TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));             \
1349     if (ReturnValue && getDerived().shouldTraversePostOrder())                 \
1350       TRY_TO(WalkUpFrom##DECL(D));                                             \
1351     return ReturnValue;                                                        \
1352   }
1353
1354 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1355
1356 DEF_TRAVERSE_DECL(BlockDecl, {
1357   if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1358     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1359   TRY_TO(TraverseStmt(D->getBody()));
1360   for (const auto &I : D->captures()) {
1361     if (I.hasCopyExpr()) {
1362       TRY_TO(TraverseStmt(I.getCopyExpr()));
1363     }
1364   }
1365   ShouldVisitChildren = false;
1366 })
1367
1368 DEF_TRAVERSE_DECL(CapturedDecl, {
1369   TRY_TO(TraverseStmt(D->getBody()));
1370   ShouldVisitChildren = false;
1371 })
1372
1373 DEF_TRAVERSE_DECL(EmptyDecl, {})
1374
1375 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1376                   { TRY_TO(TraverseStmt(D->getAsmString())); })
1377
1378 DEF_TRAVERSE_DECL(ImportDecl, {})
1379
1380 DEF_TRAVERSE_DECL(FriendDecl, {
1381   // Friend is either decl or a type.
1382   if (D->getFriendType())
1383     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1384   else
1385     TRY_TO(TraverseDecl(D->getFriendDecl()));
1386 })
1387
1388 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1389   if (D->getFriendType())
1390     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1391   else
1392     TRY_TO(TraverseDecl(D->getFriendDecl()));
1393   for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1394     TemplateParameterList *TPL = D->getTemplateParameterList(I);
1395     for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1396          ITPL != ETPL; ++ITPL) {
1397       TRY_TO(TraverseDecl(*ITPL));
1398     }
1399   }
1400 })
1401
1402 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1403   TRY_TO(TraverseDecl(D->getSpecialization()));
1404
1405   if (D->hasExplicitTemplateArgs()) {
1406     const TemplateArgumentListInfo &args = D->templateArgs();
1407     TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1408                                               args.size()));
1409   }
1410 })
1411
1412 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1413
1414 DEF_TRAVERSE_DECL(ExportDecl, {})
1415
1416 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1417                                         })
1418
1419 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1420   TRY_TO(TraverseStmt(D->getAssertExpr()));
1421   TRY_TO(TraverseStmt(D->getMessage()));
1422 })
1423
1424 DEF_TRAVERSE_DECL(
1425     TranslationUnitDecl,
1426     {// Code in an unnamed namespace shows up automatically in
1427      // decls_begin()/decls_end().  Thus we don't need to recurse on
1428      // D->getAnonymousNamespace().
1429     })
1430
1431 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1432
1433 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1434
1435 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1436
1437 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1438   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1439
1440   // We shouldn't traverse an aliased namespace, since it will be
1441   // defined (and, therefore, traversed) somewhere else.
1442   ShouldVisitChildren = false;
1443 })
1444
1445 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1446                              })
1447
1448 DEF_TRAVERSE_DECL(
1449     NamespaceDecl,
1450     {// Code in an unnamed namespace shows up automatically in
1451      // decls_begin()/decls_end().  Thus we don't need to recurse on
1452      // D->getAnonymousNamespace().
1453     })
1454
1455 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1456                                            })
1457
1458 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1459   if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1460     for (auto typeParam : *typeParamList) {
1461       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1462     }
1463   }
1464 })
1465
1466 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1467                                         })
1468
1469 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1470                                           })
1471
1472 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1473   if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1474     for (auto typeParam : *typeParamList) {
1475       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1476     }
1477   }
1478
1479   if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1480     TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1481   }
1482 })
1483
1484 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1485                                     })
1486
1487 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1488   if (D->getReturnTypeSourceInfo()) {
1489     TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1490   }
1491   for (ParmVarDecl *Parameter : D->parameters()) {
1492     TRY_TO(TraverseDecl(Parameter));
1493   }
1494   if (D->isThisDeclarationADefinition()) {
1495     TRY_TO(TraverseStmt(D->getBody()));
1496   }
1497   ShouldVisitChildren = false;
1498 })
1499
1500 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1501   if (D->hasExplicitBound()) {
1502     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1503     // We shouldn't traverse D->getTypeForDecl(); it's a result of
1504     // declaring the type alias, not something that was written in the
1505     // source.
1506   }
1507 })
1508
1509 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1510   if (D->getTypeSourceInfo())
1511     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1512   else
1513     TRY_TO(TraverseType(D->getType()));
1514   ShouldVisitChildren = false;
1515 })
1516
1517 DEF_TRAVERSE_DECL(UsingDecl, {
1518   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1519   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1520 })
1521
1522 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1523
1524 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1525   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1526 })
1527
1528 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1529
1530 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1531
1532 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1533   for (auto *I : D->varlists()) {
1534     TRY_TO(TraverseStmt(I));
1535   }
1536 })
1537
1538 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1539   TRY_TO(TraverseStmt(D->getCombiner()));
1540   if (auto *Initializer = D->getInitializer())
1541     TRY_TO(TraverseStmt(Initializer));
1542   TRY_TO(TraverseType(D->getType()));
1543   return true;
1544 })
1545
1546 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1547
1548 // A helper method for TemplateDecl's children.
1549 template <typename Derived>
1550 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1551     TemplateParameterList *TPL) {
1552   if (TPL) {
1553     for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1554          I != E; ++I) {
1555       TRY_TO(TraverseDecl(*I));
1556     }
1557   }
1558   return true;
1559 }
1560
1561 template <typename Derived>
1562 template <typename T>
1563 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1564   for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1565     TemplateParameterList *TPL = D->getTemplateParameterList(i);
1566     TraverseTemplateParameterListHelper(TPL);
1567   }
1568   return true;
1569 }
1570
1571 template <typename Derived>
1572 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1573     ClassTemplateDecl *D) {
1574   for (auto *SD : D->specializations()) {
1575     for (auto *RD : SD->redecls()) {
1576       // We don't want to visit injected-class-names in this traversal.
1577       if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1578         continue;
1579
1580       switch (
1581           cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1582       // Visit the implicit instantiations with the requested pattern.
1583       case TSK_Undeclared:
1584       case TSK_ImplicitInstantiation:
1585         TRY_TO(TraverseDecl(RD));
1586         break;
1587
1588       // We don't need to do anything on an explicit instantiation
1589       // or explicit specialization because there will be an explicit
1590       // node for it elsewhere.
1591       case TSK_ExplicitInstantiationDeclaration:
1592       case TSK_ExplicitInstantiationDefinition:
1593       case TSK_ExplicitSpecialization:
1594         break;
1595       }
1596     }
1597   }
1598
1599   return true;
1600 }
1601
1602 template <typename Derived>
1603 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1604     VarTemplateDecl *D) {
1605   for (auto *SD : D->specializations()) {
1606     for (auto *RD : SD->redecls()) {
1607       switch (
1608           cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1609       case TSK_Undeclared:
1610       case TSK_ImplicitInstantiation:
1611         TRY_TO(TraverseDecl(RD));
1612         break;
1613
1614       case TSK_ExplicitInstantiationDeclaration:
1615       case TSK_ExplicitInstantiationDefinition:
1616       case TSK_ExplicitSpecialization:
1617         break;
1618       }
1619     }
1620   }
1621
1622   return true;
1623 }
1624
1625 // A helper method for traversing the instantiations of a
1626 // function while skipping its specializations.
1627 template <typename Derived>
1628 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1629     FunctionTemplateDecl *D) {
1630   for (auto *FD : D->specializations()) {
1631     for (auto *RD : FD->redecls()) {
1632       switch (RD->getTemplateSpecializationKind()) {
1633       case TSK_Undeclared:
1634       case TSK_ImplicitInstantiation:
1635         // We don't know what kind of FunctionDecl this is.
1636         TRY_TO(TraverseDecl(RD));
1637         break;
1638
1639       // FIXME: For now traverse explicit instantiations here. Change that
1640       // once they are represented as dedicated nodes in the AST.
1641       case TSK_ExplicitInstantiationDeclaration:
1642       case TSK_ExplicitInstantiationDefinition:
1643         TRY_TO(TraverseDecl(RD));
1644         break;
1645
1646       case TSK_ExplicitSpecialization:
1647         break;
1648       }
1649     }
1650   }
1651
1652   return true;
1653 }
1654
1655 // This macro unifies the traversal of class, variable and function
1656 // template declarations.
1657 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)                                   \
1658   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, {                              \
1659     TRY_TO(TraverseDecl(D->getTemplatedDecl()));                               \
1660     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
1661                                                                                \
1662     /* By default, we do not traverse the instantiations of                    \
1663        class templates since they do not appear in the user code. The          \
1664        following code optionally traverses them.                               \
1665                                                                                \
1666        We only traverse the class instantiations when we see the canonical     \
1667        declaration of the template, to ensure we only visit them once. */      \
1668     if (getDerived().shouldVisitTemplateInstantiations() &&                    \
1669         D == D->getCanonicalDecl())                                            \
1670       TRY_TO(TraverseTemplateInstantiations(D));                               \
1671                                                                                \
1672     /* Note that getInstantiatedFromMemberTemplate() is just a link            \
1673        from a template instantiation back to the template from which           \
1674        it was instantiated, and thus should not be traversed. */               \
1675   })
1676
1677 DEF_TRAVERSE_TMPL_DECL(Class)
1678 DEF_TRAVERSE_TMPL_DECL(Var)
1679 DEF_TRAVERSE_TMPL_DECL(Function)
1680
1681 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1682   // D is the "T" in something like
1683   //   template <template <typename> class T> class container { };
1684   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1685   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1686     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1687   }
1688   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1689 })
1690
1691 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1692   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1693 })
1694
1695 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1696   // D is the "T" in something like "template<typename T> class vector;"
1697   if (D->getTypeForDecl())
1698     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1699   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1700     TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1701 })
1702
1703 DEF_TRAVERSE_DECL(TypedefDecl, {
1704   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1705   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1706   // declaring the typedef, not something that was written in the
1707   // source.
1708 })
1709
1710 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1711   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1712   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1713   // declaring the type alias, not something that was written in the
1714   // source.
1715 })
1716
1717 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1718   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1719   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1720 })
1721
1722 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1723   // A dependent using declaration which was marked with 'typename'.
1724   //   template<class T> class A : public B<T> { using typename B<T>::foo; };
1725   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1726   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1727   // declaring the type, not something that was written in the
1728   // source.
1729 })
1730
1731 DEF_TRAVERSE_DECL(EnumDecl, {
1732   TRY_TO(TraverseDeclTemplateParameterLists(D));
1733
1734   if (D->getTypeForDecl())
1735     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1736
1737   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1738   // The enumerators are already traversed by
1739   // decls_begin()/decls_end().
1740 })
1741
1742 // Helper methods for RecordDecl and its children.
1743 template <typename Derived>
1744 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1745   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1746   // declaring the type, not something that was written in the source.
1747
1748   TRY_TO(TraverseDeclTemplateParameterLists(D));
1749   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1750   return true;
1751 }
1752
1753 template <typename Derived>
1754 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1755   if (!TraverseRecordHelper(D))
1756     return false;
1757   if (D->isCompleteDefinition()) {
1758     for (const auto &I : D->bases()) {
1759       TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1760     }
1761     // We don't traverse the friends or the conversions, as they are
1762     // already in decls_begin()/decls_end().
1763   }
1764   return true;
1765 }
1766
1767 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1768
1769 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1770
1771 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND)                              \
1772   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
1773     /* For implicit instantiations ("set<int> x;"), we don't want to           \
1774        recurse at all, since the instatiated template isn't written in         \
1775        the source code anywhere.  (Note the instatiated *type* --              \
1776        set<int> -- is written, and will still get a callback of                \
1777        TemplateSpecializationType).  For explicit instantiations               \
1778        ("template set<int>;"), we do need a callback, since this               \
1779        is the only callback that's made for this instantiation.                \
1780        We use getTypeAsWritten() to distinguish. */                            \
1781     if (TypeSourceInfo *TSI = D->getTypeAsWritten())                           \
1782       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));                              \
1783                                                                                \
1784     if (!getDerived().shouldVisitTemplateInstantiations() &&                   \
1785         D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)      \
1786       /* Returning from here skips traversing the                              \
1787          declaration context of the *TemplateSpecializationDecl                \
1788          (embedded in the DEF_TRAVERSE_DECL() macro)                           \
1789          which contains the instantiated members of the template. */           \
1790       return true;                                                             \
1791   })
1792
1793 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
1794 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
1795
1796 template <typename Derived>
1797 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1798     const TemplateArgumentLoc *TAL, unsigned Count) {
1799   for (unsigned I = 0; I < Count; ++I) {
1800     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1801   }
1802   return true;
1803 }
1804
1805 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)               \
1806   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, {         \
1807     /* The partial specialization. */                                          \
1808     if (TemplateParameterList *TPL = D->getTemplateParameters()) {             \
1809       for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();   \
1810            I != E; ++I) {                                                      \
1811         TRY_TO(TraverseDecl(*I));                                              \
1812       }                                                                        \
1813     }                                                                          \
1814     /* The args that remains unspecialized. */                                 \
1815     TRY_TO(TraverseTemplateArgumentLocsHelper(                                 \
1816         D->getTemplateArgsAsWritten()->getTemplateArgs(),                      \
1817         D->getTemplateArgsAsWritten()->NumTemplateArgs));                      \
1818                                                                                \
1819     /* Don't need the *TemplatePartialSpecializationHelper, even               \
1820        though that's our parent class -- we already visit all the              \
1821        template args here. */                                                  \
1822     TRY_TO(Traverse##DECLKIND##Helper(D));                                     \
1823                                                                                \
1824     /* Instantiations will have been visited with the primary template. */     \
1825   })
1826
1827 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1828 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
1829
1830 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1831
1832 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1833   // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1834   //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
1835   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1836   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1837 })
1838
1839 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1840
1841 template <typename Derived>
1842 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1843   TRY_TO(TraverseDeclTemplateParameterLists(D));
1844   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1845   if (D->getTypeSourceInfo())
1846     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1847   else
1848     TRY_TO(TraverseType(D->getType()));
1849   return true;
1850 }
1851
1852 DEF_TRAVERSE_DECL(DecompositionDecl, {
1853   TRY_TO(TraverseVarHelper(D));
1854   for (auto *Binding : D->bindings()) {
1855     TRY_TO(TraverseDecl(Binding));
1856   }
1857 })
1858
1859 DEF_TRAVERSE_DECL(BindingDecl, {
1860   if (getDerived().shouldVisitImplicitCode())
1861     TRY_TO(TraverseStmt(D->getBinding()));
1862 })
1863
1864 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1865
1866 DEF_TRAVERSE_DECL(FieldDecl, {
1867   TRY_TO(TraverseDeclaratorHelper(D));
1868   if (D->isBitField())
1869     TRY_TO(TraverseStmt(D->getBitWidth()));
1870   else if (D->hasInClassInitializer())
1871     TRY_TO(TraverseStmt(D->getInClassInitializer()));
1872 })
1873
1874 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1875   TRY_TO(TraverseDeclaratorHelper(D));
1876   if (D->isBitField())
1877     TRY_TO(TraverseStmt(D->getBitWidth()));
1878   // FIXME: implement the rest.
1879 })
1880
1881 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1882   TRY_TO(TraverseDeclaratorHelper(D));
1883   if (D->isBitField())
1884     TRY_TO(TraverseStmt(D->getBitWidth()));
1885   // FIXME: implement the rest.
1886 })
1887
1888 template <typename Derived>
1889 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1890   TRY_TO(TraverseDeclTemplateParameterLists(D));
1891   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1892   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1893
1894   // If we're an explicit template specialization, iterate over the
1895   // template args that were explicitly specified.  If we were doing
1896   // this in typing order, we'd do it between the return type and
1897   // the function args, but both are handled by the FunctionTypeLoc
1898   // above, so we have to choose one side.  I've decided to do before.
1899   if (const FunctionTemplateSpecializationInfo *FTSI =
1900           D->getTemplateSpecializationInfo()) {
1901     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1902         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1903       // A specialization might not have explicit template arguments if it has
1904       // a templated return type and concrete arguments.
1905       if (const ASTTemplateArgumentListInfo *TALI =
1906               FTSI->TemplateArgumentsAsWritten) {
1907         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1908                                                   TALI->NumTemplateArgs));
1909       }
1910     }
1911   }
1912
1913   // Visit the function type itself, which can be either
1914   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
1915   // also covers the return type and the function parameters,
1916   // including exception specifications.
1917   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1918     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1919   } else if (getDerived().shouldVisitImplicitCode()) {
1920     // Visit parameter variable declarations of the implicit function
1921     // if the traverser is visiting implicit code. Parameter variable
1922     // declarations do not have valid TypeSourceInfo, so to visit them
1923     // we need to traverse the declarations explicitly.
1924     for (ParmVarDecl *Parameter : D->parameters()) {
1925       TRY_TO(TraverseDecl(Parameter));
1926     }
1927   }
1928
1929   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1930     // Constructor initializers.
1931     for (auto *I : Ctor->inits()) {
1932       TRY_TO(TraverseConstructorInitializer(I));
1933     }
1934   }
1935
1936   if (D->isThisDeclarationADefinition()) {
1937     TRY_TO(TraverseStmt(D->getBody())); // Function body.
1938   }
1939   return true;
1940 }
1941
1942 DEF_TRAVERSE_DECL(FunctionDecl, {
1943   // We skip decls_begin/decls_end, which are already covered by
1944   // TraverseFunctionHelper().
1945   ShouldVisitChildren = false;
1946   ReturnValue = TraverseFunctionHelper(D);
1947 })
1948
1949 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
1950   // We skip decls_begin/decls_end, which are already covered by
1951   // TraverseFunctionHelper().
1952   ShouldVisitChildren = false;
1953   ReturnValue = TraverseFunctionHelper(D);
1954 })
1955
1956 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1957   // We skip decls_begin/decls_end, which are already covered by
1958   // TraverseFunctionHelper().
1959   ShouldVisitChildren = false;
1960   ReturnValue = TraverseFunctionHelper(D);
1961 })
1962
1963 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1964   // We skip decls_begin/decls_end, which are already covered by
1965   // TraverseFunctionHelper().
1966   ShouldVisitChildren = false;
1967   ReturnValue = TraverseFunctionHelper(D);
1968 })
1969
1970 // CXXConversionDecl is the declaration of a type conversion operator.
1971 // It's not a cast expression.
1972 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1973   // We skip decls_begin/decls_end, which are already covered by
1974   // TraverseFunctionHelper().
1975   ShouldVisitChildren = false;
1976   ReturnValue = TraverseFunctionHelper(D);
1977 })
1978
1979 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1980   // We skip decls_begin/decls_end, which are already covered by
1981   // TraverseFunctionHelper().
1982   ShouldVisitChildren = false;
1983   ReturnValue = TraverseFunctionHelper(D);
1984 })
1985
1986 template <typename Derived>
1987 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1988   TRY_TO(TraverseDeclaratorHelper(D));
1989   // Default params are taken care of when we traverse the ParmVarDecl.
1990   if (!isa<ParmVarDecl>(D) &&
1991       (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
1992     TRY_TO(TraverseStmt(D->getInit()));
1993   return true;
1994 }
1995
1996 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
1997
1998 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
1999
2000 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
2001   // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
2002   TRY_TO(TraverseDeclaratorHelper(D));
2003   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2004     TRY_TO(TraverseStmt(D->getDefaultArgument()));
2005 })
2006
2007 DEF_TRAVERSE_DECL(ParmVarDecl, {
2008   TRY_TO(TraverseVarHelper(D));
2009
2010   if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
2011       !D->hasUnparsedDefaultArg())
2012     TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
2013
2014   if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
2015       !D->hasUnparsedDefaultArg())
2016     TRY_TO(TraverseStmt(D->getDefaultArg()));
2017 })
2018
2019 #undef DEF_TRAVERSE_DECL
2020
2021 // ----------------- Stmt traversal -----------------
2022 //
2023 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2024 // over the children defined in children() (every stmt defines these,
2025 // though sometimes the range is empty).  Each individual Traverse*
2026 // method only needs to worry about children other than those.  To see
2027 // what children() does for a given class, see, e.g.,
2028 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2029
2030 // This macro makes available a variable S, the passed-in stmt.
2031 #define DEF_TRAVERSE_STMT(STMT, CODE)                                          \
2032   template <typename Derived>                                                  \
2033   bool RecursiveASTVisitor<Derived>::Traverse##STMT(                           \
2034       STMT *S, DataRecursionQueue *Queue) {                                    \
2035     bool ShouldVisitChildren = true;                                           \
2036     bool ReturnValue = true;                                                   \
2037     if (!getDerived().shouldTraversePostOrder())                               \
2038       TRY_TO(WalkUpFrom##STMT(S));                                             \
2039     { CODE; }                                                                  \
2040     if (ShouldVisitChildren) {                                                 \
2041       for (Stmt *SubStmt : S->children()) {                                    \
2042         TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);                              \
2043       }                                                                        \
2044     }                                                                          \
2045     if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder())       \
2046       TRY_TO(WalkUpFrom##STMT(S));                                             \
2047     return ReturnValue;                                                        \
2048   }
2049
2050 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2051   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2052   for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2053     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2054   }
2055   for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2056     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2057   }
2058   for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2059     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2060   }
2061   // children() iterates over inputExpr and outputExpr.
2062 })
2063
2064 DEF_TRAVERSE_STMT(
2065     MSAsmStmt,
2066     {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
2067      // added this needs to be implemented.
2068     })
2069
2070 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2071   TRY_TO(TraverseDecl(S->getExceptionDecl()));
2072   // children() iterates over the handler block.
2073 })
2074
2075 DEF_TRAVERSE_STMT(DeclStmt, {
2076   for (auto *I : S->decls()) {
2077     TRY_TO(TraverseDecl(I));
2078   }
2079   // Suppress the default iteration over children() by
2080   // returning.  Here's why: A DeclStmt looks like 'type var [=
2081   // initializer]'.  The decls above already traverse over the
2082   // initializers, so we don't have to do it again (which
2083   // children() would do).
2084   ShouldVisitChildren = false;
2085 })
2086
2087 // These non-expr stmts (most of them), do not need any action except
2088 // iterating over the children.
2089 DEF_TRAVERSE_STMT(BreakStmt, {})
2090 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2091 DEF_TRAVERSE_STMT(CaseStmt, {})
2092 DEF_TRAVERSE_STMT(CompoundStmt, {})
2093 DEF_TRAVERSE_STMT(ContinueStmt, {})
2094 DEF_TRAVERSE_STMT(DefaultStmt, {})
2095 DEF_TRAVERSE_STMT(DoStmt, {})
2096 DEF_TRAVERSE_STMT(ForStmt, {})
2097 DEF_TRAVERSE_STMT(GotoStmt, {})
2098 DEF_TRAVERSE_STMT(IfStmt, {})
2099 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2100 DEF_TRAVERSE_STMT(LabelStmt, {})
2101 DEF_TRAVERSE_STMT(AttributedStmt, {})
2102 DEF_TRAVERSE_STMT(NullStmt, {})
2103 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2104 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2105 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2106 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2107 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2108 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2109 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2110
2111 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2112   if (!getDerived().shouldVisitImplicitCode()) {
2113     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2114     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2115     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2116     // Visit everything else only if shouldVisitImplicitCode().
2117     ShouldVisitChildren = false;
2118   }
2119 })
2120
2121 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2122   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2123   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2124 })
2125
2126 DEF_TRAVERSE_STMT(ReturnStmt, {})
2127 DEF_TRAVERSE_STMT(SwitchStmt, {})
2128 DEF_TRAVERSE_STMT(WhileStmt, {})
2129
2130 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2131   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2132   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2133   if (S->hasExplicitTemplateArgs()) {
2134     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2135                                               S->getNumTemplateArgs()));
2136   }
2137 })
2138
2139 DEF_TRAVERSE_STMT(DeclRefExpr, {
2140   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2141   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2142   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2143                                             S->getNumTemplateArgs()));
2144 })
2145
2146 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2147   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2148   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2149   if (S->hasExplicitTemplateArgs()) {
2150     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2151                                               S->getNumTemplateArgs()));
2152   }
2153 })
2154
2155 DEF_TRAVERSE_STMT(MemberExpr, {
2156   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2157   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2158   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2159                                             S->getNumTemplateArgs()));
2160 })
2161
2162 DEF_TRAVERSE_STMT(
2163     ImplicitCastExpr,
2164     {// We don't traverse the cast type, as it's not written in the
2165      // source code.
2166     })
2167
2168 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2169   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2170 })
2171
2172 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2173   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2174 })
2175
2176 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2177   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2178 })
2179
2180 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2181   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2182 })
2183
2184 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2185   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2186 })
2187
2188 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2189   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2190 })
2191
2192 template <typename Derived>
2193 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2194     InitListExpr *S, DataRecursionQueue *Queue) {
2195   if (S) {
2196     // Skip this if we traverse postorder. We will visit it later
2197     // in PostVisitStmt.
2198     if (!getDerived().shouldTraversePostOrder())
2199       TRY_TO(WalkUpFromInitListExpr(S));
2200
2201     // All we need are the default actions.  FIXME: use a helper function.
2202     for (Stmt *SubStmt : S->children()) {
2203       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2204     }
2205   }
2206   return true;
2207 }
2208
2209 // This method is called once for each pair of syntactic and semantic
2210 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2211 // may cause some of the children to be visited twice, if they appear both in
2212 // the syntactic and the semantic form.
2213 //
2214 // There is no guarantee about which form \p S takes when this method is called.
2215 DEF_TRAVERSE_STMT(InitListExpr, {
2216   TRY_TO(TraverseSynOrSemInitListExpr(
2217       S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2218   TRY_TO(TraverseSynOrSemInitListExpr(
2219       S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2220   ShouldVisitChildren = false;
2221 })
2222
2223 // GenericSelectionExpr is a special case because the types and expressions
2224 // are interleaved.  We also need to watch out for null types (default
2225 // generic associations).
2226 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2227   TRY_TO(TraverseStmt(S->getControllingExpr()));
2228   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2229     if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2230       TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2231     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2232   }
2233   ShouldVisitChildren = false;
2234 })
2235
2236 // PseudoObjectExpr is a special case because of the weirdness with
2237 // syntactic expressions and opaque values.
2238 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2239   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2240   for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2241                                             e = S->semantics_end();
2242        i != e; ++i) {
2243     Expr *sub = *i;
2244     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2245       sub = OVE->getSourceExpr();
2246     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2247   }
2248   ShouldVisitChildren = false;
2249 })
2250
2251 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2252   // This is called for code like 'return T()' where T is a built-in
2253   // (i.e. non-class) type.
2254   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2255 })
2256
2257 DEF_TRAVERSE_STMT(CXXNewExpr, {
2258   // The child-iterator will pick up the other arguments.
2259   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2260 })
2261
2262 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2263   // The child-iterator will pick up the expression representing
2264   // the field.
2265   // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2266   // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2267   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2268 })
2269
2270 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2271   // The child-iterator will pick up the arg if it's an expression,
2272   // but not if it's a type.
2273   if (S->isArgumentType())
2274     TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2275 })
2276
2277 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2278   // The child-iterator will pick up the arg if it's an expression,
2279   // but not if it's a type.
2280   if (S->isTypeOperand())
2281     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2282 })
2283
2284 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2285   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2286 })
2287
2288 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2289
2290 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2291   // The child-iterator will pick up the arg if it's an expression,
2292   // but not if it's a type.
2293   if (S->isTypeOperand())
2294     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2295 })
2296
2297 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2298   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2299     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2300 })
2301
2302 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2303   TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2304 })
2305
2306 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2307                   { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2308
2309 DEF_TRAVERSE_STMT(VAArgExpr, {
2310   // The child-iterator will pick up the expression argument.
2311   TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2312 })
2313
2314 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2315   // This is called for code like 'return T()' where T is a class type.
2316   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2317 })
2318
2319 // Walk only the visible parts of lambda expressions.
2320 DEF_TRAVERSE_STMT(LambdaExpr, {
2321   for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2322     const LambdaCapture *C = S->capture_begin() + I;
2323     if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2324       TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2325     }
2326   }
2327
2328   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2329   FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
2330
2331   if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2332     // Visit the whole type.
2333     TRY_TO(TraverseTypeLoc(TL));
2334   } else {
2335     if (S->hasExplicitParameters()) {
2336       // Visit parameters.
2337       for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2338         TRY_TO(TraverseDecl(Proto.getParam(I)));
2339       }
2340     } else if (S->hasExplicitResultType()) {
2341       TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2342     }
2343
2344     auto *T = Proto.getTypePtr();
2345     for (const auto &E : T->exceptions()) {
2346       TRY_TO(TraverseType(E));
2347     }
2348
2349     if (Expr *NE = T->getNoexceptExpr())
2350       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2351   }
2352
2353   ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2354   ShouldVisitChildren = false;
2355 })
2356
2357 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2358   // This is called for code like 'T()', where T is a template argument.
2359   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2360 })
2361
2362 // These expressions all might take explicit template arguments.
2363 // We traverse those if so.  FIXME: implement these.
2364 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2365 DEF_TRAVERSE_STMT(CallExpr, {})
2366 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2367
2368 // These exprs (most of them), do not need any action except iterating
2369 // over the children.
2370 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2371 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2372 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2373
2374 DEF_TRAVERSE_STMT(BlockExpr, {
2375   TRY_TO(TraverseDecl(S->getBlockDecl()));
2376   return true; // no child statements to loop through.
2377 })
2378
2379 DEF_TRAVERSE_STMT(ChooseExpr, {})
2380 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2381   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2382 })
2383 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2384 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2385
2386 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2387   if (getDerived().shouldVisitImplicitCode())
2388     TRY_TO(TraverseStmt(S->getExpr()));
2389 })
2390
2391 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2392 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2393 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2394 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2395 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2396 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2397
2398 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2399   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2400   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2401     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2402   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2403     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2404 })
2405
2406 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2407 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2408 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2409 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2410 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2411 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2412 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2413 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2414 DEF_TRAVERSE_STMT(NoInitExpr, {})
2415 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2416   // FIXME: The source expression of the OVE should be listed as
2417   // a child of the ArrayInitLoopExpr.
2418   if (OpaqueValueExpr *OVE = S->getCommonExpr())
2419     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2420 })
2421 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2422 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2423
2424 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2425   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2426     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2427 })
2428
2429 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2430 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2431
2432 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2433   if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2434     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2435 })
2436
2437 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2438 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2439 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2440 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2441 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2442
2443 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2444   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2445 })
2446
2447 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2448 DEF_TRAVERSE_STMT(ParenExpr, {})
2449 DEF_TRAVERSE_STMT(ParenListExpr, {})
2450 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2451 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2452 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2453 DEF_TRAVERSE_STMT(StmtExpr, {})
2454 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2455   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2456   if (S->hasExplicitTemplateArgs()) {
2457     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2458                                               S->getNumTemplateArgs()));
2459   }
2460 })
2461
2462 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2463   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2464   if (S->hasExplicitTemplateArgs()) {
2465     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2466                                               S->getNumTemplateArgs()));
2467   }
2468 })
2469
2470 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2471 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2472 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2473 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2474 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2475
2476 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2477 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2478 DEF_TRAVERSE_STMT(TypoExpr, {})
2479 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2480
2481 // These operators (all of them) do not need any action except
2482 // iterating over the children.
2483 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2484 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2485 DEF_TRAVERSE_STMT(UnaryOperator, {})
2486 DEF_TRAVERSE_STMT(BinaryOperator, {})
2487 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2488 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2489 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2490 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2491 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2492 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2493 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2494 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2495 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2496 DEF_TRAVERSE_STMT(AtomicExpr, {})
2497
2498 // For coroutines expressions, traverse either the operand
2499 // as written or the implied calls, depending on what the
2500 // derived class requests.
2501 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2502   if (!getDerived().shouldVisitImplicitCode()) {
2503     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2504     ShouldVisitChildren = false;
2505   }
2506 })
2507 DEF_TRAVERSE_STMT(CoreturnStmt, {
2508   if (!getDerived().shouldVisitImplicitCode()) {
2509     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2510     ShouldVisitChildren = false;
2511   }
2512 })
2513 DEF_TRAVERSE_STMT(CoawaitExpr, {
2514   if (!getDerived().shouldVisitImplicitCode()) {
2515     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2516     ShouldVisitChildren = false;
2517   }
2518 })
2519 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2520   if (!getDerived().shouldVisitImplicitCode()) {
2521     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2522     ShouldVisitChildren = false;
2523   }
2524 })
2525 DEF_TRAVERSE_STMT(CoyieldExpr, {
2526   if (!getDerived().shouldVisitImplicitCode()) {
2527     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2528     ShouldVisitChildren = false;
2529   }
2530 })
2531
2532 // These literals (all of them) do not need any action.
2533 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2534 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2535 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2536 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2537 DEF_TRAVERSE_STMT(StringLiteral, {})
2538 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2539 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2540 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2541 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2542
2543 // Traverse OpenCL: AsType, Convert.
2544 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2545
2546 // OpenMP directives.
2547 template <typename Derived>
2548 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2549     OMPExecutableDirective *S) {
2550   for (auto *C : S->clauses()) {
2551     TRY_TO(TraverseOMPClause(C));
2552   }
2553   return true;
2554 }
2555
2556 template <typename Derived>
2557 bool
2558 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2559   return TraverseOMPExecutableDirective(S);
2560 }
2561
2562 DEF_TRAVERSE_STMT(OMPParallelDirective,
2563                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2564
2565 DEF_TRAVERSE_STMT(OMPSimdDirective,
2566                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2567
2568 DEF_TRAVERSE_STMT(OMPForDirective,
2569                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2570
2571 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2572                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2573
2574 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2575                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2576
2577 DEF_TRAVERSE_STMT(OMPSectionDirective,
2578                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2579
2580 DEF_TRAVERSE_STMT(OMPSingleDirective,
2581                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2582
2583 DEF_TRAVERSE_STMT(OMPMasterDirective,
2584                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2585
2586 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2587   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2588   TRY_TO(TraverseOMPExecutableDirective(S));
2589 })
2590
2591 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2592                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2593
2594 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2595                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2596
2597 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2598                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2599
2600 DEF_TRAVERSE_STMT(OMPTaskDirective,
2601                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2602
2603 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2604                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2605
2606 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2607                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2608
2609 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2610                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2611
2612 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2613                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2614
2615 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2616                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2617
2618 DEF_TRAVERSE_STMT(OMPCancelDirective,
2619                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2620
2621 DEF_TRAVERSE_STMT(OMPFlushDirective,
2622                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2623
2624 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2625                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2626
2627 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2628                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2629
2630 DEF_TRAVERSE_STMT(OMPTargetDirective,
2631                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2632
2633 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2634                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2635
2636 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2637                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2638
2639 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2640                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2641
2642 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2643                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2644
2645 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2646                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2647
2648 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2649                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2650
2651 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2652                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2653
2654 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2655                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2656
2657 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2658                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2659
2660 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2661                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2662
2663 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2664                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2665
2666 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2667                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2668
2669 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2670                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2671
2672 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2673                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2674
2675 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
2676                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2677
2678 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
2679                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2680
2681 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
2682                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2683
2684 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
2685                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2686
2687 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
2688                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2689
2690 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
2691                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2692
2693 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
2694                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2695
2696 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
2697                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2698
2699 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
2700                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2701
2702 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
2703                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
2704
2705 // OpenMP clauses.
2706 template <typename Derived>
2707 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2708   if (!C)
2709     return true;
2710   switch (C->getClauseKind()) {
2711 #define OPENMP_CLAUSE(Name, Class)                                             \
2712   case OMPC_##Name:                                                            \
2713     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
2714     break;
2715 #include "clang/Basic/OpenMPKinds.def"
2716   case OMPC_threadprivate:
2717   case OMPC_uniform:
2718   case OMPC_unknown:
2719     break;
2720   }
2721   return true;
2722 }
2723
2724 template <typename Derived>
2725 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2726     OMPClauseWithPreInit *Node) {
2727   TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2728   return true;
2729 }
2730
2731 template <typename Derived>
2732 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2733     OMPClauseWithPostUpdate *Node) {
2734   TRY_TO(VisitOMPClauseWithPreInit(Node));
2735   TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2736   return true;
2737 }
2738
2739 template <typename Derived>
2740 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2741   TRY_TO(VisitOMPClauseWithPreInit(C));
2742   TRY_TO(TraverseStmt(C->getCondition()));
2743   return true;
2744 }
2745
2746 template <typename Derived>
2747 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2748   TRY_TO(TraverseStmt(C->getCondition()));
2749   return true;
2750 }
2751
2752 template <typename Derived>
2753 bool
2754 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2755   TRY_TO(VisitOMPClauseWithPreInit(C));
2756   TRY_TO(TraverseStmt(C->getNumThreads()));
2757   return true;
2758 }
2759
2760 template <typename Derived>
2761 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2762   TRY_TO(TraverseStmt(C->getSafelen()));
2763   return true;
2764 }
2765
2766 template <typename Derived>
2767 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2768   TRY_TO(TraverseStmt(C->getSimdlen()));
2769   return true;
2770 }
2771
2772 template <typename Derived>
2773 bool
2774 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2775   TRY_TO(TraverseStmt(C->getNumForLoops()));
2776   return true;
2777 }
2778
2779 template <typename Derived>
2780 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2781   return true;
2782 }
2783
2784 template <typename Derived>
2785 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2786   return true;
2787 }
2788
2789 template <typename Derived>
2790 bool
2791 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2792   TRY_TO(VisitOMPClauseWithPreInit(C));
2793   TRY_TO(TraverseStmt(C->getChunkSize()));
2794   return true;
2795 }
2796
2797 template <typename Derived>
2798 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2799   TRY_TO(TraverseStmt(C->getNumForLoops()));
2800   return true;
2801 }
2802
2803 template <typename Derived>
2804 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2805   return true;
2806 }
2807
2808 template <typename Derived>
2809 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2810   return true;
2811 }
2812
2813 template <typename Derived>
2814 bool
2815 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2816   return true;
2817 }
2818
2819 template <typename Derived>
2820 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2821   return true;
2822 }
2823
2824 template <typename Derived>
2825 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2826   return true;
2827 }
2828
2829 template <typename Derived>
2830 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2831   return true;
2832 }
2833
2834 template <typename Derived>
2835 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2836   return true;
2837 }
2838
2839 template <typename Derived>
2840 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2841   return true;
2842 }
2843
2844 template <typename Derived>
2845 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2846   return true;
2847 }
2848
2849 template <typename Derived>
2850 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2851   return true;
2852 }
2853
2854 template <typename Derived>
2855 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2856   return true;
2857 }
2858
2859 template <typename Derived>
2860 template <typename T>
2861 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2862   for (auto *E : Node->varlists()) {
2863     TRY_TO(TraverseStmt(E));
2864   }
2865   return true;
2866 }
2867
2868 template <typename Derived>
2869 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2870   TRY_TO(VisitOMPClauseList(C));
2871   for (auto *E : C->private_copies()) {
2872     TRY_TO(TraverseStmt(E));
2873   }
2874   return true;
2875 }
2876
2877 template <typename Derived>
2878 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2879     OMPFirstprivateClause *C) {
2880   TRY_TO(VisitOMPClauseList(C));
2881   TRY_TO(VisitOMPClauseWithPreInit(C));
2882   for (auto *E : C->private_copies()) {
2883     TRY_TO(TraverseStmt(E));
2884   }
2885   for (auto *E : C->inits()) {
2886     TRY_TO(TraverseStmt(E));
2887   }
2888   return true;
2889 }
2890
2891 template <typename Derived>
2892 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2893     OMPLastprivateClause *C) {
2894   TRY_TO(VisitOMPClauseList(C));
2895   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2896   for (auto *E : C->private_copies()) {
2897     TRY_TO(TraverseStmt(E));
2898   }
2899   for (auto *E : C->source_exprs()) {
2900     TRY_TO(TraverseStmt(E));
2901   }
2902   for (auto *E : C->destination_exprs()) {
2903     TRY_TO(TraverseStmt(E));
2904   }
2905   for (auto *E : C->assignment_ops()) {
2906     TRY_TO(TraverseStmt(E));
2907   }
2908   return true;
2909 }
2910
2911 template <typename Derived>
2912 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2913   TRY_TO(VisitOMPClauseList(C));
2914   return true;
2915 }
2916
2917 template <typename Derived>
2918 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2919   TRY_TO(TraverseStmt(C->getStep()));
2920   TRY_TO(TraverseStmt(C->getCalcStep()));
2921   TRY_TO(VisitOMPClauseList(C));
2922   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2923   for (auto *E : C->privates()) {
2924     TRY_TO(TraverseStmt(E));
2925   }
2926   for (auto *E : C->inits()) {
2927     TRY_TO(TraverseStmt(E));
2928   }
2929   for (auto *E : C->updates()) {
2930     TRY_TO(TraverseStmt(E));
2931   }
2932   for (auto *E : C->finals()) {
2933     TRY_TO(TraverseStmt(E));
2934   }
2935   return true;
2936 }
2937
2938 template <typename Derived>
2939 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2940   TRY_TO(TraverseStmt(C->getAlignment()));
2941   TRY_TO(VisitOMPClauseList(C));
2942   return true;
2943 }
2944
2945 template <typename Derived>
2946 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2947   TRY_TO(VisitOMPClauseList(C));
2948   for (auto *E : C->source_exprs()) {
2949     TRY_TO(TraverseStmt(E));
2950   }
2951   for (auto *E : C->destination_exprs()) {
2952     TRY_TO(TraverseStmt(E));
2953   }
2954   for (auto *E : C->assignment_ops()) {
2955     TRY_TO(TraverseStmt(E));
2956   }
2957   return true;
2958 }
2959
2960 template <typename Derived>
2961 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2962     OMPCopyprivateClause *C) {
2963   TRY_TO(VisitOMPClauseList(C));
2964   for (auto *E : C->source_exprs()) {
2965     TRY_TO(TraverseStmt(E));
2966   }
2967   for (auto *E : C->destination_exprs()) {
2968     TRY_TO(TraverseStmt(E));
2969   }
2970   for (auto *E : C->assignment_ops()) {
2971     TRY_TO(TraverseStmt(E));
2972   }
2973   return true;
2974 }
2975
2976 template <typename Derived>
2977 bool
2978 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
2979   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
2980   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
2981   TRY_TO(VisitOMPClauseList(C));
2982   TRY_TO(VisitOMPClauseWithPostUpdate(C));
2983   for (auto *E : C->privates()) {
2984     TRY_TO(TraverseStmt(E));
2985   }
2986   for (auto *E : C->lhs_exprs()) {
2987     TRY_TO(TraverseStmt(E));
2988   }
2989   for (auto *E : C->rhs_exprs()) {
2990     TRY_TO(TraverseStmt(E));
2991   }
2992   for (auto *E : C->reduction_ops()) {
2993     TRY_TO(TraverseStmt(E));
2994   }
2995   return true;
2996 }
2997
2998 template <typename Derived>
2999 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3000   TRY_TO(VisitOMPClauseList(C));
3001   return true;
3002 }
3003
3004 template <typename Derived>
3005 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3006   TRY_TO(VisitOMPClauseList(C));
3007   return true;
3008 }
3009
3010 template <typename Derived>
3011 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3012   TRY_TO(TraverseStmt(C->getDevice()));
3013   return true;
3014 }
3015
3016 template <typename Derived>
3017 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3018   TRY_TO(VisitOMPClauseList(C));
3019   return true;
3020 }
3021
3022 template <typename Derived>
3023 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3024     OMPNumTeamsClause *C) {
3025   TRY_TO(VisitOMPClauseWithPreInit(C));
3026   TRY_TO(TraverseStmt(C->getNumTeams()));
3027   return true;
3028 }
3029
3030 template <typename Derived>
3031 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3032     OMPThreadLimitClause *C) {
3033   TRY_TO(VisitOMPClauseWithPreInit(C));
3034   TRY_TO(TraverseStmt(C->getThreadLimit()));
3035   return true;
3036 }
3037
3038 template <typename Derived>
3039 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3040     OMPPriorityClause *C) {
3041   TRY_TO(TraverseStmt(C->getPriority()));
3042   return true;
3043 }
3044
3045 template <typename Derived>
3046 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3047     OMPGrainsizeClause *C) {
3048   TRY_TO(TraverseStmt(C->getGrainsize()));
3049   return true;
3050 }
3051
3052 template <typename Derived>
3053 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3054     OMPNumTasksClause *C) {
3055   TRY_TO(TraverseStmt(C->getNumTasks()));
3056   return true;
3057 }
3058
3059 template <typename Derived>
3060 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3061   TRY_TO(TraverseStmt(C->getHint()));
3062   return true;
3063 }
3064
3065 template <typename Derived>
3066 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3067     OMPDistScheduleClause *C) {
3068   TRY_TO(VisitOMPClauseWithPreInit(C));
3069   TRY_TO(TraverseStmt(C->getChunkSize()));
3070   return true;
3071 }
3072
3073 template <typename Derived>
3074 bool
3075 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3076   return true;
3077 }
3078
3079 template <typename Derived>
3080 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3081   TRY_TO(VisitOMPClauseList(C));
3082   return true;
3083 }
3084
3085 template <typename Derived>
3086 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3087   TRY_TO(VisitOMPClauseList(C));
3088   return true;
3089 }
3090
3091 template <typename Derived>
3092 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3093     OMPUseDevicePtrClause *C) {
3094   TRY_TO(VisitOMPClauseList(C));
3095   return true;
3096 }
3097
3098 template <typename Derived>
3099 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3100     OMPIsDevicePtrClause *C) {
3101   TRY_TO(VisitOMPClauseList(C));
3102   return true;
3103 }
3104
3105 // FIXME: look at the following tricky-seeming exprs to see if we
3106 // need to recurse on anything.  These are ones that have methods
3107 // returning decls or qualtypes or nestednamespecifier -- though I'm
3108 // not sure if they own them -- or just seemed very complicated, or
3109 // had lots of sub-types to explore.
3110 //
3111 // VisitOverloadExpr and its children: recurse on template args? etc?
3112
3113 // FIXME: go through all the stmts and exprs again, and see which of them
3114 // create new types, and recurse on the types (TypeLocs?) of those.
3115 // Candidates:
3116 //
3117 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
3118 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
3119 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
3120 //    Every class that has getQualifier.
3121
3122 #undef DEF_TRAVERSE_STMT
3123 #undef TRAVERSE_STMT
3124 #undef TRAVERSE_STMT_BASE
3125
3126 #undef TRY_TO
3127
3128 } // end namespace clang
3129
3130 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H