/// 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!");
// 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(); }
};
}