blob: 8decafa35e34a14dcd43fdf6a00eda3ef488ef23 [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()) {
Fariborz Jahanian25760612010-02-15 21:55:26 +0000114 if (!Category->IsClassExtension())
115 if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId))
116 return P;
Steve Naroff09c47192009-01-09 15:36:25 +0000117 }
118 // Look through protocols.
119 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
120 E = OID->protocol_end(); I != E; ++I) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000121 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerab351632009-02-20 20:59:54 +0000122 return P;
Steve Naroff09c47192009-01-09 15:36:25 +0000123 }
124 if (OID->getSuperClass())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000125 return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
Chris Lattnerab351632009-02-20 20:59:54 +0000126 } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000127 // Look through protocols.
Fariborz Jahanian25760612010-02-15 21:55:26 +0000128 if (!OCD->IsClassExtension())
129 for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
130 E = OCD->protocol_end(); I != E; ++I) {
131 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
132 return P;
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000133 }
134 }
Steve Naroff3d2c22b2008-06-05 13:55:23 +0000135 return 0;
136}
137
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000138/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
139/// with name 'PropertyId' in the primary class; including those in protocols
140/// (direct or indirect) used by the promary class.
141/// FIXME: Convert to DeclContext lookup...
142///
143ObjCPropertyDecl *
144ObjCContainerDecl::FindPropertyVisibleInPrimaryClass(
145 IdentifierInfo *PropertyId) const {
146 assert(isa<ObjCInterfaceDecl>(this) && "FindPropertyVisibleInPrimaryClass");
147 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
148 if ((*I)->getIdentifier() == PropertyId)
149 return *I;
150 const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this);
151 // Look through protocols.
152 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
153 E = OID->protocol_end(); I != E; ++I)
154 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
155 return P;
156 return 0;
157}
158
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000159void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
160 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000161 const SourceLocation *Locs,
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000162 ASTContext &C)
163{
164 if (ReferencedProtocols.empty()) {
Douglas Gregor18df52b2010-01-16 15:02:53 +0000165 ReferencedProtocols.set(ExtList, ExtNum, Locs, C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000166 return;
167 }
168 // Check for duplicate protocol in class's protocol list.
169 // This is (O)2. But it is extremely rare and number of protocols in
170 // class or its extension are very few.
171 llvm::SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000172 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000173 for (unsigned i = 0; i < ExtNum; i++) {
174 bool protocolExists = false;
175 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
176 for (protocol_iterator p = protocol_begin(), e = protocol_end();
177 p != e; p++) {
178 ObjCProtocolDecl *Proto = (*p);
179 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
180 protocolExists = true;
181 break;
182 }
183 }
184 // Do we want to warn on a protocol in extension class which
185 // already exist in the class? Probably not.
Douglas Gregor18df52b2010-01-16 15:02:53 +0000186 if (!protocolExists) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000187 ProtocolRefs.push_back(ProtoInExtension);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000188 ProtocolLocs.push_back(Locs[i]);
189 }
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000190 }
191 if (ProtocolRefs.empty())
192 return;
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000193 // Merge ProtocolRefs into class's protocol list;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000194 protocol_loc_iterator pl = protocol_loc_begin();
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000195 for (protocol_iterator p = protocol_begin(), e = protocol_end();
Douglas Gregor18df52b2010-01-16 15:02:53 +0000196 p != e; ++p, ++pl) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000197 ProtocolRefs.push_back(*p);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000198 ProtocolLocs.push_back(*pl);
199 }
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000200 ReferencedProtocols.Destroy(C);
201 unsigned NumProtoRefs = ProtocolRefs.size();
Douglas Gregor18df52b2010-01-16 15:02:53 +0000202 setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000203}
204
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000205/// getClassExtension - Find class extension of the given class.
206// FIXME. can speed it up, if need be.
207ObjCCategoryDecl* ObjCInterfaceDecl::getClassExtension() const {
208 const ObjCInterfaceDecl* ClassDecl = this;
209 for (ObjCCategoryDecl *CDecl = ClassDecl->getCategoryList(); CDecl;
210 CDecl = CDecl->getNextClassCategory())
211 if (CDecl->IsClassExtension())
212 return CDecl;
213 return 0;
214}
215
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000216ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
217 ObjCInterfaceDecl *&clsDeclared) {
Chris Lattner1e03a562008-03-16 00:19:01 +0000218 ObjCInterfaceDecl* ClassDecl = this;
219 while (ClassDecl != NULL) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000220 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +0000221 clsDeclared = ClassDecl;
222 return I;
Chris Lattner1e03a562008-03-16 00:19:01 +0000223 }
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000224 if (const ObjCCategoryDecl *CDecl = ClassDecl->getClassExtension())
225 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
226 clsDeclared = ClassDecl;
227 return I;
228 }
229
Chris Lattner1e03a562008-03-16 00:19:01 +0000230 ClassDecl = ClassDecl->getSuperClass();
231 }
232 return NULL;
233}
234
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000235/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
236/// class whose name is passed as argument. If it is not one of the super classes
237/// the it returns NULL.
238ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
239 const IdentifierInfo*ICName) {
240 ObjCInterfaceDecl* ClassDecl = this;
241 while (ClassDecl != NULL) {
242 if (ClassDecl->getIdentifier() == ICName)
243 return ClassDecl;
244 ClassDecl = ClassDecl->getSuperClass();
245 }
246 return NULL;
247}
248
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000249/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner1e03a562008-03-16 00:19:01 +0000250/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000251ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
252 bool isInstance) const {
253 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner1e03a562008-03-16 00:19:01 +0000254 ObjCMethodDecl *MethodDecl = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000255
Chris Lattner1e03a562008-03-16 00:19:01 +0000256 while (ClassDecl != NULL) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000257 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000258 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000259
Chris Lattner1e03a562008-03-16 00:19:01 +0000260 // Didn't find one yet - look through protocols.
Chris Lattner3db6cae2008-07-21 18:19:38 +0000261 const ObjCList<ObjCProtocolDecl> &Protocols =
262 ClassDecl->getReferencedProtocols();
263 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
264 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000265 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000266 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000267
Chris Lattner1e03a562008-03-16 00:19:01 +0000268 // Didn't find one yet - now look through categories.
269 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
270 while (CatDecl) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000271 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000272 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000273
Steve Naroffb79c01e2008-12-08 20:57:28 +0000274 // Didn't find one yet - look through protocols.
275 const ObjCList<ObjCProtocolDecl> &Protocols =
276 CatDecl->getReferencedProtocols();
277 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
278 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000279 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroffb5584222009-02-26 11:32:02 +0000280 return MethodDecl;
Chris Lattner1e03a562008-03-16 00:19:01 +0000281 CatDecl = CatDecl->getNextClassCategory();
282 }
283 ClassDecl = ClassDecl->getSuperClass();
284 }
285 return NULL;
286}
287
Steve Naroffd789d3d2009-10-01 23:46:04 +0000288ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
289 const Selector &Sel) {
290 ObjCMethodDecl *Method = 0;
291 if (ObjCImplementationDecl *ImpDecl = getImplementation())
292 Method = ImpDecl->getInstanceMethod(Sel);
293
294 if (!Method && getSuperClass())
295 return getSuperClass()->lookupPrivateInstanceMethod(Sel);
296 return Method;
297}
Chris Lattnerab351632009-02-20 20:59:54 +0000298
299//===----------------------------------------------------------------------===//
300// ObjCMethodDecl
301//===----------------------------------------------------------------------===//
302
303ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +0000304 SourceLocation beginLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000305 SourceLocation endLoc,
306 Selector SelInfo, QualType T,
307 DeclContext *contextDecl,
308 bool isInstance,
309 bool isVariadic,
310 bool isSynthesized,
311 ImplementationControl impControl) {
312 return new (C) ObjCMethodDecl(beginLoc, endLoc,
313 SelInfo, T, contextDecl,
Mike Stump1eb44332009-09-09 15:08:12 +0000314 isInstance,
Chris Lattnerab351632009-02-20 20:59:54 +0000315 isVariadic, isSynthesized, impControl);
Chris Lattner1e03a562008-03-16 00:19:01 +0000316}
317
Chris Lattner38af2de2009-02-20 21:35:13 +0000318void ObjCMethodDecl::Destroy(ASTContext &C) {
Chris Lattnerab351632009-02-20 20:59:54 +0000319 if (Body) Body->Destroy(C);
320 if (SelfDecl) SelfDecl->Destroy(C);
Mike Stump1eb44332009-09-09 15:08:12 +0000321
Chris Lattnerab351632009-02-20 20:59:54 +0000322 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
323 if (*I) (*I)->Destroy(C);
324
Chris Lattner38af2de2009-02-20 21:35:13 +0000325 ParamInfo.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000326
327 Decl::Destroy(C);
Chris Lattner1e03a562008-03-16 00:19:01 +0000328}
329
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000330/// \brief A definition will return its interface declaration.
331/// An interface declaration will return its definition.
332/// Otherwise it will return itself.
333ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
334 ASTContext &Ctx = getASTContext();
335 ObjCMethodDecl *Redecl = 0;
336 Decl *CtxD = cast<Decl>(getDeclContext());
337
338 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
339 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
340 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
341
342 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
343 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
344 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
345
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000346 } else if (ObjCImplementationDecl *ImplD =
347 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000348 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
349 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000350
351 } else if (ObjCCategoryImplDecl *CImplD =
352 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000353 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000354 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000355 }
356
357 return Redecl ? Redecl : this;
358}
359
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000360ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
361 Decl *CtxD = cast<Decl>(getDeclContext());
362
363 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
364 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
365 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
366 isInstanceMethod()))
367 return MD;
368
369 } else if (ObjCCategoryImplDecl *CImplD =
370 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000371 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000372 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
373 isInstanceMethod()))
374 return MD;
375 }
376
377 return this;
378}
379
Mike Stump1eb44332009-09-09 15:08:12 +0000380void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerab351632009-02-20 20:59:54 +0000381 const ObjCInterfaceDecl *OID) {
382 QualType selfTy;
383 if (isInstanceMethod()) {
384 // There may be no interface context due to error in declaration
385 // of the interface (which has been reported). Recover gracefully.
386 if (OID) {
Daniel Dunbar3b3a4582009-04-22 04:34:53 +0000387 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff14108da2009-07-10 23:34:53 +0000388 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerab351632009-02-20 20:59:54 +0000389 } else {
390 selfTy = Context.getObjCIdType();
391 }
392 } else // we have a factory method.
393 selfTy = Context.getObjCClassType();
394
Mike Stump1eb44332009-09-09 15:08:12 +0000395 setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000396 &Context.Idents.get("self"), selfTy));
Chris Lattnerab351632009-02-20 20:59:54 +0000397
Mike Stump1eb44332009-09-09 15:08:12 +0000398 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
399 &Context.Idents.get("_cmd"),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000400 Context.getObjCSelType()));
Chris Lattnerab351632009-02-20 20:59:54 +0000401}
402
Chris Lattnerab351632009-02-20 20:59:54 +0000403ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
404 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
405 return ID;
406 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
407 return CD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000408 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerab351632009-02-20 20:59:54 +0000409 return IMD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000410
411 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
Chris Lattnerab351632009-02-20 20:59:54 +0000412 assert(false && "unknown method context");
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000413 return 0;
414}
415
Chris Lattnerab351632009-02-20 20:59:54 +0000416//===----------------------------------------------------------------------===//
417// ObjCInterfaceDecl
418//===----------------------------------------------------------------------===//
419
420ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
421 DeclContext *DC,
422 SourceLocation atLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000423 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +0000424 SourceLocation ClassLoc,
425 bool ForwardDecl, bool isInternal){
426 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
427 isInternal);
428}
429
430ObjCInterfaceDecl::
431ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
432 SourceLocation CLoc, bool FD, bool isInternal)
433 : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
434 TypeForDecl(0), SuperClass(0),
435 CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
436 ClassLoc(CLoc) {
437}
438
Mike Stump1eb44332009-09-09 15:08:12 +0000439void ObjCInterfaceDecl::Destroy(ASTContext &C) {
Chris Lattnerd13d3022009-03-31 08:36:08 +0000440 for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
Chris Lattnerab351632009-02-20 20:59:54 +0000441 if (*I) (*I)->Destroy(C);
Mike Stump1eb44332009-09-09 15:08:12 +0000442
Chris Lattner38af2de2009-02-20 21:35:13 +0000443 IVars.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000444 // FIXME: CategoryList?
Mike Stump1eb44332009-09-09 15:08:12 +0000445
Chris Lattnerab351632009-02-20 20:59:54 +0000446 // FIXME: Because there is no clear ownership
447 // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
448 // reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
449 Decl::Destroy(C);
450}
451
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000452ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
453 return getASTContext().getObjCImplementation(
454 const_cast<ObjCInterfaceDecl*>(this));
455}
456
457void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
458 getASTContext().setObjCImplementation(this, ImplD);
459}
460
Chris Lattnerab351632009-02-20 20:59:54 +0000461
462/// FindCategoryDeclaration - Finds category declaration in the list of
463/// categories for this class and returns it. Name of the category is passed
464/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000465///
Chris Lattnerab351632009-02-20 20:59:54 +0000466ObjCCategoryDecl *
467ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
468 for (ObjCCategoryDecl *Category = getCategoryList();
469 Category; Category = Category->getNextClassCategory())
470 if (Category->getIdentifier() == CategoryId)
471 return Category;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000472 return 0;
473}
474
Argyrios Kyrtzidis1cb35dd2009-07-21 00:06:20 +0000475ObjCMethodDecl *
476ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
477 for (ObjCCategoryDecl *Category = getCategoryList();
478 Category; Category = Category->getNextClassCategory())
479 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
480 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
481 return MD;
482 return 0;
483}
484
485ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
486 for (ObjCCategoryDecl *Category = getCategoryList();
487 Category; Category = Category->getNextClassCategory())
488 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
489 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
490 return MD;
491 return 0;
492}
493
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000494/// ClassImplementsProtocol - Checks that 'lProto' protocol
495/// has been implemented in IDecl class, its super class or categories (if
496/// lookupCategory is true).
497bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
498 bool lookupCategory,
499 bool RHSIsQualifiedID) {
500 ObjCInterfaceDecl *IDecl = this;
501 // 1st, look up the class.
502 const ObjCList<ObjCProtocolDecl> &Protocols =
503 IDecl->getReferencedProtocols();
Mike Stump1eb44332009-09-09 15:08:12 +0000504
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000505 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
506 E = Protocols.end(); PI != E; ++PI) {
507 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
508 return true;
509 // This is dubious and is added to be compatible with gcc. In gcc, it is
510 // also allowed assigning a protocol-qualified 'id' type to a LHS object
511 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
512 // object. This IMO, should be a bug.
513 // FIXME: Treat this as an extension, and flag this as an error when GCC
514 // extensions are not enabled.
Mike Stump1eb44332009-09-09 15:08:12 +0000515 if (RHSIsQualifiedID &&
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000516 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
517 return true;
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000520 // 2nd, look up the category.
521 if (lookupCategory)
522 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
523 CDecl = CDecl->getNextClassCategory()) {
524 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
525 E = CDecl->protocol_end(); PI != E; ++PI)
526 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
527 return true;
528 }
Mike Stump1eb44332009-09-09 15:08:12 +0000529
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000530 // 3rd, look up the super class(s)
531 if (IDecl->getSuperClass())
532 return
533 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
534 RHSIsQualifiedID);
Mike Stump1eb44332009-09-09 15:08:12 +0000535
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000536 return false;
537}
538
Chris Lattnerab351632009-02-20 20:59:54 +0000539//===----------------------------------------------------------------------===//
540// ObjCIvarDecl
541//===----------------------------------------------------------------------===//
542
543ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
544 SourceLocation L, IdentifierInfo *Id,
John McCalla93c9342009-12-07 02:54:59 +0000545 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000546 AccessControl ac, Expr *BW) {
John McCalla93c9342009-12-07 02:54:59 +0000547 return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
Chris Lattnerab351632009-02-20 20:59:54 +0000548}
549
550
551
552//===----------------------------------------------------------------------===//
553// ObjCAtDefsFieldDecl
554//===----------------------------------------------------------------------===//
555
556ObjCAtDefsFieldDecl
557*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
558 IdentifierInfo *Id, QualType T, Expr *BW) {
559 return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
560}
561
562void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
563 this->~ObjCAtDefsFieldDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000564 C.Deallocate((void *)this);
Chris Lattnerab351632009-02-20 20:59:54 +0000565}
566
567//===----------------------------------------------------------------------===//
568// ObjCProtocolDecl
569//===----------------------------------------------------------------------===//
570
571ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump1eb44332009-09-09 15:08:12 +0000572 SourceLocation L,
Chris Lattnerab351632009-02-20 20:59:54 +0000573 IdentifierInfo *Id) {
574 return new (C) ObjCProtocolDecl(DC, L, Id);
575}
576
577void ObjCProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000578 ReferencedProtocols.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000579 ObjCContainerDecl::Destroy(C);
580}
581
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000582ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
583 ObjCProtocolDecl *PDecl = this;
584
585 if (Name == getIdentifier())
586 return PDecl;
587
588 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
589 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
590 return PDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000591
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000592 return NULL;
593}
594
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000595// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerab351632009-02-20 20:59:54 +0000596// it inherited.
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000597ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
598 bool isInstance) const {
Chris Lattnerab351632009-02-20 20:59:54 +0000599 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump1eb44332009-09-09 15:08:12 +0000600
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000601 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000602 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Chris Lattnerab351632009-02-20 20:59:54 +0000604 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000605 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000606 return MethodDecl;
607 return NULL;
608}
609
610//===----------------------------------------------------------------------===//
611// ObjCClassDecl
612//===----------------------------------------------------------------------===//
613
Mike Stump1eb44332009-09-09 15:08:12 +0000614ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Ted Kremenek321c22f2009-11-18 00:28:11 +0000615 ObjCInterfaceDecl *const *Elts,
616 const SourceLocation *Locs,
617 unsigned nElts,
Chris Lattner38af2de2009-02-20 21:35:13 +0000618 ASTContext &C)
619 : Decl(ObjCClass, DC, L) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000620 setClassList(C, Elts, Locs, nElts);
Chris Lattner38af2de2009-02-20 21:35:13 +0000621}
622
Ted Kremenek321c22f2009-11-18 00:28:11 +0000623void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
624 const SourceLocation *Locs, unsigned Num) {
625 ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num,
626 llvm::alignof<ObjCClassRef>());
627 for (unsigned i = 0; i < Num; ++i)
628 new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]);
629
630 NumDecls = Num;
631}
Chris Lattner38af2de2009-02-20 21:35:13 +0000632
Chris Lattnerab351632009-02-20 20:59:54 +0000633ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
634 SourceLocation L,
635 ObjCInterfaceDecl *const *Elts,
Ted Kremenek321c22f2009-11-18 00:28:11 +0000636 const SourceLocation *Locs,
Chris Lattnerab351632009-02-20 20:59:54 +0000637 unsigned nElts) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000638 return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000639}
640
641void ObjCClassDecl::Destroy(ASTContext &C) {
Ted Kremenek321c22f2009-11-18 00:28:11 +0000642 // ObjCInterfaceDecls registered with a DeclContext will get destroyed
643 // when the DeclContext is destroyed. For those created only by a forward
644 // declaration, the first @class that created the ObjCInterfaceDecl gets
645 // to destroy it.
646 // FIXME: Note that this ownership role is very brittle; a better
647 // polict is surely need in the future.
648 for (iterator I = begin(), E = end(); I !=E ; ++I) {
649 ObjCInterfaceDecl *ID = I->getInterface();
650 if (ID->isForwardDecl() && ID->getLocStart() == getLocStart())
651 ID->Destroy(C);
652 }
653
654 C.Deallocate(ForwardDecls);
Chris Lattnerab351632009-02-20 20:59:54 +0000655 Decl::Destroy(C);
656}
657
Ted Kremenek2dbdd622009-11-18 01:26:56 +0000658SourceRange ObjCClassDecl::getSourceRange() const {
659 // FIXME: We should include the semicolon
660 assert(NumDecls);
661 return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation());
662}
663
Chris Lattnerab351632009-02-20 20:59:54 +0000664//===----------------------------------------------------------------------===//
665// ObjCForwardProtocolDecl
666//===----------------------------------------------------------------------===//
667
Chris Lattner38af2de2009-02-20 21:35:13 +0000668ObjCForwardProtocolDecl::
669ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
670 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000671 const SourceLocation *Locs, ASTContext &C)
Mike Stump1eb44332009-09-09 15:08:12 +0000672: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor18df52b2010-01-16 15:02:53 +0000673 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner38af2de2009-02-20 21:35:13 +0000674}
675
676
Chris Lattnerab351632009-02-20 20:59:54 +0000677ObjCForwardProtocolDecl *
678ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump1eb44332009-09-09 15:08:12 +0000679 SourceLocation L,
Chris Lattnerab351632009-02-20 20:59:54 +0000680 ObjCProtocolDecl *const *Elts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000681 unsigned NumElts,
682 const SourceLocation *Locs) {
683 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000684}
685
686void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000687 ReferencedProtocols.Destroy(C);
Chris Lattnerab351632009-02-20 20:59:54 +0000688 Decl::Destroy(C);
689}
690
691//===----------------------------------------------------------------------===//
692// ObjCCategoryDecl
693//===----------------------------------------------------------------------===//
694
695ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor3db211b2010-01-16 16:38:58 +0000696 SourceLocation AtLoc,
697 SourceLocation ClassNameLoc,
698 SourceLocation CategoryNameLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000699 IdentifierInfo *Id) {
Douglas Gregor3db211b2010-01-16 16:38:58 +0000700 return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id);
Chris Lattnerab351632009-02-20 20:59:54 +0000701}
702
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000703ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
704 return getASTContext().getObjCImplementation(
705 const_cast<ObjCCategoryDecl*>(this));
706}
707
708void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
709 getASTContext().setObjCImplementation(this, ImplD);
710}
711
712
Chris Lattnerab351632009-02-20 20:59:54 +0000713//===----------------------------------------------------------------------===//
714// ObjCCategoryImplDecl
715//===----------------------------------------------------------------------===//
716
717ObjCCategoryImplDecl *
718ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
719 SourceLocation L,IdentifierInfo *Id,
720 ObjCInterfaceDecl *ClassInterface) {
721 return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
722}
723
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000724ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000725 return getClassInterface()->FindCategoryDeclaration(getIdentifier());
726}
727
Chris Lattnerab351632009-02-20 20:59:54 +0000728
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000729void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor2c2d43c2009-04-23 02:42:49 +0000730 // FIXME: The context should be correct before we get here.
Douglas Gregor653f1b12009-04-23 01:02:12 +0000731 property->setLexicalDeclContext(this);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000732 addDecl(property);
Douglas Gregor653f1b12009-04-23 01:02:12 +0000733}
734
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000735void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
736 ASTContext &Ctx = getASTContext();
737
738 if (ObjCImplementationDecl *ImplD
Duncan Sands98f2cca2009-07-21 07:56:29 +0000739 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000740 if (IFace)
741 Ctx.setObjCImplementation(IFace, ImplD);
742
Duncan Sands98f2cca2009-07-21 07:56:29 +0000743 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000744 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
745 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
746 Ctx.setObjCImplementation(CD, ImplD);
747 }
748
749 ClassInterface = IFace;
750}
751
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000752/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattnerd6eed1c2009-02-16 19:24:31 +0000753/// properties implemented in this category @implementation block and returns
754/// the implemented property that uses it.
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000755///
Chris Lattner3aa18612009-02-28 18:42:10 +0000756ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000757FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
758 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000759 ObjCPropertyImplDecl *PID = *i;
760 if (PID->getPropertyIvarDecl() &&
761 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
762 return PID;
763 }
764 return 0;
765}
766
767/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
768/// added to the list of those properties @synthesized/@dynamic in this
769/// category @implementation block.
770///
Chris Lattner3aa18612009-02-28 18:42:10 +0000771ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000772FindPropertyImplDecl(IdentifierInfo *Id) const {
773 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000774 ObjCPropertyImplDecl *PID = *i;
775 if (PID->getPropertyDecl()->getIdentifier() == Id)
776 return PID;
777 }
778 return 0;
779}
780
Chris Lattnerab351632009-02-20 20:59:54 +0000781//===----------------------------------------------------------------------===//
782// ObjCImplementationDecl
783//===----------------------------------------------------------------------===//
784
785ObjCImplementationDecl *
Mike Stump1eb44332009-09-09 15:08:12 +0000786ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerab351632009-02-20 20:59:54 +0000787 SourceLocation L,
788 ObjCInterfaceDecl *ClassInterface,
789 ObjCInterfaceDecl *SuperDecl) {
790 return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
791}
792
Chris Lattnerab351632009-02-20 20:59:54 +0000793//===----------------------------------------------------------------------===//
794// ObjCCompatibleAliasDecl
795//===----------------------------------------------------------------------===//
796
797ObjCCompatibleAliasDecl *
798ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
799 SourceLocation L,
Mike Stump1eb44332009-09-09 15:08:12 +0000800 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +0000801 ObjCInterfaceDecl* AliasedClass) {
802 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
803}
804
805//===----------------------------------------------------------------------===//
806// ObjCPropertyDecl
807//===----------------------------------------------------------------------===//
808
809ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
810 SourceLocation L,
811 IdentifierInfo *Id,
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000812 SourceLocation AtLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000813 QualType T,
814 PropertyControl propControl) {
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000815 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerab351632009-02-20 20:59:54 +0000816}
817
818
819//===----------------------------------------------------------------------===//
820// ObjCPropertyImplDecl
821//===----------------------------------------------------------------------===//
822
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000823ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregord0434102009-01-09 00:49:46 +0000824 DeclContext *DC,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000825 SourceLocation atLoc,
826 SourceLocation L,
827 ObjCPropertyDecl *property,
Daniel Dunbar9f0afd42008-08-26 04:47:31 +0000828 Kind PK,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000829 ObjCIvarDecl *ivar) {
Steve Naroff3e970492009-01-27 21:25:57 +0000830 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000831}
Chris Lattnerf4af5152008-03-17 01:19:02 +0000832
Chris Lattner0ed844b2008-04-04 06:12:32 +0000833