diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-02-08 22:23:26 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-02-08 22:23:26 +0000 |
commit | e0adbd8386d9ff7312b74e4d2d1f27337f94732c (patch) | |
tree | 6ce952dcf67c7c818d95c0a45a11509d4d521846 | |
parent | 6d2f0f589a8c38f64147e90ccdd813dde74ecdb6 (diff) |
last piece of metadata to complete modern metadata for
protocol definitions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150106 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Rewrite/RewriteModernObjC.cpp | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp index e572b96e13..c0e5f0e41b 100644 --- a/lib/Rewrite/RewriteModernObjC.cpp +++ b/lib/Rewrite/RewriteModernObjC.cpp @@ -5368,6 +5368,32 @@ static void Write__prop_list_t_initializer(RewriteModernObjC &RewriteObj, } } +static void Write__extendedMethodTypes_initializer(RewriteModernObjC &RewriteObj, + ASTContext *Context, std::string &Result, + ArrayRef<ObjCMethodDecl *> Methods, + StringRef VarName, + StringRef ProtocolName) { + if (Methods.size() == 0) + return; + + Result += "\nstatic const char *"; + Result += VarName; Result += ProtocolName; + Result += " [] __attribute__ ((used, section (\"__DATA,__objc_const\"))) = \n"; + Result += "{\n"; + for (unsigned i = 0, e = Methods.size(); i < e; i++) { + ObjCMethodDecl *MD = Methods[i]; + std::string MethodTypeString, QuoteMethodTypeString; + Context->getObjCEncodingForMethodDecl(MD, MethodTypeString, true); + RewriteObj.QuoteDoublequotes(MethodTypeString, QuoteMethodTypeString); + Result += "\t\""; Result += QuoteMethodTypeString; Result += "\""; + if (i == e-1) + Result += "\n};\n"; + else { + Result += ",\n"; + } + } +} + /// RewriteObjCProtocolMetaData - Rewrite protocols meta-data. void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, std::string &Result) { @@ -5409,7 +5435,20 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, ClassMethods.push_back(MD); } } - + std::vector<ObjCMethodDecl *> AllMethods; + for (unsigned i = 0, e = InstanceMethods.size(); i < e; i++) + AllMethods.push_back(InstanceMethods[i]); + for (unsigned i = 0, e = ClassMethods.size(); i < e; i++) + AllMethods.push_back(ClassMethods[i]); + for (unsigned i = 0, e = OptInstanceMethods.size(); i < e; i++) + AllMethods.push_back(OptInstanceMethods[i]); + for (unsigned i = 0, e = OptClassMethods.size(); i < e; i++) + AllMethods.push_back(OptClassMethods[i]); + + Write__extendedMethodTypes_initializer(*this, Context, Result, + AllMethods, + "_OBJC_PROTOCOL_METHOD_TYPES_", + PDecl->getNameAsString()); // Protocol's super protocol list std::vector<ObjCProtocolDecl *> SuperProtocols; for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(), @@ -5497,8 +5536,13 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, Result += "\t"; Result += "sizeof(_protocol_t)"; Result += ",\n"; Result += "\t0,\n"; - // FIXME. // const char ** extendedMethodTypes; - Result += "\t0\n};\n"; + if (AllMethods.size() > 0) { + Result += "\t(const char **)&"; Result += "_OBJC_PROTOCOL_METHOD_TYPES_"; + Result += PDecl->getNameAsString(); + Result += "\n};\n"; + } + else + Result += "\t0\n};\n"; // Mark this protocol as having been generated. if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl())) |