diff --git a/AST/Decl.cpp b/AST/Decl.cpp index 8208c02049..0cbadbf969 100644 --- a/AST/Decl.cpp +++ b/AST/Decl.cpp @@ -298,12 +298,12 @@ void ObjcProtocolDecl::ObjcAddProtoMethods(ObjcMethodDecl **insMethods, unsigned numClsMembers) { NumProtoInsMethods = numInsMembers; if (numInsMembers) { - ProtoInsMethods = new ObjcProtoMethodDecl*[numInsMembers]; + ProtoInsMethods = new ObjcMethodDecl*[numInsMembers]; memcpy(ProtoInsMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); } NumProtoClsMethods = numClsMembers; if (numClsMembers) { - ProtoClsMethods = new ObjcProtoMethodDecl*[numClsMembers]; + ProtoClsMethods = new ObjcMethodDecl*[numClsMembers]; memcpy(ProtoClsMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); } } diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index c2cf61d367..c4a785eed8 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -375,7 +375,7 @@ Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, tok::TokenKind methodType = Tok.getKind(); SourceLocation methodLoc = ConsumeToken(); - DeclTy *MDecl = ParseObjCMethodDecl(IDecl, pi, methodType, methodLoc); + DeclTy *MDecl = ParseObjCMethodDecl(pi, methodType, methodLoc); // Since this rule is used for both method declarations and definitions, // the caller is (optionally) responsible for consuming the ';'. return MDecl; @@ -484,8 +484,7 @@ Parser::TypeTy *Parser::ParseObjCTypeName() { /// objc-keyword-attributes: [OBJC2] /// __attribute__((unused)) /// -Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl, - tok::ObjCKeywordKind& pi, +Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::ObjCKeywordKind& pi, tok::TokenKind mType, SourceLocation mLoc) { TypeTy *ReturnType = 0; @@ -552,7 +551,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl, // If attributes exist after the method, parse them. if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) methodAttrs = ParseAttributes(); - return Actions.ObjcBuildMethodDeclaration(IDecl, pi, mLoc, mType, + return Actions.ObjcBuildMethodDeclaration(pi, mLoc, mType, ReturnType, &KeyInfo[0], KeyInfo.size(), methodAttrs); @@ -563,7 +562,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl, if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) methodAttrs = ParseAttributes(); - return Actions.ObjcBuildMethodDeclaration(IDecl, pi, + return Actions.ObjcBuildMethodDeclaration(pi, mLoc, mType, ReturnType, selIdent, methodAttrs); } diff --git a/Sema/Sema.h b/Sema/Sema.h index b50993e7e2..1b1aa781d1 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -368,14 +368,12 @@ public: virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, DeclTy **allMethods, unsigned allNum); - virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *InterfaceDecl, - tok::ObjCKeywordKind& pi, + virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, ObjcKeywordDecl *Keywords, unsigned NumKeywords, AttributeList *AttrList); - virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *InterfaceDecl, - tok::ObjCKeywordKind& pi, + virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, IdentifierInfo *SelectorName, AttributeList *AttrList); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 24b6309b1a..53efacfd0a 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1264,8 +1264,7 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl, return; } -Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl, - tok::ObjCKeywordKind& pi, +Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, ObjcKeywordDecl *Keywords, unsigned NumKeywords, @@ -1303,31 +1302,18 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl, Params.push_back(Param); } QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType); - ObjcMethodDecl* ObjcMethod; -// FIXME: Added !IDecl for now to handle @implementation - if (!IDecl || isa(static_cast(IDecl))) { - ObjcMethod = new ObjcMethodDecl(MethodLoc, SelName, resultDeclType, - 0, -1, AttrList, MethodType == tok::minus); - ObjcMethod->setMethodParams(&Params[0], NumKeywords); - } - else if (isa(static_cast(IDecl))) { - ObjcMethod = new ObjcProtoMethodDecl(MethodLoc, SelName, resultDeclType, - 0, -1, AttrList, MethodType == tok::minus); - ObjcMethod->setMethodParams(&Params[0], NumKeywords); - if (pi == tok::objc_optional) - dyn_cast(ObjcMethod)-> - setDeclImplementation(ObjcProtoMethodDecl::Optional); - else - dyn_cast(ObjcMethod)-> - setDeclImplementation(ObjcProtoMethodDecl::Required); - } + ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, + SelName, resultDeclType, + 0, -1, AttrList, MethodType == tok::minus); + ObjcMethod->setMethodParams(&Params[0], NumKeywords); + if (pi == tok::objc_optional) + ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional); else - assert(0 && "Sema::ObjcBuildMethodDeclaration(): Unknown DeclTy"); + ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required); return ObjcMethod; } -Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl, - tok::ObjCKeywordKind& pi, +Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, IdentifierInfo *SelectorName, AttributeList *AttrList) { @@ -1335,25 +1321,13 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl, SelectorInfo &SelName = Context.getSelectorInfo(methodName, methodName+strlen(methodName)); QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType); - ObjcMethodDecl* ObjcMethod; -// FIXME: Remove after IDecl is always non-null - if (!IDecl || isa(static_cast(IDecl))) { - ObjcMethod = new ObjcMethodDecl(MethodLoc, SelName, resultDeclType, 0, -1, - AttrList, MethodType == tok::minus); - } - else if (isa(static_cast(IDecl))) { - ObjcMethod = new ObjcProtoMethodDecl(MethodLoc, SelName, resultDeclType, - 0, -1, - AttrList, MethodType == tok::minus); - if (pi == tok::objc_optional) - dyn_cast(ObjcMethod)-> - setDeclImplementation(ObjcProtoMethodDecl::Optional); - else - dyn_cast(ObjcMethod)-> - setDeclImplementation(ObjcProtoMethodDecl::Required); - } + ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, + SelName, resultDeclType, 0, -1, + AttrList, MethodType == tok::minus); + if (pi == tok::objc_optional) + ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional); else - assert(0 && "Sema::ObjcBuildMethodDeclaration(): Unknown DeclTy"); + ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required); return ObjcMethod; } diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 683e98489f..6569b0657c 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -26,7 +26,6 @@ class FunctionDecl; class AttributeList; class ObjcIvarDecl; class ObjcMethodDecl; -class ObjcProtoMethodDecl; class SelectorInfo; @@ -615,6 +614,9 @@ public: /// ObjcMethodDecl - An instance of this class is created to represent an instance /// or class method declaration. class ObjcMethodDecl : public Decl { +public: + enum ImplementationControl { None, Required, Optional }; +private: // A unigue name for this method. SelectorInfo &Selector; @@ -630,6 +632,9 @@ class ObjcMethodDecl : public Decl { /// instance (true) or class (false) method. bool IsInstance : 1; + /// @required/@optional + ImplementationControl DeclImplementation : 2; + public: ObjcMethodDecl(SourceLocation L, SelectorInfo &SelId, QualType T, ParmVarDecl **paramInfo = 0, int numParams=-1, @@ -658,6 +663,11 @@ public: AttributeList *getMethodAttrs() const {return MethodAttrs;} bool isInstance() const { return IsInstance; } + // Related to protocols declared in @protocol + void setDeclImplementation(ImplementationControl ic) + { DeclImplementation = ic; } + ImplementationControl getImplementationControl() const + { return DeclImplementation; } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { @@ -667,39 +677,13 @@ public: static bool classof(const ObjcMethodDecl *D) { return true; } }; -/// ObjcProtoMethodDecl - Each instance represents a method declared -/// in a protocol. -/// -class ObjcProtoMethodDecl : public ObjcMethodDecl { -public: - ObjcProtoMethodDecl(SourceLocation L, SelectorInfo &Id, QualType T, - ParmVarDecl **paramInfo = 0, int numParams=-1, - AttributeList *M = 0, bool isInstance = true, - Decl *PrevDecl = 0) : - ObjcMethodDecl(ObjcProtoMethod, L, Id, T, paramInfo, numParams, - M, isInstance, PrevDecl) {} - - enum ImplementationControl { None, Required, Optional }; - - void setDeclImplementation(ImplementationControl ic) - { DeclImplementation = ic; } - ImplementationControl getImplementationControl() const - { return DeclImplementation; } - // Implement isa/cast/dyncast/etc. - static bool classof(const Decl *D) { return D->getKind() == ObjcProtoMethod; } - static bool classof(const ObjcMethodDecl *D) { return true; } - -private: - ImplementationControl DeclImplementation : 2; -}; - class ObjcProtocolDecl : public TypeDecl { /// protocol instance methods - ObjcProtoMethodDecl **ProtoInsMethods; // Null if not defined + ObjcMethodDecl **ProtoInsMethods; // Null if not defined int NumProtoInsMethods; // -1 if not defined /// protocol class methods - ObjcProtoMethodDecl **ProtoClsMethods; // Null if not defined + ObjcMethodDecl **ProtoClsMethods; // Null if not defined int NumProtoClsMethods; // -1 if not defined bool isForwardProtoDecl; // declared with @protocol. diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 960e4154fe..50c437dd41 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -453,15 +453,13 @@ public: IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) { return 0; } - virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *IDecl, - tok::ObjCKeywordKind& pi, + virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, ObjcKeywordDecl *Keywords, unsigned NumKeywords, AttributeList *AttrList) { return 0; } - virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *IDecl, - tok::ObjCKeywordKind& pi, + virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, IdentifierInfo *SelectorName, AttributeList *AttrList) { return 0; diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 89fd68eebd..1e51fe7f4b 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -291,7 +291,7 @@ private: void ParseObjCMethodRequirement(); DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat, tok::ObjCKeywordKind& pi); - DeclTy *ParseObjCMethodDecl(DeclTy *CDecl, tok::ObjCKeywordKind& pi, + DeclTy *ParseObjCMethodDecl(tok::ObjCKeywordKind& pi, tok::TokenKind mType, SourceLocation mLoc); void ParseObjCPropertyAttribute(DeclTy *interfaceDecl);