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