summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-05-03 14:08:48 +0200
committerLuboš Luňák <l.lunak@suse.cz>2013-05-06 16:49:36 +0200
commit6f16cfb5a661c0a4b13ed18c9246d8830ca118b5 (patch)
tree397c6ffc4666da3bdd24bb4e8380bb0fa1f0759a
parent0bac488a1b9da8812f7b888bd12d774ef75379ba (diff)
Fix handling range in removeText().
Turns out removeText( SourceRange ) treats it as a token range, so it's not always character-exact if used for removal of only several characters from a token (e.g. an identifier). Change-Id: I0223d52da90f9535d9ef1d48b0f56d69131536c8
-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 );