summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx15
-rw-r--r--compilerplugins/clang/plugin.hxx2
2 files changed, 15 insertions, 2 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 75d55782009c..85bd69625b09 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -105,9 +105,22 @@ bool RewritePlugin::insertTextBefore( SourceLocation Loc, StringRef Str )
return true;
}
+// These two removeText() overloads should not be merged into one, as the SourceRange
+// one uses a token range (which counts token length for some reason), so exact length
+// given to this overload would not match afterwards.
bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOptions opts )
{
- return removeText( SourceRange( Start, Start.getLocWithOffset( Length )), opts );
+ if( opts.RemoveWholeStatement )
+ {
+ SourceRange range( Start, Start.getLocWithOffset( Length - 1 ));
+ if( !adjustForWholeStatement( &range ))
+ return reportEditFailure( Start );
+ Start = range.getBegin();
+ Length = range.getEnd().getRawEncoding() - range.getBegin().getRawEncoding();
+ }
+ if( rewriter.RemoveText( Start, Length, opts ))
+ return reportEditFailure( Start );
+ return true;
}
bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts )
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index f564ca4700b3..da336818cccb 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -101,7 +101,7 @@ class RewritePlugin
bool insertTextAfterToken( SourceLocation Loc, StringRef Str );
bool insertTextBefore( SourceLocation Loc, StringRef Str );
bool removeText( SourceLocation Start, unsigned Length, RewriteOptions opts = RewriteOptions());
- // CharSourceRange not supported, unless really needed, as it makes RemoveSemicolon more complicated
+ // CharSourceRange not supported, unless really needed, as it needs handling for RemoveWholeStatement.
//bool removeText( CharSourceRange range, RewriteOptions opts = RewriteOptions());
bool removeText( SourceRange range, RewriteOptions opts = RewriteOptions());
bool replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr );