[cfe-commits] r49587 - in /cfe/trunk: include/clang/Rewrite/Rewriter.h lib/Rewrite/Rewriter.cpp

Chris Lattner sabre at nondot.org
Sat Apr 12 13:34:05 PDT 2008


Author: lattner
Date: Sat Apr 12 15:34:05 2008
New Revision: 49587

URL: http://llvm.org/viewvc/llvm-project?rev=49587&view=rev
Log:
remove ifdefs

Modified:
    cfe/trunk/include/clang/Rewrite/Rewriter.h
    cfe/trunk/lib/Rewrite/Rewriter.cpp

Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=49587&r1=49586&r2=49587&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Sat Apr 12 15:34:05 2008
@@ -23,8 +23,6 @@
 #include <string>
 #include "clang/Rewrite/DeltaTree.h"
 
-//#define USE_VECTOR 1
-
 namespace clang {
   class SourceManager;
   class Rewriter;
@@ -38,13 +36,9 @@
 /// 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<SourceDelta> 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 @@
   /// 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);

Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=49587&r1=49586&r2=49587&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Sat Apr 12 15:34:05 2008
@@ -19,83 +19,6 @@
 #include <sstream>
 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;





More information about the cfe-commits mailing list