diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2013-08-14 18:43:01 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-08-21 15:08:16 +0200 |
commit | 4f60eb885a5480832d1148205a08eafc6c50aa39 (patch) | |
tree | 89089f793bb57ebe94afd72f5aeb9d9daff612fe /compilerplugins/clang | |
parent | 0809d7d79295403c6b012a59b712dddb2ce92104 (diff) |
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
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 7 | ||||
-rw-r--r-- | compilerplugins/clang/plugin.hxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/pointertobool.cxx | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 50ec0a9ced1b..65333025e576 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -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; diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index 4fd766d8d2a0..24a6c3b7a2f3 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -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 ); diff --git a/compilerplugins/clang/pointertobool.cxx b/compilerplugins/clang/pointertobool.cxx index 238e0180b7e8..e0c69ff98099 100644 --- a/compilerplugins/clang/pointertobool.cxx +++ b/compilerplugins/clang/pointertobool.cxx @@ -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" ); |