always use the report() helper
Change-Id: I2966fdb5bd98b1ddf718079584acf90a3e3a3700
This commit is contained in:
@@ -27,6 +27,12 @@ Plugin::Plugin( ASTContext& context )
|
|||||||
}
|
}
|
||||||
|
|
||||||
DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
|
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();
|
DiagnosticsEngine& diag = context.getDiagnostics();
|
||||||
#if 0
|
#if 0
|
||||||
@@ -168,9 +174,7 @@ bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange
|
|||||||
|
|
||||||
bool RewritePlugin::reportEditFailure( SourceLocation loc )
|
bool RewritePlugin::reportEditFailure( SourceLocation loc )
|
||||||
{
|
{
|
||||||
DiagnosticsEngine& diag = context.getDiagnostics();
|
report( DiagnosticsEngine::Warning, "cannot perform source modification (macro expansion involved?) [loplugin]", loc );
|
||||||
diag.Report( loc, diag.getCustomDiagID( DiagnosticsEngine::Warning,
|
|
||||||
"cannot perform source modification (macro expansion involved?) [loplugin]" ));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,8 +41,10 @@ class Plugin
|
|||||||
virtual ~Plugin();
|
virtual ~Plugin();
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
template< typename T > class Registration;
|
template< typename T > class Registration;
|
||||||
protected:
|
|
||||||
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
|
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( SourceLocation loc );
|
||||||
bool ignoreLocation( const Decl* decl );
|
bool ignoreLocation( const Decl* decl );
|
||||||
bool ignoreLocation( const Stmt* stmt );
|
bool ignoreLocation( const Stmt* stmt );
|
||||||
|
@@ -37,7 +37,8 @@ static int pluginCount = 0;
|
|||||||
static bool pluginObjectsCreated = false;
|
static bool pluginObjectsCreated = false;
|
||||||
|
|
||||||
PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args )
|
PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args )
|
||||||
: rewriter( context.getSourceManager(), context.getLangOpts())
|
: context( context )
|
||||||
|
, rewriter( context.getSourceManager(), context.getLangOpts())
|
||||||
{
|
{
|
||||||
bool wasCreated = false;
|
bool wasCreated = false;
|
||||||
for( int i = 0;
|
for( int i = 0;
|
||||||
@@ -60,11 +61,7 @@ PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args
|
|||||||
}
|
}
|
||||||
pluginObjectsCreated = true;
|
pluginObjectsCreated = true;
|
||||||
if( !args.empty() && !wasCreated )
|
if( !args.empty() && !wasCreated )
|
||||||
{
|
report( DiagnosticsEngine::Fatal, "unknown plugin tool %0 [loplugin]" ) << args.front();
|
||||||
DiagnosticsEngine& diag = context.getDiagnostics();
|
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Fatal,
|
|
||||||
"unknown plugin tool %0 [loplugin]" )) << args.front();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginHandler::~PluginHandler()
|
PluginHandler::~PluginHandler()
|
||||||
@@ -87,6 +84,11 @@ void PluginHandler::registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ),
|
|||||||
++pluginCount;
|
++pluginCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
|
||||||
|
{
|
||||||
|
return Plugin::report( level, message, context, loc );
|
||||||
|
}
|
||||||
|
|
||||||
void PluginHandler::HandleTranslationUnit( ASTContext& context )
|
void PluginHandler::HandleTranslationUnit( ASTContext& context )
|
||||||
{
|
{
|
||||||
if( context.getDiagnostics().hasErrorOccurred())
|
if( context.getDiagnostics().hasErrorOccurred())
|
||||||
@@ -103,7 +105,6 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
|
|||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
const FileEntry* e = context.getSourceManager().getFileEntryForID( it->first );
|
const FileEntry* e = context.getSourceManager().getFileEntryForID( it->first );
|
||||||
DiagnosticsEngine& diag = context.getDiagnostics();
|
|
||||||
/* Check where the file actually is, and warn about cases where modification
|
/* Check where the file actually is, and warn about cases where modification
|
||||||
most probably doesn't matter (generated files in workdir).
|
most probably doesn't matter (generated files in workdir).
|
||||||
The order here is important, as OUTDIR and WORKDIR are often in SRCDIR/BUILDDIR,
|
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())
|
if( modifyFile.empty())
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
|
report( DiagnosticsEngine::Warning, "modified source in solver/ : %0 [loplugin]" ) << e->getName();
|
||||||
"modified source in solver/ : %0 [loplugin]" )) << e->getName();
|
|
||||||
}
|
}
|
||||||
else if( strncmp( e->getName(), WORKDIR, strlen( WORKDIR )) == 0 )
|
else if( strncmp( e->getName(), WORKDIR, strlen( WORKDIR )) == 0 )
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
|
report( DiagnosticsEngine::Warning, "modified source in workdir/ : %0 [loplugin]" ) << e->getName();
|
||||||
"modified source in workdir/ : %0 [loplugin]" )) << e->getName();
|
|
||||||
else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR, strlen( BUILDDIR )) == 0 )
|
else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR, strlen( BUILDDIR )) == 0 )
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
|
report( DiagnosticsEngine::Warning, "modified source in build dir : %0 [loplugin]" ) << e->getName();
|
||||||
"modified source in build dir : %0 [loplugin]" )) << e->getName();
|
|
||||||
else if( strncmp( e->getName(), SRCDIR, strlen( SRCDIR )) == 0 )
|
else if( strncmp( e->getName(), SRCDIR, strlen( SRCDIR )) == 0 )
|
||||||
; // ok
|
; // ok
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Warning,
|
report( DiagnosticsEngine::Warning, "modified source in unknown location, not modifying : %0 [loplugin]" )
|
||||||
"modified source in unknown location, not modifying : %0 [loplugin]" )) << e->getName();
|
<< e->getName();
|
||||||
continue; // --->
|
continue; // --->
|
||||||
}
|
}
|
||||||
if( modifyFile.empty())
|
if( modifyFile.empty())
|
||||||
@@ -159,8 +157,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
|
|||||||
ostream.clear_error();
|
ostream.clear_error();
|
||||||
unlink( filename );
|
unlink( filename );
|
||||||
if( !ok )
|
if( !ok )
|
||||||
diag.Report( diag.getCustomDiagID( DiagnosticsEngine::Error,
|
report( DiagnosticsEngine::Error, "cannot write modified source to %0 (%1) [loplugin]" ) << modifyFile << error;
|
||||||
"cannot write modified source to %0 (%1) [loplugin]" )) << modifyFile << error;
|
|
||||||
delete[] filename;
|
delete[] filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,8 @@ class PluginHandler
|
|||||||
virtual void HandleTranslationUnit( ASTContext& context );
|
virtual void HandleTranslationUnit( ASTContext& context );
|
||||||
static void registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ), const char* optionName, bool isRewriter );
|
static void registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ), const char* optionName, bool isRewriter );
|
||||||
private:
|
private:
|
||||||
|
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
|
||||||
|
ASTContext& context;
|
||||||
Rewriter rewriter;
|
Rewriter rewriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -119,10 +119,8 @@ bool PostfixIncrementFix::canChangePostfixToPrefix( const CXXOperatorCallExpr* o
|
|||||||
return canChangeInConditionStatement( op, dyn_cast< ForStmt >( parents[ parent_pos ] )->getCond(),
|
return canChangeInConditionStatement( op, dyn_cast< ForStmt >( parents[ parent_pos ] )->getCond(),
|
||||||
parents, parent_pos );
|
parents, parent_pos );
|
||||||
default:
|
default:
|
||||||
DiagnosticsEngine& diag = context.getDiagnostics();
|
report( DiagnosticsEngine::Fatal, "cannot analyze operator++ (plugin needs fixing) [loplugin]",
|
||||||
unsigned diagid = diag.getCustomDiagID( DiagnosticsEngine::Fatal,
|
op->getLocStart()) << parents[ parent_pos ]->getSourceRange();
|
||||||
"cannot analyze operator++ (plugin needs fixing) [loplugin]" );
|
|
||||||
diag.Report( op->getLocStart(), diagid ) << parents[ parent_pos ]->getSourceRange();
|
|
||||||
// parents[ parent_pos ]->dump();
|
// parents[ parent_pos ]->dump();
|
||||||
// parents[ std::max( parent_pos - 3, 0 ) ]->dump();
|
// parents[ std::max( parent_pos - 3, 0 ) ]->dump();
|
||||||
return false;
|
return false;
|
||||||
@@ -157,10 +155,8 @@ bool PostfixIncrementFix::shouldDoChange( const Expr* operand )
|
|||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
DiagnosticsEngine& diag = context.getDiagnostics();
|
report( DiagnosticsEngine::Fatal, "cannot analyze operator++ (plugin needs fixing) [loplugin]",
|
||||||
unsigned diagid = diag.getCustomDiagID( DiagnosticsEngine::Fatal,
|
expr->getLocStart()) << operand->getSourceRange();
|
||||||
"cannot analyze operator++ (plugin needs fixing) [loplugin]" );
|
|
||||||
diag.Report( expr->getLocStart(), diagid ) << operand->getSourceRange();
|
|
||||||
expr->dump();
|
expr->dump();
|
||||||
operand->dump();
|
operand->dump();
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user