modern objective-c translator: please symbols generated
for @protocol expression into their own section. llvm-svn: 152808
This commit is contained in:
parent
d9a909cd29
commit
b31e3af6fb
|
|
@ -2991,7 +2991,8 @@ QualType RewriteModernObjC::getProtocolType() {
|
||||||
/// The forward references (and metadata) are generated in
|
/// The forward references (and metadata) are generated in
|
||||||
/// RewriteModernObjC::HandleTranslationUnit().
|
/// RewriteModernObjC::HandleTranslationUnit().
|
||||||
Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) {
|
Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) {
|
||||||
std::string Name = "_OBJC_PROTOCOL_" + Exp->getProtocol()->getNameAsString();
|
std::string Name = "_OBJC_PROTOCOL_REFERENCE_$_" +
|
||||||
|
Exp->getProtocol()->getNameAsString();
|
||||||
IdentifierInfo *ID = &Context->Idents.get(Name);
|
IdentifierInfo *ID = &Context->Idents.get(Name);
|
||||||
VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(),
|
VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(),
|
||||||
SourceLocation(), ID, getProtocolType(), 0,
|
SourceLocation(), ID, getProtocolType(), 0,
|
||||||
|
|
@ -4971,6 +4972,23 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) {
|
||||||
// Nothing yet.
|
// Nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write_ProtocolExprReferencedMetadata - This routine writer out the
|
||||||
|
/// protocol reference symbols in the for of:
|
||||||
|
/// struct _protocol_t *PROTOCOL_REF = &PROTOCOL_METADATA.
|
||||||
|
static void Write_ProtocolExprReferencedMetadata(ASTContext *Context,
|
||||||
|
ObjCProtocolDecl *PDecl,
|
||||||
|
std::string &Result) {
|
||||||
|
// Also output .objc_protorefs$B section and its meta-data.
|
||||||
|
if (Context->getLangOpts().MicrosoftExt)
|
||||||
|
Result += "__declspec(allocate(\".objc_protorefs$B\")) ";
|
||||||
|
Result += "struct _protocol_t *";
|
||||||
|
Result += "_OBJC_PROTOCOL_REFERENCE_$_";
|
||||||
|
Result += PDecl->getNameAsString();
|
||||||
|
Result += " = &";
|
||||||
|
Result += "_OBJC_PROTOCOL_"; Result += PDecl->getNameAsString();
|
||||||
|
Result += ";\n";
|
||||||
|
}
|
||||||
|
|
||||||
void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) {
|
void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) {
|
||||||
if (Diags.hasErrorOccurred())
|
if (Diags.hasErrorOccurred())
|
||||||
return;
|
return;
|
||||||
|
|
@ -4980,8 +4998,10 @@ void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) {
|
||||||
// Here's a great place to add any extra declarations that may be needed.
|
// Here's a great place to add any extra declarations that may be needed.
|
||||||
// Write out meta data for each @protocol(<expr>).
|
// Write out meta data for each @protocol(<expr>).
|
||||||
for (llvm::SmallPtrSet<ObjCProtocolDecl *,8>::iterator I = ProtocolExprDecls.begin(),
|
for (llvm::SmallPtrSet<ObjCProtocolDecl *,8>::iterator I = ProtocolExprDecls.begin(),
|
||||||
E = ProtocolExprDecls.end(); I != E; ++I)
|
E = ProtocolExprDecls.end(); I != E; ++I) {
|
||||||
RewriteObjCProtocolMetaData(*I, Preamble);
|
RewriteObjCProtocolMetaData(*I, Preamble);
|
||||||
|
Write_ProtocolExprReferencedMetadata(Context, (*I), Preamble);
|
||||||
|
}
|
||||||
|
|
||||||
InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false);
|
InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false);
|
||||||
for (unsigned i = 0, e = ObjCInterfacesSeen.size(); i < e; i++) {
|
for (unsigned i = 0, e = ObjCInterfacesSeen.size(); i < e; i++) {
|
||||||
|
|
@ -5046,15 +5066,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) {
|
||||||
Preamble += "#pragma section(\".objc_imageinfo$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".objc_imageinfo$B\", long, read, write)\n";
|
||||||
Preamble += "#pragma section(\".objc_nlclslist$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".objc_nlclslist$B\", long, read, write)\n";
|
||||||
Preamble += "#pragma section(\".objc_nlcatlist$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".objc_nlcatlist$B\", long, read, write)\n";
|
||||||
|
|
||||||
// These need be generated. But they are not,using API calls instead.
|
|
||||||
Preamble += "#pragma section(\".objc_selrefs$B\", long, read, write)\n";
|
|
||||||
Preamble += "#pragma section(\".objc_classrefs$B\", long, read, write)\n";
|
|
||||||
Preamble += "#pragma section(\".objc_superrefs$B\", long, read, write)\n";
|
|
||||||
|
|
||||||
Preamble += "#pragma section(\".objc_protorefs$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".objc_protorefs$B\", long, read, write)\n";
|
||||||
|
|
||||||
|
|
||||||
// These are generated but not necessary for functionality.
|
// These are generated but not necessary for functionality.
|
||||||
Preamble += "#pragma section(\".datacoal_nt$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".datacoal_nt$B\", long, read, write)\n";
|
||||||
Preamble += "#pragma section(\".cat_cls_meth$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".cat_cls_meth$B\", long, read, write)\n";
|
||||||
|
|
@ -5062,6 +5074,12 @@ void RewriteModernObjC::Initialize(ASTContext &context) {
|
||||||
Preamble += "#pragma section(\".cls_meth$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".cls_meth$B\", long, read, write)\n";
|
||||||
Preamble += "#pragma section(\".objc_ivar$B\", long, read, write)\n";
|
Preamble += "#pragma section(\".objc_ivar$B\", long, read, write)\n";
|
||||||
|
|
||||||
|
// These need be generated for performance. Currently they are not,
|
||||||
|
// using API calls instead.
|
||||||
|
Preamble += "#pragma section(\".objc_selrefs$B\", long, read, write)\n";
|
||||||
|
Preamble += "#pragma section(\".objc_classrefs$B\", long, read, write)\n";
|
||||||
|
Preamble += "#pragma section(\".objc_superrefs$B\", long, read, write)\n";
|
||||||
|
|
||||||
// Add a constructor for creating temporary objects.
|
// Add a constructor for creating temporary objects.
|
||||||
Preamble += "__rw_objc_super(struct objc_object *o, struct objc_object *s) "
|
Preamble += "__rw_objc_super(struct objc_object *o, struct objc_object *s) "
|
||||||
": ";
|
": ";
|
||||||
|
|
@ -5935,7 +5953,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl,
|
||||||
Result += "\n";
|
Result += "\n";
|
||||||
if (LangOpts.MicrosoftExt)
|
if (LangOpts.MicrosoftExt)
|
||||||
Result += "__declspec(allocate(\".datacoal_nt$B\")) ";
|
Result += "__declspec(allocate(\".datacoal_nt$B\")) ";
|
||||||
Result += "static struct _protocol_t _OBJC_PROTOCOL_";
|
Result += "struct _protocol_t _OBJC_PROTOCOL_";
|
||||||
Result += PDecl->getNameAsString();
|
Result += PDecl->getNameAsString();
|
||||||
Result += " __attribute__ ((used, section (\"__DATA,__datacoal_nt,coalesced\"))) = {\n";
|
Result += " __attribute__ ((used, section (\"__DATA,__datacoal_nt,coalesced\"))) = {\n";
|
||||||
Result += "\t0,\n"; // id is; is null
|
Result += "\t0,\n"; // id is; is null
|
||||||
|
|
@ -6317,7 +6335,7 @@ void RewriteModernObjC::WriteImageInfo(std::string &Result) {
|
||||||
|
|
||||||
Result += "static struct IMAGE_INFO { unsigned version; unsigned flag; } ";
|
Result += "static struct IMAGE_INFO { unsigned version; unsigned flag; } ";
|
||||||
// version 0, ObjCABI is 2
|
// version 0, ObjCABI is 2
|
||||||
Result += "L_OBJC_IMAGE_INFO = { 0, 2 };\n";
|
Result += "_OBJC_IMAGE_INFO = { 0, 2 };\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RewriteObjCCategoryImplDecl - Rewrite metadata for each category
|
/// RewriteObjCCategoryImplDecl - Rewrite metadata for each category
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue