Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42395 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 1fb4142..ae9c719 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1567,65 +1567,25 @@
}
Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
- tok::TokenKind MethodType, TypeTy *ReturnType,
- ObjcKeywordDecl *Keywords, unsigned NumKeywords,
- AttributeList *AttrList,
- tok::ObjCKeywordKind MethodDeclKind) {
- assert(NumKeywords && "Selector must be specified");
-
- // Derive the selector name from the keyword declarations.
- int len=0;
- for (unsigned int i = 0; i < NumKeywords; i++) {
- if (Keywords[i].SelectorName)
- len += strlen(Keywords[i].SelectorName->getName());
- len++;
- }
- llvm::SmallString<128> methodName;
- methodName[0] = '\0';
- for (unsigned int i = 0; i < NumKeywords; i++) {
- if (Keywords[i].SelectorName)
- methodName += Keywords[i].SelectorName->getName();
- methodName += ":";
- }
- methodName[len] = '\0';
- IdentifierInfo &SelName = Context.Idents.get(&methodName[0],
- &methodName[0]+len);
+ tok::TokenKind MethodType, TypeTy *ReturnType, SelectorInfo *Sel,
+ // optional arguments. The number of types/arguments is obtained
+ // from the Sel.getNumArgs().
+ TypeTy **ArgTypes, IdentifierInfo **ArgNames,
+ AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind) {
llvm::SmallVector<ParmVarDecl*, 16> Params;
- for (unsigned i = 0; i < NumKeywords; i++) {
- ObjcKeywordDecl *arg = &Keywords[i];
+ for (unsigned i = 0; i < Sel->getNumArgs(); i++) {
// FIXME: arg->AttrList must be stored too!
- ParmVarDecl* Param = new ParmVarDecl(arg->ColonLoc, arg->ArgumentName,
- QualType::getFromOpaquePtr(arg->TypeInfo),
+ ParmVarDecl* Param = new ParmVarDecl(SourceLocation(/*FIXME*/), ArgNames[i],
+ QualType::getFromOpaquePtr(ArgTypes[i]),
VarDecl::None, 0);
- // FIXME: 'InvalidType' does not get set by caller yet.
- if (arg->InvalidType)
- Param->setInvalidDecl();
Params.push_back(Param);
}
QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
- ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc,
- SelName, resultDeclType,
- 0, -1, AttrList, MethodType == tok::minus);
- ObjcMethod->setMethodParams(&Params[0], NumKeywords);
- if (MethodDeclKind == tok::objc_optional)
- ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional);
- else
- ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required);
- return ObjcMethod;
-}
-
-Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
- tok::TokenKind MethodType, TypeTy *ReturnType,
- IdentifierInfo *SelectorName, AttributeList *AttrList,
- tok::ObjCKeywordKind MethodDeclKind) {
- const char *methodName = SelectorName->getName();
- IdentifierInfo &SelName = Context.Idents.get(methodName,
- methodName+strlen(methodName));
- QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
- ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc,
- SelName, resultDeclType, 0, -1,
- AttrList, MethodType == tok::minus);
+ ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel,
+ resultDeclType, 0, -1, AttrList,
+ MethodType == tok::minus);
+ ObjcMethod->setMethodParams(&Params[0], Sel->getNumArgs());
if (MethodDeclKind == tok::objc_optional)
ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional);
else