[cfe-commits] r107008 - /cfe/trunk/include/clang/AST/RecursiveASTVisitor.h

Craig Silverstein csilvers2000 at yahoo.com
Mon Jun 28 08:37:14 PDT 2010


Author: csilvers
Date: Mon Jun 28 10:37:14 2010
New Revision: 107008

URL: http://llvm.org/viewvc/llvm-project?rev=107008&view=rev
Log:
Add support for traversing initializer lists (in constructors), which
we ignoring before.  To give access to the names on the initializer,
which aren't a type or an expr or a decl, I've introduced a new
TraverseInitializer.  By default, it just traverses on the expr that
the name is being initialized to.

Reviewed by chandlerc.  Tested via clang's 'make test'.

Modified:
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=107008&r1=107007&r2=107008&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Jun 28 10:37:14 2010
@@ -179,6 +179,14 @@
   bool TraverseTemplateArguments(const TemplateArgument *Args,
                                  unsigned NumArgs);
 
+  /// \brief Recursively visit a constructor initializer.  This
+  /// automatically dispatches to another visitor for the initializer
+  /// expression, but not for the name of the initializer, so may
+  /// be overridden for clients that need access to the nam.e
+  ///
+  /// \returns false if the visitation was terminated early, true otherwise.
+  bool TraverseInitializer(clang::CXXBaseOrMemberInitializer* Init);
+
   // ---- Methods on Stmts ----
 
   // Declare Traverse*() for all concrete Stmt classes.
@@ -460,6 +468,16 @@
   return true;
 }
 
+template<typename Derived>
+bool RecursiveASTVisitor<Derived>::TraverseInitializer(
+                                    clang::CXXBaseOrMemberInitializer* Init) {
+  // FIXME: recurse on TypeLoc of the base initializer if isBaseInitializer()?
+  if (Init->isWritten())
+    TRY_TO(TraverseStmt(Init->getInit()));
+  return true;
+}
+
+
 // ----------------- Type traversal -----------------
 
 // This macro makes available a variable T, the passed-in type.
@@ -803,7 +821,6 @@
   })
 
 DEF_TRAVERSE_DECL(TypedefDecl, {
-    // FIXME: I *think* this returns the right type (D's immediate typedef)
     TRY_TO(TraverseType(D->getUnderlyingType()));
     // We shouldn't traverse D->getTypeForDecl(); it's a result of
     // declaring the typedef, not something that was written in the
@@ -880,6 +897,8 @@
     for (unsigned I = 0; I < TAL.size(); ++I) {
       TRY_TO(TraverseTemplateArgument(TAL.get(I)));
     }
+    // FIXME: I think we only want to traverse this if it's an explicit
+    // specialization.
     TRY_TO(TraverseCXXRecordHelper(D));
   })
 
@@ -995,7 +1014,7 @@
     for (CXXConstructorDecl::init_iterator I = D->init_begin(),
                                            E = D->init_end();
          I != E; ++I) {
-      // FIXME: figure out how to recurse on the initializers
+      TRY_TO(TraverseInitializer(*I));
     }
 
     // We skip decls_begin/decls_end, which are already covered by





More information about the cfe-commits mailing list