clang API Documentation

CFGRecStmtVisitor.h
Go to the documentation of this file.
00001 //==- CFGRecStmtVisitor - Recursive visitor of CFG statements ---*- C++ --*-==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the template class CFGRecStmtVisitor, which extends
00011 // CFGStmtVisitor by implementing a default recursive visit of all statements.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_ANALYSIS_CFG_REC_STMT_VISITOR_H
00016 #define LLVM_CLANG_ANALYSIS_CFG_REC_STMT_VISITOR_H
00017 
00018 #include "clang/Analysis/Visitors/CFGStmtVisitor.h"
00019 
00020 namespace clang {
00021 template <typename ImplClass>
00022 class CFGRecStmtVisitor : public CFGStmtVisitor<ImplClass,void> {
00023 public:
00024 
00025   void VisitStmt(Stmt *S) {
00026     static_cast< ImplClass* >(this)->VisitChildren(S);
00027   }
00028   
00029   void VisitCompoundStmt(CompoundStmt *S) {
00030     // Do nothing.  Everything in a CompoundStmt is inlined
00031     // into the CFG.
00032   }
00033   
00034   void VisitConditionVariableInit(Stmt *S) {
00035     assert(S == this->getCurrentBlkStmt());
00036     VarDecl *CondVar = 0;
00037     switch (S->getStmtClass()) {
00038 #define CONDVAR_CASE(CLASS) \
00039 case Stmt::CLASS ## Class:\
00040 CondVar = cast<CLASS>(S)->getConditionVariable();\
00041 break;
00042         CONDVAR_CASE(IfStmt)
00043         CONDVAR_CASE(ForStmt)
00044         CONDVAR_CASE(SwitchStmt)
00045         CONDVAR_CASE(WhileStmt)
00046 #undef CONDVAR_CASE
00047       default:
00048         llvm_unreachable("Infeasible");
00049     }    
00050     static_cast<ImplClass*>(this)->Visit(CondVar->getInit());
00051   }
00052 
00053   // Defining operator() allows the visitor to be used as a C++ style functor.
00054   void operator()(Stmt *S) { static_cast<ImplClass*>(this)->BlockStmt_Visit(S);}
00055 };
00056 
00057 } // end namespace clang
00058 
00059 #endif