blob: ffda505aaab1904449dc10e10bc093ae9316883e [file] [log] [blame]
Chris Lattner1e03a562008-03-16 00:19:01 +00001//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C related Decl classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclObjC.h"
15#include "clang/AST/ASTContext.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000016#include "clang/AST/Stmt.h"
Steve Naroff0de21fd2009-02-22 19:35:57 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattner1e03a562008-03-16 00:19:01 +000018using namespace clang;
19
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000020//===----------------------------------------------------------------------===//
Chris Lattner11e1e1a2009-02-20 21:16:26 +000021// ObjCListBase
22//===----------------------------------------------------------------------===//
23
Chris Lattner38af2de2009-02-20 21:35:13 +000024void ObjCListBase::Destroy(ASTContext &Ctx) {
Chris Lattner4ee413b2009-02-20 21:44:01 +000025 Ctx.Deallocate(List);
Chris Lattner11e1e1a2009-02-20 21:16:26 +000026 NumElts = 0;
27 List = 0;
28}
29
Chris Lattner38af2de2009-02-20 21:35:13 +000030void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Chris Lattner11e1e1a2009-02-20 21:16:26 +000031 assert(List == 0 && "Elements already set!");
32 if (Elts == 0) return; // Setting to an empty list is a noop.
Mike Stump1eb44332009-09-09 15:08:12 +000033
34
Chris Lattner4ee413b2009-02-20 21:44:01 +000035 List = new (Ctx) void*[Elts];
Chris Lattner11e1e1a2009-02-20 21:16:26 +000036 NumElts = Elts;
37 memcpy(List, InList, sizeof(void*)*Elts);
38}
39
Douglas Gregor18df52b2010-01-16 15:02:53 +000040void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
41 const SourceLocation *Locs, ASTContext &Ctx) {
42 if (Elts == 0)
43 return;
44
45 Locations = new (Ctx) SourceLocation[Elts];
46 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
47 set(InList, Elts, Ctx);
48}
49
50void ObjCProtocolList::Destroy(ASTContext &Ctx) {
51 Ctx.Deallocate(Locations);
52 Locations = 0;
53 ObjCList<ObjCProtocolDecl>::Destroy(Ctx);
54}
Chris Lattner11e1e1a2009-02-20 21:16:26 +000055
56//===----------------------------------------------------------------------===//
Chris Lattnerab351632009-02-20 20:59:54 +000057// ObjCInterfaceDecl
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000058//===----------------------------------------------------------------------===//
59
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000060/// getIvarDecl - This method looks up an ivar in this ContextDecl.
61///
62ObjCIvarDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000063ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000064 lookup_const_iterator Ivar, IvarEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000065 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000066 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
67 return ivar;
68 }
69 return 0;
70}
71
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000072// Get the local instance/class method declared in this interface.
Douglas Gregor6ab35242009-04-09 21:40:53 +000073ObjCMethodDecl *
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000074ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
Steve Naroff0de21fd2009-02-22 19:35:57 +000075 // Since instance & class methods can have the same name, the loop below
76 // ensures we get the correct method.
77 //
78 // @interface Whatever
79 // - (int) class_method;
80 // + (float) class_method;
81 // @end
82 //
83 lookup_const_iterator Meth, MethEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000084 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
Steve Naroff0de21fd2009-02-22 19:35:57 +000085 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000086 if (MD && MD->isInstanceMethod() == isInstance)
Steve Naroff0de21fd2009-02-22 19:35:57 +000087 return MD;
88 }
Steve Naroff0701bbb2009-01-08 17:28:14 +000089 return 0;
90}
91
Fariborz Jahanian559c0c42008-04-21 19:04:53 +000092/// FindPropertyDeclaration - Finds declaration of the property given its name
93/// in 'PropertyId' and returns it. It returns 0, if not found.
Steve Naroff93983f82009-01-11 12:47:58 +000094/// FIXME: Convert to DeclContext lookup...
Fariborz Jahanian559c0c42008-04-21 19:04:53 +000095///
96ObjCPropertyDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000097ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
98 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
Chris Lattnerab351632009-02-20 20:59:54 +000099 if ((*I)->getIdentifier() == PropertyId)
100 return *I;
Mike Stump1eb44332009-09-09 15:08:12 +0000101
Fariborz Jahaniana66793e2009-01-09 21:04:52 +0000102 const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this);
103 if (PID) {
Mike Stump1eb44332009-09-09 15:08:12 +0000104 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
Chris Lattnerab351632009-02-20 20:59:54 +0000105 E = PID->protocol_end(); I != E; ++I)
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000106 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerab351632009-02-20 20:59:54 +0000107 return P;
Fariborz Jahaniana66793e2009-01-09 21:04:52 +0000108 }
Mike Stump1eb44332009-09-09 15:08:12 +0000109
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000110 if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
Steve Naroff09c47192009-01-09 15:36:25 +0000111 // Look through categories.
112 for (ObjCCategoryDecl *Category = OID->getCategoryList();
113 Category; Category = Category->getNextClassCategory()) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000114 if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId))
Chris Lattnerab351632009-02-20 20:59:54 +0000115 return P;
Steve Naroff09c47192009-01-09 15:36:25 +0000116 }
117 // Look through protocols.
118 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
119 E = OID->protocol_end(); I != E; ++I) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000120 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerab351632009-02-20 20:59:54 +0000121 return P;
Steve Naroff09c47192009-01-09 15:36:25 +0000122 }
123 if (OID->getSuperClass())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000124 return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
Chris Lattnerab351632009-02-20 20:59:54 +0000125 } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000126 // Look through protocols.
127 for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
128 E = OCD->protocol_end(); I != E; ++I) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000129 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerab351632009-02-20 20:59:54 +0000130 return P;
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000131 }
132 }
Steve Naroff3d2c22b2008-06-05 13:55:23 +0000133 return 0;
134}
135
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000136/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
137/// with name 'PropertyId' in the primary class; including those in protocols
138/// (direct or indirect) used by the promary class.
139/// FIXME: Convert to DeclContext lookup...
140///
141ObjCPropertyDecl *
142ObjCContainerDecl::FindPropertyVisibleInPrimaryClass(
143 IdentifierInfo *PropertyId) const {
144 assert(isa<ObjCInterfaceDecl>(this) && "FindPropertyVisibleInPrimaryClass");
145 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
146 if ((*I)->getIdentifier() == PropertyId)
147 return *I;
148 const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this);
149 // Look through protocols.
150 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
151 E = OID->protocol_end(); I != E; ++I)
152 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
153 return P;
154 return 0;
155}
156
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000157void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
158 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000159 const SourceLocation *Locs,
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000160 ASTContext &C)
161{
162 if (ReferencedProtocols.empty()) {
Douglas Gregor18df52b2010-01-16 15:02:53 +0000163 ReferencedProtocols.set(ExtList, ExtNum, Locs, C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000164 return;
165 }
166 // Check for duplicate protocol in class's protocol list.
167 // This is (O)2. But it is extremely rare and number of protocols in
168 // class or its extension are very few.
169 llvm::SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000170 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000171 for (unsigned i = 0; i < ExtNum; i++) {
172 bool protocolExists = false;
173 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
174 for (protocol_iterator p = protocol_begin(), e = protocol_end();
175 p != e; p++) {
176 ObjCProtocolDecl *Proto = (*p);
177 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
178 protocolExists = true;
179 break;
180 }
181 }
182 // Do we want to warn on a protocol in extension class which
183 // already exist in the class? Probably not.
Douglas Gregor18df52b2010-01-16 15:02:53 +0000184 if (!protocolExists) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000185 ProtocolRefs.push_back(ProtoInExtension);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000186 ProtocolLocs.push_back(Locs[i]);
187 }
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000188 }
189 if (ProtocolRefs.empty())
190 return;
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000191 // Merge ProtocolRefs into class's protocol list;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000192 protocol_loc_iterator pl = protocol_loc_begin();
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000193 for (protocol_iterator p = protocol_begin(), e = protocol_end();
Douglas Gregor18df52b2010-01-16 15:02:53 +0000194 p != e; ++p, ++pl) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000195 ProtocolRefs.push_back(*p);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000196 ProtocolLocs.push_back(*pl);
197 }
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000198 ReferencedProtocols.Destroy(C);
199 unsigned NumProtoRefs = ProtocolRefs.size();
Douglas Gregor18df52b2010-01-16 15:02:53 +0000200 setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000201}
202
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000203ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
204 ObjCInterfaceDecl *&clsDeclared) {
Chris Lattner1e03a562008-03-16 00:19:01 +0000205 ObjCInterfaceDecl* ClassDecl = this;
206 while (ClassDecl != NULL) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000207 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +0000208 clsDeclared = ClassDecl;
209 return I;
Chris Lattner1e03a562008-03-16 00:19:01 +0000210 }
211 ClassDecl = ClassDecl->getSuperClass();
212 }
213 return NULL;
214}
215
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000216/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
217/// class whose name is passed as argument. If it is not one of the super classes
218/// the it returns NULL.
219ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
220 const IdentifierInfo*ICName) {
221 ObjCInterfaceDecl* ClassDecl = this;
222 while (ClassDecl != NULL) {
223 if (ClassDecl->getIdentifier() == ICName)
224 return ClassDecl;
225 ClassDecl = ClassDecl->getSuperClass();
226 }
227 return NULL;
228}
229
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000230/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner1e03a562008-03-16 00:19:01 +0000231/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000232ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
233 bool isInstance) const {
234 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner1e03a562008-03-16 00:19:01 +0000235 ObjCMethodDecl *MethodDecl = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000236
Chris Lattner1e03a562008-03-16 00:19:01 +0000237 while (ClassDecl != NULL) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000238 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000239 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000240
Chris Lattner1e03a562008-03-16 00:19:01 +0000241 // Didn't find one yet - look through protocols.
Chris Lattner3db6cae2008-07-21 18:19:38 +0000242 const ObjCList<ObjCProtocolDecl> &Protocols =
243 ClassDecl->getReferencedProtocols();
244 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
245 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000246 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000247 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000248
Chris Lattner1e03a562008-03-16 00:19:01 +0000249 // Didn't find one yet - now look through categories.
250 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
251 while (CatDecl) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000252 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000253 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000254
Steve Naroffb79c01e2008-12-08 20:57:28 +0000255 // Didn't find one yet - look through protocols.
256 const ObjCList<ObjCProtocolDecl> &Protocols =
257 CatDecl->getReferencedProtocols();
258 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
259 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000260 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroffb5584222009-02-26 11:32:02 +0000261 return MethodDecl;
Chris Lattner1e03a562008-03-16 00:19:01 +0000262 CatDecl = CatDecl->getNextClassCategory();
263 }
264 ClassDecl = ClassDecl->getSuperClass();
265 }
266 return NULL;
267}
268
Steve Naroffd789d3d2009-10-01 23:46:04 +0000269ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
270 const Selector &Sel) {
271 ObjCMethodDecl *Method = 0;
272 if (ObjCImplementationDecl *ImpDecl = getImplementation())
273 Method = ImpDecl->getInstanceMethod(Sel);
274
275 if (!Method && getSuperClass())
276 return getSuperClass()->lookupPrivateInstanceMethod(Sel);
277 return Method;
278}
Chris Lattnerab351632009-02-20 20:59:54 +0000279
280//===----------------------------------------------------------------------===//
281// ObjCMethodDecl
282//===----------------------------------------------------------------------===//
283
284ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +0000285 SourceLocation beginLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000286 SourceLocation endLoc,
287 Selector SelInfo, QualType T,
288 DeclContext *contextDecl,
289 bool isInstance,
290 bool isVariadic,
291 bool isSynthesized,
292 ImplementationControl impControl) {
293 return new (C) ObjCMethodDecl(beginLoc, endLoc,
294 SelInfo, T, contextDecl,
Mike Stump1eb44332009-09-09 15:08:12 +0000295 isInstance,
Chris Lattnerab351632009-02-20 20:59:54 +0000296 isVariadic, isSynthesized, impControl);
Chris Lattner1e03a562008-03-16 00:19:01 +0000297}
298
Chris Lattner38af2de2009-02-20 21:35:13 +0000299void ObjCMethodDecl::Destroy(ASTContext &C) {
Chris Lattnerab351632009-02-20 20:59:54 +0000300 if (Body) Body->Destroy(C);
301 if (SelfDecl) SelfDecl->Destroy(C);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Chris Lattnerab351632009-02-20 20:59:54 +0000303 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
304 if (*I) (*I)->Destroy(C);
305
Chris Lattner38af2de2009-02-20 21:35:13 +0000306 ParamInfo.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000307
308 Decl::Destroy(C);
Chris Lattner1e03a562008-03-16 00:19:01 +0000309}
310
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000311/// \brief A definition will return its interface declaration.
312/// An interface declaration will return its definition.
313/// Otherwise it will return itself.
314ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
315 ASTContext &Ctx = getASTContext();
316 ObjCMethodDecl *Redecl = 0;
317 Decl *CtxD = cast<Decl>(getDeclContext());
318
319 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
320 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
321 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
322
323 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
324 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
325 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
326
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000327 } else if (ObjCImplementationDecl *ImplD =
328 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000329 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
330 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000331
332 } else if (ObjCCategoryImplDecl *CImplD =
333 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000334 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000335 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000336 }
337
338 return Redecl ? Redecl : this;
339}
340
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000341ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
342 Decl *CtxD = cast<Decl>(getDeclContext());
343
344 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
345 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
346 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
347 isInstanceMethod()))
348 return MD;
349
350 } else if (ObjCCategoryImplDecl *CImplD =
351 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000352 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000353 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
354 isInstanceMethod()))
355 return MD;
356 }
357
358 return this;
359}
360
Mike Stump1eb44332009-09-09 15:08:12 +0000361void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerab351632009-02-20 20:59:54 +0000362 const ObjCInterfaceDecl *OID) {
363 QualType selfTy;
364 if (isInstanceMethod()) {
365 // There may be no interface context due to error in declaration
366 // of the interface (which has been reported). Recover gracefully.
367 if (OID) {
Daniel Dunbar3b3a4582009-04-22 04:34:53 +0000368 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff14108da2009-07-10 23:34:53 +0000369 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerab351632009-02-20 20:59:54 +0000370 } else {
371 selfTy = Context.getObjCIdType();
372 }
373 } else // we have a factory method.
374 selfTy = Context.getObjCClassType();
375
Mike Stump1eb44332009-09-09 15:08:12 +0000376 setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000377 &Context.Idents.get("self"), selfTy));
Chris Lattnerab351632009-02-20 20:59:54 +0000378
Mike Stump1eb44332009-09-09 15:08:12 +0000379 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
380 &Context.Idents.get("_cmd"),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000381 Context.getObjCSelType()));
Chris Lattnerab351632009-02-20 20:59:54 +0000382}
383
Chris Lattnerab351632009-02-20 20:59:54 +0000384ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
385 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
386 return ID;
387 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
388 return CD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000389 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerab351632009-02-20 20:59:54 +0000390 return IMD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000391
392 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
Chris Lattnerab351632009-02-20 20:59:54 +0000393 assert(false && "unknown method context");
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000394 return 0;
395}
396
Chris Lattnerab351632009-02-20 20:59:54 +0000397//===----------------------------------------------------------------------===//
398// ObjCInterfaceDecl
399//===----------------------------------------------------------------------===//
400
401ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
402 DeclContext *DC,
403 SourceLocation atLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000404 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +0000405 SourceLocation ClassLoc,
406 bool ForwardDecl, bool isInternal){
407 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
408 isInternal);
409}
410
411ObjCInterfaceDecl::
412ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
413 SourceLocation CLoc, bool FD, bool isInternal)
414 : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
415 TypeForDecl(0), SuperClass(0),
416 CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
417 ClassLoc(CLoc) {
418}
419
Mike Stump1eb44332009-09-09 15:08:12 +0000420void ObjCInterfaceDecl::Destroy(ASTContext &C) {
Chris Lattnerd13d3022009-03-31 08:36:08 +0000421 for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
Chris Lattnerab351632009-02-20 20:59:54 +0000422 if (*I) (*I)->Destroy(C);
Mike Stump1eb44332009-09-09 15:08:12 +0000423
Chris Lattner38af2de2009-02-20 21:35:13 +0000424 IVars.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000425 // FIXME: CategoryList?
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Chris Lattnerab351632009-02-20 20:59:54 +0000427 // FIXME: Because there is no clear ownership
428 // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
429 // reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
430 Decl::Destroy(C);
431}
432
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000433ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
434 return getASTContext().getObjCImplementation(
435 const_cast<ObjCInterfaceDecl*>(this));
436}
437
438void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
439 getASTContext().setObjCImplementation(this, ImplD);
440}
441
Chris Lattnerab351632009-02-20 20:59:54 +0000442
443/// FindCategoryDeclaration - Finds category declaration in the list of
444/// categories for this class and returns it. Name of the category is passed
445/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000446///
Chris Lattnerab351632009-02-20 20:59:54 +0000447ObjCCategoryDecl *
448ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
449 for (ObjCCategoryDecl *Category = getCategoryList();
450 Category; Category = Category->getNextClassCategory())
451 if (Category->getIdentifier() == CategoryId)
452 return Category;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000453 return 0;
454}
455
Argyrios Kyrtzidis1cb35dd2009-07-21 00:06:20 +0000456ObjCMethodDecl *
457ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
458 for (ObjCCategoryDecl *Category = getCategoryList();
459 Category; Category = Category->getNextClassCategory())
460 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
461 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
462 return MD;
463 return 0;
464}
465
466ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
467 for (ObjCCategoryDecl *Category = getCategoryList();
468 Category; Category = Category->getNextClassCategory())
469 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
470 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
471 return MD;
472 return 0;
473}
474
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000475/// ClassImplementsProtocol - Checks that 'lProto' protocol
476/// has been implemented in IDecl class, its super class or categories (if
477/// lookupCategory is true).
478bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
479 bool lookupCategory,
480 bool RHSIsQualifiedID) {
481 ObjCInterfaceDecl *IDecl = this;
482 // 1st, look up the class.
483 const ObjCList<ObjCProtocolDecl> &Protocols =
484 IDecl->getReferencedProtocols();
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000486 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
487 E = Protocols.end(); PI != E; ++PI) {
488 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
489 return true;
490 // This is dubious and is added to be compatible with gcc. In gcc, it is
491 // also allowed assigning a protocol-qualified 'id' type to a LHS object
492 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
493 // object. This IMO, should be a bug.
494 // FIXME: Treat this as an extension, and flag this as an error when GCC
495 // extensions are not enabled.
Mike Stump1eb44332009-09-09 15:08:12 +0000496 if (RHSIsQualifiedID &&
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000497 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
498 return true;
499 }
Mike Stump1eb44332009-09-09 15:08:12 +0000500
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000501 // 2nd, look up the category.
502 if (lookupCategory)
503 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
504 CDecl = CDecl->getNextClassCategory()) {
505 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
506 E = CDecl->protocol_end(); PI != E; ++PI)
507 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
508 return true;
509 }
Mike Stump1eb44332009-09-09 15:08:12 +0000510
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000511 // 3rd, look up the super class(s)
512 if (IDecl->getSuperClass())
513 return
514 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
515 RHSIsQualifiedID);
Mike Stump1eb44332009-09-09 15:08:12 +0000516
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000517 return false;
518}
519
Chris Lattnerab351632009-02-20 20:59:54 +0000520//===----------------------------------------------------------------------===//
521// ObjCIvarDecl
522//===----------------------------------------------------------------------===//
523
524ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
525 SourceLocation L, IdentifierInfo *Id,
John McCalla93c9342009-12-07 02:54:59 +0000526 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000527 AccessControl ac, Expr *BW) {
John McCalla93c9342009-12-07 02:54:59 +0000528 return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
Chris Lattnerab351632009-02-20 20:59:54 +0000529}
530
531
532
533//===----------------------------------------------------------------------===//
534// ObjCAtDefsFieldDecl
535//===----------------------------------------------------------------------===//
536
537ObjCAtDefsFieldDecl
538*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
539 IdentifierInfo *Id, QualType T, Expr *BW) {
540 return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
541}
542
543void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
544 this->~ObjCAtDefsFieldDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000545 C.Deallocate((void *)this);
Chris Lattnerab351632009-02-20 20:59:54 +0000546}
547
548//===----------------------------------------------------------------------===//
549// ObjCProtocolDecl
550//===----------------------------------------------------------------------===//
551
552ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump1eb44332009-09-09 15:08:12 +0000553 SourceLocation L,
Chris Lattnerab351632009-02-20 20:59:54 +0000554 IdentifierInfo *Id) {
555 return new (C) ObjCProtocolDecl(DC, L, Id);
556}
557
558void ObjCProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000559 ReferencedProtocols.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000560 ObjCContainerDecl::Destroy(C);
561}
562
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000563ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
564 ObjCProtocolDecl *PDecl = this;
565
566 if (Name == getIdentifier())
567 return PDecl;
568
569 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
570 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
571 return PDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000572
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000573 return NULL;
574}
575
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000576// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerab351632009-02-20 20:59:54 +0000577// it inherited.
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000578ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
579 bool isInstance) const {
Chris Lattnerab351632009-02-20 20:59:54 +0000580 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump1eb44332009-09-09 15:08:12 +0000581
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000582 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000583 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000584
Chris Lattnerab351632009-02-20 20:59:54 +0000585 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000586 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000587 return MethodDecl;
588 return NULL;
589}
590
591//===----------------------------------------------------------------------===//
592// ObjCClassDecl
593//===----------------------------------------------------------------------===//
594
Mike Stump1eb44332009-09-09 15:08:12 +0000595ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Ted Kremenek321c22f2009-11-18 00:28:11 +0000596 ObjCInterfaceDecl *const *Elts,
597 const SourceLocation *Locs,
598 unsigned nElts,
Chris Lattner38af2de2009-02-20 21:35:13 +0000599 ASTContext &C)
600 : Decl(ObjCClass, DC, L) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000601 setClassList(C, Elts, Locs, nElts);
Chris Lattner38af2de2009-02-20 21:35:13 +0000602}
603
Ted Kremenek321c22f2009-11-18 00:28:11 +0000604void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
605 const SourceLocation *Locs, unsigned Num) {
606 ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num,
607 llvm::alignof<ObjCClassRef>());
608 for (unsigned i = 0; i < Num; ++i)
609 new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]);
610
611 NumDecls = Num;
612}
Chris Lattner38af2de2009-02-20 21:35:13 +0000613
Chris Lattnerab351632009-02-20 20:59:54 +0000614ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
615 SourceLocation L,
616 ObjCInterfaceDecl *const *Elts,
Ted Kremenek321c22f2009-11-18 00:28:11 +0000617 const SourceLocation *Locs,
Chris Lattnerab351632009-02-20 20:59:54 +0000618 unsigned nElts) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000619 return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000620}
621
622void ObjCClassDecl::Destroy(ASTContext &C) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000623 // ObjCInterfaceDecls registered with a DeclContext will get destroyed
624 // when the DeclContext is destroyed. For those created only by a forward
625 // declaration, the first @class that created the ObjCInterfaceDecl gets
626 // to destroy it.
627 // FIXME: Note that this ownership role is very brittle; a better
628 // polict is surely need in the future.
629 for (iterator I = begin(), E = end(); I !=E ; ++I) {
630 ObjCInterfaceDecl *ID = I->getInterface();
631 if (ID->isForwardDecl() && ID->getLocStart() == getLocStart())
632 ID->Destroy(C);
633 }
634
635 C.Deallocate(ForwardDecls);
Chris Lattnerab351632009-02-20 20:59:54 +0000636 Decl::Destroy(C);
637}
638
Ted Kremenek2dbdd622009-11-18 01:26:56 +0000639SourceRange ObjCClassDecl::getSourceRange() const {
640 // FIXME: We should include the semicolon
641 assert(NumDecls);
642 return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation());
643}
644
Chris Lattnerab351632009-02-20 20:59:54 +0000645//===----------------------------------------------------------------------===//
646// ObjCForwardProtocolDecl
647//===----------------------------------------------------------------------===//
648
Chris Lattner38af2de2009-02-20 21:35:13 +0000649ObjCForwardProtocolDecl::
650ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
651 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000652 const SourceLocation *Locs, ASTContext &C)
Mike Stump1eb44332009-09-09 15:08:12 +0000653: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor18df52b2010-01-16 15:02:53 +0000654 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner38af2de2009-02-20 21:35:13 +0000655}
656
657
Chris Lattnerab351632009-02-20 20:59:54 +0000658ObjCForwardProtocolDecl *
659ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump1eb44332009-09-09 15:08:12 +0000660 SourceLocation L,
Chris Lattnerab351632009-02-20 20:59:54 +0000661 ObjCProtocolDecl *const *Elts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000662 unsigned NumElts,
663 const SourceLocation *Locs) {
664 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000665}
666
667void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000668 ReferencedProtocols.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000669 Decl::Destroy(C);
670}
671
672//===----------------------------------------------------------------------===//
673// ObjCCategoryDecl
674//===----------------------------------------------------------------------===//
675
676ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor3db211b2010-01-16 16:38:58 +0000677 SourceLocation AtLoc,
678 SourceLocation ClassNameLoc,
679 SourceLocation CategoryNameLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000680 IdentifierInfo *Id) {
Douglas Gregor3db211b2010-01-16 16:38:58 +0000681 return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id);
Chris Lattnerab351632009-02-20 20:59:54 +0000682}
683
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000684ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
685 return getASTContext().getObjCImplementation(
686 const_cast<ObjCCategoryDecl*>(this));
687}
688
689void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
690 getASTContext().setObjCImplementation(this, ImplD);
691}
692
693
Chris Lattnerab351632009-02-20 20:59:54 +0000694//===----------------------------------------------------------------------===//
695// ObjCCategoryImplDecl
696//===----------------------------------------------------------------------===//
697
698ObjCCategoryImplDecl *
699ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
700 SourceLocation L,IdentifierInfo *Id,
701 ObjCInterfaceDecl *ClassInterface) {
702 return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
703}
704
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000705ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000706 return getClassInterface()->FindCategoryDeclaration(getIdentifier());
707}
708
Chris Lattnerab351632009-02-20 20:59:54 +0000709
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000710void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor2c2d43c2009-04-23 02:42:49 +0000711 // FIXME: The context should be correct before we get here.
Douglas Gregor653f1b12009-04-23 01:02:12 +0000712 property->setLexicalDeclContext(this);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000713 addDecl(property);
Douglas Gregor653f1b12009-04-23 01:02:12 +0000714}
715
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000716void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
717 ASTContext &Ctx = getASTContext();
718
719 if (ObjCImplementationDecl *ImplD
Duncan Sands98f2cca2009-07-21 07:56:29 +0000720 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000721 if (IFace)
722 Ctx.setObjCImplementation(IFace, ImplD);
723
Duncan Sands98f2cca2009-07-21 07:56:29 +0000724 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000725 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
726 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
727 Ctx.setObjCImplementation(CD, ImplD);
728 }
729
730 ClassInterface = IFace;
731}
732
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000733/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattnerd6eed1c2009-02-16 19:24:31 +0000734/// properties implemented in this category @implementation block and returns
735/// the implemented property that uses it.
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000736///
Chris Lattner3aa18612009-02-28 18:42:10 +0000737ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000738FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
739 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000740 ObjCPropertyImplDecl *PID = *i;
741 if (PID->getPropertyIvarDecl() &&
742 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
743 return PID;
744 }
745 return 0;
746}
747
748/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
749/// added to the list of those properties @synthesized/@dynamic in this
750/// category @implementation block.
751///
Chris Lattner3aa18612009-02-28 18:42:10 +0000752ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000753FindPropertyImplDecl(IdentifierInfo *Id) const {
754 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000755 ObjCPropertyImplDecl *PID = *i;
756 if (PID->getPropertyDecl()->getIdentifier() == Id)
757 return PID;
758 }
759 return 0;
760}
761
Chris Lattnerab351632009-02-20 20:59:54 +0000762//===----------------------------------------------------------------------===//
763// ObjCImplementationDecl
764//===----------------------------------------------------------------------===//
765
766ObjCImplementationDecl *
Mike Stump1eb44332009-09-09 15:08:12 +0000767ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerab351632009-02-20 20:59:54 +0000768 SourceLocation L,
769 ObjCInterfaceDecl *ClassInterface,
770 ObjCInterfaceDecl *SuperDecl) {
771 return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
772}
773
Chris Lattnerab351632009-02-20 20:59:54 +0000774//===----------------------------------------------------------------------===//
775// ObjCCompatibleAliasDecl
776//===----------------------------------------------------------------------===//
777
778ObjCCompatibleAliasDecl *
779ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
780 SourceLocation L,
Mike Stump1eb44332009-09-09 15:08:12 +0000781 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +0000782 ObjCInterfaceDecl* AliasedClass) {
783 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
784}
785
786//===----------------------------------------------------------------------===//
787// ObjCPropertyDecl
788//===----------------------------------------------------------------------===//
789
790ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
791 SourceLocation L,
792 IdentifierInfo *Id,
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000793 SourceLocation AtLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000794 QualType T,
795 PropertyControl propControl) {
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000796 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerab351632009-02-20 20:59:54 +0000797}
798
799
800//===----------------------------------------------------------------------===//
801// ObjCPropertyImplDecl
802//===----------------------------------------------------------------------===//
803
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000804ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregord0434102009-01-09 00:49:46 +0000805 DeclContext *DC,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000806 SourceLocation atLoc,
807 SourceLocation L,
808 ObjCPropertyDecl *property,
Daniel Dunbar9f0afd42008-08-26 04:47:31 +0000809 Kind PK,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000810 ObjCIvarDecl *ivar) {
Steve Naroff3e970492009-01-27 21:25:57 +0000811 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000812}
Chris Lattnerf4af5152008-03-17 01:19:02 +0000813
Chris Lattner0ed844b2008-04-04 06:12:32 +0000814