RecursiveASTVisitor.h revision c8c222830a1d8df8ed05bedfcac868fe6838fba8
1//===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the RecursiveASTVisitor interface, which recursively
11//  traverses the entire AST.
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15#define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
16
17#include "clang/AST/Decl.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclFriend.h"
20#include "clang/AST/DeclObjC.h"
21#include "clang/AST/DeclTemplate.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
25#include "clang/AST/NestedNameSpecifier.h"
26#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
29#include "clang/AST/TemplateBase.h"
30#include "clang/AST/TemplateName.h"
31#include "clang/AST/Type.h"
32#include "clang/AST/TypeLoc.h"
33
34// The following three macros are used for meta programming.  The code
35// using them is responsible for defining macro OPERATOR().
36
37// All unary operators.
38#define UNARYOP_LIST()                          \
39  OPERATOR(PostInc)   OPERATOR(PostDec)         \
40  OPERATOR(PreInc)    OPERATOR(PreDec)          \
41  OPERATOR(AddrOf)    OPERATOR(Deref)           \
42  OPERATOR(Plus)      OPERATOR(Minus)           \
43  OPERATOR(Not)       OPERATOR(LNot)            \
44  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)    \
50  OPERATOR(Mul)   OPERATOR(Div)  OPERATOR(Rem)        \
51  OPERATOR(Add)   OPERATOR(Sub)  OPERATOR(Shl)        \
52  OPERATOR(Shr)                                       \
53                                                      \
54  OPERATOR(LT)    OPERATOR(GT)   OPERATOR(LE)         \
55  OPERATOR(GE)    OPERATOR(EQ)   OPERATOR(NE)         \
56  OPERATOR(And)   OPERATOR(Xor)  OPERATOR(Or)         \
57  OPERATOR(LAnd)  OPERATOR(LOr)                       \
58                                                      \
59  OPERATOR(Assign)                                    \
60  OPERATOR(Comma)
61
62// All compound assign operators.
63#define CAO_LIST()                                                      \
64  OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
65  OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or)  OPERATOR(Xor)
66
67namespace clang {
68
69// A helper macro to implement short-circuiting when recursing.  It
70// invokes CALL_EXPR, which must be a method call, on the derived
71// object (s.t. a user of RecursiveASTVisitor can override the method
72// in CALL_EXPR).
73#define TRY_TO(CALL_EXPR) \
74  do { if (!getDerived().CALL_EXPR) return false; } 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 NamedDecl, 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/// Clients of this visitor should subclass the visitor (providing
118/// themselves as the template argument, using the curiously recurring
119/// template pattern) and override any of the Traverse*, WalkUpFrom*,
120/// and Visit* methods for declarations, types, statements,
121/// expressions, or other AST nodes where the visitor should customize
122/// behavior.  Most users only need to override Visit*.  Advanced
123/// users may override Traverse* and WalkUpFrom* to implement custom
124/// traversal strategies.  Returning false from one of these overridden
125/// functions will abort the entire traversal.
126///
127/// By default, this visitor tries to visit every part of the explicit
128/// source code exactly once.  The default policy towards templates
129/// is to descend into the 'pattern' class or function body, not any
130/// explicit or implicit instantiations.  Explicit specializations
131/// are still visited, and the patterns of partial specializations
132/// are visited separately.  This behavior can be changed by
133/// overriding shouldVisitTemplateInstantiations() in the derived class
134/// to return true, in which case all known implicit and explicit
135/// instantiations will be visited at the same time as the pattern
136/// from which they were produced.
137template<typename Derived>
138class RecursiveASTVisitor {
139public:
140  /// \brief Return a reference to the derived class.
141  Derived &getDerived() { return *static_cast<Derived*>(this); }
142
143  /// \brief Return whether this visitor should recurse into
144  /// template instantiations.
145  bool shouldVisitTemplateInstantiations() const { return false; }
146
147  /// \brief Return whether this visitor should recurse into the types of
148  /// TypeLocs.
149  bool shouldWalkTypesOfTypeLocs() const { return true; }
150
151  /// \brief Return whether \param S should be traversed using data recursion
152  /// to avoid a stack overflow with extreme cases.
153  bool shouldUseDataRecursionFor(Stmt *S) const {
154    return isa<BinaryOperator>(S) || isa<UnaryOperator>(S) ||
155           isa<CaseStmt>(S) || isa<CXXOperatorCallExpr>(S);
156  }
157
158  /// \brief Recursively visit a statement or expression, by
159  /// dispatching to Traverse*() based on the argument's dynamic type.
160  ///
161  /// \returns false if the visitation was terminated early, true
162  /// otherwise (including when the argument is NULL).
163  bool TraverseStmt(Stmt *S);
164
165  /// \brief Recursively visit a type, by dispatching to
166  /// Traverse*Type() based on the argument's getTypeClass() property.
167  ///
168  /// \returns false if the visitation was terminated early, true
169  /// otherwise (including when the argument is a Null type).
170  bool TraverseType(QualType T);
171
172  /// \brief Recursively visit a type with location, by dispatching to
173  /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
174  ///
175  /// \returns false if the visitation was terminated early, true
176  /// otherwise (including when the argument is a Null type location).
177  bool TraverseTypeLoc(TypeLoc TL);
178
179  /// \brief Recursively visit a declaration, by dispatching to
180  /// Traverse*Decl() based on the argument's dynamic type.
181  ///
182  /// \returns false if the visitation was terminated early, true
183  /// otherwise (including when the argument is NULL).
184  bool TraverseDecl(Decl *D);
185
186  /// \brief Recursively visit a C++ nested-name-specifier.
187  ///
188  /// \returns false if the visitation was terminated early, true otherwise.
189  bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
190
191  /// \brief Recursively visit a C++ nested-name-specifier with location
192  /// information.
193  ///
194  /// \returns false if the visitation was terminated early, true otherwise.
195  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
196
197  /// \brief Recursively visit a name with its location information.
198  ///
199  /// \returns false if the visitation was terminated early, true otherwise.
200  bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
201
202  /// \brief Recursively visit a template name and dispatch to the
203  /// appropriate method.
204  ///
205  /// \returns false if the visitation was terminated early, true otherwise.
206  bool TraverseTemplateName(TemplateName Template);
207
208  /// \brief Recursively visit a template argument and dispatch to the
209  /// appropriate method for the argument type.
210  ///
211  /// \returns false if the visitation was terminated early, true otherwise.
212  // FIXME: migrate callers to TemplateArgumentLoc instead.
213  bool TraverseTemplateArgument(const TemplateArgument &Arg);
214
215  /// \brief Recursively visit a template argument location and dispatch to the
216  /// appropriate method for the argument type.
217  ///
218  /// \returns false if the visitation was terminated early, true otherwise.
219  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
220
221  /// \brief Recursively visit a set of template arguments.
222  /// This can be overridden by a subclass, but it's not expected that
223  /// will be needed -- this visitor always dispatches to another.
224  ///
225  /// \returns false if the visitation was terminated early, true otherwise.
226  // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
227  bool TraverseTemplateArguments(const TemplateArgument *Args,
228                                 unsigned NumArgs);
229
230  /// \brief Recursively visit a constructor initializer.  This
231  /// automatically dispatches to another visitor for the initializer
232  /// expression, but not for the name of the initializer, so may
233  /// be overridden for clients that need access to the name.
234  ///
235  /// \returns false if the visitation was terminated early, true otherwise.
236  bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
237
238  /// \brief Recursively visit a lambda capture.
239  ///
240  /// \returns false if the visitation was terminated early, true otherwise.
241  bool TraverseLambdaCapture(LambdaExpr::Capture C);
242
243  // ---- Methods on Stmts ----
244
245  // Declare Traverse*() for all concrete Stmt classes.
246#define ABSTRACT_STMT(STMT)
247#define STMT(CLASS, PARENT)                                     \
248  bool Traverse##CLASS(CLASS *S);
249#include "clang/AST/StmtNodes.inc"
250  // The above header #undefs ABSTRACT_STMT and STMT upon exit.
251
252  // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
253  bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
254  bool VisitStmt(Stmt *S) { return true; }
255#define STMT(CLASS, PARENT)                                     \
256  bool WalkUpFrom##CLASS(CLASS *S) {                            \
257    TRY_TO(WalkUpFrom##PARENT(S));                              \
258    TRY_TO(Visit##CLASS(S));                                    \
259    return true;                                                \
260  }                                                             \
261  bool Visit##CLASS(CLASS *S) { return true; }
262#include "clang/AST/StmtNodes.inc"
263
264  // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
265  // operator methods.  Unary operators are not classes in themselves
266  // (they're all opcodes in UnaryOperator) but do have visitors.
267#define OPERATOR(NAME)                                           \
268  bool TraverseUnary##NAME(UnaryOperator *S) {                  \
269    TRY_TO(WalkUpFromUnary##NAME(S));                           \
270    TRY_TO(TraverseStmt(S->getSubExpr()));                      \
271    return true;                                                \
272  }                                                             \
273  bool WalkUpFromUnary##NAME(UnaryOperator *S) {                \
274    TRY_TO(WalkUpFromUnaryOperator(S));                         \
275    TRY_TO(VisitUnary##NAME(S));                                \
276    return true;                                                \
277  }                                                             \
278  bool VisitUnary##NAME(UnaryOperator *S) { return true; }
279
280  UNARYOP_LIST()
281#undef OPERATOR
282
283  // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
284  // operator methods.  Binary operators are not classes in themselves
285  // (they're all opcodes in BinaryOperator) but do have visitors.
286#define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE)                \
287  bool TraverseBin##NAME(BINOP_TYPE *S) {                       \
288    TRY_TO(WalkUpFromBin##NAME(S));                             \
289    TRY_TO(TraverseStmt(S->getLHS()));                          \
290    TRY_TO(TraverseStmt(S->getRHS()));                          \
291    return true;                                                \
292  }                                                             \
293  bool WalkUpFromBin##NAME(BINOP_TYPE *S) {                     \
294    TRY_TO(WalkUpFrom##BINOP_TYPE(S));                          \
295    TRY_TO(VisitBin##NAME(S));                                  \
296    return true;                                                \
297  }                                                             \
298  bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
299
300#define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
301  BINOP_LIST()
302#undef OPERATOR
303
304  // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
305  // assignment methods.  Compound assignment operators are not
306  // classes in themselves (they're all opcodes in
307  // CompoundAssignOperator) but do have visitors.
308#define OPERATOR(NAME) \
309  GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
310
311  CAO_LIST()
312#undef OPERATOR
313#undef GENERAL_BINOP_FALLBACK
314
315  // ---- Methods on Types ----
316  // FIXME: revamp to take TypeLoc's rather than Types.
317
318  // Declare Traverse*() for all concrete Type classes.
319#define ABSTRACT_TYPE(CLASS, BASE)
320#define TYPE(CLASS, BASE) \
321  bool Traverse##CLASS##Type(CLASS##Type *T);
322#include "clang/AST/TypeNodes.def"
323  // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
324
325  // Define WalkUpFrom*() and empty Visit*() for all Type classes.
326  bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
327  bool VisitType(Type *T) { return true; }
328#define TYPE(CLASS, BASE)                                       \
329  bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                \
330    TRY_TO(WalkUpFrom##BASE(T));                                \
331    TRY_TO(Visit##CLASS##Type(T));                              \
332    return true;                                                \
333  }                                                             \
334  bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
335#include "clang/AST/TypeNodes.def"
336
337  // ---- Methods on TypeLocs ----
338  // FIXME: this currently just calls the matching Type methods
339
340  // Declare Traverse*() for all concrete Type classes.
341#define ABSTRACT_TYPELOC(CLASS, BASE)
342#define TYPELOC(CLASS, BASE) \
343  bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
344#include "clang/AST/TypeLocNodes.def"
345  // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
346
347  // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
348  bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
349  bool VisitTypeLoc(TypeLoc TL) { return true; }
350
351  // QualifiedTypeLoc and UnqualTypeLoc are not declared in
352  // TypeNodes.def and thus need to be handled specially.
353  bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
354    return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
355  }
356  bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
357  bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
358    return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
359  }
360  bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
361
362  // Note that BASE includes trailing 'Type' which CLASS doesn't.
363#define TYPE(CLASS, BASE)                                       \
364  bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {          \
365    TRY_TO(WalkUpFrom##BASE##Loc(TL));                          \
366    TRY_TO(Visit##CLASS##TypeLoc(TL));                          \
367    return true;                                                \
368  }                                                             \
369  bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
370#include "clang/AST/TypeNodes.def"
371
372  // ---- Methods on Decls ----
373
374  // Declare Traverse*() for all concrete Decl classes.
375#define ABSTRACT_DECL(DECL)
376#define DECL(CLASS, BASE) \
377  bool Traverse##CLASS##Decl(CLASS##Decl *D);
378#include "clang/AST/DeclNodes.inc"
379  // The above header #undefs ABSTRACT_DECL and DECL upon exit.
380
381  // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
382  bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
383  bool VisitDecl(Decl *D) { return true; }
384#define DECL(CLASS, BASE)                                       \
385  bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                \
386    TRY_TO(WalkUpFrom##BASE(D));                                \
387    TRY_TO(Visit##CLASS##Decl(D));                              \
388    return true;                                                \
389  }                                                             \
390  bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
391#include "clang/AST/DeclNodes.inc"
392
393private:
394  // These are helper methods used by more than one Traverse* method.
395  bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
396  bool TraverseClassInstantiations(ClassTemplateDecl *D);
397  bool TraverseFunctionInstantiations(FunctionTemplateDecl *D) ;
398  bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
399                                          unsigned Count);
400  bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
401  bool TraverseRecordHelper(RecordDecl *D);
402  bool TraverseCXXRecordHelper(CXXRecordDecl *D);
403  bool TraverseDeclaratorHelper(DeclaratorDecl *D);
404  bool TraverseDeclContextHelper(DeclContext *DC);
405  bool TraverseFunctionHelper(FunctionDecl *D);
406  bool TraverseVarHelper(VarDecl *D);
407
408  struct EnqueueJob {
409    Stmt *S;
410    Stmt::child_iterator StmtIt;
411
412    EnqueueJob(Stmt *S) : S(S), StmtIt() {}
413  };
414  bool dataTraverse(Stmt *S);
415  bool dataTraverseNode(Stmt *S, bool &EnqueueChildren);
416};
417
418template<typename Derived>
419bool RecursiveASTVisitor<Derived>::dataTraverse(Stmt *S) {
420
421  SmallVector<EnqueueJob, 16> Queue;
422  Queue.push_back(S);
423
424  while (!Queue.empty()) {
425    EnqueueJob &job = Queue.back();
426    Stmt *CurrS = job.S;
427    if (!CurrS) {
428      Queue.pop_back();
429      continue;
430    }
431
432    if (getDerived().shouldUseDataRecursionFor(CurrS)) {
433      if (job.StmtIt == Stmt::child_iterator()) {
434        bool EnqueueChildren = true;
435        if (!dataTraverseNode(CurrS, EnqueueChildren)) return false;
436        if (!EnqueueChildren) {
437          Queue.pop_back();
438          continue;
439        }
440        job.StmtIt = CurrS->child_begin();
441      } else {
442        ++job.StmtIt;
443      }
444
445      if (job.StmtIt != CurrS->child_end())
446        Queue.push_back(*job.StmtIt);
447      else
448        Queue.pop_back();
449      continue;
450    }
451
452    Queue.pop_back();
453    TRY_TO(TraverseStmt(CurrS));
454  }
455
456  return true;
457}
458
459template<typename Derived>
460bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
461                                                    bool &EnqueueChildren) {
462
463  // Dispatch to the corresponding WalkUpFrom* function only if the derived
464  // class didn't override Traverse* (and thus the traversal is trivial).
465  // The cast here is necessary to work around a bug in old versions of g++.
466#define DISPATCH_WALK(NAME, CLASS, VAR) \
467  if (&RecursiveASTVisitor::Traverse##NAME == \
468      (bool (RecursiveASTVisitor::*)(CLASS*))&Derived::Traverse##NAME) \
469    return getDerived().WalkUpFrom##NAME(static_cast<CLASS*>(VAR)); \
470  EnqueueChildren = false; \
471  return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR));
472
473  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
474    switch (BinOp->getOpcode()) {
475#define OPERATOR(NAME) \
476    case BO_##NAME: DISPATCH_WALK(Bin##NAME, BinaryOperator, S);
477
478    BINOP_LIST()
479#undef OPERATOR
480
481#define OPERATOR(NAME)                                          \
482    case BO_##NAME##Assign:                          \
483    DISPATCH_WALK(Bin##NAME##Assign, CompoundAssignOperator, S);
484
485    CAO_LIST()
486#undef OPERATOR
487    }
488  } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
489    switch (UnOp->getOpcode()) {
490#define OPERATOR(NAME)                                                  \
491    case UO_##NAME: DISPATCH_WALK(Unary##NAME, UnaryOperator, S);
492
493    UNARYOP_LIST()
494#undef OPERATOR
495    }
496  }
497
498  // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
499  switch (S->getStmtClass()) {
500  case Stmt::NoStmtClass: break;
501#define ABSTRACT_STMT(STMT)
502#define STMT(CLASS, PARENT) \
503  case Stmt::CLASS##Class: DISPATCH_WALK(CLASS, CLASS, S);
504#include "clang/AST/StmtNodes.inc"
505  }
506
507#undef DISPATCH_WALK
508
509  return true;
510}
511
512#define DISPATCH(NAME, CLASS, VAR) \
513  return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR))
514
515template<typename Derived>
516bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
517  if (!S)
518    return true;
519
520  if (getDerived().shouldUseDataRecursionFor(S))
521    return dataTraverse(S);
522
523  // If we have a binary expr, dispatch to the subcode of the binop.  A smart
524  // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
525  // below.
526  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
527    switch (BinOp->getOpcode()) {
528#define OPERATOR(NAME) \
529    case BO_##NAME: DISPATCH(Bin##NAME, BinaryOperator, S);
530
531    BINOP_LIST()
532#undef OPERATOR
533#undef BINOP_LIST
534
535#define OPERATOR(NAME)                                          \
536    case BO_##NAME##Assign:                          \
537      DISPATCH(Bin##NAME##Assign, CompoundAssignOperator, S);
538
539    CAO_LIST()
540#undef OPERATOR
541#undef CAO_LIST
542    }
543  } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
544    switch (UnOp->getOpcode()) {
545#define OPERATOR(NAME)                                                  \
546    case UO_##NAME: DISPATCH(Unary##NAME, UnaryOperator, S);
547
548    UNARYOP_LIST()
549#undef OPERATOR
550#undef UNARYOP_LIST
551    }
552  }
553
554  // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
555  switch (S->getStmtClass()) {
556  case Stmt::NoStmtClass: break;
557#define ABSTRACT_STMT(STMT)
558#define STMT(CLASS, PARENT) \
559  case Stmt::CLASS##Class: DISPATCH(CLASS, CLASS, S);
560#include "clang/AST/StmtNodes.inc"
561  }
562
563  return true;
564}
565
566template<typename Derived>
567bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
568  if (T.isNull())
569    return true;
570
571  switch (T->getTypeClass()) {
572#define ABSTRACT_TYPE(CLASS, BASE)
573#define TYPE(CLASS, BASE) \
574  case Type::CLASS: DISPATCH(CLASS##Type, CLASS##Type, \
575                             const_cast<Type*>(T.getTypePtr()));
576#include "clang/AST/TypeNodes.def"
577  }
578
579  return true;
580}
581
582template<typename Derived>
583bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
584  if (TL.isNull())
585    return true;
586
587  switch (TL.getTypeLocClass()) {
588#define ABSTRACT_TYPELOC(CLASS, BASE)
589#define TYPELOC(CLASS, BASE) \
590  case TypeLoc::CLASS: \
591    return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL));
592#include "clang/AST/TypeLocNodes.def"
593  }
594
595  return true;
596}
597
598
599template<typename Derived>
600bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
601  if (!D)
602    return true;
603
604  // As a syntax visitor, we want to ignore declarations for
605  // implicitly-defined declarations (ones not typed explicitly by the
606  // user).
607  if (D->isImplicit())
608    return true;
609
610  switch (D->getKind()) {
611#define ABSTRACT_DECL(DECL)
612#define DECL(CLASS, BASE) \
613  case Decl::CLASS: DISPATCH(CLASS##Decl, CLASS##Decl, D);
614#include "clang/AST/DeclNodes.inc"
615 }
616
617  return true;
618}
619
620#undef DISPATCH
621
622template<typename Derived>
623bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
624                                                    NestedNameSpecifier *NNS) {
625  if (!NNS)
626    return true;
627
628  if (NNS->getPrefix())
629    TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
630
631  switch (NNS->getKind()) {
632  case NestedNameSpecifier::Identifier:
633  case NestedNameSpecifier::Namespace:
634  case NestedNameSpecifier::NamespaceAlias:
635  case NestedNameSpecifier::Global:
636    return true;
637
638  case NestedNameSpecifier::TypeSpec:
639  case NestedNameSpecifier::TypeSpecWithTemplate:
640    TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
641  }
642
643  return true;
644}
645
646template<typename Derived>
647bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
648                                                  NestedNameSpecifierLoc NNS) {
649  if (!NNS)
650    return true;
651
652   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
653     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
654
655  switch (NNS.getNestedNameSpecifier()->getKind()) {
656  case NestedNameSpecifier::Identifier:
657  case NestedNameSpecifier::Namespace:
658  case NestedNameSpecifier::NamespaceAlias:
659  case NestedNameSpecifier::Global:
660    return true;
661
662  case NestedNameSpecifier::TypeSpec:
663  case NestedNameSpecifier::TypeSpecWithTemplate:
664    TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
665    break;
666  }
667
668  return true;
669}
670
671template<typename Derived>
672bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
673                                                 DeclarationNameInfo NameInfo) {
674  switch (NameInfo.getName().getNameKind()) {
675  case DeclarationName::CXXConstructorName:
676  case DeclarationName::CXXDestructorName:
677  case DeclarationName::CXXConversionFunctionName:
678    if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
679      TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
680
681    break;
682
683  case DeclarationName::Identifier:
684  case DeclarationName::ObjCZeroArgSelector:
685  case DeclarationName::ObjCOneArgSelector:
686  case DeclarationName::ObjCMultiArgSelector:
687  case DeclarationName::CXXOperatorName:
688  case DeclarationName::CXXLiteralOperatorName:
689  case DeclarationName::CXXUsingDirective:
690    break;
691  }
692
693  return true;
694}
695
696template<typename Derived>
697bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
698  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
699    TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
700  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
701    TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
702
703  return true;
704}
705
706template<typename Derived>
707bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
708                                                const TemplateArgument &Arg) {
709  switch (Arg.getKind()) {
710  case TemplateArgument::Null:
711  case TemplateArgument::Declaration:
712  case TemplateArgument::Integral:
713    return true;
714
715  case TemplateArgument::Type:
716    return getDerived().TraverseType(Arg.getAsType());
717
718  case TemplateArgument::Template:
719  case TemplateArgument::TemplateExpansion:
720    return getDerived().TraverseTemplateName(
721                                          Arg.getAsTemplateOrTemplatePattern());
722
723  case TemplateArgument::Expression:
724    return getDerived().TraverseStmt(Arg.getAsExpr());
725
726  case TemplateArgument::Pack:
727    return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
728                                                  Arg.pack_size());
729  }
730
731  return true;
732}
733
734// FIXME: no template name location?
735// FIXME: no source locations for a template argument pack?
736template<typename Derived>
737bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
738                                           const TemplateArgumentLoc &ArgLoc) {
739  const TemplateArgument &Arg = ArgLoc.getArgument();
740
741  switch (Arg.getKind()) {
742  case TemplateArgument::Null:
743  case TemplateArgument::Declaration:
744  case TemplateArgument::Integral:
745    return true;
746
747  case TemplateArgument::Type: {
748    // FIXME: how can TSI ever be NULL?
749    if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
750      return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
751    else
752      return getDerived().TraverseType(Arg.getAsType());
753  }
754
755  case TemplateArgument::Template:
756  case TemplateArgument::TemplateExpansion:
757    if (ArgLoc.getTemplateQualifierLoc())
758      TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
759                                            ArgLoc.getTemplateQualifierLoc()));
760    return getDerived().TraverseTemplateName(
761                                         Arg.getAsTemplateOrTemplatePattern());
762
763  case TemplateArgument::Expression:
764    return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
765
766  case TemplateArgument::Pack:
767    return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
768                                                  Arg.pack_size());
769  }
770
771  return true;
772}
773
774template<typename Derived>
775bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
776                                                  const TemplateArgument *Args,
777                                                            unsigned NumArgs) {
778  for (unsigned I = 0; I != NumArgs; ++I) {
779    TRY_TO(TraverseTemplateArgument(Args[I]));
780  }
781
782  return true;
783}
784
785template<typename Derived>
786bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
787                                                     CXXCtorInitializer *Init) {
788  if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
789    TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
790
791  if (Init->isWritten())
792    TRY_TO(TraverseStmt(Init->getInit()));
793  return true;
794}
795
796template<typename Derived>
797bool RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr::Capture C){
798  return true;
799}
800
801// ----------------- Type traversal -----------------
802
803// This macro makes available a variable T, the passed-in type.
804#define DEF_TRAVERSE_TYPE(TYPE, CODE)                     \
805  template<typename Derived>                                           \
806  bool RecursiveASTVisitor<Derived>::Traverse##TYPE (TYPE *T) {        \
807    TRY_TO(WalkUpFrom##TYPE (T));                                      \
808    { CODE; }                                                          \
809    return true;                                                       \
810  }
811
812DEF_TRAVERSE_TYPE(BuiltinType, { })
813
814DEF_TRAVERSE_TYPE(ComplexType, {
815    TRY_TO(TraverseType(T->getElementType()));
816  })
817
818DEF_TRAVERSE_TYPE(PointerType, {
819    TRY_TO(TraverseType(T->getPointeeType()));
820  })
821
822DEF_TRAVERSE_TYPE(BlockPointerType, {
823    TRY_TO(TraverseType(T->getPointeeType()));
824  })
825
826DEF_TRAVERSE_TYPE(LValueReferenceType, {
827    TRY_TO(TraverseType(T->getPointeeType()));
828  })
829
830DEF_TRAVERSE_TYPE(RValueReferenceType, {
831    TRY_TO(TraverseType(T->getPointeeType()));
832  })
833
834DEF_TRAVERSE_TYPE(MemberPointerType, {
835    TRY_TO(TraverseType(QualType(T->getClass(), 0)));
836    TRY_TO(TraverseType(T->getPointeeType()));
837  })
838
839DEF_TRAVERSE_TYPE(ConstantArrayType, {
840    TRY_TO(TraverseType(T->getElementType()));
841  })
842
843DEF_TRAVERSE_TYPE(IncompleteArrayType, {
844    TRY_TO(TraverseType(T->getElementType()));
845  })
846
847DEF_TRAVERSE_TYPE(VariableArrayType, {
848    TRY_TO(TraverseType(T->getElementType()));
849    TRY_TO(TraverseStmt(T->getSizeExpr()));
850  })
851
852DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
853    TRY_TO(TraverseType(T->getElementType()));
854    if (T->getSizeExpr())
855      TRY_TO(TraverseStmt(T->getSizeExpr()));
856  })
857
858DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
859    if (T->getSizeExpr())
860      TRY_TO(TraverseStmt(T->getSizeExpr()));
861    TRY_TO(TraverseType(T->getElementType()));
862  })
863
864DEF_TRAVERSE_TYPE(VectorType, {
865    TRY_TO(TraverseType(T->getElementType()));
866  })
867
868DEF_TRAVERSE_TYPE(ExtVectorType, {
869    TRY_TO(TraverseType(T->getElementType()));
870  })
871
872DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
873    TRY_TO(TraverseType(T->getResultType()));
874  })
875
876DEF_TRAVERSE_TYPE(FunctionProtoType, {
877    TRY_TO(TraverseType(T->getResultType()));
878
879    for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
880                                           AEnd = T->arg_type_end();
881         A != AEnd; ++A) {
882      TRY_TO(TraverseType(*A));
883    }
884
885    for (FunctionProtoType::exception_iterator E = T->exception_begin(),
886                                            EEnd = T->exception_end();
887         E != EEnd; ++E) {
888      TRY_TO(TraverseType(*E));
889    }
890  })
891
892DEF_TRAVERSE_TYPE(UnresolvedUsingType, { })
893DEF_TRAVERSE_TYPE(TypedefType, { })
894
895DEF_TRAVERSE_TYPE(TypeOfExprType, {
896    TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
897  })
898
899DEF_TRAVERSE_TYPE(TypeOfType, {
900    TRY_TO(TraverseType(T->getUnderlyingType()));
901  })
902
903DEF_TRAVERSE_TYPE(DecltypeType, {
904    TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
905  })
906
907DEF_TRAVERSE_TYPE(UnaryTransformType, {
908    TRY_TO(TraverseType(T->getBaseType()));
909    TRY_TO(TraverseType(T->getUnderlyingType()));
910    })
911
912DEF_TRAVERSE_TYPE(AutoType, {
913    TRY_TO(TraverseType(T->getDeducedType()));
914  })
915
916DEF_TRAVERSE_TYPE(RecordType, { })
917DEF_TRAVERSE_TYPE(EnumType, { })
918DEF_TRAVERSE_TYPE(TemplateTypeParmType, { })
919DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { })
920DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { })
921
922DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
923    TRY_TO(TraverseTemplateName(T->getTemplateName()));
924    TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
925  })
926
927DEF_TRAVERSE_TYPE(InjectedClassNameType, { })
928
929DEF_TRAVERSE_TYPE(AttributedType, {
930    TRY_TO(TraverseType(T->getModifiedType()));
931  })
932
933DEF_TRAVERSE_TYPE(ParenType, {
934    TRY_TO(TraverseType(T->getInnerType()));
935  })
936
937DEF_TRAVERSE_TYPE(ElaboratedType, {
938    if (T->getQualifier()) {
939      TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
940    }
941    TRY_TO(TraverseType(T->getNamedType()));
942  })
943
944DEF_TRAVERSE_TYPE(DependentNameType, {
945    TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
946  })
947
948DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
949    TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
950    TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
951  })
952
953DEF_TRAVERSE_TYPE(PackExpansionType, {
954    TRY_TO(TraverseType(T->getPattern()));
955  })
956
957DEF_TRAVERSE_TYPE(ObjCInterfaceType, { })
958
959DEF_TRAVERSE_TYPE(ObjCObjectType, {
960    // We have to watch out here because an ObjCInterfaceType's base
961    // type is itself.
962    if (T->getBaseType().getTypePtr() != T)
963      TRY_TO(TraverseType(T->getBaseType()));
964  })
965
966DEF_TRAVERSE_TYPE(ObjCObjectPointerType, {
967    TRY_TO(TraverseType(T->getPointeeType()));
968  })
969
970DEF_TRAVERSE_TYPE(AtomicType, {
971    TRY_TO(TraverseType(T->getValueType()));
972  })
973
974#undef DEF_TRAVERSE_TYPE
975
976// ----------------- TypeLoc traversal -----------------
977
978// This macro makes available a variable TL, the passed-in TypeLoc.
979// If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
980// in addition to WalkUpFrom* for the TypeLoc itself, such that existing
981// clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
982// continue to work.
983#define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                \
984  template<typename Derived>                                            \
985  bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
986    if (getDerived().shouldWalkTypesOfTypeLocs())                       \
987      TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE*>(TL.getTypePtr())));     \
988    TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                  \
989    { CODE; }                                                           \
990    return true;                                                        \
991  }
992
993template<typename Derived>
994bool RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(
995    QualifiedTypeLoc TL) {
996  // Move this over to the 'main' typeloc tree.  Note that this is a
997  // move -- we pretend that we were really looking at the unqualified
998  // typeloc all along -- rather than a recursion, so we don't follow
999  // the normal CRTP plan of going through
1000  // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
1001  // twice for the same type (once as a QualifiedTypeLoc version of
1002  // the type, once as an UnqualifiedTypeLoc version of the type),
1003  // which in effect means we'd call VisitTypeLoc twice with the
1004  // 'same' type.  This solves that problem, at the cost of never
1005  // seeing the qualified version of the type (unless the client
1006  // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
1007  // perfect solution.  A perfect solution probably requires making
1008  // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1009  // wrapper around Type* -- rather than being its own class in the
1010  // type hierarchy.
1011  return TraverseTypeLoc(TL.getUnqualifiedLoc());
1012}
1013
1014DEF_TRAVERSE_TYPELOC(BuiltinType, { })
1015
1016// FIXME: ComplexTypeLoc is unfinished
1017DEF_TRAVERSE_TYPELOC(ComplexType, {
1018    TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1019  })
1020
1021DEF_TRAVERSE_TYPELOC(PointerType, {
1022    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1023  })
1024
1025DEF_TRAVERSE_TYPELOC(BlockPointerType, {
1026    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1027  })
1028
1029DEF_TRAVERSE_TYPELOC(LValueReferenceType, {
1030    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1031  })
1032
1033DEF_TRAVERSE_TYPELOC(RValueReferenceType, {
1034    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1035  })
1036
1037// FIXME: location of base class?
1038// We traverse this in the type case as well, but how is it not reached through
1039// the pointee type?
1040DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1041    TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1042    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1043  })
1044
1045template<typename Derived>
1046bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1047  // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1048  TRY_TO(TraverseStmt(TL.getSizeExpr()));
1049  return true;
1050}
1051
1052DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1053    TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1054    return TraverseArrayTypeLocHelper(TL);
1055  })
1056
1057DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1058    TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1059    return TraverseArrayTypeLocHelper(TL);
1060  })
1061
1062DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1063    TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1064    return TraverseArrayTypeLocHelper(TL);
1065  })
1066
1067DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1068    TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1069    return TraverseArrayTypeLocHelper(TL);
1070  })
1071
1072// FIXME: order? why not size expr first?
1073// FIXME: base VectorTypeLoc is unfinished
1074DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1075    if (TL.getTypePtr()->getSizeExpr())
1076      TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1077    TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1078  })
1079
1080// FIXME: VectorTypeLoc is unfinished
1081DEF_TRAVERSE_TYPELOC(VectorType, {
1082    TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1083  })
1084
1085// FIXME: size and attributes
1086// FIXME: base VectorTypeLoc is unfinished
1087DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1088    TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1089  })
1090
1091DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, {
1092    TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
1093  })
1094
1095// FIXME: location of exception specifications (attributes?)
1096DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1097    TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
1098
1099    const FunctionProtoType *T = TL.getTypePtr();
1100
1101    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1102      if (TL.getArg(I)) {
1103        TRY_TO(TraverseDecl(TL.getArg(I)));
1104      } else if (I < T->getNumArgs()) {
1105        TRY_TO(TraverseType(T->getArgType(I)));
1106      }
1107    }
1108
1109    for (FunctionProtoType::exception_iterator E = T->exception_begin(),
1110                                            EEnd = T->exception_end();
1111         E != EEnd; ++E) {
1112      TRY_TO(TraverseType(*E));
1113    }
1114  })
1115
1116DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, { })
1117DEF_TRAVERSE_TYPELOC(TypedefType, { })
1118
1119DEF_TRAVERSE_TYPELOC(TypeOfExprType, {
1120    TRY_TO(TraverseStmt(TL.getUnderlyingExpr()));
1121  })
1122
1123DEF_TRAVERSE_TYPELOC(TypeOfType, {
1124    TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1125  })
1126
1127// FIXME: location of underlying expr
1128DEF_TRAVERSE_TYPELOC(DecltypeType, {
1129    TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1130  })
1131
1132DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1133    TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1134  })
1135
1136DEF_TRAVERSE_TYPELOC(AutoType, {
1137    TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1138  })
1139
1140DEF_TRAVERSE_TYPELOC(RecordType, { })
1141DEF_TRAVERSE_TYPELOC(EnumType, { })
1142DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { })
1143DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { })
1144DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { })
1145
1146// FIXME: use the loc for the template name?
1147DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1148    TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1149    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1150      TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1151    }
1152  })
1153
1154DEF_TRAVERSE_TYPELOC(InjectedClassNameType, { })
1155
1156DEF_TRAVERSE_TYPELOC(ParenType, {
1157    TRY_TO(TraverseTypeLoc(TL.getInnerLoc()));
1158  })
1159
1160DEF_TRAVERSE_TYPELOC(AttributedType, {
1161    TRY_TO(TraverseTypeLoc(TL.getModifiedLoc()));
1162  })
1163
1164DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1165    if (TL.getQualifierLoc()) {
1166      TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1167    }
1168    TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1169  })
1170
1171DEF_TRAVERSE_TYPELOC(DependentNameType, {
1172    TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1173  })
1174
1175DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1176    if (TL.getQualifierLoc()) {
1177      TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1178    }
1179
1180    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1181      TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1182    }
1183  })
1184
1185DEF_TRAVERSE_TYPELOC(PackExpansionType, {
1186    TRY_TO(TraverseTypeLoc(TL.getPatternLoc()));
1187  })
1188
1189DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, { })
1190
1191DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1192    // We have to watch out here because an ObjCInterfaceType's base
1193    // type is itself.
1194    if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1195      TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1196  })
1197
1198DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, {
1199    TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1200  })
1201
1202DEF_TRAVERSE_TYPELOC(AtomicType, {
1203    TRY_TO(TraverseTypeLoc(TL.getValueLoc()));
1204  })
1205
1206#undef DEF_TRAVERSE_TYPELOC
1207
1208// ----------------- Decl traversal -----------------
1209//
1210// For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1211// the children that come from the DeclContext associated with it.
1212// Therefore each Traverse* only needs to worry about children other
1213// than those.
1214
1215template<typename Derived>
1216bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1217  if (!DC)
1218    return true;
1219
1220  for (DeclContext::decl_iterator Child = DC->decls_begin(),
1221           ChildEnd = DC->decls_end();
1222       Child != ChildEnd; ++Child) {
1223    // BlockDecls are traversed through BlockExprs.
1224    if (!isa<BlockDecl>(*Child))
1225      TRY_TO(TraverseDecl(*Child));
1226  }
1227
1228  return true;
1229}
1230
1231// This macro makes available a variable D, the passed-in decl.
1232#define DEF_TRAVERSE_DECL(DECL, CODE)                           \
1233template<typename Derived>                                      \
1234bool RecursiveASTVisitor<Derived>::Traverse##DECL (DECL *D) {   \
1235  TRY_TO(WalkUpFrom##DECL (D));                                 \
1236  { CODE; }                                                     \
1237  TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));  \
1238  return true;                                                  \
1239}
1240
1241DEF_TRAVERSE_DECL(AccessSpecDecl, { })
1242
1243DEF_TRAVERSE_DECL(BlockDecl, {
1244    TRY_TO(TraverseTypeLoc(D->getSignatureAsWritten()->getTypeLoc()));
1245    TRY_TO(TraverseStmt(D->getBody()));
1246    // This return statement makes sure the traversal of nodes in
1247    // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1248    // is skipped - don't remove it.
1249    return true;
1250  })
1251
1252DEF_TRAVERSE_DECL(FileScopeAsmDecl, {
1253    TRY_TO(TraverseStmt(D->getAsmString()));
1254  })
1255
1256DEF_TRAVERSE_DECL(ImportDecl, { })
1257
1258DEF_TRAVERSE_DECL(FriendDecl, {
1259    // Friend is either decl or a type.
1260    if (D->getFriendType())
1261      TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1262    else
1263      TRY_TO(TraverseDecl(D->getFriendDecl()));
1264  })
1265
1266DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1267    if (D->getFriendType())
1268      TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1269    else
1270      TRY_TO(TraverseDecl(D->getFriendDecl()));
1271    for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1272      TemplateParameterList *TPL = D->getTemplateParameterList(I);
1273      for (TemplateParameterList::iterator ITPL = TPL->begin(),
1274                                           ETPL = TPL->end();
1275           ITPL != ETPL; ++ITPL) {
1276        TRY_TO(TraverseDecl(*ITPL));
1277      }
1278    }
1279  })
1280
1281DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1282  TRY_TO(TraverseDecl(D->getSpecialization()));
1283 })
1284
1285DEF_TRAVERSE_DECL(LinkageSpecDecl, { })
1286
1287DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {
1288    // FIXME: implement this
1289  })
1290
1291DEF_TRAVERSE_DECL(StaticAssertDecl, {
1292    TRY_TO(TraverseStmt(D->getAssertExpr()));
1293    TRY_TO(TraverseStmt(D->getMessage()));
1294  })
1295
1296DEF_TRAVERSE_DECL(TranslationUnitDecl, {
1297    // Code in an unnamed namespace shows up automatically in
1298    // decls_begin()/decls_end().  Thus we don't need to recurse on
1299    // D->getAnonymousNamespace().
1300  })
1301
1302DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1303    // We shouldn't traverse an aliased namespace, since it will be
1304    // defined (and, therefore, traversed) somewhere else.
1305    //
1306    // This return statement makes sure the traversal of nodes in
1307    // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1308    // is skipped - don't remove it.
1309    return true;
1310  })
1311
1312DEF_TRAVERSE_DECL(LabelDecl, {
1313  // There is no code in a LabelDecl.
1314})
1315
1316
1317DEF_TRAVERSE_DECL(NamespaceDecl, {
1318    // Code in an unnamed namespace shows up automatically in
1319    // decls_begin()/decls_end().  Thus we don't need to recurse on
1320    // D->getAnonymousNamespace().
1321  })
1322
1323DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {
1324    // FIXME: implement
1325  })
1326
1327DEF_TRAVERSE_DECL(ObjCCategoryDecl, {
1328    // FIXME: implement
1329  })
1330
1331DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {
1332    // FIXME: implement
1333  })
1334
1335DEF_TRAVERSE_DECL(ObjCImplementationDecl, {
1336    // FIXME: implement
1337  })
1338
1339DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
1340    // FIXME: implement
1341  })
1342
1343DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
1344    // FIXME: implement
1345  })
1346
1347DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1348    if (D->getResultTypeSourceInfo()) {
1349      TRY_TO(TraverseTypeLoc(D->getResultTypeSourceInfo()->getTypeLoc()));
1350    }
1351    for (ObjCMethodDecl::param_iterator
1352           I = D->param_begin(), E = D->param_end(); I != E; ++I) {
1353      TRY_TO(TraverseDecl(*I));
1354    }
1355    if (D->isThisDeclarationADefinition()) {
1356      TRY_TO(TraverseStmt(D->getBody()));
1357    }
1358    return true;
1359  })
1360
1361DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1362    // FIXME: implement
1363  })
1364
1365DEF_TRAVERSE_DECL(UsingDecl, {
1366    TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1367    TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1368  })
1369
1370DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1371    TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1372  })
1373
1374DEF_TRAVERSE_DECL(UsingShadowDecl, { })
1375
1376// A helper method for TemplateDecl's children.
1377template<typename Derived>
1378bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1379    TemplateParameterList *TPL) {
1380  if (TPL) {
1381    for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1382         I != E; ++I) {
1383      TRY_TO(TraverseDecl(*I));
1384    }
1385  }
1386  return true;
1387}
1388
1389// A helper method for traversing the implicit instantiations of a
1390// class template.
1391template<typename Derived>
1392bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations(
1393    ClassTemplateDecl *D) {
1394  ClassTemplateDecl::spec_iterator end = D->spec_end();
1395  for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {
1396    ClassTemplateSpecializationDecl* SD = *it;
1397
1398    switch (SD->getSpecializationKind()) {
1399    // Visit the implicit instantiations with the requested pattern.
1400    case TSK_Undeclared:
1401    case TSK_ImplicitInstantiation:
1402      TRY_TO(TraverseDecl(SD));
1403
1404    // We don't need to do anything on an explicit instantiation
1405    // or explicit specialization because there will be an explicit
1406    // node for it elsewhere.
1407    case TSK_ExplicitInstantiationDeclaration:
1408    case TSK_ExplicitInstantiationDefinition:
1409    case TSK_ExplicitSpecialization:
1410      break;
1411    }
1412  }
1413
1414  return true;
1415}
1416
1417DEF_TRAVERSE_DECL(ClassTemplateDecl, {
1418    CXXRecordDecl* TempDecl = D->getTemplatedDecl();
1419    TRY_TO(TraverseDecl(TempDecl));
1420    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1421
1422    // By default, we do not traverse the instantiations of
1423    // class templates since they do not appear in the user code. The
1424    // following code optionally traverses them.
1425    //
1426    // We only traverse the class instantiations when we see the canonical
1427    // declaration of the template, to ensure we only visit them once.
1428    if (getDerived().shouldVisitTemplateInstantiations() &&
1429        D == D->getCanonicalDecl())
1430      TRY_TO(TraverseClassInstantiations(D));
1431
1432    // Note that getInstantiatedFromMemberTemplate() is just a link
1433    // from a template instantiation back to the template from which
1434    // it was instantiated, and thus should not be traversed.
1435  })
1436
1437// A helper method for traversing the instantiations of a
1438// function while skipping its specializations.
1439template<typename Derived>
1440bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
1441    FunctionTemplateDecl *D) {
1442  FunctionTemplateDecl::spec_iterator end = D->spec_end();
1443  for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end;
1444       ++it) {
1445    FunctionDecl* FD = *it;
1446    switch (FD->getTemplateSpecializationKind()) {
1447    case TSK_Undeclared:
1448    case TSK_ImplicitInstantiation:
1449      // We don't know what kind of FunctionDecl this is.
1450      TRY_TO(TraverseDecl(FD));
1451      break;
1452
1453    // No need to visit explicit instantiations, we'll find the node
1454    // eventually.
1455    case TSK_ExplicitInstantiationDeclaration:
1456    case TSK_ExplicitInstantiationDefinition:
1457      break;
1458
1459    case TSK_ExplicitSpecialization:
1460      break;
1461    }
1462  }
1463
1464  return true;
1465}
1466
1467DEF_TRAVERSE_DECL(FunctionTemplateDecl, {
1468    TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1469    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1470
1471    // By default, we do not traverse the instantiations of
1472    // function templates since they do not appear in the user code. The
1473    // following code optionally traverses them.
1474    //
1475    // We only traverse the function instantiations when we see the canonical
1476    // declaration of the template, to ensure we only visit them once.
1477    if (getDerived().shouldVisitTemplateInstantiations() &&
1478        D == D->getCanonicalDecl())
1479      TRY_TO(TraverseFunctionInstantiations(D));
1480  })
1481
1482DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1483    // D is the "T" in something like
1484    //   template <template <typename> class T> class container { };
1485    TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1486    if (D->hasDefaultArgument()) {
1487      TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1488    }
1489    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1490  })
1491
1492DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1493    // D is the "T" in something like "template<typename T> class vector;"
1494    if (D->getTypeForDecl())
1495      TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1496    if (D->hasDefaultArgument())
1497      TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1498  })
1499
1500DEF_TRAVERSE_DECL(TypedefDecl, {
1501    TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1502    // We shouldn't traverse D->getTypeForDecl(); it's a result of
1503    // declaring the typedef, not something that was written in the
1504    // source.
1505  })
1506
1507DEF_TRAVERSE_DECL(TypeAliasDecl, {
1508    TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1509    // We shouldn't traverse D->getTypeForDecl(); it's a result of
1510    // declaring the type alias, not something that was written in the
1511    // source.
1512  })
1513
1514DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1515    TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1516    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1517  })
1518
1519DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1520    // A dependent using declaration which was marked with 'typename'.
1521    //   template<class T> class A : public B<T> { using typename B<T>::foo; };
1522    TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1523    // We shouldn't traverse D->getTypeForDecl(); it's a result of
1524    // declaring the type, not something that was written in the
1525    // source.
1526  })
1527
1528DEF_TRAVERSE_DECL(EnumDecl, {
1529    if (D->getTypeForDecl())
1530      TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1531
1532    TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1533    // The enumerators are already traversed by
1534    // decls_begin()/decls_end().
1535  })
1536
1537
1538// Helper methods for RecordDecl and its children.
1539template<typename Derived>
1540bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(
1541    RecordDecl *D) {
1542  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1543  // declaring the type, not something that was written in the source.
1544
1545  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1546  return true;
1547}
1548
1549template<typename Derived>
1550bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(
1551    CXXRecordDecl *D) {
1552  if (!TraverseRecordHelper(D))
1553    return false;
1554  if (D->isCompleteDefinition()) {
1555    for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
1556                                            E = D->bases_end();
1557         I != E; ++I) {
1558      TRY_TO(TraverseTypeLoc(I->getTypeSourceInfo()->getTypeLoc()));
1559    }
1560    // We don't traverse the friends or the conversions, as they are
1561    // already in decls_begin()/decls_end().
1562  }
1563  return true;
1564}
1565
1566DEF_TRAVERSE_DECL(RecordDecl, {
1567    TRY_TO(TraverseRecordHelper(D));
1568  })
1569
1570DEF_TRAVERSE_DECL(CXXRecordDecl, {
1571    TRY_TO(TraverseCXXRecordHelper(D));
1572  })
1573
1574DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {
1575    // For implicit instantiations ("set<int> x;"), we don't want to
1576    // recurse at all, since the instatiated class isn't written in
1577    // the source code anywhere.  (Note the instatiated *type* --
1578    // set<int> -- is written, and will still get a callback of
1579    // TemplateSpecializationType).  For explicit instantiations
1580    // ("template set<int>;"), we do need a callback, since this
1581    // is the only callback that's made for this instantiation.
1582    // We use getTypeAsWritten() to distinguish.
1583    if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1584      TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1585
1586    if (!getDerived().shouldVisitTemplateInstantiations() &&
1587        D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1588      // Returning from here skips traversing the
1589      // declaration context of the ClassTemplateSpecializationDecl
1590      // (embedded in the DEF_TRAVERSE_DECL() macro)
1591      // which contains the instantiated members of the class.
1592      return true;
1593  })
1594
1595template <typename Derived>
1596bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1597    const TemplateArgumentLoc *TAL, unsigned Count) {
1598  for (unsigned I = 0; I < Count; ++I) {
1599    TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1600  }
1601  return true;
1602}
1603
1604DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, {
1605    // The partial specialization.
1606    if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1607      for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1608           I != E; ++I) {
1609        TRY_TO(TraverseDecl(*I));
1610      }
1611    }
1612    // The args that remains unspecialized.
1613    TRY_TO(TraverseTemplateArgumentLocsHelper(
1614        D->getTemplateArgsAsWritten(), D->getNumTemplateArgsAsWritten()));
1615
1616    // Don't need the ClassTemplatePartialSpecializationHelper, even
1617    // though that's our parent class -- we already visit all the
1618    // template args here.
1619    TRY_TO(TraverseCXXRecordHelper(D));
1620
1621    // Instantiations will have been visited with the primary template.
1622  })
1623
1624DEF_TRAVERSE_DECL(EnumConstantDecl, {
1625    TRY_TO(TraverseStmt(D->getInitExpr()));
1626  })
1627
1628DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1629    // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1630    //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
1631    TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1632    TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1633  })
1634
1635DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1636
1637template<typename Derived>
1638bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1639  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1640  if (D->getTypeSourceInfo())
1641    TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1642  else
1643    TRY_TO(TraverseType(D->getType()));
1644  return true;
1645}
1646
1647DEF_TRAVERSE_DECL(FieldDecl, {
1648    TRY_TO(TraverseDeclaratorHelper(D));
1649    if (D->isBitField())
1650      TRY_TO(TraverseStmt(D->getBitWidth()));
1651    else if (D->hasInClassInitializer())
1652      TRY_TO(TraverseStmt(D->getInClassInitializer()));
1653  })
1654
1655DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1656    TRY_TO(TraverseDeclaratorHelper(D));
1657    if (D->isBitField())
1658      TRY_TO(TraverseStmt(D->getBitWidth()));
1659    // FIXME: implement the rest.
1660  })
1661
1662DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1663    TRY_TO(TraverseDeclaratorHelper(D));
1664    if (D->isBitField())
1665      TRY_TO(TraverseStmt(D->getBitWidth()));
1666    // FIXME: implement the rest.
1667  })
1668
1669template<typename Derived>
1670bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1671  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1672  TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1673
1674  // If we're an explicit template specialization, iterate over the
1675  // template args that were explicitly specified.  If we were doing
1676  // this in typing order, we'd do it between the return type and
1677  // the function args, but both are handled by the FunctionTypeLoc
1678  // above, so we have to choose one side.  I've decided to do before.
1679  if (const FunctionTemplateSpecializationInfo *FTSI =
1680      D->getTemplateSpecializationInfo()) {
1681    if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1682        FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1683      // A specialization might not have explicit template arguments if it has
1684      // a templated return type and concrete arguments.
1685      if (const ASTTemplateArgumentListInfo *TALI =
1686          FTSI->TemplateArgumentsAsWritten) {
1687        TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1688                                                  TALI->NumTemplateArgs));
1689      }
1690    }
1691  }
1692
1693  // Visit the function type itself, which can be either
1694  // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
1695  // also covers the return type and the function parameters,
1696  // including exception specifications.
1697  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1698
1699  if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1700    // Constructor initializers.
1701    for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(),
1702                                           E = Ctor->init_end();
1703         I != E; ++I) {
1704      TRY_TO(TraverseConstructorInitializer(*I));
1705    }
1706  }
1707
1708  if (D->isThisDeclarationADefinition()) {
1709    TRY_TO(TraverseStmt(D->getBody()));  // Function body.
1710  }
1711  return true;
1712}
1713
1714DEF_TRAVERSE_DECL(FunctionDecl, {
1715    // We skip decls_begin/decls_end, which are already covered by
1716    // TraverseFunctionHelper().
1717    return TraverseFunctionHelper(D);
1718  })
1719
1720DEF_TRAVERSE_DECL(CXXMethodDecl, {
1721    // We skip decls_begin/decls_end, which are already covered by
1722    // TraverseFunctionHelper().
1723    return TraverseFunctionHelper(D);
1724  })
1725
1726DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1727    // We skip decls_begin/decls_end, which are already covered by
1728    // TraverseFunctionHelper().
1729    return TraverseFunctionHelper(D);
1730  })
1731
1732// CXXConversionDecl is the declaration of a type conversion operator.
1733// It's not a cast expression.
1734DEF_TRAVERSE_DECL(CXXConversionDecl, {
1735    // We skip decls_begin/decls_end, which are already covered by
1736    // TraverseFunctionHelper().
1737    return TraverseFunctionHelper(D);
1738  })
1739
1740DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1741    // We skip decls_begin/decls_end, which are already covered by
1742    // TraverseFunctionHelper().
1743    return TraverseFunctionHelper(D);
1744  })
1745
1746template<typename Derived>
1747bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1748  TRY_TO(TraverseDeclaratorHelper(D));
1749  // Default params are taken care of when we traverse the ParmVarDecl.
1750  if (!isa<ParmVarDecl>(D))
1751    TRY_TO(TraverseStmt(D->getInit()));
1752  return true;
1753}
1754
1755DEF_TRAVERSE_DECL(VarDecl, {
1756    TRY_TO(TraverseVarHelper(D));
1757  })
1758
1759DEF_TRAVERSE_DECL(ImplicitParamDecl, {
1760    TRY_TO(TraverseVarHelper(D));
1761  })
1762
1763DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
1764    // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1765    TRY_TO(TraverseDeclaratorHelper(D));
1766    TRY_TO(TraverseStmt(D->getDefaultArgument()));
1767  })
1768
1769DEF_TRAVERSE_DECL(ParmVarDecl, {
1770    TRY_TO(TraverseVarHelper(D));
1771
1772    if (D->hasDefaultArg() &&
1773        D->hasUninstantiatedDefaultArg() &&
1774        !D->hasUnparsedDefaultArg())
1775      TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
1776
1777    if (D->hasDefaultArg() &&
1778        !D->hasUninstantiatedDefaultArg() &&
1779        !D->hasUnparsedDefaultArg())
1780      TRY_TO(TraverseStmt(D->getDefaultArg()));
1781  })
1782
1783#undef DEF_TRAVERSE_DECL
1784
1785// ----------------- Stmt traversal -----------------
1786//
1787// For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
1788// over the children defined in children() (every stmt defines these,
1789// though sometimes the range is empty).  Each individual Traverse*
1790// method only needs to worry about children other than those.  To see
1791// what children() does for a given class, see, e.g.,
1792//   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
1793
1794// This macro makes available a variable S, the passed-in stmt.
1795#define DEF_TRAVERSE_STMT(STMT, CODE)                                   \
1796template<typename Derived>                                              \
1797bool RecursiveASTVisitor<Derived>::Traverse##STMT (STMT *S) {           \
1798  TRY_TO(WalkUpFrom##STMT(S));                                          \
1799  { CODE; }                                                             \
1800  for (Stmt::child_range range = S->children(); range; ++range) {       \
1801    TRY_TO(TraverseStmt(*range));                                       \
1802  }                                                                     \
1803  return true;                                                          \
1804}
1805
1806DEF_TRAVERSE_STMT(AsmStmt, {
1807    TRY_TO(TraverseStmt(S->getAsmString()));
1808    for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
1809      TRY_TO(TraverseStmt(S->getInputConstraintLiteral(I)));
1810    }
1811    for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
1812      TRY_TO(TraverseStmt(S->getOutputConstraintLiteral(I)));
1813    }
1814    for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
1815      TRY_TO(TraverseStmt(S->getClobber(I)));
1816    }
1817    // children() iterates over inputExpr and outputExpr.
1818  })
1819
1820DEF_TRAVERSE_STMT(CXXCatchStmt, {
1821    TRY_TO(TraverseDecl(S->getExceptionDecl()));
1822    // children() iterates over the handler block.
1823  })
1824
1825DEF_TRAVERSE_STMT(DeclStmt, {
1826    for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();
1827         I != E; ++I) {
1828      TRY_TO(TraverseDecl(*I));
1829    }
1830    // Suppress the default iteration over children() by
1831    // returning.  Here's why: A DeclStmt looks like 'type var [=
1832    // initializer]'.  The decls above already traverse over the
1833    // initializers, so we don't have to do it again (which
1834    // children() would do).
1835    return true;
1836  })
1837
1838
1839// These non-expr stmts (most of them), do not need any action except
1840// iterating over the children.
1841DEF_TRAVERSE_STMT(BreakStmt, { })
1842DEF_TRAVERSE_STMT(CXXTryStmt, { })
1843DEF_TRAVERSE_STMT(CaseStmt, { })
1844DEF_TRAVERSE_STMT(CompoundStmt, { })
1845DEF_TRAVERSE_STMT(ContinueStmt, { })
1846DEF_TRAVERSE_STMT(DefaultStmt, { })
1847DEF_TRAVERSE_STMT(DoStmt, { })
1848DEF_TRAVERSE_STMT(ForStmt, { })
1849DEF_TRAVERSE_STMT(GotoStmt, { })
1850DEF_TRAVERSE_STMT(IfStmt, { })
1851DEF_TRAVERSE_STMT(IndirectGotoStmt, { })
1852DEF_TRAVERSE_STMT(LabelStmt, { })
1853DEF_TRAVERSE_STMT(AttributedStmt, { })
1854DEF_TRAVERSE_STMT(NullStmt, { })
1855DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { })
1856DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, { })
1857DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, { })
1858DEF_TRAVERSE_STMT(ObjCAtThrowStmt, { })
1859DEF_TRAVERSE_STMT(ObjCAtTryStmt, { })
1860DEF_TRAVERSE_STMT(ObjCForCollectionStmt, { })
1861DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, { })
1862DEF_TRAVERSE_STMT(CXXForRangeStmt, { })
1863DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
1864    TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1865    TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1866})
1867DEF_TRAVERSE_STMT(ReturnStmt, { })
1868DEF_TRAVERSE_STMT(SwitchStmt, { })
1869DEF_TRAVERSE_STMT(WhileStmt, { })
1870
1871
1872DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
1873    TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1874    TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1875    if (S->hasExplicitTemplateArgs()) {
1876      TRY_TO(TraverseTemplateArgumentLocsHelper(
1877          S->getTemplateArgs(), S->getNumTemplateArgs()));
1878    }
1879  })
1880
1881DEF_TRAVERSE_STMT(DeclRefExpr, {
1882    TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1883    TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1884    TRY_TO(TraverseTemplateArgumentLocsHelper(
1885        S->getTemplateArgs(), S->getNumTemplateArgs()));
1886  })
1887
1888DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
1889    TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1890    TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1891    if (S->hasExplicitTemplateArgs()) {
1892      TRY_TO(TraverseTemplateArgumentLocsHelper(
1893          S->getExplicitTemplateArgs().getTemplateArgs(),
1894          S->getNumTemplateArgs()));
1895    }
1896  })
1897
1898DEF_TRAVERSE_STMT(MemberExpr, {
1899    TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1900    TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1901    TRY_TO(TraverseTemplateArgumentLocsHelper(
1902        S->getTemplateArgs(), S->getNumTemplateArgs()));
1903  })
1904
1905DEF_TRAVERSE_STMT(ImplicitCastExpr, {
1906    // We don't traverse the cast type, as it's not written in the
1907    // source code.
1908  })
1909
1910DEF_TRAVERSE_STMT(CStyleCastExpr, {
1911    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1912  })
1913
1914DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
1915    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1916  })
1917
1918DEF_TRAVERSE_STMT(CXXConstCastExpr, {
1919    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1920  })
1921
1922DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
1923    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1924  })
1925
1926DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
1927    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1928  })
1929
1930DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
1931    TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1932  })
1933
1934// InitListExpr is a tricky one, because we want to do all our work on
1935// the syntactic form of the listexpr, but this method takes the
1936// semantic form by default.  We can't use the macro helper because it
1937// calls WalkUp*() on the semantic form, before our code can convert
1938// to the syntactic form.
1939template<typename Derived>
1940bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
1941  if (InitListExpr *Syn = S->getSyntacticForm())
1942    S = Syn;
1943  TRY_TO(WalkUpFromInitListExpr(S));
1944  // All we need are the default actions.  FIXME: use a helper function.
1945  for (Stmt::child_range range = S->children(); range; ++range) {
1946    TRY_TO(TraverseStmt(*range));
1947  }
1948  return true;
1949}
1950
1951// GenericSelectionExpr is a special case because the types and expressions
1952// are interleaved.  We also need to watch out for null types (default
1953// generic associations).
1954template<typename Derived>
1955bool RecursiveASTVisitor<Derived>::
1956TraverseGenericSelectionExpr(GenericSelectionExpr *S) {
1957  TRY_TO(WalkUpFromGenericSelectionExpr(S));
1958  TRY_TO(TraverseStmt(S->getControllingExpr()));
1959  for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
1960    if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
1961      TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
1962    TRY_TO(TraverseStmt(S->getAssocExpr(i)));
1963  }
1964  return true;
1965}
1966
1967// PseudoObjectExpr is a special case because of the wierdness with
1968// syntactic expressions and opaque values.
1969template<typename Derived>
1970bool RecursiveASTVisitor<Derived>::
1971TraversePseudoObjectExpr(PseudoObjectExpr *S) {
1972  TRY_TO(WalkUpFromPseudoObjectExpr(S));
1973  TRY_TO(TraverseStmt(S->getSyntacticForm()));
1974  for (PseudoObjectExpr::semantics_iterator
1975         i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) {
1976    Expr *sub = *i;
1977    if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
1978      sub = OVE->getSourceExpr();
1979    TRY_TO(TraverseStmt(sub));
1980  }
1981  return true;
1982}
1983
1984DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
1985    // This is called for code like 'return T()' where T is a built-in
1986    // (i.e. non-class) type.
1987    TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
1988  })
1989
1990DEF_TRAVERSE_STMT(CXXNewExpr, {
1991  // The child-iterator will pick up the other arguments.
1992  TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
1993  })
1994
1995DEF_TRAVERSE_STMT(OffsetOfExpr, {
1996    // The child-iterator will pick up the expression representing
1997    // the field.
1998    // FIMXE: for code like offsetof(Foo, a.b.c), should we get
1999    // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2000    TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2001  })
2002
2003DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2004    // The child-iterator will pick up the arg if it's an expression,
2005    // but not if it's a type.
2006    if (S->isArgumentType())
2007      TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2008  })
2009
2010DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2011    // The child-iterator will pick up the arg if it's an expression,
2012    // but not if it's a type.
2013    if (S->isTypeOperand())
2014      TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2015  })
2016
2017DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2018    // The child-iterator will pick up the arg if it's an expression,
2019    // but not if it's a type.
2020    if (S->isTypeOperand())
2021      TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2022  })
2023
2024DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, {
2025    TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2026  })
2027
2028DEF_TRAVERSE_STMT(BinaryTypeTraitExpr, {
2029    TRY_TO(TraverseTypeLoc(S->getLhsTypeSourceInfo()->getTypeLoc()));
2030    TRY_TO(TraverseTypeLoc(S->getRhsTypeSourceInfo()->getTypeLoc()));
2031  })
2032
2033DEF_TRAVERSE_STMT(TypeTraitExpr, {
2034  for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2035    TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2036})
2037
2038DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2039    TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2040  })
2041
2042DEF_TRAVERSE_STMT(ExpressionTraitExpr, {
2043    TRY_TO(TraverseStmt(S->getQueriedExpression()));
2044  })
2045
2046DEF_TRAVERSE_STMT(VAArgExpr, {
2047    // The child-iterator will pick up the expression argument.
2048    TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2049  })
2050
2051DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2052    // This is called for code like 'return T()' where T is a class type.
2053    TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2054  })
2055
2056// Walk only the visible parts of lambda expressions.
2057template<typename Derived>
2058bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
2059  for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
2060                                 CEnd = S->explicit_capture_end();
2061       C != CEnd; ++C) {
2062    TRY_TO(TraverseLambdaCapture(*C));
2063  }
2064
2065  if (S->hasExplicitParameters() || S->hasExplicitResultType()) {
2066    TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2067    if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2068      // Visit the whole type.
2069      TRY_TO(TraverseTypeLoc(TL));
2070    } else if (isa<FunctionProtoTypeLoc>(TL)) {
2071      FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);
2072      if (S->hasExplicitParameters()) {
2073        // Visit parameters.
2074        for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I) {
2075          TRY_TO(TraverseDecl(Proto.getArg(I)));
2076        }
2077      } else {
2078        TRY_TO(TraverseTypeLoc(Proto.getResultLoc()));
2079      }
2080    }
2081  }
2082
2083  TRY_TO(TraverseStmt(S->getBody()));
2084  return true;
2085}
2086
2087DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2088    // This is called for code like 'T()', where T is a template argument.
2089    TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2090  })
2091
2092// These expressions all might take explicit template arguments.
2093// We traverse those if so.  FIXME: implement these.
2094DEF_TRAVERSE_STMT(CXXConstructExpr, { })
2095DEF_TRAVERSE_STMT(CallExpr, { })
2096DEF_TRAVERSE_STMT(CXXMemberCallExpr, { })
2097
2098// These exprs (most of them), do not need any action except iterating
2099// over the children.
2100DEF_TRAVERSE_STMT(AddrLabelExpr, { })
2101DEF_TRAVERSE_STMT(ArraySubscriptExpr, { })
2102DEF_TRAVERSE_STMT(BlockExpr, {
2103  TRY_TO(TraverseDecl(S->getBlockDecl()));
2104  return true; // no child statements to loop through.
2105})
2106DEF_TRAVERSE_STMT(ChooseExpr, { })
2107DEF_TRAVERSE_STMT(CompoundLiteralExpr, { })
2108DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, { })
2109DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, { })
2110DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { })
2111DEF_TRAVERSE_STMT(CXXDeleteExpr, { })
2112DEF_TRAVERSE_STMT(ExprWithCleanups, { })
2113DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, { })
2114DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2115  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2116  if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2117    TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2118  if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2119    TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2120})
2121DEF_TRAVERSE_STMT(CXXThisExpr, { })
2122DEF_TRAVERSE_STMT(CXXThrowExpr, { })
2123DEF_TRAVERSE_STMT(UserDefinedLiteral, { })
2124DEF_TRAVERSE_STMT(DesignatedInitExpr, { })
2125DEF_TRAVERSE_STMT(ExtVectorElementExpr, { })
2126DEF_TRAVERSE_STMT(GNUNullExpr, { })
2127DEF_TRAVERSE_STMT(ImplicitValueInitExpr, { })
2128DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, { })
2129DEF_TRAVERSE_STMT(ObjCEncodeExpr, { })
2130DEF_TRAVERSE_STMT(ObjCIsaExpr, { })
2131DEF_TRAVERSE_STMT(ObjCIvarRefExpr, { })
2132DEF_TRAVERSE_STMT(ObjCMessageExpr, { })
2133DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, { })
2134DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, { })
2135DEF_TRAVERSE_STMT(ObjCProtocolExpr, { })
2136DEF_TRAVERSE_STMT(ObjCSelectorExpr, { })
2137DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, { })
2138DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2139  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2140})
2141DEF_TRAVERSE_STMT(ParenExpr, { })
2142DEF_TRAVERSE_STMT(ParenListExpr, { })
2143DEF_TRAVERSE_STMT(PredefinedExpr, { })
2144DEF_TRAVERSE_STMT(ShuffleVectorExpr, { })
2145DEF_TRAVERSE_STMT(StmtExpr, { })
2146DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2147  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2148  if (S->hasExplicitTemplateArgs()) {
2149    TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2150                                              S->getNumTemplateArgs()));
2151  }
2152})
2153
2154DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2155  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2156  if (S->hasExplicitTemplateArgs()) {
2157    TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2158                                              S->getNumTemplateArgs()));
2159  }
2160})
2161
2162DEF_TRAVERSE_STMT(SEHTryStmt, {})
2163DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2164DEF_TRAVERSE_STMT(SEHFinallyStmt,{})
2165
2166DEF_TRAVERSE_STMT(CXXOperatorCallExpr, { })
2167DEF_TRAVERSE_STMT(OpaqueValueExpr, { })
2168DEF_TRAVERSE_STMT(CUDAKernelCallExpr, { })
2169
2170// These operators (all of them) do not need any action except
2171// iterating over the children.
2172DEF_TRAVERSE_STMT(BinaryConditionalOperator, { })
2173DEF_TRAVERSE_STMT(ConditionalOperator, { })
2174DEF_TRAVERSE_STMT(UnaryOperator, { })
2175DEF_TRAVERSE_STMT(BinaryOperator, { })
2176DEF_TRAVERSE_STMT(CompoundAssignOperator, { })
2177DEF_TRAVERSE_STMT(CXXNoexceptExpr, { })
2178DEF_TRAVERSE_STMT(PackExpansionExpr, { })
2179DEF_TRAVERSE_STMT(SizeOfPackExpr, { })
2180DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, { })
2181DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, { })
2182DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, { })
2183DEF_TRAVERSE_STMT(AtomicExpr, { })
2184
2185// These literals (all of them) do not need any action.
2186DEF_TRAVERSE_STMT(IntegerLiteral, { })
2187DEF_TRAVERSE_STMT(CharacterLiteral, { })
2188DEF_TRAVERSE_STMT(FloatingLiteral, { })
2189DEF_TRAVERSE_STMT(ImaginaryLiteral, { })
2190DEF_TRAVERSE_STMT(StringLiteral, { })
2191DEF_TRAVERSE_STMT(ObjCStringLiteral, { })
2192DEF_TRAVERSE_STMT(ObjCBoxedExpr, { })
2193DEF_TRAVERSE_STMT(ObjCArrayLiteral, { })
2194DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, { })
2195
2196// Traverse OpenCL: AsType, Convert.
2197DEF_TRAVERSE_STMT(AsTypeExpr, { })
2198
2199// FIXME: look at the following tricky-seeming exprs to see if we
2200// need to recurse on anything.  These are ones that have methods
2201// returning decls or qualtypes or nestednamespecifier -- though I'm
2202// not sure if they own them -- or just seemed very complicated, or
2203// had lots of sub-types to explore.
2204//
2205// VisitOverloadExpr and its children: recurse on template args? etc?
2206
2207// FIXME: go through all the stmts and exprs again, and see which of them
2208// create new types, and recurse on the types (TypeLocs?) of those.
2209// Candidates:
2210//
2211//    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
2212//    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
2213//    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
2214//    Every class that has getQualifier.
2215
2216#undef DEF_TRAVERSE_STMT
2217
2218#undef TRY_TO
2219
2220} // end namespace clang
2221
2222#endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
2223