commit 6ad61450c8dae8e00515baebd2d214fded08ba4a
parent 019d43c228acbca38236f6f1c05c406d242703ce
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 30 Jul 2016 20:43:03 -0600
src: use better c++ style in ast visitor
Diffstat:
2 files changed, 18 insertions(+), 31 deletions(-)
diff --git a/src/inst_ast_visitor.cc b/src/inst_ast_visitor.cc
@@ -62,14 +62,14 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s)
std::stringstream ss;
ss << "(++_citrun_lines["
- << SM.getPresumedLineNumber(s->getLocStart())
+ << m_SM.getPresumedLineNumber(s->getLocStart())
<< "], ";
- if (TheRewriter.InsertTextBefore(stmt_to_inst->getLocStart(), ss.str()))
+ if (m_TheRewriter.InsertTextBefore(stmt_to_inst->getLocStart(), ss.str()))
// writing failed, don't attempt to add ")"
return true;
- TheRewriter.InsertTextAfter(real_loc_end(stmt_to_inst), ")");
- ++rewrite_count;
+ m_TheRewriter.InsertTextAfter(real_loc_end(stmt_to_inst), ")");
+ ++m_rewrite_count;
return true;
}
@@ -92,13 +92,13 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f)
clang::SourceLocation curly_brace(FuncBody->getLocStart().getLocWithOffset(1));
// Animate function calls by firing the entire declaration.
- int decl_start = SM.getPresumedLineNumber(f->getLocStart());
- int decl_end = SM.getPresumedLineNumber(curly_brace);
+ int decl_start = m_SM.getPresumedLineNumber(f->getLocStart());
+ int decl_end = m_SM.getPresumedLineNumber(curly_brace);
for (int i = decl_start; i <= decl_end; i++)
rewrite_text << "++_citrun_lines[" << i << "];";
// Rewrite the function source right after the beginning curly brace.
- TheRewriter.InsertTextBefore(curly_brace, rewrite_text.str());
+ m_TheRewriter.InsertTextBefore(curly_brace, rewrite_text.str());
return true;
}
@@ -107,5 +107,5 @@ clang::SourceLocation
RewriteASTVisitor::real_loc_end(clang::Stmt *d)
{
clang::SourceLocation _e(d->getLocEnd());
- return clang::SourceLocation(clang::Lexer::getLocForEndOfToken(_e, 0, SM, lopt));
+ return clang::SourceLocation(clang::Lexer::getLocForEndOfToken(_e, 0, m_SM, m_lopt));
}
diff --git a/src/inst_ast_visitor.h b/src/inst_ast_visitor.h
@@ -1,35 +1,22 @@
-/*
- * Copyright (c) 2016 Kyle Milz <kyle@0x30.net>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Rewrite/Core/Rewriter.h>
-
class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor> {
public:
- RewriteASTVisitor(clang::Rewriter &R) : TheRewriter(R), SM(R.getSourceMgr()), rewrite_count(0) {}
+ RewriteASTVisitor(clang::Rewriter &R) :
+ m_TheRewriter(R),
+ m_SM(R.getSourceMgr()),
+ m_rewrite_count(0) {}
bool VisitVarDecl(clang::VarDecl *d);
bool VisitStmt(clang::Stmt *s);
bool VisitFunctionDecl(clang::FunctionDecl *f);
- unsigned int GetRewriteCount() { return rewrite_count; };
+ unsigned int GetRewriteCount() { return m_rewrite_count; };
private:
- clang::Rewriter &TheRewriter;
- clang::SourceManager &SM;
- clang::LangOptions lopt;
- unsigned int rewrite_count;
+ clang::Rewriter &m_TheRewriter;
+ clang::SourceManager &m_SM;
+ clang::LangOptions m_lopt;
+ unsigned int m_rewrite_count;
- clang::SourceLocation real_loc_end(clang::Stmt *s);
+ clang::SourceLocation real_loc_end(clang::Stmt *s);
};