]> granicus.if.org Git - clang/commitdiff
Now that the visitor is defined in one place, it is nice and easy to allow clients
authorChris Lattner <sabre@nondot.org>
Tue, 21 Aug 2007 04:06:29 +0000 (04:06 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Aug 2007 04:06:29 +0000 (04:06 +0000)
to have visitors that return non-void.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41212 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/StmtVisitor.h

index 346f331050ce60af5fa6fd03b1871ce527dd7d7d..43f863786128df993fd771520b16406dc8ef628f 100644 (file)
@@ -20,10 +20,10 @@ namespace clang {
   
 /// StmtVisitor - This class implements a simple visitor for Stmt subclasses.
 /// Since Expr derives from Stmt, this also includes support for visiting Exprs.
-template<typename ImplClass>
+template<typename ImplClass, typename RetTy=void>
 class StmtVisitor {
 public:
-  void Visit(Stmt *S) {
+  RetTy Visit(Stmt *S) {
     // Top switch stmt: dispatch to VisitFooStmt for each FooStmt.
     switch (S->getStmtClass()) {
     default: assert(0 && "Unknown stmt kind!");
@@ -38,13 +38,13 @@ public:
   // If the implementation chooses not to implement a certain visit method, fall
   // back on VisitExpr or whatever else is the superclass.
 #define STMT(N, CLASS, PARENT)                                   \
-  void Visit ## CLASS(CLASS *Node) {                             \
+  RetTy Visit ## CLASS(CLASS *Node) {                            \
     return static_cast<ImplClass*>(this)->Visit ## PARENT(Node); \
   }
 #include "clang/AST/StmtNodes.def"
 
   // Base case, ignore it. :)
-  void VisitStmt(Stmt *Node) {}
+  RetTy VisitStmt(Stmt *Node) { return RetTy(); }
 };
   
 }