diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2013-05-06 16:41:27 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-05-06 16:51:45 +0200 |
commit | 9cb21a33421b8531dd25f76cc757f0d7f0fcc5ee (patch) | |
tree | 965f79192055ad1bc7b40736cac575b3f0fddb4e /compilerplugins | |
parent | d870271c23b997c922ddf2672df8f69fd199eef7 (diff) |
check for double modifications in compiler plugins
A different way to do 1c0669af2f1f58e6431b5e489ac48a883e242ba7.
Sometimes one piece of code can be represented several times in the AST,
e.g. with default function arguments.
Change-Id: Ic7799fa0bd918a638bdc8ebef69e6aa91d355bdc
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 15 | ||||
-rw-r--r-- | compilerplugins/clang/plugin.hxx | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 85bd69625b09..4df8bac23d78 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -110,6 +110,9 @@ bool RewritePlugin::insertTextBefore( SourceLocation Loc, StringRef Str ) // given to this overload would not match afterwards. bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOptions opts ) { + if( removals.find( Start ) != removals.end()) + report( DiagnosticsEngine::Warning, "double code removal, possible plugin error", Start ); + removals.insert( Start ); if( opts.RemoveWholeStatement ) { SourceRange range( Start, Start.getLocWithOffset( Length - 1 )); @@ -125,6 +128,9 @@ bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOp bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts ) { + if( removals.find( range.getBegin()) != removals.end()) + report( DiagnosticsEngine::Warning, "double code removal, possible plugin error", range.getBegin()); + removals.insert( range.getBegin()); if( opts.RemoveWholeStatement ) { if( !adjustForWholeStatement( &range )) @@ -166,6 +172,9 @@ bool RewritePlugin::adjustForWholeStatement( SourceRange* range ) bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr ) { + if( OrigLength != 0 && removals.find( Start ) != removals.end()) + report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", Start ); + removals.insert( Start ); if( rewriter.ReplaceText( Start, OrigLength, NewStr )) return reportEditFailure( Start ); return true; @@ -173,6 +182,9 @@ bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, Stri bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr ) { + if( removals.find( range.getBegin()) != removals.end()) + report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin()); + removals.insert( range.getBegin()); if( rewriter.ReplaceText( range, NewStr )) return reportEditFailure( range.getBegin()); return true; @@ -180,6 +192,9 @@ bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr ) bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange ) { + if( removals.find( range.getBegin()) != removals.end()) + report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin()); + removals.insert( range.getBegin()); if( rewriter.ReplaceText( range, replacementRange )) return reportEditFailure( range.getBegin()); return true; diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index da336818cccb..9c9ce7b72f55 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -18,6 +18,7 @@ #include <clang/Basic/FileManager.h> #include <clang/Basic/SourceManager.h> #include <clang/Frontend/CompilerInstance.h> +#include <set> #if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 2 #include <clang/Rewrite/Rewriter.h> @@ -114,6 +115,7 @@ class RewritePlugin enum { isRewriter = true }; bool reportEditFailure( SourceLocation loc ); bool adjustForWholeStatement( SourceRange* range ); + set< SourceLocation > removals; }; /** |