]> granicus.if.org Git - clang/commitdiff
Fix a bug steve noticed when handling nested rewrites. We now turn this:
authorChris Lattner <sabre@nondot.org>
Thu, 25 Oct 2007 17:17:34 +0000 (17:17 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 25 Oct 2007 17:17:34 +0000 (17:17 +0000)
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

into:

    NSAutoreleasePool * pool = objc_msgSend(objc_msgSend(objc_getClass("NSAutoreleasePool"), sel_getUid("alloc")), sel_getUid("init"));

instead of:

    NSAutoreleasePool * pool = objc_msgSend(objc_msgSend(objc_getClass("NSAutoreleasePool"), sel_getUid("alloc")), sel_getUid("init"))utoreleasePool"), sel_getUid("alloc")) init];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43347 91177308-0d34-0410-b5e6-96231b3b80d8

Rewrite/Rewriter.cpp

index 9e7d1b3143a778eaa6a41bef5a98ad5b4e998744..d4185648cc266f3074598852ba1f464b0e1bfac6 100644 (file)
@@ -159,11 +159,27 @@ int Rewriter::getRangeSize(SourceRange Range) const {
   if (StartFileID != EndFileID)
     return -1;
   
+  unsigned Delta;
+  
+  // If no edits have been made to this buffer, the delta between the range
+  // Is just the difference in offsets.
+  std::map<unsigned, RewriteBuffer>::const_iterator I =
+    RewriteBuffers.find(StartFileID);
+  if (I == RewriteBuffers.end()) {
+    Delta = EndOff-StartOff;
+  } else {
+    // Otherwise, subtracted the mapped offsets instead.
+    const RewriteBuffer &RB = I->second;
+    Delta = RB.getMappedOffset(EndOff, true);
+    Delta -= RB.getMappedOffset(StartOff);
+  }
+
+  
   // Adjust the end offset to the end of the last token, instead of being the
   // start of the last token.
-  EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr);
+  Delta += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr);
   
-  return EndOff-StartOff;
+  return Delta;
 }