Lines Matching full:property
1 //===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
9 // This file implements semantic analysis for Objective C @property and
33 /// getImpliedARCOwnership - Given a set of property attributes and a
54 // property type.
63 /// Check the internal consistency of a property declaration with
66 ObjCPropertyDecl *property) {
67 if (property->isInvalidDecl()) return;
69 ObjCPropertyAttribute::Kind propertyKind = property->getPropertyAttributes();
71 = property->getType().getObjCLifetime();
76 = getImpliedARCOwnership(propertyKind, property->getType());
78 // We have a lifetime qualifier but no dominating property
80 // setting the property attribute according to the lifetime
91 property->setPropertyAttributes(attr);
97 property->setInvalidDecl();
98 S.Diag(property->getLocation(),
100 << property->getDeclName()
105 /// Check this Objective-C property against a property declared in the
115 // Look for a property with the same name.
123 // Check this property against any protocols we inherit.
219 // Validate the attributes on the @property.
230 // For a class, compare the property against a property in our superclass.
244 // Also compare the property against a property in our protocols.
257 // when property in class extension is constructed.
347 // Determine whether the given property is readonly and implicitly
349 auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
351 auto Attrs = Property->getPropertyAttributes();
360 if (Property->getPropertyAttributesAsWritten() &
367 // If we're allowed to propagate atomicity, and the new property did
384 // One of the properties is atomic; if it's a readonly property, and
411 // Diagnose if this property is already in continuation class.
416 // We need to look in the @interface to see if the @property was
427 // Find the property in the extended class's primary class or
432 // If we found a property in an extension, complain.
441 // A readonly property declared in the primary class can be refined
442 // by adding a readwrite property within an extension.
446 // property is declared both in the @interface and the continuation.
486 // Take the ownership from the original property.
490 // If the redeclaration is 'weak' but the original property is not,
510 // If there was no declaration of a property with the same name in
520 // Relax the strict type matching for property type in continuation class.
521 // Allow property object type of continuation class to be different as long
522 // as it narrows the object type in its primary class property. Note that
524 // property in primary class and 'narrowed' type for a 'readwrite' property
541 // Check that atomicity of property in class extension matches the previous
561 // Property defaults to 'assign' if it is readwrite, unless this is ARC
574 // Issue a warning if property is 'assign' as default and its
608 // Class property and instance property can have the same name.
707 ObjCPropertyDecl *property,
709 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
714 // The lifetime implied by the property's attributes.
716 getImpliedARCOwnership(property->getPropertyAttributes(),
717 property->getType());
732 // property implementation before parsing any method bodies.
749 << property->getDeclName()
756 << property->getDeclName()
762 << property->getDeclName() << ivar->getDeclName()
763 << ((property->getPropertyAttributesAsWritten() &
771 // Any other property should be ignored.
775 S.Diag(property->getLocation(), diag::note_property_declare);
782 /// property with no known lifetime of its own, using backing
783 /// 'ivar's attribute, if any. If no backing 'ivar', property's
786 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
788 getImpliedARCOwnership(property->getPropertyAttributes(),
789 property->getType());
794 // if no backing ivar, make property 'strong'.
795 property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
798 // property assumes owenership of backing ivar.
802 property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
804 property->setPropertyAttributes(ObjCPropertyAttribute::kind_weak);
818 /// property declaration that should be synthesised in all of the inherited
825 ObjCPropertyDecl *Property) {
826 assert(isa<ObjCProtocolDecl>(Property->getDeclContext()) &&
827 "Expected a property from a protocol");
832 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
839 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
847 return Property;
849 ObjCPropertyDecl *OriginalProperty = Property;
852 // Select the 'readwrite' property if such property exists.
853 if (Property->isReadOnly() && !Prop.value()->isReadOnly()) {
854 Property = Prop.value();
858 if (Property != OriginalProperty) {
859 // Check that the old property is compatible with the new one.
863 QualType RHSType = S.Context.getCanonicalType(Property->getType());
864 unsigned OriginalAttributes = Property->getPropertyAttributesAsWritten();
872 // Represents a property from another protocol that conflicts with the
881 // Verify the property attributes.
889 // The ownership might be incompatible unless the property has no explicit
919 if (Property->getGetterName() != Prop->getGetterName()) {
923 if (!Property->isReadOnly() && !Prop->isReadOnly() &&
924 Property->getSetterName() != Prop->getSetterName()) {
941 return Property;
951 auto Diag = S.Diag(Property->getLocation(),
952 Property != OriginalProperty || HasIncompatibleAttributes
958 Diag << Property->getType();
965 Diag << Property->getGetterName();
968 Diag << Property->getSetterName();
995 return Property;
998 /// Determine whether any storage attributes were written on the property.
1003 // If this is a readwrite property in a class extension that refines
1004 // a readonly property in the original class definition, check it as
1007 // If it's a readonly property, we're not interested.
1014 // Find the corresponding property in the primary class definition.
1031 /// Create a synthesized property accessor stub inside the \@implementation.
1059 /// builds the AST node for a property implementation declaration; declared
1069 // Make sure we have a context for the property implementation declaration.
1079 ObjCPropertyDecl *property = nullptr;
1081 // Find the class or category class where this property must have
1092 // Look for this property declaration in the @implementation's @interface
1093 property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind);
1094 if (!property) {
1098 if (property->isClassProperty() && Synthesize) {
1102 unsigned PIkind = property->getPropertyAttributesAsWritten();
1109 Diag(property->getLocation(), diag::note_property_declare);
1113 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
1116 Diag(property->getLocation(), diag::note_property_declare);
1121 property->hasAttr<IBOutletAttr>() && !AtLoc.isValid()) {
1123 // Search into the class extensions and see if 'readonly property is
1126 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
1137 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
1138 << property;
1141 property->getLParenLoc(), readonlyLoc)) {
1145 Diag(property->getLocation(),
1151 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
1152 property = SelectPropertyForSynthesisFromProtocols(SemaRef, AtLoc, IDecl,
1153 property);
1172 // Look for this property declaration in @implementation's category
1173 property = Category->FindPropertyDeclaration(PropertyId, QueryKind);
1174 if (!property) {
1194 QualType PropType = property->getType();
1199 property->getDeclName())) {
1200 Diag(property->getLocation(), diag::note_property_declare);
1205 (property->getPropertyAttributesAsWritten() &
1208 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
1211 ObjCPropertyAttribute::Kind kind = property->getPropertyAttributes();
1215 // Add GC __weak to the ivar type if the property is weak.
1220 Diag(property->getLocation(), diag::note_property_declare);
1227 // the property type.
1236 Diag(property->getLocation(), diag::note_property_declare);
1245 Diag(property->getLocation(),
1257 // Check when default synthesizing a property that there is
1258 // an ivar matching property name and issue warning; since this
1260 // property in non-default synthesis case.
1263 IDecl->lookupInstanceVariable(property->getIdentifier(),
1270 Diag(property->getLocation(), diag::note_property_declare);
1277 // property attributes.
1283 // explicitly write an ownership attribute on the property.
1284 if (!hasWrittenStorageAttribute(property, QueryKind) &&
1288 Diag(property->getLocation(), diag::note_property_declare);
1292 assert(lifetime && "no lifetime for property?");
1308 Diag(property->getLocation(), diag::note_property_declare);
1329 // a property implementation and to avoid future warnings.
1333 << property->getDeclName() << Ivar->getDeclName()
1339 property->setPropertyIvarDecl(Ivar);
1343 // Check that type of property and its ivar are type compatible.
1357 << property->getDeclName() << PropType
1361 // a property implementation and to avoid future warnings.
1366 // specifically for property redeclarations as well as for ivars.
1372 << property->getDeclName() << PropType
1382 << property->getDeclName() << Ivar->getDeclName();
1387 if ((property->getType()->isObjCObjectPointerType() ||
1391 << property->getDeclName() << Ivar->getDeclName();
1397 checkARCPropertyImpl(SemaRef, PropertyLoc, property, Ivar);
1402 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1404 Context, SemaRef.CurContext, AtLoc, PropertyLoc, property,
1412 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1457 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1461 Diag(property->getLocation(), diag::note_property_declare);
1477 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1516 if (property->getPropertyAttributes() &
1523 if (property->getType()->isReferenceType()) {
1526 << property->getType();
1556 // use and if 1) property is @dynamic or 2) property is synthesized
1612 void SemaObjC::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1617 ObjCPropertyAttribute::Kind CAttr = Property->getPropertyAttributes();
1622 // to be overridden by a property with any explicit ownership in the subclass.
1629 Diag(Property->getLocation(), diag::warn_readonly_property)
1630 << Property->getDeclName() << inheritedName;
1633 Diag(Property->getLocation(), diag::warn_property_attribute)
1634 << Property->getDeclName() << "copy" << inheritedName;
1643 Diag(Property->getLocation(), diag::warn_property_attribute)
1644 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1650 // atomic property is 'readonly'.
1651 checkAtomicPropertyMismatch(SemaRef, SuperProperty, Property, false);
1654 if (Property->getSetterName() != SuperProperty->getSetterName() &&
1657 Diag(Property->getLocation(), diag::warn_property_attribute)
1658 << Property->getDeclName() << "setter" << inheritedName;
1661 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1662 Diag(Property->getLocation(), diag::warn_property_attribute)
1663 << Property->getDeclName() << "getter" << inheritedName;
1670 Context.getCanonicalType(Property->getType());
1674 // FIXME. For future support of covariant property types, revisit this.
1680 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1681 << Property->getType() << SuperProperty->getType() << inheritedName;
1687 bool SemaObjC::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1695 property->getType().getNonReferenceType().getAtomicUnqualifiedType();
1707 << property->getDeclName() << PropertyRValueType
1722 << property->getDeclName()
1780 // Exclude property for protocols which conform to class's super-class,
1781 // as super-class has to implement the property.
1812 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1824 // look up a property declaration whose one of its accessors is implemented
1826 for (const auto *Property : IFace->instance_properties()) {
1827 if ((Property->getGetterName() == IMD->getSelector() ||
1828 Property->getSetterName() == IMD->getSelector()) &&
1829 (Property->getPropertyIvarDecl() == IV))
1832 // Also look up property declaration in class extension whose one of its
1835 for (const auto *Property : Ext->instance_properties())
1836 if ((Property->getGetterName() == IMD->getSelector() ||
1837 Property->getSetterName() == IMD->getSelector()) &&
1838 (Property->getPropertyIvarDecl() == IV))
1879 // Is there a matching property synthesize/dynamic?
1884 // Property may have been synthesized by user.
1910 // Suppress the warning if class's superclass implements property's
1911 // getter and implements property's setter (if readwrite property).
1912 // Or, if property is going to be implemented in its super class.
1925 // If property to be implemented in the super class, ignore.
1951 /* property = */ Prop->getIdentifier(),
1985 // When reporting on missing property setter/getter implementation in
2025 // its primary class (and its super classes) if property is
2081 // Collect property accessors implemented in current implementation.
2101 // Is there a matching property synthesize/dynamic?
2121 const auto *property = propertyImpl->getPropertyDecl();
2126 (property->getPropertyAttributes() &
2128 property->getGetterMethodDecl() && property->getSetterMethodDecl()) {
2138 << setterImpl->getSelector() << property->getDeclName();
2158 const ObjCPropertyDecl *Property = I->second;
2162 unsigned Attributes = Property->getPropertyAttributes();
2163 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
2167 GetterMethod = Property->isClassProperty() ?
2168 IMPDecl->getClassMethod(Property->getGetterName()) :
2169 IMPDecl->getInstanceMethod(Property->getGetterName());
2170 SetterMethod = Property->isClassProperty() ?
2171 IMPDecl->getClassMethod(Property->getSetterName()) :
2172 IMPDecl->getInstanceMethod(Property->getSetterName());
2180 << Property->getIdentifier() << 0;
2181 Diag(Property->getLocation(), diag::note_property_declare);
2186 << Property->getIdentifier() << 1;
2187 Diag(Property->getLocation(), diag::note_property_declare);
2191 // We only care about readwrite atomic property.
2196 Property->getIdentifier(), Property->getQueryKind())) {
2210 << Property->getIdentifier() << (GetterMethod != nullptr)
2213 if (Property->getLParenLoc().isValid() &&
2215 // @property () ... case.
2217 SemaRef.getLocForEndOfToken(Property->getLParenLoc());
2220 Diag(Property->getLocation(),
2223 } else if (Property->getLParenLoc().isInvalid()) {
2224 //@property id etc.
2226 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
2227 Diag(Property->getLocation(),
2232 Diag(Property->getLocation(), diag::note_property_declare);
2261 // Look for a getter explicitly declared alongside the property.
2339 /// AddPropertyAttrs - Propagates attributes from a property to the
2340 /// implicitly-declared getter or setter for that property.
2342 ObjCPropertyDecl *Property) {
2344 for (const auto *A : Property->attrs()) {
2353 /// have the property type and issue diagnostics if they don't.
2356 void SemaObjC::ProcessPropertyDecl(ObjCPropertyDecl *property) {
2359 ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2363 bool IsClassProperty = property->isClassProperty();
2365 CD->getClassMethod(property->getGetterName()) :
2366 CD->getInstanceMethod(property->getGetterName());
2374 getClassMethod(property->getGetterName()) :
2376 getInstanceMethod(property->getGetterName());
2379 CD->getClassMethod(property->getSetterName()) :
2380 CD->getInstanceMethod(property->getSetterName());
2385 getClassMethod(property->getSetterName()) :
2387 getInstanceMethod(property->getSetterName());
2388 DiagnosePropertyAccessorMismatch(property, GetterMethod,
2389 property->getLocation());
2396 property->getGetterName(), !IsClassProperty, true, false, CatDecl);
2398 if (ExistingGetter->isDirectMethod() || property->isDirectProperty()) {
2399 Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2400 << property->isDirectProperty() << 1 /* property */
2409 if (!property->isReadOnly() && !SetterMethod) {
2412 property->getSetterName(), !IsClassProperty, true, false, CatDecl);
2414 if (ExistingSetter->isDirectMethod() || property->isDirectProperty()) {
2415 Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2416 << property->isDirectProperty() << 1 /* property */
2425 if (!property->isReadOnly() && SetterMethod) {
2432 property->getType().getNonReferenceType())) {
2433 Diag(property->getLocation(),
2435 << property->getDeclName()
2443 // FIXME: The synthesized property we set here is misleading. We almost always
2448 // No instance/class method of same name as property getter name was found.
2451 SourceLocation Loc = property->getLocation();
2453 // The getter returns the declared property type with all qualifiers
2455 QualType resultTy = property->getType().getAtomicUnqualifiedType();
2457 // If the property is null_resettable, the getter returns nonnull.
2458 if (property->getPropertyAttributes() &
2469 Context, Loc, Loc, property->getGetterName(), resultTy, nullptr, CD,
2473 (property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2478 AddPropertyAttrs(SemaRef, GetterMethod, property);
2480 if (property->isDirectProperty())
2483 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2487 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2491 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2501 // the property with the same name is seen in the @implementation
2506 property->setGetterMethodDecl(GetterMethod);
2508 // Skip setter if property is read-only.
2509 if (!property->isReadOnly()) {
2512 // No instance/class method of same name as property setter name was
2516 SourceLocation Loc = property->getLocation();
2519 Context, Loc, Loc, property->getSetterName(), Context.VoidTy, nullptr,
2526 (property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2532 property->getType().getUnqualifiedType().getAtomicUnqualifiedType();
2534 // If the property is null_resettable, the setter accepts a
2536 if (property->getPropertyAttributes() &
2550 property->getIdentifier(),
2557 AddPropertyAttrs(SemaRef, SetterMethod, property);
2559 if (property->isDirectProperty())
2563 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2575 // the property with the same name is seen in the @implementation
2580 property->setSetterMethodDecl(SetterMethod);
2586 // @property double bar;
2753 // Warn if user supplied no assignment attribute, property is
2759 // With arc, @property definitions should default to strong when
2770 // Don't issue warning on property with no life time in class
2771 // extension as it is inherited from property in primary class.