blob: 6a03360d16144ebb73b3231a5d8669d3c37f8c50 [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
Ted Kremenek4fb821e2010-03-15 20:11:46 +000092ObjCPropertyDecl *
Ted Kremenekddcd1092010-03-15 20:11:53 +000093ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
Ted Kremenek4fb821e2010-03-15 20:11:46 +000094 IdentifierInfo *propertyID) {
95
Ted Kremenekddcd1092010-03-15 20:11:53 +000096 DeclContext::lookup_const_iterator I, E;
Ted Kremenek4fb821e2010-03-15 20:11:46 +000097 llvm::tie(I, E) = DC->lookup(propertyID);
98 for ( ; I != E; ++I)
99 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
100 return PD;
101
102 return 0;
103}
104
Fariborz Jahaniana054e992008-04-21 19:04:53 +0000105/// FindPropertyDeclaration - Finds declaration of the property given its name
106/// in 'PropertyId' and returns it. It returns 0, if not found.
Fariborz Jahaniana054e992008-04-21 19:04:53 +0000107ObjCPropertyDecl *
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000108ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
Mike Stump11289f42009-09-09 15:08:12 +0000109
Ted Kremenekddcd1092010-03-15 20:11:53 +0000110 if (ObjCPropertyDecl *PD =
111 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
112 return PD;
Mike Stump11289f42009-09-09 15:08:12 +0000113
Ted Kremenekddcd1092010-03-15 20:11:53 +0000114 switch (getKind()) {
115 default:
116 break;
117 case Decl::ObjCProtocol: {
118 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
119 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
120 E = PID->protocol_end(); I != E; ++I)
Fariborz Jahanian30a42922010-02-15 21:55:26 +0000121 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
122 return P;
Ted Kremenekddcd1092010-03-15 20:11:53 +0000123 break;
124 }
125 case Decl::ObjCInterface: {
126 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
127 // Look through categories.
128 for (ObjCCategoryDecl *Cat = OID->getCategoryList();
129 Cat; Cat = Cat->getNextClassCategory())
130 if (!Cat->IsClassExtension())
131 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
132 return P;
133
134 // Look through protocols.
135 for (ObjCInterfaceDecl::protocol_iterator
136 I = OID->protocol_begin(), E = OID->protocol_end(); I != E; ++I)
137 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
138 return P;
139
140 // Finally, check the super class.
141 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
142 return superClass->FindPropertyDeclaration(PropertyId);
143 break;
144 }
145 case Decl::ObjCCategory: {
146 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
147 // Look through protocols.
148 if (!OCD->IsClassExtension())
149 for (ObjCCategoryDecl::protocol_iterator
150 I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I)
151 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
152 return P;
153
154 break;
Fariborz Jahaniandab04842009-01-19 18:16:19 +0000155 }
156 }
Steve Narofff9c65242008-06-05 13:55:23 +0000157 return 0;
158}
159
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000160/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
161/// with name 'PropertyId' in the primary class; including those in protocols
162/// (direct or indirect) used by the promary class.
163/// FIXME: Convert to DeclContext lookup...
164///
165ObjCPropertyDecl *
166ObjCContainerDecl::FindPropertyVisibleInPrimaryClass(
167 IdentifierInfo *PropertyId) const {
168 assert(isa<ObjCInterfaceDecl>(this) && "FindPropertyVisibleInPrimaryClass");
169 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
170 if ((*I)->getIdentifier() == PropertyId)
171 return *I;
172 const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this);
173 // Look through protocols.
174 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
175 E = OID->protocol_end(); I != E; ++I)
176 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
177 return P;
178 return 0;
179}
180
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000181void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
182 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
Douglas Gregor002b6712010-01-16 15:02:53 +0000183 const SourceLocation *Locs,
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000184 ASTContext &C)
185{
186 if (ReferencedProtocols.empty()) {
Douglas Gregor002b6712010-01-16 15:02:53 +0000187 ReferencedProtocols.set(ExtList, ExtNum, Locs, C);
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000188 return;
189 }
190 // Check for duplicate protocol in class's protocol list.
191 // This is (O)2. But it is extremely rare and number of protocols in
192 // class or its extension are very few.
193 llvm::SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000194 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000195 for (unsigned i = 0; i < ExtNum; i++) {
196 bool protocolExists = false;
197 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
198 for (protocol_iterator p = protocol_begin(), e = protocol_end();
199 p != e; p++) {
200 ObjCProtocolDecl *Proto = (*p);
201 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
202 protocolExists = true;
203 break;
204 }
205 }
206 // Do we want to warn on a protocol in extension class which
207 // already exist in the class? Probably not.
Douglas Gregor002b6712010-01-16 15:02:53 +0000208 if (!protocolExists) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000209 ProtocolRefs.push_back(ProtoInExtension);
Douglas Gregor002b6712010-01-16 15:02:53 +0000210 ProtocolLocs.push_back(Locs[i]);
211 }
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000212 }
213 if (ProtocolRefs.empty())
214 return;
Fariborz Jahanian8764c742009-10-05 21:32:49 +0000215 // Merge ProtocolRefs into class's protocol list;
Douglas Gregor002b6712010-01-16 15:02:53 +0000216 protocol_loc_iterator pl = protocol_loc_begin();
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000217 for (protocol_iterator p = protocol_begin(), e = protocol_end();
Douglas Gregor002b6712010-01-16 15:02:53 +0000218 p != e; ++p, ++pl) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000219 ProtocolRefs.push_back(*p);
Douglas Gregor002b6712010-01-16 15:02:53 +0000220 ProtocolLocs.push_back(*pl);
221 }
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000222 ReferencedProtocols.Destroy(C);
223 unsigned NumProtoRefs = ProtocolRefs.size();
Douglas Gregor002b6712010-01-16 15:02:53 +0000224 setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C);
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000225}
226
Fariborz Jahanianafe13862010-02-23 01:26:30 +0000227/// getClassExtension - Find class extension of the given class.
228// FIXME. can speed it up, if need be.
229ObjCCategoryDecl* ObjCInterfaceDecl::getClassExtension() const {
230 const ObjCInterfaceDecl* ClassDecl = this;
231 for (ObjCCategoryDecl *CDecl = ClassDecl->getCategoryList(); CDecl;
232 CDecl = CDecl->getNextClassCategory())
233 if (CDecl->IsClassExtension())
234 return CDecl;
235 return 0;
236}
237
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000238ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
239 ObjCInterfaceDecl *&clsDeclared) {
Chris Lattner89375192008-03-16 00:19:01 +0000240 ObjCInterfaceDecl* ClassDecl = this;
241 while (ClassDecl != NULL) {
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000242 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian68453832009-06-05 18:16:35 +0000243 clsDeclared = ClassDecl;
244 return I;
Chris Lattner89375192008-03-16 00:19:01 +0000245 }
Fariborz Jahanianafe13862010-02-23 01:26:30 +0000246 if (const ObjCCategoryDecl *CDecl = ClassDecl->getClassExtension())
247 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
248 clsDeclared = ClassDecl;
249 return I;
250 }
251
Chris Lattner89375192008-03-16 00:19:01 +0000252 ClassDecl = ClassDecl->getSuperClass();
253 }
254 return NULL;
255}
256
Fariborz Jahaniandb3a4c12009-05-22 17:12:32 +0000257/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
258/// class whose name is passed as argument. If it is not one of the super classes
259/// the it returns NULL.
260ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
261 const IdentifierInfo*ICName) {
262 ObjCInterfaceDecl* ClassDecl = this;
263 while (ClassDecl != NULL) {
264 if (ClassDecl->getIdentifier() == ICName)
265 return ClassDecl;
266 ClassDecl = ClassDecl->getSuperClass();
267 }
268 return NULL;
269}
270
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000271/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner89375192008-03-16 00:19:01 +0000272/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000273ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
274 bool isInstance) const {
275 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner89375192008-03-16 00:19:01 +0000276 ObjCMethodDecl *MethodDecl = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000277
Chris Lattner89375192008-03-16 00:19:01 +0000278 while (ClassDecl != NULL) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000279 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000280 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000281
Chris Lattner89375192008-03-16 00:19:01 +0000282 // Didn't find one yet - look through protocols.
Chris Lattnerd0045052008-07-21 18:19:38 +0000283 const ObjCList<ObjCProtocolDecl> &Protocols =
284 ClassDecl->getReferencedProtocols();
285 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
286 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000287 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000288 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000289
Chris Lattner89375192008-03-16 00:19:01 +0000290 // Didn't find one yet - now look through categories.
291 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
292 while (CatDecl) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000293 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000294 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000295
Steve Naroff5fd31b12008-12-08 20:57:28 +0000296 // Didn't find one yet - look through protocols.
297 const ObjCList<ObjCProtocolDecl> &Protocols =
298 CatDecl->getReferencedProtocols();
299 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
300 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000301 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroff8ec27842009-02-26 11:32:02 +0000302 return MethodDecl;
Chris Lattner89375192008-03-16 00:19:01 +0000303 CatDecl = CatDecl->getNextClassCategory();
304 }
305 ClassDecl = ClassDecl->getSuperClass();
306 }
307 return NULL;
308}
309
Steve Naroffbb69c942009-10-01 23:46:04 +0000310ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
311 const Selector &Sel) {
312 ObjCMethodDecl *Method = 0;
313 if (ObjCImplementationDecl *ImpDecl = getImplementation())
314 Method = ImpDecl->getInstanceMethod(Sel);
315
316 if (!Method && getSuperClass())
317 return getSuperClass()->lookupPrivateInstanceMethod(Sel);
318 return Method;
319}
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000320
321//===----------------------------------------------------------------------===//
322// ObjCMethodDecl
323//===----------------------------------------------------------------------===//
324
325ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump11289f42009-09-09 15:08:12 +0000326 SourceLocation beginLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000327 SourceLocation endLoc,
328 Selector SelInfo, QualType T,
Douglas Gregor12852d92010-03-08 14:59:44 +0000329 TypeSourceInfo *ResultTInfo,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000330 DeclContext *contextDecl,
331 bool isInstance,
332 bool isVariadic,
333 bool isSynthesized,
334 ImplementationControl impControl) {
335 return new (C) ObjCMethodDecl(beginLoc, endLoc,
Douglas Gregor12852d92010-03-08 14:59:44 +0000336 SelInfo, T, ResultTInfo, contextDecl,
337 isInstance,
338 isVariadic, isSynthesized, impControl);
Chris Lattner89375192008-03-16 00:19:01 +0000339}
340
Chris Lattner22298722009-02-20 21:35:13 +0000341void ObjCMethodDecl::Destroy(ASTContext &C) {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000342 if (Body) Body->Destroy(C);
343 if (SelfDecl) SelfDecl->Destroy(C);
Mike Stump11289f42009-09-09 15:08:12 +0000344
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000345 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
346 if (*I) (*I)->Destroy(C);
347
Chris Lattner22298722009-02-20 21:35:13 +0000348 ParamInfo.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000349
350 Decl::Destroy(C);
Chris Lattner89375192008-03-16 00:19:01 +0000351}
352
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000353/// \brief A definition will return its interface declaration.
354/// An interface declaration will return its definition.
355/// Otherwise it will return itself.
356ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
357 ASTContext &Ctx = getASTContext();
358 ObjCMethodDecl *Redecl = 0;
359 Decl *CtxD = cast<Decl>(getDeclContext());
360
361 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
362 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
363 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
364
365 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
366 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
367 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
368
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000369 } else if (ObjCImplementationDecl *ImplD =
370 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000371 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
372 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000373
374 } else if (ObjCCategoryImplDecl *CImplD =
375 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000376 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000377 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000378 }
379
380 return Redecl ? Redecl : this;
381}
382
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000383ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
384 Decl *CtxD = cast<Decl>(getDeclContext());
385
386 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
387 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
388 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
389 isInstanceMethod()))
390 return MD;
391
392 } else if (ObjCCategoryImplDecl *CImplD =
393 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000394 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000395 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
396 isInstanceMethod()))
397 return MD;
398 }
399
400 return this;
401}
402
Mike Stump11289f42009-09-09 15:08:12 +0000403void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000404 const ObjCInterfaceDecl *OID) {
405 QualType selfTy;
406 if (isInstanceMethod()) {
407 // There may be no interface context due to error in declaration
408 // of the interface (which has been reported). Recover gracefully.
409 if (OID) {
Daniel Dunbaraefc2b92009-04-22 04:34:53 +0000410 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff7cae42b2009-07-10 23:34:53 +0000411 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000412 } else {
413 selfTy = Context.getObjCIdType();
414 }
415 } else // we have a factory method.
416 selfTy = Context.getObjCClassType();
417
Mike Stump11289f42009-09-09 15:08:12 +0000418 setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
Steve Naroff04f2d142009-04-20 15:06:07 +0000419 &Context.Idents.get("self"), selfTy));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000420
Mike Stump11289f42009-09-09 15:08:12 +0000421 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
422 &Context.Idents.get("_cmd"),
Steve Naroff04f2d142009-04-20 15:06:07 +0000423 Context.getObjCSelType()));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000424}
425
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000426ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
427 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
428 return ID;
429 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
430 return CD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000431 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000432 return IMD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000433
434 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000435 assert(false && "unknown method context");
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000436 return 0;
437}
438
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000439//===----------------------------------------------------------------------===//
440// ObjCInterfaceDecl
441//===----------------------------------------------------------------------===//
442
443ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
444 DeclContext *DC,
445 SourceLocation atLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000446 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000447 SourceLocation ClassLoc,
448 bool ForwardDecl, bool isInternal){
449 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
450 isInternal);
451}
452
453ObjCInterfaceDecl::
454ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
455 SourceLocation CLoc, bool FD, bool isInternal)
456 : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
457 TypeForDecl(0), SuperClass(0),
458 CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
459 ClassLoc(CLoc) {
460}
461
Mike Stump11289f42009-09-09 15:08:12 +0000462void ObjCInterfaceDecl::Destroy(ASTContext &C) {
Chris Lattnerd8a47c42009-03-31 08:36:08 +0000463 for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000464 if (*I) (*I)->Destroy(C);
Mike Stump11289f42009-09-09 15:08:12 +0000465
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000466 // FIXME: CategoryList?
Mike Stump11289f42009-09-09 15:08:12 +0000467
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000468 // FIXME: Because there is no clear ownership
469 // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
470 // reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
471 Decl::Destroy(C);
472}
473
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000474ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
475 return getASTContext().getObjCImplementation(
476 const_cast<ObjCInterfaceDecl*>(this));
477}
478
479void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
480 getASTContext().setObjCImplementation(this, ImplD);
481}
482
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000483
484/// FindCategoryDeclaration - Finds category declaration in the list of
485/// categories for this class and returns it. Name of the category is passed
486/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000487///
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000488ObjCCategoryDecl *
489ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
490 for (ObjCCategoryDecl *Category = getCategoryList();
491 Category; Category = Category->getNextClassCategory())
492 if (Category->getIdentifier() == CategoryId)
493 return Category;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000494 return 0;
495}
496
Argyrios Kyrtzidis1559d67b2009-07-21 00:06:20 +0000497ObjCMethodDecl *
498ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
499 for (ObjCCategoryDecl *Category = getCategoryList();
500 Category; Category = Category->getNextClassCategory())
501 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
502 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
503 return MD;
504 return 0;
505}
506
507ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
508 for (ObjCCategoryDecl *Category = getCategoryList();
509 Category; Category = Category->getNextClassCategory())
510 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
511 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
512 return MD;
513 return 0;
514}
515
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000516/// ClassImplementsProtocol - Checks that 'lProto' protocol
517/// has been implemented in IDecl class, its super class or categories (if
518/// lookupCategory is true).
519bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
520 bool lookupCategory,
521 bool RHSIsQualifiedID) {
522 ObjCInterfaceDecl *IDecl = this;
523 // 1st, look up the class.
524 const ObjCList<ObjCProtocolDecl> &Protocols =
525 IDecl->getReferencedProtocols();
Mike Stump11289f42009-09-09 15:08:12 +0000526
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000527 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
528 E = Protocols.end(); PI != E; ++PI) {
529 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
530 return true;
531 // This is dubious and is added to be compatible with gcc. In gcc, it is
532 // also allowed assigning a protocol-qualified 'id' type to a LHS object
533 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
534 // object. This IMO, should be a bug.
535 // FIXME: Treat this as an extension, and flag this as an error when GCC
536 // extensions are not enabled.
Mike Stump11289f42009-09-09 15:08:12 +0000537 if (RHSIsQualifiedID &&
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000538 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
539 return true;
540 }
Mike Stump11289f42009-09-09 15:08:12 +0000541
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000542 // 2nd, look up the category.
543 if (lookupCategory)
544 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
545 CDecl = CDecl->getNextClassCategory()) {
546 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
547 E = CDecl->protocol_end(); PI != E; ++PI)
548 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
549 return true;
550 }
Mike Stump11289f42009-09-09 15:08:12 +0000551
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000552 // 3rd, look up the super class(s)
553 if (IDecl->getSuperClass())
554 return
555 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
556 RHSIsQualifiedID);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000558 return false;
559}
560
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000561//===----------------------------------------------------------------------===//
562// ObjCIvarDecl
563//===----------------------------------------------------------------------===//
564
565ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
566 SourceLocation L, IdentifierInfo *Id,
John McCallbcd03502009-12-07 02:54:59 +0000567 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000568 AccessControl ac, Expr *BW) {
John McCallbcd03502009-12-07 02:54:59 +0000569 return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000570}
571
572
573
574//===----------------------------------------------------------------------===//
575// ObjCAtDefsFieldDecl
576//===----------------------------------------------------------------------===//
577
578ObjCAtDefsFieldDecl
579*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
580 IdentifierInfo *Id, QualType T, Expr *BW) {
581 return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
582}
583
584void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
585 this->~ObjCAtDefsFieldDecl();
Mike Stump11289f42009-09-09 15:08:12 +0000586 C.Deallocate((void *)this);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000587}
588
589//===----------------------------------------------------------------------===//
590// ObjCProtocolDecl
591//===----------------------------------------------------------------------===//
592
593ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump11289f42009-09-09 15:08:12 +0000594 SourceLocation L,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000595 IdentifierInfo *Id) {
596 return new (C) ObjCProtocolDecl(DC, L, Id);
597}
598
599void ObjCProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner22298722009-02-20 21:35:13 +0000600 ReferencedProtocols.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000601 ObjCContainerDecl::Destroy(C);
602}
603
Steve Naroff114aecb2009-03-01 16:12:44 +0000604ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
605 ObjCProtocolDecl *PDecl = this;
606
607 if (Name == getIdentifier())
608 return PDecl;
609
610 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
611 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
612 return PDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000613
Steve Naroff114aecb2009-03-01 16:12:44 +0000614 return NULL;
615}
616
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000617// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000618// it inherited.
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000619ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
620 bool isInstance) const {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000621 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump11289f42009-09-09 15:08:12 +0000622
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000623 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000624 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000625
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000626 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000627 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000628 return MethodDecl;
629 return NULL;
630}
631
632//===----------------------------------------------------------------------===//
633// ObjCClassDecl
634//===----------------------------------------------------------------------===//
635
Mike Stump11289f42009-09-09 15:08:12 +0000636ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Ted Kremenek9b124e12009-11-18 00:28:11 +0000637 ObjCInterfaceDecl *const *Elts,
638 const SourceLocation *Locs,
639 unsigned nElts,
Chris Lattner22298722009-02-20 21:35:13 +0000640 ASTContext &C)
641 : Decl(ObjCClass, DC, L) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000642 setClassList(C, Elts, Locs, nElts);
Chris Lattner22298722009-02-20 21:35:13 +0000643}
644
Ted Kremenek9b124e12009-11-18 00:28:11 +0000645void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
646 const SourceLocation *Locs, unsigned Num) {
647 ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num,
648 llvm::alignof<ObjCClassRef>());
649 for (unsigned i = 0; i < Num; ++i)
650 new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]);
651
652 NumDecls = Num;
653}
Chris Lattner22298722009-02-20 21:35:13 +0000654
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000655ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
656 SourceLocation L,
657 ObjCInterfaceDecl *const *Elts,
Ted Kremenek9b124e12009-11-18 00:28:11 +0000658 const SourceLocation *Locs,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000659 unsigned nElts) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000660 return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000661}
662
663void ObjCClassDecl::Destroy(ASTContext &C) {
Ted Kremenek9b124e12009-11-18 00:28:11 +0000664 // ObjCInterfaceDecls registered with a DeclContext will get destroyed
665 // when the DeclContext is destroyed. For those created only by a forward
666 // declaration, the first @class that created the ObjCInterfaceDecl gets
667 // to destroy it.
668 // FIXME: Note that this ownership role is very brittle; a better
669 // polict is surely need in the future.
670 for (iterator I = begin(), E = end(); I !=E ; ++I) {
671 ObjCInterfaceDecl *ID = I->getInterface();
672 if (ID->isForwardDecl() && ID->getLocStart() == getLocStart())
673 ID->Destroy(C);
674 }
675
676 C.Deallocate(ForwardDecls);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000677 Decl::Destroy(C);
678}
679
Ted Kremenek49939c22009-11-18 01:26:56 +0000680SourceRange ObjCClassDecl::getSourceRange() const {
681 // FIXME: We should include the semicolon
682 assert(NumDecls);
683 return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation());
684}
685
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000686//===----------------------------------------------------------------------===//
687// ObjCForwardProtocolDecl
688//===----------------------------------------------------------------------===//
689
Chris Lattner22298722009-02-20 21:35:13 +0000690ObjCForwardProtocolDecl::
691ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
692 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000693 const SourceLocation *Locs, ASTContext &C)
Mike Stump11289f42009-09-09 15:08:12 +0000694: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor002b6712010-01-16 15:02:53 +0000695 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner22298722009-02-20 21:35:13 +0000696}
697
698
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000699ObjCForwardProtocolDecl *
700ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump11289f42009-09-09 15:08:12 +0000701 SourceLocation L,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000702 ObjCProtocolDecl *const *Elts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000703 unsigned NumElts,
704 const SourceLocation *Locs) {
705 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000706}
707
708void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
Chris Lattner22298722009-02-20 21:35:13 +0000709 ReferencedProtocols.Destroy(C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000710 Decl::Destroy(C);
711}
712
713//===----------------------------------------------------------------------===//
714// ObjCCategoryDecl
715//===----------------------------------------------------------------------===//
716
717ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor071676f2010-01-16 16:38:58 +0000718 SourceLocation AtLoc,
719 SourceLocation ClassNameLoc,
720 SourceLocation CategoryNameLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000721 IdentifierInfo *Id) {
Douglas Gregor071676f2010-01-16 16:38:58 +0000722 return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000723}
724
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000725ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
726 return getASTContext().getObjCImplementation(
727 const_cast<ObjCCategoryDecl*>(this));
728}
729
730void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
731 getASTContext().setObjCImplementation(this, ImplD);
732}
733
734
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000735//===----------------------------------------------------------------------===//
736// ObjCCategoryImplDecl
737//===----------------------------------------------------------------------===//
738
739ObjCCategoryImplDecl *
740ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
741 SourceLocation L,IdentifierInfo *Id,
742 ObjCInterfaceDecl *ClassInterface) {
743 return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
744}
745
Steve Narofff406f4d2009-10-29 21:11:04 +0000746ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000747 return getClassInterface()->FindCategoryDeclaration(getIdentifier());
748}
749
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000750
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000751void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor9a13efd2009-04-23 02:42:49 +0000752 // FIXME: The context should be correct before we get here.
Douglas Gregor29bd76f2009-04-23 01:02:12 +0000753 property->setLexicalDeclContext(this);
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000754 addDecl(property);
Douglas Gregor29bd76f2009-04-23 01:02:12 +0000755}
756
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000757void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
758 ASTContext &Ctx = getASTContext();
759
760 if (ObjCImplementationDecl *ImplD
Duncan Sands49c29ee2009-07-21 07:56:29 +0000761 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000762 if (IFace)
763 Ctx.setObjCImplementation(IFace, ImplD);
764
Duncan Sands49c29ee2009-07-21 07:56:29 +0000765 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000766 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
767 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
768 Ctx.setObjCImplementation(CD, ImplD);
769 }
770
771 ClassInterface = IFace;
772}
773
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000774/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattneraab70d22009-02-16 19:24:31 +0000775/// properties implemented in this category @implementation block and returns
776/// the implemented property that uses it.
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000777///
Chris Lattnera9ca0522009-02-28 18:42:10 +0000778ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000779FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
780 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000781 ObjCPropertyImplDecl *PID = *i;
782 if (PID->getPropertyIvarDecl() &&
783 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
784 return PID;
785 }
786 return 0;
787}
788
789/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
790/// added to the list of those properties @synthesized/@dynamic in this
791/// category @implementation block.
792///
Chris Lattnera9ca0522009-02-28 18:42:10 +0000793ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000794FindPropertyImplDecl(IdentifierInfo *Id) const {
795 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000796 ObjCPropertyImplDecl *PID = *i;
797 if (PID->getPropertyDecl()->getIdentifier() == Id)
798 return PID;
799 }
800 return 0;
801}
802
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000803//===----------------------------------------------------------------------===//
804// ObjCImplementationDecl
805//===----------------------------------------------------------------------===//
806
807ObjCImplementationDecl *
Mike Stump11289f42009-09-09 15:08:12 +0000808ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000809 SourceLocation L,
810 ObjCInterfaceDecl *ClassInterface,
811 ObjCInterfaceDecl *SuperDecl) {
812 return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
813}
814
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000815//===----------------------------------------------------------------------===//
816// ObjCCompatibleAliasDecl
817//===----------------------------------------------------------------------===//
818
819ObjCCompatibleAliasDecl *
820ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
821 SourceLocation L,
Mike Stump11289f42009-09-09 15:08:12 +0000822 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000823 ObjCInterfaceDecl* AliasedClass) {
824 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
825}
826
827//===----------------------------------------------------------------------===//
828// ObjCPropertyDecl
829//===----------------------------------------------------------------------===//
830
831ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
832 SourceLocation L,
833 IdentifierInfo *Id,
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000834 SourceLocation AtLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000835 QualType T,
836 PropertyControl propControl) {
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000837 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000838}
839
840
841//===----------------------------------------------------------------------===//
842// ObjCPropertyImplDecl
843//===----------------------------------------------------------------------===//
844
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000845ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregorc25d7a72009-01-09 00:49:46 +0000846 DeclContext *DC,
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000847 SourceLocation atLoc,
848 SourceLocation L,
849 ObjCPropertyDecl *property,
Daniel Dunbar3b4fdb02008-08-26 04:47:31 +0000850 Kind PK,
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000851 ObjCIvarDecl *ivar) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000852 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +0000853}
Chris Lattnered0e1642008-03-17 01:19:02 +0000854
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000855