1//==- CFGRecStmtVisitor - Recursive visitor of CFG statements ---*- 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 implements the template class CFGRecStmtVisitor, which extends
11// CFGStmtVisitor by implementing a default recursive visit of all statements.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_ANALYSIS_CFG_REC_STMT_VISITOR_H
16#define LLVM_CLANG_ANALYSIS_CFG_REC_STMT_VISITOR_H
17
18#include "clang/Analysis/Visitors/CFGStmtVisitor.h"
19
20namespace clang {
21template <typename ImplClass>
22class CFGRecStmtVisitor : public CFGStmtVisitor<ImplClass,void> {
23public:
24
25  void VisitStmt(Stmt *S) {
26    static_cast< ImplClass* >(this)->VisitChildren(S);
27  }
28
29  void VisitCompoundStmt(CompoundStmt *S) {
30    // Do nothing.  Everything in a CompoundStmt is inlined
31    // into the CFG.
32  }
33
34  void VisitConditionVariableInit(Stmt *S) {
35    assert(S == this->getCurrentBlkStmt());
36    VarDecl *CondVar = 0;
37    switch (S->getStmtClass()) {
38#define CONDVAR_CASE(CLASS) \
39case Stmt::CLASS ## Class:\
40CondVar = cast<CLASS>(S)->getConditionVariable();\
41break;
42        CONDVAR_CASE(IfStmt)
43        CONDVAR_CASE(ForStmt)
44        CONDVAR_CASE(SwitchStmt)
45        CONDVAR_CASE(WhileStmt)
46#undef CONDVAR_CASE
47      default:
48        llvm_unreachable("Infeasible");
49    }
50    static_cast<ImplClass*>(this)->Visit(CondVar->getInit());
51  }
52
53  // Defining operator() allows the visitor to be used as a C++ style functor.
54  void operator()(Stmt *S) { static_cast<ImplClass*>(this)->BlockStmt_Visit(S);}
55};
56
57} // end namespace clang
58
59#endif
60