DeclObjC.cpp revision 3e0a540b6d846178857289ec0eb8470a278d11a3
11e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===// 21e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// 31e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// The LLVM Compiler Infrastructure 41e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// 51e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// This file is distributed under the University of Illinois Open Source 61e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// License. See LICENSE.TXT for details. 71e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// 81e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner//===----------------------------------------------------------------------===// 91e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// 101e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// This file implements the Objective-C related Decl classes. 111e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// 121e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner//===----------------------------------------------------------------------===// 131e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 141e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner#include "clang/AST/DeclObjC.h" 151e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner#include "clang/AST/ASTContext.h" 16e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Stmt.h" 171e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattnerusing namespace clang; 181e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 196c4ae5de0c356777446f823b573821fb95560d91Chris Lattner//===----------------------------------------------------------------------===// 206c4ae5de0c356777446f823b573821fb95560d91Chris Lattner// ObjC Decl Allocation/Deallocation Method Implementations 216c4ae5de0c356777446f823b573821fb95560d91Chris Lattner//===----------------------------------------------------------------------===// 226c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 230ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, 240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation beginLoc, 256c4ae5de0c356777446f823b573821fb95560d91Chris Lattner SourceLocation endLoc, 266c4ae5de0c356777446f823b573821fb95560d91Chris Lattner Selector SelInfo, QualType T, 270701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *contextDecl, 28f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance, 296c4ae5de0c356777446f823b573821fb95560d91Chris Lattner bool isVariadic, 304607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized, 31b06fa3b86951b9f179c99c3768331536c32e902dChris Lattner ImplementationControl impControl) { 326c4ae5de0c356777446f823b573821fb95560d91Chris Lattner void *Mem = C.getAllocator().Allocate<ObjCMethodDecl>(); 330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return new (Mem) ObjCMethodDecl(beginLoc, endLoc, 340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SelInfo, T, contextDecl, 35f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar isInstance, 364607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian isVariadic, isSynthesized, impControl); 370e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner} 380e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 398a779314870760848e61da2c428a78971fe3f1c3Ted KremenekObjCMethodDecl::~ObjCMethodDecl() { 408a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek delete [] ParamInfo; 418a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek} 428a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 438a779314870760848e61da2c428a78971fe3f1c3Ted Kremenekvoid ObjCMethodDecl::Destroy(ASTContext& C) { 448a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (Body) Body->Destroy(C); 458a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (SelfDecl) SelfDecl->Destroy(C); 468a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 478a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) 488a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (*I) (*I)->Destroy(C); 498a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 508a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Decl::Destroy(C); 518a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek} 528a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 530ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, 540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation atLoc, 55d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff IdentifierInfo *Id, 56d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc, 570e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool ForwardDecl, bool isInternal){ 580e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner void *Mem = C.getAllocator().Allocate<ObjCInterfaceDecl>(); 59b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner return new (Mem) ObjCInterfaceDecl(atLoc, Id, ClassLoc, ForwardDecl, 600e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner isInternal); 610e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner} 626c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 63e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve NaroffObjCContainerDecl::~ObjCContainerDecl() { 64e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff} 65e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 66e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve NaroffObjCInterfaceDecl::~ObjCInterfaceDecl() { 67e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff delete [] Ivars; 688a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek delete [] PropertyDecl; 698a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek // FIXME: CategoryList? 708a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek} 718a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 728a779314870760848e61da2c428a78971fe3f1c3Ted Kremenekvoid ObjCInterfaceDecl::Destroy(ASTContext& C) { 738a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I) 748a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (*I) (*I)->Destroy(C); 758a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 768a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I) 778a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (*I) (*I)->Destroy(C); 788a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 798a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I) 808a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek if (*I) (*I)->Destroy(C); 811a726d7cbf62ab13949743e9ef8c0670dd862e46Ted Kremenek 821a726d7cbf62ab13949743e9ef8c0670dd862e46Ted Kremenek // FIXME: Because there is no clear ownership 831a726d7cbf62ab13949743e9ef8c0670dd862e46Ted Kremenek // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they 841a726d7cbf62ab13949743e9ef8c0670dd862e46Ted Kremenek // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. 851a726d7cbf62ab13949743e9ef8c0670dd862e46Ted Kremenek 868a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Decl::Destroy(C); 878a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek} 888a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 898a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 90b048c9835969c4f7fe06264748be18ed4b442116Chris LattnerObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, 91b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek IdentifierInfo *Id, QualType T, 92b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek AccessControl ac, Expr *BW) { 930e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>(); 94b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW); 956c4ae5de0c356777446f823b573821fb95560d91Chris Lattner} 966c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 9701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 9801e6779faca1e3a3164c697d6e2dfee0881a6981Ted KremenekObjCAtDefsFieldDecl 9944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, 10001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek IdentifierInfo *Id, QualType T, Expr *BW) { 10101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek void *Mem = C.getAllocator().Allocate<ObjCAtDefsFieldDecl>(); 10244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return new (Mem) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); 10301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek} 10401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 10501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekvoid ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { 10601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek this->~ObjCAtDefsFieldDecl(); 10701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek C.getAllocator().Deallocate((void *)this); 10801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek} 10901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 1100ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, 1110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 112c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner IdentifierInfo *Id) { 113cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>(); 114780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return new (Mem) ObjCProtocolDecl(L, Id); 115cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner} 116cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 1171c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted KremenekObjCProtocolDecl::~ObjCProtocolDecl() { 1181c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek delete [] PropertyDecl; 1191c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek} 1201c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1211c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenekvoid ObjCProtocolDecl::Destroy(ASTContext& C) { 1221c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1231c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek // Referenced Protocols are not owned, so don't Destroy them. 1241c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1251c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I) 1261c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek if (*I) (*I)->Destroy(C); 1271c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1281c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I) 1291c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek if (*I) (*I)->Destroy(C); 1301c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1311c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek // FIXME: Because there is no clear ownership 1321c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek // role between ObjCProtocolDecls and the ObjCPropertyDecls that they 1331c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. 1341c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1351c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek Decl::Destroy(C); 1361c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek} 1371c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1381c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1390ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, 1400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 14161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner ObjCInterfaceDecl **Elts, unsigned nElts) { 14261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner void *Mem = C.getAllocator().Allocate<ObjCClassDecl>(); 14361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner return new (Mem) ObjCClassDecl(L, Elts, nElts); 14461f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner} 14561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 146400d95fb7bb9fac609f8613862b84f3a2a7d510fTed KremenekObjCClassDecl::~ObjCClassDecl() { 147400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek delete [] ForwardDecls; 148400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek} 149400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 150400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenekvoid ObjCClassDecl::Destroy(ASTContext& C) { 151400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 152400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // FIXME: There is no clear ownership policy now for referenced 153400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // ObjCInterfaceDecls. Some of them can be forward declarations that 154400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // are never later defined (in which case the ObjCClassDecl owns them) 155400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // or the ObjCInterfaceDecl later becomes a real definition later. Ideally 156400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // we should have separate objects for forward declarations and definitions, 157400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // obviating this problem. Because of this situation, referenced 158400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek // ObjCInterfaceDecls are destroyed in ~TranslationUnit. 159400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 160400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek Decl::Destroy(C); 161400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek} 162400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 16361f9d41036e30ff80130f99b31c0626e3ef057ccChris LattnerObjCForwardProtocolDecl * 1640ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCForwardProtocolDecl::Create(ASTContext &C, 1650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 16661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner ObjCProtocolDecl **Elts, unsigned NumElts) { 16761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner void *Mem = C.getAllocator().Allocate<ObjCForwardProtocolDecl>(); 16861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner return new (Mem) ObjCForwardProtocolDecl(L, Elts, NumElts); 16961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner} 17061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 17105ac3ef08f9d06e0a4439073c9edabf7f912f946Ted KremenekObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() { 17205ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek delete [] ReferencedProtocols; 17305ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek} 17405ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek 1750ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, 1760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 17761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner IdentifierInfo *Id) { 17861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner void *Mem = C.getAllocator().Allocate<ObjCCategoryDecl>(); 17968c82cf61228102aba1194efef222fa1478af2a8Chris Lattner return new (Mem) ObjCCategoryDecl(L, Id); 18061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner} 18161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 18275c9cae5f85c72cbb1649e93849e16ede3f07522Chris LattnerObjCCategoryImplDecl * 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCCategoryImplDecl::Create(ASTContext &C, 1840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L,IdentifierInfo *Id, 18575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *ClassInterface) { 18675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner void *Mem = C.getAllocator().Allocate<ObjCCategoryImplDecl>(); 18775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner return new (Mem) ObjCCategoryImplDecl(L, Id, ClassInterface); 18875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner} 18975c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner 19075c9cae5f85c72cbb1649e93849e16ede3f07522Chris LattnerObjCImplementationDecl * 1910ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCImplementationDecl::Create(ASTContext &C, 1920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 19375c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner IdentifierInfo *Id, 19475c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *ClassInterface, 19575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *SuperDecl) { 19675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner void *Mem = C.getAllocator().Allocate<ObjCImplementationDecl>(); 19775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner return new (Mem) ObjCImplementationDecl(L, Id, ClassInterface, SuperDecl); 19875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner} 1991e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 200f8d17a59167d9c2026506ed8813ea434d93b662aChris LattnerObjCCompatibleAliasDecl * 2010ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCCompatibleAliasDecl::Create(ASTContext &C, 2020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, 203f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner IdentifierInfo *Id, 204f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl* AliasedClass) { 205f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner void *Mem = C.getAllocator().Allocate<ObjCCompatibleAliasDecl>(); 206f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner return new (Mem) ObjCCompatibleAliasDecl(L, Id, AliasedClass); 207f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner} 208f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 2090ed844b04ea4387caa4e1cf3dc375d269657536bChris LattnerObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, 210dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian SourceLocation L, 2111de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian IdentifierInfo *Id, 21246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian QualType T, 21346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl propControl) { 214f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>(); 2151de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian return new (Mem) ObjCPropertyDecl(L, Id, T); 216f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner} 217f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 2181e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner//===----------------------------------------------------------------------===// 2191e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// Objective-C Decl Implementation 2201e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner//===----------------------------------------------------------------------===// 2211e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 222fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanianvoid ObjCMethodDecl::createImplicitParams(ASTContext &Context, 223fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCInterfaceDecl *OID) { 22408a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar QualType selfTy; 22508a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar if (isInstance()) { 22608a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar // There may be no interface context due to error in declaration 22708a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar // of the interface (which has been reported). Recover gracefully. 228fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian if (OID) { 229fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian selfTy = Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl *>(OID)); 23008a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar selfTy = Context.getPointerType(selfTy); 23108a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar } else { 23208a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar selfTy = Context.getObjCIdType(); 23308a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar } 23408a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar } else // we have a factory method. 23508a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar selfTy = Context.getObjCClassType(); 23608a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar 23708a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar SelfDecl = ImplicitParamDecl::Create(Context, this, 23808a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar SourceLocation(), 23908a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar &Context.Idents.get("self"), 24008a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar selfTy, 0); 24108a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar 24208a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar CmdDecl = ImplicitParamDecl::Create(Context, this, 24308a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar SourceLocation(), 24408a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar &Context.Idents.get("_cmd"), 24508a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar Context.getObjCSelType(), 0); 24608a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar} 24708a356cc2b98cff990ef6969e819a214443d7f8fDaniel Dunbar 2481e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattnervoid ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, 2491e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner unsigned NumParams) { 2501e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner assert(ParamInfo == 0 && "Already has param info!"); 2511e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 2521e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Zero params -> null pointer. 2531e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if (NumParams) { 2541e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ParamInfo = new ParmVarDecl*[NumParams]; 2551e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); 2561e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner NumMethodParams = NumParams; 2571e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 2581e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 2591e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 26031afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian/// isPropertyReadonly - Return true if property is a readonly, by seaching 26131afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian/// for the property in the class and in its categories. 26231afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian/// 26331afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanianbool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const 26431afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian{ 26531afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian if (PDecl->isReadOnly()) { 26631afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian // Main class has the property as 'readyonly'. Must search 26731afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian // through the category list to see if the property's 26831afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian // attribute has been over-ridden to 'readwrite'. 26931afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian for (ObjCCategoryDecl *Category = getCategoryList(); 27031afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian Category; Category = Category->getNextClassCategory()) { 27131afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian PDecl= Category->FindPropertyDeclaration(PDecl->getIdentifier()); 27231afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian if (PDecl && !PDecl->isReadOnly()) 27331afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian return false; 27431afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian } 27531afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian return true; 27631afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian } 27731afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian return false; 27831afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian} 27931afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian 280559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// FindPropertyDeclaration - Finds declaration of the property given its name 281559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// in 'PropertyId' and returns it. It returns 0, if not found. 282559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// 283559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz JahanianObjCPropertyDecl * 284559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCInterfaceDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { 285559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian for (ObjCInterfaceDecl::classprop_iterator I = classprop_begin(), 286559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian E = classprop_end(); I != E; ++I) { 287559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCPropertyDecl *property = *I; 288559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian if (property->getIdentifier() == PropertyId) 289559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return property; 290559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 2916c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff // Look through categories. 2926c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff for (ObjCCategoryDecl *Category = getCategoryList(); 2936c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff Category; Category = Category->getNextClassCategory()) { 2946c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId); 2956c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff if (property) 2966c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff return property; 2976c930f2ac0af05a120a39cb780b50d4a293abdfcSteve Naroff } 2983d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff // Look through protocols. 2993d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff for (ObjCInterfaceDecl::protocol_iterator I = protocol_begin(), 3003d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff E = protocol_end(); I != E; ++I) { 3013d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff ObjCProtocolDecl *Protocol = *I; 3023d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); 3033d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff if (property) 3043d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff return property; 3053d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff } 306c70bee863b6f800d7c88f409e89dc85ed867ef64Fariborz Jahanian if (getSuperClass()) 307c70bee863b6f800d7c88f409e89dc85ed867ef64Fariborz Jahanian return getSuperClass()->FindPropertyDeclaration(PropertyId); 308559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return 0; 309559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian} 310559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 311559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// FindCategoryDeclaration - Finds category declaration in the list of 312559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// categories for this class and returns it. Name of the category is passed 313559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// in 'CategoryId'. If category not found, return 0; 314559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// 315559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz JahanianObjCCategoryDecl * 316559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { 317559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian for (ObjCCategoryDecl *Category = getCategoryList(); 318559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian Category; Category = Category->getNextClassCategory()) 319559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian if (Category->getIdentifier() == CategoryId) 320559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return Category; 321559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return 0; 322559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian} 323559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 324559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// FindIvarDeclaration - Find an Ivar declaration in this class given its 325559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// name in 'IvarId'. On failure to find, return 0; 326559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// 327559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz JahanianObjCIvarDecl * 328559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCInterfaceDecl::FindIvarDeclaration(IdentifierInfo *IvarId) const { 329559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator IVI = ivar_begin(), 330559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian IVE = ivar_end(); IVI != IVE; ++IVI) { 331559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCIvarDecl* Ivar = (*IVI); 332559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian if (Ivar->getIdentifier() == IvarId) 333559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return Ivar; 334559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 335c70bee863b6f800d7c88f409e89dc85ed867ef64Fariborz Jahanian if (getSuperClass()) 336c70bee863b6f800d7c88f409e89dc85ed867ef64Fariborz Jahanian return getSuperClass()->FindIvarDeclaration(IvarId); 337559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return 0; 338559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian} 339559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 3401e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// ObjCAddInstanceVariablesToClass - Inserts instance variables 3411e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// into ObjCInterfaceDecl's fields. 3421e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// 3431e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattnervoid ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars, 3441e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner unsigned numIvars, 3451e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner SourceLocation RBrac) { 3461e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner NumIvars = numIvars; 3471e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if (numIvars) { 3481e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner Ivars = new ObjCIvarDecl*[numIvars]; 3491e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); 3501e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 3511e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner setLocEnd(RBrac); 3521e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 3531e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 354aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian/// lookupFieldDeclForIvar - looks up a field decl' in the laid out 355aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian/// storage which matches this 'ivar'. 356aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian/// 357aaa63a761c6671a08e3f4f463435b72739fa194bFariborz JahanianFieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, 358fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian const ObjCIvarDecl *ivar) { 359a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian const RecordDecl *RecordForDecl = Context.addRecordToClass(this); 360aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class"); 361aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian DeclarationName Member = ivar->getDeclName(); 362a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian DeclContext::lookup_result Lookup = (const_cast< RecordDecl *>(RecordForDecl)) 3630701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ->lookup(Member); 364aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian assert((Lookup.first != Lookup.second) && "field decl not found"); 365aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first); 366aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian assert(MemberDecl && "field decl not found"); 367aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian return MemberDecl; 368aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian} 369aaa63a761c6671a08e3f4f463435b72739fa194bFariborz Jahanian 3701e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance 3711e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// Variables (Ivars) relative to what declared in @implementation;s class. 3721e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// Ivars into ObjCImplementationDecl's fields. 3731e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// 3741e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattnervoid ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( 3751e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCIvarDecl **ivars, unsigned numIvars) { 3761e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner NumIvars = numIvars; 3771e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if (numIvars) { 3781e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner Ivars = new ObjCIvarDecl*[numIvars]; 3791e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); 3801e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 3811e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 3821e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 3837e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian/// addProperties - Insert property declaration AST nodes into 3847e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian/// ObjCInterfaceDecl's PropertyDecl field. 38555d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner/// 38655d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattnervoid ObjCInterfaceDecl::addProperties(ObjCPropertyDecl **Properties, 38755d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner unsigned NumProperties) { 38855d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner if (NumProperties == 0) return; 38955d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner 39055d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner NumPropertyDecl = NumProperties; 39155d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner PropertyDecl = new ObjCPropertyDecl*[NumProperties]; 39255d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*)); 39355d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner} 39455d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner 395aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian/// mergeProperties - Adds properties to the end of list of current properties 396aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian/// for this class. 397aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 398aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanianvoid ObjCInterfaceDecl::mergeProperties(ObjCPropertyDecl **Properties, 399aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian unsigned NumNewProperties) { 400aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian if (NumNewProperties == 0) return; 401aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 402aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian if (PropertyDecl) { 403aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian ObjCPropertyDecl **newPropertyDecl = 404aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian new ObjCPropertyDecl*[NumNewProperties + NumPropertyDecl]; 405aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian ObjCPropertyDecl **buf = newPropertyDecl; 406aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian // put back original properties in buffer. 407aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian memcpy(buf, PropertyDecl, NumPropertyDecl*sizeof(ObjCPropertyDecl*)); 408aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian // Add new properties to this buffer. 409aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian memcpy(buf+NumPropertyDecl, Properties, 410aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian NumNewProperties*sizeof(ObjCPropertyDecl*)); 4116b3502c5c3eba1d3da40c4c78b31f4d8cffec051Nuno Lopes delete[] PropertyDecl; 412aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian PropertyDecl = newPropertyDecl; 413aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian NumPropertyDecl += NumNewProperties; 414aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 415aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian else { 4166b3502c5c3eba1d3da40c4c78b31f4d8cffec051Nuno Lopes addProperties(Properties, NumNewProperties); 417aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 418aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian} 419aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 4200701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff// Get the local instance method declared in this interface. 4210701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff// FIXME: handle overloading, instance & class methods can have the same name. 4220701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve NaroffObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const { 4230701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_const_result MethodResult = lookup(Sel); 4240701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff if (MethodResult.first) 4250701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return const_cast<ObjCMethodDecl*>( 4260701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff dyn_cast<ObjCMethodDecl>(*MethodResult.first)); 4270701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return 0; 4280701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff} 4290701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 4300701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff// Get the local class method declared in this interface. 4310701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve NaroffObjCMethodDecl *ObjCContainerDecl::getClassMethod(Selector Sel) const { 4320701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_const_result MethodResult = lookup(Sel); 4330701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff if (MethodResult.first) 4340701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return const_cast<ObjCMethodDecl*>( 4350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff dyn_cast<ObjCMethodDecl>(*MethodResult.first)); 4360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return 0; 4370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff} 4380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 4390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffunsigned ObjCContainerDecl::getNumInstanceMethods() const { 4400701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff unsigned sum = 0; 4410701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I != E; ++I) 4420701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff sum++; 4430701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return sum; 4440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff} 4450701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffunsigned ObjCContainerDecl::getNumClassMethods() const { 4460701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff unsigned sum = 0; 4470701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I != E; ++I) 4480701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff sum++; 4490701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return sum; 4500701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff} 4510701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 4520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// addPropertyMethods - Goes through list of properties declared in this class 4530701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// and builds setter/getter method declartions depending on the setter/getter 4540701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// attributes of the property. 4550701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// 4560701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffvoid ObjCContainerDecl::getPropertyMethods( 4570701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ASTContext &Context, ObjCPropertyDecl *property, 4580701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ObjCMethodDecl *& GetterDecl, ObjCMethodDecl *&SetterDecl) { 4593216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar // FIXME: The synthesized property we set here is misleading. We 4603216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar // almost always synthesize these methods unless the user explicitly 4613216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar // provided prototypes (which is odd, but allowed). Sema should be 4623216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar // typechecking that the declarations jive in that situation (which 4633216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar // it is not currently). 4643216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar 46533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian // Find the default getter and if one not found, add one. 4664d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar if (!GetterDecl) { 46733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian // No instance method of same name as property getter name was found. 46833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian // Declare a getter method and add it to the list of methods 46933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian // for this class. 4704d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar GetterDecl = 4714d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar ObjCMethodDecl::Create(Context, property->getLocation(), 4724d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getLocation(), 4734d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getGetterName(), 4740701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff property->getType(), this, 475669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian true, false, true, 476669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian (property->getPropertyImplementation() == 477669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCPropertyDecl::Optional) ? 478669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCMethodDecl::Optional : 479669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCMethodDecl::Required); 4804d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar } 48191b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian else 48291b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian // A user declared getter will be synthesize when @synthesize of 48391b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian // the property with the same name is seen in the @implementation 48491b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian GetterDecl->setIsSynthesized(); 4854d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->setGetterMethodDecl(GetterDecl); 4864d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar 487394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar // Skip setter if property is read-only. 488394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar if (property->isReadOnly()) 489394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar return; 490394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar 4914d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // Find the default setter and if one not found, add one. 4924d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar if (!SetterDecl) { 4934d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // No instance method of same name as property setter name was found. 4944d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // Declare a setter method and add it to the list of methods 4954d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // for this class. 4964d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SetterDecl = 4974d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar ObjCMethodDecl::Create(Context, property->getLocation(), 4984d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getLocation(), 4994d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getSetterName(), 5000701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff Context.VoidTy, this, 501669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian true, false, true, 502669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian (property->getPropertyImplementation() == 503669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCPropertyDecl::Optional) ? 504669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCMethodDecl::Optional : 505669e8d3c6a89c1ff45500d36dde7011b3cf7af7cFariborz Jahanian ObjCMethodDecl::Required); 5064d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // Invent the arguments for the setter. We don't bother making a 5074d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar // nice name for the argument. 5084d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar ParmVarDecl *Argument = ParmVarDecl::Create(Context, 5094d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SetterDecl, 5104d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SourceLocation(), 5114d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getIdentifier(), 5124d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->getType(), 5134d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar VarDecl::None, 5144d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar 0, 0); 5154d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SetterDecl->setMethodParams(&Argument, 1); 51633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian } 51791b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian else 51891b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian // A user declared setter will be synthesize when @synthesize of 51991b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian // the property with the same name is seen in the @implementation 52091b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian SetterDecl->setIsSynthesized(); 5214d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar property->setSetterMethodDecl(SetterDecl); 52233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian} 52333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 5241ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian/// mergeProperties - Adds properties to the end of list of current properties 5251ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian/// for this category. 5261ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian 5271ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanianvoid ObjCCategoryDecl::mergeProperties(ObjCPropertyDecl **Properties, 5281ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian unsigned NumNewProperties) { 5291ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian if (NumNewProperties == 0) return; 5301ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian 5311ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian if (PropertyDecl) { 5321ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian ObjCPropertyDecl **newPropertyDecl = 5331ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian new ObjCPropertyDecl*[NumNewProperties + NumPropertyDecl]; 5341ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian ObjCPropertyDecl **buf = newPropertyDecl; 5351ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian // put back original properties in buffer. 5361ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian memcpy(buf, PropertyDecl, NumPropertyDecl*sizeof(ObjCPropertyDecl*)); 5371ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian // Add new properties to this buffer. 5381ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian memcpy(buf+NumPropertyDecl, Properties, 5391ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian NumNewProperties*sizeof(ObjCPropertyDecl*)); 5401ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian delete[] PropertyDecl; 5411ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian PropertyDecl = newPropertyDecl; 5421ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian NumPropertyDecl += NumNewProperties; 5431ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian } 5441ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian else { 5451ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian addProperties(Properties, NumNewProperties); 5461ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian } 5471ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian} 5481ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian 5497e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian/// addProperties - Insert property declaration AST nodes into 5503dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian/// ObjCProtocolDecl's PropertyDecl field. 5513dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian/// 5523dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanianvoid ObjCProtocolDecl::addProperties(ObjCPropertyDecl **Properties, 5533dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian unsigned NumProperties) { 5543dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian if (NumProperties == 0) return; 5553dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian 5563dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian NumPropertyDecl = NumProperties; 5573dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian PropertyDecl = new ObjCPropertyDecl*[NumProperties]; 5583dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*)); 5593dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian} 5603dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian 5613dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian/// addProperties - Insert property declaration AST nodes into 562d9a3c330b02c52630014dc26fc009236facf8227Fariborz Jahanian/// ObjCCategoryDecl's PropertyDecl field. 5637e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian/// 5647e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanianvoid ObjCCategoryDecl::addProperties(ObjCPropertyDecl **Properties, 5657e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian unsigned NumProperties) { 5667e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian if (NumProperties == 0) return; 5677e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian 5687e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian NumPropertyDecl = NumProperties; 5697e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian PropertyDecl = new ObjCPropertyDecl*[NumProperties]; 5707e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*)); 5717e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian} 5727e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian 573559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// FindPropertyDeclaration - Finds declaration of the property given its name 574559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// in 'PropertyId' and returns it. It returns 0, if not found. 575559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// 576559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz JahanianObjCPropertyDecl * 577559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz JahanianObjCCategoryDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { 578559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian for (ObjCCategoryDecl::classprop_iterator I = classprop_begin(), 579559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian E = classprop_end(); I != E; ++I) { 580559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCPropertyDecl *property = *I; 581559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian if (property->getIdentifier() == PropertyId) 582559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return property; 5833d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff } 5843d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff return 0; 5853d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff} 5863d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff 5873d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff/// FindPropertyDeclaration - Finds declaration of the property given its name 5883d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff/// in 'PropertyId' and returns it. It returns 0, if not found. 5893d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff/// 5903d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve NaroffObjCPropertyDecl * 5913d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve NaroffObjCProtocolDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { 5923d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff for (ObjCProtocolDecl::classprop_iterator I = classprop_begin(), 5933d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff E = classprop_end(); I != E; ++I) { 5943d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff ObjCPropertyDecl *property = *I; 5953d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff if (property->getIdentifier() == PropertyId) 5963d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff return property; 597559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 598559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return 0; 599559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian} 600559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 6011e03a561f4bd96910cb31a8af53a6ad321a12b51Chris LattnerObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable( 6021e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) { 6031e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCInterfaceDecl* ClassDecl = this; 6041e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner while (ClassDecl != NULL) { 6051e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end(); 6061e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner I != E; ++I) { 6071e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((*I)->getIdentifier() == ID) { 6081e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner clsDeclared = ClassDecl; 6091e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return *I; 6101e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6111e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6121e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ClassDecl = ClassDecl->getSuperClass(); 6131e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6141e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 6151e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 6161e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6171e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// lookupInstanceMethod - This method returns an instance method by looking in 6181e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// the class, its categories, and its super classes (using a linear search). 6191e03a561f4bd96910cb31a8af53a6ad321a12b51Chris LattnerObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) { 6201e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCInterfaceDecl* ClassDecl = this; 6211e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCMethodDecl *MethodDecl = 0; 6221e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6231e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner while (ClassDecl != NULL) { 6241e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = ClassDecl->getInstanceMethod(Sel))) 6251e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 6261e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6271e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Didn't find one yet - look through protocols. 6283db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner const ObjCList<ObjCProtocolDecl> &Protocols = 6293db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner ClassDecl->getReferencedProtocols(); 6303db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 6313db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner E = Protocols.end(); I != E; ++I) 6323db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner if ((MethodDecl = (*I)->getInstanceMethod(Sel))) 6331e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 6343db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 6351e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Didn't find one yet - now look through categories. 6361e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); 6371e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner while (CatDecl) { 6381e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = CatDecl->getInstanceMethod(Sel))) 6391e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 640b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff 641b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff // Didn't find one yet - look through protocols. 642b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff const ObjCList<ObjCProtocolDecl> &Protocols = 643b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff CatDecl->getReferencedProtocols(); 644b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 645b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff E = Protocols.end(); I != E; ++I) 646b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff if ((MethodDecl = (*I)->getInstanceMethod(Sel))) 647b79c01ea321687d8b9e82968395f30c5c261a6b0Steve Naroff return MethodDecl; 6481e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner CatDecl = CatDecl->getNextClassCategory(); 6491e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6501e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ClassDecl = ClassDecl->getSuperClass(); 6511e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6521e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 6531e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 6541e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6551e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// lookupClassMethod - This method returns a class method by looking in the 6561e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// class, its categories, and its super classes (using a linear search). 6571e03a561f4bd96910cb31a8af53a6ad321a12b51Chris LattnerObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { 6581e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCInterfaceDecl* ClassDecl = this; 6591e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCMethodDecl *MethodDecl = 0; 6601e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6611e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner while (ClassDecl != NULL) { 6621e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = ClassDecl->getClassMethod(Sel))) 6631e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 6641e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6651e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Didn't find one yet - look through protocols. 666780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), 667780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner E = ClassDecl->protocol_end(); I != E; ++I) 6683db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner if ((MethodDecl = (*I)->getClassMethod(Sel))) 6691e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 670780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 6711e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Didn't find one yet - now look through categories. 6721e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); 6731e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner while (CatDecl) { 6741e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = CatDecl->getClassMethod(Sel))) 6751e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 6761e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner CatDecl = CatDecl->getNextClassCategory(); 6771e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6781e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ClassDecl = ClassDecl->getSuperClass(); 6791e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner } 6801e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 6811e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 6821e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6833216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// getInstanceMethod - This method returns an instance method by 6843216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// looking in the class implementation. Unlike interfaces, we don't 6853216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// look outside the implementation. 6863216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel DunbarObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) const { 6871e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) 6881e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((*I)->getSelector() == Sel) 6891e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return *I; 6901e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 6911e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 6921e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 6933216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// getClassMethod - This method returns a class method by looking in 6943216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// the class implementation. Unlike interfaces, we don't look outside 6953216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar/// the implementation. 6963216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel DunbarObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) const { 6971e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); 6981e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner I != E; ++I) 6991e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((*I)->getSelector() == Sel) 7001e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return *I; 7011e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 7021e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 7031e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 704ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl 705ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// added to the list of those properties @synthesized/@dynamic in this 706ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// @implementation block. 707ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// 708ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz JahanianObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplDecl(IdentifierInfo *Id) const { 709ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { 710ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *PID = *i; 711ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian if (PID->getPropertyDecl()->getIdentifier() == Id) 712ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return PID; 713ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian } 714ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return 0; 715ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian} 716ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 717ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of 7189482a4f0feca4bc9eb7c6ad36e21cbf7365f5359Fariborz Jahanian/// properties implemented in this @implementation block and returns the 7199482a4f0feca4bc9eb7c6ad36e21cbf7365f5359Fariborz Jahanian/// implemented property that uses it. 720ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// 721ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz JahanianObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { 722ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { 723ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *PID = *i; 724ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian if (PID->getPropertyIvarDecl() && 725ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian PID->getPropertyIvarDecl()->getIdentifier() == ivarId) 726ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return PID; 727ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian } 728ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return 0; 729ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian} 730ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 731ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of 7329482a4f0feca4bc9eb7c6ad36e21cbf7365f5359Fariborz Jahanian/// properties implemented in this category @implementation block and returns the 7339482a4f0feca4bc9eb7c6ad36e21cbf7365f5359Fariborz Jahanian/// implemented property that uses it. 734ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// 735ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz JahanianObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { 736ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { 737ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *PID = *i; 738ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian if (PID->getPropertyIvarDecl() && 739ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian PID->getPropertyIvarDecl()->getIdentifier() == ivarId) 740ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return PID; 741ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian } 742ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return 0; 743ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian} 744ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 745ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl 746ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// added to the list of those properties @synthesized/@dynamic in this 747ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// category @implementation block. 748ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian/// 749ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz JahanianObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplDecl(IdentifierInfo *Id) const { 750ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { 751ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *PID = *i; 752ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian if (PID->getPropertyDecl()->getIdentifier() == Id) 753ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return PID; 754ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian } 755ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian return 0; 756ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian} 757ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 7581e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// lookupInstanceMethod - This method returns an instance method by looking in 7591e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// the class implementation. Unlike interfaces, we don't look outside the 7601e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// implementation. 7613216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel DunbarObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) const { 7621e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) 7631e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((*I)->getSelector() == Sel) 7641e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return *I; 7651e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 7661e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 7671e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 7681e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// lookupClassMethod - This method returns an instance method by looking in 7691e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// the class implementation. Unlike interfaces, we don't look outside the 7701e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// implementation. 7713216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel DunbarObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) const { 7721e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); 7731e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner I != E; ++I) 7741e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((*I)->getSelector() == Sel) 7751e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return *I; 7761e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 7771e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 7781e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 7791e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// lookupInstanceMethod - Lookup a instance method in the protocol and protocols 7801e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// it inherited. 7811e03a561f4bd96910cb31a8af53a6ad321a12b51Chris LattnerObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { 7821e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCMethodDecl *MethodDecl = NULL; 7831e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 7841e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = getInstanceMethod(Sel))) 7851e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 7861e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 787780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) 788d8df6823420c22329a2a9aacd2a440368d38d86cSteve Naroff if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) 789780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return MethodDecl; 7901e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 7911e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 7921e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 7931e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// lookupInstanceMethod - Lookup a class method in the protocol and protocols 7941e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner// it inherited. 7951e03a561f4bd96910cb31a8af53a6ad321a12b51Chris LattnerObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { 7961e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner ObjCMethodDecl *MethodDecl = NULL; 7971e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 7981e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if ((MethodDecl = getClassMethod(Sel))) 7991e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return MethodDecl; 8001e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 801780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) 802d8df6823420c22329a2a9aacd2a440368d38d86cSteve Naroff if ((MethodDecl = (*I)->lookupClassMethod(Sel))) 803780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return MethodDecl; 8041e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return NULL; 8051e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 8061e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 8071e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// getSynthesizedMethodSize - Compute size of synthesized method name 8081e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// as done be the rewrite. 8091e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner/// 8101e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattnerunsigned ObjCMethodDecl::getSynthesizedMethodSize() const { 8111e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // syntesized method name is a concatenation of -/+[class-name selector] 8121e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner // Get length of this name. 8131e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner unsigned length = 3; // _I_ or _C_ 8148ec03f58c33c33a917f54bb7f2cd61b6d7ffe0caChris Lattner length += getClassInterface()->getNameAsString().size()+1; // extra for _ 8153e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff if (const ObjCCategoryImplDecl *CID = 8163e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) 8178ec03f58c33c33a917f54bb7f2cd61b6d7ffe0caChris Lattner length += CID->getNameAsString().size()+1; 818077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner length += getSelector().getAsString().size(); // selector name 8191e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return length; 8201e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 8211e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner 8225619688510185081cbb4621d703daf7ee24cf39aChris LattnerObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { 8233e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) 8241e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return ID; 8253e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) 8261e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return CD->getClassInterface(); 8271e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner if (ObjCImplementationDecl *IMD = 8283e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff dyn_cast<ObjCImplementationDecl>(getDeclContext())) 8291e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return IMD->getClassInterface(); 8303e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff if (ObjCCategoryImplDecl *CID = 8313e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) 8321e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return CID->getClassInterface(); 8331e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner assert(false && "unknown method context"); 8341e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner return 0; 8351e03a561f4bd96910cb31a8af53a6ad321a12b51Chris Lattner} 836f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner 837628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz JahanianObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, 838628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian SourceLocation atLoc, 839628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian SourceLocation L, 840628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCPropertyDecl *property, 8419f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind PK, 842628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivar) { 843628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian void *Mem = C.getAllocator().Allocate<ObjCPropertyImplDecl>(); 8449f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar return new (Mem) ObjCPropertyImplDecl(atLoc, L, property, PK, ivar); 845628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian} 846f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner 8470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 848