Add support for ObjC keyword selectors.
- Add SelectorInfo/SelectorTable classes, modeled after IdentifierInfo/IdentifierTable.
- Add SelectorTable instance to ASTContext, created lazily through ASTContext::getSelectorInfo().
- Add SelectorInfo slot to ObjcMethodDecl.
- Add helper function to derive a SelectorInfo from ObjcKeywordInfo.
Misc: Got the Decl stats stuff up and running again...it was missing support for ObjC AST's.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42023 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 16d7213..22a7c04 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1239,13 +1239,37 @@
return;
}
+/// Build objective-c style method name.
+static SelectorInfo &
+ ObjcGetSelectorInfo(ObjcKeywordInfo* KeyInfo, unsigned numKeyInfo,
+ ASTContext &Context)
+{
+ int len=0;
+ char *methodName;
+ for (unsigned int i = 0; i < numKeyInfo; i++) {
+ IdentifierInfo *selectorName = KeyInfo[i].SelectorName;
+ if (selectorName)
+ len += strlen(selectorName->getName());
+ len++;
+ }
+ methodName = (char *) alloca (len + 1);
+ methodName[0] = '\0';
+ for (unsigned int i = 0; i < numKeyInfo; i++) {
+ IdentifierInfo *selectorName = KeyInfo[i].SelectorName;
+ if (selectorName)
+ strcat(methodName, selectorName->getName());
+ strcat(methodName, ":");
+ }
+ return Context.getSelectorInfo(methodName, methodName+len);
+}
+
+
Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
tok::TokenKind MethodType, TypeTy *ReturnType,
ObjcKeywordInfo *Keywords, unsigned NumKeywords,
AttributeList *AttrList) {
assert(NumKeywords && "Selector must be specified");
- // FIXME: SelectorName to be changed to comform to objc's abi for method names
- IdentifierInfo *SelectorName = Keywords[0].SelectorName;
+ SelectorInfo &SelName = ObjcGetSelectorInfo(Keywords, NumKeywords, Context);
llvm::SmallVector<ParmVarDecl*, 16> Params;
for (unsigned i = 0; i < NumKeywords; i++) {
@@ -1261,7 +1285,7 @@
}
QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc,
- SelectorName, resultDeclType,
+ SelName, resultDeclType,
0, -1, AttrList, MethodType == tok::minus);
ObjcMethod->setMethodParams(&Params[0], NumKeywords);
return ObjcMethod;
@@ -1270,9 +1294,11 @@
Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
tok::TokenKind MethodType, TypeTy *ReturnType,
IdentifierInfo *SelectorName, AttributeList *AttrList) {
- // FIXME: SelectorName to be changed to comform to objc's abi for method names
+ const char *methodName = SelectorName->getName();
+ SelectorInfo &SelName = Context.getSelectorInfo(methodName,
+ methodName+strlen(methodName));
QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
- return new ObjcMethodDecl(MethodLoc, SelectorName, resultDeclType, 0, -1,
+ return new ObjcMethodDecl(MethodLoc, SelName, resultDeclType, 0, -1,
AttrList, MethodType == tok::minus);
}