[cfe-commits] r43347 - /cfe/trunk/Rewrite/Rewriter.cpp
Chris Lattner
sabre at nondot.org
Thu Oct 25 10:17:34 PDT 2007
Author: lattner
Date: Thu Oct 25 12:17:34 2007
New Revision: 43347
URL: http://llvm.org/viewvc/llvm-project?rev=43347&view=rev
Log:
Fix a bug steve noticed when handling nested rewrites. We now turn this:
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];
Modified:
cfe/trunk/Rewrite/Rewriter.cpp
Modified: cfe/trunk/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Rewrite/Rewriter.cpp?rev=43347&r1=43346&r2=43347&view=diff
==============================================================================
--- cfe/trunk/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/Rewrite/Rewriter.cpp Thu Oct 25 12:17:34 2007
@@ -159,11 +159,27 @@
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;
}
More information about the cfe-commits
mailing list