summaryrefslogtreecommitdiff
path: root/lib/Tooling/Refactoring.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-08-27 15:44:26 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-08-27 15:44:26 +0000
commita778cde0ddf4c47a63786fb1067f25c1fbfcf19d (patch)
treec983bfcadd5aa652881f5128cd684d742b3bd38e /lib/Tooling/Refactoring.cpp
parentd36e46350b50907425bba0db1b3ddfb46cc1637f (diff)
Adding a vector version of clang::tooling::shiftedCodePosition().
During the transition of clang::tooling::Replacements from std::set to std::vector, functions such as clang::tooling::applyAllReplacements() have been duplicated to take a std::vector<Replacement>. Applying this same temporary duplication to clang::tooling::shiftedCodePosition(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189358 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Refactoring.cpp')
-rw-r--r--lib/Tooling/Refactoring.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp
index 7a8203f93d..b03fb50b38 100644
--- a/lib/Tooling/Refactoring.cpp
+++ b/lib/Tooling/Refactoring.cpp
@@ -203,6 +203,23 @@ unsigned shiftedCodePosition(const Replacements &Replaces, unsigned Position) {
return NewPosition;
}
+// FIXME: Remove this function when Replacements is implemented as std::vector
+// instead of std::set.
+unsigned shiftedCodePosition(const std::vector<Replacement> &Replaces,
+ unsigned Position) {
+ unsigned NewPosition = Position;
+ for (std::vector<Replacement>::const_iterator I = Replaces.begin(),
+ E = Replaces.end();
+ I != E; ++I) {
+ if (I->getOffset() >= Position)
+ break;
+ if (I->getOffset() + I->getLength() > Position)
+ NewPosition += I->getOffset() + I->getLength() - Position;
+ NewPosition += I->getReplacementText().size() - I->getLength();
+ }
+ return NewPosition;
+}
+
void deduplicate(std::vector<Replacement> &Replaces,
std::vector<Range> &Conflicts) {
if (Replaces.empty())