summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-03-20 21:41:28 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-03-20 21:41:28 +0000
commitcd79a49f37a0603635a823149d4708ecfc611920 (patch)
treec21001f38d2f960be49cf18d92abcb8d7467055f
parent1283317db47cdec313361137e2098d3e0eb8771c (diff)
downloadbcm5719-llvm-cd79a49f37a0603635a823149d4708ecfc611920.tar.gz
bcm5719-llvm-cd79a49f37a0603635a823149d4708ecfc611920.zip
modern objective-c translator: add static function to initialize
the class pointer in the category structure. // rdar://11076938 llvm-svn: 153138
-rw-r--r--clang/lib/Rewrite/RewriteModernObjC.cpp31
-rw-r--r--clang/test/Rewriter/objc-modern-class-init.mm8
2 files changed, 36 insertions, 3 deletions
diff --git a/clang/lib/Rewrite/RewriteModernObjC.cpp b/clang/lib/Rewrite/RewriteModernObjC.cpp
index 3c9c5ddbe4e..fed50b1a3db 100644
--- a/clang/lib/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Rewrite/RewriteModernObjC.cpp
@@ -5277,7 +5277,7 @@ void RewriteModernObjC::RewriteIvarOffsetComputation(ObjCIvarDecl *ivar,
/// 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 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re
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 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context,
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 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context,
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,
diff --git a/clang/test/Rewriter/objc-modern-class-init.mm b/clang/test/Rewriter/objc-modern-class-init.mm
index 4a21bc4e30e..b0326a40281 100644
--- a/clang/test/Rewriter/objc-modern-class-init.mm
+++ b/clang/test/Rewriter/objc-modern-class-init.mm
@@ -13,3 +13,11 @@
@implementation Sub @end
@implementation Root @end
+
+@interface Root(Cat) @end
+
+@interface Sub(Cat) @end
+
+@implementation Root(Cat) @end
+
+@implementation Sub(Cat) @end
OpenPOWER on IntegriCloud