Lines Matching full: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.
355 // Determine whether the given property is readonly and implicitly
357 auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
359 auto Attrs = Property->getPropertyAttributes();
366 if (Property->getPropertyAttributesAsWritten() &
373 // If we're allowed to propagate atomicity, and the new property did
390 // One of the properties is atomic; if it's a readonly property, and
423 // Diagnose if this property is already in continuation class.
428 // We need to look in the @interface to see if the @property was
438 // Find the property in the extended class's primary class or
443 // If we found a property in an extension, complain.
452 // A readonly property declared in the primary class can be refined
453 // by adding a readwrite property within an extension.
457 // property is declared both in the @interface and the continuation.
497 // Take the ownership from the original property.
501 // If the redeclaration is 'weak' but the original property is not,
520 // If there was no declaration of a property with the same name in
530 // Relax the strict type matching for property type in continuation class.
531 // Allow property object type of continuation class to be different as long
532 // as it narrows the object type in its primary class property. Note that
534 // property in primary class and 'narrowed' type for a 'readwrite' property
550 // Check that atomicity of property in class extension matches the previous
575 // Property defaults to 'assign' if it is readwrite, unless this is ARC
588 // Issue a warning if property is 'assign' as default and its
621 // Class property and instance property can have the same name.
708 ObjCPropertyDecl *property,
710 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
715 // The lifetime implied by the property's attributes.
717 getImpliedARCOwnership(property->getPropertyAttributes(),
718 property->getType());
733 // property implementation before parsing any method bodies.
750 << property->getDeclName()
757 << property->getDeclName()
763 << property->getDeclName()
765 << ((property->getPropertyAttributesAsWritten()
773 // Any other property should be ignored.
777 S.Diag(property->getLocation(), diag::note_property_declare);
784 /// property with no known lifetime of its own, using backing
785 /// 'ivar's attribute, if any. If no backing 'ivar', property's
788 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
790 getImpliedARCOwnership(property->getPropertyAttributes(),
791 property->getType());
796 // if no backing ivar, make property 'strong'.
797 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
800 // property assumes owenership of backing ivar.
804 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
806 property
815 ObjCPropertyDecl *Property) {
819 PDecl->collectInheritedProtocolProperties(Property, PropMap);
825 PDecl->collectInheritedProtocolProperties(Property, PropMap);
833 QualType RHSType = S.Context.getCanonicalType(Property->getType());
845 S.Diag(Property->getLocation(), diag::warn_protocol_property_mismatch)
846 << Property->getType();
858 /// Determine whether any storage attributes were written on the property.
863 // If this is a readwrite property in a class extension that refines
864 // a readonly property in the original class definition, check it as
867 // If it's a readonly property, we're not interested.
874 // Find the corresponding property in the primary class definition.
892 /// builds the AST node for a property implementation declaration; declared
905 // Make sure we have a context for the property implementation declaration.
915 ObjCPropertyDecl *property = nullptr;
917 // Find the class or category class where this property must have
928 // Look for this property declaration in the @implementation's @interface
929 property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind);
930 if (!property) {
934 if (property->isClassProperty() && Synthesize) {
938 unsigned PIkind = property->getPropertyAttributesAsWritten();
945 Diag(property->getLocation(), diag::note_property_declare);
949 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
952 Diag(property->getLocation(), diag::note_property_declare);
958 property->hasAttr<IBOutletAttr>() &&
961 // Search into the class extensions and see if 'readonly property is
964 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
976 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
977 << property;
980 property->getLParenLoc(), readonlyLoc)) {
984 Diag(property->getLocation(),
990 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
991 DiagnosePropertyMismatchDeclInProtocols(*this, AtLoc, IDecl, property);
1010 // Look for this property declaration in @implementation's category
1011 property = Category->FindPropertyDeclaration(PropertyId, QueryKind);
1012 if (!property) {
1032 QualType PropType = property->getType();
1037 property->getDeclName())) {
1038 Diag(property->getLocation(), diag::note_property_declare);
1043 (property->getPropertyAttributesAsWritten() &
1046 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
1050 = property->getPropertyAttributes();
1054 // Add GC __weak to the ivar type if the property is weak.
1059 Diag(property->getLocation(), diag::note_property_declare);
1066 // the property type.
1075 Diag(property->getLocation(), diag::note_property_declare);
1084 Diag(property->getLocation(),
1096 // Check when default synthesizing a property that there is
1097 // an ivar matching property name and issue warning; since this
1099 // property in non-default synthesis case.
1102 IDecl->lookupInstanceVariable(property->getIdentifier(),
1109 Diag(property->getLocation(), diag::note_property_declare);
1116 // property attributes.
1122 // explicitly write an ownership attribute on the property.
1123 if (!hasWrittenStorageAttribute(property, QueryKind) &&
1127 Diag(property->getLocation(), diag::note_property_declare);
1131 assert(lifetime && "no lifetime for property?");
1148 Diag(property->getLocation(), diag::note_property_declare);
1159 // a property implementation and to avoid future warnings.
1163 << property->getDeclName() << Ivar->getDeclName()
1169 property->setPropertyIvarDecl(Ivar);
1173 // Check that type of property and its ivar are type compatible.
1188 << property->getDeclName() << PropType
1192 // a property implementation and to avoid future warnings.
1197 // specifically for property redeclarations as well as for ivars.
1203 << property->getDeclName() << PropType
1213 << property->getDeclName() << Ivar->getDeclName();
1218 if ((property->getType()->isObjCObjectPointerType() ||
1222 << property->getDeclName() << Ivar->getDeclName();
1228 checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
1233 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1236 property,
1245 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1280 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1284 Diag(property->getLocation(), diag::note_property_declare);
1299 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1328 if (property->getPropertyAttributes() &
1335 if (property->getType()->isReferenceType()) {
1338 << property->getType();
1368 // use and if 1) property is @dynamic or 2) property is synthesized
1416 Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1421 Property->getPropertyAttributes();
1427 // to be overridden by a property with any explicit ownership in the subclass.
1434 Diag(Property->getLocation(), diag::warn_readonly_property)
1435 << Property->getDeclName() << inheritedName;
1438 Diag(Property->getLocation(), diag::warn_property_attribute)
1439 << Property->getDeclName() << "copy" << inheritedName;
1450 Diag(Property->getLocation(), diag::warn_property_attribute)
1451 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1457 // atomic property is 'readonly'.
1458 checkAtomicPropertyMismatch(*this, SuperProperty, Property, false);
1459 if (Property->getSetterName() != SuperProperty->getSetterName()) {
1460 Diag(Property->getLocation(), diag::warn_property_attribute)
1461 << Property->getDeclName() << "setter" << inheritedName;
1464 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1465 Diag(Property->getLocation(), diag::warn_property_attribute)
1466 << Property->getDeclName() << "getter" << inheritedName;
1473 Context.getCanonicalType(Property->getType());
1477 // FIXME. For future support of covariant property types, revisit this.
1483 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1484 << Property->getType() << SuperProperty->getType() << inheritedName;
1490 bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1497 property->getType().getNonReferenceType().getAtomicUnqualifiedType();
1509 << property->getDeclName() << PropertyRValueType
1524 << property->getDeclName()
1582 // Exclude property for protocols which conform to class's super-class,
1583 // as super-class has to implement the property.
1615 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1627 // look up a property declaration whose one of its accessors is implemented
1629 for (const auto *Property : IFace->instance_properties()) {
1630 if ((Property->getGetterName() == IMD->getSelector() ||
1631 Property->getSetterName() == IMD->getSelector()) &&
1632 (Property->getPropertyIvarDecl() == IV))
1635 // Also look up property declaration in class extension whose one of its
1638 for (const auto *Property : Ext->instance_properties())
1639 if ((Property->getGetterName() == IMD->getSelector() ||
1640 Property->getSetterName() == IMD->getSelector()) &&
1641 (Property->getPropertyIvarDecl() == IV))
1681 // Is there a matching property synthesize/dynamic?
1686 // Property may have been synthesized by user.
1710 // Suppress the warning if class's superclass implements property's
1711 // getter and implements property's setter (if readwrite property).
1712 // Or, if property is going to be implemented in its super class.
1721 // If property to be implemented in the super class, ignore.
1747 /* property = */ Prop->getIdentifier(),
1780 // When reporting on missing property setter/getter implementation in
1820 // its primary class (and its super classes) if property is
1877 // Collect property accessors implemented in current implementation.
1897 // Is there a matching property synthesize/dynamic?
1916 const auto *property = propertyImpl->getPropertyDecl();
1922 (property->getPropertyAttributes() &
1924 property
1925 property->getSetterMethodDecl()) {
1926 auto *getterMethod = property->getGetterMethodDecl();
1927 auto *setterMethod = property->getSetterMethodDecl();
1935 << setterMethod->getSelector() << property->getDeclName();
1956 const ObjCPropertyDecl *Property = I->second;
1961 unsigned Attributes = Property->getPropertyAttributes();
1962 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
1966 GetterMethod = Property->isClassProperty() ?
1967 IMPDecl->getClassMethod(Property->getGetterName()) :
1968 IMPDecl->getInstanceMethod(Property->getGetterName());
1969 SetterMethod = Property->isClassProperty() ?
1970 IMPDecl->getClassMethod(Property->getSetterName()) :
1971 IMPDecl->getInstanceMethod(Property->getSetterName());
1976 << Property->getIdentifier() << 0;
1977 Diag(Property->getLocation(), diag::note_property_declare);
1982 << Property->getIdentifier() << 1;
1983 Diag(Property->getLocation(), diag::note_property_declare);
1987 // We only care about readwrite atomic property.
1992 Property->getIdentifier(), Property->getQueryKind())) {
1996 GetterMethod = Property->isClassProperty() ?
1997 IMPDecl->getClassMethod(Property->getGetterName()) :
1998 IMPDecl->getInstanceMethod(Property->getGetterName());
1999 SetterMethod = Property->isClassProperty() ?
2000 IMPDecl->getClassMethod(Property->getSetterName()) :
2001 IMPDecl->getInstanceMethod(Property->getSetterName());
2008 << Property->getIdentifier() << (GetterMethod != nullptr)
2011 if (Property->getLParenLoc().isValid() &&
2013 // @property () ... case.
2015 getLocForEndOfToken(Property->getLParenLoc());
2018 Diag(Property->getLocation(),
2021 } else if (Property->getLParenLoc().isInvalid()) {
2022 //@property id etc.
2024 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
2025 Diag(Property->getLocation(),
2031 Diag(Property->getLocation(), diag::note_property_declare);
2057 // Look for a getter explicitly declared alongside the property.
2127 /// AddPropertyAttrs - Propagates attributes from a property to the
2128 /// implicitly-declared getter or setter for that property.
2130 ObjCPropertyDecl *Property) {
2132 for (const auto *A : Property->attrs()) {
2141 /// have the property type and issue diagnostics if they don't.
2144 void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) {
2146 ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2150 bool IsClassProperty = property->isClassProperty();
2152 CD->getClassMethod(property->getGetterName()) :
2153 CD->getInstanceMethod(property->getGetterName());
2161 getClassMethod(property->getGetterName()) :
2163 getInstanceMethod(property->getGetterName());
2166 CD->getClassMethod(property->getSetterName()) :
2167 CD->getInstanceMethod(property->getSetterName());
2172 getClassMethod(property->getSetterName()) :
2174 getInstanceMethod(property->getSetterName());
2175 DiagnosePropertyAccessorMismatch(property, GetterMethod,
2176 property->getLocation());
2180 property->getPropertyAttributes();
2188 property->getType().getNonReferenceType())) {
2189 Diag(property->getLocation(),
2191 << property->getDeclName()
2199 // FIXME: The synthesized property we set here is misleading. We almost always
2204 // No instance/class method of same name as property getter name was found.
2207 SourceLocation Loc = property->getLocation();
2209 // The getter returns the declared property type with all qualifiers
2211 QualType resultTy = property->getType().getAtomicUnqualifiedType();
2213 // If the property is null_resettable, the getter returns nonnull.
2214 if (property->getPropertyAttributes() &
2225 property->getGetterName(),
2230 (property->getPropertyImplementation() ==
2236 AddPropertyAttrs(*this, GetterMethod, property);
2238 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2242 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2246 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2255 // the property with the same name is seen in the @implementation
2257 property->setGetterMethodDecl(GetterMethod);
2259 // Skip setter if property is read-only.
2260 if (!property->isReadOnly()) {
2263 // No instance/class method of same name as property setter name was
2267 SourceLocation Loc = property->getLocation();
2271 property->getSetterName(), Context.VoidTy,
2277 (property->getPropertyImplementation() ==
2284 property->getType().getUnqualifiedType().getAtomicUnqualifiedType();
2286 // If the property is null_resettable, the setter accepts a
2288 if (property->getPropertyAttributes() &
2302 property->getIdentifier(),
2309 AddPropertyAttrs(*this, SetterMethod, property);
2312 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2322 // the property with the same name is seen in the @implementation
2324 property->setSetterMethodDecl(SetterMethod);
2330 // @property double bar;
2485 // Warn if user supplied no assignment attribute, property is
2491 // With arc, @property definitions should default to strong when
2503 // Don't issue warning on property with no life time in class
2504 // extension as it is inherited from property in primary class.