blob: d4e32a3b5f283339970dcc2f0c4aacc320faf38b [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"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000017#include "clang/AST/ASTMutationListener.h"
Steve Naroffc4173fa2009-02-22 19:35:57 +000018#include "llvm/ADT/STLExtras.h"
Chris Lattner89375192008-03-16 00:19:01 +000019using namespace clang;
20
Chris Lattner8d8829e2008-03-16 00:49:28 +000021//===----------------------------------------------------------------------===//
Chris Lattner4d1eb762009-02-20 21:16:26 +000022// ObjCListBase
23//===----------------------------------------------------------------------===//
24
Chris Lattner22298722009-02-20 21:35:13 +000025void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Douglas Gregorb412e172010-07-25 18:17:45 +000026 List = 0;
Chris Lattner4d1eb762009-02-20 21:16:26 +000027 if (Elts == 0) return; // Setting to an empty list is a noop.
Mike Stump11289f42009-09-09 15:08:12 +000028
29
Chris Lattner7c981a72009-02-20 21:44:01 +000030 List = new (Ctx) void*[Elts];
Chris Lattner4d1eb762009-02-20 21:16:26 +000031 NumElts = Elts;
32 memcpy(List, InList, sizeof(void*)*Elts);
33}
34
Douglas Gregor002b6712010-01-16 15:02:53 +000035void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
36 const SourceLocation *Locs, ASTContext &Ctx) {
37 if (Elts == 0)
38 return;
39
40 Locations = new (Ctx) SourceLocation[Elts];
41 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
42 set(InList, Elts, Ctx);
43}
44
Chris Lattner4d1eb762009-02-20 21:16:26 +000045//===----------------------------------------------------------------------===//
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +000046// ObjCInterfaceDecl
Chris Lattner8d8829e2008-03-16 00:49:28 +000047//===----------------------------------------------------------------------===//
48
Fariborz Jahanian68453832009-06-05 18:16:35 +000049/// getIvarDecl - This method looks up an ivar in this ContextDecl.
50///
51ObjCIvarDecl *
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000052ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
Fariborz Jahanian68453832009-06-05 18:16:35 +000053 lookup_const_iterator Ivar, IvarEnd;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000054 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
Fariborz Jahanian68453832009-06-05 18:16:35 +000055 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
56 return ivar;
57 }
58 return 0;
59}
60
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000061// Get the local instance/class method declared in this interface.
Douglas Gregorbcced4e2009-04-09 21:40:53 +000062ObjCMethodDecl *
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000063ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
Steve Naroffc4173fa2009-02-22 19:35:57 +000064 // Since instance & class methods can have the same name, the loop below
65 // ensures we get the correct method.
66 //
67 // @interface Whatever
68 // - (int) class_method;
69 // + (float) class_method;
70 // @end
71 //
72 lookup_const_iterator Meth, MethEnd;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000073 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
Steve Naroffc4173fa2009-02-22 19:35:57 +000074 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
Argyrios Kyrtzidis6de05602009-07-25 22:15:22 +000075 if (MD && MD->isInstanceMethod() == isInstance)
Steve Naroffc4173fa2009-02-22 19:35:57 +000076 return MD;
77 }
Steve Naroff35c62ae2009-01-08 17:28:14 +000078 return 0;
79}
80
Ted Kremenek4fb821e2010-03-15 20:11:46 +000081ObjCPropertyDecl *
Ted Kremenekddcd1092010-03-15 20:11:53 +000082ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
Ted Kremenek4fb821e2010-03-15 20:11:46 +000083 IdentifierInfo *propertyID) {
84
Ted Kremenekddcd1092010-03-15 20:11:53 +000085 DeclContext::lookup_const_iterator I, E;
Ted Kremenek4fb821e2010-03-15 20:11:46 +000086 llvm::tie(I, E) = DC->lookup(propertyID);
87 for ( ; I != E; ++I)
88 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
89 return PD;
90
91 return 0;
92}
93
Fariborz Jahaniana054e992008-04-21 19:04:53 +000094/// FindPropertyDeclaration - Finds declaration of the property given its name
95/// in 'PropertyId' and returns it. It returns 0, if not found.
Fariborz Jahaniana054e992008-04-21 19:04:53 +000096ObjCPropertyDecl *
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +000097ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
Mike Stump11289f42009-09-09 15:08:12 +000098
Ted Kremenekddcd1092010-03-15 20:11:53 +000099 if (ObjCPropertyDecl *PD =
100 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
101 return PD;
Mike Stump11289f42009-09-09 15:08:12 +0000102
Ted Kremenekddcd1092010-03-15 20:11:53 +0000103 switch (getKind()) {
104 default:
105 break;
106 case Decl::ObjCProtocol: {
107 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
108 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
109 E = PID->protocol_end(); I != E; ++I)
Fariborz Jahanian30a42922010-02-15 21:55:26 +0000110 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
111 return P;
Ted Kremenekddcd1092010-03-15 20:11:53 +0000112 break;
113 }
114 case Decl::ObjCInterface: {
115 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
116 // Look through categories.
117 for (ObjCCategoryDecl *Cat = OID->getCategoryList();
118 Cat; Cat = Cat->getNextClassCategory())
119 if (!Cat->IsClassExtension())
120 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
121 return P;
122
123 // Look through protocols.
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000124 for (ObjCInterfaceDecl::all_protocol_iterator
125 I = OID->all_referenced_protocol_begin(),
126 E = OID->all_referenced_protocol_end(); I != E; ++I)
Ted Kremenekddcd1092010-03-15 20:11:53 +0000127 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
128 return P;
129
130 // Finally, check the super class.
131 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
132 return superClass->FindPropertyDeclaration(PropertyId);
133 break;
134 }
135 case Decl::ObjCCategory: {
136 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
137 // Look through protocols.
138 if (!OCD->IsClassExtension())
139 for (ObjCCategoryDecl::protocol_iterator
140 I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I)
141 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
142 return P;
143
144 break;
Fariborz Jahaniandab04842009-01-19 18:16:19 +0000145 }
146 }
Steve Narofff9c65242008-06-05 13:55:23 +0000147 return 0;
148}
149
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000150/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
151/// with name 'PropertyId' in the primary class; including those in protocols
Ted Kremenekd133a862010-03-15 20:30:07 +0000152/// (direct or indirect) used by the primary class.
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000153///
154ObjCPropertyDecl *
Ted Kremenekd133a862010-03-15 20:30:07 +0000155ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000156 IdentifierInfo *PropertyId) const {
Douglas Gregor73693022010-12-01 23:49:52 +0000157 if (ExternallyCompleted)
158 LoadExternalDefinition();
159
Ted Kremenekd133a862010-03-15 20:30:07 +0000160 if (ObjCPropertyDecl *PD =
161 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
162 return PD;
163
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000164 // Look through protocols.
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000165 for (ObjCInterfaceDecl::all_protocol_iterator
166 I = all_referenced_protocol_begin(),
167 E = all_referenced_protocol_end(); I != E; ++I)
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000168 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
169 return P;
Ted Kremenekd133a862010-03-15 20:30:07 +0000170
Fariborz Jahaniande8db162009-11-02 22:45:15 +0000171 return 0;
172}
173
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000174void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
175 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
176 ASTContext &C)
177{
Douglas Gregor73693022010-12-01 23:49:52 +0000178 if (ExternallyCompleted)
179 LoadExternalDefinition();
180
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000181 if (AllReferencedProtocols.empty() && ReferencedProtocols.empty()) {
182 AllReferencedProtocols.set(ExtList, ExtNum, C);
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000183 return;
184 }
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000185
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000186 // Check for duplicate protocol in class's protocol list.
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000187 // This is O(n*m). But it is extremely rare and number of protocols in
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000188 // class or its extension are very few.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000189 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000190 for (unsigned i = 0; i < ExtNum; i++) {
191 bool protocolExists = false;
192 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000193 for (all_protocol_iterator
194 p = all_referenced_protocol_begin(),
195 e = all_referenced_protocol_end(); p != e; ++p) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000196 ObjCProtocolDecl *Proto = (*p);
197 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
198 protocolExists = true;
199 break;
200 }
201 }
202 // Do we want to warn on a protocol in extension class which
203 // already exist in the class? Probably not.
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000204 if (!protocolExists)
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000205 ProtocolRefs.push_back(ProtoInExtension);
206 }
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000207
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000208 if (ProtocolRefs.empty())
209 return;
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000210
Fariborz Jahanian8764c742009-10-05 21:32:49 +0000211 // Merge ProtocolRefs into class's protocol list;
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000212 for (all_protocol_iterator p = all_referenced_protocol_begin(),
213 e = all_referenced_protocol_end(); p != e; ++p) {
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000214 ProtocolRefs.push_back(*p);
Douglas Gregor002b6712010-01-16 15:02:53 +0000215 }
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000216
217 AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(), C);
Fariborz Jahanian092cd6e2009-10-05 20:41:32 +0000218}
219
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000220void ObjCInterfaceDecl::completedForwardDecl() {
221 assert(isForwardDecl() && "Only valid to call for forward refs");
222 ForwardDecl = false;
223 if (ASTMutationListener *L = getASTContext().getASTMutationListener())
224 L->CompletedObjCForwardRef(this);
225}
226
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000227/// getFirstClassExtension - Find first class extension of the given class.
228ObjCCategoryDecl* ObjCInterfaceDecl::getFirstClassExtension() const {
229 for (ObjCCategoryDecl *CDecl = getCategoryList(); CDecl;
Fariborz Jahanianafe13862010-02-23 01:26:30 +0000230 CDecl = CDecl->getNextClassCategory())
231 if (CDecl->IsClassExtension())
232 return CDecl;
233 return 0;
234}
235
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000236/// getNextClassCategory - Find next class extension in list of categories.
237const ObjCCategoryDecl* ObjCCategoryDecl::getNextClassExtension() const {
238 for (const ObjCCategoryDecl *CDecl = getNextClassCategory(); CDecl;
239 CDecl = CDecl->getNextClassCategory())
240 if (CDecl->IsClassExtension())
241 return CDecl;
242 return 0;
243}
244
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000245ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
246 ObjCInterfaceDecl *&clsDeclared) {
Argyrios Kyrtzidis4e8b1362011-10-19 02:25:16 +0000247 if (ExternallyCompleted)
248 LoadExternalDefinition();
249
Chris Lattner89375192008-03-16 00:19:01 +0000250 ObjCInterfaceDecl* ClassDecl = this;
251 while (ClassDecl != NULL) {
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000252 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian68453832009-06-05 18:16:35 +0000253 clsDeclared = ClassDecl;
254 return I;
Chris Lattner89375192008-03-16 00:19:01 +0000255 }
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000256 for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension();
257 CDecl; CDecl = CDecl->getNextClassExtension()) {
Fariborz Jahanianafe13862010-02-23 01:26:30 +0000258 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
259 clsDeclared = ClassDecl;
260 return I;
261 }
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000262 }
Fariborz Jahanianafe13862010-02-23 01:26:30 +0000263
Chris Lattner89375192008-03-16 00:19:01 +0000264 ClassDecl = ClassDecl->getSuperClass();
265 }
266 return NULL;
267}
268
Fariborz Jahaniandb3a4c12009-05-22 17:12:32 +0000269/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
270/// class whose name is passed as argument. If it is not one of the super classes
271/// the it returns NULL.
272ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
273 const IdentifierInfo*ICName) {
Argyrios Kyrtzidis4e8b1362011-10-19 02:25:16 +0000274 if (ExternallyCompleted)
275 LoadExternalDefinition();
276
Fariborz Jahaniandb3a4c12009-05-22 17:12:32 +0000277 ObjCInterfaceDecl* ClassDecl = this;
278 while (ClassDecl != NULL) {
279 if (ClassDecl->getIdentifier() == ICName)
280 return ClassDecl;
281 ClassDecl = ClassDecl->getSuperClass();
282 }
283 return NULL;
284}
285
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000286/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner89375192008-03-16 00:19:01 +0000287/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000288ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
289 bool isInstance) const {
290 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner89375192008-03-16 00:19:01 +0000291 ObjCMethodDecl *MethodDecl = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000292
Douglas Gregor73693022010-12-01 23:49:52 +0000293 if (ExternallyCompleted)
294 LoadExternalDefinition();
295
Chris Lattner89375192008-03-16 00:19:01 +0000296 while (ClassDecl != NULL) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000297 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000298 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000299
Chris Lattner89375192008-03-16 00:19:01 +0000300 // Didn't find one yet - look through protocols.
Chris Lattnerd0045052008-07-21 18:19:38 +0000301 const ObjCList<ObjCProtocolDecl> &Protocols =
302 ClassDecl->getReferencedProtocols();
303 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
304 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000305 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000306 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000307
Chris Lattner89375192008-03-16 00:19:01 +0000308 // Didn't find one yet - now look through categories.
309 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
310 while (CatDecl) {
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000311 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner89375192008-03-16 00:19:01 +0000312 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000313
Steve Naroff5fd31b12008-12-08 20:57:28 +0000314 // Didn't find one yet - look through protocols.
315 const ObjCList<ObjCProtocolDecl> &Protocols =
316 CatDecl->getReferencedProtocols();
317 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
318 E = Protocols.end(); I != E; ++I)
Argyrios Kyrtzidis553376b2009-07-25 22:15:51 +0000319 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroff8ec27842009-02-26 11:32:02 +0000320 return MethodDecl;
Chris Lattner89375192008-03-16 00:19:01 +0000321 CatDecl = CatDecl->getNextClassCategory();
322 }
323 ClassDecl = ClassDecl->getSuperClass();
324 }
325 return NULL;
326}
327
Fariborz Jahanianecbbb6e2010-12-03 23:37:08 +0000328ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
329 const Selector &Sel,
330 bool Instance) {
Argyrios Kyrtzidis4e8b1362011-10-19 02:25:16 +0000331 if (ExternallyCompleted)
332 LoadExternalDefinition();
333
Steve Naroffbb69c942009-10-01 23:46:04 +0000334 ObjCMethodDecl *Method = 0;
335 if (ObjCImplementationDecl *ImpDecl = getImplementation())
Fariborz Jahanianecbbb6e2010-12-03 23:37:08 +0000336 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
337 : ImpDecl->getClassMethod(Sel);
Steve Naroffbb69c942009-10-01 23:46:04 +0000338
339 if (!Method && getSuperClass())
Fariborz Jahanianecbbb6e2010-12-03 23:37:08 +0000340 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
Steve Naroffbb69c942009-10-01 23:46:04 +0000341 return Method;
342}
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000343
344//===----------------------------------------------------------------------===//
345// ObjCMethodDecl
346//===----------------------------------------------------------------------===//
347
348ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump11289f42009-09-09 15:08:12 +0000349 SourceLocation beginLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000350 SourceLocation endLoc,
351 Selector SelInfo, QualType T,
Douglas Gregor12852d92010-03-08 14:59:44 +0000352 TypeSourceInfo *ResultTInfo,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000353 DeclContext *contextDecl,
354 bool isInstance,
355 bool isVariadic,
356 bool isSynthesized,
Argyrios Kyrtzidis004df6e2011-08-17 19:25:08 +0000357 bool isImplicitlyDeclared,
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000358 bool isDefined,
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000359 ImplementationControl impControl,
Argyrios Kyrtzidis38493942011-10-03 06:36:29 +0000360 bool HasRelatedResultType) {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000361 return new (C) ObjCMethodDecl(beginLoc, endLoc,
Douglas Gregor12852d92010-03-08 14:59:44 +0000362 SelInfo, T, ResultTInfo, contextDecl,
363 isInstance,
Argyrios Kyrtzidis004df6e2011-08-17 19:25:08 +0000364 isVariadic, isSynthesized, isImplicitlyDeclared,
365 isDefined,
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000366 impControl,
Argyrios Kyrtzidis38493942011-10-03 06:36:29 +0000367 HasRelatedResultType);
Chris Lattner89375192008-03-16 00:19:01 +0000368}
369
Argyrios Kyrtzidisdcaaa212011-10-14 08:02:31 +0000370void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
371 assert(PrevMethod);
372 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
373 IsRedeclaration = true;
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000374 PrevMethod->HasRedeclaration = true;
Argyrios Kyrtzidisdcaaa212011-10-14 08:02:31 +0000375}
376
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000377void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
378 ArrayRef<ParmVarDecl*> Params,
379 ArrayRef<SourceLocation> SelLocs) {
380 ParamsAndSelLocs = 0;
381 NumParams = Params.size();
382 if (Params.empty() && SelLocs.empty())
383 return;
384
385 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
386 sizeof(SourceLocation) * SelLocs.size();
387 ParamsAndSelLocs = C.Allocate(Size);
388 std::copy(Params.begin(), Params.end(), getParams());
389 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
390}
391
392void ObjCMethodDecl::getSelectorLocs(
393 SmallVectorImpl<SourceLocation> &SelLocs) const {
394 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
395 SelLocs.push_back(getSelectorLoc(i));
396}
397
398void ObjCMethodDecl::setMethodParams(ASTContext &C,
399 ArrayRef<ParmVarDecl*> Params,
400 ArrayRef<SourceLocation> SelLocs) {
401 assert((!SelLocs.empty() || isImplicit()) &&
402 "No selector locs for non-implicit method");
403 if (isImplicit())
404 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
405
406 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc);
407 if (SelLocsKind != SelLoc_NonStandard)
408 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
409
410 setParamsAndSelLocs(C, Params, SelLocs);
411}
412
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000413/// \brief A definition will return its interface declaration.
414/// An interface declaration will return its definition.
415/// Otherwise it will return itself.
416ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
417 ASTContext &Ctx = getASTContext();
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000418 ObjCMethodDecl *Redecl = 0;
419 if (HasRedeclaration)
420 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
Argyrios Kyrtzidisc5e829c2011-10-14 06:48:06 +0000421 if (Redecl)
422 return Redecl;
423
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000424 Decl *CtxD = cast<Decl>(getDeclContext());
425
426 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
427 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
428 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
429
430 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
431 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
432 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
433
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000434 } else if (ObjCImplementationDecl *ImplD =
435 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000436 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
437 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000438
439 } else if (ObjCCategoryImplDecl *CImplD =
440 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000441 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +0000442 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000443 }
444
Argyrios Kyrtzidisdcaaa212011-10-14 08:02:31 +0000445 if (!Redecl && isRedeclaration()) {
446 // This is the last redeclaration, go back to the first method.
447 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
448 isInstanceMethod());
449 }
450
Argyrios Kyrtzidisa8cf0be2009-07-21 00:06:36 +0000451 return Redecl ? Redecl : this;
452}
453
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000454ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
455 Decl *CtxD = cast<Decl>(getDeclContext());
456
457 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
458 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
459 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
460 isInstanceMethod()))
461 return MD;
462
463 } else if (ObjCCategoryImplDecl *CImplD =
464 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Narofff406f4d2009-10-29 21:11:04 +0000465 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000466 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
467 isInstanceMethod()))
468 return MD;
469 }
470
Argyrios Kyrtzidis690dccd2011-10-17 19:48:09 +0000471 if (isRedeclaration())
472 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
473 isInstanceMethod());
474
Argyrios Kyrtzidisf390c432009-07-28 05:11:17 +0000475 return this;
476}
477
John McCallb4526252011-03-02 01:50:55 +0000478ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
479 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
John McCallfb55f852011-03-02 21:01:41 +0000480 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
John McCallb4526252011-03-02 01:50:55 +0000481 return family;
482
John McCall86bc21f2011-03-02 11:33:24 +0000483 // Check for an explicit attribute.
484 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
485 // The unfortunate necessity of mapping between enums here is due
486 // to the attributes framework.
487 switch (attr->getFamily()) {
488 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
489 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
490 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
491 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
492 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
493 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
494 }
495 Family = static_cast<unsigned>(family);
496 return family;
497 }
498
John McCallb4526252011-03-02 01:50:55 +0000499 family = getSelector().getMethodFamily();
500 switch (family) {
501 case OMF_None: break;
502
503 // init only has a conventional meaning for an instance method, and
504 // it has to return an object.
505 case OMF_init:
506 if (!isInstanceMethod() || !getResultType()->isObjCObjectPointerType())
507 family = OMF_None;
508 break;
509
510 // alloc/copy/new have a conventional meaning for both class and
511 // instance methods, but they require an object return.
512 case OMF_alloc:
513 case OMF_copy:
514 case OMF_mutableCopy:
515 case OMF_new:
516 if (!getResultType()->isObjCObjectPointerType())
517 family = OMF_None;
518 break;
519
520 // These selectors have a conventional meaning only for instance methods.
521 case OMF_dealloc:
Nico Weber1fb82662011-08-28 22:35:17 +0000522 case OMF_finalize:
John McCallb4526252011-03-02 01:50:55 +0000523 case OMF_retain:
524 case OMF_release:
525 case OMF_autorelease:
526 case OMF_retainCount:
Douglas Gregor33823722011-06-11 01:09:30 +0000527 case OMF_self:
John McCallb4526252011-03-02 01:50:55 +0000528 if (!isInstanceMethod())
529 family = OMF_None;
530 break;
Fariborz Jahanianb7a77362011-07-05 22:38:59 +0000531
532 case OMF_performSelector:
533 if (!isInstanceMethod() ||
534 !getResultType()->isObjCIdType())
535 family = OMF_None;
536 else {
537 unsigned noParams = param_size();
538 if (noParams < 1 || noParams > 3)
539 family = OMF_None;
540 else {
541 ObjCMethodDecl::arg_type_iterator it = arg_type_begin();
542 QualType ArgT = (*it);
543 if (!ArgT->isObjCSelType()) {
544 family = OMF_None;
545 break;
546 }
547 while (--noParams) {
548 it++;
549 ArgT = (*it);
550 if (!ArgT->isObjCIdType()) {
551 family = OMF_None;
552 break;
553 }
554 }
555 }
556 }
557 break;
558
John McCallb4526252011-03-02 01:50:55 +0000559 }
560
561 // Cache the result.
562 Family = static_cast<unsigned>(family);
563 return family;
564}
565
Mike Stump11289f42009-09-09 15:08:12 +0000566void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000567 const ObjCInterfaceDecl *OID) {
568 QualType selfTy;
569 if (isInstanceMethod()) {
570 // There may be no interface context due to error in declaration
571 // of the interface (which has been reported). Recover gracefully.
572 if (OID) {
Daniel Dunbaraefc2b92009-04-22 04:34:53 +0000573 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff7cae42b2009-07-10 23:34:53 +0000574 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000575 } else {
576 selfTy = Context.getObjCIdType();
577 }
578 } else // we have a factory method.
579 selfTy = Context.getObjCClassType();
580
John McCalld4631322011-06-17 06:42:21 +0000581 bool selfIsPseudoStrong = false;
John McCall31168b02011-06-15 23:02:42 +0000582 bool selfIsConsumed = false;
Ted Kremenek1fcdaa92011-11-14 21:59:25 +0000583
584 if (Context.getLangOptions().ObjCAutoRefCount) {
585 if (isInstanceMethod()) {
586 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
John McCall31168b02011-06-15 23:02:42 +0000587
Ted Kremenek1fcdaa92011-11-14 21:59:25 +0000588 // 'self' is always __strong. It's actually pseudo-strong except
589 // in init methods (or methods labeled ns_consumes_self), though.
590 Qualifiers qs;
591 qs.setObjCLifetime(Qualifiers::OCL_Strong);
592 selfTy = Context.getQualifiedType(selfTy, qs);
John McCall31168b02011-06-15 23:02:42 +0000593
Ted Kremenek1fcdaa92011-11-14 21:59:25 +0000594 // In addition, 'self' is const unless this is an init method.
595 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
596 selfTy = selfTy.withConst();
597 selfIsPseudoStrong = true;
598 }
599 }
600 else {
601 assert(isClassMethod());
602 // 'self' is always const in class methods.
John McCall31168b02011-06-15 23:02:42 +0000603 selfTy = selfTy.withConst();
John McCalld4631322011-06-17 06:42:21 +0000604 selfIsPseudoStrong = true;
605 }
John McCall31168b02011-06-15 23:02:42 +0000606 }
607
608 ImplicitParamDecl *self
609 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
610 &Context.Idents.get("self"), selfTy);
611 setSelfDecl(self);
612
613 if (selfIsConsumed)
614 self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000615
John McCalld4631322011-06-17 06:42:21 +0000616 if (selfIsPseudoStrong)
617 self->setARCPseudoStrong(true);
618
Mike Stump11289f42009-09-09 15:08:12 +0000619 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
620 &Context.Idents.get("_cmd"),
Steve Naroff04f2d142009-04-20 15:06:07 +0000621 Context.getObjCSelType()));
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000622}
623
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000624ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
625 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
626 return ID;
627 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
628 return CD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000629 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000630 return IMD->getClassInterface();
Argyrios Kyrtzidis2cee40d2009-07-28 05:10:52 +0000631
632 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
David Blaikie83d382b2011-09-23 05:06:16 +0000633 llvm_unreachable("unknown method context");
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000634}
635
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000636//===----------------------------------------------------------------------===//
637// ObjCInterfaceDecl
638//===----------------------------------------------------------------------===//
639
640ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
641 DeclContext *DC,
642 SourceLocation atLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000643 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000644 SourceLocation ClassLoc,
645 bool ForwardDecl, bool isInternal){
Douglas Gregor1c283312010-08-11 12:19:30 +0000646 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
647 isInternal);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000648}
649
650ObjCInterfaceDecl::
651ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
Douglas Gregor1c283312010-08-11 12:19:30 +0000652 SourceLocation CLoc, bool FD, bool isInternal)
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000653 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000654 TypeForDecl(0), SuperClass(0),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000655 CategoryList(0), IvarList(0),
656 InitiallyForwardDecl(FD), ForwardDecl(FD),
Argyrios Kyrtzidisae8e7922011-11-15 06:20:21 +0000657 ExternallyCompleted(false) {
658 setImplicit(isInternal);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000659}
660
Douglas Gregor73693022010-12-01 23:49:52 +0000661void ObjCInterfaceDecl::LoadExternalDefinition() const {
662 assert(ExternallyCompleted && "Class is not externally completed");
663 ExternallyCompleted = false;
664 getASTContext().getExternalSource()->CompleteType(
665 const_cast<ObjCInterfaceDecl *>(this));
666}
667
668void ObjCInterfaceDecl::setExternallyCompleted() {
669 assert(getASTContext().getExternalSource() &&
670 "Class can't be externally completed without an external source");
671 assert(!ForwardDecl &&
672 "Forward declarations can't be externally completed");
673 ExternallyCompleted = true;
674}
675
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000676ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
Douglas Gregor73693022010-12-01 23:49:52 +0000677 if (ExternallyCompleted)
678 LoadExternalDefinition();
679
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +0000680 return getASTContext().getObjCImplementation(
681 const_cast<ObjCInterfaceDecl*>(this));
682}
683
684void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
685 getASTContext().setObjCImplementation(this, ImplD);
686}
687
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000688/// all_declared_ivar_begin - return first ivar declared in this class,
689/// its extensions and its implementation. Lazily build the list on first
690/// access.
691ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
692 if (IvarList)
693 return IvarList;
694
695 ObjCIvarDecl *curIvar = 0;
696 if (!ivar_empty()) {
697 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
698 IvarList = (*I); ++I;
699 for (curIvar = IvarList; I != E; curIvar = *I, ++I)
700 curIvar->setNextIvar(*I);
701 }
702
703 for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl;
704 CDecl = CDecl->getNextClassExtension()) {
705 if (!CDecl->ivar_empty()) {
706 ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
707 E = CDecl->ivar_end();
708 if (!IvarList) {
709 IvarList = (*I); ++I;
710 curIvar = IvarList;
711 }
712 for ( ;I != E; curIvar = *I, ++I)
713 curIvar->setNextIvar(*I);
714 }
715 }
716
717 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
718 if (!ImplDecl->ivar_empty()) {
719 ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
720 E = ImplDecl->ivar_end();
721 if (!IvarList) {
722 IvarList = (*I); ++I;
723 curIvar = IvarList;
724 }
725 for ( ;I != E; curIvar = *I, ++I)
726 curIvar->setNextIvar(*I);
727 }
728 }
729 return IvarList;
730}
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000731
732/// FindCategoryDeclaration - Finds category declaration in the list of
733/// categories for this class and returns it. Name of the category is passed
734/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000735///
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000736ObjCCategoryDecl *
737ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
Douglas Gregor73693022010-12-01 23:49:52 +0000738 if (ExternallyCompleted)
739 LoadExternalDefinition();
740
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000741 for (ObjCCategoryDecl *Category = getCategoryList();
742 Category; Category = Category->getNextClassCategory())
743 if (Category->getIdentifier() == CategoryId)
744 return Category;
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +0000745 return 0;
746}
747
Argyrios Kyrtzidis1559d67b2009-07-21 00:06:20 +0000748ObjCMethodDecl *
749ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
750 for (ObjCCategoryDecl *Category = getCategoryList();
751 Category; Category = Category->getNextClassCategory())
752 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
753 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
754 return MD;
755 return 0;
756}
757
758ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
759 for (ObjCCategoryDecl *Category = getCategoryList();
760 Category; Category = Category->getNextClassCategory())
761 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
762 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
763 return MD;
764 return 0;
765}
766
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000767/// ClassImplementsProtocol - Checks that 'lProto' protocol
768/// has been implemented in IDecl class, its super class or categories (if
769/// lookupCategory is true).
770bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
771 bool lookupCategory,
772 bool RHSIsQualifiedID) {
773 ObjCInterfaceDecl *IDecl = this;
774 // 1st, look up the class.
775 const ObjCList<ObjCProtocolDecl> &Protocols =
776 IDecl->getReferencedProtocols();
Mike Stump11289f42009-09-09 15:08:12 +0000777
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000778 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
779 E = Protocols.end(); PI != E; ++PI) {
780 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
781 return true;
782 // This is dubious and is added to be compatible with gcc. In gcc, it is
783 // also allowed assigning a protocol-qualified 'id' type to a LHS object
784 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
785 // object. This IMO, should be a bug.
786 // FIXME: Treat this as an extension, and flag this as an error when GCC
787 // extensions are not enabled.
Mike Stump11289f42009-09-09 15:08:12 +0000788 if (RHSIsQualifiedID &&
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000789 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
790 return true;
791 }
Mike Stump11289f42009-09-09 15:08:12 +0000792
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000793 // 2nd, look up the category.
794 if (lookupCategory)
795 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
796 CDecl = CDecl->getNextClassCategory()) {
797 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
798 E = CDecl->protocol_end(); PI != E; ++PI)
799 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
800 return true;
801 }
Mike Stump11289f42009-09-09 15:08:12 +0000802
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000803 // 3rd, look up the super class(s)
804 if (IDecl->getSuperClass())
805 return
806 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
807 RHSIsQualifiedID);
Mike Stump11289f42009-09-09 15:08:12 +0000808
Fariborz Jahanian3f8917a2009-08-11 22:02:25 +0000809 return false;
810}
811
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000812//===----------------------------------------------------------------------===//
813// ObjCIvarDecl
814//===----------------------------------------------------------------------===//
815
Daniel Dunbarfe3ead72010-04-02 20:10:03 +0000816ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
Abramo Bagnaradff19302011-03-08 08:55:46 +0000817 SourceLocation StartLoc,
818 SourceLocation IdLoc, IdentifierInfo *Id,
John McCallbcd03502009-12-07 02:54:59 +0000819 QualType T, TypeSourceInfo *TInfo,
Fariborz Jahanian18722982010-07-17 00:59:30 +0000820 AccessControl ac, Expr *BW,
821 bool synthesized) {
Daniel Dunbarfe3ead72010-04-02 20:10:03 +0000822 if (DC) {
823 // Ivar's can only appear in interfaces, implementations (via synthesized
824 // properties), and class extensions (via direct declaration, or synthesized
825 // properties).
826 //
827 // FIXME: This should really be asserting this:
828 // (isa<ObjCCategoryDecl>(DC) &&
829 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
830 // but unfortunately we sometimes place ivars into non-class extension
831 // categories on error. This breaks an AST invariant, and should not be
832 // fixed.
833 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
834 isa<ObjCCategoryDecl>(DC)) &&
835 "Invalid ivar decl context!");
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000836 // Once a new ivar is created in any of class/class-extension/implementation
837 // decl contexts, the previously built IvarList must be rebuilt.
838 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
839 if (!ID) {
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000840 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) {
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000841 ID = IM->getClassInterface();
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000842 if (BW)
843 IM->setHasSynthBitfield(true);
Chad Rosier6fdf38b2011-08-17 23:08:45 +0000844 } else {
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000845 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
846 ID = CD->getClassInterface();
847 if (BW)
848 CD->setHasSynthBitfield(true);
849 }
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000850 }
851 ID->setIvarList(0);
Daniel Dunbarfe3ead72010-04-02 20:10:03 +0000852 }
853
Abramo Bagnaradff19302011-03-08 08:55:46 +0000854 return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo,
855 ac, BW, synthesized);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000856}
857
Daniel Dunbar89947ea2010-04-02 21:13:59 +0000858const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
859 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000860
Daniel Dunbar89947ea2010-04-02 21:13:59 +0000861 switch (DC->getKind()) {
862 default:
863 case ObjCCategoryImpl:
864 case ObjCProtocol:
David Blaikie83d382b2011-09-23 05:06:16 +0000865 llvm_unreachable("invalid ivar container!");
Daniel Dunbar89947ea2010-04-02 21:13:59 +0000866
867 // Ivars can only appear in class extension categories.
868 case ObjCCategory: {
869 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
870 assert(CD->IsClassExtension() && "invalid container for ivar!");
871 return CD->getClassInterface();
872 }
873
874 case ObjCImplementation:
875 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
876
877 case ObjCInterface:
878 return cast<ObjCInterfaceDecl>(DC);
879 }
880}
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000881
882//===----------------------------------------------------------------------===//
883// ObjCAtDefsFieldDecl
884//===----------------------------------------------------------------------===//
885
886ObjCAtDefsFieldDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +0000887*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
888 SourceLocation StartLoc, SourceLocation IdLoc,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000889 IdentifierInfo *Id, QualType T, Expr *BW) {
Abramo Bagnaradff19302011-03-08 08:55:46 +0000890 return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000891}
892
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000893//===----------------------------------------------------------------------===//
894// ObjCProtocolDecl
895//===----------------------------------------------------------------------===//
896
897ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000898 IdentifierInfo *Id,
899 SourceLocation nameLoc,
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000900 SourceLocation atStartLoc,
901 bool isForwardDecl) {
902 return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000903}
904
Steve Naroff114aecb2009-03-01 16:12:44 +0000905ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
906 ObjCProtocolDecl *PDecl = this;
907
908 if (Name == getIdentifier())
909 return PDecl;
910
911 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
912 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
913 return PDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000914
Steve Naroff114aecb2009-03-01 16:12:44 +0000915 return NULL;
916}
917
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000918// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000919// it inherited.
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000920ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
921 bool isInstance) const {
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000922 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump11289f42009-09-09 15:08:12 +0000923
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000924 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000925 return MethodDecl;
Mike Stump11289f42009-09-09 15:08:12 +0000926
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000927 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidise6ed65b2009-07-25 22:15:38 +0000928 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000929 return MethodDecl;
930 return NULL;
931}
932
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000933void ObjCProtocolDecl::completedForwardDecl() {
934 assert(isForwardDecl() && "Only valid to call for forward refs");
935 isForwardProtoDecl = false;
936 if (ASTMutationListener *L = getASTContext().getASTMutationListener())
937 L->CompletedObjCForwardRef(this);
938}
939
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000940//===----------------------------------------------------------------------===//
941// ObjCClassDecl
942//===----------------------------------------------------------------------===//
943
Mike Stump11289f42009-09-09 15:08:12 +0000944ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000945 ObjCInterfaceDecl *const Elt,
946 const SourceLocation Loc,
Chris Lattner22298722009-02-20 21:35:13 +0000947 ASTContext &C)
948 : Decl(ObjCClass, DC, L) {
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000949 setClass(C, Elt, Loc);
Ted Kremenek9b124e12009-11-18 00:28:11 +0000950}
Chris Lattner22298722009-02-20 21:35:13 +0000951
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000952ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
953 SourceLocation L,
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000954 ObjCInterfaceDecl *const Elt,
955 const SourceLocation Loc) {
956 return new (C) ObjCClassDecl(DC, L, Elt, Loc, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000957}
958
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000959void ObjCClassDecl::setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
960 const SourceLocation Loc) {
961
962 ForwardDecl = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef),
963 llvm::alignOf<ObjCClassRef>());
964 new (ForwardDecl) ObjCClassRef(Cls, Loc);
965}
966
Ted Kremenek49939c22009-11-18 01:26:56 +0000967SourceRange ObjCClassDecl::getSourceRange() const {
968 // FIXME: We should include the semicolon
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000969 return SourceRange(getLocation(), ForwardDecl->getLocation());
Ted Kremenek49939c22009-11-18 01:26:56 +0000970}
971
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000972//===----------------------------------------------------------------------===//
973// ObjCForwardProtocolDecl
974//===----------------------------------------------------------------------===//
975
Chris Lattner22298722009-02-20 21:35:13 +0000976ObjCForwardProtocolDecl::
977ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
978 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000979 const SourceLocation *Locs, ASTContext &C)
Mike Stump11289f42009-09-09 15:08:12 +0000980: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor002b6712010-01-16 15:02:53 +0000981 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner22298722009-02-20 21:35:13 +0000982}
983
984
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000985ObjCForwardProtocolDecl *
986ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump11289f42009-09-09 15:08:12 +0000987 SourceLocation L,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000988 ObjCProtocolDecl *const *Elts,
Douglas Gregor002b6712010-01-16 15:02:53 +0000989 unsigned NumElts,
990 const SourceLocation *Locs) {
991 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000992}
993
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +0000994//===----------------------------------------------------------------------===//
995// ObjCCategoryDecl
996//===----------------------------------------------------------------------===//
997
998ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor071676f2010-01-16 16:38:58 +0000999 SourceLocation AtLoc,
1000 SourceLocation ClassNameLoc,
1001 SourceLocation CategoryNameLoc,
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +00001002 IdentifierInfo *Id,
1003 ObjCInterfaceDecl *IDecl) {
1004 ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
1005 CategoryNameLoc, Id,
1006 IDecl);
1007 if (IDecl) {
1008 // Link this category into its class's category list.
1009 CatDecl->NextClassCategory = IDecl->getCategoryList();
1010 IDecl->setCategoryList(CatDecl);
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001011 if (ASTMutationListener *L = C.getASTMutationListener())
1012 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +00001013 }
1014
1015 return CatDecl;
1016}
1017
1018ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, EmptyShell Empty) {
1019 return new (C) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(),
1020 SourceLocation(), 0, 0);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001021}
1022
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +00001023ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1024 return getASTContext().getObjCImplementation(
1025 const_cast<ObjCCategoryDecl*>(this));
1026}
1027
1028void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1029 getASTContext().setObjCImplementation(this, ImplD);
1030}
1031
1032
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001033//===----------------------------------------------------------------------===//
1034// ObjCCategoryImplDecl
1035//===----------------------------------------------------------------------===//
1036
1037ObjCCategoryImplDecl *
1038ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001039 IdentifierInfo *Id,
1040 ObjCInterfaceDecl *ClassInterface,
1041 SourceLocation nameLoc,
1042 SourceLocation atStartLoc) {
1043 return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface,
1044 nameLoc, atStartLoc);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001045}
1046
Steve Narofff406f4d2009-10-29 21:11:04 +00001047ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Ted Kremeneke184ac52010-03-19 20:39:03 +00001048 // The class interface might be NULL if we are working with invalid code.
1049 if (const ObjCInterfaceDecl *ID = getClassInterface())
1050 return ID->FindCategoryDeclaration(getIdentifier());
1051 return 0;
Argyrios Kyrtzidisa56fa192009-07-28 05:11:05 +00001052}
1053
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001054
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +00001055void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor9a13efd2009-04-23 02:42:49 +00001056 // FIXME: The context should be correct before we get here.
Douglas Gregor29bd76f2009-04-23 01:02:12 +00001057 property->setLexicalDeclContext(this);
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +00001058 addDecl(property);
Douglas Gregor29bd76f2009-04-23 01:02:12 +00001059}
1060
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +00001061void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
1062 ASTContext &Ctx = getASTContext();
1063
1064 if (ObjCImplementationDecl *ImplD
Duncan Sands49c29ee2009-07-21 07:56:29 +00001065 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +00001066 if (IFace)
1067 Ctx.setObjCImplementation(IFace, ImplD);
1068
Duncan Sands49c29ee2009-07-21 07:56:29 +00001069 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis6d9fab72009-07-21 00:05:53 +00001070 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
1071 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
1072 Ctx.setObjCImplementation(CD, ImplD);
1073 }
1074
1075 ClassInterface = IFace;
1076}
1077
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +00001078/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattneraab70d22009-02-16 19:24:31 +00001079/// properties implemented in this category @implementation block and returns
1080/// the implemented property that uses it.
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +00001081///
Chris Lattnera9ca0522009-02-28 18:42:10 +00001082ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +00001083FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
1084 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +00001085 ObjCPropertyImplDecl *PID = *i;
1086 if (PID->getPropertyIvarDecl() &&
1087 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
1088 return PID;
1089 }
1090 return 0;
1091}
1092
1093/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
1094/// added to the list of those properties @synthesized/@dynamic in this
1095/// category @implementation block.
1096///
Chris Lattnera9ca0522009-02-28 18:42:10 +00001097ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +00001098FindPropertyImplDecl(IdentifierInfo *Id) const {
1099 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianfbbaf6a2008-12-05 22:32:48 +00001100 ObjCPropertyImplDecl *PID = *i;
1101 if (PID->getPropertyDecl()->getIdentifier() == Id)
1102 return PID;
1103 }
1104 return 0;
1105}
1106
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001107raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001108 const ObjCCategoryImplDecl *CID) {
1109 OS << CID->getName();
1110 return OS;
1111}
1112
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001113//===----------------------------------------------------------------------===//
1114// ObjCImplementationDecl
1115//===----------------------------------------------------------------------===//
1116
1117ObjCImplementationDecl *
Mike Stump11289f42009-09-09 15:08:12 +00001118ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001119 ObjCInterfaceDecl *ClassInterface,
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001120 ObjCInterfaceDecl *SuperDecl,
1121 SourceLocation nameLoc,
1122 SourceLocation atStartLoc) {
1123 return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
1124 nameLoc, atStartLoc);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001125}
1126
John McCall0410e572011-07-22 04:15:06 +00001127void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
1128 CXXCtorInitializer ** initializers,
1129 unsigned numInitializers) {
1130 if (numInitializers > 0) {
1131 NumIvarInitializers = numInitializers;
1132 CXXCtorInitializer **ivarInitializers =
1133 new (C) CXXCtorInitializer*[NumIvarInitializers];
1134 memcpy(ivarInitializers, initializers,
1135 numInitializers * sizeof(CXXCtorInitializer*));
1136 IvarInitializers = ivarInitializers;
1137 }
1138}
1139
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001140raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001141 const ObjCImplementationDecl *ID) {
1142 OS << ID->getName();
1143 return OS;
1144}
1145
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001146//===----------------------------------------------------------------------===//
1147// ObjCCompatibleAliasDecl
1148//===----------------------------------------------------------------------===//
1149
1150ObjCCompatibleAliasDecl *
1151ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
1152 SourceLocation L,
Mike Stump11289f42009-09-09 15:08:12 +00001153 IdentifierInfo *Id,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001154 ObjCInterfaceDecl* AliasedClass) {
1155 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
1156}
1157
1158//===----------------------------------------------------------------------===//
1159// ObjCPropertyDecl
1160//===----------------------------------------------------------------------===//
1161
1162ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
1163 SourceLocation L,
1164 IdentifierInfo *Id,
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001165 SourceLocation AtLoc,
John McCall339bb662010-06-04 20:50:08 +00001166 TypeSourceInfo *T,
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001167 PropertyControl propControl) {
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001168 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001169}
1170
Chris Lattnerf1ccb0c2009-02-20 20:59:54 +00001171//===----------------------------------------------------------------------===//
1172// ObjCPropertyImplDecl
1173//===----------------------------------------------------------------------===//
1174
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +00001175ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregorc25d7a72009-01-09 00:49:46 +00001176 DeclContext *DC,
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +00001177 SourceLocation atLoc,
1178 SourceLocation L,
1179 ObjCPropertyDecl *property,
Daniel Dunbar3b4fdb02008-08-26 04:47:31 +00001180 Kind PK,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001181 ObjCIvarDecl *ivar,
1182 SourceLocation ivarLoc) {
1183 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
1184 ivarLoc);
Fariborz Jahanian6efdf1d2008-04-23 00:06:01 +00001185}
Chris Lattnered0e1642008-03-17 01:19:02 +00001186
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001187SourceRange ObjCPropertyImplDecl::getSourceRange() const {
1188 SourceLocation EndLoc = getLocation();
1189 if (IvarLoc.isValid())
1190 EndLoc = IvarLoc;
Chris Lattnerc5ffed42008-04-04 06:12:32 +00001191
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001192 return SourceRange(AtLoc, EndLoc);
1193}