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

Fariborz Jahanian fjahanian at apple.com
Mon Feb 13 13:34:45 PST 2012


Author: fjahanian
Date: Mon Feb 13 15:34:45 2012
New Revision: 150415

URL: http://llvm.org/viewvc/llvm-project?rev=150415&view=rev
Log:
modern objc translator. More ivar rewrite work.


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=150415&r1=150414&r2=150415&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Feb 13 15:34:45 2012
@@ -5473,8 +5473,7 @@
   }
 }
 
-static void Write_IvarOffsetVar(RewriteModernObjC &RewriteObj, 
-                                ASTContext *Context, std::string &Result, 
+static void Write_IvarOffsetVar(std::string &Result, 
                                 ArrayRef<ObjCIvarDecl *> Ivars, 
                                 StringRef VarName, 
                                 StringRef ClassName) {
@@ -5489,15 +5488,20 @@
      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 += "\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 += " = ";
+    if (IvarDecl->isBitField()) {
+      // FIXME: The hack below doesn't work for bitfields. For now, we simply
+      // place all bitfields at offset 0.
+      Result += "0;\n";
+    }
+    else {
       Result += "__OFFSETOFIVAR__(struct ";
       Result += ClassName;
       Result += "_IMPL, "; 
@@ -5512,6 +5516,8 @@
                                            StringRef VarName,
                                            StringRef ClassName) {
   if (Ivars.size() > 0) {
+    Write_IvarOffsetVar(Result, Ivars, "OBJC_IVAR_$_", ClassName);
+    
     Result += "\nstatic ";
     Write__ivar_list_t_TypeDecl(Result, Ivars.size());
     Result += " "; Result += VarName;
@@ -5771,9 +5777,6 @@
     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