return 0;
}
+void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
+ unsigned NumParams) {
+ assert(ParamInfo == 0 && "Already has param info!");
+
+ // Zero params -> null pointer.
+ if (NumParams) {
+ ParamInfo = new ParmVarDecl*[NumParams];
+ memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
+ NumMethodParams = NumParams;
+ }
+}
+
+ObjcMethodDecl::~ObjcMethodDecl() {
+ delete[] ParamInfo;
+}
+
/// addObjcMethods - Insert instance and methods declarations into
/// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
///
ConsumeToken();
continue;
} else if (ocKind == tok::objc_property) {
- ParseObjCPropertyDecl(0/*FIXME*/);
+ ParseObjCPropertyDecl(interfaceDecl);
continue;
} else {
Diag(Tok, diag::err_objc_illegal_interface_qual);
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);
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;
}
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,
class ObjcMethodDecl : public Decl {
public:
ObjcMethodDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
+ ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
Decl *PrevDecl = 0)
- : Decl(ObjcMethod, L, Id, PrevDecl), MethodDeclType(T), ParamInfo(0),
+ : Decl(ObjcMethod, L, Id, PrevDecl), MethodDeclType(T),
+ ParamInfo(paramInfo), NumMethodParams(numParams),
MethodAttrs(M), IsInstance(isInstance) {}
virtual ~ObjcMethodDecl();
QualType getMethodType() const { return MethodDeclType; }
- unsigned getNumMethodParams() const;
+ unsigned getNumMethodParams() const { return NumMethodParams; }
ParmVarDecl *getMethodParamDecl(unsigned i) {
assert(i < getNumMethodParams() && "Illegal param #");
return ParamInfo[i];
}
- void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
+ void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
AttributeList *getMethodAttrs() const {return MethodAttrs;}
bool isInstance() const { return IsInstance; }
/// ParamInfo - new[]'d array of pointers to VarDecls for the formal
/// parameters of this Method. This is null if there are no formals.
ParmVarDecl **ParamInfo;
+ int NumMethodParams; // -1 if no parameters
/// List of attributes for this method declaration.
AttributeList *MethodAttrs;