Lines Matching +full:bool +full:- +full:property
1 //===- DeclObjC.cpp - ObjC Declaration AST Node Implementation ------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Objective-C related Decl classes.
11 //===----------------------------------------------------------------------===//
41 //===----------------------------------------------------------------------===//
43 //===----------------------------------------------------------------------===//
64 //===----------------------------------------------------------------------===//
66 //===----------------------------------------------------------------------===//
78 /// getIvarDecl - This method looks up an ivar in this ContextDecl.
93 ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
94 bool AllowHidden) const {
98 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
99 if (!Def->isUnconditionallyVisible() && !AllowHidden)
107 // - (int) class_method;
114 if (MD && MD->isInstanceMethod() == isInstance)
123 /// property. This is because, user must provide a setter method for the
124 /// category's 'readwrite' property.
125 bool ObjCContainerDecl::HasUserDeclaredSetterMethod(
126 const ObjCPropertyDecl *Property) const {
127 Selector Sel = Property->getSetterName();
132 if (MD && MD->isInstanceMethod() && !MD->isImplicit())
139 for (const auto *Cat : ID->visible_categories()) {
140 if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel))
141 if (!MD->isImplicit())
143 if (Cat->IsClassExtension())
146 // declaration of this property. If one found, presumably a setter will
148 // auto-synthesized).
149 for (const auto *P : Cat->properties())
150 if (P->getIdentifier() == Property->getIdentifier()) {
151 if (P->getPropertyAttributes() &
159 for (const auto *Proto : ID->all_referenced_protocols())
160 if (Proto->HasUserDeclaredSetterMethod(Property))
164 ObjCInterfaceDecl *OSC = ID->getSuperClass();
166 if (OSC->HasUserDeclaredSetterMethod(Property))
168 OSC = OSC->getSuperClass();
172 for (const auto *PI : PD->protocols())
173 if (PI->HasUserDeclaredSetterMethod(Property))
183 // property.
185 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
186 if (!Def->isUnconditionallyVisible())
190 // If context is class, then lookup property in its visible extensions.
191 // This comes before property is looked up in primary class.
193 for (const auto *Ext : IDecl->visible_extensions())
200 DeclContext::lookup_result R = DC->lookup(propertyID);
205 // If queryKind is unknown, we return the instance property if one
206 // exists; otherwise we return the class property.
208 !PD->isClassProperty()) ||
210 PD->isClassProperty()) ||
212 !PD->isClassProperty()))
215 if (PD->isClassProperty())
220 // We can't find the instance property, return the class property.
231 os << '_' << getIdentifier()->getName();
237 bool IsInstance) const {
240 if (Prop->isInstanceProperty() == IsInstance) {
248 /// FindPropertyDeclaration - Finds declaration of the property given its name
255 if (const ObjCProtocolDecl *Def = Proto->getDefinition())
256 if (!Def->isUnconditionallyVisible())
263 for (const auto *Ext : ClassDecl->visible_extensions()) {
264 if (auto *P = Ext->FindPropertyDeclaration(PropertyId, QueryKind))
279 for (const auto *I : PID->protocols())
280 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
288 for (const auto *Cat : OID->visible_categories()) {
289 if (!Cat->IsClassExtension())
290 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(
296 for (const auto *I : OID->all_referenced_protocols())
297 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
302 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
303 return superClass->FindPropertyDeclaration(PropertyId, QueryKind);
309 if (!OCD->IsClassExtension())
310 for (const auto *I : OCD->protocols())
311 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
329 return def->getTypeParamListAsWritten();
335 decl = decl->getPreviousDecl()) {
336 if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten())
349 typeParam->setDeclContext(this);
361 if (ObjCInterfaceDecl *superDecl = superType->getInterface()) {
362 if (ObjCInterfaceDecl *superDef = superDecl->getDefinition())
374 return superTInfo->getTypeLoc().getBeginLoc();
379 /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
398 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
407 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
411 for (auto *Prop : ClassExt->properties()) {
412 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
416 PI->collectPropertiesToImplement(PM);
418 // into the main @interface's property list, and therefore we don't
422 bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const {
425 if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
427 Class = Class->getSuperClass();
435 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
437 Class = Class->getSuperClass();
459 bool protocolExists = false;
487 if (IFace->hasDesignatedInitializers())
489 if (!IFace->inheritsDesignatedInitializers())
491 IFace = IFace->getSuperClass();
496 static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
497 for (const auto *MD : D->instance_methods()) {
498 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
501 for (const auto *Ext : D->visible_extensions()) {
502 for (const auto *MD : Ext->instance_methods()) {
503 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
507 if (const auto *ImplD = D->getImplementation()) {
508 for (const auto *MD : ImplD->instance_methods()) {
509 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
516 bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
531 SuperD->declaresOrInheritsDesignatedInitializers() ?
560 for (const auto *MD : IFace->instance_methods())
561 if (MD->isThisDeclarationADesignatedInitializer())
563 for (const auto *Ext : IFace->visible_extensions()) {
564 for (const auto *MD : Ext->instance_methods())
565 if (MD->isThisDeclarationADesignatedInitializer())
570 bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel,
572 bool HasCompleteDef = isThisDeclarationADefinition();
576 if (!HasCompleteDef && getCanonicalDecl()->hasDefinition() &&
577 getCanonicalDecl()->getDefinition() == getDefinition())
591 if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) {
592 if (MD->isThisDeclarationADesignatedInitializer()) {
598 for (const auto *Ext : IFace->visible_extensions()) {
599 if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) {
600 if (MD->isThisDeclarationADesignatedInitializer()) {
613 Data.getPointer()->Definition = this;
622 RD->Data = Data;
634 Data = Definition->Data;
648 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
653 for (const auto *Ext : ClassDecl->visible_extensions()) {
654 if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) {
660 ClassDecl = ClassDecl->getSuperClass();
665 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
679 if (ClassDecl->getIdentifier() == ICName)
681 ClassDecl = ClassDecl->getSuperClass();
689 if (P->lookupProtocolNamed(Name))
692 return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr;
695 /// lookupMethod - This method returns an instance/class method by looking in
700 bool isInstance,
701 bool shallowCategoryLookup,
702 bool followSuper,
717 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
720 // 2. Didn't find one yet - now look through categories.
721 for (const auto *Cat : ClassDecl->visible_categories())
722 if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
723 if (C != Cat || !MethodDecl->isImplicit())
726 // 3. Didn't find one yet - look through primary class's protocols.
727 for (const auto *I : ClassDecl->protocols())
728 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
731 // 4. Didn't find one yet - now look through categories' protocols
733 for (const auto *Cat : ClassDecl->visible_categories()) {
734 // Didn't find one yet - look through protocols.
736 Cat->getReferencedProtocols();
738 if ((MethodDecl = Protocol->lookupMethod(Sel, isInstance)))
739 if (C != Cat || !MethodDecl->isImplicit())
748 ClassDecl = ClassDecl->getSuperClass();
758 bool Instance) const {
768 Method = Instance ? ImpDecl->getInstanceMethod(Sel)
769 : ImpDecl->getClassMethod(Sel);
787 return getSuperClass()->lookupPrivateMethod(Sel, Instance);
807 bool ObjCInterfaceDecl::hasODRHash() const {
813 void ObjCInterfaceDecl::setHasODRHash(bool HasHash) {
818 //===----------------------------------------------------------------------===//
820 //===----------------------------------------------------------------------===//
825 bool isInstance, bool isVariadic, bool isPropertyAccessor,
826 bool isSynthesizedAccessorStub, bool isImplicitlyDeclared, bool isDefined,
827 ObjCImplementationControl impControl, bool HasRelatedResultType)
855 DeclContext *contextDecl, bool isInstance, bool isVariadic,
856 bool isPropertyAccessor, bool isSynthesizedAccessorStub,
857 bool isImplicitlyDeclared, bool isDefined,
858 ObjCImplementationControl impControl, bool HasRelatedResultType) {
871 bool ObjCMethodDecl::isDirectMethod() const {
876 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
881 bool ObjCMethodDecl::definedInNSObject(const ASTContext &Ctx) const {
883 return PD->getIdentifier() == Ctx.getNSObjectName();
885 return ID->getIdentifier() == Ctx.getNSObjectName();
889 bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
897 return ID->isDesignatedInitializer(getSelector(), InitMethod);
901 bool ObjCMethodDecl::hasParamDestroyedInCallee() const {
903 if (param->isDestroyedInCallee())
917 PrevMethod->setHasRedeclaration(true);
948 "No selector locs for non-implicit method");
973 if (!CtxD->isInvalidDecl()) {
976 if (!ImplD->isInvalidDecl())
977 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
981 if (!ImplD->isInvalidDecl())
982 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
985 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
986 if (!IFD->isInvalidDecl())
987 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
990 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
991 if (!CatD->isInvalidDecl())
992 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
999 if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl())
1004 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
1017 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) {
1024 if (ObjCMethodDecl *MD = IFD->getMethod(Sel, isInstanceMethod()))
1026 for (auto *Ext : IFD->known_extensions())
1027 if (ObjCMethodDecl *MD = Ext->getMethod(Sel, isInstanceMethod()))
1031 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
1032 if (ObjCMethodDecl *MD = CatD->getMethod(Sel, isInstanceMethod()))
1039 cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod(),
1049 return Body->getEndLoc();
1062 switch (attr->getFamily()) {
1081 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
1091 if (!getReturnType()->isObjCObjectPointerType())
1108 if (isInstanceMethod() || !getReturnType()->isVoidType())
1113 if (!isInstanceMethod() || !getReturnType()->isObjCIdType())
1122 if (!ArgT->isObjCSelType()) {
1126 while (--noParams) {
1129 if (!ArgT->isObjCIdType()) {
1147 bool &selfIsPseudoStrong,
1148 bool &selfIsConsumed) const {
1168 // 'self' is always __strong. It's actually pseudo-strong except
1192 bool selfIsPseudoStrong, selfIsConsumed;
1201 Self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1204 Self->setARCPseudoStrong(true);
1215 return CD->getClassInterface();
1217 return IMD->getClassInterface();
1227 return IMD->getCategoryDecl();
1234 return TSI->getTypeLoc().getSourceRange();
1255 bool MovedToSuper) {
1267 Overridden = Container->getMethod(Method->getSelector(),
1268 Method->isInstanceMethod(),
1277 for (const auto *P : Category->protocols())
1284 Overridden = Container->getMethod(Method->getSelector(),
1285 Method->isInstanceMethod(),
1295 for (const auto *P : Protocol->protocols())
1300 for (const auto *P : Interface->protocols())
1303 for (const auto *Cat : Interface->known_categories())
1306 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1321 assert(Method->isOverriding());
1324 dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1328 dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1329 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1334 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1335 Method->isInstanceMethod(),
1341 dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1342 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1347 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1348 Method->isInstanceMethod(),
1355 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1364 if (Method->isRedeclaration()) {
1365 Method = cast<ObjCContainerDecl>(Method->getDeclContext())
1366 ->getMethod(Method->getSelector(), Method->isInstanceMethod(),
1370 if (Method->isOverriding()) {
1378 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1389 Container = ImplDecl->getClassInterface();
1391 bool IsGetter = (NumArgs == 0);
1392 bool IsInstance = isInstanceMethod();
1394 /// Local function that attempts to find a matching property within the
1395 /// given Objective-C container.
1397 [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {
1399 for (const auto *I : Container->instance_properties()) {
1400 Selector NextSel = IsGetter ? I->getGetterName()
1401 : I->getSetterName();
1406 for (const auto *I : Container->class_properties()) {
1407 Selector NextSel = IsGetter ? I->getGetterName()
1408 : I->getSetterName();
1424 ClassDecl = Category->getClassInterface();
1434 for (const auto *Ext : ClassDecl->visible_extensions()) {
1443 for (const auto *Cat : ClassDecl->known_categories()) {
1450 llvm_unreachable("Marked as a property accessor but no property found!");
1461 if (const ObjCPropertyDecl *Prop = Override->findPropertyDecl(false))
1467 //===----------------------------------------------------------------------===//
1469 //===----------------------------------------------------------------------===//
1485 TPDecl->setTypeForDecl(TPType.getTypePtr());
1504 getTypeSourceInfo()->getTypeLoc().getEndLoc());
1510 //===----------------------------------------------------------------------===//
1512 //===----------------------------------------------------------------------===//
1535 typeArgs.push_back(typeParam->getUnderlyingType());
1538 //===----------------------------------------------------------------------===//
1540 //===----------------------------------------------------------------------===//
1545 ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc, bool isInternal) {
1549 Result->Data.setInt(!C.getLangOpts().Modules);
1559 Result->Data.setInt(!C.getLangOpts().Modules);
1566 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl, bool IsInternal)
1573 Data = PrevDecl->Data;
1583 getASTContext().getExternalSource()->CompleteType(
1602 bool ObjCInterfaceDecl::hasDesignatedInitializers() const {
1615 return ObjCRTName->getMetadataName();
1623 const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1624 return ID->getObjCRuntimeNameAsString();
1656 bool operator<(const SynthesizeIvarChunk & LHS,
1663 /// all_declared_ivar_begin - return first ivar declared in this class,
1682 (void)Ext->ivar_empty();
1688 curIvar->setNextIvar(*I);
1692 if (!Ext->ivar_empty()) {
1694 I = Ext->ivar_begin(),
1695 E = Ext->ivar_end();
1701 curIvar->setNextIvar(*I);
1713 if (!ImplDecl->ivar_empty()) {
1715 for (auto *IV : ImplDecl->ivars()) {
1716 if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1718 IV->getASTContext().getTypeSize(IV->getType()), IV));
1724 curIvar->setNextIvar(IV);
1737 curIvar->setNextIvar(layout[Ix].Ivar);
1744 /// FindCategoryDeclaration - Finds category declaration in the list of
1758 if (Cat->getIdentifier() == CategoryId)
1767 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1768 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1777 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1778 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1785 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1788 bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1789 bool lookupCategory,
1790 bool RHSIsQualifiedID) {
1796 for (auto *PI : IDecl->protocols()){
1800 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1813 for (auto *PI : Cat->protocols())
1819 if (IDecl->getSuperClass())
1821 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1827 //===----------------------------------------------------------------------===//
1829 //===----------------------------------------------------------------------===//
1838 Expr *BW, bool synthesized) {
1846 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1847 // but unfortunately we sometimes place ivars into non-class extension
1853 // Once a new ivar is created in any of class/class-extension/implementation
1858 ID = IM->getClassInterface();
1860 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1862 ID->setIvarList(nullptr);
1878 switch (DC->getKind()) {
1887 assert(CD->IsClassExtension() && "invalid container for ivar!");
1888 return CD->getClassInterface();
1892 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1901 ObjCSubstitutionContext::Property);
1904 //===----------------------------------------------------------------------===//
1906 //===----------------------------------------------------------------------===//
1924 //===----------------------------------------------------------------------===//
1926 //===----------------------------------------------------------------------===//
1938 Data = PrevDecl->Data;
1948 Result->Data.setInt(!C.getLangOpts().Modules);
1957 Result->Data.setInt(!C.getLangOpts().Modules);
1961 bool ObjCProtocolDecl::isNonRuntimeProtocol() const {
1973 for (const auto *Parent : PD->protocols()) {
1974 const auto *Can = Parent->getCanonicalDecl();
1989 if ((PDecl = I->lookupProtocolNamed(Name)))
1995 // lookupMethod - Lookup a instance/class method in the protocol and protocols
1998 bool isInstance) const {
2004 if (!Def || !Def->isUnconditionallyVisible())
2011 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
2019 Data.getPointer()->Definition = this;
2020 Data.getPointer()->HasODRHash = false;
2028 RD->Data = this->Data;
2039 Data = Definition->Data;
2044 for (auto *Prop : PDecl->properties()) {
2047 std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()),
2051 for (const auto *PI : PDecl->protocols())
2052 PI->collectPropertiesToImplement(PM);
2057 const ObjCPropertyDecl *Property, ProtocolPropertySet &PS,
2062 for (auto *Prop : PDecl->properties()) {
2063 if (Prop == Property)
2065 if (Prop->getIdentifier() == Property->getIdentifier()) {
2070 // Scan through protocol's protocols which did not have a matching property.
2071 for (const auto *PI : PDecl->protocols())
2072 PI->collectInheritedProtocolProperties(Property, PS, PO);
2079 return ObjCRTName->getMetadataName();
2100 bool ObjCProtocolDecl::hasODRHash() const {
2106 void ObjCProtocolDecl::setHasODRHash(bool HasHash) {
2111 //===----------------------------------------------------------------------===//
2113 //===----------------------------------------------------------------------===//
2140 CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
2141 if (IDecl->hasDefinition()) {
2142 IDecl->setCategoryListRaw(CatDecl);
2144 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
2173 typeParam->setDeclContext(this);
2176 //===----------------------------------------------------------------------===//
2178 //===----------------------------------------------------------------------===//
2186 if (ClassInterface && ClassInterface->hasDefinition())
2187 ClassInterface = ClassInterface->getDefinition();
2202 return ID->FindCategoryDeclaration(getIdentifier());
2208 void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
2210 property->setLexicalDeclContext(this);
2211 addDecl(property);
2222 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
2229 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
2231 /// the implemented property that uses it.
2235 if (PID->getPropertyIvarDecl() &&
2236 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
2241 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
2249 // If queryKind is unknown, we return the instance property if one
2250 // exists; otherwise we return the class property.
2251 if (PID->getPropertyDecl()->getIdentifier() == Id) {
2253 !PID->getPropertyDecl()->isClassProperty()) ||
2255 PID->getPropertyDecl()->isClassProperty()) ||
2257 !PID->getPropertyDecl()->isClassProperty()))
2260 if (PID->getPropertyDecl()->isClassProperty())
2265 // We can't find the instance property, return the class property.
2277 //===----------------------------------------------------------------------===//
2279 //===----------------------------------------------------------------------===//
2292 if (ClassInterface && ClassInterface->hasDefinition())
2293 ClassInterface = ClassInterface->getDefinition();
2328 //===----------------------------------------------------------------------===//
2330 //===----------------------------------------------------------------------===//
2348 //===----------------------------------------------------------------------===//
2350 //===----------------------------------------------------------------------===//
2372 ObjCSubstitutionContext::Property);
2375 bool ObjCPropertyDecl::isDirectProperty() const {
2380 //===----------------------------------------------------------------------===//
2382 //===----------------------------------------------------------------------===//
2388 ObjCPropertyDecl *property,
2392 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,