[cfe-commits] r94724 - in /cfe/trunk: include/clang/Rewrite/Rewriter.h lib/Frontend/RewriteObjC.cpp lib/Rewrite/Rewriter.cpp test/Rewriter/rewrite-nested-ivar.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Jan 27 17:41:21 PST 2010
Author: fjahanian
Date: Wed Jan 27 19:41:20 2010
New Revision: 94724
URL: http://llvm.org/viewvc/llvm-project?rev=94724&view=rev
Log:
Fixes a rewrite bug rewriting nested ivars reference.
(Radar 7583971).
Added:
cfe/trunk/test/Rewriter/rewrite-nested-ivar.mm
Modified:
cfe/trunk/include/clang/Rewrite/Rewriter.h
cfe/trunk/lib/Frontend/RewriteObjC.cpp
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=94724&r1=94723&r2=94724&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Wed Jan 27 19:41:20 2010
@@ -190,7 +190,7 @@
/// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty
/// printer to generate the replacement code. This returns true if the input
/// could not be rewritten, or false if successful.
- bool ReplaceStmt(Stmt *From, Stmt *To);
+ bool ReplaceStmt(Stmt *From, Stmt *To, int Size=0);
/// getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
/// If no modification has been made to it, return null.
Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=94724&r1=94723&r2=94724&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Wed Jan 27 19:41:20 2010
@@ -167,7 +167,7 @@
virtual void HandleTranslationUnit(ASTContext &C);
- void ReplaceStmt(Stmt *Old, Stmt *New) {
+ void ReplaceStmt(Stmt *Old, Stmt *New, int Size=0) {
Stmt *ReplacingStmt = ReplacedNodes[Old];
if (ReplacingStmt)
@@ -177,7 +177,7 @@
return; // Used when rewriting the assignment of a property setter.
// If replacement succeeded or warning disabled return with no warning.
- if (!Rewrite.ReplaceStmt(Old, New)) {
+ if (!Rewrite.ReplaceStmt(Old, New, Size)) {
ReplacedNodes[Old] = New;
return;
}
@@ -1247,8 +1247,12 @@
// delete IV; leak for now, see RewritePropertySetter() usage for more info.
return ME;
}
-
- ReplaceStmt(IV->getBase(), PE);
+ // Get the old text, only to get its size.
+ std::string SStr;
+ llvm::raw_string_ostream S(SStr);
+ IV->getBase()->printPretty(S, *Context, 0, PrintingPolicy(LangOpts));
+ // Get the new text
+ ReplaceStmt(IV->getBase(), PE, S.str().size());
// Cannot delete IV->getBase(), since PE points to it.
// Replace the old base with the cast. This is important when doing
// embedded rewrites. For example, [newInv->_container addObject:0].
Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=94724&r1=94723&r2=94724&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Wed Jan 27 19:41:20 2010
@@ -207,9 +207,10 @@
/// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty
/// printer to generate the replacement code. This returns true if the input
/// could not be rewritten, or false if successful.
-bool Rewriter::ReplaceStmt(Stmt *From, Stmt *To) {
+bool Rewriter::ReplaceStmt(Stmt *From, Stmt *To, int Size) {
// Measaure the old text.
- int Size = getRangeSize(From->getSourceRange());
+ if (!Size)
+ Size = getRangeSize(From->getSourceRange());
if (Size == -1)
return true;
Added: cfe/trunk/test/Rewriter/rewrite-nested-ivar.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-ivar.mm?rev=94724&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-ivar.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-nested-ivar.mm Wed Jan 27 19:41:20 2010
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7583971
+
+
+ at interface NSURLResponse {
+ at public
+ NSURLResponse *InnerResponse;
+}
+ at end
+
+ at interface NSCachedURLResponseInternal
+{
+ @public
+ NSURLResponse *response;
+}
+ at end
+
+ at interface NSCachedURLResponse
+{
+ @private
+ NSCachedURLResponseInternal *_internal;
+}
+- (void) Meth;
+ at end
+
+ at implementation NSCachedURLResponse
+- (void) Meth {
+ _internal->response->InnerResponse = 0;
+ }
+ at end
+
+// CHECK-LP: ((struct NSURLResponse_IMPL *)((struct NSCachedURLResponseInternal_IMPL *)((struct NSCachedURLResponse_IMPL *)self)->_internal)->response)->InnerResponse
More information about the cfe-commits
mailing list