diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-10-09 16:27:25 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-10-09 17:25:28 +0200 |
commit | 4fc56b9d4cd12cca51d7696e0776de5aa8f822cd (patch) | |
tree | 8a513a329ca300785307e3185eb9df4b686ce50c /compilerplugins | |
parent | d4aa136e975b150add5f32013ea37aa68e9ccb57 (diff) |
move some code to a common base
Change-Id: Ife306c69054dfcc20b1339b88a4e14e5333ced71
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/bodynotinblock.cxx | 15 | ||||
-rw-r--r-- | compilerplugins/clang/bodynotinblock.hxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/compileplugin.cxx | 16 | ||||
-rw-r--r-- | compilerplugins/clang/compileplugin.hxx | 18 | ||||
-rw-r--r-- | compilerplugins/clang/unusedvariablecheck.cxx | 15 | ||||
-rw-r--r-- | compilerplugins/clang/unusedvariablecheck.hxx | 8 |
6 files changed, 41 insertions, 41 deletions
diff --git a/compilerplugins/clang/bodynotinblock.cxx b/compilerplugins/clang/bodynotinblock.cxx index 9f5bf0e75c4e..ce19a5f6477a 100644 --- a/compilerplugins/clang/bodynotinblock.cxx +++ b/compilerplugins/clang/bodynotinblock.cxx @@ -12,8 +12,6 @@ #include <clang/Basic/SourceManager.h> -using namespace clang; - namespace loplugin { @@ -23,19 +21,8 @@ but are not inside a compound statement and thus the second one is unrelated. */ BodyNotInBlock::BodyNotInBlock( ASTContext& context ) - : context( context ) - { - } - -DiagnosticBuilder BodyNotInBlock::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ) + : Plugin( context ) { - // Do some mappings (e.g. for -Werror) that clang does not do for custom messages for some reason. - DiagnosticsEngine& diag = context.getDiagnostics(); - if( level == DiagnosticsEngine::Warning && diag.getWarningsAsErrors()) - level = DiagnosticsEngine::Error; - if( level == DiagnosticsEngine::Error && diag.getErrorsAsFatal()) - level = DiagnosticsEngine::Fatal; - return diag.Report( loc, diag.getCustomDiagID( level, message )); } void BodyNotInBlock::run() diff --git a/compilerplugins/clang/bodynotinblock.hxx b/compilerplugins/clang/bodynotinblock.hxx index dba82a67917e..9846d7a0e567 100644 --- a/compilerplugins/clang/bodynotinblock.hxx +++ b/compilerplugins/clang/bodynotinblock.hxx @@ -11,27 +11,23 @@ #ifndef BODYNOTINBLOCK_H #define BODYNOTINBLOCK_H -#include <clang/AST/RecursiveASTVisitor.h> - -using namespace clang; +#include "compileplugin.hxx" namespace loplugin { -typedef std::vector< const Stmt* > StmtParents; - class BodyNotInBlock : public RecursiveASTVisitor< BodyNotInBlock > + , public Plugin { public: explicit BodyNotInBlock( ASTContext& context ); void run(); bool VisitFunctionDecl( FunctionDecl* declaration ); private: + typedef std::vector< const Stmt* > StmtParents; void traverseStatement( const Stmt* stmt, StmtParents& parents ); void checkBody( const Stmt* body, const StmtParents& parents, int stmtType ); - DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ); - ASTContext& context; }; } // namespace diff --git a/compilerplugins/clang/compileplugin.cxx b/compilerplugins/clang/compileplugin.cxx index d2e32c04a5d8..99ab2725d7c5 100644 --- a/compilerplugins/clang/compileplugin.cxx +++ b/compilerplugins/clang/compileplugin.cxx @@ -25,6 +25,22 @@ using namespace clang; namespace loplugin { +Plugin::Plugin( ASTContext& context ) + : context( context ) + { + } + +DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ) + { + // Do some mappings (e.g. for -Werror) that clang does not do for custom messages for some reason. + DiagnosticsEngine& diag = context.getDiagnostics(); + if( level == DiagnosticsEngine::Warning && diag.getWarningsAsErrors()) + level = DiagnosticsEngine::Error; + if( level == DiagnosticsEngine::Error && diag.getErrorsAsFatal()) + level = DiagnosticsEngine::Fatal; + return diag.Report( loc, diag.getCustomDiagID( level, message )); + } + /** Class that manages all LO modules. */ diff --git a/compilerplugins/clang/compileplugin.hxx b/compilerplugins/clang/compileplugin.hxx index f7d5182b7b0f..edf3a5ea11a8 100644 --- a/compilerplugins/clang/compileplugin.hxx +++ b/compilerplugins/clang/compileplugin.hxx @@ -11,4 +11,22 @@ #ifndef COMPILEPLUGIN_H #define COMPILEPLUGIN_H +#include <clang/AST/RecursiveASTVisitor.h> + +using namespace clang; + +namespace loplugin +{ + +class Plugin + { + public: + explicit Plugin( ASTContext& context ); + protected: + DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ); + ASTContext& context; + }; + +} // namespace + #endif // COMPILEPLUGIN_H diff --git a/compilerplugins/clang/unusedvariablecheck.cxx b/compilerplugins/clang/unusedvariablecheck.cxx index 029e637b578c..a9e47b2eb316 100644 --- a/compilerplugins/clang/unusedvariablecheck.cxx +++ b/compilerplugins/clang/unusedvariablecheck.cxx @@ -12,8 +12,6 @@ #include <clang/Basic/SourceManager.h> -using namespace clang; - namespace loplugin { @@ -31,7 +29,7 @@ that cannot be edited there is a manual list below. */ UnusedVariableCheck::UnusedVariableCheck( ASTContext& context ) - : context( context ) + : Plugin( context ) { } @@ -40,17 +38,6 @@ void UnusedVariableCheck::run() TraverseDecl( context.getTranslationUnitDecl()); } -DiagnosticBuilder UnusedVariableCheck::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ) - { - // Do some mappings (e.g. for -Werror) that clang does not do for custom messages for some reason. - DiagnosticsEngine& diag = context.getDiagnostics(); - if( level == DiagnosticsEngine::Warning && diag.getWarningsAsErrors()) - level = DiagnosticsEngine::Error; - if( level == DiagnosticsEngine::Error && diag.getErrorsAsFatal()) - level = DiagnosticsEngine::Fatal; - return diag.Report( loc, diag.getCustomDiagID( level, message )); - } - bool UnusedVariableCheck::VisitNamedDecl( NamedDecl* declaration ) { // TODO also LO header files? or a subdir? diff --git a/compilerplugins/clang/unusedvariablecheck.hxx b/compilerplugins/clang/unusedvariablecheck.hxx index c49532a86414..21e0eabd03c0 100644 --- a/compilerplugins/clang/unusedvariablecheck.hxx +++ b/compilerplugins/clang/unusedvariablecheck.hxx @@ -11,23 +11,19 @@ #ifndef UNUSEDVARIABLECHECK_H #define UNUSEDVARIABLECHECK_H -#include <clang/AST/RecursiveASTVisitor.h> - -using namespace clang; +#include "compileplugin.hxx" namespace loplugin { class UnusedVariableCheck : public RecursiveASTVisitor< UnusedVariableCheck > + , public Plugin { public: explicit UnusedVariableCheck( ASTContext& context ); void run(); bool VisitNamedDecl( NamedDecl* declaration ); - private: - DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ); - ASTContext& context; }; } // namespace |