citrun

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

commit ce5762df302d58a99431ee3450ce26cc07b0512e
parent eda5b40d6912ca16ba36b768e481c2f357c904a4
Author: Kyle Milz <kyle@0x30.net>
Date:   Mon,  8 Aug 2016 22:09:57 -0600

src: move ast visitor statistics descriptions

Diffstat:
Msrc/inst_action.cc | 21++++++---------------
Msrc/inst_ast_visitor.h | 13++++++++++++-
2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/inst_action.cc b/src/inst_action.cc @@ -81,24 +81,15 @@ InstrumentAction::EndSourceFileAction() *m_log << m_pfx << " " << num_lines << " Lines of source code\n"; *m_log << m_pfx << " " << header_sz << " Lines of instrumentation header\n"; - std::vector<std::string> counter_descr; - counter_descr.push_back("Functions called 'main'"); - counter_descr.push_back("Function definitions"); - counter_descr.push_back("If statements"); - counter_descr.push_back("For statements"); - counter_descr.push_back("While statements"); - counter_descr.push_back("Switch statements"); - counter_descr.push_back("Return statement values"); - counter_descr.push_back("Call expressions"); - counter_descr.push_back("Total statements"); - + // + // Write out statistics from the AST visitor. + // RewriteASTVisitor v = m_InstrumentASTConsumer->get_visitor(); for (int i = 0; i < 9; i++) { - int count = v.m_counters[i]; - if (count == 0) + if (v.m_counters[i] == 0) continue; - *m_log << m_pfx << " " << count << " " << counter_descr[i] - << "\n"; + *m_log << m_pfx << " " << v.m_counters[i] << " " + << v.m_counter_descr[i] << "\n"; } std::string out_file(file_name); diff --git a/src/inst_ast_visitor.h b/src/inst_ast_visitor.h @@ -6,6 +6,17 @@ class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor> { public: RewriteASTVisitor(clang::Rewriter &R) : m_counters(), + m_counter_descr({ + "Functions called 'main'", + "Function definitions", + "If statements", + "For statements", + "While statements", + "Switch statements", + "Return statement values", + "Call expressions", + "Total statements" + }), m_TheRewriter(R), m_SM(R.getSourceMgr()) {} @@ -14,8 +25,8 @@ public: bool VisitStmt(clang::Stmt *s); bool VisitFunctionDecl(clang::FunctionDecl *f); - // Order defined by descriptions in inst_action.cc. std::array<int, 9> m_counters; + std::array<std::string, 9> m_counter_descr; private: bool modify_stmt(clang::Stmt *);