Kaydet (Commit) 4f60eb88 authored tarafından Luboš Luňák's avatar Luboš Luňák

helper for getting location after current token

Given that locations often point to a (start of) token, even if it's
e.g. getLocEnd(), this should be very useful.

Change-Id: I266e4c0a234262e99158c8f495b631f54f8a5608
üst 0809d7d7
......@@ -145,6 +145,11 @@ void Plugin::buildParents( CompilerInstance& compiler )
builder.TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
SourceLocation Plugin::locationAfterToken( SourceLocation location )
{
return Lexer::getLocForEndOfToken( location, 0, compiler.getSourceManager(), compiler.getLangOpts());
}
/////
RewritePlugin::RewritePlugin( CompilerInstance& compiler, Rewriter& rewriter )
......@@ -222,7 +227,7 @@ bool RewritePlugin::adjustRangeForOptions( CharSourceRange* range, RewriteOption
return false;
SourceLocation locationEnd = range->getEnd();
if( range->isTokenRange())
locationEnd = Lexer::getLocForEndOfToken( locationEnd, 0, compiler.getSourceManager(), compiler.getLangOpts());
locationEnd = locationAfterToken( locationEnd );
const char* endBuf = SM.getCharacterData( locationEnd, &invalid );
if( invalid )
return false;
......
......@@ -51,6 +51,8 @@ class Plugin
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
static DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
// Returns location right after the end of the token that starts at the given location.
SourceLocation locationAfterToken( SourceLocation location );
protected:
bool ignoreLocation( SourceLocation loc );
bool ignoreLocation( const Decl* decl );
......
......@@ -73,7 +73,7 @@ bool PointerToBool::VisitImplicitCastExpr( const ImplicitCastExpr* expr )
report( DiagnosticsEngine::Warning,
"pointer %0 implicitly converted to bool", expr->getLocStart())
<< expr->getSubExpr()->getType() << expr->getSourceRange();
SourceLocation endOfExpression = Lexer::getLocForEndOfToken( expr->getLocEnd(), 0, compiler.getSourceManager(), compiler.getLangOpts());
SourceLocation endOfExpression = locationAfterToken( expr->getLocEnd());
report( DiagnosticsEngine::Note,
"explicitly compare to null pointer to silence this warning", endOfExpression )
<< FixItHint::CreateInsertion( endOfExpression, " != NULL" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment