[cfe-commits] r150413 - /cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Mon Feb 13 12:59:03 PST 2012


Author: fjahanian
Date: Mon Feb 13 14:59:02 2012
New Revision: 150413

URL: http://llvm.org/viewvc/llvm-project?rev=150413&view=rev
Log:
objc modern translator. ivar offset symbols.


Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=150413&r1=150412&r2=150413&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Feb 13 14:59:02 2012
@@ -5473,6 +5473,39 @@
   }
 }
 
+static void Write_IvarOffsetVar(RewriteModernObjC &RewriteObj, 
+                                ASTContext *Context, std::string &Result, 
+                                ArrayRef<ObjCIvarDecl *> Ivars, 
+                                StringRef VarName, 
+                                StringRef ClassName) {
+  // FIXME. visibilty of offset symbols may have to be set; for Darwin
+  // this is what happens:
+  /**
+   if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
+       Ivar->getAccessControl() == ObjCIvarDecl::Package ||
+       Class->getVisibility() == HiddenVisibility)
+     Visibility shoud be: HiddenVisibility;
+   else
+     Visibility shoud be: DefaultVisibility;
+  */
+  
+  if (Ivars.size() > 0) {
+    Result += "\n";
+    for (unsigned i =0, e = Ivars.size(); i < e; i++) {
+      ObjCIvarDecl *IvarDecl = Ivars[i];
+      Result += "unsigned long int "; Result += VarName;
+      Result += ClassName; Result += "_";
+      Result += IvarDecl->getName(); 
+      Result += " __attribute__ ((used, section (\"__DATA,__objc_ivar\")))";
+      Result += " = ";
+      Result += "__OFFSETOFIVAR__(struct ";
+      Result += ClassName;
+      Result += "_IMPL, "; 
+      Result += IvarDecl->getName(); Result += ");\n";
+    }
+  }
+}
+
 static void Write__ivar_list_t_initializer(RewriteModernObjC &RewriteObj,
                                            ASTContext *Context, std::string &Result,
                                            ArrayRef<ObjCIvarDecl *> Ivars,
@@ -5492,8 +5525,10 @@
         Result += "\t{{";
       else
         Result += "\t {";
-      // FIXME: // pointer to ivar offset location
-      Result += "(unsigned long int *)0, ";
+      
+      Result += "(unsigned long int *)&OBJC_IVAR_$_";
+      Result += ClassName; Result += "_"; Result += IvarDecl->getName();
+      Result += ", ";
       
       Result += "\""; Result += IvarDecl->getName(); Result += "\", ";
       std::string IvarTypeString, QuoteIvarTypeString;
@@ -5736,6 +5771,9 @@
     IVars.push_back(IVD);
   }
   
+  Write_IvarOffsetVar(*this, Context, Result, IVars, "OBJC_IVAR_$_", 
+                      CDecl->getNameAsString());
+  
   Write__ivar_list_t_initializer(*this, Context, Result, IVars, 
                                  "_OBJC_INSTANCE_VARIABLES_",
                                  CDecl->getNameAsString());





More information about the cfe-commits mailing list