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.
65 static void checkARCPropertyDecl(Sema &S, ObjCPropertyDecl *property) {
66 if (property->isInvalidDecl()) return;
69 = property->getPropertyAttributes();
71 = property->getType().getObjCLifetime();
77 = getImpliedARCOwnership(propertyKind, property->getType());
79 // We have a lifetime qualifier but no dominating property
81 // setting the property attribute according to the lifetime
92 property->setPropertyAttributes(attr);
98 property->setInvalidDecl();
99 S.Diag(property->getLocation(),
101 << property->getDeclName()
115 /// \brief Check this Objective-C property against a property declared in the
125 // Look for a property with the same name.
134 // Check this property against any protocols we inherit.
156 // property is defaulted to 'assign' if it is readwrite and is
192 // Validate the attributes on the @property.
202 // For a class, compare the property against a property in our superclass.
221 // Also compare the property against a property in our protocols.
328 // Diagnose if this property is already in continuation class.
334 // Check for duplicate declaration of this property in current and
368 // We need to look in the @interface to see if the @property was
376 // Find the property in continuation class's primary class only.
381 // No matching property found in the primary class. Just fall thru
382 // and add property to continuation class's primary class.
388 // A case of continuation class adding a new property in the class. This
404 // Relax the strict type matching for property type in continuation class.
405 // Allow property object type of continuation class to be different as long
406 // as it narrows the object type in its primary class property. Note that
408 // property in primary class and 'narrowed' type for a 'readwrite' property
424 // The property 'PIDecl's readonly attribute will be over-ridden
425 // with continuation class's readwrite property attribute!
457 // In mrr mode, 'readwrite' property must have an explicit
500 // property is declared both in the @interface and the continuation.
540 // Issue a warning if property is 'assign' as default and its object, which is
646 ObjCPropertyDecl *property,
648 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
653 // The lifetime implied by the property's attributes.
655 getImpliedARCOwnership(property->getPropertyAttributes(),
656 property->getType());
669 // property implementation before parsing any method bodies.
686 << property->getDeclName()
693 << property->getDeclName()
699 << property->getDeclName()
701 << ((property->getPropertyAttributesAsWritten()
709 // Any other property should be ignored.
713 S.Diag(property->getLocation(), diag::note_property_declare);
720 /// property with no known lifetime of its own, using backing
721 /// 'ivar's attribute, if any. If no backing 'ivar', property's
724 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
726 getImpliedARCOwnership(property->getPropertyAttributes(),
727 property->getType());
732 // if no backing ivar, make property 'strong'.
733 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
736 // property assumes owenership of backing ivar.
740 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
742 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_weak);
752 ObjCPropertyDecl *Property) {
756 PDecl->collectInheritedProtocolProperties(Property, PropMap);
762 PDecl->collectInheritedProtocolProperties(Property, PropMap);
770 QualType RHSType = S.Context.getCanonicalType(Property->getType());
782 S.Diag(Property->getLocation(), diag::warn_protocol_property_mismatch)
783 << Property->getType();
796 /// builds the AST node for a property implementation declaration; declared
808 // Make sure we have a context for the property implementation declaration.
818 ObjCPropertyDecl *property = nullptr;
820 // Find the class or category class where this property must have
831 // Look for this property declaration in the @implementation's @interface
832 property = IDecl->FindPropertyDeclaration(PropertyId);
833 if (!property) {
837 unsigned PIkind = property->getPropertyAttributesAsWritten();
844 Diag(property->getLocation(), diag::note_property_declare);
848 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
851 Diag(property->getLocation(), diag::note_property_declare);
857 property->hasAttr<IBOutletAttr>() &&
860 // Search into the class extensions and see if 'readonly property is
863 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
875 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
876 << property;
879 property->getLParenLoc(), readonlyLoc)) {
883 Diag(property->getLocation(),
889 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
890 DiagnosePropertyMismatchDeclInProtocols(*this, AtLoc, IDecl, property);
909 // Look for this property declaration in @implementation's category
910 property = Category->FindPropertyDeclaration(PropertyId);
911 if (!property) {
931 QualType PropType = property->getType();
936 property->getDeclName())) {
937 Diag(property->getLocation(), diag::note_property_declare);
942 (property->getPropertyAttributesAsWritten() &
945 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
949 = property->getPropertyAttributes();
951 // Add GC __weak to the ivar type if the property is weak.
957 Diag(property->getLocation(), diag::note_property_declare);
964 // Check when default synthesizing a property that there is
965 // an ivar matching property name and issue warning; since this
967 // property in non-default synthesis case.
970 IDecl->lookupInstanceVariable(property->getIdentifier(),
977 Diag(property->getLocation(), diag::note_property_declare);
984 // property attributes.
990 // explicitly write an ownership attribute on the property.
991 if (!property->hasWrittenStorageAttribute() &&
995 Diag(property->getLocation(), diag::note_property_declare);
999 assert(lifetime && "no lifetime for property?");
1006 Diag(property->getLocation(),
1015 Diag(property->getLocation(), diag::note_property_declare);
1029 Diag(property->getLocation(), diag::note_property_declare);
1041 Diag(property->getLocation(), diag::note_property_declare);
1052 // a property implementation and to avoid future warnings.
1056 << property->getDeclName() << Ivar->getDeclName()
1062 property->setPropertyIvarDecl(Ivar);
1066 // Check that type of property and its ivar are type compatible.
1081 << property->getDeclName() << PropType
1085 // a property implementation and to avoid future warnings.
1090 // specifically for property redeclarations as well as for ivars.
1096 << property->getDeclName() << PropType
1106 << property->getDeclName() << Ivar->getDeclName();
1111 if ((property->getType()->isObjCObjectPointerType() ||
1115 << property->getDeclName() << Ivar->getDeclName();
1120 checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
1125 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1128 property,
1137 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1170 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1174 Diag(property->getLocation(), diag::note_property_declare);
1189 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1216 if (property->getPropertyAttributes() &
1223 if (property->getType()->isReferenceType()) {
1226 << property->getType();
1256 // use and if 1) property is @dynamic or 2) property is synthesized
1304 Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1309 Property->getPropertyAttributes();
1315 // to be overridden by a property with any explicit ownership in the subclass.
1322 Diag(Property->getLocation(), diag::warn_readonly_property)
1323 << Property->getDeclName() << inheritedName;
1326 Diag(Property->getLocation(), diag::warn_property_attribute)
1327 << Property->getDeclName() << "copy" << inheritedName;
1338 Diag(Property->getLocation(), diag::warn_property_attribute)
1339 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1345 Diag(Property->getLocation(), diag::warn_property_attribute)
1346 << Property->getDeclName() << "atomic" << inheritedName;
1349 if (Property->getSetterName() != SuperProperty->getSetterName()) {
1350 Diag(Property->getLocation(), diag::warn_property_attribute)
1351 << Property->getDeclName() << "setter" << inheritedName;
1354 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1355 Diag(Property->getLocation(), diag::warn_property_attribute)
1356 << Property->getDeclName() << "getter" << inheritedName;
1363 Context.getCanonicalType(Property->getType());
1367 // FIXME. For future support of covariant property types, revisit this.
1373 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1374 << Property->getType() << SuperProperty->getType() << inheritedName;
1380 bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1386 QualType PropertyIvarType = property->getType().getNonReferenceType();
1398 << property->getDeclName() << PropertyIvarType
1413 << property->getDeclName()
1451 // Exclude property for protocols which conform to class's super-class,
1452 // as super-class has to implement the property.
1481 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1493 // look up a property declaration whose one of its accessors is implemented
1495 for (const auto *Property : IFace->properties()) {
1496 if ((Property->getGetterName() == IMD->getSelector() ||
1497 Property->getSetterName() == IMD->getSelector()) &&
1498 (Property->getPropertyIvarDecl() == IV))
1540 // Is there a matching property synthesize/dynamic?
1544 // Property may have been synthesized by user.
1565 // Suppress the warning if class's superclass implements property's
1566 // getter and implements property's setter (if readwrite property).
1567 // Or, if property is going to be implemented in its super class.
1576 // If property to be implemented in the super class, ignore.
1602 /* property = */ Prop->getIdentifier(),
1631 // When reporting on missing property setter/getter implementation in
1666 // its primary class (and its super classes) if property is
1719 // Collect property accessors implemented in current implementation.
1762 for (const auto *Property : IDecl->properties()) {
1767 unsigned Attributes = Property->getPropertyAttributes();
1768 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
1772 GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName());
1773 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1778 << Property->getIdentifier() << 0;
1779 Diag(Property->getLocation(), diag::note_property_declare);
1784 << Property->getIdentifier() << 1;
1785 Diag(Property->getLocation(), diag::note_property_declare);
1789 // We only care about readwrite atomic property.
1794 = IMPDecl->FindPropertyImplDecl(Property->getIdentifier())) {
1798 GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName());
1799 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1806 << Property->getIdentifier() << (GetterMethod != nullptr)
1810 if (Property->getLParenLoc().isValid()) {
1811 // @property () ... case.
1812 SourceRange PropSourceRange(Property->getAtLoc(),
1813 Property->getLParenLoc());
1814 Diag(Property->getLocation(), diag::note_atomic_property_fixup_suggest) <<
1815 FixItHint::CreateReplacement(PropSourceRange, "@property (nonatomic");
1818 //@property id etc.
1820 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
1822 SourceRange PropSourceRange(Property->getAtLoc(), endLoc);
1823 Diag(Property->getLocation(), diag::note_atomic_property_fixup_suggest) <<
1824 FixItHint::CreateReplacement(PropSourceRange, "@property (nonatomic) ");
1828 // @property () ... case.
1829 SourceLocation endLoc = Property->getLParenLoc();
1830 SourceRange PropSourceRange(Property->getAtLoc(), endLoc);
1831 Diag(Property->getLocation(), diag::note_atomic_property_fixup_suggest) <<
1832 FixItHint::CreateReplacement(PropSourceRange, "@property (nonatomic, ");
1836 Diag(Property->getLocation(), diag::note_property_declare);
1861 // Look for a getter explicitly declared alongside the property.
1925 /// AddPropertyAttrs - Propagates attributes from a property to the
1926 /// implicitly-declared getter or setter for that property.
1928 ObjCPropertyDecl *Property) {
1930 for (const auto *A : Property->attrs()) {
1939 /// have the property type and issue diagnostics if they don't.
1943 void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
1953 GetterMethod = CD->getInstanceMethod(property->getGetterName());
1954 SetterMethod = CD->getInstanceMethod(property->getSetterName());
1955 DiagnosePropertyAccessorMismatch(property, GetterMethod,
1956 property->getLocation());
1960 property->getPropertyAttributes();
1968 property->getType().getNonReferenceType())) {
1969 Diag(property->getLocation(),
1971 << property->getDeclName()
1979 // FIXME: The synthesized property we set here is misleading. We almost always
1984 // No instance method of same name as property getter name was found.
1989 property->getLocation();
1992 property->getGetterName(),
1993 property->getType(), nullptr, CD,
1997 (property->getPropertyImplementation() ==
2003 AddPropertyAttrs(*this, GetterMethod, property);
2009 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2013 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2017 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2026 // the property with the same name is seen in the @implementation
2028 property->setGetterMethodDecl(GetterMethod);
2030 // Skip setter if property is read-only.
2031 if (!property->isReadOnly()) {
2034 // No instance method of same name as property setter name was found.
2039 property->getLocation();
2043 property->getSetterName(), Context.VoidTy,
2049 (property->getPropertyImplementation() ==
2058 property->getIdentifier(),
2059 property->getType().getUnqualifiedType(),
2065 AddPropertyAttrs(*this, SetterMethod, property);
2072 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2082 // the property with the same name is seen in the @implementation
2084 property->setSetterMethodDecl(SetterMethod);
2090 // @property double bar;
2133 // 'readonly' property with no obvious lifetime.
2238 // Warn if user supplied no assignment attribute, property is
2246 // With arc, @property definitions should default to (strong) when
2247 // not specified; including when property is 'readonly'.
2258 // Don't issue warning on property with no life time in class
2259 // extension as it is inherited from property in primary class.