Lines Matching defs:property
1 //===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
10 // This file implements semantic analysis for Objective C @property and
33 /// getImpliedARCOwnership - Given a set of property attributes and a
55 // property type.
64 /// Check the internal consistency of a property declaration with
67 ObjCPropertyDecl *property) {
68 if (property->isInvalidDecl()) return;
71 = property->getPropertyAttributes();
73 = property->getType().getObjCLifetime();
78 = getImpliedARCOwnership(propertyKind, property->getType());
80 // We have a lifetime qualifier but no dominating property
82 // setting the property attribute according to the lifetime
93 property->setPropertyAttributes(attr);
99 property->setInvalidDecl();
100 S.Diag(property->getLocation(),
102 << property->getDeclName()
107 /// \brief Check this Objective-C property against a property declared in the
117 // Look for a property with the same name.
126 // Check this property against any protocols we inherit.
222 // Validate the attributes on the @property.
233 // For a class, compare the property against a property in our superclass.
252 // Also compare the property against a property in our protocols.
265 // when property in class extension is constructed.
354 // Determine whether the given property is readonly and implicitly
356 auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
358 auto Attrs = Property->getPropertyAttributes();
365 if (Property->getPropertyAttributesAsWritten() &
372 // If we're allowed to propagate atomicity, and the new property did
389 // One of the properties is atomic; if it's a readonly property, and
422 // Diagnose if this property is already in continuation class.
427 // We need to look in the @interface to see if the @property was
434 // Find the property in the extended class's primary class or
439 // If we found a property in an extension, complain.
448 // A readonly property declared in the primary class can be refined
449 // by adding a readwrite property within an extension.
453 // property is declared both in the @interface and the continuation.
493 // Take the ownership from the original property.
497 // If the redeclaration is 'weak' but the original property is not,
516 // If there was no declaration of a property with the same name in
526 // Relax the strict type matching for property type in continuation class.
527 // Allow property object type of continuation class to be different as long
528 // as it narrows the object type in its primary class property. Note that
530 // property in primary class and 'narrowed' type for a 'readwrite' property
546 // Check that atomicity of property in class extension matches the previous
571 // Property defaults to 'assign' if it is readwrite, unless this is ARC
584 // Issue a warning if property is 'assign' as default and its
698 ObjCPropertyDecl *property,
700 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
705 // The lifetime implied by the property's attributes.
707 getImpliedARCOwnership(property->getPropertyAttributes(),
708 property->getType());
723 // property implementation before parsing any method bodies.
740 << property->getDeclName()
747 << property->getDeclName()
753 << property->getDeclName()
755 << ((property->getPropertyAttributesAsWritten()
763 // Any other property should be ignored.
767 S.Diag(property->getLocation(), diag::note_property_declare);
774 /// property with no known lifetime of its own, using backing
775 /// 'ivar's attribute, if any. If no backing 'ivar', property's
778 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
780 getImpliedARCOwnership(property->getPropertyAttributes(),
781 property->getType());
786 // if no backing ivar, make property 'strong'.
787 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
790 // property assumes owenership of backing ivar.
794 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
796 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_weak);
806 ObjCPropertyDecl *Property) {
810 PDecl->collectInheritedProtocolProperties(Property, PropMap);
816 PDecl->collectInheritedProtocolProperties(Property, PropMap);
824 QualType RHSType = S.Context.getCanonicalType(Property->getType());
836 S.Diag(Property->getLocation(), diag::warn_protocol_property_mismatch)
837 << Property->getType();
849 /// Determine whether any storage attributes were written on the property.
853 // If this is a readwrite property in a class extension that refines
854 // a readonly property in the original class definition, check it as
857 // If it's a readonly property, we're not interested.
864 // Find the corresponding property in the primary class definition.
882 /// builds the AST node for a property implementation declaration; declared
894 // Make sure we have a context for the property implementation declaration.
904 ObjCPropertyDecl *property = nullptr;
906 // Find the class or category class where this property must have
917 // Look for this property declaration in the @implementation's @interface
918 property = IDecl->FindPropertyDeclaration(PropertyId);
919 if (!property) {
923 unsigned PIkind = property->getPropertyAttributesAsWritten();
930 Diag(property->getLocation(), diag::note_property_declare);
934 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
937 Diag(property->getLocation(), diag::note_property_declare);
943 property->hasAttr<IBOutletAttr>() &&
946 // Search into the class extensions and see if 'readonly property is
949 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
961 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
962 << property;
965 property->getLParenLoc(), readonlyLoc)) {
969 Diag(property->getLocation(),
975 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
976 DiagnosePropertyMismatchDeclInProtocols(*this, AtLoc, IDecl, property);
995 // Look for this property declaration in @implementation's category
996 property = Category->FindPropertyDeclaration(PropertyId);
997 if (!property) {
1017 QualType PropType = property->getType();
1022 property->getDeclName())) {
1023 Diag(property->getLocation(), diag::note_property_declare);
1028 (property->getPropertyAttributesAsWritten() &
1031 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
1035 = property->getPropertyAttributes();
1039 // Add GC __weak to the ivar type if the property is weak.
1044 Diag(property->getLocation(), diag::note_property_declare);
1051 // the property type.
1060 Diag(property->getLocation(), diag::note_property_declare);
1069 Diag(property->getLocation(),
1081 // Check when default synthesizing a property that there is
1082 // an ivar matching property name and issue warning; since this
1084 // property in non-default synthesis case.
1087 IDecl->lookupInstanceVariable(property->getIdentifier(),
1094 Diag(property->getLocation(), diag::note_property_declare);
1101 // property attributes.
1107 // explicitly write an ownership attribute on the property.
1108 if (!hasWrittenStorageAttribute(property) &&
1112 Diag(property->getLocation(), diag::note_property_declare);
1116 assert(lifetime && "no lifetime for property?");
1133 Diag(property->getLocation(), diag::note_property_declare);
1144 // a property implementation and to avoid future warnings.
1148 << property->getDeclName() << Ivar->getDeclName()
1154 property->setPropertyIvarDecl(Ivar);
1158 // Check that type of property and its ivar are type compatible.
1173 << property->getDeclName() << PropType
1177 // a property implementation and to avoid future warnings.
1182 // specifically for property redeclarations as well as for ivars.
1188 << property->getDeclName() << PropType
1198 << property->getDeclName() << Ivar->getDeclName();
1203 if ((property->getType()->isObjCObjectPointerType() ||
1207 << property->getDeclName() << Ivar->getDeclName();
1213 checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
1218 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1221 property,
1230 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1265 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1269 Diag(property->getLocation(), diag::note_property_declare);
1284 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1313 if (property->getPropertyAttributes() &
1320 if (property->getType()->isReferenceType()) {
1323 << property->getType();
1353 // use and if 1) property is @dynamic or 2) property is synthesized
1401 Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1406 Property->getPropertyAttributes();
1412 // to be overridden by a property with any explicit ownership in the subclass.
1419 Diag(Property->getLocation(), diag::warn_readonly_property)
1420 << Property->getDeclName() << inheritedName;
1423 Diag(Property->getLocation(), diag::warn_property_attribute)
1424 << Property->getDeclName() << "copy" << inheritedName;
1435 Diag(Property->getLocation(), diag::warn_property_attribute)
1436 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1442 // atomic property is 'readonly'.
1443 checkAtomicPropertyMismatch(*this, SuperProperty, Property, false);
1444 if (Property->getSetterName() != SuperProperty->getSetterName()) {
1445 Diag(Property->getLocation(), diag::warn_property_attribute)
1446 << Property->getDeclName() << "setter" << inheritedName;
1449 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1450 Diag(Property->getLocation(), diag::warn_property_attribute)
1451 << Property->getDeclName() << "getter" << inheritedName;
1458 Context.getCanonicalType(Property->getType());
1462 // FIXME. For future support of covariant property types, revisit this.
1468 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1469 << Property->getType() << SuperProperty->getType() << inheritedName;
1475 bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1481 QualType PropertyIvarType = property->getType().getNonReferenceType();
1492 << property->getDeclName() << PropertyIvarType
1507 << property->getDeclName()
1549 // Exclude property for protocols which conform to class's super-class,
1550 // as super-class has to implement the property.
1579 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1591 // look up a property declaration whose one of its accessors is implemented
1593 for (const auto *Property : IFace->properties()) {
1594 if ((Property->getGetterName() == IMD->getSelector() ||
1595 Property->getSetterName() == IMD->getSelector()) &&
1596 (Property->getPropertyIvarDecl() == IV))
1599 // Also look up property declaration in class extension whose one of its
1602 for (const auto *Property : Ext->properties())
1603 if ((Property->getGetterName() == IMD->getSelector() ||
1604 Property->getSetterName() == IMD->getSelector()) &&
1605 (Property->getPropertyIvarDecl() == IV))
1646 // Is there a matching property synthesize/dynamic?
1650 // Property may have been synthesized by user.
1671 // Suppress the warning if class's superclass implements property's
1672 // getter and implements property's setter (if readwrite property).
1673 // Or, if property is going to be implemented in its super class.
1682 // If property to be implemented in the super class, ignore.
1708 /* property = */ Prop->getIdentifier(),
1737 // When reporting on missing property setter/getter implementation in
1772 // its primary class (and its super classes) if property is
1825 // Collect property accessors implemented in current implementation.
1864 const auto *property = propertyImpl->getPropertyDecl();
1870 (property->getPropertyAttributes() &
1872 property->getGetterMethodDecl() &&
1873 property->getSetterMethodDecl()) {
1874 auto *getterMethod = property->getGetterMethodDecl();
1875 auto *setterMethod = property->getSetterMethodDecl();
1883 << setterMethod->getSelector() << property->getDeclName();
1904 const ObjCPropertyDecl *Property = I->second;
1909 unsigned Attributes = Property->getPropertyAttributes();
1910 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
1914 GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName());
1915 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1920 << Property->getIdentifier() << 0;
1921 Diag(Property->getLocation(), diag::note_property_declare);
1926 << Property->getIdentifier() << 1;
1927 Diag(Property->getLocation(), diag::note_property_declare);
1931 // We only care about readwrite atomic property.
1936 = IMPDecl->FindPropertyImplDecl(Property->getIdentifier())) {
1940 Property->getGetterName());
1941 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1948 << Property->getIdentifier() << (GetterMethod != nullptr)
1951 if (Property->getLParenLoc().isValid() &&
1953 // @property () ... case.
1955 getLocForEndOfToken(Property->getLParenLoc());
1958 Diag(Property->getLocation(),
1961 } else if (Property->getLParenLoc().isInvalid()) {
1962 //@property id etc.
1964 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
1965 Diag(Property->getLocation(),
1971 Diag(Property->getLocation(), diag::note_property_declare);
1996 // Look for a getter explicitly declared alongside the property.
2066 /// AddPropertyAttrs - Propagates attributes from a property to the
2067 /// implicitly-declared getter or setter for that property.
2069 ObjCPropertyDecl *Property) {
2071 for (const auto *A : Property->attrs()) {
2080 /// have the property type and issue diagnostics if they don't.
2083 void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) {
2085 ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2089 GetterMethod = CD->getInstanceMethod(property->getGetterName());
2096 getInstanceMethod(property->getGetterName());
2098 SetterMethod = CD->getInstanceMethod(property->getSetterName());
2103 getInstanceMethod(property->getSetterName());
2104 DiagnosePropertyAccessorMismatch(property, GetterMethod,
2105 property->getLocation());
2109 property->getPropertyAttributes();
2117 property->getType().getNonReferenceType())) {
2118 Diag(property->getLocation(),
2120 << property->getDeclName()
2128 // FIXME: The synthesized property we set here is misleading. We almost always
2133 // No instance method of same name as property getter name was found.
2136 SourceLocation Loc = property->getLocation();
2138 // If the property is null_resettable, the getter returns nonnull.
2139 QualType resultTy = property->getType();
2140 if (property->getPropertyAttributes() &
2151 property->getGetterName(),
2156 (property->getPropertyImplementation() ==
2162 AddPropertyAttrs(*this, GetterMethod, property);
2164 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2168 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2172 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2181 // the property with the same name is seen in the @implementation
2183 property->setGetterMethodDecl(GetterMethod);
2185 // Skip setter if property is read-only.
2186 if (!property->isReadOnly()) {
2189 // No instance method of same name as property setter name was found.
2192 SourceLocation Loc = property->getLocation();
2196 property->getSetterName(), Context.VoidTy,
2202 (property->getPropertyImplementation() ==
2207 // If the property is null_resettable, the setter accepts a
2209 QualType paramTy = property->getType().getUnqualifiedType();
2210 if (property->getPropertyAttributes() &
2224 property->getIdentifier(),
2231 AddPropertyAttrs(*this, SetterMethod, property);
2234 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2244 // the property with the same name is seen in the @implementation
2246 property->setSetterMethodDecl(SetterMethod);
2252 // @property double bar;
2400 // Warn if user supplied no assignment attribute, property is
2406 // With arc, @property definitions should default to strong when
2418 // Don't issue warning on property with no life time in class
2419 // extension as it is inherited from property in primary class.