[cfe-commits] r53858 - /cfe/trunk/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Mon Jul 21 11:26:02 PDT 2008


Author: snaroff
Date: Mon Jul 21 13:26:02 2008
New Revision: 53858

URL: http://llvm.org/viewvc/llvm-project?rev=53858&view=rev
Log:
RewriteObjC::RewriteObjCForCollectionStmt() needs to handle bodies with a single statement.
Fixes <rdar://problem/6084870> clang ObjC rewriter: for-in enumeration in 1 line produces output with error.


Modified:
    cfe/trunk/Driver/RewriteObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=53858&r1=53857&r2=53858&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Mon Jul 21 13:26:02 2008
@@ -1248,9 +1248,25 @@
   buf += elementName;
   buf += " = nil;\n";
   buf += "}\n";
+  
   // Insert all these *after* the statement body.
-  SourceLocation endBodyLoc = OrigEnd.getFileLocWithOffset(1);
-  InsertText(endBodyLoc, buf.c_str(), buf.size());
+  if (isa<CompoundStmt>(S->getBody())) {
+    SourceLocation endBodyLoc = OrigEnd.getFileLocWithOffset(1);
+    InsertText(endBodyLoc, buf.c_str(), buf.size());
+  } else {
+    /* Need to treat single statements specially. For example:
+     *
+     *     for (A *a in b) if (stuff()) break;
+     *     for (A *a in b) xxxyy;
+     *
+     * The following code simply scans ahead to the semi to find the actual end.
+     */
+    const char *stmtBuf = SM->getCharacterData(OrigEnd);
+    const char *semiBuf = strchr(stmtBuf, ';');
+    assert(semiBuf && "Can't find ';'");
+    SourceLocation endBodyLoc = OrigEnd.getFileLocWithOffset(semiBuf-stmtBuf+1);
+    InsertText(endBodyLoc, buf.c_str(), buf.size());
+  }
   Stmts.pop_back();
   ObjCBcLabelNo.pop_back();
   return 0;





More information about the cfe-commits mailing list