citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

visitor.h (1317B)


      1 #include <array>
      2 #include <clang/AST/RecursiveASTVisitor.h>
      3 #include <clang/Rewrite/Core/Rewriter.h>
      4 
      5 enum counters {
      6 	FUNC_DEF,
      7 	IF_STMT,
      8 	FOR_STMT,
      9 	WHILE_STMT,
     10 	DOWHILE_STMT,
     11 	SWITCH_STMT,
     12 	RET_STMT_VAL,
     13 	CALL_EXPR,
     14 	TOTAL_STMT,
     15 	BIN_OPER,
     16 	REWRITE_ERROR,
     17 	NCOUNTERS
     18 };
     19 
     20 class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor>
     21 {
     22 	bool			 modify_stmt(clang::Stmt *, int &);
     23 	clang::SourceLocation	 real_loc_end(clang::Stmt *);
     24 
     25 	clang::Rewriter		&m_TheRewriter;
     26 	clang::SourceManager	&m_SM;
     27 	clang::LangOptions	 m_lopt;
     28 
     29 public:
     30 	explicit		 RewriteASTVisitor(clang::Rewriter &R);
     31 	virtual			~RewriteASTVisitor() {};
     32 
     33 	virtual bool		 TraverseStmt(clang::Stmt *);
     34 	virtual bool		 TraverseDecl(clang::Decl *);
     35 
     36 	bool			 VisitVarDecl(clang::VarDecl *d);
     37 	bool			 VisitStmt(clang::Stmt *s);
     38 	bool			 VisitFunctionDecl(clang::FunctionDecl *f);
     39 
     40 	bool			 VisitIfStmt(clang::IfStmt *);
     41 	bool			 VisitForStmt(clang::ForStmt *);
     42 	bool			 VisitWhileStmt(clang::WhileStmt *);
     43 	bool			 VisitDoStmt(clang::DoStmt *);
     44 	bool			 VisitSwitchStmt(clang::SwitchStmt *);
     45 	bool			 VisitReturnStmt(clang::ReturnStmt *);
     46 	bool			 VisitCallExpr(clang::CallExpr *);
     47 	bool			 VisitBinaryOperator(clang::BinaryOperator *);
     48 
     49 	std::array<int, NCOUNTERS> m_counters;
     50 	std::array<std::string, NCOUNTERS> m_counter_descr;
     51 };