diff options
author | Steve Naroff <snaroff@apple.com> | 2007-09-17 14:16:13 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-09-17 14:16:13 +0000 |
commit | 3f128ad2691d299b96663da85a9e069c4081ea7c (patch) | |
tree | dd6d3313ba38b90d71adfcf7b1d135465b54aaa2 /Sema/SemaDecl.cpp | |
parent | 3860c11a3f8a862db25014d555745d8cfd3aaec9 (diff) |
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
Diffstat (limited to 'Sema/SemaDecl.cpp')
-rw-r--r-- | Sema/SemaDecl.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 16d72130f5..22a7c0418d 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1239,13 +1239,37 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl, 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 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc, } 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, 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); } |