From 77257889f5829144767c8a1d7fc18a929a377b5c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 12 Apr 2008 20:34:05 +0000 Subject: [PATCH] remove ifdefs git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49587 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Rewrite/Rewriter.h | 18 ++++---- lib/Rewrite/Rewriter.cpp | 77 -------------------------------- 2 files changed, 8 insertions(+), 87 deletions(-) diff --git a/include/clang/Rewrite/Rewriter.h b/include/clang/Rewrite/Rewriter.h index e141c79fc3..bb4e16a8e8 100644 --- a/include/clang/Rewrite/Rewriter.h +++ b/include/clang/Rewrite/Rewriter.h @@ -23,8 +23,6 @@ #include #include "clang/Rewrite/DeltaTree.h" -//#define USE_VECTOR 1 - namespace clang { class SourceManager; class Rewriter; @@ -38,13 +36,9 @@ namespace clang { /// locations after the insertion point have to be mapped. class RewriteBuffer { friend class Rewriter; -#ifdef USE_VECTOR /// Deltas - Keep track of all the deltas in the source code due to insertions - /// and deletions. These are kept in sorted order based on the FileLoc. - std::vector Deltas; -#else + /// and deletions. DeltaTree Deltas; -#endif /// Buffer - This is the actual buffer itself. Note that using a vector or /// string is a horribly inefficient way to do this, we should use a rope @@ -69,12 +63,16 @@ private: // Methods only usable by Rewriter. /// RewriteBuffer. If AfterInserts is true and if the OrigOffset indicates a /// position where text is inserted, the location returned will be after any /// inserted text at the position. - unsigned getMappedOffset(unsigned OrigOffset, bool AfterInserts = false)const; - + unsigned getMappedOffset(unsigned OrigOffset, + bool AfterInserts = false) const{ + return Deltas.getDeltaAt(OrigOffset+AfterInserts)+OrigOffset; + } /// AddDelta - When a change is made that shifts around the text buffer, this /// method is used to record that info. - void AddDelta(unsigned OrigOffset, int Change); + void AddDelta(unsigned OrigOffset, int Change) { + return Deltas.AddDelta(OrigOffset, Change); + } /// RemoveText - Remove the specified text. void RemoveText(unsigned OrigOffset, unsigned Size); diff --git a/lib/Rewrite/Rewriter.cpp b/lib/Rewrite/Rewriter.cpp index e3c27eaad1..1c1903cc40 100644 --- a/lib/Rewrite/Rewriter.cpp +++ b/lib/Rewrite/Rewriter.cpp @@ -19,83 +19,6 @@ #include using namespace clang; - -/// getMappedOffset - Given an offset into the original SourceBuffer that this -/// RewriteBuffer is based on, map it into the offset space of the -/// RewriteBuffer. -unsigned RewriteBuffer::getMappedOffset(unsigned OrigOffset, - bool AfterInserts) const { - unsigned ResultOffset = 0; -#if !defined(USE_VECTOR) - ResultOffset += Deltas.getDeltaAt(OrigOffset+AfterInserts); -#else - unsigned DeltaIdx = 0; - - // Move past any deltas that are relevant. - // FIXME: binary search. - for (; DeltaIdx != Deltas.size() && - Deltas[DeltaIdx].FileLoc < OrigOffset; ++DeltaIdx) - ResultOffset += Deltas[DeltaIdx].Delta; - - if (AfterInserts) - for (; DeltaIdx != Deltas.size() && - OrigOffset == Deltas[DeltaIdx].FileLoc; ++DeltaIdx) - ResultOffset += Deltas[DeltaIdx].Delta; -#endif - - // printf("Map: %d/%d -> %d\n", OrigOffset, AfterInserts, ResultOffset); - return ResultOffset+OrigOffset; -} - -/// AddDelta - When a change is made that shifts around the text buffer, this -/// method is used to record that info. -void RewriteBuffer::AddDelta(unsigned OrigOffset, int Change) { - // printf("AddDelta: %d/%d\n", OrigOffset, Change); -#if !defined(USE_VECTOR) - return Deltas.AddDelta(OrigOffset, Change); -#else - assert(Change != 0 && "Not changing anything"); - unsigned DeltaIdx = 0; - - // Skip over any unrelated deltas. - for (; DeltaIdx != Deltas.size() && - Deltas[DeltaIdx].FileLoc < OrigOffset; ++DeltaIdx) - ; - - // If there is no a delta for this offset, insert a new delta record. - if (DeltaIdx == Deltas.size() || OrigOffset != Deltas[DeltaIdx].FileLoc) { - // If this is a removal, check to see if this can be folded into - // a delta at the end of the deletion. For example, if we have: - // ABCXDEF (X inserted after C) and delete C, we want to end up with no - // delta because X basically replaced C. - if (Change < 0 && DeltaIdx != Deltas.size() && - OrigOffset-Change == Deltas[DeltaIdx].FileLoc) { - // Adjust the start of the delta to be the start of the deleted region. - Deltas[DeltaIdx].FileLoc += Change; - Deltas[DeltaIdx].Delta += Change; - - // If the delta becomes a noop, remove it. - if (Deltas[DeltaIdx].Delta == 0) - Deltas.erase(Deltas.begin()+DeltaIdx); - return; - } - - // Otherwise, create an entry and return. - Deltas.insert(Deltas.begin()+DeltaIdx, - SourceDelta::get(OrigOffset, Change)); - return; - } - - // Otherwise, we found a delta record at this offset, adjust it. - Deltas[DeltaIdx].Delta += Change; - - // If it is now dead, remove it. - if (Deltas[DeltaIdx].Delta == 0) - Deltas.erase(Deltas.begin()+DeltaIdx); -#endif -} - - void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size) { // Nothing to remove, exit early. if (Size == 0) return; -- 2.40.0