summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-02-02 19:31:24 +0100
committerLuboš Luňák <l.lunak@suse.cz>2013-02-02 22:59:45 +0100
commitb4392c575e5aaf31ccf0813a20450187df37cf59 (patch)
treed4ff38959cfbca91ba1c8bcef3b8280cab860c58 /compilerplugins
parentefe9bf61ed408e94a9171992c1582e00f21d209e (diff)
always use the report() helper
Change-Id: I2966fdb5bd98b1ddf718079584acf90a3e3a3700
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx10
-rw-r--r--compilerplugins/clang/plugin.hxx4
-rw-r--r--compilerplugins/clang/pluginhandler.cxx31
-rw-r--r--compilerplugins/clang/pluginhandler.hxx2
-rw-r--r--compilerplugins/clang/postfixincrementfix.cxx12
5 files changed, 30 insertions, 29 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 01b2894dfcab..799fbabdbf22 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -28,6 +28,12 @@ Plugin::Plugin( ASTContext& context )
DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
{
+ return report( level, message, context, loc );
+ }
+
+DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef message, ASTContext& context,
+ SourceLocation loc )
+ {
DiagnosticsEngine& diag = context.getDiagnostics();
#if 0
// Do some mappings (e.g. for -Werror) that clang does not do for custom messages for some reason.
@@ -168,9 +174,7 @@ bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange
bool RewritePlugin::reportEditFailure( SourceLocation loc )
{
- DiagnosticsEngine& diag = context.getDiagnostics();
- diag.Report( loc, diag.getCustomDiagID( DiagnosticsEngine::Warning,
- "cannot perform source modification (macro expansion involved?) [loplugin]" ));
+ report( DiagnosticsEngine::Warning, "cannot perform source modification (macro expansion involved?) [loplugin]", loc );
return false;
}
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 014329e12eb1..f7f8e9f10382 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -41,8 +41,10 @@ class Plugin
virtual ~Plugin();
virtual void run() = 0;
template< typename T > class Registration;
- protected:
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
+ static DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message,
+ ASTContext& context, SourceLocation loc = SourceLocation());
+ protected:
bool ignoreLocation( SourceLocation loc );
bool ignoreLocation( const Decl* decl );
bool ignoreLocation( const Stmt* stmt );
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index 023a270dae46..1c36ede707f8 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -37,7 +37,8 @@ static int pluginCount = 0;
static bool pluginObjectsCreated = false;
PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args )
- : rewriter( context.getSourceManager(), context.getLangOpts())
+ : context( context )
+ , rewriter( context.getSourceManager(), context.getLangOpts())
{
bool wasCreated = false;
for( int i = 0;
@@ -60,11 +61,7 @@ PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args
}
pluginObjectsCreated = true;
if( !args.empty() && !wasCreated )
- {
- DiagnosticsEngine& diag = context.getDiagnostics();
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Fatal,
- "unknown plugin tool %0 [loplugin]" )) << args.front();
- }
+ report( DiagnosticsEngine::Fatal, "unknown plugin tool %0 [loplugin]" ) << args.front();
}
PluginHandler::~PluginHandler()
@@ -87,6 +84,11 @@ void PluginHandler::registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ),
++pluginCount;
}
+DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
+ {
+ return Plugin::report( level, message, context, loc );
+ }
+
void PluginHandler::HandleTranslationUnit( ASTContext& context )
{
if( context.getDiagnostics().hasErrorOccurred())
@@ -103,7 +105,6 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
++it )
{
const FileEntry* e = context.getSourceManager().getFileEntryForID( it->first );
- DiagnosticsEngine& diag = context.getDiagnostics();
/* Check where the file actually is, and warn about cases where modification
most probably doesn't matter (generated files in workdir).
The order here is important, as OUTDIR and WORKDIR are often in SRCDIR/BUILDDIR,
@@ -125,21 +126,18 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
}
}
if( modifyFile.empty())
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
- "modified source in solver/ : %0 [loplugin]" )) << e->getName();
+ report( DiagnosticsEngine::Warning, "modified source in solver/ : %0 [loplugin]" ) << e->getName();
}
else if( strncmp( e->getName(), WORKDIR, strlen( WORKDIR )) == 0 )
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
- "modified source in workdir/ : %0 [loplugin]" )) << e->getName();
+ report( DiagnosticsEngine::Warning, "modified source in workdir/ : %0 [loplugin]" ) << e->getName();
else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR, strlen( BUILDDIR )) == 0 )
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
- "modified source in build dir : %0 [loplugin]" )) << e->getName();
+ report( DiagnosticsEngine::Warning, "modified source in build dir : %0 [loplugin]" ) << e->getName();
else if( strncmp( e->getName(), SRCDIR, strlen( SRCDIR )) == 0 )
; // ok
else
{
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
- "modified source in unknown location, not modifying : %0 [loplugin]" )) << e->getName();
+ report( DiagnosticsEngine::Warning, "modified source in unknown location, not modifying : %0 [loplugin]" )
+ << e->getName();
continue; // --->
}
if( modifyFile.empty())
@@ -159,8 +157,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
ostream.clear_error();
unlink( filename );
if( !ok )
- diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Error,
- "cannot write modified source to %0 (%1) [loplugin]" )) << modifyFile << error;
+ report( DiagnosticsEngine::Error, "cannot write modified source to %0 (%1) [loplugin]" ) << modifyFile << error;
delete[] filename;
}
}
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index 2211275208ae..23ca21767fd5 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -31,6 +31,8 @@ class PluginHandler
virtual void HandleTranslationUnit( ASTContext& context );
static void registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ), const char* optionName, bool isRewriter );
private:
+ DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
+ ASTContext& context;
Rewriter rewriter;
};
diff --git a/compilerplugins/clang/postfixincrementfix.cxx b/compilerplugins/clang/postfixincrementfix.cxx
index 3f4688ec8bfb..e1f6849ec993 100644
--- a/compilerplugins/clang/postfixincrementfix.cxx
+++ b/compilerplugins/clang/postfixincrementfix.cxx
@@ -119,10 +119,8 @@ bool PostfixIncrementFix::canChangePostfixToPrefix( const CXXOperatorCallExpr* o
return canChangeInConditionStatement( op, dyn_cast< ForStmt >( parents[ parent_pos ] )->getCond(),
parents, parent_pos );
default:
- DiagnosticsEngine& diag = context.getDiagnostics();
- unsigned diagid = diag.getCustomDiagID( DiagnosticsEngine::Fatal,
- "cannot analyze operator++ (plugin needs fixing) [loplugin]" );
- diag.Report( op->getLocStart(), diagid ) << parents[ parent_pos ]->getSourceRange();
+ report( DiagnosticsEngine::Fatal, "cannot analyze operator++ (plugin needs fixing) [loplugin]",
+ op->getLocStart()) << parents[ parent_pos ]->getSourceRange();
// parents[ parent_pos ]->dump();
// parents[ std::max( parent_pos - 3, 0 ) ]->dump();
return false;
@@ -157,10 +155,8 @@ bool PostfixIncrementFix::shouldDoChange( const Expr* operand )
return true;
default:
{
- DiagnosticsEngine& diag = context.getDiagnostics();
- unsigned diagid = diag.getCustomDiagID( DiagnosticsEngine::Fatal,
- "cannot analyze operator++ (plugin needs fixing) [loplugin]" );
- diag.Report( expr->getLocStart(), diagid ) << operand->getSourceRange();
+ report( DiagnosticsEngine::Fatal, "cannot analyze operator++ (plugin needs fixing) [loplugin]",
+ expr->getLocStart()) << operand->getSourceRange();
expr->dump();
operand->dump();
return false;