blob: 4e22ebea16b0c0696b2055cd407ddb229c53062d [file] [log] [blame]
Chris Lattner10318b82008-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 Dunbarde300732008-08-11 04:54:23 +000016#include "clang/AST/Stmt.h"
Chris Lattner10318b82008-03-16 00:19:01 +000017using namespace clang;
18
Chris Lattner114add62008-03-16 00:49:28 +000019//===----------------------------------------------------------------------===//
Chris Lattner217eb8c2009-02-20 21:16:26 +000020// ObjCListBase
21//===----------------------------------------------------------------------===//
22
Chris Lattnerdf6133b2009-02-20 21:35:13 +000023void ObjCListBase::Destroy(ASTContext &Ctx) {
Chris Lattner217eb8c2009-02-20 21:16:26 +000024 delete[] List;
25 NumElts = 0;
26 List = 0;
27}
28
Chris Lattnerdf6133b2009-02-20 21:35:13 +000029void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Chris Lattner217eb8c2009-02-20 21:16:26 +000030 assert(List == 0 && "Elements already set!");
31 if (Elts == 0) return; // Setting to an empty list is a noop.
32
33 List = new void*[Elts];
34 NumElts = Elts;
35 memcpy(List, InList, sizeof(void*)*Elts);
36}
37
38
39//===----------------------------------------------------------------------===//
Chris Lattner13f63602009-02-20 20:59:54 +000040// ObjCInterfaceDecl
Chris Lattner114add62008-03-16 00:49:28 +000041//===----------------------------------------------------------------------===//
42
Steve Naroffab63fd62009-01-08 17:28:14 +000043// Get the local instance method declared in this interface.
44// FIXME: handle overloading, instance & class methods can have the same name.
45ObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const {
46 lookup_const_result MethodResult = lookup(Sel);
47 if (MethodResult.first)
48 return const_cast<ObjCMethodDecl*>(
Chris Lattner13f63602009-02-20 20:59:54 +000049 dyn_cast<ObjCMethodDecl>(*MethodResult.first));
Steve Naroffab63fd62009-01-08 17:28:14 +000050 return 0;
51}
52
53// Get the local class method declared in this interface.
54ObjCMethodDecl *ObjCContainerDecl::getClassMethod(Selector Sel) const {
55 lookup_const_result MethodResult = lookup(Sel);
56 if (MethodResult.first)
57 return const_cast<ObjCMethodDecl*>(
Chris Lattner13f63602009-02-20 20:59:54 +000058 dyn_cast<ObjCMethodDecl>(*MethodResult.first));
Steve Naroffab63fd62009-01-08 17:28:14 +000059 return 0;
60}
61
Fariborz Jahanianef8a3df2008-04-21 19:04:53 +000062/// FindPropertyDeclaration - Finds declaration of the property given its name
63/// in 'PropertyId' and returns it. It returns 0, if not found.
Steve Naroffdcf1e842009-01-11 12:47:58 +000064/// FIXME: Convert to DeclContext lookup...
Fariborz Jahanianef8a3df2008-04-21 19:04:53 +000065///
66ObjCPropertyDecl *
Steve Naroff451f83c2009-01-09 15:36:25 +000067ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
Chris Lattner13f63602009-02-20 20:59:54 +000068 for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
69 if ((*I)->getIdentifier() == PropertyId)
70 return *I;
71
Fariborz Jahanianfaca5e22009-01-09 21:04:52 +000072 const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this);
73 if (PID) {
Chris Lattner13f63602009-02-20 20:59:54 +000074 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
75 E = PID->protocol_end(); I != E; ++I)
76 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
77 return P;
Fariborz Jahanianfaca5e22009-01-09 21:04:52 +000078 }
79
Fariborz Jahanian6b0ed6f2009-01-19 18:16:19 +000080 if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
Steve Naroff451f83c2009-01-09 15:36:25 +000081 // Look through categories.
82 for (ObjCCategoryDecl *Category = OID->getCategoryList();
83 Category; Category = Category->getNextClassCategory()) {
Chris Lattner13f63602009-02-20 20:59:54 +000084 if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId))
85 return P;
Steve Naroff451f83c2009-01-09 15:36:25 +000086 }
87 // Look through protocols.
88 for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
89 E = OID->protocol_end(); I != E; ++I) {
Chris Lattner13f63602009-02-20 20:59:54 +000090 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
91 return P;
Steve Naroff451f83c2009-01-09 15:36:25 +000092 }
93 if (OID->getSuperClass())
94 return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
Chris Lattner13f63602009-02-20 20:59:54 +000095 } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
Fariborz Jahanian6b0ed6f2009-01-19 18:16:19 +000096 // Look through protocols.
97 for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
98 E = OCD->protocol_end(); I != E; ++I) {
Chris Lattner13f63602009-02-20 20:59:54 +000099 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
100 return P;
Fariborz Jahanian6b0ed6f2009-01-19 18:16:19 +0000101 }
102 }
Steve Naroffd1f0eb42008-06-05 13:55:23 +0000103 return 0;
104}
105
Chris Lattner10318b82008-03-16 00:19:01 +0000106ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
107 IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
108 ObjCInterfaceDecl* ClassDecl = this;
109 while (ClassDecl != NULL) {
110 for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
111 I != E; ++I) {
112 if ((*I)->getIdentifier() == ID) {
113 clsDeclared = ClassDecl;
114 return *I;
115 }
116 }
117 ClassDecl = ClassDecl->getSuperClass();
118 }
119 return NULL;
120}
121
122/// lookupInstanceMethod - This method returns an instance method by looking in
123/// the class, its categories, and its super classes (using a linear search).
124ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
125 ObjCInterfaceDecl* ClassDecl = this;
126 ObjCMethodDecl *MethodDecl = 0;
127
128 while (ClassDecl != NULL) {
129 if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
130 return MethodDecl;
131
132 // Didn't find one yet - look through protocols.
Chris Lattner8bcb5252008-07-21 18:19:38 +0000133 const ObjCList<ObjCProtocolDecl> &Protocols =
134 ClassDecl->getReferencedProtocols();
135 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
136 E = Protocols.end(); I != E; ++I)
137 if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
Chris Lattner10318b82008-03-16 00:19:01 +0000138 return MethodDecl;
Chris Lattner8bcb5252008-07-21 18:19:38 +0000139
Chris Lattner10318b82008-03-16 00:19:01 +0000140 // Didn't find one yet - now look through categories.
141 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
142 while (CatDecl) {
143 if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
144 return MethodDecl;
Steve Naroffaf151802008-12-08 20:57:28 +0000145
146 // Didn't find one yet - look through protocols.
147 const ObjCList<ObjCProtocolDecl> &Protocols =
148 CatDecl->getReferencedProtocols();
149 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
150 E = Protocols.end(); I != E; ++I)
151 if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
152 return MethodDecl;
Chris Lattner10318b82008-03-16 00:19:01 +0000153 CatDecl = CatDecl->getNextClassCategory();
154 }
155 ClassDecl = ClassDecl->getSuperClass();
156 }
157 return NULL;
158}
159
160// lookupClassMethod - This method returns a class method by looking in the
161// class, its categories, and its super classes (using a linear search).
162ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
163 ObjCInterfaceDecl* ClassDecl = this;
164 ObjCMethodDecl *MethodDecl = 0;
165
166 while (ClassDecl != NULL) {
167 if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
168 return MethodDecl;
169
170 // Didn't find one yet - look through protocols.
Chris Lattner0be08822008-07-21 21:32:27 +0000171 for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
172 E = ClassDecl->protocol_end(); I != E; ++I)
Chris Lattner8bcb5252008-07-21 18:19:38 +0000173 if ((MethodDecl = (*I)->getClassMethod(Sel)))
Chris Lattner10318b82008-03-16 00:19:01 +0000174 return MethodDecl;
Chris Lattner0be08822008-07-21 21:32:27 +0000175
Chris Lattner10318b82008-03-16 00:19:01 +0000176 // Didn't find one yet - now look through categories.
177 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
178 while (CatDecl) {
179 if ((MethodDecl = CatDecl->getClassMethod(Sel)))
180 return MethodDecl;
181 CatDecl = CatDecl->getNextClassCategory();
182 }
183 ClassDecl = ClassDecl->getSuperClass();
184 }
185 return NULL;
186}
187
Chris Lattner13f63602009-02-20 20:59:54 +0000188
189
190//===----------------------------------------------------------------------===//
191// ObjCMethodDecl
192//===----------------------------------------------------------------------===//
193
194ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
195 SourceLocation beginLoc,
196 SourceLocation endLoc,
197 Selector SelInfo, QualType T,
198 DeclContext *contextDecl,
199 bool isInstance,
200 bool isVariadic,
201 bool isSynthesized,
202 ImplementationControl impControl) {
203 return new (C) ObjCMethodDecl(beginLoc, endLoc,
204 SelInfo, T, contextDecl,
205 isInstance,
206 isVariadic, isSynthesized, impControl);
Chris Lattner10318b82008-03-16 00:19:01 +0000207}
208
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000209void ObjCMethodDecl::Destroy(ASTContext &C) {
Chris Lattner13f63602009-02-20 20:59:54 +0000210 if (Body) Body->Destroy(C);
211 if (SelfDecl) SelfDecl->Destroy(C);
212
213 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
214 if (*I) (*I)->Destroy(C);
215
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000216 ParamInfo.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000217
218 Decl::Destroy(C);
Chris Lattner10318b82008-03-16 00:19:01 +0000219}
220
Chris Lattner13f63602009-02-20 20:59:54 +0000221void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
222 const ObjCInterfaceDecl *OID) {
223 QualType selfTy;
224 if (isInstanceMethod()) {
225 // There may be no interface context due to error in declaration
226 // of the interface (which has been reported). Recover gracefully.
227 if (OID) {
228 selfTy =Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl*>(OID));
229 selfTy = Context.getPointerType(selfTy);
230 } else {
231 selfTy = Context.getObjCIdType();
232 }
233 } else // we have a factory method.
234 selfTy = Context.getObjCClassType();
235
236 SelfDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(),
237 &Context.Idents.get("self"), selfTy);
238
239 CmdDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(),
240 &Context.Idents.get("_cmd"),
241 Context.getObjCSelType());
242}
243
244
245
246/// getSynthesizedMethodSize - Compute size of synthesized method name
247/// as done be the rewrite.
Fariborz Jahanian68342282008-12-05 22:32:48 +0000248///
Chris Lattner13f63602009-02-20 20:59:54 +0000249unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
250 // syntesized method name is a concatenation of -/+[class-name selector]
251 // Get length of this name.
252 unsigned length = 3; // _I_ or _C_
253 length += getClassInterface()->getNameAsString().size()+1; // extra for _
254 if (const ObjCCategoryImplDecl *CID =
255 dyn_cast<ObjCCategoryImplDecl>(getDeclContext()))
256 length += CID->getNameAsString().size()+1;
257 length += getSelector().getAsString().size(); // selector name
258 return length;
259}
260
261ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
262 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
263 return ID;
264 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
265 return CD->getClassInterface();
266 if (ObjCImplementationDecl *IMD =
267 dyn_cast<ObjCImplementationDecl>(getDeclContext()))
268 return IMD->getClassInterface();
269 if (ObjCCategoryImplDecl *CID =
270 dyn_cast<ObjCCategoryImplDecl>(getDeclContext()))
271 return CID->getClassInterface();
272 assert(false && "unknown method context");
Fariborz Jahanian68342282008-12-05 22:32:48 +0000273 return 0;
274}
275
Chris Lattner13f63602009-02-20 20:59:54 +0000276//===----------------------------------------------------------------------===//
277// ObjCInterfaceDecl
278//===----------------------------------------------------------------------===//
279
280ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
281 DeclContext *DC,
282 SourceLocation atLoc,
283 IdentifierInfo *Id,
284 SourceLocation ClassLoc,
285 bool ForwardDecl, bool isInternal){
286 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
287 isInternal);
288}
289
290ObjCInterfaceDecl::
291ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
292 SourceLocation CLoc, bool FD, bool isInternal)
293 : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
294 TypeForDecl(0), SuperClass(0),
295 CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
296 ClassLoc(CLoc) {
297}
298
299void ObjCInterfaceDecl::Destroy(ASTContext &C) {
300 for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
301 if (*I) (*I)->Destroy(C);
302
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000303 IVars.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000304 // FIXME: CategoryList?
305
306 // FIXME: Because there is no clear ownership
307 // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
308 // reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
309 Decl::Destroy(C);
310}
311
312
313/// FindCategoryDeclaration - Finds category declaration in the list of
314/// categories for this class and returns it. Name of the category is passed
315/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanian68342282008-12-05 22:32:48 +0000316///
Chris Lattner13f63602009-02-20 20:59:54 +0000317ObjCCategoryDecl *
318ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
319 for (ObjCCategoryDecl *Category = getCategoryList();
320 Category; Category = Category->getNextClassCategory())
321 if (Category->getIdentifier() == CategoryId)
322 return Category;
Fariborz Jahanian68342282008-12-05 22:32:48 +0000323 return 0;
324}
325
Chris Lattner13f63602009-02-20 20:59:54 +0000326/// lookupFieldDeclForIvar - looks up a field decl' in the laid out
327/// storage which matches this 'ivar'.
328///
329FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context,
330 const ObjCIvarDecl *IVar) {
331 const RecordDecl *RecordForDecl = Context.addRecordToClass(this);
332 assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class");
333 DeclarationName Member = IVar->getDeclName();
334 DeclContext::lookup_result Lookup =
335 (const_cast< RecordDecl *>(RecordForDecl))->lookup(Member);
336 assert((Lookup.first != Lookup.second) && "field decl not found");
337 FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first);
338 assert(MemberDecl && "field decl not found");
339 return MemberDecl;
340}
341
342//===----------------------------------------------------------------------===//
343// ObjCIvarDecl
344//===----------------------------------------------------------------------===//
345
346ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
347 SourceLocation L, IdentifierInfo *Id,
348 QualType T, AccessControl ac, Expr *BW) {
349 return new (C) ObjCIvarDecl(DC, L, Id, T, ac, BW);
350}
351
352
353
354//===----------------------------------------------------------------------===//
355// ObjCAtDefsFieldDecl
356//===----------------------------------------------------------------------===//
357
358ObjCAtDefsFieldDecl
359*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
360 IdentifierInfo *Id, QualType T, Expr *BW) {
361 return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
362}
363
364void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
365 this->~ObjCAtDefsFieldDecl();
366 C.Deallocate((void *)this);
367}
368
369//===----------------------------------------------------------------------===//
370// ObjCProtocolDecl
371//===----------------------------------------------------------------------===//
372
373ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
374 SourceLocation L,
375 IdentifierInfo *Id) {
376 return new (C) ObjCProtocolDecl(DC, L, Id);
377}
378
379void ObjCProtocolDecl::Destroy(ASTContext &C) {
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000380 ReferencedProtocols.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000381 ObjCContainerDecl::Destroy(C);
382}
383
384// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
385// it inherited.
386ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
387 ObjCMethodDecl *MethodDecl = NULL;
388
389 if ((MethodDecl = getInstanceMethod(Sel)))
390 return MethodDecl;
391
392 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
393 if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
394 return MethodDecl;
395 return NULL;
396}
397
398// lookupInstanceMethod - Lookup a class method in the protocol and protocols
399// it inherited.
400ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
401 ObjCMethodDecl *MethodDecl = NULL;
402
403 if ((MethodDecl = getClassMethod(Sel)))
404 return MethodDecl;
405
406 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
407 if ((MethodDecl = (*I)->lookupClassMethod(Sel)))
408 return MethodDecl;
409 return NULL;
410}
411
412//===----------------------------------------------------------------------===//
413// ObjCClassDecl
414//===----------------------------------------------------------------------===//
415
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000416ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
417 ObjCInterfaceDecl *const *Elts, unsigned nElts,
418 ASTContext &C)
419 : Decl(ObjCClass, DC, L) {
420 ForwardDecls.set(Elts, nElts, C);
421}
422
423
Chris Lattner13f63602009-02-20 20:59:54 +0000424ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
425 SourceLocation L,
426 ObjCInterfaceDecl *const *Elts,
427 unsigned nElts) {
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000428 return new (C) ObjCClassDecl(DC, L, Elts, nElts, C);
Chris Lattner13f63602009-02-20 20:59:54 +0000429}
430
431void ObjCClassDecl::Destroy(ASTContext &C) {
432
433 // FIXME: There is no clear ownership policy now for referenced
434 // ObjCInterfaceDecls. Some of them can be forward declarations that
435 // are never later defined (in which case the ObjCClassDecl owns them)
436 // or the ObjCInterfaceDecl later becomes a real definition later. Ideally
437 // we should have separate objects for forward declarations and definitions,
438 // obviating this problem. Because of this situation, referenced
439 // ObjCInterfaceDecls are destroyed in ~TranslationUnit.
440
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000441 ForwardDecls.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000442 Decl::Destroy(C);
443}
444
445//===----------------------------------------------------------------------===//
446// ObjCForwardProtocolDecl
447//===----------------------------------------------------------------------===//
448
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000449ObjCForwardProtocolDecl::
450ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
451 ObjCProtocolDecl *const *Elts, unsigned nElts,
452 ASTContext &C)
453: Decl(ObjCForwardProtocol, DC, L) {
454 ReferencedProtocols.set(Elts, nElts, C);
455}
456
457
Chris Lattner13f63602009-02-20 20:59:54 +0000458ObjCForwardProtocolDecl *
459ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
460 SourceLocation L,
461 ObjCProtocolDecl *const *Elts,
462 unsigned NumElts) {
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000463 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, C);
Chris Lattner13f63602009-02-20 20:59:54 +0000464}
465
466void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000467 ReferencedProtocols.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000468 Decl::Destroy(C);
469}
470
471//===----------------------------------------------------------------------===//
472// ObjCCategoryDecl
473//===----------------------------------------------------------------------===//
474
475ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
476 SourceLocation L,
477 IdentifierInfo *Id) {
478 return new (C) ObjCCategoryDecl(DC, L, Id);
479}
480
481//===----------------------------------------------------------------------===//
482// ObjCCategoryImplDecl
483//===----------------------------------------------------------------------===//
484
485ObjCCategoryImplDecl *
486ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
487 SourceLocation L,IdentifierInfo *Id,
488 ObjCInterfaceDecl *ClassInterface) {
489 return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
490}
491
492
Fariborz Jahanian68342282008-12-05 22:32:48 +0000493/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattner715e8482009-02-16 19:24:31 +0000494/// properties implemented in this category @implementation block and returns
495/// the implemented property that uses it.
Fariborz Jahanian68342282008-12-05 22:32:48 +0000496///
Chris Lattner715e8482009-02-16 19:24:31 +0000497ObjCPropertyImplDecl *ObjCCategoryImplDecl::
498FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
499 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanian68342282008-12-05 22:32:48 +0000500 ObjCPropertyImplDecl *PID = *i;
501 if (PID->getPropertyIvarDecl() &&
502 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
503 return PID;
504 }
505 return 0;
506}
507
508/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
509/// added to the list of those properties @synthesized/@dynamic in this
510/// category @implementation block.
511///
Chris Lattner715e8482009-02-16 19:24:31 +0000512ObjCPropertyImplDecl *ObjCCategoryImplDecl::
513FindPropertyImplDecl(IdentifierInfo *Id) const {
514 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanian68342282008-12-05 22:32:48 +0000515 ObjCPropertyImplDecl *PID = *i;
516 if (PID->getPropertyDecl()->getIdentifier() == Id)
517 return PID;
518 }
519 return 0;
520}
521
Chris Lattner10318b82008-03-16 00:19:01 +0000522// lookupInstanceMethod - This method returns an instance method by looking in
523// the class implementation. Unlike interfaces, we don't look outside the
524// implementation.
Daniel Dunbardd24b9a2008-08-26 06:53:45 +0000525ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) const {
Chris Lattner10318b82008-03-16 00:19:01 +0000526 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
527 if ((*I)->getSelector() == Sel)
528 return *I;
529 return NULL;
530}
531
532// lookupClassMethod - This method returns an instance method by looking in
533// the class implementation. Unlike interfaces, we don't look outside the
534// implementation.
Daniel Dunbardd24b9a2008-08-26 06:53:45 +0000535ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) const {
Chris Lattner10318b82008-03-16 00:19:01 +0000536 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
537 I != E; ++I)
538 if ((*I)->getSelector() == Sel)
539 return *I;
540 return NULL;
541}
542
Chris Lattner13f63602009-02-20 20:59:54 +0000543//===----------------------------------------------------------------------===//
544// ObjCImplementationDecl
545//===----------------------------------------------------------------------===//
546
547ObjCImplementationDecl *
548ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
549 SourceLocation L,
550 ObjCInterfaceDecl *ClassInterface,
551 ObjCInterfaceDecl *SuperDecl) {
552 return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
553}
554
555/// Destroy - Call destructors and release memory.
Chris Lattnerdf6133b2009-02-20 21:35:13 +0000556void ObjCImplementationDecl::Destroy(ASTContext &C) {
557 IVars.Destroy(C);
Chris Lattner13f63602009-02-20 20:59:54 +0000558 Decl::Destroy(C);
559}
560
561/// getInstanceMethod - This method returns an instance method by
562/// looking in the class implementation. Unlike interfaces, we don't
563/// look outside the implementation.
564ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) const {
565 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
566 if ((*I)->getSelector() == Sel)
567 return *I;
Chris Lattner10318b82008-03-16 00:19:01 +0000568 return NULL;
569}
570
Chris Lattner13f63602009-02-20 20:59:54 +0000571/// getClassMethod - This method returns a class method by looking in
572/// the class implementation. Unlike interfaces, we don't look outside
573/// the implementation.
574ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) const {
575 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
576 I != E; ++I)
577 if ((*I)->getSelector() == Sel)
578 return *I;
Chris Lattner10318b82008-03-16 00:19:01 +0000579 return NULL;
580}
581
Chris Lattner13f63602009-02-20 20:59:54 +0000582/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
583/// added to the list of those properties @synthesized/@dynamic in this
584/// @implementation block.
Chris Lattner10318b82008-03-16 00:19:01 +0000585///
Chris Lattner13f63602009-02-20 20:59:54 +0000586ObjCPropertyImplDecl *ObjCImplementationDecl::
587FindPropertyImplDecl(IdentifierInfo *Id) const {
588 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
589 ObjCPropertyImplDecl *PID = *i;
590 if (PID->getPropertyDecl()->getIdentifier() == Id)
591 return PID;
592 }
Chris Lattner10318b82008-03-16 00:19:01 +0000593 return 0;
594}
Chris Lattner44859612008-03-17 01:19:02 +0000595
Chris Lattner13f63602009-02-20 20:59:54 +0000596/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
597/// properties implemented in this @implementation block and returns the
598/// implemented property that uses it.
599///
600ObjCPropertyImplDecl *ObjCImplementationDecl::
601FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
602 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
603 ObjCPropertyImplDecl *PID = *i;
604 if (PID->getPropertyIvarDecl() &&
605 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
606 return PID;
607 }
608 return 0;
609}
610
611//===----------------------------------------------------------------------===//
612// ObjCCompatibleAliasDecl
613//===----------------------------------------------------------------------===//
614
615ObjCCompatibleAliasDecl *
616ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
617 SourceLocation L,
618 IdentifierInfo *Id,
619 ObjCInterfaceDecl* AliasedClass) {
620 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
621}
622
623//===----------------------------------------------------------------------===//
624// ObjCPropertyDecl
625//===----------------------------------------------------------------------===//
626
627ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
628 SourceLocation L,
629 IdentifierInfo *Id,
630 QualType T,
631 PropertyControl propControl) {
632 return new (C) ObjCPropertyDecl(DC, L, Id, T);
633}
634
635
636//===----------------------------------------------------------------------===//
637// ObjCPropertyImplDecl
638//===----------------------------------------------------------------------===//
639
Fariborz Jahaniandc0569e2008-04-23 00:06:01 +0000640ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregor6e4fa2c2009-01-09 00:49:46 +0000641 DeclContext *DC,
Fariborz Jahaniandc0569e2008-04-23 00:06:01 +0000642 SourceLocation atLoc,
643 SourceLocation L,
644 ObjCPropertyDecl *property,
Daniel Dunbar14117fc2008-08-26 04:47:31 +0000645 Kind PK,
Fariborz Jahaniandc0569e2008-04-23 00:06:01 +0000646 ObjCIvarDecl *ivar) {
Steve Naroff5abb0282009-01-27 21:25:57 +0000647 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
Fariborz Jahaniandc0569e2008-04-23 00:06:01 +0000648}
Chris Lattner44859612008-03-17 01:19:02 +0000649
Chris Lattnereee57c02008-04-04 06:12:32 +0000650