summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/plugin.cxx15
-rw-r--r--compilerplugins/clang/plugin.hxx2
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;
};
/**