citrun

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

commit 36b8bcdc320462f835081977e92ff296bc421bb4
parent 535cea6debdcbb473403b0b5e287cd3fbe0c8daa
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Fri, 25 Mar 2016 12:56:36 -0600

instrument: hang onto the ast visitor for use later

Diffstat:
Minstrument/instrument_action.cc | 4+++-
Minstrument/instrument_action.h | 32+++++++++++++++-----------------
2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/instrument/instrument_action.cc b/instrument/instrument_action.cc @@ -22,7 +22,9 @@ InstrumentAction::CreateASTConsumer(clang::CompilerInstance &CI, clang::StringRe clang::SourceManager &sm = CI.getSourceManager(); TheRewriter.setSourceMgr(sm, CI.getLangOpts()); - return new MyASTConsumer(TheRewriter); + // Hang onto a reference to this so we can read from it later + InstrumentASTConsumer = new RewriteASTConsumer(TheRewriter); + return &InstrumentASTConsumer; } unsigned int diff --git a/instrument/instrument_action.h b/instrument/instrument_action.h @@ -4,24 +4,9 @@ #include "rewrite_ast_visitor.h" -// For each source file provided to the tool, a new FrontendAction is created. -class InstrumentAction : public clang::ASTFrontendAction { -public: - InstrumentAction() {}; - - void EndSourceFileAction() override; - clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &, clang::StringRef) override; - -private: - clang::Rewriter TheRewriter; -}; - - -// Implementation of the ASTConsumer interface for reading an AST produced -// by the Clang parser. -class MyASTConsumer : public clang::ASTConsumer { +class RewriteASTConsumer : public clang::ASTConsumer { public: - MyASTConsumer(clang::Rewriter &R) : Visitor(R) {} + RewriteASTConsumer(clang::Rewriter &R) : Visitor(R) {} // Override the method that gets called for each parsed top-level // declaration. @@ -37,3 +22,16 @@ public: private: RewriteASTVisitor Visitor; }; + +// For each source file provided to the tool, a new FrontendAction is created. +class InstrumentAction : public clang::ASTFrontendAction { +public: + InstrumentAction() {}; + + void EndSourceFileAction() override; + clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &, clang::StringRef) override; + +private: + clang::Rewriter TheRewriter; + RewriteASTConsumer *InstrumentASTConsumer; +};