always use the report() helper
Change-Id: I2966fdb5bd98b1ddf718079584acf90a3e3a3700
This commit is contained in:
parent
efe9bf61ed
commit
b4392c575e
@ -27,6 +27,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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user