1 //===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Objective-C related Decl classes.
12 //===----------------------------------------------------------------------===//
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"
21 using namespace clang;
23 //===----------------------------------------------------------------------===//
25 //===----------------------------------------------------------------------===//
27 void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
29 if (Elts == 0) return; // Setting to an empty list is a noop.
32 List = new (Ctx) void*[Elts];
34 memcpy(List, InList, sizeof(void*)*Elts);
37 void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
38 const SourceLocation *Locs, ASTContext &Ctx) {
42 Locations = new (Ctx) SourceLocation[Elts];
43 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
44 set(InList, Elts, Ctx);
47 //===----------------------------------------------------------------------===//
49 //===----------------------------------------------------------------------===//
51 void ObjCContainerDecl::anchor() { }
53 /// getIvarDecl - This method looks up an ivar in this ContextDecl.
56 ObjCContainerDecl::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))
66 // Get the local instance/class method declared in this interface.
68 ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
69 bool AllowHidden) const {
70 // If this context is a hidden protocol definition, don't find any
72 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
73 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
74 if (Def->isHidden() && !AllowHidden)
78 // Since instance & class methods can have the same name, the loop below
79 // ensures we get the correct method.
81 // @interface Whatever
82 // - (int) class_method;
83 // + (float) class_method;
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)
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.
101 bool 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())
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())
119 if (Cat->IsClassExtension())
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)
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))
138 // And in its super class.
139 ObjCInterfaceDecl *OSC = ID->getSuperClass();
141 if (OSC->HasUserDeclaredSetterMethod(Property))
143 OSC = OSC->getSuperClass();
146 if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this))
147 for (const auto *PI : PD->protocols())
148 if (PI->HasUserDeclaredSetterMethod(Property))
154 ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
155 const IdentifierInfo *propertyID) {
156 // If this context is a hidden protocol definition, don't find any
158 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) {
159 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
164 DeclContext::lookup_result R = DC->lookup(propertyID);
165 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
167 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
174 ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const {
175 SmallString<128> ivarName;
177 llvm::raw_svector_ostream os(ivarName);
178 os << '_' << getIdentifier()->getName();
180 return &Ctx.Idents.get(ivarName.str());
183 /// FindPropertyDeclaration - Finds declaration of the property given its name
184 /// in 'PropertyId' and returns it. It returns 0, if not found.
185 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
186 const IdentifierInfo *PropertyId) const {
187 // Don't find properties within hidden protocol definitions.
188 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
189 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
194 if (ObjCPropertyDecl *PD =
195 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
201 case Decl::ObjCProtocol: {
202 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
203 for (const auto *I : PID->protocols())
204 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
208 case Decl::ObjCInterface: {
209 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
210 // Look through categories (but not extensions).
211 for (const auto *Cat : OID->visible_categories()) {
212 if (!Cat->IsClassExtension())
213 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
217 // Look through protocols.
218 for (const auto *I : OID->all_referenced_protocols())
219 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
222 // Finally, check the super class.
223 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
224 return superClass->FindPropertyDeclaration(PropertyId);
227 case Decl::ObjCCategory: {
228 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
229 // Look through protocols.
230 if (!OCD->IsClassExtension())
231 for (const auto *I : OCD->protocols())
232 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
240 void ObjCInterfaceDecl::anchor() { }
242 ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const {
243 // If this particular declaration has a type parameter list, return it.
244 if (ObjCTypeParamList *written = getTypeParamListAsWritten())
247 // If there is a definition, return its type parameter list.
248 if (const ObjCInterfaceDecl *def = getDefinition())
249 return def->getTypeParamListAsWritten();
251 // Otherwise, look at previous declarations to determine whether any
252 // of them has a type parameter list, skipping over those
253 // declarations that do not.
254 for (auto decl = getMostRecentDecl(); decl; decl = decl->getPreviousDecl()) {
255 if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten())
262 void ObjCInterfaceDecl::setTypeParamList(ObjCTypeParamList *TPL) {
266 // Set the declaration context of each of the type parameters.
267 for (auto typeParam : *TypeParamList)
268 typeParam->setDeclContext(this);
271 ObjCInterfaceDecl *ObjCInterfaceDecl::getSuperClass() const {
272 // FIXME: Should make sure no callers ever do this.
273 if (!hasDefinition())
276 if (data().ExternallyCompleted)
277 LoadExternalDefinition();
279 if (const ObjCObjectType *superType = getSuperClassType()) {
280 if (ObjCInterfaceDecl *superDecl = superType->getInterface()) {
281 if (ObjCInterfaceDecl *superDef = superDecl->getDefinition())
291 SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const {
292 if (TypeSourceInfo *superTInfo = getSuperClassTInfo())
293 return superTInfo->getTypeLoc().getLocStart();
295 return SourceLocation();
298 /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
299 /// with name 'PropertyId' in the primary class; including those in protocols
300 /// (direct or indirect) used by the primary class.
303 ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
304 IdentifierInfo *PropertyId) const {
305 // FIXME: Should make sure no callers ever do this.
306 if (!hasDefinition())
309 if (data().ExternallyCompleted)
310 LoadExternalDefinition();
312 if (ObjCPropertyDecl *PD =
313 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
316 // Look through protocols.
317 for (const auto *I : all_referenced_protocols())
318 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
324 void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM,
325 PropertyDeclOrder &PO) const {
326 for (auto *Prop : properties()) {
327 PM[Prop->getIdentifier()] = Prop;
330 for (const auto *PI : all_referenced_protocols())
331 PI->collectPropertiesToImplement(PM, PO);
332 // Note, the properties declared only in class extensions are still copied
333 // into the main @interface's property list, and therefore we don't
334 // explicitly, have to search class extension properties.
337 bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const {
338 const ObjCInterfaceDecl *Class = this;
340 if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
342 Class = Class->getSuperClass();
347 const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const {
348 const ObjCInterfaceDecl *Class = this;
350 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
352 Class = Class->getSuperClass();
357 void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
358 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
361 if (data().ExternallyCompleted)
362 LoadExternalDefinition();
364 if (data().AllReferencedProtocols.empty() &&
365 data().ReferencedProtocols.empty()) {
366 data().AllReferencedProtocols.set(ExtList, ExtNum, C);
370 // Check for duplicate protocol in class's protocol list.
371 // This is O(n*m). But it is extremely rare and number of protocols in
372 // class or its extension are very few.
373 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
374 for (unsigned i = 0; i < ExtNum; i++) {
375 bool protocolExists = false;
376 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
377 for (auto *Proto : all_referenced_protocols()) {
378 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
379 protocolExists = true;
383 // Do we want to warn on a protocol in extension class which
384 // already exist in the class? Probably not.
386 ProtocolRefs.push_back(ProtoInExtension);
389 if (ProtocolRefs.empty())
392 // Merge ProtocolRefs into class's protocol list;
393 ProtocolRefs.append(all_referenced_protocol_begin(),
394 all_referenced_protocol_end());
396 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C);
399 const ObjCInterfaceDecl *
400 ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const {
401 const ObjCInterfaceDecl *IFace = this;
403 if (IFace->hasDesignatedInitializers())
405 if (!IFace->inheritsDesignatedInitializers())
407 IFace = IFace->getSuperClass();
412 static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
413 for (const auto *MD : D->instance_methods()) {
414 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
417 for (const auto *Ext : D->visible_extensions()) {
418 for (const auto *MD : Ext->instance_methods()) {
419 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
423 if (const auto *ImplD = D->getImplementation()) {
424 for (const auto *MD : ImplD->instance_methods()) {
425 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
432 bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
433 switch (data().InheritedDesignatedInitializers) {
434 case DefinitionData::IDI_Inherited:
436 case DefinitionData::IDI_NotInherited:
438 case DefinitionData::IDI_Unknown: {
439 // If the class introduced initializers we conservatively assume that we
440 // don't know if any of them is a designated initializer to avoid possible
441 // misleading warnings.
442 if (isIntroducingInitializers(this)) {
443 data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited;
445 if (auto SuperD = getSuperClass()) {
446 data().InheritedDesignatedInitializers =
447 SuperD->declaresOrInheritsDesignatedInitializers() ?
448 DefinitionData::IDI_Inherited :
449 DefinitionData::IDI_NotInherited;
451 data().InheritedDesignatedInitializers =
452 DefinitionData::IDI_NotInherited;
455 assert(data().InheritedDesignatedInitializers
456 != DefinitionData::IDI_Unknown);
457 return data().InheritedDesignatedInitializers ==
458 DefinitionData::IDI_Inherited;
462 llvm_unreachable("unexpected InheritedDesignatedInitializers value");
465 void ObjCInterfaceDecl::getDesignatedInitializers(
466 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const {
467 // Check for a complete definition and recover if not so.
468 if (!isThisDeclarationADefinition())
470 if (data().ExternallyCompleted)
471 LoadExternalDefinition();
473 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
477 for (const auto *MD : IFace->instance_methods())
478 if (MD->isThisDeclarationADesignatedInitializer())
479 Methods.push_back(MD);
480 for (const auto *Ext : IFace->visible_extensions()) {
481 for (const auto *MD : Ext->instance_methods())
482 if (MD->isThisDeclarationADesignatedInitializer())
483 Methods.push_back(MD);
487 bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel,
488 const ObjCMethodDecl **InitMethod) const {
489 // Check for a complete definition and recover if not so.
490 if (!isThisDeclarationADefinition())
492 if (data().ExternallyCompleted)
493 LoadExternalDefinition();
495 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
499 if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) {
500 if (MD->isThisDeclarationADesignatedInitializer()) {
506 for (const auto *Ext : IFace->visible_extensions()) {
507 if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) {
508 if (MD->isThisDeclarationADesignatedInitializer()) {
518 void ObjCInterfaceDecl::allocateDefinitionData() {
519 assert(!hasDefinition() && "ObjC class already has a definition");
520 Data.setPointer(new (getASTContext()) DefinitionData());
521 Data.getPointer()->Definition = this;
523 // Make the type point at the definition, now that we have one.
525 cast<ObjCInterfaceType>(TypeForDecl)->Decl = this;
528 void ObjCInterfaceDecl::startDefinition() {
529 allocateDefinitionData();
531 // Update all of the declarations with a pointer to the definition.
532 for (auto RD : redecls()) {
538 ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
539 ObjCInterfaceDecl *&clsDeclared) {
540 // FIXME: Should make sure no callers ever do this.
541 if (!hasDefinition())
544 if (data().ExternallyCompleted)
545 LoadExternalDefinition();
547 ObjCInterfaceDecl* ClassDecl = this;
548 while (ClassDecl != nullptr) {
549 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
550 clsDeclared = ClassDecl;
554 for (const auto *Ext : ClassDecl->visible_extensions()) {
555 if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) {
556 clsDeclared = ClassDecl;
561 ClassDecl = ClassDecl->getSuperClass();
566 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
567 /// class whose name is passed as argument. If it is not one of the super classes
568 /// the it returns NULL.
569 ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
570 const IdentifierInfo*ICName) {
571 // FIXME: Should make sure no callers ever do this.
572 if (!hasDefinition())
575 if (data().ExternallyCompleted)
576 LoadExternalDefinition();
578 ObjCInterfaceDecl* ClassDecl = this;
579 while (ClassDecl != nullptr) {
580 if (ClassDecl->getIdentifier() == ICName)
582 ClassDecl = ClassDecl->getSuperClass();
588 ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) {
589 for (auto *P : all_referenced_protocols())
590 if (P->lookupProtocolNamed(Name))
592 ObjCInterfaceDecl *SuperClass = getSuperClass();
593 return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr;
596 /// lookupMethod - This method returns an instance/class method by looking in
597 /// the class, its categories, and its super classes (using a linear search).
598 /// When argument category "C" is specified, any implicit method found
599 /// in this category is ignored.
600 ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
602 bool shallowCategoryLookup,
604 const ObjCCategoryDecl *C) const
606 // FIXME: Should make sure no callers ever do this.
607 if (!hasDefinition())
610 const ObjCInterfaceDecl* ClassDecl = this;
611 ObjCMethodDecl *MethodDecl = nullptr;
613 if (data().ExternallyCompleted)
614 LoadExternalDefinition();
617 // 1. Look through primary class.
618 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
621 // 2. Didn't find one yet - now look through categories.
622 for (const auto *Cat : ClassDecl->visible_categories())
623 if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
624 if (C != Cat || !MethodDecl->isImplicit())
627 // 3. Didn't find one yet - look through primary class's protocols.
628 for (const auto *I : ClassDecl->protocols())
629 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
632 // 4. Didn't find one yet - now look through categories' protocols
633 if (!shallowCategoryLookup)
634 for (const auto *Cat : ClassDecl->visible_categories()) {
635 // Didn't find one yet - look through protocols.
636 const ObjCList<ObjCProtocolDecl> &Protocols =
637 Cat->getReferencedProtocols();
638 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
639 E = Protocols.end(); I != E; ++I)
640 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
641 if (C != Cat || !MethodDecl->isImplicit())
649 // 5. Get to the super class (if any).
650 ClassDecl = ClassDecl->getSuperClass();
655 // Will search "local" class/category implementations for a method decl.
656 // If failed, then we search in class's root for an instance method.
657 // Returns 0 if no method is found.
658 ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
660 bool Instance) const {
661 // FIXME: Should make sure no callers ever do this.
662 if (!hasDefinition())
665 if (data().ExternallyCompleted)
666 LoadExternalDefinition();
668 ObjCMethodDecl *Method = nullptr;
669 if (ObjCImplementationDecl *ImpDecl = getImplementation())
670 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
671 : ImpDecl->getClassMethod(Sel);
673 // Look through local category implementations associated with the class.
675 Method = getCategoryMethod(Sel, Instance);
677 // Before we give up, check if the selector is an instance method.
678 // But only in the root. This matches gcc's behavior and what the
680 if (!Instance && !Method && !getSuperClass()) {
681 Method = lookupInstanceMethod(Sel);
682 // Look through local category implementations associated
683 // with the root class.
685 Method = lookupPrivateMethod(Sel, true);
688 if (!Method && getSuperClass())
689 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
693 //===----------------------------------------------------------------------===//
695 //===----------------------------------------------------------------------===//
697 ObjCMethodDecl *ObjCMethodDecl::Create(
698 ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
699 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
700 DeclContext *contextDecl, bool isInstance, bool isVariadic,
701 bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined,
702 ImplementationControl impControl, bool HasRelatedResultType) {
703 return new (C, contextDecl) ObjCMethodDecl(
704 beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance,
705 isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined,
706 impControl, HasRelatedResultType);
709 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
710 return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
711 Selector(), QualType(), nullptr, nullptr);
714 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
715 return getMethodFamily() == OMF_init &&
716 hasAttr<ObjCDesignatedInitializerAttr>();
719 bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
720 const ObjCMethodDecl **InitMethod) const {
721 if (getMethodFamily() != OMF_init)
723 const DeclContext *DC = getDeclContext();
724 if (isa<ObjCProtocolDecl>(DC))
726 if (const ObjCInterfaceDecl *ID = getClassInterface())
727 return ID->isDesignatedInitializer(getSelector(), InitMethod);
731 Stmt *ObjCMethodDecl::getBody() const {
732 return Body.get(getASTContext().getExternalSource());
735 void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
737 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
738 IsRedeclaration = true;
739 PrevMethod->HasRedeclaration = true;
742 void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
743 ArrayRef<ParmVarDecl*> Params,
744 ArrayRef<SourceLocation> SelLocs) {
745 ParamsAndSelLocs = nullptr;
746 NumParams = Params.size();
747 if (Params.empty() && SelLocs.empty())
750 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
751 sizeof(SourceLocation) * SelLocs.size();
752 ParamsAndSelLocs = C.Allocate(Size);
753 std::copy(Params.begin(), Params.end(), getParams());
754 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
757 void ObjCMethodDecl::getSelectorLocs(
758 SmallVectorImpl<SourceLocation> &SelLocs) const {
759 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
760 SelLocs.push_back(getSelectorLoc(i));
763 void ObjCMethodDecl::setMethodParams(ASTContext &C,
764 ArrayRef<ParmVarDecl*> Params,
765 ArrayRef<SourceLocation> SelLocs) {
766 assert((!SelLocs.empty() || isImplicit()) &&
767 "No selector locs for non-implicit method");
769 return setParamsAndSelLocs(C, Params, llvm::None);
771 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
773 if (SelLocsKind != SelLoc_NonStandard)
774 return setParamsAndSelLocs(C, Params, llvm::None);
776 setParamsAndSelLocs(C, Params, SelLocs);
779 /// \brief A definition will return its interface declaration.
780 /// An interface declaration will return its definition.
781 /// Otherwise it will return itself.
782 ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
783 ASTContext &Ctx = getASTContext();
784 ObjCMethodDecl *Redecl = nullptr;
785 if (HasRedeclaration)
786 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
790 Decl *CtxD = cast<Decl>(getDeclContext());
792 if (!CtxD->isInvalidDecl()) {
793 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
794 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
795 if (!ImplD->isInvalidDecl())
796 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
798 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
799 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
800 if (!ImplD->isInvalidDecl())
801 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
803 } else if (ObjCImplementationDecl *ImplD =
804 dyn_cast<ObjCImplementationDecl>(CtxD)) {
805 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
806 if (!IFD->isInvalidDecl())
807 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
809 } else if (ObjCCategoryImplDecl *CImplD =
810 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
811 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
812 if (!CatD->isInvalidDecl())
813 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
817 if (!Redecl && isRedeclaration()) {
818 // This is the last redeclaration, go back to the first method.
819 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
823 return Redecl ? Redecl : this;
826 ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
827 Decl *CtxD = cast<Decl>(getDeclContext());
829 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
830 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
831 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
835 } else if (ObjCCategoryImplDecl *CImplD =
836 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
837 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
838 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
843 if (isRedeclaration())
844 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
850 SourceLocation ObjCMethodDecl::getLocEnd() const {
851 if (Stmt *Body = getBody())
852 return Body->getLocEnd();
856 ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
857 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
858 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
861 // Check for an explicit attribute.
862 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
863 // The unfortunate necessity of mapping between enums here is due
864 // to the attributes framework.
865 switch (attr->getFamily()) {
866 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
867 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
868 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
869 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
870 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
871 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
873 Family = static_cast<unsigned>(family);
877 family = getSelector().getMethodFamily();
879 case OMF_None: break;
881 // init only has a conventional meaning for an instance method, and
882 // it has to return an object.
884 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
888 // alloc/copy/new have a conventional meaning for both class and
889 // instance methods, but they require an object return.
892 case OMF_mutableCopy:
894 if (!getReturnType()->isObjCObjectPointerType())
898 // These selectors have a conventional meaning only for instance methods.
903 case OMF_autorelease:
904 case OMF_retainCount:
906 if (!isInstanceMethod())
911 if (isInstanceMethod() || !getReturnType()->isVoidType())
915 case OMF_performSelector:
916 if (!isInstanceMethod() || !getReturnType()->isObjCIdType())
919 unsigned noParams = param_size();
920 if (noParams < 1 || noParams > 3)
923 ObjCMethodDecl::param_type_iterator it = param_type_begin();
924 QualType ArgT = (*it);
925 if (!ArgT->isObjCSelType()) {
932 if (!ArgT->isObjCIdType()) {
944 Family = static_cast<unsigned>(family);
948 QualType ObjCMethodDecl::getSelfType(ASTContext &Context,
949 const ObjCInterfaceDecl *OID,
950 bool &selfIsPseudoStrong,
951 bool &selfIsConsumed) {
953 selfIsPseudoStrong = false;
954 selfIsConsumed = false;
955 if (isInstanceMethod()) {
956 // There may be no interface context due to error in declaration
957 // of the interface (which has been reported). Recover gracefully.
959 selfTy = Context.getObjCInterfaceType(OID);
960 selfTy = Context.getObjCObjectPointerType(selfTy);
962 selfTy = Context.getObjCIdType();
964 } else // we have a factory method.
965 selfTy = Context.getObjCClassType();
967 if (Context.getLangOpts().ObjCAutoRefCount) {
968 if (isInstanceMethod()) {
969 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
971 // 'self' is always __strong. It's actually pseudo-strong except
972 // in init methods (or methods labeled ns_consumes_self), though.
974 qs.setObjCLifetime(Qualifiers::OCL_Strong);
975 selfTy = Context.getQualifiedType(selfTy, qs);
977 // In addition, 'self' is const unless this is an init method.
978 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
979 selfTy = selfTy.withConst();
980 selfIsPseudoStrong = true;
984 assert(isClassMethod());
985 // 'self' is always const in class methods.
986 selfTy = selfTy.withConst();
987 selfIsPseudoStrong = true;
993 void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
994 const ObjCInterfaceDecl *OID) {
995 bool selfIsPseudoStrong, selfIsConsumed;
997 getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed);
998 ImplicitParamDecl *self
999 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
1000 &Context.Idents.get("self"), selfTy);
1004 self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1006 if (selfIsPseudoStrong)
1007 self->setARCPseudoStrong(true);
1009 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
1010 &Context.Idents.get("_cmd"),
1011 Context.getObjCSelType()));
1014 ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
1015 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
1017 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
1018 return CD->getClassInterface();
1019 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
1020 return IMD->getClassInterface();
1021 if (isa<ObjCProtocolDecl>(getDeclContext()))
1023 llvm_unreachable("unknown method context");
1026 SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
1027 const auto *TSI = getReturnTypeSourceInfo();
1029 return TSI->getTypeLoc().getSourceRange();
1030 return SourceRange();
1033 QualType ObjCMethodDecl::getSendResultType() const {
1034 ASTContext &Ctx = getASTContext();
1035 return getReturnType().getNonLValueExprType(Ctx)
1036 .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
1039 QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const {
1040 // FIXME: Handle related result types here.
1042 return getReturnType().getNonLValueExprType(getASTContext())
1043 .substObjCMemberType(receiverType, getDeclContext(),
1044 ObjCSubstitutionContext::Result);
1047 static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
1048 const ObjCMethodDecl *Method,
1049 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
1050 bool MovedToSuper) {
1054 // In categories look for overriden methods from protocols. A method from
1055 // category is not "overriden" since it is considered as the "same" method
1056 // (same USR) as the one from the interface.
1057 if (const ObjCCategoryDecl *
1058 Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1059 // Check whether we have a matching method at this category but only if we
1060 // are at the super class level.
1062 if (ObjCMethodDecl *
1063 Overridden = Container->getMethod(Method->getSelector(),
1064 Method->isInstanceMethod(),
1065 /*AllowHidden=*/true))
1066 if (Method != Overridden) {
1067 // We found an override at this category; there is no need to look
1068 // into its protocols.
1069 Methods.push_back(Overridden);
1073 for (const auto *P : Category->protocols())
1074 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1078 // Check whether we have a matching method at this level.
1079 if (const ObjCMethodDecl *
1080 Overridden = Container->getMethod(Method->getSelector(),
1081 Method->isInstanceMethod(),
1082 /*AllowHidden=*/true))
1083 if (Method != Overridden) {
1084 // We found an override at this level; there is no need to look
1085 // into other protocols or categories.
1086 Methods.push_back(Overridden);
1090 if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
1091 for (const auto *P : Protocol->protocols())
1092 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1095 if (const ObjCInterfaceDecl *
1096 Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
1097 for (const auto *P : Interface->protocols())
1098 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1100 for (const auto *Cat : Interface->known_categories())
1101 CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper);
1103 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1104 return CollectOverriddenMethodsRecurse(Super, Method, Methods,
1105 /*MovedToSuper=*/true);
1109 static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
1110 const ObjCMethodDecl *Method,
1111 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
1112 CollectOverriddenMethodsRecurse(Container, Method, Methods,
1113 /*MovedToSuper=*/false);
1116 static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method,
1117 SmallVectorImpl<const ObjCMethodDecl *> &overridden) {
1118 assert(Method->isOverriding());
1120 if (const ObjCProtocolDecl *
1121 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1122 CollectOverriddenMethods(ProtD, Method, overridden);
1124 } else if (const ObjCImplDecl *
1125 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1126 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1129 // Start searching for overridden methods using the method from the
1130 // interface as starting point.
1131 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1132 Method->isInstanceMethod(),
1133 /*AllowHidden=*/true))
1135 CollectOverriddenMethods(ID, Method, overridden);
1137 } else if (const ObjCCategoryDecl *
1138 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1139 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1142 // Start searching for overridden methods using the method from the
1143 // interface as starting point.
1144 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1145 Method->isInstanceMethod(),
1146 /*AllowHidden=*/true))
1148 CollectOverriddenMethods(ID, Method, overridden);
1151 CollectOverriddenMethods(
1152 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1153 Method, overridden);
1157 void ObjCMethodDecl::getOverriddenMethods(
1158 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
1159 const ObjCMethodDecl *Method = this;
1161 if (Method->isRedeclaration()) {
1162 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1163 getMethod(Method->getSelector(), Method->isInstanceMethod());
1166 if (Method->isOverriding()) {
1167 collectOverriddenMethodsSlow(Method, Overridden);
1168 assert(!Overridden.empty() &&
1169 "ObjCMethodDecl's overriding bit is not as expected");
1173 const ObjCPropertyDecl *
1174 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1175 Selector Sel = getSelector();
1176 unsigned NumArgs = Sel.getNumArgs();
1180 if (!isInstanceMethod())
1183 if (isPropertyAccessor()) {
1184 const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
1185 // If container is class extension, find its primary class.
1186 if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(Container))
1187 if (CatDecl->IsClassExtension())
1188 Container = CatDecl->getClassInterface();
1190 bool IsGetter = (NumArgs == 0);
1192 for (const auto *I : Container->properties()) {
1193 Selector NextSel = IsGetter ? I->getGetterName()
1194 : I->getSetterName();
1199 llvm_unreachable("Marked as a property accessor but no property found!");
1202 if (!CheckOverrides)
1205 typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy;
1206 OverridesTy Overrides;
1207 getOverriddenMethods(Overrides);
1208 for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
1210 if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false))
1217 //===----------------------------------------------------------------------===//
1218 // ObjCTypeParamDecl
1219 //===----------------------------------------------------------------------===//
1221 void ObjCTypeParamDecl::anchor() { }
1223 ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc,
1224 ObjCTypeParamVariance variance,
1225 SourceLocation varianceLoc,
1227 SourceLocation nameLoc,
1228 IdentifierInfo *name,
1229 SourceLocation colonLoc,
1230 TypeSourceInfo *boundInfo) {
1231 return new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
1232 nameLoc, name, colonLoc, boundInfo);
1235 ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext &ctx,
1237 return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr,
1238 ObjCTypeParamVariance::Invariant,
1239 SourceLocation(), 0, SourceLocation(),
1240 nullptr, SourceLocation(), nullptr);
1243 SourceRange ObjCTypeParamDecl::getSourceRange() const {
1244 SourceLocation startLoc = VarianceLoc;
1245 if (startLoc.isInvalid())
1246 startLoc = getLocation();
1248 if (hasExplicitBound()) {
1249 return SourceRange(startLoc,
1250 getTypeSourceInfo()->getTypeLoc().getEndLoc());
1253 return SourceRange(startLoc);
1256 //===----------------------------------------------------------------------===//
1257 // ObjCTypeParamList
1258 //===----------------------------------------------------------------------===//
1259 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
1260 ArrayRef<ObjCTypeParamDecl *> typeParams,
1261 SourceLocation rAngleLoc)
1262 : NumParams(typeParams.size())
1264 Brackets.Begin = lAngleLoc.getRawEncoding();
1265 Brackets.End = rAngleLoc.getRawEncoding();
1266 std::copy(typeParams.begin(), typeParams.end(), begin());
1270 ObjCTypeParamList *ObjCTypeParamList::create(
1272 SourceLocation lAngleLoc,
1273 ArrayRef<ObjCTypeParamDecl *> typeParams,
1274 SourceLocation rAngleLoc) {
1275 unsigned size = sizeof(ObjCTypeParamList)
1276 + sizeof(ObjCTypeParamDecl *) * typeParams.size();
1277 static_assert(llvm::AlignOf<ObjCTypeParamList>::Alignment >=
1278 llvm::AlignOf<ObjCTypeParamDecl *>::Alignment,
1279 "type parameter list needs greater alignment");
1280 unsigned align = llvm::alignOf<ObjCTypeParamList>();
1281 void *mem = ctx.Allocate(size, align);
1282 return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc);
1285 void ObjCTypeParamList::gatherDefaultTypeArgs(
1286 SmallVectorImpl<QualType> &typeArgs) const {
1287 typeArgs.reserve(size());
1288 for (auto typeParam : *this)
1289 typeArgs.push_back(typeParam->getUnderlyingType());
1292 //===----------------------------------------------------------------------===//
1293 // ObjCInterfaceDecl
1294 //===----------------------------------------------------------------------===//
1296 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
1298 SourceLocation atLoc,
1300 ObjCTypeParamList *typeParamList,
1301 ObjCInterfaceDecl *PrevDecl,
1302 SourceLocation ClassLoc,
1304 ObjCInterfaceDecl *Result = new (C, DC)
1305 ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl,
1307 Result->Data.setInt(!C.getLangOpts().Modules);
1308 C.getObjCInterfaceType(Result, PrevDecl);
1312 ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C,
1314 ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr,
1320 Result->Data.setInt(!C.getLangOpts().Modules);
1324 ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
1325 SourceLocation AtLoc, IdentifierInfo *Id,
1326 ObjCTypeParamList *typeParamList,
1327 SourceLocation CLoc,
1328 ObjCInterfaceDecl *PrevDecl,
1330 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
1331 redeclarable_base(C), TypeForDecl(nullptr), TypeParamList(nullptr),
1333 setPreviousDecl(PrevDecl);
1335 // Copy the 'data' pointer over.
1337 Data = PrevDecl->Data;
1339 setImplicit(IsInternal);
1341 setTypeParamList(typeParamList);
1344 void ObjCInterfaceDecl::LoadExternalDefinition() const {
1345 assert(data().ExternallyCompleted && "Class is not externally completed");
1346 data().ExternallyCompleted = false;
1347 getASTContext().getExternalSource()->CompleteType(
1348 const_cast<ObjCInterfaceDecl *>(this));
1351 void ObjCInterfaceDecl::setExternallyCompleted() {
1352 assert(getASTContext().getExternalSource() &&
1353 "Class can't be externally completed without an external source");
1354 assert(hasDefinition() &&
1355 "Forward declarations can't be externally completed");
1356 data().ExternallyCompleted = true;
1359 void ObjCInterfaceDecl::setHasDesignatedInitializers() {
1360 // Check for a complete definition and recover if not so.
1361 if (!isThisDeclarationADefinition())
1363 data().HasDesignatedInitializers = true;
1366 bool ObjCInterfaceDecl::hasDesignatedInitializers() const {
1367 // Check for a complete definition and recover if not so.
1368 if (!isThisDeclarationADefinition())
1370 if (data().ExternallyCompleted)
1371 LoadExternalDefinition();
1373 return data().HasDesignatedInitializers;
1377 ObjCInterfaceDecl::getObjCRuntimeNameAsString() const {
1378 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1379 return ObjCRTName->getMetadataName();
1385 ObjCImplementationDecl::getObjCRuntimeNameAsString() const {
1386 if (ObjCInterfaceDecl *ID =
1387 const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1388 return ID->getObjCRuntimeNameAsString();
1393 ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
1394 if (const ObjCInterfaceDecl *Def = getDefinition()) {
1395 if (data().ExternallyCompleted)
1396 LoadExternalDefinition();
1398 return getASTContext().getObjCImplementation(
1399 const_cast<ObjCInterfaceDecl*>(Def));
1402 // FIXME: Should make sure no callers ever do this.
1406 void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
1407 getASTContext().setObjCImplementation(getDefinition(), ImplD);
1411 struct SynthesizeIvarChunk {
1414 SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
1415 : Size(size), Ivar(ivar) {}
1418 bool operator<(const SynthesizeIvarChunk & LHS,
1419 const SynthesizeIvarChunk &RHS) {
1420 return LHS.Size < RHS.Size;
1424 /// all_declared_ivar_begin - return first ivar declared in this class,
1425 /// its extensions and its implementation. Lazily build the list on first
1428 /// Caveat: The list returned by this method reflects the current
1429 /// state of the parser. The cache will be updated for every ivar
1430 /// added by an extension or the implementation when they are
1432 /// See also ObjCIvarDecl::Create().
1433 ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
1434 // FIXME: Should make sure no callers ever do this.
1435 if (!hasDefinition())
1438 ObjCIvarDecl *curIvar = nullptr;
1439 if (!data().IvarList) {
1440 if (!ivar_empty()) {
1441 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
1442 data().IvarList = *I; ++I;
1443 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1444 curIvar->setNextIvar(*I);
1447 for (const auto *Ext : known_extensions()) {
1448 if (!Ext->ivar_empty()) {
1449 ObjCCategoryDecl::ivar_iterator
1450 I = Ext->ivar_begin(),
1451 E = Ext->ivar_end();
1452 if (!data().IvarList) {
1453 data().IvarList = *I; ++I;
1454 curIvar = data().IvarList;
1456 for ( ;I != E; curIvar = *I, ++I)
1457 curIvar->setNextIvar(*I);
1460 data().IvarListMissingImplementation = true;
1463 // cached and complete!
1464 if (!data().IvarListMissingImplementation)
1465 return data().IvarList;
1467 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
1468 data().IvarListMissingImplementation = false;
1469 if (!ImplDecl->ivar_empty()) {
1470 SmallVector<SynthesizeIvarChunk, 16> layout;
1471 for (auto *IV : ImplDecl->ivars()) {
1472 if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1473 layout.push_back(SynthesizeIvarChunk(
1474 IV->getASTContext().getTypeSize(IV->getType()), IV));
1477 if (!data().IvarList)
1478 data().IvarList = IV;
1480 curIvar->setNextIvar(IV);
1484 if (!layout.empty()) {
1485 // Order synthesized ivars by their size.
1486 std::stable_sort(layout.begin(), layout.end());
1487 unsigned Ix = 0, EIx = layout.size();
1488 if (!data().IvarList) {
1489 data().IvarList = layout[0].Ivar; Ix++;
1490 curIvar = data().IvarList;
1492 for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
1493 curIvar->setNextIvar(layout[Ix].Ivar);
1497 return data().IvarList;
1500 /// FindCategoryDeclaration - Finds category declaration in the list of
1501 /// categories for this class and returns it. Name of the category is passed
1502 /// in 'CategoryId'. If category not found, return 0;
1505 ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
1506 // FIXME: Should make sure no callers ever do this.
1507 if (!hasDefinition())
1510 if (data().ExternallyCompleted)
1511 LoadExternalDefinition();
1513 for (auto *Cat : visible_categories())
1514 if (Cat->getIdentifier() == CategoryId)
1521 ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
1522 for (const auto *Cat : visible_categories()) {
1523 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1524 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1531 ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
1532 for (const auto *Cat : visible_categories()) {
1533 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1534 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1541 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1542 /// has been implemented in IDecl class, its super class or categories (if
1543 /// lookupCategory is true).
1544 bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1545 bool lookupCategory,
1546 bool RHSIsQualifiedID) {
1547 if (!hasDefinition())
1550 ObjCInterfaceDecl *IDecl = this;
1551 // 1st, look up the class.
1552 for (auto *PI : IDecl->protocols()){
1553 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1555 // This is dubious and is added to be compatible with gcc. In gcc, it is
1556 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1557 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1558 // object. This IMO, should be a bug.
1559 // FIXME: Treat this as an extension, and flag this as an error when GCC
1560 // extensions are not enabled.
1561 if (RHSIsQualifiedID &&
1562 getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
1566 // 2nd, look up the category.
1568 for (const auto *Cat : visible_categories()) {
1569 for (auto *PI : Cat->protocols())
1570 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1574 // 3rd, look up the super class(s)
1575 if (IDecl->getSuperClass())
1577 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1583 //===----------------------------------------------------------------------===//
1585 //===----------------------------------------------------------------------===//
1587 void ObjCIvarDecl::anchor() { }
1589 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
1590 SourceLocation StartLoc,
1591 SourceLocation IdLoc, IdentifierInfo *Id,
1592 QualType T, TypeSourceInfo *TInfo,
1593 AccessControl ac, Expr *BW,
1596 // Ivar's can only appear in interfaces, implementations (via synthesized
1597 // properties), and class extensions (via direct declaration, or synthesized
1600 // FIXME: This should really be asserting this:
1601 // (isa<ObjCCategoryDecl>(DC) &&
1602 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1603 // but unfortunately we sometimes place ivars into non-class extension
1604 // categories on error. This breaks an AST invariant, and should not be
1606 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
1607 isa<ObjCCategoryDecl>(DC)) &&
1608 "Invalid ivar decl context!");
1609 // Once a new ivar is created in any of class/class-extension/implementation
1610 // decl contexts, the previously built IvarList must be rebuilt.
1611 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1613 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
1614 ID = IM->getClassInterface();
1616 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1618 ID->setIvarList(nullptr);
1621 return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
1625 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1626 return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(),
1627 nullptr, QualType(), nullptr,
1628 ObjCIvarDecl::None, nullptr, false);
1631 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
1632 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
1634 switch (DC->getKind()) {
1636 case ObjCCategoryImpl:
1638 llvm_unreachable("invalid ivar container!");
1640 // Ivars can only appear in class extension categories.
1641 case ObjCCategory: {
1642 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
1643 assert(CD->IsClassExtension() && "invalid container for ivar!");
1644 return CD->getClassInterface();
1647 case ObjCImplementation:
1648 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1651 return cast<ObjCInterfaceDecl>(DC);
1655 QualType ObjCIvarDecl::getUsageType(QualType objectType) const {
1656 return getType().substObjCMemberType(objectType, getDeclContext(),
1657 ObjCSubstitutionContext::Property);
1660 //===----------------------------------------------------------------------===//
1661 // ObjCAtDefsFieldDecl
1662 //===----------------------------------------------------------------------===//
1664 void ObjCAtDefsFieldDecl::anchor() { }
1667 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
1668 SourceLocation StartLoc, SourceLocation IdLoc,
1669 IdentifierInfo *Id, QualType T, Expr *BW) {
1670 return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
1673 ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
1675 return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(),
1676 SourceLocation(), nullptr, QualType(),
1680 //===----------------------------------------------------------------------===//
1682 //===----------------------------------------------------------------------===//
1684 void ObjCProtocolDecl::anchor() { }
1686 ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
1687 IdentifierInfo *Id, SourceLocation nameLoc,
1688 SourceLocation atStartLoc,
1689 ObjCProtocolDecl *PrevDecl)
1690 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
1691 redeclarable_base(C), Data() {
1692 setPreviousDecl(PrevDecl);
1694 Data = PrevDecl->Data;
1697 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
1699 SourceLocation nameLoc,
1700 SourceLocation atStartLoc,
1701 ObjCProtocolDecl *PrevDecl) {
1702 ObjCProtocolDecl *Result =
1703 new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl);
1704 Result->Data.setInt(!C.getLangOpts().Modules);
1708 ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
1710 ObjCProtocolDecl *Result =
1711 new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(),
1712 SourceLocation(), nullptr);
1713 Result->Data.setInt(!C.getLangOpts().Modules);
1717 ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
1718 ObjCProtocolDecl *PDecl = this;
1720 if (Name == getIdentifier())
1723 for (auto *I : protocols())
1724 if ((PDecl = I->lookupProtocolNamed(Name)))
1730 // lookupMethod - Lookup a instance/class method in the protocol and protocols
1732 ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
1733 bool isInstance) const {
1734 ObjCMethodDecl *MethodDecl = nullptr;
1736 // If there is no definition or the definition is hidden, we don't find
1738 const ObjCProtocolDecl *Def = getDefinition();
1739 if (!Def || Def->isHidden())
1742 if ((MethodDecl = getMethod(Sel, isInstance)))
1745 for (const auto *I : protocols())
1746 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
1751 void ObjCProtocolDecl::allocateDefinitionData() {
1752 assert(!Data.getPointer() && "Protocol already has a definition!");
1753 Data.setPointer(new (getASTContext()) DefinitionData);
1754 Data.getPointer()->Definition = this;
1757 void ObjCProtocolDecl::startDefinition() {
1758 allocateDefinitionData();
1760 // Update all of the declarations with a pointer to the definition.
1761 for (auto RD : redecls())
1762 RD->Data = this->Data;
1765 void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
1766 PropertyDeclOrder &PO) const {
1768 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1769 for (auto *Prop : PDecl->properties()) {
1770 // Insert into PM if not there already.
1771 PM.insert(std::make_pair(Prop->getIdentifier(), Prop));
1774 // Scan through protocol's protocols.
1775 for (const auto *PI : PDecl->protocols())
1776 PI->collectPropertiesToImplement(PM, PO);
1781 void ObjCProtocolDecl::collectInheritedProtocolProperties(
1782 const ObjCPropertyDecl *Property,
1783 ProtocolPropertyMap &PM) const {
1784 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1785 bool MatchFound = false;
1786 for (auto *Prop : PDecl->properties()) {
1787 if (Prop == Property)
1789 if (Prop->getIdentifier() == Property->getIdentifier()) {
1795 // Scan through protocol's protocols which did not have a matching property.
1797 for (const auto *PI : PDecl->protocols())
1798 PI->collectInheritedProtocolProperties(Property, PM);
1803 ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
1804 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1805 return ObjCRTName->getMetadataName();
1810 //===----------------------------------------------------------------------===//
1812 //===----------------------------------------------------------------------===//
1814 void ObjCCategoryDecl::anchor() { }
1816 ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1817 SourceLocation ClassNameLoc,
1818 SourceLocation CategoryNameLoc,
1819 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1820 ObjCTypeParamList *typeParamList,
1821 SourceLocation IvarLBraceLoc,
1822 SourceLocation IvarRBraceLoc)
1823 : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1824 ClassInterface(IDecl), TypeParamList(nullptr),
1825 NextClassCategory(nullptr), CategoryNameLoc(CategoryNameLoc),
1826 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc)
1828 setTypeParamList(typeParamList);
1831 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
1832 SourceLocation AtLoc,
1833 SourceLocation ClassNameLoc,
1834 SourceLocation CategoryNameLoc,
1836 ObjCInterfaceDecl *IDecl,
1837 ObjCTypeParamList *typeParamList,
1838 SourceLocation IvarLBraceLoc,
1839 SourceLocation IvarRBraceLoc) {
1840 ObjCCategoryDecl *CatDecl =
1841 new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
1842 IDecl, typeParamList, IvarLBraceLoc,
1845 // Link this category into its class's category list.
1846 CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
1847 if (IDecl->hasDefinition()) {
1848 IDecl->setCategoryListRaw(CatDecl);
1849 if (ASTMutationListener *L = C.getASTMutationListener())
1850 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
1857 ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
1859 return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(),
1860 SourceLocation(), SourceLocation(),
1861 nullptr, nullptr, nullptr);
1864 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1865 return getASTContext().getObjCImplementation(
1866 const_cast<ObjCCategoryDecl*>(this));
1869 void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1870 getASTContext().setObjCImplementation(this, ImplD);
1873 void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) {
1874 TypeParamList = TPL;
1877 // Set the declaration context of each of the type parameters.
1878 for (auto typeParam : *TypeParamList)
1879 typeParam->setDeclContext(this);
1883 //===----------------------------------------------------------------------===//
1884 // ObjCCategoryImplDecl
1885 //===----------------------------------------------------------------------===//
1887 void ObjCCategoryImplDecl::anchor() { }
1889 ObjCCategoryImplDecl *
1890 ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
1892 ObjCInterfaceDecl *ClassInterface,
1893 SourceLocation nameLoc,
1894 SourceLocation atStartLoc,
1895 SourceLocation CategoryNameLoc) {
1896 if (ClassInterface && ClassInterface->hasDefinition())
1897 ClassInterface = ClassInterface->getDefinition();
1898 return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
1899 atStartLoc, CategoryNameLoc);
1902 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C,
1904 return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr,
1905 SourceLocation(), SourceLocation(),
1909 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
1910 // The class interface might be NULL if we are working with invalid code.
1911 if (const ObjCInterfaceDecl *ID = getClassInterface())
1912 return ID->FindCategoryDeclaration(getIdentifier());
1917 void ObjCImplDecl::anchor() { }
1919 void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
1920 // FIXME: The context should be correct before we get here.
1921 property->setLexicalDeclContext(this);
1925 void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
1926 ASTContext &Ctx = getASTContext();
1928 if (ObjCImplementationDecl *ImplD
1929 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
1931 Ctx.setObjCImplementation(IFace, ImplD);
1933 } else if (ObjCCategoryImplDecl *ImplD =
1934 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
1935 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
1936 Ctx.setObjCImplementation(CD, ImplD);
1939 ClassInterface = IFace;
1942 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
1943 /// properties implemented in this \@implementation block and returns
1944 /// the implemented property that uses it.
1946 ObjCPropertyImplDecl *ObjCImplDecl::
1947 FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
1948 for (auto *PID : property_impls())
1949 if (PID->getPropertyIvarDecl() &&
1950 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
1955 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
1956 /// added to the list of those properties \@synthesized/\@dynamic in this
1957 /// category \@implementation block.
1959 ObjCPropertyImplDecl *ObjCImplDecl::
1960 FindPropertyImplDecl(IdentifierInfo *Id) const {
1961 for (auto *PID : property_impls())
1962 if (PID->getPropertyDecl()->getIdentifier() == Id)
1967 raw_ostream &clang::operator<<(raw_ostream &OS,
1968 const ObjCCategoryImplDecl &CID) {
1969 OS << CID.getName();
1973 //===----------------------------------------------------------------------===//
1974 // ObjCImplementationDecl
1975 //===----------------------------------------------------------------------===//
1977 void ObjCImplementationDecl::anchor() { }
1979 ObjCImplementationDecl *
1980 ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
1981 ObjCInterfaceDecl *ClassInterface,
1982 ObjCInterfaceDecl *SuperDecl,
1983 SourceLocation nameLoc,
1984 SourceLocation atStartLoc,
1985 SourceLocation superLoc,
1986 SourceLocation IvarLBraceLoc,
1987 SourceLocation IvarRBraceLoc) {
1988 if (ClassInterface && ClassInterface->hasDefinition())
1989 ClassInterface = ClassInterface->getDefinition();
1990 return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
1991 nameLoc, atStartLoc, superLoc,
1992 IvarLBraceLoc, IvarRBraceLoc);
1995 ObjCImplementationDecl *
1996 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1997 return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr,
1998 SourceLocation(), SourceLocation());
2001 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
2002 CXXCtorInitializer ** initializers,
2003 unsigned numInitializers) {
2004 if (numInitializers > 0) {
2005 NumIvarInitializers = numInitializers;
2006 CXXCtorInitializer **ivarInitializers =
2007 new (C) CXXCtorInitializer*[NumIvarInitializers];
2008 memcpy(ivarInitializers, initializers,
2009 numInitializers * sizeof(CXXCtorInitializer*));
2010 IvarInitializers = ivarInitializers;
2014 ObjCImplementationDecl::init_const_iterator
2015 ObjCImplementationDecl::init_begin() const {
2016 return IvarInitializers.get(getASTContext().getExternalSource());
2019 raw_ostream &clang::operator<<(raw_ostream &OS,
2020 const ObjCImplementationDecl &ID) {
2025 //===----------------------------------------------------------------------===//
2026 // ObjCCompatibleAliasDecl
2027 //===----------------------------------------------------------------------===//
2029 void ObjCCompatibleAliasDecl::anchor() { }
2031 ObjCCompatibleAliasDecl *
2032 ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
2035 ObjCInterfaceDecl* AliasedClass) {
2036 return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
2039 ObjCCompatibleAliasDecl *
2040 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2041 return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(),
2045 //===----------------------------------------------------------------------===//
2047 //===----------------------------------------------------------------------===//
2049 void ObjCPropertyDecl::anchor() { }
2051 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
2054 SourceLocation AtLoc,
2055 SourceLocation LParenLoc,
2057 TypeSourceInfo *TSI,
2058 PropertyControl propControl) {
2059 return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI,
2063 ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
2065 return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr,
2066 SourceLocation(), SourceLocation(),
2067 QualType(), nullptr, None);
2070 QualType ObjCPropertyDecl::getUsageType(QualType objectType) const {
2071 return DeclType.substObjCMemberType(objectType, getDeclContext(),
2072 ObjCSubstitutionContext::Property);
2075 //===----------------------------------------------------------------------===//
2076 // ObjCPropertyImplDecl
2077 //===----------------------------------------------------------------------===//
2079 ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
2081 SourceLocation atLoc,
2083 ObjCPropertyDecl *property,
2086 SourceLocation ivarLoc) {
2087 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
2091 ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
2093 return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(),
2094 SourceLocation(), nullptr, Dynamic,
2095 nullptr, SourceLocation());
2098 SourceRange ObjCPropertyImplDecl::getSourceRange() const {
2099 SourceLocation EndLoc = getLocation();
2100 if (IvarLoc.isValid())
2103 return SourceRange(AtLoc, EndLoc);