Patch for building method declaration nodes. Also fixed a segfault in cocoa.m due
to use of @property.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41880 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index b6fe89a..7a3466f 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -360,6 +360,13 @@
virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum);
+ virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
+ tok::TokenKind MethodType, TypeTy *ReturnType,
+ ObjcKeywordInfo *Keywords, unsigned NumKeywords,
+ AttributeList *AttrList);
+ virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
+ tok::TokenKind MethodType, TypeTy *ReturnType,
+ IdentifierInfo *SelectorName, AttributeList *AttrList);
virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivar,
tok::ObjCKeywordKind visibility);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 6bfae19..d367038 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1197,8 +1197,10 @@
void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum) {
- // FIXME: Add method insertion code here.
-#if 0
+ // FIXME: Fix this when we can handle methods declared in protocols.
+ // See Parser::ParseObjCAtProtocolDeclaration
+ if (!ClassDecl)
+ return;
ObjcInterfaceDecl *Interface = cast<ObjcInterfaceDecl>(
static_cast<Decl*>(ClassDecl));
llvm::SmallVector<ObjcMethodDecl*, 32> insMethods;
@@ -1215,10 +1217,46 @@
}
Interface->ObjcAddMethods(&insMethods[0], insMethods.size(),
&clsMethods[0], clsMethods.size());
-#endif
return;
}
+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;
+ llvm::SmallVector<ParmVarDecl*, 16> Params;
+
+ for (unsigned i = 0; i < NumKeywords; i++) {
+ ObjcKeywordInfo *arg = &Keywords[i];
+ // FIXME: arg->AttrList must be stored too!
+ ParmVarDecl* Param = new ParmVarDecl(arg->ColonLoc, arg->ArgumentName,
+ QualType::getFromOpaquePtr(arg->TypeInfo),
+ 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,
+ SelectorName, resultDeclType,
+ 0, -1, AttrList, MethodType == tok::minus);
+ ObjcMethod->setMethodParams(&Params[0], NumKeywords);
+ return ObjcMethod;
+}
+
+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
+ QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
+ return new ObjcMethodDecl(MethodLoc, SelectorName, resultDeclType, 0, -1,
+ AttrList, MethodType == tok::minus);
+}
+
Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
DeclTy *lastEnumConst,
SourceLocation IdLoc, IdentifierInfo *Id,