blob: 35ee7c6ccdb4f735d316d8fa7eb8b82158f624c3 [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"
Chris Lattner1e03a562008-03-16 00:19:01 +000019using namespace clang;
20
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000021//===----------------------------------------------------------------------===//
Chris Lattner11e1e1a2009-02-20 21:16:26 +000022// ObjCListBase
23//===----------------------------------------------------------------------===//
24
Chris Lattner38af2de2009-02-20 21:35:13 +000025void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
Douglas Gregorff331c12010-07-25 18:17:45 +000026 List = 0;
Chris Lattner11e1e1a2009-02-20 21:16:26 +000027 if (Elts == 0) return; // Setting to an empty list is a noop.
Mike Stump1eb44332009-09-09 15:08:12 +000028
29
Chris Lattner4ee413b2009-02-20 21:44:01 +000030 List = new (Ctx) void*[Elts];
Chris Lattner11e1e1a2009-02-20 21:16:26 +000031 NumElts = Elts;
32 memcpy(List, InList, sizeof(void*)*Elts);
33}
34
Douglas Gregor18df52b2010-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 Lattner11e1e1a2009-02-20 21:16:26 +000045//===----------------------------------------------------------------------===//
Chris Lattnerab351632009-02-20 20:59:54 +000046// ObjCInterfaceDecl
Chris Lattner6c4ae5d2008-03-16 00:49:28 +000047//===----------------------------------------------------------------------===//
48
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000049/// getIvarDecl - This method looks up an ivar in this ContextDecl.
50///
51ObjCIvarDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000052ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000053 lookup_const_iterator Ivar, IvarEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000054 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +000055 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
56 return ivar;
57 }
58 return 0;
59}
60
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000061// Get the local instance/class method declared in this interface.
Douglas Gregor6ab35242009-04-09 21:40:53 +000062ObjCMethodDecl *
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000063ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
Steve Naroff0de21fd2009-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 Kyrtzidis17945a02009-06-30 02:36:12 +000073 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
Steve Naroff0de21fd2009-02-22 19:35:57 +000074 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
Argyrios Kyrtzidis467c0b12009-07-25 22:15:22 +000075 if (MD && MD->isInstanceMethod() == isInstance)
Steve Naroff0de21fd2009-02-22 19:35:57 +000076 return MD;
77 }
Steve Naroff0701bbb2009-01-08 17:28:14 +000078 return 0;
79}
80
Ted Kremenek9f550ff2010-03-15 20:11:46 +000081ObjCPropertyDecl *
Ted Kremenekde09d0c2010-03-15 20:11:53 +000082ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
Ted Kremenek9f550ff2010-03-15 20:11:46 +000083 IdentifierInfo *propertyID) {
84
Ted Kremenekde09d0c2010-03-15 20:11:53 +000085 DeclContext::lookup_const_iterator I, E;
Ted Kremenek9f550ff2010-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 Jahanian559c0c42008-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 Jahanian559c0c42008-04-21 19:04:53 +000096ObjCPropertyDecl *
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000097ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
Mike Stump1eb44332009-09-09 15:08:12 +000098
Ted Kremenekde09d0c2010-03-15 20:11:53 +000099 if (ObjCPropertyDecl *PD =
100 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
101 return PD;
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Ted Kremenekde09d0c2010-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 Jahanian25760612010-02-15 21:55:26 +0000110 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
111 return P;
Ted Kremenekde09d0c2010-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 Kremenek53b94412010-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 Kremenekde09d0c2010-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 Jahanianf034e9c2009-01-19 18:16:19 +0000145 }
146 }
Steve Naroff3d2c22b2008-06-05 13:55:23 +0000147 return 0;
148}
149
Fariborz Jahaniana6f14e12009-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 Kremenek37cafb02010-03-15 20:30:07 +0000152/// (direct or indirect) used by the primary class.
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000153///
154ObjCPropertyDecl *
Ted Kremenek37cafb02010-03-15 20:30:07 +0000155ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000156 IdentifierInfo *PropertyId) const {
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000157 if (ExternallyCompleted)
158 LoadExternalDefinition();
159
Ted Kremenek37cafb02010-03-15 20:30:07 +0000160 if (ObjCPropertyDecl *PD =
161 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
162 return PD;
163
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000164 // Look through protocols.
Ted Kremenek53b94412010-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 Jahaniana6f14e12009-11-02 22:45:15 +0000168 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
169 return P;
Ted Kremenek37cafb02010-03-15 20:30:07 +0000170
Fariborz Jahaniana6f14e12009-11-02 22:45:15 +0000171 return 0;
172}
173
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000174void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
175 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
176 ASTContext &C)
177{
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000178 if (ExternallyCompleted)
179 LoadExternalDefinition();
180
Ted Kremenek53b94412010-09-01 01:21:15 +0000181 if (AllReferencedProtocols.empty() && ReferencedProtocols.empty()) {
182 AllReferencedProtocols.set(ExtList, ExtNum, C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000183 return;
184 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000185
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000186 // Check for duplicate protocol in class's protocol list.
Ted Kremenek53b94412010-09-01 01:21:15 +0000187 // This is O(n*m). But it is extremely rare and number of protocols in
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000188 // class or its extension are very few.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000189 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000190 for (unsigned i = 0; i < ExtNum; i++) {
191 bool protocolExists = false;
192 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
Ted Kremenek53b94412010-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 Jahanian339798e2009-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 Kremenek53b94412010-09-01 01:21:15 +0000204 if (!protocolExists)
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000205 ProtocolRefs.push_back(ProtoInExtension);
206 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000207
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000208 if (ProtocolRefs.empty())
209 return;
Ted Kremenek53b94412010-09-01 01:21:15 +0000210
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000211 // Merge ProtocolRefs into class's protocol list;
Ted Kremenek53b94412010-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 Jahanian339798e2009-10-05 20:41:32 +0000214 ProtocolRefs.push_back(*p);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000215 }
Ted Kremenek53b94412010-09-01 01:21:15 +0000216
217 AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(), C);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000218}
219
Argyrios Kyrtzidisad834d52011-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 Jahanian80aa1cd2010-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 Jahanian0e5ad252010-02-23 01:26:30 +0000230 CDecl = CDecl->getNextClassCategory())
231 if (CDecl->IsClassExtension())
232 return CDecl;
233 return 0;
234}
235
Fariborz Jahanian80aa1cd2010-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 Kyrtzidis17945a02009-06-30 02:36:12 +0000245ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
246 ObjCInterfaceDecl *&clsDeclared) {
Argyrios Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000247 if (ExternallyCompleted)
248 LoadExternalDefinition();
249
Chris Lattner1e03a562008-03-16 00:19:01 +0000250 ObjCInterfaceDecl* ClassDecl = this;
251 while (ClassDecl != NULL) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000252 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
Fariborz Jahanian496b5a82009-06-05 18:16:35 +0000253 clsDeclared = ClassDecl;
254 return I;
Chris Lattner1e03a562008-03-16 00:19:01 +0000255 }
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000256 for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension();
257 CDecl; CDecl = CDecl->getNextClassExtension()) {
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000258 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
259 clsDeclared = ClassDecl;
260 return I;
261 }
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000262 }
Fariborz Jahanian0e5ad252010-02-23 01:26:30 +0000263
Chris Lattner1e03a562008-03-16 00:19:01 +0000264 ClassDecl = ClassDecl->getSuperClass();
265 }
266 return NULL;
267}
268
Fariborz Jahaniancd187622009-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 Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000274 if (ExternallyCompleted)
275 LoadExternalDefinition();
276
Fariborz Jahaniancd187622009-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 Kyrtzidisaa5420c2009-07-25 22:15:51 +0000286/// lookupMethod - This method returns an instance/class method by looking in
Chris Lattner1e03a562008-03-16 00:19:01 +0000287/// the class, its categories, and its super classes (using a linear search).
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000288ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
289 bool isInstance) const {
290 const ObjCInterfaceDecl* ClassDecl = this;
Chris Lattner1e03a562008-03-16 00:19:01 +0000291 ObjCMethodDecl *MethodDecl = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000292
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000293 if (ExternallyCompleted)
294 LoadExternalDefinition();
295
Chris Lattner1e03a562008-03-16 00:19:01 +0000296 while (ClassDecl != NULL) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000297 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000298 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000299
Chris Lattner1e03a562008-03-16 00:19:01 +0000300 // Didn't find one yet - look through protocols.
Chris Lattner3db6cae2008-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 Kyrtzidisaa5420c2009-07-25 22:15:51 +0000305 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000306 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Chris Lattner1e03a562008-03-16 00:19:01 +0000308 // Didn't find one yet - now look through categories.
309 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
310 while (CatDecl) {
Argyrios Kyrtzidisaa5420c2009-07-25 22:15:51 +0000311 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
Chris Lattner1e03a562008-03-16 00:19:01 +0000312 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Steve Naroffb79c01e2008-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 Kyrtzidisaa5420c2009-07-25 22:15:51 +0000319 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Steve Naroffb5584222009-02-26 11:32:02 +0000320 return MethodDecl;
Chris Lattner1e03a562008-03-16 00:19:01 +0000321 CatDecl = CatDecl->getNextClassCategory();
322 }
323 ClassDecl = ClassDecl->getSuperClass();
324 }
325 return NULL;
326}
327
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000328ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
329 const Selector &Sel,
330 bool Instance) {
Argyrios Kyrtzidis7c81c2a2011-10-19 02:25:16 +0000331 if (ExternallyCompleted)
332 LoadExternalDefinition();
333
Steve Naroffd789d3d2009-10-01 23:46:04 +0000334 ObjCMethodDecl *Method = 0;
335 if (ObjCImplementationDecl *ImpDecl = getImplementation())
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000336 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
337 : ImpDecl->getClassMethod(Sel);
Steve Naroffd789d3d2009-10-01 23:46:04 +0000338
339 if (!Method && getSuperClass())
Fariborz Jahanian74b27562010-12-03 23:37:08 +0000340 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
Steve Naroffd789d3d2009-10-01 23:46:04 +0000341 return Method;
342}
Chris Lattnerab351632009-02-20 20:59:54 +0000343
344//===----------------------------------------------------------------------===//
345// ObjCMethodDecl
346//===----------------------------------------------------------------------===//
347
348ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +0000349 SourceLocation beginLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000350 SourceLocation endLoc,
351 Selector SelInfo, QualType T,
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000352 TypeSourceInfo *ResultTInfo,
Chris Lattnerab351632009-02-20 20:59:54 +0000353 DeclContext *contextDecl,
354 bool isInstance,
355 bool isVariadic,
356 bool isSynthesized,
Argyrios Kyrtzidis75cf3e82011-08-17 19:25:08 +0000357 bool isImplicitlyDeclared,
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000358 bool isDefined,
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000359 ImplementationControl impControl,
Argyrios Kyrtzidisda92a7f2011-10-03 06:36:29 +0000360 bool HasRelatedResultType) {
Chris Lattnerab351632009-02-20 20:59:54 +0000361 return new (C) ObjCMethodDecl(beginLoc, endLoc,
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000362 SelInfo, T, ResultTInfo, contextDecl,
363 isInstance,
Argyrios Kyrtzidis75cf3e82011-08-17 19:25:08 +0000364 isVariadic, isSynthesized, isImplicitlyDeclared,
365 isDefined,
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000366 impControl,
Argyrios Kyrtzidisda92a7f2011-10-03 06:36:29 +0000367 HasRelatedResultType);
Chris Lattner1e03a562008-03-16 00:19:01 +0000368}
369
Argyrios Kyrtzidis3a919e72011-10-14 08:02:31 +0000370void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
371 assert(PrevMethod);
372 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
373 IsRedeclaration = true;
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000374 PrevMethod->HasRedeclaration = true;
Argyrios Kyrtzidis3a919e72011-10-14 08:02:31 +0000375}
376
Argyrios Kyrtzidis491306a2011-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 Kyrtzidis57ea6be2009-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 Kyrtzidis72b26252011-10-14 17:41:52 +0000418 ObjCMethodDecl *Redecl = 0;
419 if (HasRedeclaration)
420 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
Argyrios Kyrtzidisb40034c2011-10-14 06:48:06 +0000421 if (Redecl)
422 return Redecl;
423
Argyrios Kyrtzidis57ea6be2009-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 Kyrtzidis42920732009-07-28 05:11:05 +0000434 } else if (ObjCImplementationDecl *ImplD =
435 dyn_cast<ObjCImplementationDecl>(CtxD)) {
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000436 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
437 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000438
439 } else if (ObjCCategoryImplDecl *CImplD =
440 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
Steve Naroff0d69b8c2009-10-29 21:11:04 +0000441 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +0000442 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
Argyrios Kyrtzidis57ea6be2009-07-21 00:06:36 +0000443 }
444
Argyrios Kyrtzidis3a919e72011-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 Kyrtzidis57ea6be2009-07-21 00:06:36 +0000451 return Redecl ? Redecl : this;
452}
453
Argyrios Kyrtzidise7f9d302009-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 Naroff0d69b8c2009-10-29 21:11:04 +0000465 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000466 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
467 isInstanceMethod()))
468 return MD;
469 }
470
Argyrios Kyrtzidis6d4740e2011-10-17 19:48:09 +0000471 if (isRedeclaration())
472 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
473 isInstanceMethod());
474
Argyrios Kyrtzidise7f9d302009-07-28 05:11:17 +0000475 return this;
476}
477
John McCall85f3d762011-03-02 01:50:55 +0000478ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
479 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
John McCalld976c8e2011-03-02 21:01:41 +0000480 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
John McCall85f3d762011-03-02 01:50:55 +0000481 return family;
482
John McCalld5313b02011-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 McCall85f3d762011-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 Weber80cb6e62011-08-28 22:35:17 +0000522 case OMF_finalize:
John McCall85f3d762011-03-02 01:50:55 +0000523 case OMF_retain:
524 case OMF_release:
525 case OMF_autorelease:
526 case OMF_retainCount:
Douglas Gregor926df6c2011-06-11 01:09:30 +0000527 case OMF_self:
John McCall85f3d762011-03-02 01:50:55 +0000528 if (!isInstanceMethod())
529 family = OMF_None;
530 break;
Fariborz Jahanian9670e172011-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 McCall85f3d762011-03-02 01:50:55 +0000559 }
560
561 // Cache the result.
562 Family = static_cast<unsigned>(family);
563 return family;
564}
565
Mike Stump1eb44332009-09-09 15:08:12 +0000566void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
Chris Lattnerab351632009-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 Dunbar3b3a4582009-04-22 04:34:53 +0000573 selfTy = Context.getObjCInterfaceType(OID);
Steve Naroff14108da2009-07-10 23:34:53 +0000574 selfTy = Context.getObjCObjectPointerType(selfTy);
Chris Lattnerab351632009-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 McCall7acddac2011-06-17 06:42:21 +0000581 bool selfIsPseudoStrong = false;
John McCallf85e1932011-06-15 23:02:42 +0000582 bool selfIsConsumed = false;
583 if (isInstanceMethod() && Context.getLangOptions().ObjCAutoRefCount) {
584 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
585
John McCall7acddac2011-06-17 06:42:21 +0000586 // 'self' is always __strong. It's actually pseudo-strong except
Ted Kremenek3045ce72011-10-25 04:52:20 +0000587 // in init methods (or methods labeled ns_consumes_self), though.
John McCallf85e1932011-06-15 23:02:42 +0000588 Qualifiers qs;
589 qs.setObjCLifetime(Qualifiers::OCL_Strong);
590 selfTy = Context.getQualifiedType(selfTy, qs);
591
592 // In addition, 'self' is const unless this is an init method.
Ted Kremenek3045ce72011-10-25 04:52:20 +0000593 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
John McCallf85e1932011-06-15 23:02:42 +0000594 selfTy = selfTy.withConst();
John McCall7acddac2011-06-17 06:42:21 +0000595 selfIsPseudoStrong = true;
596 }
John McCallf85e1932011-06-15 23:02:42 +0000597 }
598
599 ImplicitParamDecl *self
600 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
601 &Context.Idents.get("self"), selfTy);
602 setSelfDecl(self);
603
604 if (selfIsConsumed)
605 self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context));
Chris Lattnerab351632009-02-20 20:59:54 +0000606
John McCall7acddac2011-06-17 06:42:21 +0000607 if (selfIsPseudoStrong)
608 self->setARCPseudoStrong(true);
609
Mike Stump1eb44332009-09-09 15:08:12 +0000610 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
611 &Context.Idents.get("_cmd"),
Steve Naroff53c9d8a2009-04-20 15:06:07 +0000612 Context.getObjCSelType()));
Chris Lattnerab351632009-02-20 20:59:54 +0000613}
614
Chris Lattnerab351632009-02-20 20:59:54 +0000615ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
616 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
617 return ID;
618 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
619 return CD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000620 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
Chris Lattnerab351632009-02-20 20:59:54 +0000621 return IMD->getClassInterface();
Argyrios Kyrtzidisa8530372009-07-28 05:10:52 +0000622
623 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
David Blaikieb219cfc2011-09-23 05:06:16 +0000624 llvm_unreachable("unknown method context");
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000625}
626
Chris Lattnerab351632009-02-20 20:59:54 +0000627//===----------------------------------------------------------------------===//
628// ObjCInterfaceDecl
629//===----------------------------------------------------------------------===//
630
631ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
632 DeclContext *DC,
633 SourceLocation atLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000634 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +0000635 SourceLocation ClassLoc,
636 bool ForwardDecl, bool isInternal){
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000637 return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
638 isInternal);
Chris Lattnerab351632009-02-20 20:59:54 +0000639}
640
641ObjCInterfaceDecl::
642ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000643 SourceLocation CLoc, bool FD, bool isInternal)
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000644 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
Chris Lattnerab351632009-02-20 20:59:54 +0000645 TypeForDecl(0), SuperClass(0),
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000646 CategoryList(0), IvarList(0),
647 InitiallyForwardDecl(FD), ForwardDecl(FD),
648 InternalInterface(isInternal), ExternallyCompleted(false) {
Chris Lattnerab351632009-02-20 20:59:54 +0000649}
650
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000651void ObjCInterfaceDecl::LoadExternalDefinition() const {
652 assert(ExternallyCompleted && "Class is not externally completed");
653 ExternallyCompleted = false;
654 getASTContext().getExternalSource()->CompleteType(
655 const_cast<ObjCInterfaceDecl *>(this));
656}
657
658void ObjCInterfaceDecl::setExternallyCompleted() {
659 assert(getASTContext().getExternalSource() &&
660 "Class can't be externally completed without an external source");
661 assert(!ForwardDecl &&
662 "Forward declarations can't be externally completed");
663 ExternallyCompleted = true;
664}
665
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000666ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000667 if (ExternallyCompleted)
668 LoadExternalDefinition();
669
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000670 return getASTContext().getObjCImplementation(
671 const_cast<ObjCInterfaceDecl*>(this));
672}
673
674void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
675 getASTContext().setObjCImplementation(this, ImplD);
676}
677
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000678/// all_declared_ivar_begin - return first ivar declared in this class,
679/// its extensions and its implementation. Lazily build the list on first
680/// access.
681ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
682 if (IvarList)
683 return IvarList;
684
685 ObjCIvarDecl *curIvar = 0;
686 if (!ivar_empty()) {
687 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
688 IvarList = (*I); ++I;
689 for (curIvar = IvarList; I != E; curIvar = *I, ++I)
690 curIvar->setNextIvar(*I);
691 }
692
693 for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl;
694 CDecl = CDecl->getNextClassExtension()) {
695 if (!CDecl->ivar_empty()) {
696 ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
697 E = CDecl->ivar_end();
698 if (!IvarList) {
699 IvarList = (*I); ++I;
700 curIvar = IvarList;
701 }
702 for ( ;I != E; curIvar = *I, ++I)
703 curIvar->setNextIvar(*I);
704 }
705 }
706
707 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
708 if (!ImplDecl->ivar_empty()) {
709 ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
710 E = ImplDecl->ivar_end();
711 if (!IvarList) {
712 IvarList = (*I); ++I;
713 curIvar = IvarList;
714 }
715 for ( ;I != E; curIvar = *I, ++I)
716 curIvar->setNextIvar(*I);
717 }
718 }
719 return IvarList;
720}
Chris Lattnerab351632009-02-20 20:59:54 +0000721
722/// FindCategoryDeclaration - Finds category declaration in the list of
723/// categories for this class and returns it. Name of the category is passed
724/// in 'CategoryId'. If category not found, return 0;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000725///
Chris Lattnerab351632009-02-20 20:59:54 +0000726ObjCCategoryDecl *
727ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
Douglas Gregor26ac3f32010-12-01 23:49:52 +0000728 if (ExternallyCompleted)
729 LoadExternalDefinition();
730
Chris Lattnerab351632009-02-20 20:59:54 +0000731 for (ObjCCategoryDecl *Category = getCategoryList();
732 Category; Category = Category->getNextClassCategory())
733 if (Category->getIdentifier() == CategoryId)
734 return Category;
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +0000735 return 0;
736}
737
Argyrios Kyrtzidis1cb35dd2009-07-21 00:06:20 +0000738ObjCMethodDecl *
739ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
740 for (ObjCCategoryDecl *Category = getCategoryList();
741 Category; Category = Category->getNextClassCategory())
742 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
743 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
744 return MD;
745 return 0;
746}
747
748ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
749 for (ObjCCategoryDecl *Category = getCategoryList();
750 Category; Category = Category->getNextClassCategory())
751 if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
752 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
753 return MD;
754 return 0;
755}
756
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000757/// ClassImplementsProtocol - Checks that 'lProto' protocol
758/// has been implemented in IDecl class, its super class or categories (if
759/// lookupCategory is true).
760bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
761 bool lookupCategory,
762 bool RHSIsQualifiedID) {
763 ObjCInterfaceDecl *IDecl = this;
764 // 1st, look up the class.
765 const ObjCList<ObjCProtocolDecl> &Protocols =
766 IDecl->getReferencedProtocols();
Mike Stump1eb44332009-09-09 15:08:12 +0000767
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000768 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
769 E = Protocols.end(); PI != E; ++PI) {
770 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
771 return true;
772 // This is dubious and is added to be compatible with gcc. In gcc, it is
773 // also allowed assigning a protocol-qualified 'id' type to a LHS object
774 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
775 // object. This IMO, should be a bug.
776 // FIXME: Treat this as an extension, and flag this as an error when GCC
777 // extensions are not enabled.
Mike Stump1eb44332009-09-09 15:08:12 +0000778 if (RHSIsQualifiedID &&
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000779 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
780 return true;
781 }
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000783 // 2nd, look up the category.
784 if (lookupCategory)
785 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
786 CDecl = CDecl->getNextClassCategory()) {
787 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
788 E = CDecl->protocol_end(); PI != E; ++PI)
789 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
790 return true;
791 }
Mike Stump1eb44332009-09-09 15:08:12 +0000792
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000793 // 3rd, look up the super class(s)
794 if (IDecl->getSuperClass())
795 return
796 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
797 RHSIsQualifiedID);
Mike Stump1eb44332009-09-09 15:08:12 +0000798
Fariborz Jahanian0fd89042009-08-11 22:02:25 +0000799 return false;
800}
801
Chris Lattnerab351632009-02-20 20:59:54 +0000802//===----------------------------------------------------------------------===//
803// ObjCIvarDecl
804//===----------------------------------------------------------------------===//
805
Daniel Dunbara0654922010-04-02 20:10:03 +0000806ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000807 SourceLocation StartLoc,
808 SourceLocation IdLoc, IdentifierInfo *Id,
John McCalla93c9342009-12-07 02:54:59 +0000809 QualType T, TypeSourceInfo *TInfo,
Fariborz Jahanianad51e742010-07-17 00:59:30 +0000810 AccessControl ac, Expr *BW,
811 bool synthesized) {
Daniel Dunbara0654922010-04-02 20:10:03 +0000812 if (DC) {
813 // Ivar's can only appear in interfaces, implementations (via synthesized
814 // properties), and class extensions (via direct declaration, or synthesized
815 // properties).
816 //
817 // FIXME: This should really be asserting this:
818 // (isa<ObjCCategoryDecl>(DC) &&
819 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
820 // but unfortunately we sometimes place ivars into non-class extension
821 // categories on error. This breaks an AST invariant, and should not be
822 // fixed.
823 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
824 isa<ObjCCategoryDecl>(DC)) &&
825 "Invalid ivar decl context!");
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000826 // Once a new ivar is created in any of class/class-extension/implementation
827 // decl contexts, the previously built IvarList must be rebuilt.
828 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
829 if (!ID) {
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000830 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) {
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000831 ID = IM->getClassInterface();
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000832 if (BW)
833 IM->setHasSynthBitfield(true);
Chad Rosier30601782011-08-17 23:08:45 +0000834 } else {
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000835 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
836 ID = CD->getClassInterface();
837 if (BW)
838 CD->setHasSynthBitfield(true);
839 }
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000840 }
841 ID->setIvarList(0);
Daniel Dunbara0654922010-04-02 20:10:03 +0000842 }
843
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000844 return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo,
845 ac, BW, synthesized);
Chris Lattnerab351632009-02-20 20:59:54 +0000846}
847
Daniel Dunbar27a961a2010-04-02 21:13:59 +0000848const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
849 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
Chris Lattnerab351632009-02-20 20:59:54 +0000850
Daniel Dunbar27a961a2010-04-02 21:13:59 +0000851 switch (DC->getKind()) {
852 default:
853 case ObjCCategoryImpl:
854 case ObjCProtocol:
David Blaikieb219cfc2011-09-23 05:06:16 +0000855 llvm_unreachable("invalid ivar container!");
Daniel Dunbar27a961a2010-04-02 21:13:59 +0000856
857 // Ivars can only appear in class extension categories.
858 case ObjCCategory: {
859 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
860 assert(CD->IsClassExtension() && "invalid container for ivar!");
861 return CD->getClassInterface();
862 }
863
864 case ObjCImplementation:
865 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
866
867 case ObjCInterface:
868 return cast<ObjCInterfaceDecl>(DC);
869 }
870}
Chris Lattnerab351632009-02-20 20:59:54 +0000871
872//===----------------------------------------------------------------------===//
873// ObjCAtDefsFieldDecl
874//===----------------------------------------------------------------------===//
875
876ObjCAtDefsFieldDecl
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000877*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
878 SourceLocation StartLoc, SourceLocation IdLoc,
Chris Lattnerab351632009-02-20 20:59:54 +0000879 IdentifierInfo *Id, QualType T, Expr *BW) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000880 return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
Chris Lattnerab351632009-02-20 20:59:54 +0000881}
882
Chris Lattnerab351632009-02-20 20:59:54 +0000883//===----------------------------------------------------------------------===//
884// ObjCProtocolDecl
885//===----------------------------------------------------------------------===//
886
887ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000888 IdentifierInfo *Id,
889 SourceLocation nameLoc,
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000890 SourceLocation atStartLoc,
891 bool isForwardDecl) {
892 return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl);
Chris Lattnerab351632009-02-20 20:59:54 +0000893}
894
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000895ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
896 ObjCProtocolDecl *PDecl = this;
897
898 if (Name == getIdentifier())
899 return PDecl;
900
901 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
902 if ((PDecl = (*I)->lookupProtocolNamed(Name)))
903 return PDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000904
Steve Naroff91b0b0c2009-03-01 16:12:44 +0000905 return NULL;
906}
907
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000908// lookupMethod - Lookup a instance/class method in the protocol and protocols
Chris Lattnerab351632009-02-20 20:59:54 +0000909// it inherited.
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000910ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
911 bool isInstance) const {
Chris Lattnerab351632009-02-20 20:59:54 +0000912 ObjCMethodDecl *MethodDecl = NULL;
Mike Stump1eb44332009-09-09 15:08:12 +0000913
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000914 if ((MethodDecl = getMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000915 return MethodDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000916
Chris Lattnerab351632009-02-20 20:59:54 +0000917 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
Argyrios Kyrtzidis094e2bb2009-07-25 22:15:38 +0000918 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
Chris Lattnerab351632009-02-20 20:59:54 +0000919 return MethodDecl;
920 return NULL;
921}
922
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000923void ObjCProtocolDecl::completedForwardDecl() {
924 assert(isForwardDecl() && "Only valid to call for forward refs");
925 isForwardProtoDecl = false;
926 if (ASTMutationListener *L = getASTContext().getASTMutationListener())
927 L->CompletedObjCForwardRef(this);
928}
929
Chris Lattnerab351632009-02-20 20:59:54 +0000930//===----------------------------------------------------------------------===//
931// ObjCClassDecl
932//===----------------------------------------------------------------------===//
933
Mike Stump1eb44332009-09-09 15:08:12 +0000934ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000935 ObjCInterfaceDecl *const Elt,
936 const SourceLocation Loc,
Chris Lattner38af2de2009-02-20 21:35:13 +0000937 ASTContext &C)
938 : Decl(ObjCClass, DC, L) {
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000939 setClass(C, Elt, Loc);
Ted Kremenek321c22f2009-11-18 00:28:11 +0000940}
Chris Lattner38af2de2009-02-20 21:35:13 +0000941
Chris Lattnerab351632009-02-20 20:59:54 +0000942ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
943 SourceLocation L,
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000944 ObjCInterfaceDecl *const Elt,
945 const SourceLocation Loc) {
946 return new (C) ObjCClassDecl(DC, L, Elt, Loc, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000947}
948
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000949void ObjCClassDecl::setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
950 const SourceLocation Loc) {
951
952 ForwardDecl = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef),
953 llvm::alignOf<ObjCClassRef>());
954 new (ForwardDecl) ObjCClassRef(Cls, Loc);
955}
956
Ted Kremenek2dbdd622009-11-18 01:26:56 +0000957SourceRange ObjCClassDecl::getSourceRange() const {
958 // FIXME: We should include the semicolon
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000959 return SourceRange(getLocation(), ForwardDecl->getLocation());
Ted Kremenek2dbdd622009-11-18 01:26:56 +0000960}
961
Chris Lattnerab351632009-02-20 20:59:54 +0000962//===----------------------------------------------------------------------===//
963// ObjCForwardProtocolDecl
964//===----------------------------------------------------------------------===//
965
Chris Lattner38af2de2009-02-20 21:35:13 +0000966ObjCForwardProtocolDecl::
967ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
968 ObjCProtocolDecl *const *Elts, unsigned nElts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000969 const SourceLocation *Locs, ASTContext &C)
Mike Stump1eb44332009-09-09 15:08:12 +0000970: Decl(ObjCForwardProtocol, DC, L) {
Douglas Gregor18df52b2010-01-16 15:02:53 +0000971 ReferencedProtocols.set(Elts, nElts, Locs, C);
Chris Lattner38af2de2009-02-20 21:35:13 +0000972}
973
974
Chris Lattnerab351632009-02-20 20:59:54 +0000975ObjCForwardProtocolDecl *
976ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
Mike Stump1eb44332009-09-09 15:08:12 +0000977 SourceLocation L,
Chris Lattnerab351632009-02-20 20:59:54 +0000978 ObjCProtocolDecl *const *Elts,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000979 unsigned NumElts,
980 const SourceLocation *Locs) {
981 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
Chris Lattnerab351632009-02-20 20:59:54 +0000982}
983
Chris Lattnerab351632009-02-20 20:59:54 +0000984//===----------------------------------------------------------------------===//
985// ObjCCategoryDecl
986//===----------------------------------------------------------------------===//
987
988ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor3db211b2010-01-16 16:38:58 +0000989 SourceLocation AtLoc,
990 SourceLocation ClassNameLoc,
991 SourceLocation CategoryNameLoc,
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000992 IdentifierInfo *Id,
993 ObjCInterfaceDecl *IDecl) {
994 ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
995 CategoryNameLoc, Id,
996 IDecl);
997 if (IDecl) {
998 // Link this category into its class's category list.
999 CatDecl->NextClassCategory = IDecl->getCategoryList();
1000 IDecl->setCategoryList(CatDecl);
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001001 if (ASTMutationListener *L = C.getASTMutationListener())
1002 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +00001003 }
1004
1005 return CatDecl;
1006}
1007
1008ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, EmptyShell Empty) {
1009 return new (C) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(),
1010 SourceLocation(), 0, 0);
Chris Lattnerab351632009-02-20 20:59:54 +00001011}
1012
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001013ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1014 return getASTContext().getObjCImplementation(
1015 const_cast<ObjCCategoryDecl*>(this));
1016}
1017
1018void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1019 getASTContext().setObjCImplementation(this, ImplD);
1020}
1021
1022
Chris Lattnerab351632009-02-20 20:59:54 +00001023//===----------------------------------------------------------------------===//
1024// ObjCCategoryImplDecl
1025//===----------------------------------------------------------------------===//
1026
1027ObjCCategoryImplDecl *
1028ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001029 IdentifierInfo *Id,
1030 ObjCInterfaceDecl *ClassInterface,
1031 SourceLocation nameLoc,
1032 SourceLocation atStartLoc) {
1033 return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface,
1034 nameLoc, atStartLoc);
Chris Lattnerab351632009-02-20 20:59:54 +00001035}
1036
Steve Naroff0d69b8c2009-10-29 21:11:04 +00001037ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
Ted Kremenekebfa3392010-03-19 20:39:03 +00001038 // The class interface might be NULL if we are working with invalid code.
1039 if (const ObjCInterfaceDecl *ID = getClassInterface())
1040 return ID->FindCategoryDeclaration(getIdentifier());
1041 return 0;
Argyrios Kyrtzidis42920732009-07-28 05:11:05 +00001042}
1043
Chris Lattnerab351632009-02-20 20:59:54 +00001044
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001045void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
Douglas Gregor2c2d43c2009-04-23 02:42:49 +00001046 // FIXME: The context should be correct before we get here.
Douglas Gregor653f1b12009-04-23 01:02:12 +00001047 property->setLexicalDeclContext(this);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001048 addDecl(property);
Douglas Gregor653f1b12009-04-23 01:02:12 +00001049}
1050
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001051void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
1052 ASTContext &Ctx = getASTContext();
1053
1054 if (ObjCImplementationDecl *ImplD
Duncan Sands98f2cca2009-07-21 07:56:29 +00001055 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001056 if (IFace)
1057 Ctx.setObjCImplementation(IFace, ImplD);
1058
Duncan Sands98f2cca2009-07-21 07:56:29 +00001059 } else if (ObjCCategoryImplDecl *ImplD =
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +00001060 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
1061 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
1062 Ctx.setObjCImplementation(CD, ImplD);
1063 }
1064
1065 ClassInterface = IFace;
1066}
1067
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001068/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
Chris Lattnerd6eed1c2009-02-16 19:24:31 +00001069/// properties implemented in this category @implementation block and returns
1070/// the implemented property that uses it.
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001071///
Chris Lattner3aa18612009-02-28 18:42:10 +00001072ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001073FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
1074 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001075 ObjCPropertyImplDecl *PID = *i;
1076 if (PID->getPropertyIvarDecl() &&
1077 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
1078 return PID;
1079 }
1080 return 0;
1081}
1082
1083/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
1084/// added to the list of those properties @synthesized/@dynamic in this
1085/// category @implementation block.
1086///
Chris Lattner3aa18612009-02-28 18:42:10 +00001087ObjCPropertyImplDecl *ObjCImplDecl::
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001088FindPropertyImplDecl(IdentifierInfo *Id) const {
1089 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
Fariborz Jahanianae6f6fd2008-12-05 22:32:48 +00001090 ObjCPropertyImplDecl *PID = *i;
1091 if (PID->getPropertyDecl()->getIdentifier() == Id)
1092 return PID;
1093 }
1094 return 0;
1095}
1096
Chris Lattner5f9e2722011-07-23 10:55:15 +00001097raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramer900fc632010-04-17 09:33:03 +00001098 const ObjCCategoryImplDecl *CID) {
1099 OS << CID->getName();
1100 return OS;
1101}
1102
Chris Lattnerab351632009-02-20 20:59:54 +00001103//===----------------------------------------------------------------------===//
1104// ObjCImplementationDecl
1105//===----------------------------------------------------------------------===//
1106
1107ObjCImplementationDecl *
Mike Stump1eb44332009-09-09 15:08:12 +00001108ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerab351632009-02-20 20:59:54 +00001109 ObjCInterfaceDecl *ClassInterface,
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001110 ObjCInterfaceDecl *SuperDecl,
1111 SourceLocation nameLoc,
1112 SourceLocation atStartLoc) {
1113 return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
1114 nameLoc, atStartLoc);
Chris Lattnerab351632009-02-20 20:59:54 +00001115}
1116
John McCallda6d9762011-07-22 04:15:06 +00001117void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
1118 CXXCtorInitializer ** initializers,
1119 unsigned numInitializers) {
1120 if (numInitializers > 0) {
1121 NumIvarInitializers = numInitializers;
1122 CXXCtorInitializer **ivarInitializers =
1123 new (C) CXXCtorInitializer*[NumIvarInitializers];
1124 memcpy(ivarInitializers, initializers,
1125 numInitializers * sizeof(CXXCtorInitializer*));
1126 IvarInitializers = ivarInitializers;
1127 }
1128}
1129
Chris Lattner5f9e2722011-07-23 10:55:15 +00001130raw_ostream &clang::operator<<(raw_ostream &OS,
Benjamin Kramer900fc632010-04-17 09:33:03 +00001131 const ObjCImplementationDecl *ID) {
1132 OS << ID->getName();
1133 return OS;
1134}
1135
Chris Lattnerab351632009-02-20 20:59:54 +00001136//===----------------------------------------------------------------------===//
1137// ObjCCompatibleAliasDecl
1138//===----------------------------------------------------------------------===//
1139
1140ObjCCompatibleAliasDecl *
1141ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
1142 SourceLocation L,
Mike Stump1eb44332009-09-09 15:08:12 +00001143 IdentifierInfo *Id,
Chris Lattnerab351632009-02-20 20:59:54 +00001144 ObjCInterfaceDecl* AliasedClass) {
1145 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
1146}
1147
1148//===----------------------------------------------------------------------===//
1149// ObjCPropertyDecl
1150//===----------------------------------------------------------------------===//
1151
1152ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
1153 SourceLocation L,
1154 IdentifierInfo *Id,
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001155 SourceLocation AtLoc,
John McCall83a230c2010-06-04 20:50:08 +00001156 TypeSourceInfo *T,
Chris Lattnerab351632009-02-20 20:59:54 +00001157 PropertyControl propControl) {
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001158 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
Chris Lattnerab351632009-02-20 20:59:54 +00001159}
1160
Chris Lattnerab351632009-02-20 20:59:54 +00001161//===----------------------------------------------------------------------===//
1162// ObjCPropertyImplDecl
1163//===----------------------------------------------------------------------===//
1164
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001165ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
Douglas Gregord0434102009-01-09 00:49:46 +00001166 DeclContext *DC,
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001167 SourceLocation atLoc,
1168 SourceLocation L,
1169 ObjCPropertyDecl *property,
Daniel Dunbar9f0afd42008-08-26 04:47:31 +00001170 Kind PK,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001171 ObjCIvarDecl *ivar,
1172 SourceLocation ivarLoc) {
1173 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
1174 ivarLoc);
Fariborz Jahanian628b96f2008-04-23 00:06:01 +00001175}
Chris Lattnerf4af5152008-03-17 01:19:02 +00001176
Douglas Gregora4ffd852010-11-17 01:03:52 +00001177SourceRange ObjCPropertyImplDecl::getSourceRange() const {
1178 SourceLocation EndLoc = getLocation();
1179 if (IvarLoc.isValid())
1180 EndLoc = IvarLoc;
Chris Lattner0ed844b2008-04-04 06:12:32 +00001181
Douglas Gregora4ffd852010-11-17 01:03:52 +00001182 return SourceRange(AtLoc, EndLoc);
1183}