citrun

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

commit ff95de310a656ea68fe4e4bb5497fc968395bbbd
parent 18f985ddc431ae4e838f004da7e869e5ff1f59c7
Author: Kyle Milz <kyle@0x30.net>
Date:   Tue,  9 Aug 2016 22:46:22 -0600

src: use an enum to keep track of counters

Diffstat:
Msrc/inst_action.cc | 2+-
Msrc/inst_visitor.cc | 18+++++++++---------
Msrc/inst_visitor.h | 17+++++++++++++++--
3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/inst_action.cc b/src/inst_action.cc @@ -116,7 +116,7 @@ InstrumentAction::EndSourceFileAction() // Write out statistics from the AST visitor. // RewriteASTVisitor v = m_InstrumentASTConsumer->get_visitor(); - for (int i = 0; i < 9; i++) { + for (int i = 0; i < NCOUNTERS; i++) { if (v.m_counters[i] == 0) continue; *m_log << m_pfx << " " << v.m_counters[i] << " " diff --git a/src/inst_visitor.cc b/src/inst_visitor.cc @@ -29,37 +29,37 @@ RewriteASTVisitor::VisitVarDecl(clang::VarDecl *d) bool RewriteASTVisitor::VisitStmt(clang::Stmt *s) { - m_counters[8]++; + m_counters[TOTAL_STMT]++; if (clang::isa<clang::IfStmt>(s)) { s = clang::cast<clang::IfStmt>(s)->getCond(); if (modify_stmt(s) == false) return true; - m_counters[2]++; + m_counters[IF_STMT]++; } else if (clang::isa<clang::ForStmt>(s)) { s = clang::cast<clang::ForStmt>(s)->getCond(); if (modify_stmt(s) == false) return true; - m_counters[3]++; + m_counters[FOR_STMT]++; } else if (clang::isa<clang::WhileStmt>(s)) { s = clang::cast<clang::WhileStmt>(s)->getCond(); if (modify_stmt(s) == false) return true; - m_counters[4]++; + m_counters[WHILE_STMT]++; } else if (clang::isa<clang::SwitchStmt>(s)) { s = clang::cast<clang::SwitchStmt>(s)->getCond(); if (modify_stmt(s) == false) return true; - m_counters[5]++; + m_counters[SWITCH_STMT]++; } else if (clang::isa<clang::ReturnStmt>(s)) { s = clang::cast<clang::ReturnStmt>(s)->getRetValue(); if (modify_stmt(s) == false) return true; - m_counters[6]++; + m_counters[RET_STMT_VAL]++; } /* else if (isa<BreakStmt>(s) || isa<ContinueStmt>(s) || @@ -71,7 +71,7 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s) else if (clang::isa<clang::CallExpr>(s)) { if (modify_stmt(s) == false) return true; - m_counters[7]++; + m_counters[CALL_EXPR]++; } return true; @@ -107,7 +107,7 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f) // main() is a special case because it must start the runtime thread. clang::DeclarationName DeclName = f->getNameInfo().getName(); if (DeclName.getAsString() == "main") { - m_counters[0]++; + m_counters[FUNC_MAIN]++; rewrite_text << "citrun_start();"; } @@ -123,7 +123,7 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f) // Rewrite the function source right after the beginning curly brace. m_TheRewriter.InsertTextBefore(curly_brace, rewrite_text.str()); - m_counters[1]++; + m_counters[FUNC_DEF]++; return true; } diff --git a/src/inst_visitor.h b/src/inst_visitor.h @@ -2,6 +2,19 @@ #include <clang/AST/RecursiveASTVisitor.h> #include <clang/Rewrite/Core/Rewriter.h> +enum counters { + FUNC_MAIN, + FUNC_DEF, + IF_STMT, + FOR_STMT, + WHILE_STMT, + SWITCH_STMT, + RET_STMT_VAL, + CALL_EXPR, + TOTAL_STMT, + NCOUNTERS +}; + class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor> { public: RewriteASTVisitor(clang::Rewriter &R) : @@ -25,8 +38,8 @@ public: bool VisitStmt(clang::Stmt *s); bool VisitFunctionDecl(clang::FunctionDecl *f); - std::array<int, 9> m_counters; - std::array<std::string, 9> m_counter_descr; + std::array<int, NCOUNTERS> m_counters; + std::array<std::string, NCOUNTERS> m_counter_descr; private: bool modify_stmt(clang::Stmt *);