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

Fariborz Jahanian fjahanian at apple.com
Tue Jan 5 11:21:35 PST 2010


Author: fjahanian
Date: Tue Jan  5 13:21:35 2010
New Revision: 92755

URL: http://llvm.org/viewvc/llvm-project?rev=92755&view=rev
Log:
API support for __block variables which are also __weak.


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=92755&r1=92754&r2=92755&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue Jan  5 13:21:35 2010
@@ -603,8 +603,10 @@
     Preamble += "#undef __OBJC_RW_STATICIMPORT\n";
     Preamble += "#define __attribute__(X)\n";
   }
-  else
+  else {
     Preamble += "#define __block\n";
+    Preamble += "#define __weak\n";
+  }
 }
 
 
@@ -4461,7 +4463,8 @@
 ///
 ///
 void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
-  int flag;
+  int flag = 0;
+  int isa = 0;
   SourceLocation DeclLoc = ND->getTypeSpecStartLoc();
   const char *startBuf = SM->getCharacterData(DeclLoc);
   SourceLocation X = ND->getLocEnd();
@@ -4491,6 +4494,11 @@
   assert(CurFunctionDef && "RewriteByRefVar - CurFunctionDef is null");
   SourceLocation FunLocStart = CurFunctionDef->getTypeSpecStartLoc();
   InsertText(FunLocStart, ByrefType.c_str(), ByrefType.size());
+  if (Ty.isObjCGCWeak()) {
+    flag |= BLOCK_FIELD_IS_WEAK;
+    isa = 1;
+  }
+  
   if (HasCopyAndDispose) {
     flag = BLOCK_BYREF_CALLER;
     QualType Ty = ND->getType();
@@ -4514,8 +4522,9 @@
   Name = ND->getNameAsString();
   ByrefType = "struct __Block_byref_" + Name;
   if (!hasInit) {
-    ByrefType += " " + Name + " = ";
-    ByrefType += "{0, &" + Name + ", ";
+    ByrefType += " " + Name + " = {(void*)";
+    ByrefType += utostr(isa);
+    ByrefType += ", &" + Name + ", ";
     ByrefType += utostr(flags);
     ByrefType += ", ";
     ByrefType += "sizeof(struct __Block_byref_" + Name + ")";
@@ -4534,7 +4543,9 @@
     ByrefType += " " + Name;
     ReplaceText(DeclLoc, endBuf-startBuf, 
                 ByrefType.c_str(), ByrefType.size());
-    ByrefType = " = {0, &" + Name + ", ";
+    ByrefType = " = {(void*)";
+    ByrefType += utostr(isa);
+    ByrefType += ", &" + Name + ", ";
     ByrefType += utostr(flags);
     ByrefType += ", ";
     ByrefType += "sizeof(struct __Block_byref_" + Name + "), ";





More information about the cfe-commits mailing list