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 // If context is class, then lookup property in its extensions.
165 // This comes before property is looked up in primary class.
166 if (auto *IDecl = dyn_cast<ObjCInterfaceDecl>(DC)) {
167 for (const auto *Ext : IDecl->known_extensions())
168 if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext,
173 DeclContext::lookup_result R = DC->lookup(propertyID);
174 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
176 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
183 ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const {
184 SmallString<128> ivarName;
186 llvm::raw_svector_ostream os(ivarName);
187 os << '_' << getIdentifier()->getName();
189 return &Ctx.Idents.get(ivarName.str());
192 /// FindPropertyDeclaration - Finds declaration of the property given its name
193 /// in 'PropertyId' and returns it. It returns 0, if not found.
194 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
195 const IdentifierInfo *PropertyId) const {
196 // Don't find properties within hidden protocol definitions.
197 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
198 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
203 // Search the extensions of a class first; they override what's in
205 if (const auto *ClassDecl = dyn_cast<ObjCInterfaceDecl>(this)) {
206 for (const auto *Ext : ClassDecl->visible_extensions()) {
207 if (auto *P = Ext->FindPropertyDeclaration(PropertyId))
212 if (ObjCPropertyDecl *PD =
213 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
219 case Decl::ObjCProtocol: {
220 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
221 for (const auto *I : PID->protocols())
222 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
226 case Decl::ObjCInterface: {
227 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
228 // Look through categories (but not extensions; they were handled above).
229 for (const auto *Cat : OID->visible_categories()) {
230 if (!Cat->IsClassExtension())
231 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
235 // Look through protocols.
236 for (const auto *I : OID->all_referenced_protocols())
237 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
240 // Finally, check the super class.
241 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
242 return superClass->FindPropertyDeclaration(PropertyId);
245 case Decl::ObjCCategory: {
246 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
247 // Look through protocols.
248 if (!OCD->IsClassExtension())
249 for (const auto *I : OCD->protocols())
250 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
258 void ObjCInterfaceDecl::anchor() { }
260 ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const {
261 // If this particular declaration has a type parameter list, return it.
262 if (ObjCTypeParamList *written = getTypeParamListAsWritten())
265 // If there is a definition, return its type parameter list.
266 if (const ObjCInterfaceDecl *def = getDefinition())
267 return def->getTypeParamListAsWritten();
269 // Otherwise, look at previous declarations to determine whether any
270 // of them has a type parameter list, skipping over those
271 // declarations that do not.
272 for (auto decl = getMostRecentDecl(); decl; decl = decl->getPreviousDecl()) {
273 if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten())
280 void ObjCInterfaceDecl::setTypeParamList(ObjCTypeParamList *TPL) {
284 // Set the declaration context of each of the type parameters.
285 for (auto typeParam : *TypeParamList)
286 typeParam->setDeclContext(this);
289 ObjCInterfaceDecl *ObjCInterfaceDecl::getSuperClass() const {
290 // FIXME: Should make sure no callers ever do this.
291 if (!hasDefinition())
294 if (data().ExternallyCompleted)
295 LoadExternalDefinition();
297 if (const ObjCObjectType *superType = getSuperClassType()) {
298 if (ObjCInterfaceDecl *superDecl = superType->getInterface()) {
299 if (ObjCInterfaceDecl *superDef = superDecl->getDefinition())
309 SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const {
310 if (TypeSourceInfo *superTInfo = getSuperClassTInfo())
311 return superTInfo->getTypeLoc().getLocStart();
313 return SourceLocation();
316 /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
317 /// with name 'PropertyId' in the primary class; including those in protocols
318 /// (direct or indirect) used by the primary class.
321 ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
322 IdentifierInfo *PropertyId) const {
323 // FIXME: Should make sure no callers ever do this.
324 if (!hasDefinition())
327 if (data().ExternallyCompleted)
328 LoadExternalDefinition();
330 if (ObjCPropertyDecl *PD =
331 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
334 // Look through protocols.
335 for (const auto *I : all_referenced_protocols())
336 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
342 void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM,
343 PropertyDeclOrder &PO) const {
344 for (auto *Prop : properties()) {
345 PM[Prop->getIdentifier()] = Prop;
348 for (const auto *Ext : known_extensions()) {
349 const ObjCCategoryDecl *ClassExt = Ext;
350 for (auto *Prop : ClassExt->properties()) {
351 PM[Prop->getIdentifier()] = Prop;
355 for (const auto *PI : all_referenced_protocols())
356 PI->collectPropertiesToImplement(PM, PO);
357 // Note, the properties declared only in class extensions are still copied
358 // into the main @interface's property list, and therefore we don't
359 // explicitly, have to search class extension properties.
362 bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const {
363 const ObjCInterfaceDecl *Class = this;
365 if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
367 Class = Class->getSuperClass();
372 const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const {
373 const ObjCInterfaceDecl *Class = this;
375 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
377 Class = Class->getSuperClass();
382 void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
383 ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
386 if (data().ExternallyCompleted)
387 LoadExternalDefinition();
389 if (data().AllReferencedProtocols.empty() &&
390 data().ReferencedProtocols.empty()) {
391 data().AllReferencedProtocols.set(ExtList, ExtNum, C);
395 // Check for duplicate protocol in class's protocol list.
396 // This is O(n*m). But it is extremely rare and number of protocols in
397 // class or its extension are very few.
398 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
399 for (unsigned i = 0; i < ExtNum; i++) {
400 bool protocolExists = false;
401 ObjCProtocolDecl *ProtoInExtension = ExtList[i];
402 for (auto *Proto : all_referenced_protocols()) {
403 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
404 protocolExists = true;
408 // Do we want to warn on a protocol in extension class which
409 // already exist in the class? Probably not.
411 ProtocolRefs.push_back(ProtoInExtension);
414 if (ProtocolRefs.empty())
417 // Merge ProtocolRefs into class's protocol list;
418 ProtocolRefs.append(all_referenced_protocol_begin(),
419 all_referenced_protocol_end());
421 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C);
424 const ObjCInterfaceDecl *
425 ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const {
426 const ObjCInterfaceDecl *IFace = this;
428 if (IFace->hasDesignatedInitializers())
430 if (!IFace->inheritsDesignatedInitializers())
432 IFace = IFace->getSuperClass();
437 static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
438 for (const auto *MD : D->instance_methods()) {
439 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
442 for (const auto *Ext : D->visible_extensions()) {
443 for (const auto *MD : Ext->instance_methods()) {
444 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
448 if (const auto *ImplD = D->getImplementation()) {
449 for (const auto *MD : ImplD->instance_methods()) {
450 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
457 bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
458 switch (data().InheritedDesignatedInitializers) {
459 case DefinitionData::IDI_Inherited:
461 case DefinitionData::IDI_NotInherited:
463 case DefinitionData::IDI_Unknown: {
464 // If the class introduced initializers we conservatively assume that we
465 // don't know if any of them is a designated initializer to avoid possible
466 // misleading warnings.
467 if (isIntroducingInitializers(this)) {
468 data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited;
470 if (auto SuperD = getSuperClass()) {
471 data().InheritedDesignatedInitializers =
472 SuperD->declaresOrInheritsDesignatedInitializers() ?
473 DefinitionData::IDI_Inherited :
474 DefinitionData::IDI_NotInherited;
476 data().InheritedDesignatedInitializers =
477 DefinitionData::IDI_NotInherited;
480 assert(data().InheritedDesignatedInitializers
481 != DefinitionData::IDI_Unknown);
482 return data().InheritedDesignatedInitializers ==
483 DefinitionData::IDI_Inherited;
487 llvm_unreachable("unexpected InheritedDesignatedInitializers value");
490 void ObjCInterfaceDecl::getDesignatedInitializers(
491 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const {
492 // Check for a complete definition and recover if not so.
493 if (!isThisDeclarationADefinition())
495 if (data().ExternallyCompleted)
496 LoadExternalDefinition();
498 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
502 for (const auto *MD : IFace->instance_methods())
503 if (MD->isThisDeclarationADesignatedInitializer())
504 Methods.push_back(MD);
505 for (const auto *Ext : IFace->visible_extensions()) {
506 for (const auto *MD : Ext->instance_methods())
507 if (MD->isThisDeclarationADesignatedInitializer())
508 Methods.push_back(MD);
512 bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel,
513 const ObjCMethodDecl **InitMethod) const {
514 // Check for a complete definition and recover if not so.
515 if (!isThisDeclarationADefinition())
517 if (data().ExternallyCompleted)
518 LoadExternalDefinition();
520 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
524 if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) {
525 if (MD->isThisDeclarationADesignatedInitializer()) {
531 for (const auto *Ext : IFace->visible_extensions()) {
532 if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) {
533 if (MD->isThisDeclarationADesignatedInitializer()) {
543 void ObjCInterfaceDecl::allocateDefinitionData() {
544 assert(!hasDefinition() && "ObjC class already has a definition");
545 Data.setPointer(new (getASTContext()) DefinitionData());
546 Data.getPointer()->Definition = this;
548 // Make the type point at the definition, now that we have one.
550 cast<ObjCInterfaceType>(TypeForDecl)->Decl = this;
553 void ObjCInterfaceDecl::startDefinition() {
554 allocateDefinitionData();
556 // Update all of the declarations with a pointer to the definition.
557 for (auto RD : redecls()) {
563 ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
564 ObjCInterfaceDecl *&clsDeclared) {
565 // FIXME: Should make sure no callers ever do this.
566 if (!hasDefinition())
569 if (data().ExternallyCompleted)
570 LoadExternalDefinition();
572 ObjCInterfaceDecl* ClassDecl = this;
573 while (ClassDecl != nullptr) {
574 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
575 clsDeclared = ClassDecl;
579 for (const auto *Ext : ClassDecl->visible_extensions()) {
580 if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) {
581 clsDeclared = ClassDecl;
586 ClassDecl = ClassDecl->getSuperClass();
591 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
592 /// class whose name is passed as argument. If it is not one of the super classes
593 /// the it returns NULL.
594 ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
595 const IdentifierInfo*ICName) {
596 // FIXME: Should make sure no callers ever do this.
597 if (!hasDefinition())
600 if (data().ExternallyCompleted)
601 LoadExternalDefinition();
603 ObjCInterfaceDecl* ClassDecl = this;
604 while (ClassDecl != nullptr) {
605 if (ClassDecl->getIdentifier() == ICName)
607 ClassDecl = ClassDecl->getSuperClass();
613 ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) {
614 for (auto *P : all_referenced_protocols())
615 if (P->lookupProtocolNamed(Name))
617 ObjCInterfaceDecl *SuperClass = getSuperClass();
618 return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr;
621 /// lookupMethod - This method returns an instance/class method by looking in
622 /// the class, its categories, and its super classes (using a linear search).
623 /// When argument category "C" is specified, any implicit method found
624 /// in this category is ignored.
625 ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
627 bool shallowCategoryLookup,
629 const ObjCCategoryDecl *C) const
631 // FIXME: Should make sure no callers ever do this.
632 if (!hasDefinition())
635 const ObjCInterfaceDecl* ClassDecl = this;
636 ObjCMethodDecl *MethodDecl = nullptr;
638 if (data().ExternallyCompleted)
639 LoadExternalDefinition();
642 // 1. Look through primary class.
643 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
646 // 2. Didn't find one yet - now look through categories.
647 for (const auto *Cat : ClassDecl->visible_categories())
648 if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
649 if (C != Cat || !MethodDecl->isImplicit())
652 // 3. Didn't find one yet - look through primary class's protocols.
653 for (const auto *I : ClassDecl->protocols())
654 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
657 // 4. Didn't find one yet - now look through categories' protocols
658 if (!shallowCategoryLookup)
659 for (const auto *Cat : ClassDecl->visible_categories()) {
660 // Didn't find one yet - look through protocols.
661 const ObjCList<ObjCProtocolDecl> &Protocols =
662 Cat->getReferencedProtocols();
663 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
664 E = Protocols.end(); I != E; ++I)
665 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
666 if (C != Cat || !MethodDecl->isImplicit())
674 // 5. Get to the super class (if any).
675 ClassDecl = ClassDecl->getSuperClass();
680 // Will search "local" class/category implementations for a method decl.
681 // If failed, then we search in class's root for an instance method.
682 // Returns 0 if no method is found.
683 ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
685 bool Instance) const {
686 // FIXME: Should make sure no callers ever do this.
687 if (!hasDefinition())
690 if (data().ExternallyCompleted)
691 LoadExternalDefinition();
693 ObjCMethodDecl *Method = nullptr;
694 if (ObjCImplementationDecl *ImpDecl = getImplementation())
695 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
696 : ImpDecl->getClassMethod(Sel);
698 // Look through local category implementations associated with the class.
700 Method = getCategoryMethod(Sel, Instance);
702 // Before we give up, check if the selector is an instance method.
703 // But only in the root. This matches gcc's behavior and what the
705 if (!Instance && !Method && !getSuperClass()) {
706 Method = lookupInstanceMethod(Sel);
707 // Look through local category implementations associated
708 // with the root class.
710 Method = lookupPrivateMethod(Sel, true);
713 if (!Method && getSuperClass())
714 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
718 //===----------------------------------------------------------------------===//
720 //===----------------------------------------------------------------------===//
722 ObjCMethodDecl *ObjCMethodDecl::Create(
723 ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
724 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
725 DeclContext *contextDecl, bool isInstance, bool isVariadic,
726 bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined,
727 ImplementationControl impControl, bool HasRelatedResultType) {
728 return new (C, contextDecl) ObjCMethodDecl(
729 beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance,
730 isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined,
731 impControl, HasRelatedResultType);
734 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
735 return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
736 Selector(), QualType(), nullptr, nullptr);
739 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
740 return getMethodFamily() == OMF_init &&
741 hasAttr<ObjCDesignatedInitializerAttr>();
744 bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
745 const ObjCMethodDecl **InitMethod) const {
746 if (getMethodFamily() != OMF_init)
748 const DeclContext *DC = getDeclContext();
749 if (isa<ObjCProtocolDecl>(DC))
751 if (const ObjCInterfaceDecl *ID = getClassInterface())
752 return ID->isDesignatedInitializer(getSelector(), InitMethod);
756 Stmt *ObjCMethodDecl::getBody() const {
757 return Body.get(getASTContext().getExternalSource());
760 void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
762 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
763 IsRedeclaration = true;
764 PrevMethod->HasRedeclaration = true;
767 void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
768 ArrayRef<ParmVarDecl*> Params,
769 ArrayRef<SourceLocation> SelLocs) {
770 ParamsAndSelLocs = nullptr;
771 NumParams = Params.size();
772 if (Params.empty() && SelLocs.empty())
775 static_assert(llvm::AlignOf<ParmVarDecl *>::Alignment >=
776 llvm::AlignOf<SourceLocation>::Alignment,
777 "Alignment not sufficient for SourceLocation");
779 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
780 sizeof(SourceLocation) * SelLocs.size();
781 ParamsAndSelLocs = C.Allocate(Size);
782 std::copy(Params.begin(), Params.end(), getParams());
783 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
786 void ObjCMethodDecl::getSelectorLocs(
787 SmallVectorImpl<SourceLocation> &SelLocs) const {
788 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
789 SelLocs.push_back(getSelectorLoc(i));
792 void ObjCMethodDecl::setMethodParams(ASTContext &C,
793 ArrayRef<ParmVarDecl*> Params,
794 ArrayRef<SourceLocation> SelLocs) {
795 assert((!SelLocs.empty() || isImplicit()) &&
796 "No selector locs for non-implicit method");
798 return setParamsAndSelLocs(C, Params, llvm::None);
800 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
802 if (SelLocsKind != SelLoc_NonStandard)
803 return setParamsAndSelLocs(C, Params, llvm::None);
805 setParamsAndSelLocs(C, Params, SelLocs);
808 /// \brief A definition will return its interface declaration.
809 /// An interface declaration will return its definition.
810 /// Otherwise it will return itself.
811 ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
812 ASTContext &Ctx = getASTContext();
813 ObjCMethodDecl *Redecl = nullptr;
814 if (HasRedeclaration)
815 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
819 Decl *CtxD = cast<Decl>(getDeclContext());
821 if (!CtxD->isInvalidDecl()) {
822 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
823 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
824 if (!ImplD->isInvalidDecl())
825 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
827 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
828 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
829 if (!ImplD->isInvalidDecl())
830 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
832 } else if (ObjCImplementationDecl *ImplD =
833 dyn_cast<ObjCImplementationDecl>(CtxD)) {
834 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
835 if (!IFD->isInvalidDecl())
836 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
838 } else if (ObjCCategoryImplDecl *CImplD =
839 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
840 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
841 if (!CatD->isInvalidDecl())
842 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
846 if (!Redecl && isRedeclaration()) {
847 // This is the last redeclaration, go back to the first method.
848 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
852 return Redecl ? Redecl : this;
855 ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
856 Decl *CtxD = cast<Decl>(getDeclContext());
858 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
859 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
860 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
864 } else if (ObjCCategoryImplDecl *CImplD =
865 dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
866 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
867 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
872 if (isRedeclaration())
873 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
879 SourceLocation ObjCMethodDecl::getLocEnd() const {
880 if (Stmt *Body = getBody())
881 return Body->getLocEnd();
885 ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
886 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
887 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
890 // Check for an explicit attribute.
891 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
892 // The unfortunate necessity of mapping between enums here is due
893 // to the attributes framework.
894 switch (attr->getFamily()) {
895 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
896 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
897 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
898 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
899 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
900 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
902 Family = static_cast<unsigned>(family);
906 family = getSelector().getMethodFamily();
908 case OMF_None: break;
910 // init only has a conventional meaning for an instance method, and
911 // it has to return an object.
913 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
917 // alloc/copy/new have a conventional meaning for both class and
918 // instance methods, but they require an object return.
921 case OMF_mutableCopy:
923 if (!getReturnType()->isObjCObjectPointerType())
927 // These selectors have a conventional meaning only for instance methods.
932 case OMF_autorelease:
933 case OMF_retainCount:
935 if (!isInstanceMethod())
940 if (isInstanceMethod() || !getReturnType()->isVoidType())
944 case OMF_performSelector:
945 if (!isInstanceMethod() || !getReturnType()->isObjCIdType())
948 unsigned noParams = param_size();
949 if (noParams < 1 || noParams > 3)
952 ObjCMethodDecl::param_type_iterator it = param_type_begin();
953 QualType ArgT = (*it);
954 if (!ArgT->isObjCSelType()) {
961 if (!ArgT->isObjCIdType()) {
973 Family = static_cast<unsigned>(family);
977 QualType ObjCMethodDecl::getSelfType(ASTContext &Context,
978 const ObjCInterfaceDecl *OID,
979 bool &selfIsPseudoStrong,
980 bool &selfIsConsumed) {
982 selfIsPseudoStrong = false;
983 selfIsConsumed = false;
984 if (isInstanceMethod()) {
985 // There may be no interface context due to error in declaration
986 // of the interface (which has been reported). Recover gracefully.
988 selfTy = Context.getObjCInterfaceType(OID);
989 selfTy = Context.getObjCObjectPointerType(selfTy);
991 selfTy = Context.getObjCIdType();
993 } else // we have a factory method.
994 selfTy = Context.getObjCClassType();
996 if (Context.getLangOpts().ObjCAutoRefCount) {
997 if (isInstanceMethod()) {
998 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
1000 // 'self' is always __strong. It's actually pseudo-strong except
1001 // in init methods (or methods labeled ns_consumes_self), though.
1003 qs.setObjCLifetime(Qualifiers::OCL_Strong);
1004 selfTy = Context.getQualifiedType(selfTy, qs);
1006 // In addition, 'self' is const unless this is an init method.
1007 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
1008 selfTy = selfTy.withConst();
1009 selfIsPseudoStrong = true;
1013 assert(isClassMethod());
1014 // 'self' is always const in class methods.
1015 selfTy = selfTy.withConst();
1016 selfIsPseudoStrong = true;
1022 void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
1023 const ObjCInterfaceDecl *OID) {
1024 bool selfIsPseudoStrong, selfIsConsumed;
1026 getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed);
1027 ImplicitParamDecl *self
1028 = ImplicitParamDecl::Create(Context, this, SourceLocation(),
1029 &Context.Idents.get("self"), selfTy);
1033 self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1035 if (selfIsPseudoStrong)
1036 self->setARCPseudoStrong(true);
1038 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
1039 &Context.Idents.get("_cmd"),
1040 Context.getObjCSelType()));
1043 ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
1044 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
1046 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
1047 return CD->getClassInterface();
1048 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
1049 return IMD->getClassInterface();
1050 if (isa<ObjCProtocolDecl>(getDeclContext()))
1052 llvm_unreachable("unknown method context");
1055 SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
1056 const auto *TSI = getReturnTypeSourceInfo();
1058 return TSI->getTypeLoc().getSourceRange();
1059 return SourceRange();
1062 QualType ObjCMethodDecl::getSendResultType() const {
1063 ASTContext &Ctx = getASTContext();
1064 return getReturnType().getNonLValueExprType(Ctx)
1065 .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
1068 QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const {
1069 // FIXME: Handle related result types here.
1071 return getReturnType().getNonLValueExprType(getASTContext())
1072 .substObjCMemberType(receiverType, getDeclContext(),
1073 ObjCSubstitutionContext::Result);
1076 static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
1077 const ObjCMethodDecl *Method,
1078 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
1079 bool MovedToSuper) {
1083 // In categories look for overriden methods from protocols. A method from
1084 // category is not "overriden" since it is considered as the "same" method
1085 // (same USR) as the one from the interface.
1086 if (const ObjCCategoryDecl *
1087 Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1088 // Check whether we have a matching method at this category but only if we
1089 // are at the super class level.
1091 if (ObjCMethodDecl *
1092 Overridden = Container->getMethod(Method->getSelector(),
1093 Method->isInstanceMethod(),
1094 /*AllowHidden=*/true))
1095 if (Method != Overridden) {
1096 // We found an override at this category; there is no need to look
1097 // into its protocols.
1098 Methods.push_back(Overridden);
1102 for (const auto *P : Category->protocols())
1103 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1107 // Check whether we have a matching method at this level.
1108 if (const ObjCMethodDecl *
1109 Overridden = Container->getMethod(Method->getSelector(),
1110 Method->isInstanceMethod(),
1111 /*AllowHidden=*/true))
1112 if (Method != Overridden) {
1113 // We found an override at this level; there is no need to look
1114 // into other protocols or categories.
1115 Methods.push_back(Overridden);
1119 if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
1120 for (const auto *P : Protocol->protocols())
1121 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1124 if (const ObjCInterfaceDecl *
1125 Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
1126 for (const auto *P : Interface->protocols())
1127 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1129 for (const auto *Cat : Interface->known_categories())
1130 CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper);
1132 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1133 return CollectOverriddenMethodsRecurse(Super, Method, Methods,
1134 /*MovedToSuper=*/true);
1138 static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
1139 const ObjCMethodDecl *Method,
1140 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
1141 CollectOverriddenMethodsRecurse(Container, Method, Methods,
1142 /*MovedToSuper=*/false);
1145 static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method,
1146 SmallVectorImpl<const ObjCMethodDecl *> &overridden) {
1147 assert(Method->isOverriding());
1149 if (const ObjCProtocolDecl *
1150 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1151 CollectOverriddenMethods(ProtD, Method, overridden);
1153 } else if (const ObjCImplDecl *
1154 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1155 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1158 // Start searching for overridden methods using the method from the
1159 // interface as starting point.
1160 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1161 Method->isInstanceMethod(),
1162 /*AllowHidden=*/true))
1164 CollectOverriddenMethods(ID, Method, overridden);
1166 } else if (const ObjCCategoryDecl *
1167 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1168 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1171 // Start searching for overridden methods using the method from the
1172 // interface as starting point.
1173 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1174 Method->isInstanceMethod(),
1175 /*AllowHidden=*/true))
1177 CollectOverriddenMethods(ID, Method, overridden);
1180 CollectOverriddenMethods(
1181 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1182 Method, overridden);
1186 void ObjCMethodDecl::getOverriddenMethods(
1187 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
1188 const ObjCMethodDecl *Method = this;
1190 if (Method->isRedeclaration()) {
1191 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1192 getMethod(Method->getSelector(), Method->isInstanceMethod());
1195 if (Method->isOverriding()) {
1196 collectOverriddenMethodsSlow(Method, Overridden);
1197 assert(!Overridden.empty() &&
1198 "ObjCMethodDecl's overriding bit is not as expected");
1202 const ObjCPropertyDecl *
1203 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1204 Selector Sel = getSelector();
1205 unsigned NumArgs = Sel.getNumArgs();
1209 if (!isInstanceMethod())
1212 if (isPropertyAccessor()) {
1213 const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
1214 bool IsGetter = (NumArgs == 0);
1216 /// Local function that attempts to find a matching property within the
1217 /// given Objective-C container.
1218 auto findMatchingProperty =
1219 [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {
1221 for (const auto *I : Container->properties()) {
1222 Selector NextSel = IsGetter ? I->getGetterName()
1223 : I->getSetterName();
1231 // Look in the container we were given.
1232 if (const auto *Found = findMatchingProperty(Container))
1235 // If we're in a category or extension, look in the main class.
1236 const ObjCInterfaceDecl *ClassDecl = nullptr;
1237 if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1238 ClassDecl = Category->getClassInterface();
1239 if (const auto *Found = findMatchingProperty(ClassDecl))
1242 // Determine whether the container is a class.
1243 ClassDecl = dyn_cast<ObjCInterfaceDecl>(Container);
1246 // If we have a class, check its visible extensions.
1248 for (const auto *Ext : ClassDecl->visible_extensions()) {
1249 if (Ext == Container)
1252 if (const auto *Found = findMatchingProperty(Ext))
1257 llvm_unreachable("Marked as a property accessor but no property found!");
1260 if (!CheckOverrides)
1263 typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy;
1264 OverridesTy Overrides;
1265 getOverriddenMethods(Overrides);
1266 for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
1268 if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false))
1275 //===----------------------------------------------------------------------===//
1276 // ObjCTypeParamDecl
1277 //===----------------------------------------------------------------------===//
1279 void ObjCTypeParamDecl::anchor() { }
1281 ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc,
1282 ObjCTypeParamVariance variance,
1283 SourceLocation varianceLoc,
1285 SourceLocation nameLoc,
1286 IdentifierInfo *name,
1287 SourceLocation colonLoc,
1288 TypeSourceInfo *boundInfo) {
1289 return new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
1290 nameLoc, name, colonLoc, boundInfo);
1293 ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext &ctx,
1295 return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr,
1296 ObjCTypeParamVariance::Invariant,
1297 SourceLocation(), 0, SourceLocation(),
1298 nullptr, SourceLocation(), nullptr);
1301 SourceRange ObjCTypeParamDecl::getSourceRange() const {
1302 SourceLocation startLoc = VarianceLoc;
1303 if (startLoc.isInvalid())
1304 startLoc = getLocation();
1306 if (hasExplicitBound()) {
1307 return SourceRange(startLoc,
1308 getTypeSourceInfo()->getTypeLoc().getEndLoc());
1311 return SourceRange(startLoc);
1314 //===----------------------------------------------------------------------===//
1315 // ObjCTypeParamList
1316 //===----------------------------------------------------------------------===//
1317 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
1318 ArrayRef<ObjCTypeParamDecl *> typeParams,
1319 SourceLocation rAngleLoc)
1320 : NumParams(typeParams.size())
1322 Brackets.Begin = lAngleLoc.getRawEncoding();
1323 Brackets.End = rAngleLoc.getRawEncoding();
1324 std::copy(typeParams.begin(), typeParams.end(), begin());
1328 ObjCTypeParamList *ObjCTypeParamList::create(
1330 SourceLocation lAngleLoc,
1331 ArrayRef<ObjCTypeParamDecl *> typeParams,
1332 SourceLocation rAngleLoc) {
1334 ctx.Allocate(totalSizeToAlloc<ObjCTypeParamDecl *>(typeParams.size()),
1335 llvm::alignOf<ObjCTypeParamList>());
1336 return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc);
1339 void ObjCTypeParamList::gatherDefaultTypeArgs(
1340 SmallVectorImpl<QualType> &typeArgs) const {
1341 typeArgs.reserve(size());
1342 for (auto typeParam : *this)
1343 typeArgs.push_back(typeParam->getUnderlyingType());
1346 //===----------------------------------------------------------------------===//
1347 // ObjCInterfaceDecl
1348 //===----------------------------------------------------------------------===//
1350 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
1352 SourceLocation atLoc,
1354 ObjCTypeParamList *typeParamList,
1355 ObjCInterfaceDecl *PrevDecl,
1356 SourceLocation ClassLoc,
1358 ObjCInterfaceDecl *Result = new (C, DC)
1359 ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl,
1361 Result->Data.setInt(!C.getLangOpts().Modules);
1362 C.getObjCInterfaceType(Result, PrevDecl);
1366 ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C,
1368 ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr,
1374 Result->Data.setInt(!C.getLangOpts().Modules);
1378 ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
1379 SourceLocation AtLoc, IdentifierInfo *Id,
1380 ObjCTypeParamList *typeParamList,
1381 SourceLocation CLoc,
1382 ObjCInterfaceDecl *PrevDecl,
1384 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
1385 redeclarable_base(C), TypeForDecl(nullptr), TypeParamList(nullptr),
1387 setPreviousDecl(PrevDecl);
1389 // Copy the 'data' pointer over.
1391 Data = PrevDecl->Data;
1393 setImplicit(IsInternal);
1395 setTypeParamList(typeParamList);
1398 void ObjCInterfaceDecl::LoadExternalDefinition() const {
1399 assert(data().ExternallyCompleted && "Class is not externally completed");
1400 data().ExternallyCompleted = false;
1401 getASTContext().getExternalSource()->CompleteType(
1402 const_cast<ObjCInterfaceDecl *>(this));
1405 void ObjCInterfaceDecl::setExternallyCompleted() {
1406 assert(getASTContext().getExternalSource() &&
1407 "Class can't be externally completed without an external source");
1408 assert(hasDefinition() &&
1409 "Forward declarations can't be externally completed");
1410 data().ExternallyCompleted = true;
1413 void ObjCInterfaceDecl::setHasDesignatedInitializers() {
1414 // Check for a complete definition and recover if not so.
1415 if (!isThisDeclarationADefinition())
1417 data().HasDesignatedInitializers = true;
1420 bool ObjCInterfaceDecl::hasDesignatedInitializers() const {
1421 // Check for a complete definition and recover if not so.
1422 if (!isThisDeclarationADefinition())
1424 if (data().ExternallyCompleted)
1425 LoadExternalDefinition();
1427 return data().HasDesignatedInitializers;
1431 ObjCInterfaceDecl::getObjCRuntimeNameAsString() const {
1432 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1433 return ObjCRTName->getMetadataName();
1439 ObjCImplementationDecl::getObjCRuntimeNameAsString() const {
1440 if (ObjCInterfaceDecl *ID =
1441 const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1442 return ID->getObjCRuntimeNameAsString();
1447 ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
1448 if (const ObjCInterfaceDecl *Def = getDefinition()) {
1449 if (data().ExternallyCompleted)
1450 LoadExternalDefinition();
1452 return getASTContext().getObjCImplementation(
1453 const_cast<ObjCInterfaceDecl*>(Def));
1456 // FIXME: Should make sure no callers ever do this.
1460 void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
1461 getASTContext().setObjCImplementation(getDefinition(), ImplD);
1465 struct SynthesizeIvarChunk {
1468 SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
1469 : Size(size), Ivar(ivar) {}
1472 bool operator<(const SynthesizeIvarChunk & LHS,
1473 const SynthesizeIvarChunk &RHS) {
1474 return LHS.Size < RHS.Size;
1478 /// all_declared_ivar_begin - return first ivar declared in this class,
1479 /// its extensions and its implementation. Lazily build the list on first
1482 /// Caveat: The list returned by this method reflects the current
1483 /// state of the parser. The cache will be updated for every ivar
1484 /// added by an extension or the implementation when they are
1486 /// See also ObjCIvarDecl::Create().
1487 ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
1488 // FIXME: Should make sure no callers ever do this.
1489 if (!hasDefinition())
1492 ObjCIvarDecl *curIvar = nullptr;
1493 if (!data().IvarList) {
1494 if (!ivar_empty()) {
1495 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
1496 data().IvarList = *I; ++I;
1497 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1498 curIvar->setNextIvar(*I);
1501 for (const auto *Ext : known_extensions()) {
1502 if (!Ext->ivar_empty()) {
1503 ObjCCategoryDecl::ivar_iterator
1504 I = Ext->ivar_begin(),
1505 E = Ext->ivar_end();
1506 if (!data().IvarList) {
1507 data().IvarList = *I; ++I;
1508 curIvar = data().IvarList;
1510 for ( ;I != E; curIvar = *I, ++I)
1511 curIvar->setNextIvar(*I);
1514 data().IvarListMissingImplementation = true;
1517 // cached and complete!
1518 if (!data().IvarListMissingImplementation)
1519 return data().IvarList;
1521 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
1522 data().IvarListMissingImplementation = false;
1523 if (!ImplDecl->ivar_empty()) {
1524 SmallVector<SynthesizeIvarChunk, 16> layout;
1525 for (auto *IV : ImplDecl->ivars()) {
1526 if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1527 layout.push_back(SynthesizeIvarChunk(
1528 IV->getASTContext().getTypeSize(IV->getType()), IV));
1531 if (!data().IvarList)
1532 data().IvarList = IV;
1534 curIvar->setNextIvar(IV);
1538 if (!layout.empty()) {
1539 // Order synthesized ivars by their size.
1540 std::stable_sort(layout.begin(), layout.end());
1541 unsigned Ix = 0, EIx = layout.size();
1542 if (!data().IvarList) {
1543 data().IvarList = layout[0].Ivar; Ix++;
1544 curIvar = data().IvarList;
1546 for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
1547 curIvar->setNextIvar(layout[Ix].Ivar);
1551 return data().IvarList;
1554 /// FindCategoryDeclaration - Finds category declaration in the list of
1555 /// categories for this class and returns it. Name of the category is passed
1556 /// in 'CategoryId'. If category not found, return 0;
1559 ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
1560 // FIXME: Should make sure no callers ever do this.
1561 if (!hasDefinition())
1564 if (data().ExternallyCompleted)
1565 LoadExternalDefinition();
1567 for (auto *Cat : visible_categories())
1568 if (Cat->getIdentifier() == CategoryId)
1575 ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
1576 for (const auto *Cat : visible_categories()) {
1577 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1578 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1585 ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
1586 for (const auto *Cat : visible_categories()) {
1587 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1588 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1595 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1596 /// has been implemented in IDecl class, its super class or categories (if
1597 /// lookupCategory is true).
1598 bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1599 bool lookupCategory,
1600 bool RHSIsQualifiedID) {
1601 if (!hasDefinition())
1604 ObjCInterfaceDecl *IDecl = this;
1605 // 1st, look up the class.
1606 for (auto *PI : IDecl->protocols()){
1607 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1609 // This is dubious and is added to be compatible with gcc. In gcc, it is
1610 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1611 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1612 // object. This IMO, should be a bug.
1613 // FIXME: Treat this as an extension, and flag this as an error when GCC
1614 // extensions are not enabled.
1615 if (RHSIsQualifiedID &&
1616 getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
1620 // 2nd, look up the category.
1622 for (const auto *Cat : visible_categories()) {
1623 for (auto *PI : Cat->protocols())
1624 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1628 // 3rd, look up the super class(s)
1629 if (IDecl->getSuperClass())
1631 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1637 //===----------------------------------------------------------------------===//
1639 //===----------------------------------------------------------------------===//
1641 void ObjCIvarDecl::anchor() { }
1643 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
1644 SourceLocation StartLoc,
1645 SourceLocation IdLoc, IdentifierInfo *Id,
1646 QualType T, TypeSourceInfo *TInfo,
1647 AccessControl ac, Expr *BW,
1650 // Ivar's can only appear in interfaces, implementations (via synthesized
1651 // properties), and class extensions (via direct declaration, or synthesized
1654 // FIXME: This should really be asserting this:
1655 // (isa<ObjCCategoryDecl>(DC) &&
1656 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1657 // but unfortunately we sometimes place ivars into non-class extension
1658 // categories on error. This breaks an AST invariant, and should not be
1660 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
1661 isa<ObjCCategoryDecl>(DC)) &&
1662 "Invalid ivar decl context!");
1663 // Once a new ivar is created in any of class/class-extension/implementation
1664 // decl contexts, the previously built IvarList must be rebuilt.
1665 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1667 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
1668 ID = IM->getClassInterface();
1670 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1672 ID->setIvarList(nullptr);
1675 return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
1679 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1680 return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(),
1681 nullptr, QualType(), nullptr,
1682 ObjCIvarDecl::None, nullptr, false);
1685 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
1686 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
1688 switch (DC->getKind()) {
1690 case ObjCCategoryImpl:
1692 llvm_unreachable("invalid ivar container!");
1694 // Ivars can only appear in class extension categories.
1695 case ObjCCategory: {
1696 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
1697 assert(CD->IsClassExtension() && "invalid container for ivar!");
1698 return CD->getClassInterface();
1701 case ObjCImplementation:
1702 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1705 return cast<ObjCInterfaceDecl>(DC);
1709 QualType ObjCIvarDecl::getUsageType(QualType objectType) const {
1710 return getType().substObjCMemberType(objectType, getDeclContext(),
1711 ObjCSubstitutionContext::Property);
1714 //===----------------------------------------------------------------------===//
1715 // ObjCAtDefsFieldDecl
1716 //===----------------------------------------------------------------------===//
1718 void ObjCAtDefsFieldDecl::anchor() { }
1721 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
1722 SourceLocation StartLoc, SourceLocation IdLoc,
1723 IdentifierInfo *Id, QualType T, Expr *BW) {
1724 return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
1727 ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
1729 return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(),
1730 SourceLocation(), nullptr, QualType(),
1734 //===----------------------------------------------------------------------===//
1736 //===----------------------------------------------------------------------===//
1738 void ObjCProtocolDecl::anchor() { }
1740 ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
1741 IdentifierInfo *Id, SourceLocation nameLoc,
1742 SourceLocation atStartLoc,
1743 ObjCProtocolDecl *PrevDecl)
1744 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
1745 redeclarable_base(C), Data() {
1746 setPreviousDecl(PrevDecl);
1748 Data = PrevDecl->Data;
1751 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
1753 SourceLocation nameLoc,
1754 SourceLocation atStartLoc,
1755 ObjCProtocolDecl *PrevDecl) {
1756 ObjCProtocolDecl *Result =
1757 new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl);
1758 Result->Data.setInt(!C.getLangOpts().Modules);
1762 ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
1764 ObjCProtocolDecl *Result =
1765 new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(),
1766 SourceLocation(), nullptr);
1767 Result->Data.setInt(!C.getLangOpts().Modules);
1771 ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
1772 ObjCProtocolDecl *PDecl = this;
1774 if (Name == getIdentifier())
1777 for (auto *I : protocols())
1778 if ((PDecl = I->lookupProtocolNamed(Name)))
1784 // lookupMethod - Lookup a instance/class method in the protocol and protocols
1786 ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
1787 bool isInstance) const {
1788 ObjCMethodDecl *MethodDecl = nullptr;
1790 // If there is no definition or the definition is hidden, we don't find
1792 const ObjCProtocolDecl *Def = getDefinition();
1793 if (!Def || Def->isHidden())
1796 if ((MethodDecl = getMethod(Sel, isInstance)))
1799 for (const auto *I : protocols())
1800 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
1805 void ObjCProtocolDecl::allocateDefinitionData() {
1806 assert(!Data.getPointer() && "Protocol already has a definition!");
1807 Data.setPointer(new (getASTContext()) DefinitionData);
1808 Data.getPointer()->Definition = this;
1811 void ObjCProtocolDecl::startDefinition() {
1812 allocateDefinitionData();
1814 // Update all of the declarations with a pointer to the definition.
1815 for (auto RD : redecls())
1816 RD->Data = this->Data;
1819 void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
1820 PropertyDeclOrder &PO) const {
1822 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1823 for (auto *Prop : PDecl->properties()) {
1824 // Insert into PM if not there already.
1825 PM.insert(std::make_pair(Prop->getIdentifier(), Prop));
1828 // Scan through protocol's protocols.
1829 for (const auto *PI : PDecl->protocols())
1830 PI->collectPropertiesToImplement(PM, PO);
1835 void ObjCProtocolDecl::collectInheritedProtocolProperties(
1836 const ObjCPropertyDecl *Property,
1837 ProtocolPropertyMap &PM) const {
1838 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1839 bool MatchFound = false;
1840 for (auto *Prop : PDecl->properties()) {
1841 if (Prop == Property)
1843 if (Prop->getIdentifier() == Property->getIdentifier()) {
1849 // Scan through protocol's protocols which did not have a matching property.
1851 for (const auto *PI : PDecl->protocols())
1852 PI->collectInheritedProtocolProperties(Property, PM);
1857 ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
1858 if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1859 return ObjCRTName->getMetadataName();
1864 //===----------------------------------------------------------------------===//
1866 //===----------------------------------------------------------------------===//
1868 void ObjCCategoryDecl::anchor() { }
1870 ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1871 SourceLocation ClassNameLoc,
1872 SourceLocation CategoryNameLoc,
1873 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1874 ObjCTypeParamList *typeParamList,
1875 SourceLocation IvarLBraceLoc,
1876 SourceLocation IvarRBraceLoc)
1877 : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1878 ClassInterface(IDecl), TypeParamList(nullptr),
1879 NextClassCategory(nullptr), CategoryNameLoc(CategoryNameLoc),
1880 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc)
1882 setTypeParamList(typeParamList);
1885 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
1886 SourceLocation AtLoc,
1887 SourceLocation ClassNameLoc,
1888 SourceLocation CategoryNameLoc,
1890 ObjCInterfaceDecl *IDecl,
1891 ObjCTypeParamList *typeParamList,
1892 SourceLocation IvarLBraceLoc,
1893 SourceLocation IvarRBraceLoc) {
1894 ObjCCategoryDecl *CatDecl =
1895 new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
1896 IDecl, typeParamList, IvarLBraceLoc,
1899 // Link this category into its class's category list.
1900 CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
1901 if (IDecl->hasDefinition()) {
1902 IDecl->setCategoryListRaw(CatDecl);
1903 if (ASTMutationListener *L = C.getASTMutationListener())
1904 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
1911 ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
1913 return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(),
1914 SourceLocation(), SourceLocation(),
1915 nullptr, nullptr, nullptr);
1918 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
1919 return getASTContext().getObjCImplementation(
1920 const_cast<ObjCCategoryDecl*>(this));
1923 void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
1924 getASTContext().setObjCImplementation(this, ImplD);
1927 void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) {
1928 TypeParamList = TPL;
1931 // Set the declaration context of each of the type parameters.
1932 for (auto typeParam : *TypeParamList)
1933 typeParam->setDeclContext(this);
1937 //===----------------------------------------------------------------------===//
1938 // ObjCCategoryImplDecl
1939 //===----------------------------------------------------------------------===//
1941 void ObjCCategoryImplDecl::anchor() { }
1943 ObjCCategoryImplDecl *
1944 ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
1946 ObjCInterfaceDecl *ClassInterface,
1947 SourceLocation nameLoc,
1948 SourceLocation atStartLoc,
1949 SourceLocation CategoryNameLoc) {
1950 if (ClassInterface && ClassInterface->hasDefinition())
1951 ClassInterface = ClassInterface->getDefinition();
1952 return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
1953 atStartLoc, CategoryNameLoc);
1956 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C,
1958 return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr,
1959 SourceLocation(), SourceLocation(),
1963 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
1964 // The class interface might be NULL if we are working with invalid code.
1965 if (const ObjCInterfaceDecl *ID = getClassInterface())
1966 return ID->FindCategoryDeclaration(getIdentifier());
1971 void ObjCImplDecl::anchor() { }
1973 void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
1974 // FIXME: The context should be correct before we get here.
1975 property->setLexicalDeclContext(this);
1979 void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
1980 ASTContext &Ctx = getASTContext();
1982 if (ObjCImplementationDecl *ImplD
1983 = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
1985 Ctx.setObjCImplementation(IFace, ImplD);
1987 } else if (ObjCCategoryImplDecl *ImplD =
1988 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
1989 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
1990 Ctx.setObjCImplementation(CD, ImplD);
1993 ClassInterface = IFace;
1996 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
1997 /// properties implemented in this \@implementation block and returns
1998 /// the implemented property that uses it.
2000 ObjCPropertyImplDecl *ObjCImplDecl::
2001 FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
2002 for (auto *PID : property_impls())
2003 if (PID->getPropertyIvarDecl() &&
2004 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
2009 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
2010 /// added to the list of those properties \@synthesized/\@dynamic in this
2011 /// category \@implementation block.
2013 ObjCPropertyImplDecl *ObjCImplDecl::
2014 FindPropertyImplDecl(IdentifierInfo *Id) const {
2015 for (auto *PID : property_impls())
2016 if (PID->getPropertyDecl()->getIdentifier() == Id)
2021 raw_ostream &clang::operator<<(raw_ostream &OS,
2022 const ObjCCategoryImplDecl &CID) {
2023 OS << CID.getName();
2027 //===----------------------------------------------------------------------===//
2028 // ObjCImplementationDecl
2029 //===----------------------------------------------------------------------===//
2031 void ObjCImplementationDecl::anchor() { }
2033 ObjCImplementationDecl *
2034 ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
2035 ObjCInterfaceDecl *ClassInterface,
2036 ObjCInterfaceDecl *SuperDecl,
2037 SourceLocation nameLoc,
2038 SourceLocation atStartLoc,
2039 SourceLocation superLoc,
2040 SourceLocation IvarLBraceLoc,
2041 SourceLocation IvarRBraceLoc) {
2042 if (ClassInterface && ClassInterface->hasDefinition())
2043 ClassInterface = ClassInterface->getDefinition();
2044 return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
2045 nameLoc, atStartLoc, superLoc,
2046 IvarLBraceLoc, IvarRBraceLoc);
2049 ObjCImplementationDecl *
2050 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2051 return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr,
2052 SourceLocation(), SourceLocation());
2055 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
2056 CXXCtorInitializer ** initializers,
2057 unsigned numInitializers) {
2058 if (numInitializers > 0) {
2059 NumIvarInitializers = numInitializers;
2060 CXXCtorInitializer **ivarInitializers =
2061 new (C) CXXCtorInitializer*[NumIvarInitializers];
2062 memcpy(ivarInitializers, initializers,
2063 numInitializers * sizeof(CXXCtorInitializer*));
2064 IvarInitializers = ivarInitializers;
2068 ObjCImplementationDecl::init_const_iterator
2069 ObjCImplementationDecl::init_begin() const {
2070 return IvarInitializers.get(getASTContext().getExternalSource());
2073 raw_ostream &clang::operator<<(raw_ostream &OS,
2074 const ObjCImplementationDecl &ID) {
2079 //===----------------------------------------------------------------------===//
2080 // ObjCCompatibleAliasDecl
2081 //===----------------------------------------------------------------------===//
2083 void ObjCCompatibleAliasDecl::anchor() { }
2085 ObjCCompatibleAliasDecl *
2086 ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
2089 ObjCInterfaceDecl* AliasedClass) {
2090 return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
2093 ObjCCompatibleAliasDecl *
2094 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2095 return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(),
2099 //===----------------------------------------------------------------------===//
2101 //===----------------------------------------------------------------------===//
2103 void ObjCPropertyDecl::anchor() { }
2105 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
2108 SourceLocation AtLoc,
2109 SourceLocation LParenLoc,
2111 TypeSourceInfo *TSI,
2112 PropertyControl propControl) {
2113 return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI,
2117 ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
2119 return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr,
2120 SourceLocation(), SourceLocation(),
2121 QualType(), nullptr, None);
2124 QualType ObjCPropertyDecl::getUsageType(QualType objectType) const {
2125 return DeclType.substObjCMemberType(objectType, getDeclContext(),
2126 ObjCSubstitutionContext::Property);
2129 //===----------------------------------------------------------------------===//
2130 // ObjCPropertyImplDecl
2131 //===----------------------------------------------------------------------===//
2133 ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
2135 SourceLocation atLoc,
2137 ObjCPropertyDecl *property,
2140 SourceLocation ivarLoc) {
2141 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
2145 ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
2147 return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(),
2148 SourceLocation(), nullptr, Dynamic,
2149 nullptr, SourceLocation());
2152 SourceRange ObjCPropertyImplDecl::getSourceRange() const {
2153 SourceLocation EndLoc = getLocation();
2154 if (IvarLoc.isValid())
2157 return SourceRange(AtLoc, EndLoc);