blob: 67b71a0c44e56bc93f623163558b79209514ece0 [file] [log] [blame]
Chris Lattner89375192008-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 Dunbar221fa942008-08-11 04:54:23 +000016#include "clang/AST/Stmt.h"
Steve Naroffc4173fa2009-02-22 19:35:57 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattner89375192008-03-16 00:19:01 +000018using namespace clang;
19
Chris Lattner8d8829e2008-03-16 00:49:28 +000020//===----------------------------------------------------------------------===//
Chris Lattner4d1eb762009-02-20 21:16:26 +000021// ObjCListBase
22//===----------------------------------------------------------------------===//
23
Chris Lattner22298722009-02-20 21:35:13 +000024void ObjCListBase::Destroy(ASTContext &Ctx) {
Chris Lattner7c981a72009-02-20 21:44:01 +000025 Ctx.Deallocate(List);
Chris Lattner4d1eb762009-02-20 21:16:26 +000026 NumElts = 0;
27 List = 0;
28}
29
Chris Lattner22298722009-02-20 21:35:13 +000030void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Chris Lattner4d1eb762009-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 Stump11289f42009-09-09 15:08:12 +000033
34
Chris Lattner7c981a72009-02-20 21:44:01 +000035 List = new (Ctx) void*[Elts];
Chris Lattner4d1eb762009-02-20 21:16:26 +000036 NumElts = Elts;
37 memcpy(List, InList, sizeof(void*)*Elts);
38}
39
Douglas Gregor002b6712010-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 Lattner4d1eb762009-02-20 21:16:26 +000055
56//===----------------------------------------------------------------------===//
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +000057// ObjCInterfaceDecl
Chris Lattner8d8829e2008-03-16 00:49:28 +000058//===----------------------------------------------------------------------===//
59
Fariborz Jahanian68453832009-06-05 18:16:35 +000060/// getIvarDecl - This method looks up an ivar in this ContextDecl.
61///
62ObjCIvarDecl *
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000063ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
Fariborz Jahanian68453832009-06-05 18:16:35 +000064 lookup_const_iterator Ivar, IvarEnd;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000065 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
Fariborz Jahanian68453832009-06-05 18:16:35 +000066 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
67 return ivar;
68 }
69 return 0;
70}
71
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000072// Get the local instance/class method declared in this interface.
Douglas Gregorbcced4e2009-04-09 21:40:53 +000073ObjCMethodDecl *
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000074ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
Steve Naroffc4173fa2009-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 Kyrtzidiscfbfe782009-06-30 02:36:12 +000084 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
Steve Naroffc4173fa2009-02-22 19:35:57 +000085 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000086 if (MD && MD->isInstanceMethod() == isInstance)
Steve Naroffc4173fa2009-02-22 19:35:57 +000087 return MD;
88 }
Steve Naroff35c62ae2009-01-08 17:28:14 +000089 return 0;
90}
91
Fariborz Jahaniana054e992008-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 Naroffba3dc382009-01-11 12:47:58 +000094/// FIXME: Convert to DeclContext lookup...
Fariborz Jahaniana054e992008-04-21 19:04:53 +000095///
96ObjCPropertyDecl *
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000097ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
98 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +000099 if ((*I)->getIdentifier() == PropertyId)
100 return *I;
Mike Stump11289f42009-09-09 15:08:12 +0000101
Fariborz Jahanian519976c2009-01-09 21:04:52 +0000102 const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this);
103 if (PID) {
Mike Stump11289f42009-09-09 15:08:12 +0000104 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000105 E = PID->protocol_end(); I != E; ++I)
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000106 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000107 return P;
Fariborz Jahanian519976c2009-01-09 21:04:52 +0000108 }
Mike Stump11289f42009-09-09 15:08:12 +0000109
Fariborz Jahaniandab04842009-01-19 18:16:19 +0000110 if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
Steve Naroffb3a87982009-01-09 15:36:25 +0000111 // Look through categories.
112 for (ObjCCategoryDecl *Category = OID->getCategoryList();
113 Category; Category = Category->getNextClassCategory()) {
Fariborz Jahanian30a42922010-02-15 21:55:26 +0000114 if (!Category->IsClassExtension())
115 if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId))
116 return P;
Steve Naroffb3a87982009-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 Kyrtzidiscfbfe782009-06-30 02:36:12 +0000121 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000122 return P;
Steve Naroffb3a87982009-01-09 15:36:25 +0000123 }
124 if (OID->getSuperClass())
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000125 return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000126 } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
Fariborz Jahaniandab04842009-01-19 18:16:19 +0000127 // Look through protocols.
Fariborz Jahanian30a42922010-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 Jahaniandab04842009-01-19 18:16:19 +0000133 }
134 }
Steve Narofff9c65242008-06-05 13:55:23 +0000135 return 0;
136}
137
Fariborz Jahaniande8db162009-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 Jahanian092cd6e2009-10-05 20:41:32 +0000159void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
160 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
Douglas Gregor002b6712010-01-16 15:02:53 +0000161 const SourceLocation *Locs,
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000162 ASTContext &C)
163{
164 if (ReferencedProtocols.empty()) {
Douglas Gregor002b6712010-01-16 15:02:53 +0000165 ReferencedProtocols.set(ExtList, ExtNum, Locs, C);
Fariborz Jahanian092cd6e2009-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 Gregor002b6712010-01-16 15:02:53 +0000172 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Fariborz Jahanian092cd6e2009-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 Gregor002b6712010-01-16 15:02:53 +0000186 if (!protocolExists) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000187 ProtocolRefs.push_back(ProtoInExtension);
Douglas Gregor002b6712010-01-16 15:02:53 +0000188 ProtocolLocs.push_back(Locs[i]);
189 }
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000190 }
191 if (ProtocolRefs.empty())
192 return;
Fariborz Jahanian8764c742009-10-05 21:32:49 +0000193 // Merge ProtocolRefs into class's protocol list;
Douglas Gregor002b6712010-01-16 15:02:53 +0000194 protocol_loc_iterator pl = protocol_loc_begin();
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000195 for (protocol_iterator p = protocol_begin(), e = protocol_end();
Douglas Gregor002b6712010-01-16 15:02:53 +0000196 p != e; ++p, ++pl) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000197 ProtocolRefs.push_back(*p);
Douglas Gregor002b6712010-01-16 15:02:53 +0000198 ProtocolLocs.push_back(*pl);
199 }
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000200 ReferencedProtocols.Destroy(C);
201 unsigned NumProtoRefs = ProtocolRefs.size();
Douglas Gregor002b6712010-01-16 15:02:53 +0000202 setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C);
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000203}
204
Fariborz Jahanianafe13862010-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 Kyrtzidiscfbfe782009-06-30 02:36:12 +0000216ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
217 ObjCInterfaceDecl *&clsDeclared) {
Chris Lattner89375192008-03-16 00:19:01 +0000218 ObjCInterfaceDecl* ClassDecl = this;
219 while (ClassDecl != NULL) {
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000220 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian68453832009-06-05 18:16:35 +0000221 clsDeclared = ClassDecl;
222 return I;
Chris Lattner89375192008-03-16 00:19:01 +0000223 }
Fariborz Jahanianafe13862010-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 Lattner89375192008-03-16 00:19:01 +0000230 ClassDecl = ClassDecl->getSuperClass();
231 }
232 return NULL;
233}
234
Fariborz Jahaniandb3a4c12009-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 Kyrtzidis553376b2009-07-25 22:15:51 +0000249/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner89375192008-03-16 00:19:01 +0000250/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000251ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
252 bool isInstance) const {
253 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner89375192008-03-16 00:19:01 +0000254 ObjCMethodDecl *MethodDecl = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000255
Chris Lattner89375192008-03-16 00:19:01 +0000256 while (ClassDecl != NULL) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000257 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000258 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000259
Chris Lattner89375192008-03-16 00:19:01 +0000260 // Didn't find one yet - look through protocols.
Chris Lattnerd0045052008-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 Kyrtzidis553376b2009-07-25 22:15:51 +0000265 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000266 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000267
Chris Lattner89375192008-03-16 00:19:01 +0000268 // Didn't find one yet - now look through categories.
269 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
270 while (CatDecl) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000271 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000272 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000273
Steve Naroff5fd31b12008-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 Kyrtzidis553376b2009-07-25 22:15:51 +0000279 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroff8ec27842009-02-26 11:32:02 +0000280 return MethodDecl;
Chris Lattner89375192008-03-16 00:19:01 +0000281 CatDecl = CatDecl->getNextClassCategory();
282 }
283 ClassDecl = ClassDecl->getSuperClass();
284 }
285 return NULL;
286}
287
Steve Naroffbb69c942009-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 Lattnerf1ccb0c2009-02-20 20:59:54 +0000298
299//===----------------------------------------------------------------------===//
300// ObjCMethodDecl
301//===----------------------------------------------------------------------===//
302
303ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump11289f42009-09-09 15:08:12 +0000304 SourceLocation beginLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000305 SourceLocation endLoc,
306 Selector SelInfo, QualType T,
Douglas Gregor12852d92010-03-08 14:59:44 +0000307 TypeSourceInfo *ResultTInfo,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000308 DeclContext *contextDecl,
309 bool isInstance,
310 bool isVariadic,
311 bool isSynthesized,
312 ImplementationControl impControl) {
313 return new (C) ObjCMethodDecl(beginLoc, endLoc,
Douglas Gregor12852d92010-03-08 14:59:44 +0000314 SelInfo, T, ResultTInfo, contextDecl,
315 isInstance,
316 isVariadic, isSynthesized, impControl);
Chris Lattner89375192008-03-16 00:19:01 +0000317}
318
Chris Lattner22298722009-02-20 21:35:13 +0000319void ObjCMethodDecl::Destroy(ASTContext &C) {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000320 if (Body) Body->Destroy(C);
321 if (SelfDecl) SelfDecl->Destroy(C);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000323 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
324 if (*I) (*I)->Destroy(C);
325
Chris Lattner22298722009-02-20 21:35:13 +0000326 ParamInfo.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000327
328 Decl::Destroy(C);
Chris Lattner89375192008-03-16 00:19:01 +0000329}
330
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000331/// \brief A definition will return its interface declaration.
332/// An interface declaration will return its definition.
333/// Otherwise it will return itself.
334ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
335 ASTContext &Ctx = getASTContext();
336 ObjCMethodDecl *Redecl = 0;
337 Decl *CtxD = cast<Decl>(getDeclContext());
338
339 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
340 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
341 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
342
343 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
344 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
345 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
346
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000347 } else if (ObjCImplementationDecl *ImplD =
348 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000349 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
350 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000351
352 } else if (ObjCCategoryImplDecl *CImplD =
353 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000354 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000355 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000356 }
357
358 return Redecl ? Redecl : this;
359}
360
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000361ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
362 Decl *CtxD = cast<Decl>(getDeclContext());
363
364 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
365 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
366 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
367 isInstanceMethod()))
368 return MD;
369
370 } else if (ObjCCategoryImplDecl *CImplD =
371 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000372 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000373 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
374 isInstanceMethod()))
375 return MD;
376 }
377
378 return this;
379}
380
Mike Stump11289f42009-09-09 15:08:12 +0000381void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000382 const ObjCInterfaceDecl *OID) {
383 QualType selfTy;
384 if (isInstanceMethod()) {
385 // There may be no interface context due to error in declaration
386 // of the interface (which has been reported). Recover gracefully.
387 if (OID) {
Daniel Dunbaraefc2b92009-04-22 04:34:53 +0000388 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff7cae42b2009-07-10 23:34:53 +0000389 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000390 } else {
391 selfTy = Context.getObjCIdType();
392 }
393 } else // we have a factory method.
394 selfTy = Context.getObjCClassType();
395
Mike Stump11289f42009-09-09 15:08:12 +0000396 setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
Steve Naroff04f2d142009-04-20 15:06:07 +0000397 &Context.Idents.get("self"), selfTy));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000398
Mike Stump11289f42009-09-09 15:08:12 +0000399 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
400 &Context.Idents.get("_cmd"),
Steve Naroff04f2d142009-04-20 15:06:07 +0000401 Context.getObjCSelType()));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000402}
403
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000404ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
405 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
406 return ID;
407 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
408 return CD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000409 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000410 return IMD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000411
412 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000413 assert(false && "unknown method context");
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000414 return 0;
415}
416
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000417//===----------------------------------------------------------------------===//
418// ObjCInterfaceDecl
419//===----------------------------------------------------------------------===//
420
421ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
422 DeclContext *DC,
423 SourceLocation atLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000424 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000425 SourceLocation ClassLoc,
426 bool ForwardDecl, bool isInternal){
427 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
428 isInternal);
429}
430
431ObjCInterfaceDecl::
432ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
433 SourceLocation CLoc, bool FD, bool isInternal)
434 : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
435 TypeForDecl(0), SuperClass(0),
436 CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
437 ClassLoc(CLoc) {
438}
439
Mike Stump11289f42009-09-09 15:08:12 +0000440void ObjCInterfaceDecl::Destroy(ASTContext &C) {
Chris Lattnerd8a47c42009-03-31 08:36:08 +0000441 for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000442 if (*I) (*I)->Destroy(C);
Mike Stump11289f42009-09-09 15:08:12 +0000443
Chris Lattner22298722009-02-20 21:35:13 +0000444 IVars.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000445 // FIXME: CategoryList?
Mike Stump11289f42009-09-09 15:08:12 +0000446
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000447 // FIXME: Because there is no clear ownership
448 // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
449 // reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
450 Decl::Destroy(C);
451}
452
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000453ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
454 return getASTContext().getObjCImplementation(
455 const_cast<ObjCInterfaceDecl*>(this));
456}
457
458void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
459 getASTContext().setObjCImplementation(this, ImplD);
460}
461
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000462
463/// FindCategoryDeclaration - Finds category declaration in the list of
464/// categories for this class and returns it. Name of the category is passed
465/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000466///
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000467ObjCCategoryDecl *
468ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
469 for (ObjCCategoryDecl *Category = getCategoryList();
470 Category; Category = Category->getNextClassCategory())
471 if (Category->getIdentifier() == CategoryId)
472 return Category;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000473 return 0;
474}
475
Argyrios Kyrtzidis1559d67b2009-07-21 00:06:20 +0000476ObjCMethodDecl *
477ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
478 for (ObjCCategoryDecl *Category = getCategoryList();
479 Category; Category = Category->getNextClassCategory())
480 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
481 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
482 return MD;
483 return 0;
484}
485
486ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
487 for (ObjCCategoryDecl *Category = getCategoryList();
488 Category; Category = Category->getNextClassCategory())
489 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
490 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
491 return MD;
492 return 0;
493}
494
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000495/// ClassImplementsProtocol - Checks that 'lProto' protocol
496/// has been implemented in IDecl class, its super class or categories (if
497/// lookupCategory is true).
498bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
499 bool lookupCategory,
500 bool RHSIsQualifiedID) {
501 ObjCInterfaceDecl *IDecl = this;
502 // 1st, look up the class.
503 const ObjCList<ObjCProtocolDecl> &Protocols =
504 IDecl->getReferencedProtocols();
Mike Stump11289f42009-09-09 15:08:12 +0000505
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000506 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
507 E = Protocols.end(); PI != E; ++PI) {
508 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
509 return true;
510 // This is dubious and is added to be compatible with gcc. In gcc, it is
511 // also allowed assigning a protocol-qualified 'id' type to a LHS object
512 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
513 // object. This IMO, should be a bug.
514 // FIXME: Treat this as an extension, and flag this as an error when GCC
515 // extensions are not enabled.
Mike Stump11289f42009-09-09 15:08:12 +0000516 if (RHSIsQualifiedID &&
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000517 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
518 return true;
519 }
Mike Stump11289f42009-09-09 15:08:12 +0000520
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000521 // 2nd, look up the category.
522 if (lookupCategory)
523 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
524 CDecl = CDecl->getNextClassCategory()) {
525 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
526 E = CDecl->protocol_end(); PI != E; ++PI)
527 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
528 return true;
529 }
Mike Stump11289f42009-09-09 15:08:12 +0000530
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000531 // 3rd, look up the super class(s)
532 if (IDecl->getSuperClass())
533 return
534 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
535 RHSIsQualifiedID);
Mike Stump11289f42009-09-09 15:08:12 +0000536
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000537 return false;
538}
539
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000540//===----------------------------------------------------------------------===//
541// ObjCIvarDecl
542//===----------------------------------------------------------------------===//
543
544ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
545 SourceLocation L, IdentifierInfo *Id,
John McCallbcd03502009-12-07 02:54:59 +0000546 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000547 AccessControl ac, Expr *BW) {
John McCallbcd03502009-12-07 02:54:59 +0000548 return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000549}
550
551
552
553//===----------------------------------------------------------------------===//
554// ObjCAtDefsFieldDecl
555//===----------------------------------------------------------------------===//
556
557ObjCAtDefsFieldDecl
558*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
559 IdentifierInfo *Id, QualType T, Expr *BW) {
560 return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
561}
562
563void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
564 this->~ObjCAtDefsFieldDecl();
Mike Stump11289f42009-09-09 15:08:12 +0000565 C.Deallocate((void *)this);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000566}
567
568//===----------------------------------------------------------------------===//
569// ObjCProtocolDecl
570//===----------------------------------------------------------------------===//
571
572ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump11289f42009-09-09 15:08:12 +0000573 SourceLocation L,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000574 IdentifierInfo *Id) {
575 return new (C) ObjCProtocolDecl(DC, L, Id);
576}
577
578void ObjCProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner22298722009-02-20 21:35:13 +0000579 ReferencedProtocols.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000580 ObjCContainerDecl::Destroy(C);
581}
582
Steve Naroff114aecb2009-03-01 16:12:44 +0000583ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
584 ObjCProtocolDecl *PDecl = this;
585
586 if (Name == getIdentifier())
587 return PDecl;
588
589 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
590 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
591 return PDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000592
Steve Naroff114aecb2009-03-01 16:12:44 +0000593 return NULL;
594}
595
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000596// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000597// it inherited.
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000598ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
599 bool isInstance) const {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000600 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump11289f42009-09-09 15:08:12 +0000601
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000602 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000603 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000604
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000605 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000606 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000607 return MethodDecl;
608 return NULL;
609}
610
611//===----------------------------------------------------------------------===//
612// ObjCClassDecl
613//===----------------------------------------------------------------------===//
614
Mike Stump11289f42009-09-09 15:08:12 +0000615ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Ted Kremenek9b124e12009-11-18 00:28:11 +0000616 ObjCInterfaceDecl *const *Elts,
617 const SourceLocation *Locs,
618 unsigned nElts,
Chris Lattner22298722009-02-20 21:35:13 +0000619 ASTContext &C)
620 : Decl(ObjCClass, DC, L) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000621 setClassList(C, Elts, Locs, nElts);
Chris Lattner22298722009-02-20 21:35:13 +0000622}
623
Ted Kremenek9b124e12009-11-18 00:28:11 +0000624void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
625 const SourceLocation *Locs, unsigned Num) {
626 ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num,
627 llvm::alignof<ObjCClassRef>());
628 for (unsigned i = 0; i < Num; ++i)
629 new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]);
630
631 NumDecls = Num;
632}
Chris Lattner22298722009-02-20 21:35:13 +0000633
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000634ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
635 SourceLocation L,
636 ObjCInterfaceDecl *const *Elts,
Ted Kremenek9b124e12009-11-18 00:28:11 +0000637 const SourceLocation *Locs,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000638 unsigned nElts) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000639 return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000640}
641
642void ObjCClassDecl::Destroy(ASTContext &C) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000643 // ObjCInterfaceDecls registered with a DeclContext will get destroyed
644 // when the DeclContext is destroyed. For those created only by a forward
645 // declaration, the first @class that created the ObjCInterfaceDecl gets
646 // to destroy it.
647 // FIXME: Note that this ownership role is very brittle; a better
648 // polict is surely need in the future.
649 for (iterator I = begin(), E = end(); I !=E ; ++I) {
650 ObjCInterfaceDecl *ID = I->getInterface();
651 if (ID->isForwardDecl() && ID->getLocStart() == getLocStart())
652 ID->Destroy(C);
653 }
654
655 C.Deallocate(ForwardDecls);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000656 Decl::Destroy(C);
657}
658
Ted Kremenek49939c22009-11-18 01:26:56 +0000659SourceRange ObjCClassDecl::getSourceRange() const {
660 // FIXME: We should include the semicolon
661 assert(NumDecls);
662 return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation());
663}
664
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000665//===----------------------------------------------------------------------===//
666// ObjCForwardProtocolDecl
667//===----------------------------------------------------------------------===//
668
Chris Lattner22298722009-02-20 21:35:13 +0000669ObjCForwardProtocolDecl::
670ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
671 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000672 const SourceLocation *Locs, ASTContext &C)
Mike Stump11289f42009-09-09 15:08:12 +0000673: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor002b6712010-01-16 15:02:53 +0000674 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner22298722009-02-20 21:35:13 +0000675}
676
677
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000678ObjCForwardProtocolDecl *
679ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump11289f42009-09-09 15:08:12 +0000680 SourceLocation L,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000681 ObjCProtocolDecl *const *Elts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000682 unsigned NumElts,
683 const SourceLocation *Locs) {
684 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000685}
686
687void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner22298722009-02-20 21:35:13 +0000688 ReferencedProtocols.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000689 Decl::Destroy(C);
690}
691
692//===----------------------------------------------------------------------===//
693// ObjCCategoryDecl
694//===----------------------------------------------------------------------===//
695
696ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor071676f2010-01-16 16:38:58 +0000697 SourceLocation AtLoc,
698 SourceLocation ClassNameLoc,
699 SourceLocation CategoryNameLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000700 IdentifierInfo *Id) {
Douglas Gregor071676f2010-01-16 16:38:58 +0000701 return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000702}
703
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000704ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
705 return getASTContext().getObjCImplementation(
706 const_cast<ObjCCategoryDecl*>(this));
707}
708
709void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
710 getASTContext().setObjCImplementation(this, ImplD);
711}
712
713
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000714//===----------------------------------------------------------------------===//
715// ObjCCategoryImplDecl
716//===----------------------------------------------------------------------===//
717
718ObjCCategoryImplDecl *
719ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
720 SourceLocation L,IdentifierInfo *Id,
721 ObjCInterfaceDecl *ClassInterface) {
722 return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
723}
724
Steve Narofff406f4d2009-10-29 21:11:04 +0000725ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000726 return getClassInterface()->FindCategoryDeclaration(getIdentifier());
727}
728
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000729
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000730void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor9a13efd2009-04-23 02:42:49 +0000731 // FIXME: The context should be correct before we get here.
Douglas Gregor29bd76f2009-04-23 01:02:12 +0000732 property->setLexicalDeclContext(this);
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000733 addDecl(property);
Douglas Gregor29bd76f2009-04-23 01:02:12 +0000734}
735
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000736void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
737 ASTContext &Ctx = getASTContext();
738
739 if (ObjCImplementationDecl *ImplD
Duncan Sands49c29ee2009-07-21 07:56:29 +0000740 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000741 if (IFace)
742 Ctx.setObjCImplementation(IFace, ImplD);
743
Duncan Sands49c29ee2009-07-21 07:56:29 +0000744 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000745 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
746 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
747 Ctx.setObjCImplementation(CD, ImplD);
748 }
749
750 ClassInterface = IFace;
751}
752
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000753/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattneraab70d22009-02-16 19:24:31 +0000754/// properties implemented in this category @implementation block and returns
755/// the implemented property that uses it.
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000756///
Chris Lattnera9ca0522009-02-28 18:42:10 +0000757ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000758FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
759 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000760 ObjCPropertyImplDecl *PID = *i;
761 if (PID->getPropertyIvarDecl() &&
762 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
763 return PID;
764 }
765 return 0;
766}
767
768/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
769/// added to the list of those properties @synthesized/@dynamic in this
770/// category @implementation block.
771///
Chris Lattnera9ca0522009-02-28 18:42:10 +0000772ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000773FindPropertyImplDecl(IdentifierInfo *Id) const {
774 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000775 ObjCPropertyImplDecl *PID = *i;
776 if (PID->getPropertyDecl()->getIdentifier() == Id)
777 return PID;
778 }
779 return 0;
780}
781
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000782//===----------------------------------------------------------------------===//
783// ObjCImplementationDecl
784//===----------------------------------------------------------------------===//
785
786ObjCImplementationDecl *
Mike Stump11289f42009-09-09 15:08:12 +0000787ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000788 SourceLocation L,
789 ObjCInterfaceDecl *ClassInterface,
790 ObjCInterfaceDecl *SuperDecl) {
791 return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
792}
793
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000794//===----------------------------------------------------------------------===//
795// ObjCCompatibleAliasDecl
796//===----------------------------------------------------------------------===//
797
798ObjCCompatibleAliasDecl *
799ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
800 SourceLocation L,
Mike Stump11289f42009-09-09 15:08:12 +0000801 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000802 ObjCInterfaceDecl* AliasedClass) {
803 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
804}
805
806//===----------------------------------------------------------------------===//
807// ObjCPropertyDecl
808//===----------------------------------------------------------------------===//
809
810ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
811 SourceLocation L,
812 IdentifierInfo *Id,
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000813 SourceLocation AtLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000814 QualType T,
815 PropertyControl propControl) {
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000816 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000817}
818
819
820//===----------------------------------------------------------------------===//
821// ObjCPropertyImplDecl
822//===----------------------------------------------------------------------===//
823
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000824ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregorc25d7a72009-01-09 00:49:46 +0000825 DeclContext *DC,
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000826 SourceLocation atLoc,
827 SourceLocation L,
828 ObjCPropertyDecl *property,
Daniel Dunbar3b4fdb02008-08-26 04:47:31 +0000829 Kind PK,
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000830 ObjCIvarDecl *ivar) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000831 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000832}
Chris Lattnered0e1642008-03-17 01:19:02 +0000833
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000834