blob: 5eb9cdc5dcab95ec1032c6cf1cb3f030723b5412 [file] [log] [blame]
Chris Lattner1e03a562008-03-16 00:19:01 +00001//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C related Decl classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclObjC.h"
15#include "clang/AST/ASTContext.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000016#include "clang/AST/Stmt.h"
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000017#include "clang/AST/ASTMutationListener.h"
Steve Naroff0de21fd2009-02-22 19:35:57 +000018#include "llvm/ADT/STLExtras.h"
Anna Zaksad0ce532012-09-27 19:45:11 +000019#include "llvm/ADT/SmallString.h"
Chris Lattner1e03a562008-03-16 00:19:01 +000020using namespace clang;
21
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000022//===----------------------------------------------------------------------===//
Chris Lattner11e1e1a2009-02-20 21:16:26 +000023// ObjCListBase
24//===----------------------------------------------------------------------===//
25
Chris Lattner38af2de2009-02-20 21:35:13 +000026void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Douglas Gregorff331c12010-07-25 18:17:45 +000027 List = 0;
Chris Lattner11e1e1a2009-02-20 21:16:26 +000028 if (Elts == 0) return; // Setting to an empty list is a noop.
Mike Stump1eb44332009-09-09 15:08:12 +000029
30
Chris Lattner4ee413b2009-02-20 21:44:01 +000031 List = new (Ctx) void*[Elts];
Chris Lattner11e1e1a2009-02-20 21:16:26 +000032 NumElts = Elts;
33 memcpy(List, InList, sizeof(void*)*Elts);
34}
35
Douglas Gregor18df52b2010-01-16 15:02:53 +000036void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
37 const SourceLocation *Locs, ASTContext &Ctx) {
38 if (Elts == 0)
39 return;
40
41 Locations = new (Ctx) SourceLocation[Elts];
42 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
43 set(InList, Elts, Ctx);
44}
45
Chris Lattner11e1e1a2009-02-20 21:16:26 +000046//===----------------------------------------------------------------------===//
Chris Lattnerab351632009-02-20 20:59:54 +000047// ObjCInterfaceDecl
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000048//===----------------------------------------------------------------------===//
49
David Blaikie99ba9e32011-12-20 02:48:34 +000050void ObjCContainerDecl::anchor() { }
51
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000052/// getIvarDecl - This method looks up an ivar in this ContextDecl.
53///
54ObjCIvarDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000055ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000056 lookup_const_iterator Ivar, IvarEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000057 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000058 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
59 return ivar;
60 }
61 return 0;
62}
63
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000064// Get the local instance/class method declared in this interface.
Douglas Gregor6ab35242009-04-09 21:40:53 +000065ObjCMethodDecl *
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000066ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
Steve Naroff0de21fd2009-02-22 19:35:57 +000067 // Since instance & class methods can have the same name, the loop below
68 // ensures we get the correct method.
69 //
70 // @interface Whatever
71 // - (int) class_method;
72 // + (float) class_method;
73 // @end
74 //
75 lookup_const_iterator Meth, MethEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000076 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
Steve Naroff0de21fd2009-02-22 19:35:57 +000077 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000078 if (MD && MD->isInstanceMethod() == isInstance)
Steve Naroff0de21fd2009-02-22 19:35:57 +000079 return MD;
80 }
Steve Naroff0701bbb2009-01-08 17:28:14 +000081 return 0;
82}
83
Ted Kremenek9f550ff2010-03-15 20:11:46 +000084ObjCPropertyDecl *
Ted Kremenekde09d0c2010-03-15 20:11:53 +000085ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
Ted Kremenek9f550ff2010-03-15 20:11:46 +000086 IdentifierInfo *propertyID) {
87
Ted Kremenekde09d0c2010-03-15 20:11:53 +000088 DeclContext::lookup_const_iterator I, E;
Ted Kremenek9f550ff2010-03-15 20:11:46 +000089 llvm::tie(I, E) = DC->lookup(propertyID);
90 for ( ; I != E; ++I)
91 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
92 return PD;
93
94 return 0;
95}
96
Anna Zaksad0ce532012-09-27 19:45:11 +000097IdentifierInfo *
98ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const {
99 SmallString<128> ivarName;
100 {
101 llvm::raw_svector_ostream os(ivarName);
102 os << '_' << getIdentifier()->getName();
103 }
104 return &Ctx.Idents.get(ivarName.str());
105}
106
Fariborz Jahanian559c0c42008-04-21 19:04:53 +0000107/// FindPropertyDeclaration - Finds declaration of the property given its name
108/// in 'PropertyId' and returns it. It returns 0, if not found.
Fariborz Jahanian559c0c42008-04-21 19:04:53 +0000109ObjCPropertyDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000110ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
Mike Stump1eb44332009-09-09 15:08:12 +0000111
Ted Kremenekde09d0c2010-03-15 20:11:53 +0000112 if (ObjCPropertyDecl *PD =
113 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
114 return PD;
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Ted Kremenekde09d0c2010-03-15 20:11:53 +0000116 switch (getKind()) {
117 default:
118 break;
119 case Decl::ObjCProtocol: {
120 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
121 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
122 E = PID->protocol_end(); I != E; ++I)
Fariborz Jahanian25760612010-02-15 21:55:26 +0000123 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
124 return P;
Ted Kremenekde09d0c2010-03-15 20:11:53 +0000125 break;
126 }
127 case Decl::ObjCInterface: {
128 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
129 // Look through categories.
130 for (ObjCCategoryDecl *Cat = OID->getCategoryList();
131 Cat; Cat = Cat->getNextClassCategory())
132 if (!Cat->IsClassExtension())
133 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
134 return P;
135
136 // Look through protocols.
Ted Kremenek53b94412010-09-01 01:21:15 +0000137 for (ObjCInterfaceDecl::all_protocol_iterator
138 I = OID->all_referenced_protocol_begin(),
139 E = OID->all_referenced_protocol_end(); I != E; ++I)
Ted Kremenekde09d0c2010-03-15 20:11:53 +0000140 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
141 return P;
142
143 // Finally, check the super class.
144 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
145 return superClass->FindPropertyDeclaration(PropertyId);
146 break;
147 }
148 case Decl::ObjCCategory: {
149 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
150 // Look through protocols.
151 if (!OCD->IsClassExtension())
152 for (ObjCCategoryDecl::protocol_iterator
153 I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I)
154 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
155 return P;
156
157 break;
Fariborz Jahanianf034e9c2009-01-19 18:16:19 +0000158 }
159 }
Steve Naroff3d2c22b2008-06-05 13:55:23 +0000160 return 0;
161}
162
David Blaikie99ba9e32011-12-20 02:48:34 +0000163void ObjCInterfaceDecl::anchor() { }
164
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000165/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
166/// with name 'PropertyId' in the primary class; including those in protocols
Ted Kremenek37cafb02010-03-15 20:30:07 +0000167/// (direct or indirect) used by the primary class.
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000168///
169ObjCPropertyDecl *
Ted Kremenek37cafb02010-03-15 20:30:07 +0000170ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000171 IdentifierInfo *PropertyId) const {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000172 // FIXME: Should make sure no callers ever do this.
173 if (!hasDefinition())
174 return 0;
175
176 if (data().ExternallyCompleted)
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000177 LoadExternalDefinition();
178
Ted Kremenek37cafb02010-03-15 20:30:07 +0000179 if (ObjCPropertyDecl *PD =
180 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
181 return PD;
182
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000183 // Look through protocols.
Ted Kremenek53b94412010-09-01 01:21:15 +0000184 for (ObjCInterfaceDecl::all_protocol_iterator
185 I = all_referenced_protocol_begin(),
186 E = all_referenced_protocol_end(); I != E; ++I)
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000187 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
188 return P;
Ted Kremenek37cafb02010-03-15 20:30:07 +0000189
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000190 return 0;
191}
192
Anna Zaksb36ea372012-10-18 19:17:53 +0000193void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap& PM) const {
194 for (ObjCContainerDecl::prop_iterator P = prop_begin(),
195 E = prop_end(); P != E; ++P) {
196 ObjCPropertyDecl *Prop = *P;
197 PM[Prop->getIdentifier()] = Prop;
198 }
199 for (ObjCInterfaceDecl::all_protocol_iterator
200 PI = all_referenced_protocol_begin(),
201 E = all_referenced_protocol_end(); PI != E; ++PI)
202 (*PI)->collectPropertiesToImplement(PM);
203}
204
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000205void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
206 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
207 ASTContext &C)
208{
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000209 if (data().ExternallyCompleted)
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000210 LoadExternalDefinition();
211
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000212 if (data().AllReferencedProtocols.empty() &&
213 data().ReferencedProtocols.empty()) {
214 data().AllReferencedProtocols.set(ExtList, ExtNum, C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000215 return;
216 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000217
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000218 // Check for duplicate protocol in class's protocol list.
Ted Kremenek53b94412010-09-01 01:21:15 +0000219 // This is O(n*m). But it is extremely rare and number of protocols in
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000220 // class or its extension are very few.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000221 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000222 for (unsigned i = 0; i < ExtNum; i++) {
223 bool protocolExists = false;
224 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
Ted Kremenek53b94412010-09-01 01:21:15 +0000225 for (all_protocol_iterator
226 p = all_referenced_protocol_begin(),
227 e = all_referenced_protocol_end(); p != e; ++p) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000228 ObjCProtocolDecl *Proto = (*p);
229 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
230 protocolExists = true;
231 break;
232 }
233 }
234 // Do we want to warn on a protocol in extension class which
235 // already exist in the class? Probably not.
Ted Kremenek53b94412010-09-01 01:21:15 +0000236 if (!protocolExists)
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000237 ProtocolRefs.push_back(ProtoInExtension);
238 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000239
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000240 if (ProtocolRefs.empty())
241 return;
Ted Kremenek53b94412010-09-01 01:21:15 +0000242
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000243 // Merge ProtocolRefs into class's protocol list;
Ted Kremenek53b94412010-09-01 01:21:15 +0000244 for (all_protocol_iterator p = all_referenced_protocol_begin(),
245 e = all_referenced_protocol_end(); p != e; ++p) {
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000246 ProtocolRefs.push_back(*p);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000247 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000248
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000249 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000250}
251
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000252void ObjCInterfaceDecl::allocateDefinitionData() {
253 assert(!hasDefinition() && "ObjC class already has a definition");
Douglas Gregor26fec632011-12-15 18:17:27 +0000254 Data = new (getASTContext()) DefinitionData();
Douglas Gregor8d2dbbf2011-12-16 16:34:57 +0000255 Data->Definition = this;
256
257 // Make the type point at the definition, now that we have one.
258 if (TypeForDecl)
259 cast<ObjCInterfaceType>(TypeForDecl)->Decl = this;
Douglas Gregor0af55012011-12-16 03:12:41 +0000260}
261
262void ObjCInterfaceDecl::startDefinition() {
263 allocateDefinitionData();
264
Douglas Gregor53df7a12011-12-15 18:03:09 +0000265 // Update all of the declarations with a pointer to the definition.
266 for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end();
267 RD != RDEnd; ++RD) {
268 if (*RD != this)
Douglas Gregor26fec632011-12-15 18:17:27 +0000269 RD->Data = Data;
Douglas Gregor53df7a12011-12-15 18:03:09 +0000270 }
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000271}
272
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000273/// getFirstClassExtension - Find first class extension of the given class.
274ObjCCategoryDecl* ObjCInterfaceDecl::getFirstClassExtension() const {
275 for (ObjCCategoryDecl *CDecl = getCategoryList(); CDecl;
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000276 CDecl = CDecl->getNextClassCategory())
277 if (CDecl->IsClassExtension())
278 return CDecl;
279 return 0;
280}
281
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000282/// getNextClassCategory - Find next class extension in list of categories.
283const ObjCCategoryDecl* ObjCCategoryDecl::getNextClassExtension() const {
284 for (const ObjCCategoryDecl *CDecl = getNextClassCategory(); CDecl;
285 CDecl = CDecl->getNextClassCategory())
286 if (CDecl->IsClassExtension())
287 return CDecl;
288 return 0;
289}
290
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000291ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
292 ObjCInterfaceDecl *&clsDeclared) {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000293 // FIXME: Should make sure no callers ever do this.
294 if (!hasDefinition())
295 return 0;
296
297 if (data().ExternallyCompleted)
Argyrios Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000298 LoadExternalDefinition();
299
Chris Lattner1e03a562008-03-16 00:19:01 +0000300 ObjCInterfaceDecl* ClassDecl = this;
301 while (ClassDecl != NULL) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000302 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +0000303 clsDeclared = ClassDecl;
304 return I;
Chris Lattner1e03a562008-03-16 00:19:01 +0000305 }
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000306 for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension();
307 CDecl; CDecl = CDecl->getNextClassExtension()) {
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000308 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
309 clsDeclared = ClassDecl;
310 return I;
311 }
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000312 }
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000313
Chris Lattner1e03a562008-03-16 00:19:01 +0000314 ClassDecl = ClassDecl->getSuperClass();
315 }
316 return NULL;
317}
318
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000319/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
320/// class whose name is passed as argument. If it is not one of the super classes
321/// the it returns NULL.
322ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
323 const IdentifierInfo*ICName) {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000324 // FIXME: Should make sure no callers ever do this.
325 if (!hasDefinition())
326 return 0;
327
328 if (data().ExternallyCompleted)
Argyrios Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000329 LoadExternalDefinition();
330
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000331 ObjCInterfaceDecl* ClassDecl = this;
332 while (ClassDecl != NULL) {
333 if (ClassDecl->getIdentifier() == ICName)
334 return ClassDecl;
335 ClassDecl = ClassDecl->getSuperClass();
336 }
337 return NULL;
338}
339
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000340/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner1e03a562008-03-16 00:19:01 +0000341/// the class, its categories, and its super classes (using a linear search).
Fariborz Jahanianbf393be2012-04-05 22:14:12 +0000342ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
343 bool isInstance,
344 bool shallowCategoryLookup) const {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000345 // FIXME: Should make sure no callers ever do this.
346 if (!hasDefinition())
347 return 0;
348
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000349 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner1e03a562008-03-16 00:19:01 +0000350 ObjCMethodDecl *MethodDecl = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000351
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000352 if (data().ExternallyCompleted)
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000353 LoadExternalDefinition();
354
Chris Lattner1e03a562008-03-16 00:19:01 +0000355 while (ClassDecl != NULL) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000356 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000357 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000358
Chris Lattner1e03a562008-03-16 00:19:01 +0000359 // Didn't find one yet - look through protocols.
Argyrios Kyrtzidisa5f44412012-03-13 01:09:41 +0000360 for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
361 E = ClassDecl->protocol_end();
362 I != E; ++I)
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000363 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000364 return MethodDecl;
Fariborz Jahanianbf393be2012-04-05 22:14:12 +0000365
366 // Didn't find one yet - now look through categories.
367 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
368 while (CatDecl) {
369 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
370 return MethodDecl;
Fariborz Jahanianbb3d14e2012-02-09 21:30:24 +0000371
Fariborz Jahanianbf393be2012-04-05 22:14:12 +0000372 if (!shallowCategoryLookup) {
Fariborz Jahanianbb3d14e2012-02-09 21:30:24 +0000373 // Didn't find one yet - look through protocols.
374 const ObjCList<ObjCProtocolDecl> &Protocols =
375 CatDecl->getReferencedProtocols();
376 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
377 E = Protocols.end(); I != E; ++I)
378 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
379 return MethodDecl;
Fariborz Jahanianbb3d14e2012-02-09 21:30:24 +0000380 }
Fariborz Jahanianbf393be2012-04-05 22:14:12 +0000381 CatDecl = CatDecl->getNextClassCategory();
Chris Lattner1e03a562008-03-16 00:19:01 +0000382 }
Fariborz Jahanianbf393be2012-04-05 22:14:12 +0000383
Chris Lattner1e03a562008-03-16 00:19:01 +0000384 ClassDecl = ClassDecl->getSuperClass();
385 }
386 return NULL;
387}
388
Anna Zakse61354b2012-07-27 19:07:44 +0000389// Will search "local" class/category implementations for a method decl.
390// If failed, then we search in class's root for an instance method.
391// Returns 0 if no method is found.
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000392ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
393 const Selector &Sel,
Anna Zaksca93ee72012-07-30 20:31:21 +0000394 bool Instance) const {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000395 // FIXME: Should make sure no callers ever do this.
396 if (!hasDefinition())
397 return 0;
398
399 if (data().ExternallyCompleted)
Argyrios Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000400 LoadExternalDefinition();
401
Steve Naroffd789d3d2009-10-01 23:46:04 +0000402 ObjCMethodDecl *Method = 0;
403 if (ObjCImplementationDecl *ImpDecl = getImplementation())
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000404 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
405 : ImpDecl->getClassMethod(Sel);
Anna Zakse61354b2012-07-27 19:07:44 +0000406
407 // Look through local category implementations associated with the class.
408 if (!Method)
409 Method = Instance ? getCategoryInstanceMethod(Sel)
410 : getCategoryClassMethod(Sel);
411
412 // Before we give up, check if the selector is an instance method.
413 // But only in the root. This matches gcc's behavior and what the
414 // runtime expects.
415 if (!Instance && !Method && !getSuperClass()) {
416 Method = lookupInstanceMethod(Sel);
417 // Look through local category implementations associated
418 // with the root class.
419 if (!Method)
420 Method = lookupPrivateMethod(Sel, true);
421 }
422
Steve Naroffd789d3d2009-10-01 23:46:04 +0000423 if (!Method && getSuperClass())
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000424 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
Steve Naroffd789d3d2009-10-01 23:46:04 +0000425 return Method;
426}
Chris Lattnerab351632009-02-20 20:59:54 +0000427
428//===----------------------------------------------------------------------===//
429// ObjCMethodDecl
430//===----------------------------------------------------------------------===//
431
432ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +0000433 SourceLocation beginLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000434 SourceLocation endLoc,
435 Selector SelInfo, QualType T,
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000436 TypeSourceInfo *ResultTInfo,
Chris Lattnerab351632009-02-20 20:59:54 +0000437 DeclContext *contextDecl,
438 bool isInstance,
439 bool isVariadic,
Jordan Rose1e4691b2012-10-10 16:42:25 +0000440 bool isPropertyAccessor,
Argyrios Kyrtzidis75cf3e82011-08-17 19:25:08 +0000441 bool isImplicitlyDeclared,
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000442 bool isDefined,
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000443 ImplementationControl impControl,
Argyrios Kyrtzidisda92a7f2011-10-03 06:36:29 +0000444 bool HasRelatedResultType) {
Chris Lattnerab351632009-02-20 20:59:54 +0000445 return new (C) ObjCMethodDecl(beginLoc, endLoc,
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000446 SelInfo, T, ResultTInfo, contextDecl,
Jordan Rose1e4691b2012-10-10 16:42:25 +0000447 isInstance, isVariadic, isPropertyAccessor,
448 isImplicitlyDeclared, isDefined,
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000449 impControl,
Argyrios Kyrtzidisda92a7f2011-10-03 06:36:29 +0000450 HasRelatedResultType);
Chris Lattner1e03a562008-03-16 00:19:01 +0000451}
452
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000453ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
454 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCMethodDecl));
455 return new (Mem) ObjCMethodDecl(SourceLocation(), SourceLocation(),
456 Selector(), QualType(), 0, 0);
457}
458
Douglas Gregor5456b0fe2012-10-09 17:21:28 +0000459Stmt *ObjCMethodDecl::getBody() const {
460 return Body.get(getASTContext().getExternalSource());
461}
462
Argyrios Kyrtzidis3a919e72011-10-14 08:02:31 +0000463void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
464 assert(PrevMethod);
465 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
466 IsRedeclaration = true;
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000467 PrevMethod->HasRedeclaration = true;
Argyrios Kyrtzidis3a919e72011-10-14 08:02:31 +0000468}
469
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000470void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
471 ArrayRef<ParmVarDecl*> Params,
472 ArrayRef<SourceLocation> SelLocs) {
473 ParamsAndSelLocs = 0;
474 NumParams = Params.size();
475 if (Params.empty() && SelLocs.empty())
476 return;
477
478 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
479 sizeof(SourceLocation) * SelLocs.size();
480 ParamsAndSelLocs = C.Allocate(Size);
481 std::copy(Params.begin(), Params.end(), getParams());
482 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
483}
484
485void ObjCMethodDecl::getSelectorLocs(
486 SmallVectorImpl<SourceLocation> &SelLocs) const {
487 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
488 SelLocs.push_back(getSelectorLoc(i));
489}
490
491void ObjCMethodDecl::setMethodParams(ASTContext &C,
492 ArrayRef<ParmVarDecl*> Params,
493 ArrayRef<SourceLocation> SelLocs) {
494 assert((!SelLocs.empty() || isImplicit()) &&
495 "No selector locs for non-implicit method");
496 if (isImplicit())
497 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
498
Argyrios Kyrtzidisa0cff722012-06-16 00:46:02 +0000499 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
500 DeclEndLoc);
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000501 if (SelLocsKind != SelLoc_NonStandard)
502 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
503
504 setParamsAndSelLocs(C, Params, SelLocs);
505}
506
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000507/// \brief A definition will return its interface declaration.
508/// An interface declaration will return its definition.
509/// Otherwise it will return itself.
510ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
511 ASTContext &Ctx = getASTContext();
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000512 ObjCMethodDecl *Redecl = 0;
513 if (HasRedeclaration)
514 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
Argyrios Kyrtzidisb40034c2011-10-14 06:48:06 +0000515 if (Redecl)
516 return Redecl;
517
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000518 Decl *CtxD = cast<Decl>(getDeclContext());
519
520 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
521 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
522 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
523
524 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
525 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
526 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
527
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000528 } else if (ObjCImplementationDecl *ImplD =
529 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000530 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
531 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000532
533 } else if (ObjCCategoryImplDecl *CImplD =
534 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000535 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000536 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000537 }
538
Argyrios Kyrtzidis3a919e72011-10-14 08:02:31 +0000539 if (!Redecl && isRedeclaration()) {
540 // This is the last redeclaration, go back to the first method.
541 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
542 isInstanceMethod());
543 }
544
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000545 return Redecl ? Redecl : this;
546}
547
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000548ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
549 Decl *CtxD = cast<Decl>(getDeclContext());
550
551 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
552 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
553 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
554 isInstanceMethod()))
555 return MD;
556
557 } else if (ObjCCategoryImplDecl *CImplD =
558 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000559 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000560 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
561 isInstanceMethod()))
562 return MD;
563 }
564
Argyrios Kyrtzidis6d4740e2011-10-17 19:48:09 +0000565 if (isRedeclaration())
566 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
567 isInstanceMethod());
568
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000569 return this;
570}
571
Argyrios Kyrtzidisa0cff722012-06-16 00:46:02 +0000572SourceLocation ObjCMethodDecl::getLocEnd() const {
573 if (Stmt *Body = getBody())
574 return Body->getLocEnd();
575 return DeclEndLoc;
576}
577
John McCall85f3d762011-03-02 01:50:55 +0000578ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
579 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
John McCalld976c8e2011-03-02 21:01:41 +0000580 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
John McCall85f3d762011-03-02 01:50:55 +0000581 return family;
582
John McCalld5313b02011-03-02 11:33:24 +0000583 // Check for an explicit attribute.
584 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
585 // The unfortunate necessity of mapping between enums here is due
586 // to the attributes framework.
587 switch (attr->getFamily()) {
588 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
589 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
590 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
591 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
592 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
593 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
594 }
595 Family = static_cast<unsigned>(family);
596 return family;
597 }
598
John McCall85f3d762011-03-02 01:50:55 +0000599 family = getSelector().getMethodFamily();
600 switch (family) {
601 case OMF_None: break;
602
603 // init only has a conventional meaning for an instance method, and
604 // it has to return an object.
605 case OMF_init:
606 if (!isInstanceMethod() || !getResultType()->isObjCObjectPointerType())
607 family = OMF_None;
608 break;
609
610 // alloc/copy/new have a conventional meaning for both class and
611 // instance methods, but they require an object return.
612 case OMF_alloc:
613 case OMF_copy:
614 case OMF_mutableCopy:
615 case OMF_new:
616 if (!getResultType()->isObjCObjectPointerType())
617 family = OMF_None;
618 break;
619
620 // These selectors have a conventional meaning only for instance methods.
621 case OMF_dealloc:
Nico Weber80cb6e62011-08-28 22:35:17 +0000622 case OMF_finalize:
John McCall85f3d762011-03-02 01:50:55 +0000623 case OMF_retain:
624 case OMF_release:
625 case OMF_autorelease:
626 case OMF_retainCount:
Douglas Gregor926df6c2011-06-11 01:09:30 +0000627 case OMF_self:
John McCall85f3d762011-03-02 01:50:55 +0000628 if (!isInstanceMethod())
629 family = OMF_None;
630 break;
Fariborz Jahanian9670e172011-07-05 22:38:59 +0000631
632 case OMF_performSelector:
633 if (!isInstanceMethod() ||
634 !getResultType()->isObjCIdType())
635 family = OMF_None;
636 else {
637 unsigned noParams = param_size();
638 if (noParams < 1 || noParams > 3)
639 family = OMF_None;
640 else {
641 ObjCMethodDecl::arg_type_iterator it = arg_type_begin();
642 QualType ArgT = (*it);
643 if (!ArgT->isObjCSelType()) {
644 family = OMF_None;
645 break;
646 }
647 while (--noParams) {
648 it++;
649 ArgT = (*it);
650 if (!ArgT->isObjCIdType()) {
651 family = OMF_None;
652 break;
653 }
654 }
655 }
656 }
657 break;
658
John McCall85f3d762011-03-02 01:50:55 +0000659 }
660
661 // Cache the result.
662 Family = static_cast<unsigned>(family);
663 return family;
664}
665
Mike Stump1eb44332009-09-09 15:08:12 +0000666void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerab351632009-02-20 20:59:54 +0000667 const ObjCInterfaceDecl *OID) {
668 QualType selfTy;
669 if (isInstanceMethod()) {
670 // There may be no interface context due to error in declaration
671 // of the interface (which has been reported). Recover gracefully.
672 if (OID) {
Daniel Dunbar3b3a4582009-04-22 04:34:53 +0000673 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff14108da2009-07-10 23:34:53 +0000674 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerab351632009-02-20 20:59:54 +0000675 } else {
676 selfTy = Context.getObjCIdType();
677 }
678 } else // we have a factory method.
679 selfTy = Context.getObjCClassType();
680
John McCall7acddac2011-06-17 06:42:21 +0000681 bool selfIsPseudoStrong = false;
John McCallf85e1932011-06-15 23:02:42 +0000682 bool selfIsConsumed = false;
Ted Kremenek2bbcd5c2011-11-14 21:59:25 +0000683
David Blaikie4e4d0842012-03-11 07:00:24 +0000684 if (Context.getLangOpts().ObjCAutoRefCount) {
Ted Kremenek2bbcd5c2011-11-14 21:59:25 +0000685 if (isInstanceMethod()) {
686 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
John McCallf85e1932011-06-15 23:02:42 +0000687
Ted Kremenek2bbcd5c2011-11-14 21:59:25 +0000688 // 'self' is always __strong. It's actually pseudo-strong except
689 // in init methods (or methods labeled ns_consumes_self), though.
690 Qualifiers qs;
691 qs.setObjCLifetime(Qualifiers::OCL_Strong);
692 selfTy = Context.getQualifiedType(selfTy, qs);
John McCallf85e1932011-06-15 23:02:42 +0000693
Ted Kremenek2bbcd5c2011-11-14 21:59:25 +0000694 // In addition, 'self' is const unless this is an init method.
695 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
696 selfTy = selfTy.withConst();
697 selfIsPseudoStrong = true;
698 }
699 }
700 else {
701 assert(isClassMethod());
702 // 'self' is always const in class methods.
John McCallf85e1932011-06-15 23:02:42 +0000703 selfTy = selfTy.withConst();
John McCall7acddac2011-06-17 06:42:21 +0000704 selfIsPseudoStrong = true;
705 }
John McCallf85e1932011-06-15 23:02:42 +0000706 }
707
708 ImplicitParamDecl *self
709 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
710 &Context.Idents.get("self"), selfTy);
711 setSelfDecl(self);
712
713 if (selfIsConsumed)
714 self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context));
Chris Lattnerab351632009-02-20 20:59:54 +0000715
John McCall7acddac2011-06-17 06:42:21 +0000716 if (selfIsPseudoStrong)
717 self->setARCPseudoStrong(true);
718
Mike Stump1eb44332009-09-09 15:08:12 +0000719 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
720 &Context.Idents.get("_cmd"),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000721 Context.getObjCSelType()));
Chris Lattnerab351632009-02-20 20:59:54 +0000722}
723
Chris Lattnerab351632009-02-20 20:59:54 +0000724ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
725 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
726 return ID;
727 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
728 return CD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000729 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerab351632009-02-20 20:59:54 +0000730 return IMD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000731
732 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
David Blaikieb219cfc2011-09-23 05:06:16 +0000733 llvm_unreachable("unknown method context");
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000734}
735
Argyrios Kyrtzidis740ae672012-10-09 18:19:01 +0000736static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
737 const ObjCMethodDecl *Method,
738 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
739 bool MovedToSuper) {
740 if (!Container)
741 return;
742
743 // In categories look for overriden methods from protocols. A method from
744 // category is not "overriden" since it is considered as the "same" method
745 // (same USR) as the one from the interface.
746 if (const ObjCCategoryDecl *
747 Category = dyn_cast<ObjCCategoryDecl>(Container)) {
748 // Check whether we have a matching method at this category but only if we
749 // are at the super class level.
750 if (MovedToSuper)
751 if (ObjCMethodDecl *
752 Overridden = Container->getMethod(Method->getSelector(),
753 Method->isInstanceMethod()))
754 if (Method != Overridden) {
755 // We found an override at this category; there is no need to look
756 // into its protocols.
757 Methods.push_back(Overridden);
758 return;
759 }
760
761 for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
762 PEnd = Category->protocol_end();
763 P != PEnd; ++P)
764 CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
765 return;
766 }
767
768 // Check whether we have a matching method at this level.
769 if (const ObjCMethodDecl *
770 Overridden = Container->getMethod(Method->getSelector(),
771 Method->isInstanceMethod()))
772 if (Method != Overridden) {
773 // We found an override at this level; there is no need to look
774 // into other protocols or categories.
775 Methods.push_back(Overridden);
776 return;
777 }
778
779 if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
780 for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
781 PEnd = Protocol->protocol_end();
782 P != PEnd; ++P)
783 CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
784 }
785
786 if (const ObjCInterfaceDecl *
787 Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
788 for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(),
789 PEnd = Interface->protocol_end();
790 P != PEnd; ++P)
791 CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
792
793 for (const ObjCCategoryDecl *Category = Interface->getCategoryList();
794 Category; Category = Category->getNextClassCategory())
795 CollectOverriddenMethodsRecurse(Category, Method, Methods,
796 MovedToSuper);
797
798 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
799 return CollectOverriddenMethodsRecurse(Super, Method, Methods,
800 /*MovedToSuper=*/true);
801 }
802}
803
804static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
805 const ObjCMethodDecl *Method,
806 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
807 CollectOverriddenMethodsRecurse(Container, Method, Methods,
808 /*MovedToSuper=*/false);
809}
810
811static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method,
812 SmallVectorImpl<const ObjCMethodDecl *> &overridden) {
813 assert(Method->isOverriding());
814
815 if (const ObjCProtocolDecl *
816 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
817 CollectOverriddenMethods(ProtD, Method, overridden);
818
819 } else if (const ObjCImplDecl *
820 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
821 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
822 if (!ID)
823 return;
824 // Start searching for overridden methods using the method from the
825 // interface as starting point.
826 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
827 Method->isInstanceMethod()))
828 Method = IFaceMeth;
829 CollectOverriddenMethods(ID, Method, overridden);
830
831 } else if (const ObjCCategoryDecl *
832 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
833 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
834 if (!ID)
835 return;
836 // Start searching for overridden methods using the method from the
837 // interface as starting point.
838 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
839 Method->isInstanceMethod()))
840 Method = IFaceMeth;
841 CollectOverriddenMethods(ID, Method, overridden);
842
843 } else {
844 CollectOverriddenMethods(
845 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
846 Method, overridden);
847 }
848}
849
850static void collectOnCategoriesAfterLocation(SourceLocation Loc,
851 const ObjCInterfaceDecl *Class,
852 SourceManager &SM,
853 const ObjCMethodDecl *Method,
854 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
855 if (!Class)
856 return;
857
858 for (const ObjCCategoryDecl *Category = Class->getCategoryList();
859 Category; Category = Category->getNextClassCategory())
860 if (SM.isBeforeInTranslationUnit(Loc, Category->getLocation()))
861 CollectOverriddenMethodsRecurse(Category, Method, Methods, true);
862
863 collectOnCategoriesAfterLocation(Loc, Class->getSuperClass(), SM,
864 Method, Methods);
865}
866
867/// \brief Faster collection that is enabled when ObjCMethodDecl::isOverriding()
868/// returns false.
869/// You'd think that in that case there are no overrides but categories can
870/// "introduce" new overridden methods that are missed by Sema because the
871/// overrides lookup that it does for methods, inside implementations, will
872/// stop at the interface level (if there is a method there) and not look
873/// further in super classes.
Fariborz Jahanianbf967be2012-10-10 18:34:52 +0000874/// Methods in an implementation can overide methods in super class's category
875/// but not in current class's category. But, such methods
Argyrios Kyrtzidis740ae672012-10-09 18:19:01 +0000876static void collectOverriddenMethodsFast(SourceManager &SM,
877 const ObjCMethodDecl *Method,
878 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
879 assert(!Method->isOverriding());
880
881 const ObjCContainerDecl *
882 ContD = cast<ObjCContainerDecl>(Method->getDeclContext());
883 if (isa<ObjCInterfaceDecl>(ContD) || isa<ObjCProtocolDecl>(ContD))
884 return;
885 const ObjCInterfaceDecl *Class = Method->getClassInterface();
886 if (!Class)
887 return;
888
889 collectOnCategoriesAfterLocation(Class->getLocation(), Class->getSuperClass(),
890 SM, Method, Methods);
891}
892
893void ObjCMethodDecl::getOverriddenMethods(
894 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
895 const ObjCMethodDecl *Method = this;
896
897 if (Method->isRedeclaration()) {
898 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
899 getMethod(Method->getSelector(), Method->isInstanceMethod());
900 }
901
902 if (!Method->isOverriding()) {
903 collectOverriddenMethodsFast(getASTContext().getSourceManager(),
904 Method, Overridden);
905 } else {
906 collectOverriddenMethodsSlow(Method, Overridden);
907 assert(!Overridden.empty() &&
908 "ObjCMethodDecl's overriding bit is not as expected");
909 }
910}
911
Jordan Rose04bec392012-10-10 16:42:54 +0000912const ObjCPropertyDecl *
913ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
914 Selector Sel = getSelector();
915 unsigned NumArgs = Sel.getNumArgs();
916 if (NumArgs > 1)
917 return 0;
918
Jordan Rose50d2b262012-10-11 16:02:02 +0000919 if (!isInstanceMethod() || getMethodFamily() != OMF_None)
Jordan Rose04bec392012-10-10 16:42:54 +0000920 return 0;
921
922 if (isPropertyAccessor()) {
923 const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
924 bool IsGetter = (NumArgs == 0);
925
926 for (ObjCContainerDecl::prop_iterator I = Container->prop_begin(),
927 E = Container->prop_end();
928 I != E; ++I) {
929 Selector NextSel = IsGetter ? (*I)->getGetterName()
930 : (*I)->getSetterName();
931 if (NextSel == Sel)
932 return *I;
933 }
934
935 llvm_unreachable("Marked as a property accessor but no property found!");
936 }
937
938 if (!CheckOverrides)
939 return 0;
940
941 typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy;
942 OverridesTy Overrides;
943 getOverriddenMethods(Overrides);
944 for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
945 I != E; ++I) {
946 if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false))
947 return Prop;
948 }
949
950 return 0;
951
952}
953
Chris Lattnerab351632009-02-20 20:59:54 +0000954//===----------------------------------------------------------------------===//
955// ObjCInterfaceDecl
956//===----------------------------------------------------------------------===//
957
Douglas Gregora6ea10e2012-01-17 18:09:05 +0000958ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
Chris Lattnerab351632009-02-20 20:59:54 +0000959 DeclContext *DC,
960 SourceLocation atLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000961 IdentifierInfo *Id,
Douglas Gregor0af55012011-12-16 03:12:41 +0000962 ObjCInterfaceDecl *PrevDecl,
Chris Lattnerab351632009-02-20 20:59:54 +0000963 SourceLocation ClassLoc,
Douglas Gregor7723fec2011-12-15 20:29:51 +0000964 bool isInternal){
Douglas Gregor0af55012011-12-16 03:12:41 +0000965 ObjCInterfaceDecl *Result = new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc,
Douglas Gregorfd002a72011-12-16 22:37:11 +0000966 PrevDecl, isInternal);
Douglas Gregor0af55012011-12-16 03:12:41 +0000967 C.getObjCInterfaceType(Result, PrevDecl);
Douglas Gregor0af55012011-12-16 03:12:41 +0000968 return Result;
969}
970
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000971ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C,
972 unsigned ID) {
973 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCInterfaceDecl));
974 return new (Mem) ObjCInterfaceDecl(0, SourceLocation(), 0, SourceLocation(),
975 0, false);
Chris Lattnerab351632009-02-20 20:59:54 +0000976}
977
978ObjCInterfaceDecl::
979ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
Douglas Gregorfd002a72011-12-16 22:37:11 +0000980 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
981 bool isInternal)
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000982 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
Douglas Gregor7723fec2011-12-15 20:29:51 +0000983 TypeForDecl(0), Data()
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000984{
Douglas Gregorfd002a72011-12-16 22:37:11 +0000985 setPreviousDeclaration(PrevDecl);
986
987 // Copy the 'data' pointer over.
988 if (PrevDecl)
989 Data = PrevDecl->Data;
990
Argyrios Kyrtzidis40f57ee2011-11-15 06:20:21 +0000991 setImplicit(isInternal);
Chris Lattnerab351632009-02-20 20:59:54 +0000992}
993
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000994void ObjCInterfaceDecl::LoadExternalDefinition() const {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000995 assert(data().ExternallyCompleted && "Class is not externally completed");
996 data().ExternallyCompleted = false;
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000997 getASTContext().getExternalSource()->CompleteType(
998 const_cast<ObjCInterfaceDecl *>(this));
999}
1000
1001void ObjCInterfaceDecl::setExternallyCompleted() {
1002 assert(getASTContext().getExternalSource() &&
1003 "Class can't be externally completed without an external source");
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001004 assert(hasDefinition() &&
Douglas Gregor26ac3f32010-12-01 23:49:52 +00001005 "Forward declarations can't be externally completed");
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001006 data().ExternallyCompleted = true;
Douglas Gregor26ac3f32010-12-01 23:49:52 +00001007}
1008
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001009ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
Douglas Gregor7723fec2011-12-15 20:29:51 +00001010 if (const ObjCInterfaceDecl *Def = getDefinition()) {
1011 if (data().ExternallyCompleted)
1012 LoadExternalDefinition();
1013
1014 return getASTContext().getObjCImplementation(
1015 const_cast<ObjCInterfaceDecl*>(Def));
1016 }
1017
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001018 // FIXME: Should make sure no callers ever do this.
Douglas Gregor7723fec2011-12-15 20:29:51 +00001019 return 0;
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001020}
1021
1022void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
Douglas Gregor7723fec2011-12-15 20:29:51 +00001023 getASTContext().setObjCImplementation(getDefinition(), ImplD);
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001024}
1025
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001026/// all_declared_ivar_begin - return first ivar declared in this class,
1027/// its extensions and its implementation. Lazily build the list on first
1028/// access.
1029ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001030 // FIXME: Should make sure no callers ever do this.
1031 if (!hasDefinition())
1032 return 0;
1033
1034 if (data().IvarList)
1035 return data().IvarList;
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001036
1037 ObjCIvarDecl *curIvar = 0;
1038 if (!ivar_empty()) {
1039 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
David Blaikie581deb32012-06-06 20:45:41 +00001040 data().IvarList = *I; ++I;
1041 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1042 curIvar->setNextIvar(*I);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001043 }
1044
1045 for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl;
1046 CDecl = CDecl->getNextClassExtension()) {
1047 if (!CDecl->ivar_empty()) {
1048 ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
1049 E = CDecl->ivar_end();
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001050 if (!data().IvarList) {
David Blaikie581deb32012-06-06 20:45:41 +00001051 data().IvarList = *I; ++I;
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001052 curIvar = data().IvarList;
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001053 }
David Blaikie581deb32012-06-06 20:45:41 +00001054 for ( ;I != E; curIvar = *I, ++I)
1055 curIvar->setNextIvar(*I);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001056 }
1057 }
1058
1059 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
1060 if (!ImplDecl->ivar_empty()) {
1061 ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
1062 E = ImplDecl->ivar_end();
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001063 if (!data().IvarList) {
David Blaikie581deb32012-06-06 20:45:41 +00001064 data().IvarList = *I; ++I;
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001065 curIvar = data().IvarList;
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001066 }
David Blaikie581deb32012-06-06 20:45:41 +00001067 for ( ;I != E; curIvar = *I, ++I)
1068 curIvar->setNextIvar(*I);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001069 }
1070 }
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001071 return data().IvarList;
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001072}
Chris Lattnerab351632009-02-20 20:59:54 +00001073
1074/// FindCategoryDeclaration - Finds category declaration in the list of
1075/// categories for this class and returns it. Name of the category is passed
1076/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001077///
Chris Lattnerab351632009-02-20 20:59:54 +00001078ObjCCategoryDecl *
1079ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
Argyrios Kyrtzidis5a61e0c2012-03-02 19:14:29 +00001080 // FIXME: Should make sure no callers ever do this.
1081 if (!hasDefinition())
1082 return 0;
1083
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001084 if (data().ExternallyCompleted)
Douglas Gregor26ac3f32010-12-01 23:49:52 +00001085 LoadExternalDefinition();
1086
Chris Lattnerab351632009-02-20 20:59:54 +00001087 for (ObjCCategoryDecl *Category = getCategoryList();
1088 Category; Category = Category->getNextClassCategory())
1089 if (Category->getIdentifier() == CategoryId)
1090 return Category;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001091 return 0;
1092}
1093
Argyrios Kyrtzidis1cb35dd2009-07-21 00:06:20 +00001094ObjCMethodDecl *
1095ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
1096 for (ObjCCategoryDecl *Category = getCategoryList();
1097 Category; Category = Category->getNextClassCategory())
1098 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
1099 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1100 return MD;
1101 return 0;
1102}
1103
1104ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
1105 for (ObjCCategoryDecl *Category = getCategoryList();
1106 Category; Category = Category->getNextClassCategory())
1107 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
1108 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1109 return MD;
1110 return 0;
1111}
1112
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001113/// ClassImplementsProtocol - Checks that 'lProto' protocol
1114/// has been implemented in IDecl class, its super class or categories (if
1115/// lookupCategory is true).
1116bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1117 bool lookupCategory,
1118 bool RHSIsQualifiedID) {
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001119 if (!hasDefinition())
1120 return false;
1121
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001122 ObjCInterfaceDecl *IDecl = this;
1123 // 1st, look up the class.
Argyrios Kyrtzidisa5f44412012-03-13 01:09:41 +00001124 for (ObjCInterfaceDecl::protocol_iterator
1125 PI = IDecl->protocol_begin(), E = IDecl->protocol_end(); PI != E; ++PI){
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001126 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
1127 return true;
1128 // This is dubious and is added to be compatible with gcc. In gcc, it is
1129 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1130 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1131 // object. This IMO, should be a bug.
1132 // FIXME: Treat this as an extension, and flag this as an error when GCC
1133 // extensions are not enabled.
Mike Stump1eb44332009-09-09 15:08:12 +00001134 if (RHSIsQualifiedID &&
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001135 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
1136 return true;
1137 }
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001139 // 2nd, look up the category.
1140 if (lookupCategory)
1141 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
1142 CDecl = CDecl->getNextClassCategory()) {
1143 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
1144 E = CDecl->protocol_end(); PI != E; ++PI)
1145 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
1146 return true;
1147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001149 // 3rd, look up the super class(s)
1150 if (IDecl->getSuperClass())
1151 return
1152 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1153 RHSIsQualifiedID);
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Fariborz Jahanian0fd89042009-08-11 22:02:25 +00001155 return false;
1156}
1157
Chris Lattnerab351632009-02-20 20:59:54 +00001158//===----------------------------------------------------------------------===//
1159// ObjCIvarDecl
1160//===----------------------------------------------------------------------===//
1161
David Blaikie99ba9e32011-12-20 02:48:34 +00001162void ObjCIvarDecl::anchor() { }
1163
Daniel Dunbara0654922010-04-02 20:10:03 +00001164ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001165 SourceLocation StartLoc,
1166 SourceLocation IdLoc, IdentifierInfo *Id,
John McCalla93c9342009-12-07 02:54:59 +00001167 QualType T, TypeSourceInfo *TInfo,
Fariborz Jahanianad51e742010-07-17 00:59:30 +00001168 AccessControl ac, Expr *BW,
1169 bool synthesized) {
Daniel Dunbara0654922010-04-02 20:10:03 +00001170 if (DC) {
1171 // Ivar's can only appear in interfaces, implementations (via synthesized
1172 // properties), and class extensions (via direct declaration, or synthesized
1173 // properties).
1174 //
1175 // FIXME: This should really be asserting this:
1176 // (isa<ObjCCategoryDecl>(DC) &&
1177 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1178 // but unfortunately we sometimes place ivars into non-class extension
1179 // categories on error. This breaks an AST invariant, and should not be
1180 // fixed.
1181 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
1182 isa<ObjCCategoryDecl>(DC)) &&
1183 "Invalid ivar decl context!");
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001184 // Once a new ivar is created in any of class/class-extension/implementation
1185 // decl contexts, the previously built IvarList must be rebuilt.
1186 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1187 if (!ID) {
Eric Christopherffb0c3a2012-07-19 22:22:55 +00001188 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001189 ID = IM->getClassInterface();
Eric Christopherffb0c3a2012-07-19 22:22:55 +00001190 else
1191 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001192 }
1193 ID->setIvarList(0);
Daniel Dunbara0654922010-04-02 20:10:03 +00001194 }
1195
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001196 return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo,
1197 ac, BW, synthesized);
Chris Lattnerab351632009-02-20 20:59:54 +00001198}
1199
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001200ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1201 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCIvarDecl));
1202 return new (Mem) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0,
1203 QualType(), 0, ObjCIvarDecl::None, 0, false);
1204}
1205
Daniel Dunbar27a961a2010-04-02 21:13:59 +00001206const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
1207 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
Chris Lattnerab351632009-02-20 20:59:54 +00001208
Daniel Dunbar27a961a2010-04-02 21:13:59 +00001209 switch (DC->getKind()) {
1210 default:
1211 case ObjCCategoryImpl:
1212 case ObjCProtocol:
David Blaikieb219cfc2011-09-23 05:06:16 +00001213 llvm_unreachable("invalid ivar container!");
Daniel Dunbar27a961a2010-04-02 21:13:59 +00001214
1215 // Ivars can only appear in class extension categories.
1216 case ObjCCategory: {
1217 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
1218 assert(CD->IsClassExtension() && "invalid container for ivar!");
1219 return CD->getClassInterface();
1220 }
1221
1222 case ObjCImplementation:
1223 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1224
1225 case ObjCInterface:
1226 return cast<ObjCInterfaceDecl>(DC);
1227 }
1228}
Chris Lattnerab351632009-02-20 20:59:54 +00001229
1230//===----------------------------------------------------------------------===//
1231// ObjCAtDefsFieldDecl
1232//===----------------------------------------------------------------------===//
1233
David Blaikie99ba9e32011-12-20 02:48:34 +00001234void ObjCAtDefsFieldDecl::anchor() { }
1235
Chris Lattnerab351632009-02-20 20:59:54 +00001236ObjCAtDefsFieldDecl
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001237*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
1238 SourceLocation StartLoc, SourceLocation IdLoc,
Chris Lattnerab351632009-02-20 20:59:54 +00001239 IdentifierInfo *Id, QualType T, Expr *BW) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001240 return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
Chris Lattnerab351632009-02-20 20:59:54 +00001241}
1242
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001243ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
1244 unsigned ID) {
1245 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCAtDefsFieldDecl));
1246 return new (Mem) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(),
1247 0, QualType(), 0);
1248}
1249
Chris Lattnerab351632009-02-20 20:59:54 +00001250//===----------------------------------------------------------------------===//
1251// ObjCProtocolDecl
1252//===----------------------------------------------------------------------===//
1253
David Blaikie99ba9e32011-12-20 02:48:34 +00001254void ObjCProtocolDecl::anchor() { }
1255
Douglas Gregor27c6da22012-01-01 20:30:41 +00001256ObjCProtocolDecl::ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
1257 SourceLocation nameLoc,
1258 SourceLocation atStartLoc,
Douglas Gregorc9d3c7e2012-01-01 22:06:18 +00001259 ObjCProtocolDecl *PrevDecl)
1260 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), Data()
Douglas Gregor27c6da22012-01-01 20:30:41 +00001261{
1262 setPreviousDeclaration(PrevDecl);
1263 if (PrevDecl)
1264 Data = PrevDecl->Data;
1265}
1266
Chris Lattnerab351632009-02-20 20:59:54 +00001267ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001268 IdentifierInfo *Id,
1269 SourceLocation nameLoc,
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +00001270 SourceLocation atStartLoc,
Douglas Gregorc9d3c7e2012-01-01 22:06:18 +00001271 ObjCProtocolDecl *PrevDecl) {
Douglas Gregor27c6da22012-01-01 20:30:41 +00001272 ObjCProtocolDecl *Result
Douglas Gregorc9d3c7e2012-01-01 22:06:18 +00001273 = new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl);
Douglas Gregor27c6da22012-01-01 20:30:41 +00001274
1275 return Result;
Chris Lattnerab351632009-02-20 20:59:54 +00001276}
1277
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001278ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
1279 unsigned ID) {
1280 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCProtocolDecl));
1281 return new (Mem) ObjCProtocolDecl(0, 0, SourceLocation(), SourceLocation(),
1282 0);
1283}
1284
Steve Naroff91b0b0c2009-03-01 16:12:44 +00001285ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
1286 ObjCProtocolDecl *PDecl = this;
1287
1288 if (Name == getIdentifier())
1289 return PDecl;
1290
1291 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
1292 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
1293 return PDecl;
Mike Stump1eb44332009-09-09 15:08:12 +00001294
Steve Naroff91b0b0c2009-03-01 16:12:44 +00001295 return NULL;
1296}
1297
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +00001298// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerab351632009-02-20 20:59:54 +00001299// it inherited.
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +00001300ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
1301 bool isInstance) const {
Chris Lattnerab351632009-02-20 20:59:54 +00001302 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump1eb44332009-09-09 15:08:12 +00001303
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +00001304 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +00001305 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +00001306
Chris Lattnerab351632009-02-20 20:59:54 +00001307 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +00001308 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +00001309 return MethodDecl;
1310 return NULL;
1311}
1312
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +00001313void ObjCProtocolDecl::allocateDefinitionData() {
1314 assert(!Data && "Protocol already has a definition!");
Douglas Gregor1d784b22012-01-01 19:51:50 +00001315 Data = new (getASTContext()) DefinitionData;
1316 Data->Definition = this;
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +00001317}
1318
1319void ObjCProtocolDecl::startDefinition() {
1320 allocateDefinitionData();
Douglas Gregor1d784b22012-01-01 19:51:50 +00001321
1322 // Update all of the declarations with a pointer to the definition.
1323 for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end();
1324 RD != RDEnd; ++RD)
1325 RD->Data = this->Data;
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +00001326}
1327
Anna Zaksb36ea372012-10-18 19:17:53 +00001328void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap& PM) const {
1329 for (ObjCProtocolDecl::prop_iterator P = prop_begin(),
1330 E = prop_end(); P != E; ++P) {
1331 ObjCPropertyDecl *Prop = *P;
1332 // Insert into PM if not there already.
1333 PM.insert(std::make_pair(Prop->getIdentifier(), Prop));
1334 }
1335 // Scan through protocol's protocols.
1336 for (ObjCProtocolDecl::protocol_iterator PI = protocol_begin(),
1337 E = protocol_end(); PI != E; ++PI)
1338 (*PI)->collectPropertiesToImplement(PM);
1339}
1340
1341
Chris Lattnerab351632009-02-20 20:59:54 +00001342//===----------------------------------------------------------------------===//
Chris Lattnerab351632009-02-20 20:59:54 +00001343// ObjCCategoryDecl
1344//===----------------------------------------------------------------------===//
1345
David Blaikie99ba9e32011-12-20 02:48:34 +00001346void ObjCCategoryDecl::anchor() { }
1347
Chris Lattnerab351632009-02-20 20:59:54 +00001348ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor3db211b2010-01-16 16:38:58 +00001349 SourceLocation AtLoc,
1350 SourceLocation ClassNameLoc,
1351 SourceLocation CategoryNameLoc,
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +00001352 IdentifierInfo *Id,
Fariborz Jahanianaf300292012-02-20 20:09:20 +00001353 ObjCInterfaceDecl *IDecl,
1354 SourceLocation IvarLBraceLoc,
1355 SourceLocation IvarRBraceLoc) {
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +00001356 ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
1357 CategoryNameLoc, Id,
Fariborz Jahanianaf300292012-02-20 20:09:20 +00001358 IDecl,
1359 IvarLBraceLoc, IvarRBraceLoc);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +00001360 if (IDecl) {
1361 // Link this category into its class's category list.
1362 CatDecl->NextClassCategory = IDecl->getCategoryList();
Douglas Gregor2e5c15b2011-12-15 05:27:12 +00001363 if (IDecl->hasDefinition()) {
1364 IDecl->setCategoryList(CatDecl);
1365 if (ASTMutationListener *L = C.getASTMutationListener())
1366 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
1367 }
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +00001368 }
1369
1370 return CatDecl;
1371}
1372
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001373ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
1374 unsigned ID) {
1375 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryDecl));
1376 return new (Mem) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(),
1377 SourceLocation(), 0, 0);
Chris Lattnerab351632009-02-20 20:59:54 +00001378}
1379
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001380ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1381 return getASTContext().getObjCImplementation(
1382 const_cast<ObjCCategoryDecl*>(this));
1383}
1384
1385void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1386 getASTContext().setObjCImplementation(this, ImplD);
1387}
1388
1389
Chris Lattnerab351632009-02-20 20:59:54 +00001390//===----------------------------------------------------------------------===//
1391// ObjCCategoryImplDecl
1392//===----------------------------------------------------------------------===//
1393
David Blaikie99ba9e32011-12-20 02:48:34 +00001394void ObjCCategoryImplDecl::anchor() { }
1395
Chris Lattnerab351632009-02-20 20:59:54 +00001396ObjCCategoryImplDecl *
1397ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001398 IdentifierInfo *Id,
1399 ObjCInterfaceDecl *ClassInterface,
1400 SourceLocation nameLoc,
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +00001401 SourceLocation atStartLoc,
1402 SourceLocation CategoryNameLoc) {
Fariborz Jahanian712ef872011-12-23 00:31:02 +00001403 if (ClassInterface && ClassInterface->hasDefinition())
1404 ClassInterface = ClassInterface->getDefinition();
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001405 return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface,
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +00001406 nameLoc, atStartLoc, CategoryNameLoc);
Chris Lattnerab351632009-02-20 20:59:54 +00001407}
1408
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001409ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C,
1410 unsigned ID) {
1411 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryImplDecl));
1412 return new (Mem) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(),
1413 SourceLocation(), SourceLocation());
1414}
1415
Steve Naroff0d69b8c2009-10-29 21:11:04 +00001416ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Ted Kremenekebfa3392010-03-19 20:39:03 +00001417 // The class interface might be NULL if we are working with invalid code.
1418 if (const ObjCInterfaceDecl *ID = getClassInterface())
1419 return ID->FindCategoryDeclaration(getIdentifier());
1420 return 0;
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +00001421}
1422
Chris Lattnerab351632009-02-20 20:59:54 +00001423
David Blaikie99ba9e32011-12-20 02:48:34 +00001424void ObjCImplDecl::anchor() { }
1425
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001426void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor2c2d43c2009-04-23 02:42:49 +00001427 // FIXME: The context should be correct before we get here.
Douglas Gregor653f1b12009-04-23 01:02:12 +00001428 property->setLexicalDeclContext(this);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001429 addDecl(property);
Douglas Gregor653f1b12009-04-23 01:02:12 +00001430}
1431
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001432void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
1433 ASTContext &Ctx = getASTContext();
1434
1435 if (ObjCImplementationDecl *ImplD
Duncan Sands98f2cca2009-07-21 07:56:29 +00001436 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001437 if (IFace)
1438 Ctx.setObjCImplementation(IFace, ImplD);
1439
Duncan Sands98f2cca2009-07-21 07:56:29 +00001440 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001441 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
1442 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
1443 Ctx.setObjCImplementation(CD, ImplD);
1444 }
1445
1446 ClassInterface = IFace;
1447}
1448
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001449/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
James Dennett1c3a46a2012-06-15 22:30:14 +00001450/// properties implemented in this category \@implementation block and returns
Chris Lattnerd6eed1c2009-02-16 19:24:31 +00001451/// the implemented property that uses it.
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001452///
Chris Lattner3aa18612009-02-28 18:42:10 +00001453ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001454FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
1455 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
David Blaikie581deb32012-06-06 20:45:41 +00001456 ObjCPropertyImplDecl *PID = *i;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001457 if (PID->getPropertyIvarDecl() &&
1458 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
1459 return PID;
1460 }
1461 return 0;
1462}
1463
1464/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
James Dennett1c3a46a2012-06-15 22:30:14 +00001465/// added to the list of those properties \@synthesized/\@dynamic in this
1466/// category \@implementation block.
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001467///
Chris Lattner3aa18612009-02-28 18:42:10 +00001468ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001469FindPropertyImplDecl(IdentifierInfo *Id) const {
1470 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
David Blaikie581deb32012-06-06 20:45:41 +00001471 ObjCPropertyImplDecl *PID = *i;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001472 if (PID->getPropertyDecl()->getIdentifier() == Id)
1473 return PID;
1474 }
1475 return 0;
1476}
1477
Chris Lattner5f9e2722011-07-23 10:55:15 +00001478raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramerf9780592012-02-07 11:57:45 +00001479 const ObjCCategoryImplDecl &CID) {
1480 OS << CID.getName();
Benjamin Kramer900fc632010-04-17 09:33:03 +00001481 return OS;
1482}
1483
Chris Lattnerab351632009-02-20 20:59:54 +00001484//===----------------------------------------------------------------------===//
1485// ObjCImplementationDecl
1486//===----------------------------------------------------------------------===//
1487
David Blaikie99ba9e32011-12-20 02:48:34 +00001488void ObjCImplementationDecl::anchor() { }
1489
Chris Lattnerab351632009-02-20 20:59:54 +00001490ObjCImplementationDecl *
Mike Stump1eb44332009-09-09 15:08:12 +00001491ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerab351632009-02-20 20:59:54 +00001492 ObjCInterfaceDecl *ClassInterface,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001493 ObjCInterfaceDecl *SuperDecl,
1494 SourceLocation nameLoc,
Fariborz Jahanianaf300292012-02-20 20:09:20 +00001495 SourceLocation atStartLoc,
1496 SourceLocation IvarLBraceLoc,
1497 SourceLocation IvarRBraceLoc) {
Fariborz Jahanian712ef872011-12-23 00:31:02 +00001498 if (ClassInterface && ClassInterface->hasDefinition())
1499 ClassInterface = ClassInterface->getDefinition();
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001500 return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
Fariborz Jahanianaf300292012-02-20 20:09:20 +00001501 nameLoc, atStartLoc,
1502 IvarLBraceLoc, IvarRBraceLoc);
Chris Lattnerab351632009-02-20 20:59:54 +00001503}
1504
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001505ObjCImplementationDecl *
1506ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1507 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCImplementationDecl));
1508 return new (Mem) ObjCImplementationDecl(0, 0, 0, SourceLocation(),
1509 SourceLocation());
1510}
1511
John McCallda6d9762011-07-22 04:15:06 +00001512void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
1513 CXXCtorInitializer ** initializers,
1514 unsigned numInitializers) {
1515 if (numInitializers > 0) {
1516 NumIvarInitializers = numInitializers;
1517 CXXCtorInitializer **ivarInitializers =
1518 new (C) CXXCtorInitializer*[NumIvarInitializers];
1519 memcpy(ivarInitializers, initializers,
1520 numInitializers * sizeof(CXXCtorInitializer*));
1521 IvarInitializers = ivarInitializers;
1522 }
1523}
1524
Chris Lattner5f9e2722011-07-23 10:55:15 +00001525raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramerf9780592012-02-07 11:57:45 +00001526 const ObjCImplementationDecl &ID) {
1527 OS << ID.getName();
Benjamin Kramer900fc632010-04-17 09:33:03 +00001528 return OS;
1529}
1530
Chris Lattnerab351632009-02-20 20:59:54 +00001531//===----------------------------------------------------------------------===//
1532// ObjCCompatibleAliasDecl
1533//===----------------------------------------------------------------------===//
1534
David Blaikie99ba9e32011-12-20 02:48:34 +00001535void ObjCCompatibleAliasDecl::anchor() { }
1536
Chris Lattnerab351632009-02-20 20:59:54 +00001537ObjCCompatibleAliasDecl *
1538ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
1539 SourceLocation L,
Mike Stump1eb44332009-09-09 15:08:12 +00001540 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +00001541 ObjCInterfaceDecl* AliasedClass) {
1542 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
1543}
1544
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001545ObjCCompatibleAliasDecl *
1546ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1547 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCompatibleAliasDecl));
1548 return new (Mem) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0);
1549}
1550
Chris Lattnerab351632009-02-20 20:59:54 +00001551//===----------------------------------------------------------------------===//
1552// ObjCPropertyDecl
1553//===----------------------------------------------------------------------===//
1554
David Blaikie99ba9e32011-12-20 02:48:34 +00001555void ObjCPropertyDecl::anchor() { }
1556
Chris Lattnerab351632009-02-20 20:59:54 +00001557ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
1558 SourceLocation L,
1559 IdentifierInfo *Id,
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001560 SourceLocation AtLoc,
Fariborz Jahanian77bfb8b2012-02-29 22:18:55 +00001561 SourceLocation LParenLoc,
John McCall83a230c2010-06-04 20:50:08 +00001562 TypeSourceInfo *T,
Chris Lattnerab351632009-02-20 20:59:54 +00001563 PropertyControl propControl) {
Fariborz Jahanian77bfb8b2012-02-29 22:18:55 +00001564 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T);
Chris Lattnerab351632009-02-20 20:59:54 +00001565}
1566
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001567ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
1568 unsigned ID) {
1569 void * Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyDecl));
1570 return new (Mem) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(),
Fariborz Jahanian77bfb8b2012-02-29 22:18:55 +00001571 SourceLocation(),
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001572 0);
1573}
1574
Chris Lattnerab351632009-02-20 20:59:54 +00001575//===----------------------------------------------------------------------===//
1576// ObjCPropertyImplDecl
1577//===----------------------------------------------------------------------===//
1578
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001579ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregord0434102009-01-09 00:49:46 +00001580 DeclContext *DC,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001581 SourceLocation atLoc,
1582 SourceLocation L,
1583 ObjCPropertyDecl *property,
Daniel Dunbar9f0afd42008-08-26 04:47:31 +00001584 Kind PK,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001585 ObjCIvarDecl *ivar,
1586 SourceLocation ivarLoc) {
1587 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
1588 ivarLoc);
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001589}
Chris Lattnerf4af5152008-03-17 01:19:02 +00001590
Douglas Gregor1e68ecc2012-01-05 21:55:30 +00001591ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
1592 unsigned ID) {
1593 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyImplDecl));
1594 return new (Mem) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(),
1595 0, Dynamic, 0, SourceLocation());
1596}
1597
Douglas Gregora4ffd852010-11-17 01:03:52 +00001598SourceRange ObjCPropertyImplDecl::getSourceRange() const {
1599 SourceLocation EndLoc = getLocation();
1600 if (IvarLoc.isValid())
1601 EndLoc = IvarLoc;
Chris Lattner0ed844b2008-04-04 06:12:32 +00001602
Douglas Gregora4ffd852010-11-17 01:03:52 +00001603 return SourceRange(AtLoc, EndLoc);
1604}