[cfe-commits] r129300 - in /cfe/trunk: include/clang/Rewrite/Rewriter.h lib/Rewrite/RewriteObjC.cpp lib/Rewrite/Rewriter.cpp test/Rewriter/rewrite-block-literal-1.mm
Fariborz Jahanian
fjahanian at apple.com
Mon Apr 11 14:17:02 PDT 2011
Author: fjahanian
Date: Mon Apr 11 16:17:02 2011
New Revision: 129300
URL: http://llvm.org/viewvc/llvm-project?rev=129300&view=rev
Log:
Fixup more objc rwriter bug having to do with
rewriting of blocks which have objective-c
stuff which need be rewritten as well. // rdar://9254348
Modified:
cfe/trunk/include/clang/Rewrite/Rewriter.h
cfe/trunk/lib/Rewrite/RewriteObjC.cpp
cfe/trunk/lib/Rewrite/Rewriter.cpp
cfe/trunk/test/Rewriter/rewrite-block-literal-1.mm
Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=129300&r1=129299&r2=129300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Mon Apr 11 16:17:02 2011
@@ -245,6 +245,10 @@
/// 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);
+
+ /// ConvertToString converts statement 'From' to a string using the
+ /// pretty pronter.
+ std::string ConvertToString(Stmt *From);
/// getEditBuffer - This is like getRewriteBufferFor, but always returns a
/// buffer, and allows you to write on it directly. This is useful if you
Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=129300&r1=129299&r2=129300&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Mon Apr 11 16:17:02 2011
@@ -5519,27 +5519,34 @@
for (Stmt::child_range CI = S->children(); CI; ++CI)
if (*CI) {
Stmt *newStmt;
- Stmt *S = (*CI);
- if (ObjCIvarRefExpr *IvarRefExpr = dyn_cast<ObjCIvarRefExpr>(S)) {
+ Stmt *ChildStmt = (*CI);
+ if (ObjCIvarRefExpr *IvarRefExpr = dyn_cast<ObjCIvarRefExpr>(ChildStmt)) {
Expr *OldBase = IvarRefExpr->getBase();
bool replaced = false;
- newStmt = RewriteObjCNestedIvarRefExpr(S, replaced);
+ newStmt = RewriteObjCNestedIvarRefExpr(ChildStmt, replaced);
if (replaced) {
if (ObjCIvarRefExpr *IRE = dyn_cast<ObjCIvarRefExpr>(newStmt))
ReplaceStmt(OldBase, IRE->getBase());
else
- ReplaceStmt(S, newStmt);
+ ReplaceStmt(ChildStmt, newStmt);
}
}
else
- newStmt = RewriteFunctionBodyOrGlobalInitializer(S);
- if (newStmt)
- *CI = newStmt;
+ newStmt = RewriteFunctionBodyOrGlobalInitializer(ChildStmt);
+ if (newStmt) {
+ if (Expr *PropOrImplicitRefExpr = dyn_cast<Expr>(ChildStmt))
+ if (PropSetters[PropOrImplicitRefExpr] == S) {
+ S = newStmt;
+ newStmt = 0;
+ }
+ if (newStmt)
+ *CI = newStmt;
+ }
// If dealing with an assignment with LHS being a property reference
// expression, the entire assignment tree is rewritten into a property
// setter messaging. This involvs the RHS too. Do not attempt to rewrite
// RHS again.
- if (Expr *Exp = dyn_cast<Expr>(S))
+ if (Expr *Exp = dyn_cast<Expr>(ChildStmt))
if (isa<ObjCPropertyRefExpr>(Exp)) {
if (PropSetters[Exp]) {
++CI;
@@ -5565,7 +5572,7 @@
PropParentMap = 0;
ImportedLocalExternalDecls.clear();
// Now we snarf the rewritten text and stash it away for later use.
- std::string Str = Rewrite.getRewrittenText(BE->getSourceRange());
+ std::string Str = Rewrite.ConvertToString(BE->getBody());
RewrittenBlockExprs[BE] = Str;
Stmt *blockTranscribed = SynthBlockInitExpr(BE, InnerBlockDeclRefs);
Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=129300&r1=129299&r2=129300&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Mon Apr 11 16:17:02 2011
@@ -303,3 +303,10 @@
ReplaceText(From->getLocStart(), Size, Str);
return false;
}
+
+std::string Rewriter::ConvertToString(Stmt *From) {
+ std::string SStr;
+ llvm::raw_string_ostream S(SStr);
+ From->printPretty(S, 0, PrintingPolicy(*LangOpts));
+ return SStr;
+}
Modified: cfe/trunk/test/Rewriter/rewrite-block-literal-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-literal-1.mm?rev=129300&r1=129299&r2=129300&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-literal-1.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-literal-1.mm Mon Apr 11 16:17:02 2011
@@ -16,9 +16,14 @@
@implementation CoreDAVTaskGroup
- (void)_finishInitialSync {
CoreDAVTaskGroup *folderPost;
- [folderPost setCompletionBlock : (^{
- self.IVAR = 0;
- })];
+ folderPost.completionBlock = ^{
+ self.IVAR = 0;
+ [self _finishInitialSync];
+ };
+
+ [folderPost setCompletionBlock : (^{
+ self.IVAR = 0;
+ })];
}
@dynamic IVAR;
- (void) setCompletionBlock : (BLOCK_TYPE) arg {}
More information about the cfe-commits
mailing list