summaryrefslogtreecommitdiff
path: root/lib/Tooling/Core/Replacement.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-06-16 10:22:10 +0000
committerDaniel Jasper <djasper@google.com>2015-06-16 10:22:10 +0000
commit07074ae5b37e632c355214930f522a840a1f0157 (patch)
tree8e1a0ff77fd407226c4db41f50fc263026675ed2 /lib/Tooling/Core/Replacement.cpp
parent2e855badf1e8b8541b1ed7dcfbe86c9813088087 (diff)
downloadclang-07074ae5b37e632c355214930f522a840a1f0157.tar.gz
Tooling: When applying a set of replacements, do deletions before
insertions. It is unlikely to be the intention to delete parts of newly inserted code. To do so, changed sorting Replacements at the same offset to have decreasing length. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Core/Replacement.cpp')
-rw-r--r--lib/Tooling/Core/Replacement.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Tooling/Core/Replacement.cpp b/lib/Tooling/Core/Replacement.cpp
index 32e8e5bd6b..6d37a49db3 100644
--- a/lib/Tooling/Core/Replacement.cpp
+++ b/lib/Tooling/Core/Replacement.cpp
@@ -88,8 +88,13 @@ std::string Replacement::toString() const {
bool operator<(const Replacement &LHS, const Replacement &RHS) {
if (LHS.getOffset() != RHS.getOffset())
return LHS.getOffset() < RHS.getOffset();
+
+ // Apply longer replacements first, specifically so that deletions are
+ // executed before insertions. It is (hopefully) never the intention to
+ // delete parts of newly inserted code.
if (LHS.getLength() != RHS.getLength())
- return LHS.getLength() < RHS.getLength();
+ return LHS.getLength() > RHS.getLength();
+
if (LHS.getFilePath() != RHS.getFilePath())
return LHS.getFilePath() < RHS.getFilePath();
return LHS.getReplacementText() < RHS.getReplacementText();