StringRef prefix, StringRef ClassName, std::string &Result);
virtual void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
std::string &Result);
+ virtual void RewriteClassSetupInitHook(std::string &Result);
+
virtual void RewriteMetaDataIntoBuffer(std::string &Result);
virtual void WriteImageInfo(std::string &Result);
virtual void RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *CDecl,
std::string &Result);
+ virtual void RewriteCategorySetupInitHook(std::string &Result);
// Rewriting ivar
virtual void RewriteIvarOffsetComputation(ObjCIvarDecl *ivar,
Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString();
Result += ".cache = "; Result += "&_objc_empty_cache"; Result += ";\n";
Result += "}\n";
-
- Result += "#pragma section(\".objc_inithooks$B\", long, read, write)\n";
- Result += "__declspec(allocate(\".objc_inithooks$B\")) ";
- Result += "static void *OBJC_CLASS_SETUP2_$_";
- Result += CDecl->getNameAsString();
- Result += " = (void *)&OBJC_CLASS_SETUP_$_";
- Result += CDecl->getNameAsString();
- Result += ";\n\n";
}
static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context,
std::string &Result,
- StringRef CatName,
+ ObjCCategoryDecl *CatDecl,
ObjCInterfaceDecl *ClassDecl,
ArrayRef<ObjCMethodDecl *> InstanceMethods,
ArrayRef<ObjCMethodDecl *> ClassMethods,
ArrayRef<ObjCProtocolDecl *> RefedProtocols,
ArrayRef<ObjCPropertyDecl *> ClassProperties) {
-
+ StringRef CatName = CatDecl->getName();
StringRef ClassName = ClassDecl->getName();
// must declare an extern class object in case this class is not implemented
// in this TU.
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,
}
+void RewriteModernObjC::RewriteClassSetupInitHook(std::string &Result) {
+ int ClsDefCount = ClassImplementation.size();
+ if (!ClsDefCount)
+ return;
+ Result += "#pragma section(\".objc_inithooks$B\", long, read, write)\n";
+ Result += "__declspec(allocate(\".objc_inithooks$B\")) ";
+ Result += "static void *OBJC_CLASS_SETUP[] = {\n";
+ for (int i = 0; i < ClsDefCount; i++) {
+ ObjCImplementationDecl *IDecl = ClassImplementation[i];
+ ObjCInterfaceDecl *CDecl = IDecl->getClassInterface();
+ Result += "\t(void *)&OBJC_CLASS_SETUP_$_";
+ Result += CDecl->getName(); Result += ",\n";
+ }
+ Result += "};\n";
+}
+
void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) {
int ClsDefCount = ClassImplementation.size();
int CatDefCount = CategoryImplementation.size();
for (int i = 0; i < ClsDefCount; i++)
RewriteObjCClassMetaData(ClassImplementation[i], Result);
+ RewriteClassSetupInitHook(Result);
+
// For each implemented category, write out all its meta data.
for (int i = 0; i < CatDefCount; i++)
RewriteObjCCategoryImplDecl(CategoryImplementation[i], Result);
+ RewriteCategorySetupInitHook(Result);
+
if (ClsDefCount > 0) {
if (LangOpts.MicrosoftExt)
Result += "__declspec(allocate(\".objc_classlist$B\")) ";
FullCategoryName);
Write_category_t(*this, Context, Result,
- CDecl->getNameAsString(),
+ CDecl,
ClassDecl,
InstanceMethods,
ClassMethods,
// Determine if this category is also "non-lazy".
if (ImplementationIsNonLazy(IDecl))
DefinedNonLazyCategories.push_back(CDecl);
-
+
+}
+
+void RewriteModernObjC::RewriteCategorySetupInitHook(std::string &Result) {
+ int CatDefCount = CategoryImplementation.size();
+ if (!CatDefCount)
+ return;
+ Result += "#pragma section(\".objc_inithooks$B\", long, read, write)\n";
+ Result += "__declspec(allocate(\".objc_inithooks$B\")) ";
+ Result += "static void *OBJC_CATEGORY_SETUP[] = {\n";
+ for (int i = 0; i < CatDefCount; i++) {
+ ObjCCategoryImplDecl *IDecl = CategoryImplementation[i];
+ ObjCCategoryDecl *CatDecl= IDecl->getCategoryDecl();
+ ObjCInterfaceDecl *ClassDecl = IDecl->getClassInterface();
+ Result += "\t(void *)&OBJC_CATEGORY_SETUP_$_";
+ Result += ClassDecl->getName();
+ Result += "_$_";
+ Result += CatDecl->getName();
+ Result += ",\n";
+ }
+ Result += "};\n";
}
// RewriteObjCMethodsMetaData - Rewrite methods metadata for instance or
--- /dev/null
+// RUN: %clang_cc1 -E %s -o %t.mm
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
+// rdar:// 11124354
+
+@interface Root @end
+
+@interface Super : Root
+@end
+
+@interface Sub : Super
+@end
+
+@implementation Sub @end
+
+@implementation Root @end
+
+@interface Root(Cat) @end
+
+@interface Sub(Cat) @end
+
+@implementation Root(Cat) @end
+
+@implementation Sub(Cat) @end
+
+
+// CHECK: #pragma section(".objc_inithooks$B", long, read, write)
+// CHECK: __declspec(allocate(".objc_inithooks$B")) static void *OBJC_CLASS_SETUP[] = {
+// CHECK: (void *)&OBJC_CLASS_SETUP_$_Sub,
+// CHECK: (void *)&OBJC_CLASS_SETUP_$_Root,
+// CHECK: };
+
+// CHECK: #pragma section(".objc_inithooks$B", long, read, write)
+// CHECK: __declspec(allocate(".objc_inithooks$B")) static void *OBJC_CATEGORY_SETUP[] = {
+// CHECK: (void *)&OBJC_CATEGORY_SETUP_$_Root_$_Cat,
+// CHECK: (void *)&OBJC_CATEGORY_SETUP_$_Sub_$_Cat,
+// CHECK: };