summaryrefslogtreecommitdiffstats
path: root/lib/Tooling
diff options
context:
space:
mode:
authorArtem Belevich <tra@google.com>2016-09-14 23:03:06 +0000
committerArtem Belevich <tra@google.com>2016-09-14 23:03:06 +0000
commite119918940e135d30c11a07061dd3b0d516c3c90 (patch)
tree8a9b13bf987ba50e5aeb0be798e2ab4679c7262d /lib/Tooling
parent19dd934f97ab1a5fffc068eb0ade5afdafb46ea7 (diff)
Revert r281457 "Supports adding insertion around non-insertion replacements."
Commit was breaking our internal tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281557 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling')
-rw-r--r--lib/Tooling/Core/Replacement.cpp44
1 files changed, 11 insertions, 33 deletions
diff --git a/lib/Tooling/Core/Replacement.cpp b/lib/Tooling/Core/Replacement.cpp
index d74c56f947..b257f0f137 100644
--- a/lib/Tooling/Core/Replacement.cpp
+++ b/lib/Tooling/Core/Replacement.cpp
@@ -137,14 +137,6 @@ void Replacement::setFromSourceRange(const SourceManager &Sources,
ReplacementText);
}
-llvm::Error makeConflictReplacementsError(const Replacement &New,
- const Replacement &Existing) {
- return llvm::make_error<llvm::StringError>(
- "New replacement:\n" + New.toString() +
- "\nconflicts with existing replacement:\n" + Existing.toString(),
- llvm::inconvertibleErrorCode());
-}
-
llvm::Error Replacements::add(const Replacement &R) {
// Check the file path.
if (!Replaces.empty() && R.getFilePath() != Replaces.begin()->getFilePath())
@@ -171,22 +163,11 @@ llvm::Error Replacements::add(const Replacement &R) {
// entries that start at the end can still be conflicting if R is an
// insertion.
auto I = Replaces.lower_bound(AtEnd);
- // If `I` starts at the same offset as `R`, `R` must be an insertion.
- if (I != Replaces.end() && R.getOffset() == I->getOffset()) {
- assert(R.getLength() == 0);
- // `I` is also an insertion, `R` and `I` conflict.
- if (I->getLength() == 0)
- return makeConflictReplacementsError(R, *I);
- // Insertion `R` is adjacent to a non-insertion replacement `I`, so they
- // are order-independent. It is safe to assume that `R` will not conflict
- // with any replacement before `I` since all replacements before `I` must
- // either end before `R` or end at `R` but has length > 0 (if the
- // replacement before `I` is an insertion at `R`, it would have been `I`
- // since it is a lower bound of `AtEnd` and ordered before the current `I`
- // in the set).
- Replaces.insert(R);
- return llvm::Error::success();
- }
+ // If it starts at the same offset as R (can only happen if R is an
+ // insertion), we have a conflict. In that case, increase I to fall through
+ // to the conflict check.
+ if (I != Replaces.end() && R.getOffset() == I->getOffset())
+ ++I;
// I is the smallest iterator whose entry cannot overlap.
// If that is begin(), there are no overlaps.
@@ -197,19 +178,16 @@ llvm::Error Replacements::add(const Replacement &R) {
--I;
// If the previous entry does not overlap, we know that entries before it
// can also not overlap.
- if (!Range(R.getOffset(), R.getLength())
+ if (R.getOffset() != I->getOffset() &&
+ !Range(R.getOffset(), R.getLength())
.overlapsWith(Range(I->getOffset(), I->getLength()))) {
- // If `R` and `I` do not have the same offset, it is safe to add `R` since
- // it must come after `I`. Otherwise:
- // - If `R` is an insertion, `I` must not be an insertion since it would
- // have come after `AtEnd` if it has length 0.
- // - If `R` is not an insertion, `I` must be an insertion; otherwise, `R`
- // and `I` would have overlapped.
- // In either case, we can safely insert `R`.
Replaces.insert(R);
return llvm::Error::success();
}
- return makeConflictReplacementsError(R, *I);
+ return llvm::make_error<llvm::StringError>(
+ "New replacement:\n" + R.toString() +
+ "\nconflicts with existing replacement:\n" + I->toString(),
+ llvm::inconvertibleErrorCode());
}
namespace {