Bug Summary

File:tools/clang/lib/AST/DeclObjC.cpp
Warning:line 1596, column 11
Called C++ object pointer is null

Annotated Source Code

1//===--- 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"
16#include "clang/AST/ASTMutationListener.h"
17#include "clang/AST/Attr.h"
18#include "clang/AST/Stmt.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/SmallString.h"
21using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// ObjCListBase
25//===----------------------------------------------------------------------===//
26
27void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
28 List = nullptr;
29 if (Elts == 0) return; // Setting to an empty list is a noop.
30
31
32 List = new (Ctx) void*[Elts];
33 NumElts = Elts;
34 memcpy(List, InList, sizeof(void*)*Elts);
35}
36
37void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
38 const SourceLocation *Locs, ASTContext &Ctx) {
39 if (Elts == 0)
40 return;
41
42 Locations = new (Ctx) SourceLocation[Elts];
43 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
44 set(InList, Elts, Ctx);
45}
46
47//===----------------------------------------------------------------------===//
48// ObjCInterfaceDecl
49//===----------------------------------------------------------------------===//
50
51void ObjCContainerDecl::anchor() { }
52
53/// getIvarDecl - This method looks up an ivar in this ContextDecl.
54///
55ObjCIvarDecl *
56ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
57 lookup_result R = lookup(Id);
58 for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end();
59 Ivar != IvarEnd; ++Ivar) {
60 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
61 return ivar;
62 }
63 return nullptr;
64}
65
66// Get the local instance/class method declared in this interface.
67ObjCMethodDecl *
68ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
69 bool AllowHidden) const {
70 // If this context is a hidden protocol definition, don't find any
71 // methods there.
72 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
73 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
74 if (Def->isHidden() && !AllowHidden)
75 return nullptr;
76 }
77
78 // Since instance & class methods can have the same name, the loop below
79 // ensures we get the correct method.
80 //
81 // @interface Whatever
82 // - (int) class_method;
83 // + (float) class_method;
84 // @end
85 //
86 lookup_result R = lookup(Sel);
87 for (lookup_iterator Meth = R.begin(), MethEnd = R.end();
88 Meth != MethEnd; ++Meth) {
89 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
90 if (MD && MD->isInstanceMethod() == isInstance)
91 return MD;
92 }
93 return nullptr;
94}
95
96/// \brief This routine returns 'true' if a user declared setter method was
97/// found in the class, its protocols, its super classes or categories.
98/// It also returns 'true' if one of its categories has declared a 'readwrite'
99/// property. This is because, user must provide a setter method for the
100/// category's 'readwrite' property.
101bool ObjCContainerDecl::HasUserDeclaredSetterMethod(
102 const ObjCPropertyDecl *Property) const {
103 Selector Sel = Property->getSetterName();
104 lookup_result R = lookup(Sel);
105 for (lookup_iterator Meth = R.begin(), MethEnd = R.end();
106 Meth != MethEnd; ++Meth) {
107 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
108 if (MD && MD->isInstanceMethod() && !MD->isImplicit())
109 return true;
110 }
111
112 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(this)) {
113 // Also look into categories, including class extensions, looking
114 // for a user declared instance method.
115 for (const auto *Cat : ID->visible_categories()) {
116 if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel))
117 if (!MD->isImplicit())
118 return true;
119 if (Cat->IsClassExtension())
120 continue;
121 // Also search through the categories looking for a 'readwrite'
122 // declaration of this property. If one found, presumably a setter will
123 // be provided (properties declared in categories will not get
124 // auto-synthesized).
125 for (const auto *P : Cat->properties())
126 if (P->getIdentifier() == Property->getIdentifier()) {
127 if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite)
128 return true;
129 break;
130 }
131 }
132
133 // Also look into protocols, for a user declared instance method.
134 for (const auto *Proto : ID->all_referenced_protocols())
135 if (Proto->HasUserDeclaredSetterMethod(Property))
136 return true;
137
138 // And in its super class.
139 ObjCInterfaceDecl *OSC = ID->getSuperClass();
140 while (OSC) {
141 if (OSC->HasUserDeclaredSetterMethod(Property))
142 return true;
143 OSC = OSC->getSuperClass();
144 }
145 }
146 if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this))
147 for (const auto *PI : PD->protocols())
148 if (PI->HasUserDeclaredSetterMethod(Property))
149 return true;
150 return false;
151}
152
153ObjCPropertyDecl *
154ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
155 const IdentifierInfo *propertyID,
156 ObjCPropertyQueryKind queryKind) {
157 // If this context is a hidden protocol definition, don't find any
158 // property.
159 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) {
160 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
161 if (Def->isHidden())
162 return nullptr;
163 }
164
165 // If context is class, then lookup property in its visible extensions.
166 // This comes before property is looked up in primary class.
167 if (auto *IDecl = dyn_cast<ObjCInterfaceDecl>(DC)) {
168 for (const auto *Ext : IDecl->visible_extensions())
169 if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext,
170 propertyID,
171 queryKind))
172 return PD;
173 }
174
175 DeclContext::lookup_result R = DC->lookup(propertyID);
176 ObjCPropertyDecl *classProp = nullptr;
177 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
178 ++I)
179 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) {
180 // If queryKind is unknown, we return the instance property if one
181 // exists; otherwise we return the class property.
182 if ((queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown &&
183 !PD->isClassProperty()) ||
184 (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_class &&
185 PD->isClassProperty()) ||
186 (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance &&
187 !PD->isClassProperty()))
188 return PD;
189
190 if (PD->isClassProperty())
191 classProp = PD;
192 }
193
194 if (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown)
195 // We can't find the instance property, return the class property.
196 return classProp;
197
198 return nullptr;
199}
200
201IdentifierInfo *
202ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const {
203 SmallString<128> ivarName;
204 {
205 llvm::raw_svector_ostream os(ivarName);
206 os << '_' << getIdentifier()->getName();
207 }
208 return &Ctx.Idents.get(ivarName.str());
209}
210
211/// FindPropertyDeclaration - Finds declaration of the property given its name
212/// in 'PropertyId' and returns it. It returns 0, if not found.
213ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
214 const IdentifierInfo *PropertyId,
215 ObjCPropertyQueryKind QueryKind) const {
216 // Don't find properties within hidden protocol definitions.
217 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
218 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
219 if (Def->isHidden())
220 return nullptr;
221 }
222
223 // Search the extensions of a class first; they override what's in
224 // the class itself.
225 if (const auto *ClassDecl = dyn_cast<ObjCInterfaceDecl>(this)) {
226 for (const auto *Ext : ClassDecl->visible_extensions()) {
227 if (auto *P = Ext->FindPropertyDeclaration(PropertyId, QueryKind))
228 return P;
229 }
230 }
231
232 if (ObjCPropertyDecl *PD =
233 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
234 QueryKind))
235 return PD;
236
237 switch (getKind()) {
238 default:
239 break;
240 case Decl::ObjCProtocol: {
241 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
242 for (const auto *I : PID->protocols())
243 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
244 QueryKind))
245 return P;
246 break;
247 }
248 case Decl::ObjCInterface: {
249 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
250 // Look through categories (but not extensions; they were handled above).
251 for (const auto *Cat : OID->visible_categories()) {
252 if (!Cat->IsClassExtension())
253 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(
254 PropertyId, QueryKind))
255 return P;
256 }
257
258 // Look through protocols.
259 for (const auto *I : OID->all_referenced_protocols())
260 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
261 QueryKind))
262 return P;
263
264 // Finally, check the super class.
265 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
266 return superClass->FindPropertyDeclaration(PropertyId, QueryKind);
267 break;
268 }
269 case Decl::ObjCCategory: {
270 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
271 // Look through protocols.
272 if (!OCD->IsClassExtension())
273 for (const auto *I : OCD->protocols())
274 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
275 QueryKind))
276 return P;
277 break;
278 }
279 }
280 return nullptr;
281}
282
283void ObjCInterfaceDecl::anchor() { }
284
285ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const {
286 // If this particular declaration has a type parameter list, return it.
287 if (ObjCTypeParamList *written = getTypeParamListAsWritten())
288 return written;
289
290 // If there is a definition, return its type parameter list.
291 if (const ObjCInterfaceDecl *def = getDefinition())
292 return def->getTypeParamListAsWritten();
293
294 // Otherwise, look at previous declarations to determine whether any
295 // of them has a type parameter list, skipping over those
296 // declarations that do not.
297 for (auto decl = getMostRecentDecl(); decl; decl = decl->getPreviousDecl()) {
298 if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten())
299 return written;
300 }
301
302 return nullptr;
303}
304
305void ObjCInterfaceDecl::setTypeParamList(ObjCTypeParamList *TPL) {
306 TypeParamList = TPL;
307 if (!TPL)
308 return;
309 // Set the declaration context of each of the type parameters.
310 for (auto typeParam : *TypeParamList)
311 typeParam->setDeclContext(this);
312}
313
314ObjCInterfaceDecl *ObjCInterfaceDecl::getSuperClass() const {
315 // FIXME: Should make sure no callers ever do this.
316 if (!hasDefinition())
317 return nullptr;
318
319 if (data().ExternallyCompleted)
320 LoadExternalDefinition();
321
322 if (const ObjCObjectType *superType = getSuperClassType()) {
323 if (ObjCInterfaceDecl *superDecl = superType->getInterface()) {
324 if (ObjCInterfaceDecl *superDef = superDecl->getDefinition())
325 return superDef;
326
327 return superDecl;
328 }
329 }
330
331 return nullptr;
332}
333
334SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const {
335 if (TypeSourceInfo *superTInfo = getSuperClassTInfo())
336 return superTInfo->getTypeLoc().getLocStart();
337
338 return SourceLocation();
339}
340
341/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
342/// with name 'PropertyId' in the primary class; including those in protocols
343/// (direct or indirect) used by the primary class.
344///
345ObjCPropertyDecl *
346ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
347 IdentifierInfo *PropertyId,
348 ObjCPropertyQueryKind QueryKind) const {
349 // FIXME: Should make sure no callers ever do this.
350 if (!hasDefinition())
351 return nullptr;
352
353 if (data().ExternallyCompleted)
354 LoadExternalDefinition();
355
356 if (ObjCPropertyDecl *PD =
357 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
358 QueryKind))
359 return PD;
360
361 // Look through protocols.
362 for (const auto *I : all_referenced_protocols())
363 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
364 QueryKind))
365 return P;
366
367 return nullptr;
368}
369
370void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM,
371 PropertyDeclOrder &PO) const {
372 for (auto *Prop : properties()) {
373 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
374 PO.push_back(Prop);
375 }
376 for (const auto *Ext : known_extensions()) {
377 const ObjCCategoryDecl *ClassExt = Ext;
378 for (auto *Prop : ClassExt->properties()) {
379 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
380 PO.push_back(Prop);
381 }
382 }
383 for (const auto *PI : all_referenced_protocols())
384 PI->collectPropertiesToImplement(PM, PO);
385 // Note, the properties declared only in class extensions are still copied
386 // into the main @interface's property list, and therefore we don't
387 // explicitly, have to search class extension properties.
388}
389
390bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const {
391 const ObjCInterfaceDecl *Class = this;
392 while (Class) {
393 if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
394 return true;
395 Class = Class->getSuperClass();
396 }
397 return false;
398}
399
400const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const {
401 const ObjCInterfaceDecl *Class = this;
402 while (Class) {
403 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
404 return Class;
405 Class = Class->getSuperClass();
406 }
407 return nullptr;
408}
409
410void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
411 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
412 ASTContext &C)
413{
414 if (data().ExternallyCompleted)
415 LoadExternalDefinition();
416
417 if (data().AllReferencedProtocols.empty() &&
418 data().ReferencedProtocols.empty()) {
419 data().AllReferencedProtocols.set(ExtList, ExtNum, C);
420 return;
421 }
422
423 // Check for duplicate protocol in class's protocol list.
424 // This is O(n*m). But it is extremely rare and number of protocols in
425 // class or its extension are very few.
426 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
427 for (unsigned i = 0; i < ExtNum; i++) {
428 bool protocolExists = false;
429 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
430 for (auto *Proto : all_referenced_protocols()) {
431 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
432 protocolExists = true;
433 break;
434 }
435 }
436 // Do we want to warn on a protocol in extension class which
437 // already exist in the class? Probably not.
438 if (!protocolExists)
439 ProtocolRefs.push_back(ProtoInExtension);
440 }
441
442 if (ProtocolRefs.empty())
443 return;
444
445 // Merge ProtocolRefs into class's protocol list;
446 ProtocolRefs.append(all_referenced_protocol_begin(),
447 all_referenced_protocol_end());
448
449 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C);
450}
451
452const ObjCInterfaceDecl *
453ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const {
454 const ObjCInterfaceDecl *IFace = this;
455 while (IFace) {
456 if (IFace->hasDesignatedInitializers())
457 return IFace;
458 if (!IFace->inheritsDesignatedInitializers())
459 break;
460 IFace = IFace->getSuperClass();
461 }
462 return nullptr;
463}
464
465static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
466 for (const auto *MD : D->instance_methods()) {
467 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
468 return true;
469 }
470 for (const auto *Ext : D->visible_extensions()) {
471 for (const auto *MD : Ext->instance_methods()) {
472 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
473 return true;
474 }
475 }
476 if (const auto *ImplD = D->getImplementation()) {
477 for (const auto *MD : ImplD->instance_methods()) {
478 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
479 return true;
480 }
481 }
482 return false;
483}
484
485bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
486 switch (data().InheritedDesignatedInitializers) {
487 case DefinitionData::IDI_Inherited:
488 return true;
489 case DefinitionData::IDI_NotInherited:
490 return false;
491 case DefinitionData::IDI_Unknown: {
492 // If the class introduced initializers we conservatively assume that we
493 // don't know if any of them is a designated initializer to avoid possible
494 // misleading warnings.
495 if (isIntroducingInitializers(this)) {
496 data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited;
497 } else {
498 if (auto SuperD = getSuperClass()) {
499 data().InheritedDesignatedInitializers =
500 SuperD->declaresOrInheritsDesignatedInitializers() ?
501 DefinitionData::IDI_Inherited :
502 DefinitionData::IDI_NotInherited;
503 } else {
504 data().InheritedDesignatedInitializers =
505 DefinitionData::IDI_NotInherited;
506 }
507 }
508 assert(data().InheritedDesignatedInitializers((data().InheritedDesignatedInitializers != DefinitionData::IDI_Unknown
) ? static_cast<void> (0) : __assert_fail ("data().InheritedDesignatedInitializers != DefinitionData::IDI_Unknown"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 509, __PRETTY_FUNCTION__))
509 != DefinitionData::IDI_Unknown)((data().InheritedDesignatedInitializers != DefinitionData::IDI_Unknown
) ? static_cast<void> (0) : __assert_fail ("data().InheritedDesignatedInitializers != DefinitionData::IDI_Unknown"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 509, __PRETTY_FUNCTION__))
;
510 return data().InheritedDesignatedInitializers ==
511 DefinitionData::IDI_Inherited;
512 }
513 }
514
515 llvm_unreachable("unexpected InheritedDesignatedInitializers value")::llvm::llvm_unreachable_internal("unexpected InheritedDesignatedInitializers value"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 515)
;
516}
517
518void ObjCInterfaceDecl::getDesignatedInitializers(
519 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const {
520 // Check for a complete definition and recover if not so.
521 if (!isThisDeclarationADefinition())
522 return;
523 if (data().ExternallyCompleted)
524 LoadExternalDefinition();
525
526 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
527 if (!IFace)
528 return;
529
530 for (const auto *MD : IFace->instance_methods())
531 if (MD->isThisDeclarationADesignatedInitializer())
532 Methods.push_back(MD);
533 for (const auto *Ext : IFace->visible_extensions()) {
534 for (const auto *MD : Ext->instance_methods())
535 if (MD->isThisDeclarationADesignatedInitializer())
536 Methods.push_back(MD);
537 }
538}
539
540bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel,
541 const ObjCMethodDecl **InitMethod) const {
542 // Check for a complete definition and recover if not so.
543 if (!isThisDeclarationADefinition())
544 return false;
545 if (data().ExternallyCompleted)
546 LoadExternalDefinition();
547
548 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
549 if (!IFace)
550 return false;
551
552 if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) {
553 if (MD->isThisDeclarationADesignatedInitializer()) {
554 if (InitMethod)
555 *InitMethod = MD;
556 return true;
557 }
558 }
559 for (const auto *Ext : IFace->visible_extensions()) {
560 if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) {
561 if (MD->isThisDeclarationADesignatedInitializer()) {
562 if (InitMethod)
563 *InitMethod = MD;
564 return true;
565 }
566 }
567 }
568 return false;
569}
570
571void ObjCInterfaceDecl::allocateDefinitionData() {
572 assert(!hasDefinition() && "ObjC class already has a definition")((!hasDefinition() && "ObjC class already has a definition"
) ? static_cast<void> (0) : __assert_fail ("!hasDefinition() && \"ObjC class already has a definition\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 572, __PRETTY_FUNCTION__))
;
573 Data.setPointer(new (getASTContext()) DefinitionData());
574 Data.getPointer()->Definition = this;
575
576 // Make the type point at the definition, now that we have one.
577 if (TypeForDecl)
578 cast<ObjCInterfaceType>(TypeForDecl)->Decl = this;
579}
580
581void ObjCInterfaceDecl::startDefinition() {
582 allocateDefinitionData();
583
584 // Update all of the declarations with a pointer to the definition.
585 for (auto RD : redecls()) {
586 if (RD != this)
587 RD->Data = Data;
588 }
589}
590
591ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
592 ObjCInterfaceDecl *&clsDeclared) {
593 // FIXME: Should make sure no callers ever do this.
594 if (!hasDefinition())
595 return nullptr;
596
597 if (data().ExternallyCompleted)
598 LoadExternalDefinition();
599
600 ObjCInterfaceDecl* ClassDecl = this;
601 while (ClassDecl != nullptr) {
602 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
603 clsDeclared = ClassDecl;
604 return I;
605 }
606
607 for (const auto *Ext : ClassDecl->visible_extensions()) {
608 if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) {
609 clsDeclared = ClassDecl;
610 return I;
611 }
612 }
613
614 ClassDecl = ClassDecl->getSuperClass();
615 }
616 return nullptr;
617}
618
619/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
620/// class whose name is passed as argument. If it is not one of the super classes
621/// the it returns NULL.
622ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
623 const IdentifierInfo*ICName) {
624 // FIXME: Should make sure no callers ever do this.
625 if (!hasDefinition())
626 return nullptr;
627
628 if (data().ExternallyCompleted)
629 LoadExternalDefinition();
630
631 ObjCInterfaceDecl* ClassDecl = this;
632 while (ClassDecl != nullptr) {
633 if (ClassDecl->getIdentifier() == ICName)
634 return ClassDecl;
635 ClassDecl = ClassDecl->getSuperClass();
636 }
637 return nullptr;
638}
639
640ObjCProtocolDecl *
641ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) {
642 for (auto *P : all_referenced_protocols())
643 if (P->lookupProtocolNamed(Name))
644 return P;
645 ObjCInterfaceDecl *SuperClass = getSuperClass();
646 return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr;
647}
648
649/// lookupMethod - This method returns an instance/class method by looking in
650/// the class, its categories, and its super classes (using a linear search).
651/// When argument category "C" is specified, any implicit method found
652/// in this category is ignored.
653ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
654 bool isInstance,
655 bool shallowCategoryLookup,
656 bool followSuper,
657 const ObjCCategoryDecl *C) const
658{
659 // FIXME: Should make sure no callers ever do this.
660 if (!hasDefinition())
661 return nullptr;
662
663 const ObjCInterfaceDecl* ClassDecl = this;
664 ObjCMethodDecl *MethodDecl = nullptr;
665
666 if (data().ExternallyCompleted)
667 LoadExternalDefinition();
668
669 while (ClassDecl) {
670 // 1. Look through primary class.
671 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
672 return MethodDecl;
673
674 // 2. Didn't find one yet - now look through categories.
675 for (const auto *Cat : ClassDecl->visible_categories())
676 if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
677 if (C != Cat || !MethodDecl->isImplicit())
678 return MethodDecl;
679
680 // 3. Didn't find one yet - look through primary class's protocols.
681 for (const auto *I : ClassDecl->protocols())
682 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
683 return MethodDecl;
684
685 // 4. Didn't find one yet - now look through categories' protocols
686 if (!shallowCategoryLookup)
687 for (const auto *Cat : ClassDecl->visible_categories()) {
688 // Didn't find one yet - look through protocols.
689 const ObjCList<ObjCProtocolDecl> &Protocols =
690 Cat->getReferencedProtocols();
691 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
692 E = Protocols.end(); I != E; ++I)
693 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
694 if (C != Cat || !MethodDecl->isImplicit())
695 return MethodDecl;
696 }
697
698
699 if (!followSuper)
700 return nullptr;
701
702 // 5. Get to the super class (if any).
703 ClassDecl = ClassDecl->getSuperClass();
704 }
705 return nullptr;
706}
707
708// Will search "local" class/category implementations for a method decl.
709// If failed, then we search in class's root for an instance method.
710// Returns 0 if no method is found.
711ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
712 const Selector &Sel,
713 bool Instance) const {
714 // FIXME: Should make sure no callers ever do this.
715 if (!hasDefinition())
716 return nullptr;
717
718 if (data().ExternallyCompleted)
719 LoadExternalDefinition();
720
721 ObjCMethodDecl *Method = nullptr;
722 if (ObjCImplementationDecl *ImpDecl = getImplementation())
723 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
724 : ImpDecl->getClassMethod(Sel);
725
726 // Look through local category implementations associated with the class.
727 if (!Method)
728 Method = getCategoryMethod(Sel, Instance);
729
730 // Before we give up, check if the selector is an instance method.
731 // But only in the root. This matches gcc's behavior and what the
732 // runtime expects.
733 if (!Instance && !Method && !getSuperClass()) {
734 Method = lookupInstanceMethod(Sel);
735 // Look through local category implementations associated
736 // with the root class.
737 if (!Method)
738 Method = lookupPrivateMethod(Sel, true);
739 }
740
741 if (!Method && getSuperClass())
742 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
743 return Method;
744}
745
746//===----------------------------------------------------------------------===//
747// ObjCMethodDecl
748//===----------------------------------------------------------------------===//
749
750ObjCMethodDecl *ObjCMethodDecl::Create(
751 ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
752 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
753 DeclContext *contextDecl, bool isInstance, bool isVariadic,
754 bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined,
755 ImplementationControl impControl, bool HasRelatedResultType) {
756 return new (C, contextDecl) ObjCMethodDecl(
757 beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance,
758 isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined,
759 impControl, HasRelatedResultType);
760}
761
762ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
763 return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
764 Selector(), QualType(), nullptr, nullptr);
765}
766
767bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
768 return getMethodFamily() == OMF_init &&
769 hasAttr<ObjCDesignatedInitializerAttr>();
770}
771
772bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
773 const ObjCMethodDecl **InitMethod) const {
774 if (getMethodFamily() != OMF_init)
775 return false;
776 const DeclContext *DC = getDeclContext();
777 if (isa<ObjCProtocolDecl>(DC))
778 return false;
779 if (const ObjCInterfaceDecl *ID = getClassInterface())
780 return ID->isDesignatedInitializer(getSelector(), InitMethod);
781 return false;
782}
783
784Stmt *ObjCMethodDecl::getBody() const {
785 return Body.get(getASTContext().getExternalSource());
786}
787
788void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
789 assert(PrevMethod)((PrevMethod) ? static_cast<void> (0) : __assert_fail (
"PrevMethod", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 789, __PRETTY_FUNCTION__))
;
790 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
791 IsRedeclaration = true;
792 PrevMethod->HasRedeclaration = true;
793}
794
795void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
796 ArrayRef<ParmVarDecl*> Params,
797 ArrayRef<SourceLocation> SelLocs) {
798 ParamsAndSelLocs = nullptr;
799 NumParams = Params.size();
800 if (Params.empty() && SelLocs.empty())
801 return;
802
803 static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation),
804 "Alignment not sufficient for SourceLocation");
805
806 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
807 sizeof(SourceLocation) * SelLocs.size();
808 ParamsAndSelLocs = C.Allocate(Size);
809 std::copy(Params.begin(), Params.end(), getParams());
810 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
811}
812
813void ObjCMethodDecl::getSelectorLocs(
814 SmallVectorImpl<SourceLocation> &SelLocs) const {
815 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
816 SelLocs.push_back(getSelectorLoc(i));
817}
818
819void ObjCMethodDecl::setMethodParams(ASTContext &C,
820 ArrayRef<ParmVarDecl*> Params,
821 ArrayRef<SourceLocation> SelLocs) {
822 assert((!SelLocs.empty() || isImplicit()) &&(((!SelLocs.empty() || isImplicit()) && "No selector locs for non-implicit method"
) ? static_cast<void> (0) : __assert_fail ("(!SelLocs.empty() || isImplicit()) && \"No selector locs for non-implicit method\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 823, __PRETTY_FUNCTION__))
823 "No selector locs for non-implicit method")(((!SelLocs.empty() || isImplicit()) && "No selector locs for non-implicit method"
) ? static_cast<void> (0) : __assert_fail ("(!SelLocs.empty() || isImplicit()) && \"No selector locs for non-implicit method\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 823, __PRETTY_FUNCTION__))
;
824 if (isImplicit())
825 return setParamsAndSelLocs(C, Params, llvm::None);
826
827 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
828 DeclEndLoc);
829 if (SelLocsKind != SelLoc_NonStandard)
830 return setParamsAndSelLocs(C, Params, llvm::None);
831
832 setParamsAndSelLocs(C, Params, SelLocs);
833}
834
835/// \brief A definition will return its interface declaration.
836/// An interface declaration will return its definition.
837/// Otherwise it will return itself.
838ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
839 ASTContext &Ctx = getASTContext();
840 ObjCMethodDecl *Redecl = nullptr;
841 if (HasRedeclaration)
842 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
843 if (Redecl)
844 return Redecl;
845
846 Decl *CtxD = cast<Decl>(getDeclContext());
847
848 if (!CtxD->isInvalidDecl()) {
849 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
850 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
851 if (!ImplD->isInvalidDecl())
852 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
853
854 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
855 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
856 if (!ImplD->isInvalidDecl())
857 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
858
859 } else if (ObjCImplementationDecl *ImplD =
860 dyn_cast<ObjCImplementationDecl>(CtxD)) {
861 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
862 if (!IFD->isInvalidDecl())
863 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
864
865 } else if (ObjCCategoryImplDecl *CImplD =
866 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
867 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
868 if (!CatD->isInvalidDecl())
869 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
870 }
871 }
872
873 // Ensure that the discovered method redeclaration has a valid declaration
874 // context. Used to prevent infinite loops when iterating redeclarations in
875 // a partially invalid AST.
876 if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl())
877 Redecl = nullptr;
878
879 if (!Redecl && isRedeclaration()) {
880 // This is the last redeclaration, go back to the first method.
881 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
882 isInstanceMethod());
883 }
884
885 return Redecl ? Redecl : this;
886}
887
888ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
889 Decl *CtxD = cast<Decl>(getDeclContext());
890
891 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
892 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
893 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
894 isInstanceMethod()))
895 return MD;
896
897 } else if (ObjCCategoryImplDecl *CImplD =
898 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
899 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
900 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
901 isInstanceMethod()))
902 return MD;
903 }
904
905 if (isRedeclaration()) {
906 // It is possible that we have not done deserializing the ObjCMethod yet.
907 ObjCMethodDecl *MD =
908 cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
909 isInstanceMethod());
910 return MD ? MD : this;
911 }
912
913 return this;
914}
915
916SourceLocation ObjCMethodDecl::getLocEnd() const {
917 if (Stmt *Body = getBody())
918 return Body->getLocEnd();
919 return DeclEndLoc;
920}
921
922ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
923 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
924 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
925 return family;
926
927 // Check for an explicit attribute.
928 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
929 // The unfortunate necessity of mapping between enums here is due
930 // to the attributes framework.
931 switch (attr->getFamily()) {
932 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
933 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
934 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
935 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
936 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
937 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
938 }
939 Family = static_cast<unsigned>(family);
940 return family;
941 }
942
943 family = getSelector().getMethodFamily();
944 switch (family) {
945 case OMF_None: break;
946
947 // init only has a conventional meaning for an instance method, and
948 // it has to return an object.
949 case OMF_init:
950 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
951 family = OMF_None;
952 break;
953
954 // alloc/copy/new have a conventional meaning for both class and
955 // instance methods, but they require an object return.
956 case OMF_alloc:
957 case OMF_copy:
958 case OMF_mutableCopy:
959 case OMF_new:
960 if (!getReturnType()->isObjCObjectPointerType())
961 family = OMF_None;
962 break;
963
964 // These selectors have a conventional meaning only for instance methods.
965 case OMF_dealloc:
966 case OMF_finalize:
967 case OMF_retain:
968 case OMF_release:
969 case OMF_autorelease:
970 case OMF_retainCount:
971 case OMF_self:
972 if (!isInstanceMethod())
973 family = OMF_None;
974 break;
975
976 case OMF_initialize:
977 if (isInstanceMethod() || !getReturnType()->isVoidType())
978 family = OMF_None;
979 break;
980
981 case OMF_performSelector:
982 if (!isInstanceMethod() ||
983 !(getReturnType()->isObjCIdType() || getReturnType()->isVoidType()))
984 family = OMF_None;
985 else {
986 unsigned noParams = param_size();
987 if (noParams < 1 || noParams > 5)
988 family = OMF_None;
989 else {
990 ObjCMethodDecl::param_type_iterator it = param_type_begin();
991 QualType ArgT = (*it);
992 if (!ArgT->isObjCSelType()) {
993 family = OMF_None;
994 break;
995 }
996 // The first type should generally always be 'id' or 'Thread *', the
997 // other types can vary.
998 if (noParams > 1) {
999 ArgT = *(it + 1);
1000 if (!ArgT->isObjCObjectPointerType()) {
1001 family = OMF_None;
1002 break;
1003 }
1004 }
1005 }
1006 }
1007 break;
1008
1009 }
1010
1011 // Cache the result.
1012 Family = static_cast<unsigned>(family);
1013 return family;
1014}
1015
1016QualType ObjCMethodDecl::getSelfType(ASTContext &Context,
1017 const ObjCInterfaceDecl *OID,
1018 bool &selfIsPseudoStrong,
1019 bool &selfIsConsumed) {
1020 QualType selfTy;
1021 selfIsPseudoStrong = false;
1022 selfIsConsumed = false;
1023 if (isInstanceMethod()) {
1024 // There may be no interface context due to error in declaration
1025 // of the interface (which has been reported). Recover gracefully.
1026 if (OID) {
1027 selfTy = Context.getObjCInterfaceType(OID);
1028 selfTy = Context.getObjCObjectPointerType(selfTy);
1029 } else {
1030 selfTy = Context.getObjCIdType();
1031 }
1032 } else // we have a factory method.
1033 selfTy = Context.getObjCClassType();
1034
1035 if (Context.getLangOpts().ObjCAutoRefCount) {
1036 if (isInstanceMethod()) {
1037 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
1038
1039 // 'self' is always __strong. It's actually pseudo-strong except
1040 // in init methods (or methods labeled ns_consumes_self), though.
1041 Qualifiers qs;
1042 qs.setObjCLifetime(Qualifiers::OCL_Strong);
1043 selfTy = Context.getQualifiedType(selfTy, qs);
1044
1045 // In addition, 'self' is const unless this is an init method.
1046 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
1047 selfTy = selfTy.withConst();
1048 selfIsPseudoStrong = true;
1049 }
1050 }
1051 else {
1052 assert(isClassMethod())((isClassMethod()) ? static_cast<void> (0) : __assert_fail
("isClassMethod()", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1052, __PRETTY_FUNCTION__))
;
1053 // 'self' is always const in class methods.
1054 selfTy = selfTy.withConst();
1055 selfIsPseudoStrong = true;
1056 }
1057 }
1058 return selfTy;
1059}
1060
1061void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
1062 const ObjCInterfaceDecl *OID) {
1063 bool selfIsPseudoStrong, selfIsConsumed;
1064 QualType selfTy =
1065 getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed);
1066 ImplicitParamDecl *self
1067 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
1068 &Context.Idents.get("self"), selfTy);
1069 setSelfDecl(self);
1070
1071 if (selfIsConsumed)
1072 self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1073
1074 if (selfIsPseudoStrong)
1075 self->setARCPseudoStrong(true);
1076
1077 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
1078 &Context.Idents.get("_cmd"),
1079 Context.getObjCSelType()));
1080}
1081
1082ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
1083 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
1084 return ID;
1085 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
1086 return CD->getClassInterface();
1087 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
1088 return IMD->getClassInterface();
1089 if (isa<ObjCProtocolDecl>(getDeclContext()))
1090 return nullptr;
1091 llvm_unreachable("unknown method context")::llvm::llvm_unreachable_internal("unknown method context", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1091)
;
1092}
1093
1094SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
1095 const auto *TSI = getReturnTypeSourceInfo();
1096 if (TSI)
1097 return TSI->getTypeLoc().getSourceRange();
1098 return SourceRange();
1099}
1100
1101QualType ObjCMethodDecl::getSendResultType() const {
1102 ASTContext &Ctx = getASTContext();
1103 return getReturnType().getNonLValueExprType(Ctx)
1104 .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
1105}
1106
1107QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const {
1108 // FIXME: Handle related result types here.
1109
1110 return getReturnType().getNonLValueExprType(getASTContext())
1111 .substObjCMemberType(receiverType, getDeclContext(),
1112 ObjCSubstitutionContext::Result);
1113}
1114
1115static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
1116 const ObjCMethodDecl *Method,
1117 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
1118 bool MovedToSuper) {
1119 if (!Container)
1120 return;
1121
1122 // In categories look for overriden methods from protocols. A method from
1123 // category is not "overriden" since it is considered as the "same" method
1124 // (same USR) as the one from the interface.
1125 if (const ObjCCategoryDecl *
1126 Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1127 // Check whether we have a matching method at this category but only if we
1128 // are at the super class level.
1129 if (MovedToSuper)
1130 if (ObjCMethodDecl *
1131 Overridden = Container->getMethod(Method->getSelector(),
1132 Method->isInstanceMethod(),
1133 /*AllowHidden=*/true))
1134 if (Method != Overridden) {
1135 // We found an override at this category; there is no need to look
1136 // into its protocols.
1137 Methods.push_back(Overridden);
1138 return;
1139 }
1140
1141 for (const auto *P : Category->protocols())
1142 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1143 return;
1144 }
1145
1146 // Check whether we have a matching method at this level.
1147 if (const ObjCMethodDecl *
1148 Overridden = Container->getMethod(Method->getSelector(),
1149 Method->isInstanceMethod(),
1150 /*AllowHidden=*/true))
1151 if (Method != Overridden) {
1152 // We found an override at this level; there is no need to look
1153 // into other protocols or categories.
1154 Methods.push_back(Overridden);
1155 return;
1156 }
1157
1158 if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
1159 for (const auto *P : Protocol->protocols())
1160 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1161 }
1162
1163 if (const ObjCInterfaceDecl *
1164 Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
1165 for (const auto *P : Interface->protocols())
1166 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1167
1168 for (const auto *Cat : Interface->known_categories())
1169 CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper);
1170
1171 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1172 return CollectOverriddenMethodsRecurse(Super, Method, Methods,
1173 /*MovedToSuper=*/true);
1174 }
1175}
1176
1177static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
1178 const ObjCMethodDecl *Method,
1179 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
1180 CollectOverriddenMethodsRecurse(Container, Method, Methods,
1181 /*MovedToSuper=*/false);
1182}
1183
1184static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method,
1185 SmallVectorImpl<const ObjCMethodDecl *> &overridden) {
1186 assert(Method->isOverriding())((Method->isOverriding()) ? static_cast<void> (0) : __assert_fail
("Method->isOverriding()", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1186, __PRETTY_FUNCTION__))
;
1187
1188 if (const ObjCProtocolDecl *
1189 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1190 CollectOverriddenMethods(ProtD, Method, overridden);
1191
1192 } else if (const ObjCImplDecl *
1193 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1194 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1195 if (!ID)
1196 return;
1197 // Start searching for overridden methods using the method from the
1198 // interface as starting point.
1199 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1200 Method->isInstanceMethod(),
1201 /*AllowHidden=*/true))
1202 Method = IFaceMeth;
1203 CollectOverriddenMethods(ID, Method, overridden);
1204
1205 } else if (const ObjCCategoryDecl *
1206 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1207 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1208 if (!ID)
1209 return;
1210 // Start searching for overridden methods using the method from the
1211 // interface as starting point.
1212 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1213 Method->isInstanceMethod(),
1214 /*AllowHidden=*/true))
1215 Method = IFaceMeth;
1216 CollectOverriddenMethods(ID, Method, overridden);
1217
1218 } else {
1219 CollectOverriddenMethods(
1220 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1221 Method, overridden);
1222 }
1223}
1224
1225void ObjCMethodDecl::getOverriddenMethods(
1226 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
1227 const ObjCMethodDecl *Method = this;
1228
1229 if (Method->isRedeclaration()) {
1230 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1231 getMethod(Method->getSelector(), Method->isInstanceMethod());
1232 }
1233
1234 if (Method->isOverriding()) {
1235 collectOverriddenMethodsSlow(Method, Overridden);
1236 assert(!Overridden.empty() &&((!Overridden.empty() && "ObjCMethodDecl's overriding bit is not as expected"
) ? static_cast<void> (0) : __assert_fail ("!Overridden.empty() && \"ObjCMethodDecl's overriding bit is not as expected\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1237, __PRETTY_FUNCTION__))
1237 "ObjCMethodDecl's overriding bit is not as expected")((!Overridden.empty() && "ObjCMethodDecl's overriding bit is not as expected"
) ? static_cast<void> (0) : __assert_fail ("!Overridden.empty() && \"ObjCMethodDecl's overriding bit is not as expected\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1237, __PRETTY_FUNCTION__))
;
1238 }
1239}
1240
1241const ObjCPropertyDecl *
1242ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1243 Selector Sel = getSelector();
1244 unsigned NumArgs = Sel.getNumArgs();
1245 if (NumArgs > 1)
1246 return nullptr;
1247
1248 if (isPropertyAccessor()) {
1249 const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
1250 bool IsGetter = (NumArgs == 0);
1251 bool IsInstance = isInstanceMethod();
1252
1253 /// Local function that attempts to find a matching property within the
1254 /// given Objective-C container.
1255 auto findMatchingProperty =
1256 [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {
1257 if (IsInstance) {
1258 for (const auto *I : Container->instance_properties()) {
1259 Selector NextSel = IsGetter ? I->getGetterName()
1260 : I->getSetterName();
1261 if (NextSel == Sel)
1262 return I;
1263 }
1264 } else {
1265 for (const auto *I : Container->class_properties()) {
1266 Selector NextSel = IsGetter ? I->getGetterName()
1267 : I->getSetterName();
1268 if (NextSel == Sel)
1269 return I;
1270 }
1271 }
1272
1273 return nullptr;
1274 };
1275
1276 // Look in the container we were given.
1277 if (const auto *Found = findMatchingProperty(Container))
1278 return Found;
1279
1280 // If we're in a category or extension, look in the main class.
1281 const ObjCInterfaceDecl *ClassDecl = nullptr;
1282 if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1283 ClassDecl = Category->getClassInterface();
1284 if (const auto *Found = findMatchingProperty(ClassDecl))
1285 return Found;
1286 } else {
1287 // Determine whether the container is a class.
1288 ClassDecl = dyn_cast<ObjCInterfaceDecl>(Container);
1289 }
1290
1291 // If we have a class, check its visible extensions.
1292 if (ClassDecl) {
1293 for (const auto *Ext : ClassDecl->visible_extensions()) {
1294 if (Ext == Container)
1295 continue;
1296
1297 if (const auto *Found = findMatchingProperty(Ext))
1298 return Found;
1299 }
1300 }
1301
1302 llvm_unreachable("Marked as a property accessor but no property found!")::llvm::llvm_unreachable_internal("Marked as a property accessor but no property found!"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1302)
;
1303 }
1304
1305 if (!CheckOverrides)
1306 return nullptr;
1307
1308 typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy;
1309 OverridesTy Overrides;
1310 getOverriddenMethods(Overrides);
1311 for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
1312 I != E; ++I) {
1313 if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false))
1314 return Prop;
1315 }
1316
1317 return nullptr;
1318}
1319
1320//===----------------------------------------------------------------------===//
1321// ObjCTypeParamDecl
1322//===----------------------------------------------------------------------===//
1323
1324void ObjCTypeParamDecl::anchor() { }
1325
1326ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc,
1327 ObjCTypeParamVariance variance,
1328 SourceLocation varianceLoc,
1329 unsigned index,
1330 SourceLocation nameLoc,
1331 IdentifierInfo *name,
1332 SourceLocation colonLoc,
1333 TypeSourceInfo *boundInfo) {
1334 auto *TPDecl =
1335 new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
1336 nameLoc, name, colonLoc, boundInfo);
1337 QualType TPType = ctx.getObjCTypeParamType(TPDecl, {});
1338 TPDecl->setTypeForDecl(TPType.getTypePtr());
1339 return TPDecl;
1340}
1341
1342ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext &ctx,
1343 unsigned ID) {
1344 return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr,
1345 ObjCTypeParamVariance::Invariant,
1346 SourceLocation(), 0, SourceLocation(),
1347 nullptr, SourceLocation(), nullptr);
1348}
1349
1350SourceRange ObjCTypeParamDecl::getSourceRange() const {
1351 SourceLocation startLoc = VarianceLoc;
1352 if (startLoc.isInvalid())
1353 startLoc = getLocation();
1354
1355 if (hasExplicitBound()) {
1356 return SourceRange(startLoc,
1357 getTypeSourceInfo()->getTypeLoc().getEndLoc());
1358 }
1359
1360 return SourceRange(startLoc);
1361}
1362
1363//===----------------------------------------------------------------------===//
1364// ObjCTypeParamList
1365//===----------------------------------------------------------------------===//
1366ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
1367 ArrayRef<ObjCTypeParamDecl *> typeParams,
1368 SourceLocation rAngleLoc)
1369 : NumParams(typeParams.size())
1370{
1371 Brackets.Begin = lAngleLoc.getRawEncoding();
1372 Brackets.End = rAngleLoc.getRawEncoding();
1373 std::copy(typeParams.begin(), typeParams.end(), begin());
1374}
1375
1376
1377ObjCTypeParamList *ObjCTypeParamList::create(
1378 ASTContext &ctx,
1379 SourceLocation lAngleLoc,
1380 ArrayRef<ObjCTypeParamDecl *> typeParams,
1381 SourceLocation rAngleLoc) {
1382 void *mem =
1383 ctx.Allocate(totalSizeToAlloc<ObjCTypeParamDecl *>(typeParams.size()),
1384 alignof(ObjCTypeParamList));
1385 return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc);
1386}
1387
1388void ObjCTypeParamList::gatherDefaultTypeArgs(
1389 SmallVectorImpl<QualType> &typeArgs) const {
1390 typeArgs.reserve(size());
1391 for (auto typeParam : *this)
1392 typeArgs.push_back(typeParam->getUnderlyingType());
1393}
1394
1395//===----------------------------------------------------------------------===//
1396// ObjCInterfaceDecl
1397//===----------------------------------------------------------------------===//
1398
1399ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
1400 DeclContext *DC,
1401 SourceLocation atLoc,
1402 IdentifierInfo *Id,
1403 ObjCTypeParamList *typeParamList,
1404 ObjCInterfaceDecl *PrevDecl,
1405 SourceLocation ClassLoc,
1406 bool isInternal){
1407 ObjCInterfaceDecl *Result = new (C, DC)
1408 ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl,
1409 isInternal);
1410 Result->Data.setInt(!C.getLangOpts().Modules);
1411 C.getObjCInterfaceType(Result, PrevDecl);
1412 return Result;
1413}
1414
1415ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C,
1416 unsigned ID) {
1417 ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr,
1418 SourceLocation(),
1419 nullptr,
1420 nullptr,
1421 SourceLocation(),
1422 nullptr, false);
1423 Result->Data.setInt(!C.getLangOpts().Modules);
1424 return Result;
1425}
1426
1427ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
1428 SourceLocation AtLoc, IdentifierInfo *Id,
1429 ObjCTypeParamList *typeParamList,
1430 SourceLocation CLoc,
1431 ObjCInterfaceDecl *PrevDecl,
1432 bool IsInternal)
1433 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
1434 redeclarable_base(C), TypeForDecl(nullptr), TypeParamList(nullptr),
1435 Data() {
1436 setPreviousDecl(PrevDecl);
1437
1438 // Copy the 'data' pointer over.
1439 if (PrevDecl)
1440 Data = PrevDecl->Data;
1441
1442 setImplicit(IsInternal);
1443
1444 setTypeParamList(typeParamList);
1445}
1446
1447void ObjCInterfaceDecl::LoadExternalDefinition() const {
1448 assert(data().ExternallyCompleted && "Class is not externally completed")((data().ExternallyCompleted && "Class is not externally completed"
) ? static_cast<void> (0) : __assert_fail ("data().ExternallyCompleted && \"Class is not externally completed\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1448, __PRETTY_FUNCTION__))
;
1449 data().ExternallyCompleted = false;
1450 getASTContext().getExternalSource()->CompleteType(
1451 const_cast<ObjCInterfaceDecl *>(this));
1452}
1453
1454void ObjCInterfaceDecl::setExternallyCompleted() {
1455 assert(getASTContext().getExternalSource() &&((getASTContext().getExternalSource() && "Class can't be externally completed without an external source"
) ? static_cast<void> (0) : __assert_fail ("getASTContext().getExternalSource() && \"Class can't be externally completed without an external source\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1456, __PRETTY_FUNCTION__))
1456 "Class can't be externally completed without an external source")((getASTContext().getExternalSource() && "Class can't be externally completed without an external source"
) ? static_cast<void> (0) : __assert_fail ("getASTContext().getExternalSource() && \"Class can't be externally completed without an external source\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1456, __PRETTY_FUNCTION__))
;
1457 assert(hasDefinition() &&((hasDefinition() && "Forward declarations can't be externally completed"
) ? static_cast<void> (0) : __assert_fail ("hasDefinition() && \"Forward declarations can't be externally completed\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1458, __PRETTY_FUNCTION__))
1458 "Forward declarations can't be externally completed")((hasDefinition() && "Forward declarations can't be externally completed"
) ? static_cast<void> (0) : __assert_fail ("hasDefinition() && \"Forward declarations can't be externally completed\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1458, __PRETTY_FUNCTION__))
;
1459 data().ExternallyCompleted = true;
1460}
1461
1462void ObjCInterfaceDecl::setHasDesignatedInitializers() {
1463 // Check for a complete definition and recover if not so.
1464 if (!isThisDeclarationADefinition())
1465 return;
1466 data().HasDesignatedInitializers = true;
1467}
1468
1469bool ObjCInterfaceDecl::hasDesignatedInitializers() const {
1470 // Check for a complete definition and recover if not so.
1471 if (!isThisDeclarationADefinition())
1472 return false;
1473 if (data().ExternallyCompleted)
1474 LoadExternalDefinition();
1475
1476 return data().HasDesignatedInitializers;
1477}
1478
1479StringRef
1480ObjCInterfaceDecl::getObjCRuntimeNameAsString() const {
1481 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1482 return ObjCRTName->getMetadataName();
1483
1484 return getName();
1485}
1486
1487StringRef
1488ObjCImplementationDecl::getObjCRuntimeNameAsString() const {
1489 if (ObjCInterfaceDecl *ID =
1490 const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1491 return ID->getObjCRuntimeNameAsString();
1492
1493 return getName();
1494}
1495
1496ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
1497 if (const ObjCInterfaceDecl *Def = getDefinition()) {
1498 if (data().ExternallyCompleted)
1499 LoadExternalDefinition();
1500
1501 return getASTContext().getObjCImplementation(
1502 const_cast<ObjCInterfaceDecl*>(Def));
1503 }
1504
1505 // FIXME: Should make sure no callers ever do this.
1506 return nullptr;
1507}
1508
1509void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
1510 getASTContext().setObjCImplementation(getDefinition(), ImplD);
1511}
1512
1513namespace {
1514 struct SynthesizeIvarChunk {
1515 uint64_t Size;
1516 ObjCIvarDecl *Ivar;
1517 SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
1518 : Size(size), Ivar(ivar) {}
1519 };
1520
1521 bool operator<(const SynthesizeIvarChunk & LHS,
1522 const SynthesizeIvarChunk &RHS) {
1523 return LHS.Size < RHS.Size;
1524 }
1525}
1526
1527/// all_declared_ivar_begin - return first ivar declared in this class,
1528/// its extensions and its implementation. Lazily build the list on first
1529/// access.
1530///
1531/// Caveat: The list returned by this method reflects the current
1532/// state of the parser. The cache will be updated for every ivar
1533/// added by an extension or the implementation when they are
1534/// encountered.
1535/// See also ObjCIvarDecl::Create().
1536ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
1537 // FIXME: Should make sure no callers ever do this.
1538 if (!hasDefinition())
1
Assuming the condition is false
2
Taking false branch
1539 return nullptr;
1540
1541 ObjCIvarDecl *curIvar = nullptr;
3
'curIvar' initialized to a null pointer value
1542 if (!data().IvarList) {
4
Assuming the condition is false
5
Taking false branch
1543 if (!ivar_empty()) {
1544 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
1545 data().IvarList = *I; ++I;
1546 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1547 curIvar->setNextIvar(*I);
1548 }
1549
1550 for (const auto *Ext : known_extensions()) {
1551 if (!Ext->ivar_empty()) {
1552 ObjCCategoryDecl::ivar_iterator
1553 I = Ext->ivar_begin(),
1554 E = Ext->ivar_end();
1555 if (!data().IvarList) {
1556 data().IvarList = *I; ++I;
1557 curIvar = data().IvarList;
1558 }
1559 for ( ;I != E; curIvar = *I, ++I)
1560 curIvar->setNextIvar(*I);
1561 }
1562 }
1563 data().IvarListMissingImplementation = true;
1564 }
1565
1566 // cached and complete!
1567 if (!data().IvarListMissingImplementation)
6
Assuming the condition is false
7
Taking false branch
1568 return data().IvarList;
1569
1570 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
8
Assuming 'ImplDecl' is non-null
9
Taking true branch
1571 data().IvarListMissingImplementation = false;
1572 if (!ImplDecl->ivar_empty()) {
10
Taking true branch
1573 SmallVector<SynthesizeIvarChunk, 16> layout;
1574 for (auto *IV : ImplDecl->ivars()) {
1575 if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1576 layout.push_back(SynthesizeIvarChunk(
1577 IV->getASTContext().getTypeSize(IV->getType()), IV));
1578 continue;
1579 }
1580 if (!data().IvarList)
1581 data().IvarList = IV;
1582 else
1583 curIvar->setNextIvar(IV);
1584 curIvar = IV;
1585 }
1586
1587 if (!layout.empty()) {
11
Taking true branch
1588 // Order synthesized ivars by their size.
1589 std::stable_sort(layout.begin(), layout.end());
1590 unsigned Ix = 0, EIx = layout.size();
1591 if (!data().IvarList) {
12
Assuming the condition is false
13
Taking false branch
1592 data().IvarList = layout[0].Ivar; Ix++;
1593 curIvar = data().IvarList;
1594 }
1595 for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
14
Assuming 'Ix' is not equal to 'EIx'
15
Loop condition is true. Entering loop body
1596 curIvar->setNextIvar(layout[Ix].Ivar);
16
Called C++ object pointer is null
1597 }
1598 }
1599 }
1600 return data().IvarList;
1601}
1602
1603/// FindCategoryDeclaration - Finds category declaration in the list of
1604/// categories for this class and returns it. Name of the category is passed
1605/// in 'CategoryId'. If category not found, return 0;
1606///
1607ObjCCategoryDecl *
1608ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
1609 // FIXME: Should make sure no callers ever do this.
1610 if (!hasDefinition())
1611 return nullptr;
1612
1613 if (data().ExternallyCompleted)
1614 LoadExternalDefinition();
1615
1616 for (auto *Cat : visible_categories())
1617 if (Cat->getIdentifier() == CategoryId)
1618 return Cat;
1619
1620 return nullptr;
1621}
1622
1623ObjCMethodDecl *
1624ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
1625 for (const auto *Cat : visible_categories()) {
1626 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1627 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1628 return MD;
1629 }
1630
1631 return nullptr;
1632}
1633
1634ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
1635 for (const auto *Cat : visible_categories()) {
1636 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1637 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1638 return MD;
1639 }
1640
1641 return nullptr;
1642}
1643
1644/// ClassImplementsProtocol - Checks that 'lProto' protocol
1645/// has been implemented in IDecl class, its super class or categories (if
1646/// lookupCategory is true).
1647bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1648 bool lookupCategory,
1649 bool RHSIsQualifiedID) {
1650 if (!hasDefinition())
1651 return false;
1652
1653 ObjCInterfaceDecl *IDecl = this;
1654 // 1st, look up the class.
1655 for (auto *PI : IDecl->protocols()){
1656 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1657 return true;
1658 // This is dubious and is added to be compatible with gcc. In gcc, it is
1659 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1660 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1661 // object. This IMO, should be a bug.
1662 // FIXME: Treat this as an extension, and flag this as an error when GCC
1663 // extensions are not enabled.
1664 if (RHSIsQualifiedID &&
1665 getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
1666 return true;
1667 }
1668
1669 // 2nd, look up the category.
1670 if (lookupCategory)
1671 for (const auto *Cat : visible_categories()) {
1672 for (auto *PI : Cat->protocols())
1673 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1674 return true;
1675 }
1676
1677 // 3rd, look up the super class(s)
1678 if (IDecl->getSuperClass())
1679 return
1680 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1681 RHSIsQualifiedID);
1682
1683 return false;
1684}
1685
1686//===----------------------------------------------------------------------===//
1687// ObjCIvarDecl
1688//===----------------------------------------------------------------------===//
1689
1690void ObjCIvarDecl::anchor() { }
1691
1692ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
1693 SourceLocation StartLoc,
1694 SourceLocation IdLoc, IdentifierInfo *Id,
1695 QualType T, TypeSourceInfo *TInfo,
1696 AccessControl ac, Expr *BW,
1697 bool synthesized) {
1698 if (DC) {
1699 // Ivar's can only appear in interfaces, implementations (via synthesized
1700 // properties), and class extensions (via direct declaration, or synthesized
1701 // properties).
1702 //
1703 // FIXME: This should really be asserting this:
1704 // (isa<ObjCCategoryDecl>(DC) &&
1705 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1706 // but unfortunately we sometimes place ivars into non-class extension
1707 // categories on error. This breaks an AST invariant, and should not be
1708 // fixed.
1709 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||(((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl
>(DC) || isa<ObjCCategoryDecl>(DC)) && "Invalid ivar decl context!"
) ? static_cast<void> (0) : __assert_fail ("(isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || isa<ObjCCategoryDecl>(DC)) && \"Invalid ivar decl context!\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1711, __PRETTY_FUNCTION__))
1710 isa<ObjCCategoryDecl>(DC)) &&(((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl
>(DC) || isa<ObjCCategoryDecl>(DC)) && "Invalid ivar decl context!"
) ? static_cast<void> (0) : __assert_fail ("(isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || isa<ObjCCategoryDecl>(DC)) && \"Invalid ivar decl context!\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1711, __PRETTY_FUNCTION__))
1711 "Invalid ivar decl context!")(((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl
>(DC) || isa<ObjCCategoryDecl>(DC)) && "Invalid ivar decl context!"
) ? static_cast<void> (0) : __assert_fail ("(isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || isa<ObjCCategoryDecl>(DC)) && \"Invalid ivar decl context!\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1711, __PRETTY_FUNCTION__))
;
1712 // Once a new ivar is created in any of class/class-extension/implementation
1713 // decl contexts, the previously built IvarList must be rebuilt.
1714 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1715 if (!ID) {
1716 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
1717 ID = IM->getClassInterface();
1718 else
1719 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1720 }
1721 ID->setIvarList(nullptr);
1722 }
1723
1724 return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
1725 synthesized);
1726}
1727
1728ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1729 return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(),
1730 nullptr, QualType(), nullptr,
1731 ObjCIvarDecl::None, nullptr, false);
1732}
1733
1734const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
1735 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
1736
1737 switch (DC->getKind()) {
1738 default:
1739 case ObjCCategoryImpl:
1740 case ObjCProtocol:
1741 llvm_unreachable("invalid ivar container!")::llvm::llvm_unreachable_internal("invalid ivar container!", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1741)
;
1742
1743 // Ivars can only appear in class extension categories.
1744 case ObjCCategory: {
1745 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
1746 assert(CD->IsClassExtension() && "invalid container for ivar!")((CD->IsClassExtension() && "invalid container for ivar!"
) ? static_cast<void> (0) : __assert_fail ("CD->IsClassExtension() && \"invalid container for ivar!\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1746, __PRETTY_FUNCTION__))
;
1747 return CD->getClassInterface();
1748 }
1749
1750 case ObjCImplementation:
1751 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1752
1753 case ObjCInterface:
1754 return cast<ObjCInterfaceDecl>(DC);
1755 }
1756}
1757
1758QualType ObjCIvarDecl::getUsageType(QualType objectType) const {
1759 return getType().substObjCMemberType(objectType, getDeclContext(),
1760 ObjCSubstitutionContext::Property);
1761}
1762
1763//===----------------------------------------------------------------------===//
1764// ObjCAtDefsFieldDecl
1765//===----------------------------------------------------------------------===//
1766
1767void ObjCAtDefsFieldDecl::anchor() { }
1768
1769ObjCAtDefsFieldDecl
1770*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
1771 SourceLocation StartLoc, SourceLocation IdLoc,
1772 IdentifierInfo *Id, QualType T, Expr *BW) {
1773 return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
1774}
1775
1776ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
1777 unsigned ID) {
1778 return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(),
1779 SourceLocation(), nullptr, QualType(),
1780 nullptr);
1781}
1782
1783//===----------------------------------------------------------------------===//
1784// ObjCProtocolDecl
1785//===----------------------------------------------------------------------===//
1786
1787void ObjCProtocolDecl::anchor() { }
1788
1789ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
1790 IdentifierInfo *Id, SourceLocation nameLoc,
1791 SourceLocation atStartLoc,
1792 ObjCProtocolDecl *PrevDecl)
1793 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
1794 redeclarable_base(C), Data() {
1795 setPreviousDecl(PrevDecl);
1796 if (PrevDecl)
1797 Data = PrevDecl->Data;
1798}
1799
1800ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
1801 IdentifierInfo *Id,
1802 SourceLocation nameLoc,
1803 SourceLocation atStartLoc,
1804 ObjCProtocolDecl *PrevDecl) {
1805 ObjCProtocolDecl *Result =
1806 new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl);
1807 Result->Data.setInt(!C.getLangOpts().Modules);
1808 return Result;
1809}
1810
1811ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
1812 unsigned ID) {
1813 ObjCProtocolDecl *Result =
1814 new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(),
1815 SourceLocation(), nullptr);
1816 Result->Data.setInt(!C.getLangOpts().Modules);
1817 return Result;
1818}
1819
1820ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
1821 ObjCProtocolDecl *PDecl = this;
1822
1823 if (Name == getIdentifier())
1824 return PDecl;
1825
1826 for (auto *I : protocols())
1827 if ((PDecl = I->lookupProtocolNamed(Name)))
1828 return PDecl;
1829
1830 return nullptr;
1831}
1832
1833// lookupMethod - Lookup a instance/class method in the protocol and protocols
1834// it inherited.
1835ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
1836 bool isInstance) const {
1837 ObjCMethodDecl *MethodDecl = nullptr;
1838
1839 // If there is no definition or the definition is hidden, we don't find
1840 // anything.
1841 const ObjCProtocolDecl *Def = getDefinition();
1842 if (!Def || Def->isHidden())
1843 return nullptr;
1844
1845 if ((MethodDecl = getMethod(Sel, isInstance)))
1846 return MethodDecl;
1847
1848 for (const auto *I : protocols())
1849 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
1850 return MethodDecl;
1851 return nullptr;
1852}
1853
1854void ObjCProtocolDecl::allocateDefinitionData() {
1855 assert(!Data.getPointer() && "Protocol already has a definition!")((!Data.getPointer() && "Protocol already has a definition!"
) ? static_cast<void> (0) : __assert_fail ("!Data.getPointer() && \"Protocol already has a definition!\""
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn298304/tools/clang/lib/AST/DeclObjC.cpp"
, 1855, __PRETTY_FUNCTION__))
;
1856 Data.setPointer(new (getASTContext()) DefinitionData);
1857 Data.getPointer()->Definition = this;
1858}
1859
1860void ObjCProtocolDecl::startDefinition() {
1861 allocateDefinitionData();
1862
1863 // Update all of the declarations with a pointer to the definition.
1864 for (auto RD : redecls())
1865 RD->Data = this->Data;
1866}
1867
1868void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
1869 PropertyDeclOrder &PO) const {
1870
1871 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1872 for (auto *Prop : PDecl->properties()) {
1873 // Insert into PM if not there already.
1874 PM.insert(std::make_pair(
1875 std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()),
1876 Prop));
1877 PO.push_back(Prop);
1878 }
1879 // Scan through protocol's protocols.
1880 for (const auto *PI : PDecl->protocols())
1881 PI->collectPropertiesToImplement(PM, PO);
1882 }
1883}
1884
1885
1886void ObjCProtocolDecl::collectInheritedProtocolProperties(
1887 const ObjCPropertyDecl *Property,
1888 ProtocolPropertyMap &PM) const {
1889 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1890 bool MatchFound = false;
1891 for (auto *Prop : PDecl->properties()) {
1892 if (Prop == Property)
1893 continue;
1894 if (Prop->getIdentifier() == Property->getIdentifier()) {
1895 PM[PDecl] = Prop;
1896 MatchFound = true;
1897 break;
1898 }
1899 }
1900 // Scan through protocol's protocols which did not have a matching property.
1901 if (!MatchFound)
1902 for (const auto *PI : PDecl->protocols())
1903 PI->collectInheritedProtocolProperties(Property, PM);
1904 }
1905}
1906
1907StringRef
1908ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
1909 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1910 return ObjCRTName->getMetadataName();
1911
1912 return getName();
1913}
1914
1915//===----------------------------------------------------------------------===//
1916// ObjCCategoryDecl
1917//===----------------------------------------------------------------------===//
1918
1919void ObjCCategoryDecl::anchor() { }
1920
1921ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1922 SourceLocation ClassNameLoc,
1923 SourceLocation CategoryNameLoc,
1924 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1925 ObjCTypeParamList *typeParamList,
1926 SourceLocation IvarLBraceLoc,
1927 SourceLocation IvarRBraceLoc)
1928 : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1929 ClassInterface(IDecl), TypeParamList(nullptr),
1930 NextClassCategory(nullptr), CategoryNameLoc(CategoryNameLoc),
1931 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc)
1932{
1933 setTypeParamList(typeParamList);
1934}
1935
1936ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
1937 SourceLocation AtLoc,
1938 SourceLocation ClassNameLoc,
1939 SourceLocation CategoryNameLoc,
1940 IdentifierInfo *Id,
1941 ObjCInterfaceDecl *IDecl,
1942 ObjCTypeParamList *typeParamList,
1943 SourceLocation IvarLBraceLoc,
1944 SourceLocation IvarRBraceLoc) {
1945 ObjCCategoryDecl *CatDecl =
1946 new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
1947 IDecl, typeParamList, IvarLBraceLoc,
1948 IvarRBraceLoc);
1949 if (IDecl) {
1950 // Link this category into its class's category list.
1951 CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
1952 if (IDecl->hasDefinition()) {
1953 IDecl->setCategoryListRaw(CatDecl);
1954 if (ASTMutationListener *L = C.getASTMutationListener())
1955 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
1956 }
1957 }
1958
1959 return CatDecl;
1960}
1961
1962ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
1963 unsigned ID) {
1964 return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(),
1965 SourceLocation(), SourceLocation(),
1966 nullptr, nullptr, nullptr);
1967}
1968
1969ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1970 return getASTContext().getObjCImplementation(
1971 const_cast<ObjCCategoryDecl*>(this));
1972}
1973
1974void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1975 getASTContext().setObjCImplementation(this, ImplD);
1976}
1977
1978void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) {
1979 TypeParamList = TPL;
1980 if (!TPL)
1981 return;
1982 // Set the declaration context of each of the type parameters.
1983 for (auto typeParam : *TypeParamList)
1984 typeParam->setDeclContext(this);
1985}
1986
1987
1988//===----------------------------------------------------------------------===//
1989// ObjCCategoryImplDecl
1990//===----------------------------------------------------------------------===//
1991
1992void ObjCCategoryImplDecl::anchor() { }
1993
1994ObjCCategoryImplDecl *
1995ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
1996 IdentifierInfo *Id,
1997 ObjCInterfaceDecl *ClassInterface,
1998 SourceLocation nameLoc,
1999 SourceLocation atStartLoc,
2000 SourceLocation CategoryNameLoc) {
2001 if (ClassInterface && ClassInterface->hasDefinition())
2002 ClassInterface = ClassInterface->getDefinition();
2003 return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
2004 atStartLoc, CategoryNameLoc);
2005}
2006
2007ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C,
2008 unsigned ID) {
2009 return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr,
2010 SourceLocation(), SourceLocation(),
2011 SourceLocation());
2012}
2013
2014ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
2015 // The class interface might be NULL if we are working with invalid code.
2016 if (const ObjCInterfaceDecl *ID = getClassInterface())
2017 return ID->FindCategoryDeclaration(getIdentifier());
2018 return nullptr;
2019}
2020
2021
2022void ObjCImplDecl::anchor() { }
2023
2024void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
2025 // FIXME: The context should be correct before we get here.
2026 property->setLexicalDeclContext(this);
2027 addDecl(property);
2028}
2029
2030void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
2031 ASTContext &Ctx = getASTContext();
2032
2033 if (ObjCImplementationDecl *ImplD
2034 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
2035 if (IFace)
2036 Ctx.setObjCImplementation(IFace, ImplD);
2037
2038 } else if (ObjCCategoryImplDecl *ImplD =
2039 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
2040 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
2041 Ctx.setObjCImplementation(CD, ImplD);
2042 }
2043
2044 ClassInterface = IFace;
2045}
2046
2047/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
2048/// properties implemented in this \@implementation block and returns
2049/// the implemented property that uses it.
2050///
2051ObjCPropertyImplDecl *ObjCImplDecl::
2052FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
2053 for (auto *PID : property_impls())
2054 if (PID->getPropertyIvarDecl() &&
2055 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
2056 return PID;
2057 return nullptr;
2058}
2059
2060/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
2061/// added to the list of those properties \@synthesized/\@dynamic in this
2062/// category \@implementation block.
2063///
2064ObjCPropertyImplDecl *ObjCImplDecl::
2065FindPropertyImplDecl(IdentifierInfo *Id,
2066 ObjCPropertyQueryKind QueryKind) const {
2067 ObjCPropertyImplDecl *ClassPropImpl = nullptr;
2068 for (auto *PID : property_impls())
2069 // If queryKind is unknown, we return the instance property if one
2070 // exists; otherwise we return the class property.
2071 if (PID->getPropertyDecl()->getIdentifier() == Id) {
2072 if ((QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown &&
2073 !PID->getPropertyDecl()->isClassProperty()) ||
2074 (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_class &&
2075 PID->getPropertyDecl()->isClassProperty()) ||
2076 (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance &&
2077 !PID->getPropertyDecl()->isClassProperty()))
2078 return PID;
2079
2080 if (PID->getPropertyDecl()->isClassProperty())
2081 ClassPropImpl = PID;
2082 }
2083
2084 if (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown)
2085 // We can't find the instance property, return the class property.
2086 return ClassPropImpl;
2087
2088 return nullptr;
2089}
2090
2091raw_ostream &clang::operator<<(raw_ostream &OS,
2092 const ObjCCategoryImplDecl &CID) {
2093 OS << CID.getName();
2094 return OS;
2095}
2096
2097//===----------------------------------------------------------------------===//
2098// ObjCImplementationDecl
2099//===----------------------------------------------------------------------===//
2100
2101void ObjCImplementationDecl::anchor() { }
2102
2103ObjCImplementationDecl *
2104ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
2105 ObjCInterfaceDecl *ClassInterface,
2106 ObjCInterfaceDecl *SuperDecl,
2107 SourceLocation nameLoc,
2108 SourceLocation atStartLoc,
2109 SourceLocation superLoc,
2110 SourceLocation IvarLBraceLoc,
2111 SourceLocation IvarRBraceLoc) {
2112 if (ClassInterface && ClassInterface->hasDefinition())
2113 ClassInterface = ClassInterface->getDefinition();
2114 return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
2115 nameLoc, atStartLoc, superLoc,
2116 IvarLBraceLoc, IvarRBraceLoc);
2117}
2118
2119ObjCImplementationDecl *
2120ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2121 return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr,
2122 SourceLocation(), SourceLocation());
2123}
2124
2125void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
2126 CXXCtorInitializer ** initializers,
2127 unsigned numInitializers) {
2128 if (numInitializers > 0) {
2129 NumIvarInitializers = numInitializers;
2130 CXXCtorInitializer **ivarInitializers =
2131 new (C) CXXCtorInitializer*[NumIvarInitializers];
2132 memcpy(ivarInitializers, initializers,
2133 numInitializers * sizeof(CXXCtorInitializer*));
2134 IvarInitializers = ivarInitializers;
2135 }
2136}
2137
2138ObjCImplementationDecl::init_const_iterator
2139ObjCImplementationDecl::init_begin() const {
2140 return IvarInitializers.get(getASTContext().getExternalSource());
2141}
2142
2143raw_ostream &clang::operator<<(raw_ostream &OS,
2144 const ObjCImplementationDecl &ID) {
2145 OS << ID.getName();
2146 return OS;
2147}
2148
2149//===----------------------------------------------------------------------===//
2150// ObjCCompatibleAliasDecl
2151//===----------------------------------------------------------------------===//
2152
2153void ObjCCompatibleAliasDecl::anchor() { }
2154
2155ObjCCompatibleAliasDecl *
2156ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
2157 SourceLocation L,
2158 IdentifierInfo *Id,
2159 ObjCInterfaceDecl* AliasedClass) {
2160 return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
2161}
2162
2163ObjCCompatibleAliasDecl *
2164ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2165 return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(),
2166 nullptr, nullptr);
2167}
2168
2169//===----------------------------------------------------------------------===//
2170// ObjCPropertyDecl
2171//===----------------------------------------------------------------------===//
2172
2173void ObjCPropertyDecl::anchor() { }
2174
2175ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
2176 SourceLocation L,
2177 IdentifierInfo *Id,
2178 SourceLocation AtLoc,
2179 SourceLocation LParenLoc,
2180 QualType T,
2181 TypeSourceInfo *TSI,
2182 PropertyControl propControl) {
2183 return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI,
2184 propControl);
2185}
2186
2187ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
2188 unsigned ID) {
2189 return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr,
2190 SourceLocation(), SourceLocation(),
2191 QualType(), nullptr, None);
2192}
2193
2194QualType ObjCPropertyDecl::getUsageType(QualType objectType) const {
2195 return DeclType.substObjCMemberType(objectType, getDeclContext(),
2196 ObjCSubstitutionContext::Property);
2197}
2198
2199//===----------------------------------------------------------------------===//
2200// ObjCPropertyImplDecl
2201//===----------------------------------------------------------------------===//
2202
2203ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
2204 DeclContext *DC,
2205 SourceLocation atLoc,
2206 SourceLocation L,
2207 ObjCPropertyDecl *property,
2208 Kind PK,
2209 ObjCIvarDecl *ivar,
2210 SourceLocation ivarLoc) {
2211 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
2212 ivarLoc);
2213}
2214
2215ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
2216 unsigned ID) {
2217 return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(),
2218 SourceLocation(), nullptr, Dynamic,
2219 nullptr, SourceLocation());
2220}
2221
2222SourceRange ObjCPropertyImplDecl::getSourceRange() const {
2223 SourceLocation EndLoc = getLocation();
2224 if (IvarLoc.isValid())
2225 EndLoc = IvarLoc;
2226
2227 return SourceRange(AtLoc, EndLoc);
2228}