[cfe-commits] r92007 - /cfe/trunk/lib/Frontend/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Wed Dec 23 09:24:34 PST 2009


Author: snaroff
Date: Wed Dec 23 11:24:33 2009
New Revision: 92007

URL: http://llvm.org/viewvc/llvm-project?rev=92007&view=rev
Log:
Add support for handling initializers in RewriteObjC::RewriteByRefVar().

As the FIXME indicates, RewriteByRefVar() won't work for multiple declarators (in general). I've discussed this with Fariborz and he is aware of the limitation.

Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=92007&r1=92006&r2=92007&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Wed Dec 23 11:24:33 2009
@@ -4392,11 +4392,22 @@
     ByrefType += "0, ";
     ByrefType += "sizeof(struct __Block_byref_" + Name + "), ";
     InsertText(startLoc, ByrefType.c_str(), ByrefType.size());
-#if 0
-    ByrefType = "};\n";
-    SourceLocation endLoc = ND->getInit()->getLocEnd();
-    InsertText(startLoc, ByrefType.c_str(), ByrefType.size());
-#endif
+    
+    // Complete the newly synthesized compound expression by inserting a right
+    // curly brace before the end of the declaration.
+    // FIXME: This approach avoids rewriting the initializer expression. It
+    // also assumes there is only one declarator. For example, the following
+    // isn't currently supported by this routine (in general):
+    // 
+    // double __block BYREFVAR = 1.34, BYREFVAR2 = 1.37;
+    //
+    const char *startBuf = SM->getCharacterData(startLoc);
+    const char *semiBuf = strchr(startBuf, ';');
+    assert((*semiBuf == ';') && "RewriteByRefVar: can't find ';'");
+    SourceLocation semiLoc =
+      startLoc.getFileLocWithOffset(semiBuf-startBuf);
+
+    InsertText(semiLoc, "}", 1);
   }
   return;
 }





More information about the cfe-commits mailing list