Stmt *RewriteObjCCatchStmt(ObjCAtCatchStmt *S);
Stmt *RewriteObjCFinallyStmt(ObjCAtFinallyStmt *S);
Stmt *RewriteObjCThrowStmt(ObjCAtThrowStmt *S);
- Stmt *RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S);
+ Stmt *RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
+ SourceLocation OrigEnd);
CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD,
Expr **args, unsigned nargs);
Stmt *SynthMessageExpr(ObjCMessageExpr *Exp);
ObjCBcLabelNo.push_back(++BcLabelCount);
}
- // Otherwise, just rewrite all children.
+ SourceLocation OrigStmtEnd = S->getLocEnd();
+
+ // Start by rewriting all children.
for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
CI != E; ++CI)
if (*CI) {
if (ObjCForCollectionStmt *StmtForCollection =
dyn_cast<ObjCForCollectionStmt>(S))
- return RewriteObjCForCollectionStmt(StmtForCollection);
+ return RewriteObjCForCollectionStmt(StmtForCollection, OrigStmtEnd);
if (BreakStmt *StmtBreakStmt =
dyn_cast<BreakStmt>(S))
return RewriteBreakStmt(StmtBreakStmt);
/// elem = nil;
/// }
///
-Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) {
+Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
+ SourceLocation OrigEnd) {
assert(!Stmts.empty() && "ObjCForCollectionStmt - Statement stack empty");
assert(isa<ObjCForCollectionStmt>(Stmts.back()) &&
"ObjCForCollectionStmt Statement stack mismatch");
buf += " = nil;\n";
buf += "}\n";
// Insert all these *after* the statement body.
- SourceLocation endBodyLoc = S->getBody()->getLocEnd();
- const char *endBodyBuf = SM->getCharacterData(endBodyLoc)+1;
- endBodyLoc = startLoc.getFileLocWithOffset(endBodyBuf-startBuf);
+ SourceLocation endBodyLoc = OrigEnd.getFileLocWithOffset(1);
Rewrite.InsertText(endBodyLoc, buf.c_str(), buf.size());
Stmts.pop_back();
ObjCBcLabelNo.pop_back();
-
return 0;
}
--- /dev/null
+// RUN: clang %s -rewrite-test
+// rdar://5716356
+// FIXME: Should be able to pipe into clang, but code is not
+// yet correct for other reasons: rdar://5716940
+
+@class NSNotification;
+@class NSMutableArray;
+
+void foo(NSMutableArray *notificationArray, id X) {
+ for (NSNotification *notification in notificationArray)
+ [X postNotification:notification];
+}
+