[cfe-commits] r153138 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/objc-modern-class-init.mm

Fariborz Jahanian fjahanian at apple.com
Tue Mar 20 14:41:29 PDT 2012


Author: fjahanian
Date: Tue Mar 20 16:41:28 2012
New Revision: 153138

URL: http://llvm.org/viewvc/llvm-project?rev=153138&view=rev
Log:
modern objective-c translator: add static function to initialize 
the class pointer in the category structure.
// rdar://11076938

Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/test/Rewriter/objc-modern-class-init.mm

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=153138&r1=153137&r2=153138&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Tue Mar 20 16:41:28 2012
@@ -5277,7 +5277,7 @@
 
 /// struct _category_t {
 ///   const char * const name;
-///   struct _class_t *const cls;
+///   struct _class_t *cls;
 ///   const struct _method_list_t * const instance_methods;
 ///   const struct _method_list_t * const class_methods;
 ///   const struct _protocol_list_t * const protocols;
@@ -5362,7 +5362,7 @@
   
   Result += "\nstruct _category_t {\n";
   Result += "\tconst char * const name;\n";
-  Result += "\tstruct _class_t *const cls;\n";
+  Result += "\tstruct _class_t *cls;\n";
   Result += "\tconst struct _method_list_t *const instance_methods;\n";
   Result += "\tconst struct _method_list_t *const class_methods;\n";
   Result += "\tconst struct _protocol_list_t *const protocols;\n";
@@ -5753,7 +5753,7 @@
   Result += " __attribute__ ((used, section (\"__DATA,__objc_const\"))) = \n";
   Result += "{\n";
   Result += "\t\""; Result += ClassName; Result += "\",\n";
-  Result += "\t&"; Result += "OBJC_CLASS_$_"; Result += ClassName;
+  Result += "\t0, // &"; Result += "OBJC_CLASS_$_"; Result += ClassName;
   Result += ",\n";
   if (InstanceMethods.size() > 0) {
     Result += "\t(const struct _method_list_t *)&";  
@@ -5791,6 +5791,31 @@
     Result += "\t0,\n";
   
   Result += "};\n";
+  
+  // Add static function to initialize the class pointer in the category structure.
+  Result += "static void OBJC_CATEGORY_SETUP_$_";
+  Result += ClassDecl->getNameAsString();
+  Result += "_$_";
+  Result += CatName;
+  Result += "(void ) {\n";
+  Result += "\t_OBJC_$_CATEGORY_"; 
+  Result += ClassDecl->getNameAsString();
+  Result += "_$_";
+  Result += CatName;
+  Result += ".cls = "; Result += "&OBJC_CLASS_$_"; Result += ClassName;
+  Result += ";\n}\n";
+  
+  Result += "#pragma section(\".objc_inithooks$B\", long, read, write\n";
+  Result += "__declspec(allocate(\".objc_inithooks$B\")) ";
+  Result += "static void *OBJC_CATEGORY_SETUP2_$_";
+  Result += ClassDecl->getNameAsString();
+  Result += "_$_";
+  Result += CatName;
+  Result += " = (void *)&OBJC_CATEGORY_SETUP_$_"; 
+  Result += ClassDecl->getNameAsString();
+  Result += "_$_";
+  Result += CatName;
+  Result += ";\n\n";
 }
 
 static void Write__extendedMethodTypes_initializer(RewriteModernObjC &RewriteObj,

Modified: cfe/trunk/test/Rewriter/objc-modern-class-init.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-class-init.mm?rev=153138&r1=153137&r2=153138&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-class-init.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-class-init.mm Tue Mar 20 16:41:28 2012
@@ -13,3 +13,11 @@
 @implementation Sub @end
 
 @implementation Root @end
+
+ at interface Root(Cat) @end
+
+ at interface Sub(Cat) @end
+
+ at implementation Root(Cat) @end
+
+ at implementation Sub(Cat) @end





More information about the cfe-commits mailing list