blob: 4933f001c4e3afc72116321f023739359daaff4f [file] [log] [blame]
Ted Kremenek9d64c152010-03-12 00:38:38 +00001//===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for Objective C @property and
11// @synthesize declarations.
12//
13//===----------------------------------------------------------------------===//
14
John McCall2d887082010-08-25 22:03:47 +000015#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000016#include "clang/Sema/Initialization.h"
John McCall7cd088e2010-08-24 07:21:54 +000017#include "clang/AST/DeclObjC.h"
Fariborz Jahanian17cb3262010-05-05 21:52:17 +000018#include "clang/AST/ExprObjC.h"
Fariborz Jahanian57e264e2011-10-06 18:38:18 +000019#include "clang/AST/ExprCXX.h"
John McCall50df6ae2010-08-25 07:03:20 +000020#include "llvm/ADT/DenseSet.h"
Ted Kremenek9d64c152010-03-12 00:38:38 +000021
22using namespace clang;
23
Ted Kremenek28685ab2010-03-12 00:46:40 +000024//===----------------------------------------------------------------------===//
25// Grammar actions.
26//===----------------------------------------------------------------------===//
27
John McCall265941b2011-09-13 18:31:23 +000028/// getImpliedARCOwnership - Given a set of property attributes and a
29/// type, infer an expected lifetime. The type's ownership qualification
30/// is not considered.
31///
32/// Returns OCL_None if the attributes as stated do not imply an ownership.
33/// Never returns OCL_Autoreleasing.
34static Qualifiers::ObjCLifetime getImpliedARCOwnership(
35 ObjCPropertyDecl::PropertyAttributeKind attrs,
36 QualType type) {
37 // retain, strong, copy, weak, and unsafe_unretained are only legal
38 // on properties of retainable pointer type.
39 if (attrs & (ObjCPropertyDecl::OBJC_PR_retain |
40 ObjCPropertyDecl::OBJC_PR_strong |
41 ObjCPropertyDecl::OBJC_PR_copy)) {
Fariborz Jahanian5fa065b2011-10-13 23:45:45 +000042 return type->getObjCARCImplicitLifetime();
John McCall265941b2011-09-13 18:31:23 +000043 } else if (attrs & ObjCPropertyDecl::OBJC_PR_weak) {
44 return Qualifiers::OCL_Weak;
45 } else if (attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained) {
46 return Qualifiers::OCL_ExplicitNone;
47 }
48
49 // assign can appear on other types, so we have to check the
50 // property type.
51 if (attrs & ObjCPropertyDecl::OBJC_PR_assign &&
52 type->isObjCRetainableType()) {
53 return Qualifiers::OCL_ExplicitNone;
54 }
55
56 return Qualifiers::OCL_None;
57}
58
John McCallf85e1932011-06-15 23:02:42 +000059/// Check the internal consistency of a property declaration.
60static void checkARCPropertyDecl(Sema &S, ObjCPropertyDecl *property) {
61 if (property->isInvalidDecl()) return;
62
63 ObjCPropertyDecl::PropertyAttributeKind propertyKind
64 = property->getPropertyAttributes();
65 Qualifiers::ObjCLifetime propertyLifetime
66 = property->getType().getObjCLifetime();
67
68 // Nothing to do if we don't have a lifetime.
69 if (propertyLifetime == Qualifiers::OCL_None) return;
70
John McCall265941b2011-09-13 18:31:23 +000071 Qualifiers::ObjCLifetime expectedLifetime
72 = getImpliedARCOwnership(propertyKind, property->getType());
73 if (!expectedLifetime) {
John McCallf85e1932011-06-15 23:02:42 +000074 // We have a lifetime qualifier but no dominating property
John McCall265941b2011-09-13 18:31:23 +000075 // attribute. That's okay, but restore reasonable invariants by
76 // setting the property attribute according to the lifetime
77 // qualifier.
78 ObjCPropertyDecl::PropertyAttributeKind attr;
79 if (propertyLifetime == Qualifiers::OCL_Strong) {
80 attr = ObjCPropertyDecl::OBJC_PR_strong;
81 } else if (propertyLifetime == Qualifiers::OCL_Weak) {
82 attr = ObjCPropertyDecl::OBJC_PR_weak;
83 } else {
84 assert(propertyLifetime == Qualifiers::OCL_ExplicitNone);
85 attr = ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
86 }
87 property->setPropertyAttributes(attr);
John McCallf85e1932011-06-15 23:02:42 +000088 return;
89 }
90
91 if (propertyLifetime == expectedLifetime) return;
92
93 property->setInvalidDecl();
94 S.Diag(property->getLocation(),
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +000095 diag::err_arc_inconsistent_property_ownership)
John McCallf85e1932011-06-15 23:02:42 +000096 << property->getDeclName()
John McCall265941b2011-09-13 18:31:23 +000097 << expectedLifetime
John McCallf85e1932011-06-15 23:02:42 +000098 << propertyLifetime;
99}
100
John McCalld226f652010-08-21 09:40:31 +0000101Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
102 FieldDeclarator &FD,
103 ObjCDeclSpec &ODS,
104 Selector GetterSel,
105 Selector SetterSel,
John McCalld226f652010-08-21 09:40:31 +0000106 bool *isOverridingProperty,
Ted Kremenek4a2e9ea2010-09-23 21:18:05 +0000107 tok::ObjCKeywordKind MethodImplKind,
108 DeclContext *lexicalDC) {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000109 unsigned Attributes = ODS.getPropertyAttributes();
John McCallf85e1932011-06-15 23:02:42 +0000110 TypeSourceInfo *TSI = GetTypeForDeclarator(FD.D, S);
111 QualType T = TSI->getType();
Douglas Gregore289d812011-09-13 17:21:33 +0000112 if ((getLangOptions().getGC() != LangOptions::NonGC &&
John McCallf85e1932011-06-15 23:02:42 +0000113 T.isObjCGCWeak()) ||
114 (getLangOptions().ObjCAutoRefCount &&
115 T.getObjCLifetime() == Qualifiers::OCL_Weak))
116 Attributes |= ObjCDeclSpec::DQ_PR_weak;
117
Ted Kremenek28685ab2010-03-12 00:46:40 +0000118 bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) ||
119 // default is readwrite!
120 !(Attributes & ObjCDeclSpec::DQ_PR_readonly));
121 // property is defaulted to 'assign' if it is readwrite and is
122 // not retain or copy
123 bool isAssign = ((Attributes & ObjCDeclSpec::DQ_PR_assign) ||
124 (isReadWrite &&
125 !(Attributes & ObjCDeclSpec::DQ_PR_retain) &&
John McCallf85e1932011-06-15 23:02:42 +0000126 !(Attributes & ObjCDeclSpec::DQ_PR_strong) &&
127 !(Attributes & ObjCDeclSpec::DQ_PR_copy) &&
128 !(Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) &&
129 !(Attributes & ObjCDeclSpec::DQ_PR_weak)));
Fariborz Jahanian14086762011-03-28 23:47:18 +0000130
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000131 // Proceed with constructing the ObjCPropertDecls.
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000132 ObjCContainerDecl *ClassDecl = cast<ObjCContainerDecl>(CurContext);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000133
Ted Kremenek28685ab2010-03-12 00:46:40 +0000134 if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl))
Fariborz Jahanianae415dc2010-07-13 22:04:56 +0000135 if (CDecl->IsClassExtension()) {
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000136 Decl *Res = HandlePropertyInClassExtension(S, AtLoc,
Fariborz Jahanianae415dc2010-07-13 22:04:56 +0000137 FD, GetterSel, SetterSel,
138 isAssign, isReadWrite,
139 Attributes,
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000140 ODS.getPropertyAttributes(),
Fariborz Jahanianae415dc2010-07-13 22:04:56 +0000141 isOverridingProperty, TSI,
142 MethodImplKind);
John McCallf85e1932011-06-15 23:02:42 +0000143 if (Res) {
Fariborz Jahanianae415dc2010-07-13 22:04:56 +0000144 CheckObjCPropertyAttributes(Res, AtLoc, Attributes);
John McCallf85e1932011-06-15 23:02:42 +0000145 if (getLangOptions().ObjCAutoRefCount)
146 checkARCPropertyDecl(*this, cast<ObjCPropertyDecl>(Res));
147 }
Fariborz Jahanianae415dc2010-07-13 22:04:56 +0000148 return Res;
149 }
150
John McCallf85e1932011-06-15 23:02:42 +0000151 ObjCPropertyDecl *Res = CreatePropertyDecl(S, ClassDecl, AtLoc, FD,
152 GetterSel, SetterSel,
153 isAssign, isReadWrite,
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000154 Attributes,
155 ODS.getPropertyAttributes(),
156 TSI, MethodImplKind);
Ted Kremenek4a2e9ea2010-09-23 21:18:05 +0000157 if (lexicalDC)
158 Res->setLexicalDeclContext(lexicalDC);
159
Fariborz Jahanian842f07b2010-03-30 22:40:11 +0000160 // Validate the attributes on the @property.
161 CheckObjCPropertyAttributes(Res, AtLoc, Attributes);
John McCallf85e1932011-06-15 23:02:42 +0000162
163 if (getLangOptions().ObjCAutoRefCount)
164 checkARCPropertyDecl(*this, Res);
165
Fariborz Jahanian842f07b2010-03-30 22:40:11 +0000166 return Res;
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000167}
Ted Kremenek2d2f9362010-03-12 00:49:00 +0000168
Argyrios Kyrtzidisb98ffde2011-10-18 19:49:16 +0000169static ObjCPropertyDecl::PropertyAttributeKind
170makePropertyAttributesAsWritten(unsigned Attributes) {
171 unsigned attributesAsWritten = 0;
172 if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
173 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_readonly;
174 if (Attributes & ObjCDeclSpec::DQ_PR_readwrite)
175 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_readwrite;
176 if (Attributes & ObjCDeclSpec::DQ_PR_getter)
177 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_getter;
178 if (Attributes & ObjCDeclSpec::DQ_PR_setter)
179 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_setter;
180 if (Attributes & ObjCDeclSpec::DQ_PR_assign)
181 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_assign;
182 if (Attributes & ObjCDeclSpec::DQ_PR_retain)
183 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_retain;
184 if (Attributes & ObjCDeclSpec::DQ_PR_strong)
185 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_strong;
186 if (Attributes & ObjCDeclSpec::DQ_PR_weak)
187 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_weak;
188 if (Attributes & ObjCDeclSpec::DQ_PR_copy)
189 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_copy;
190 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
191 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
192 if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)
193 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_nonatomic;
194 if (Attributes & ObjCDeclSpec::DQ_PR_atomic)
195 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_atomic;
196
197 return (ObjCPropertyDecl::PropertyAttributeKind)attributesAsWritten;
198}
199
John McCalld226f652010-08-21 09:40:31 +0000200Decl *
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000201Sema::HandlePropertyInClassExtension(Scope *S,
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000202 SourceLocation AtLoc, FieldDeclarator &FD,
203 Selector GetterSel, Selector SetterSel,
204 const bool isAssign,
205 const bool isReadWrite,
206 const unsigned Attributes,
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000207 const unsigned AttributesAsWritten,
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000208 bool *isOverridingProperty,
John McCall83a230c2010-06-04 20:50:08 +0000209 TypeSourceInfo *T,
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000210 tok::ObjCKeywordKind MethodImplKind) {
Fariborz Jahanian58a76492011-08-22 18:34:22 +0000211 ObjCCategoryDecl *CDecl = cast<ObjCCategoryDecl>(CurContext);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000212 // Diagnose if this property is already in continuation class.
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000213 DeclContext *DC = CurContext;
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000214 IdentifierInfo *PropertyId = FD.D.getIdentifier();
Fariborz Jahanian2a289142010-11-10 18:01:36 +0000215 ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
216
217 if (CCPrimary)
218 // Check for duplicate declaration of this property in current and
219 // other class extensions.
220 for (const ObjCCategoryDecl *ClsExtDecl =
221 CCPrimary->getFirstClassExtension();
222 ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) {
223 if (ObjCPropertyDecl *prevDecl =
224 ObjCPropertyDecl::findPropertyDecl(ClsExtDecl, PropertyId)) {
225 Diag(AtLoc, diag::err_duplicate_property);
226 Diag(prevDecl->getLocation(), diag::note_property_declare);
227 return 0;
228 }
229 }
230
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000231 // Create a new ObjCPropertyDecl with the DeclContext being
232 // the class extension.
Fariborz Jahanian88f5e9b2010-12-10 23:36:33 +0000233 // FIXME. We should really be using CreatePropertyDecl for this.
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000234 ObjCPropertyDecl *PDecl =
235 ObjCPropertyDecl::Create(Context, DC, FD.D.getIdentifierLoc(),
236 PropertyId, AtLoc, T);
Argyrios Kyrtzidisb98ffde2011-10-18 19:49:16 +0000237 PDecl->setPropertyAttributesAsWritten(
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000238 makePropertyAttributesAsWritten(AttributesAsWritten));
Fariborz Jahanian22f757b2010-03-22 23:25:52 +0000239 if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
240 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
241 if (Attributes & ObjCDeclSpec::DQ_PR_readwrite)
242 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
Fariborz Jahanian88f5e9b2010-12-10 23:36:33 +0000243 // Set setter/getter selector name. Needed later.
244 PDecl->setGetterName(GetterSel);
245 PDecl->setSetterName(SetterSel);
Douglas Gregor91ae6b42011-07-15 15:30:21 +0000246 ProcessDeclAttributes(S, PDecl, FD.D);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000247 DC->addDecl(PDecl);
248
249 // We need to look in the @interface to see if the @property was
250 // already declared.
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000251 if (!CCPrimary) {
252 Diag(CDecl->getLocation(), diag::err_continuation_class);
253 *isOverridingProperty = true;
John McCalld226f652010-08-21 09:40:31 +0000254 return 0;
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000255 }
256
257 // Find the property in continuation class's primary class only.
258 ObjCPropertyDecl *PIDecl =
259 CCPrimary->FindPropertyVisibleInPrimaryClass(PropertyId);
260
261 if (!PIDecl) {
262 // No matching property found in the primary class. Just fall thru
263 // and add property to continuation class's primary class.
264 ObjCPropertyDecl *PDecl =
265 CreatePropertyDecl(S, CCPrimary, AtLoc,
266 FD, GetterSel, SetterSel, isAssign, isReadWrite,
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000267 Attributes,AttributesAsWritten, T, MethodImplKind, DC);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000268
269 // A case of continuation class adding a new property in the class. This
270 // is not what it was meant for. However, gcc supports it and so should we.
271 // Make sure setter/getters are declared here.
Ted Kremeneka054fb42010-09-21 20:52:59 +0000272 ProcessPropertyDecl(PDecl, CCPrimary, /* redeclaredProperty = */ 0,
273 /* lexicalDC = */ CDecl);
John McCalld226f652010-08-21 09:40:31 +0000274 return PDecl;
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000275 }
Fariborz Jahaniana4b984d2011-09-24 00:56:59 +0000276 if (PIDecl->getType().getCanonicalType()
277 != PDecl->getType().getCanonicalType()) {
278 Diag(AtLoc,
Fariborz Jahanian68af5362011-10-04 18:44:26 +0000279 diag::warn_type_mismatch_continuation_class) << PDecl->getType();
Fariborz Jahaniana4b984d2011-09-24 00:56:59 +0000280 Diag(PIDecl->getLocation(), diag::note_property_declare);
281 }
282
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000283 // The property 'PIDecl's readonly attribute will be over-ridden
284 // with continuation class's readwrite property attribute!
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000285 unsigned PIkind = PIDecl->getPropertyAttributesAsWritten();
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000286 if (isReadWrite && (PIkind & ObjCPropertyDecl::OBJC_PR_readonly)) {
287 unsigned retainCopyNonatomic =
288 (ObjCPropertyDecl::OBJC_PR_retain |
John McCallf85e1932011-06-15 23:02:42 +0000289 ObjCPropertyDecl::OBJC_PR_strong |
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000290 ObjCPropertyDecl::OBJC_PR_copy |
291 ObjCPropertyDecl::OBJC_PR_nonatomic);
292 if ((Attributes & retainCopyNonatomic) !=
293 (PIkind & retainCopyNonatomic)) {
294 Diag(AtLoc, diag::warn_property_attr_mismatch);
295 Diag(PIDecl->getLocation(), diag::note_property_declare);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000296 }
Ted Kremenek9944c762010-03-18 01:22:36 +0000297 DeclContext *DC = cast<DeclContext>(CCPrimary);
298 if (!ObjCPropertyDecl::findPropertyDecl(DC,
299 PIDecl->getDeclName().getAsIdentifierInfo())) {
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000300 // Protocol is not in the primary class. Must build one for it.
301 ObjCDeclSpec ProtocolPropertyODS;
302 // FIXME. Assuming that ObjCDeclSpec::ObjCPropertyAttributeKind
303 // and ObjCPropertyDecl::PropertyAttributeKind have identical
304 // values. Should consolidate both into one enum type.
305 ProtocolPropertyODS.
306 setPropertyAttributes((ObjCDeclSpec::ObjCPropertyAttributeKind)
307 PIkind);
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000308 // Must re-establish the context from class extension to primary
309 // class context.
Fariborz Jahanian79394182011-08-22 20:15:24 +0000310 ContextRAII SavedContext(*this, CCPrimary);
311
John McCalld226f652010-08-21 09:40:31 +0000312 Decl *ProtocolPtrTy =
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000313 ActOnProperty(S, AtLoc, FD, ProtocolPropertyODS,
314 PIDecl->getGetterName(),
315 PIDecl->getSetterName(),
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000316 isOverridingProperty,
Ted Kremenek4a2e9ea2010-09-23 21:18:05 +0000317 MethodImplKind,
318 /* lexicalDC = */ CDecl);
John McCalld226f652010-08-21 09:40:31 +0000319 PIDecl = cast<ObjCPropertyDecl>(ProtocolPtrTy);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000320 }
321 PIDecl->makeitReadWriteAttribute();
322 if (Attributes & ObjCDeclSpec::DQ_PR_retain)
323 PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
John McCallf85e1932011-06-15 23:02:42 +0000324 if (Attributes & ObjCDeclSpec::DQ_PR_strong)
325 PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000326 if (Attributes & ObjCDeclSpec::DQ_PR_copy)
327 PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
328 PIDecl->setSetterName(SetterSel);
329 } else {
Ted Kremenek788f4892010-10-21 18:49:42 +0000330 // Tailor the diagnostics for the common case where a readwrite
331 // property is declared both in the @interface and the continuation.
332 // This is a common error where the user often intended the original
333 // declaration to be readonly.
334 unsigned diag =
335 (Attributes & ObjCDeclSpec::DQ_PR_readwrite) &&
336 (PIkind & ObjCPropertyDecl::OBJC_PR_readwrite)
337 ? diag::err_use_continuation_class_redeclaration_readwrite
338 : diag::err_use_continuation_class;
339 Diag(AtLoc, diag)
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000340 << CCPrimary->getDeclName();
341 Diag(PIDecl->getLocation(), diag::note_property_declare);
342 }
343 *isOverridingProperty = true;
344 // Make sure setter decl is synthesized, and added to primary class's list.
Ted Kremenek8254aa62010-09-21 18:28:43 +0000345 ProcessPropertyDecl(PIDecl, CCPrimary, PDecl, CDecl);
John McCalld226f652010-08-21 09:40:31 +0000346 return 0;
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000347}
348
349ObjCPropertyDecl *Sema::CreatePropertyDecl(Scope *S,
350 ObjCContainerDecl *CDecl,
351 SourceLocation AtLoc,
352 FieldDeclarator &FD,
353 Selector GetterSel,
354 Selector SetterSel,
355 const bool isAssign,
356 const bool isReadWrite,
357 const unsigned Attributes,
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000358 const unsigned AttributesAsWritten,
John McCall83a230c2010-06-04 20:50:08 +0000359 TypeSourceInfo *TInfo,
Ted Kremenek23173d72010-05-18 21:09:07 +0000360 tok::ObjCKeywordKind MethodImplKind,
361 DeclContext *lexicalDC){
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000362 IdentifierInfo *PropertyId = FD.D.getIdentifier();
John McCall83a230c2010-06-04 20:50:08 +0000363 QualType T = TInfo->getType();
Ted Kremenek28685ab2010-03-12 00:46:40 +0000364
365 // Issue a warning if property is 'assign' as default and its object, which is
366 // gc'able conforms to NSCopying protocol
Douglas Gregore289d812011-09-13 17:21:33 +0000367 if (getLangOptions().getGC() != LangOptions::NonGC &&
Ted Kremenek28685ab2010-03-12 00:46:40 +0000368 isAssign && !(Attributes & ObjCDeclSpec::DQ_PR_assign))
John McCallc12c5bb2010-05-15 11:32:37 +0000369 if (const ObjCObjectPointerType *ObjPtrTy =
370 T->getAs<ObjCObjectPointerType>()) {
371 ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
372 if (IDecl)
373 if (ObjCProtocolDecl* PNSCopying =
374 LookupProtocol(&Context.Idents.get("NSCopying"), AtLoc))
375 if (IDecl->ClassImplementsProtocol(PNSCopying, true))
376 Diag(AtLoc, diag::warn_implements_nscopying) << PropertyId;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000377 }
John McCallc12c5bb2010-05-15 11:32:37 +0000378 if (T->isObjCObjectType())
Ted Kremenek28685ab2010-03-12 00:46:40 +0000379 Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object);
380
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000381 DeclContext *DC = cast<DeclContext>(CDecl);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000382 ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
383 FD.D.getIdentifierLoc(),
John McCall83a230c2010-06-04 20:50:08 +0000384 PropertyId, AtLoc, TInfo);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000385
Ted Kremenek9f550ff2010-03-15 20:11:46 +0000386 if (ObjCPropertyDecl *prevDecl =
387 ObjCPropertyDecl::findPropertyDecl(DC, PropertyId)) {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000388 Diag(PDecl->getLocation(), diag::err_duplicate_property);
Ted Kremenek894ae6a2010-03-15 18:47:25 +0000389 Diag(prevDecl->getLocation(), diag::note_property_declare);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000390 PDecl->setInvalidDecl();
391 }
Ted Kremenek23173d72010-05-18 21:09:07 +0000392 else {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000393 DC->addDecl(PDecl);
Ted Kremenek23173d72010-05-18 21:09:07 +0000394 if (lexicalDC)
395 PDecl->setLexicalDeclContext(lexicalDC);
396 }
Ted Kremenek28685ab2010-03-12 00:46:40 +0000397
398 if (T->isArrayType() || T->isFunctionType()) {
399 Diag(AtLoc, diag::err_property_type) << T;
400 PDecl->setInvalidDecl();
401 }
402
403 ProcessDeclAttributes(S, PDecl, FD.D);
404
405 // Regardless of setter/getter attribute, we save the default getter/setter
406 // selector names in anticipation of declaration of setter/getter methods.
407 PDecl->setGetterName(GetterSel);
408 PDecl->setSetterName(SetterSel);
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000409 PDecl->setPropertyAttributesAsWritten(
Argyrios Kyrtzidisdbbdec92011-11-06 18:58:12 +0000410 makePropertyAttributesAsWritten(AttributesAsWritten));
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000411
Ted Kremenek28685ab2010-03-12 00:46:40 +0000412 if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
413 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
414
415 if (Attributes & ObjCDeclSpec::DQ_PR_getter)
416 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
417
418 if (Attributes & ObjCDeclSpec::DQ_PR_setter)
419 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
420
421 if (isReadWrite)
422 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
423
424 if (Attributes & ObjCDeclSpec::DQ_PR_retain)
425 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
426
John McCallf85e1932011-06-15 23:02:42 +0000427 if (Attributes & ObjCDeclSpec::DQ_PR_strong)
428 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
429
430 if (Attributes & ObjCDeclSpec::DQ_PR_weak)
431 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_weak);
432
Ted Kremenek28685ab2010-03-12 00:46:40 +0000433 if (Attributes & ObjCDeclSpec::DQ_PR_copy)
434 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
435
John McCallf85e1932011-06-15 23:02:42 +0000436 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
437 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
438
Ted Kremenek28685ab2010-03-12 00:46:40 +0000439 if (isAssign)
440 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
441
John McCall265941b2011-09-13 18:31:23 +0000442 // In the semantic attributes, one of nonatomic or atomic is always set.
Ted Kremenek28685ab2010-03-12 00:46:40 +0000443 if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)
444 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
John McCall265941b2011-09-13 18:31:23 +0000445 else
Fariborz Jahanian45937ae2011-06-11 00:45:12 +0000446 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_atomic);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000447
John McCallf85e1932011-06-15 23:02:42 +0000448 // 'unsafe_unretained' is alias for 'assign'.
449 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
450 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
451 if (isAssign)
452 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
453
Ted Kremenek28685ab2010-03-12 00:46:40 +0000454 if (MethodImplKind == tok::objc_required)
455 PDecl->setPropertyImplementation(ObjCPropertyDecl::Required);
456 else if (MethodImplKind == tok::objc_optional)
457 PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000458
Ted Kremeneke3d67bc2010-03-12 02:31:10 +0000459 return PDecl;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000460}
461
John McCallf85e1932011-06-15 23:02:42 +0000462static void checkARCPropertyImpl(Sema &S, SourceLocation propertyImplLoc,
463 ObjCPropertyDecl *property,
464 ObjCIvarDecl *ivar) {
465 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
466
John McCallf85e1932011-06-15 23:02:42 +0000467 QualType ivarType = ivar->getType();
468 Qualifiers::ObjCLifetime ivarLifetime = ivarType.getObjCLifetime();
John McCallf85e1932011-06-15 23:02:42 +0000469
John McCall265941b2011-09-13 18:31:23 +0000470 // The lifetime implied by the property's attributes.
471 Qualifiers::ObjCLifetime propertyLifetime =
472 getImpliedARCOwnership(property->getPropertyAttributes(),
473 property->getType());
John McCallf85e1932011-06-15 23:02:42 +0000474
John McCall265941b2011-09-13 18:31:23 +0000475 // We're fine if they match.
476 if (propertyLifetime == ivarLifetime) return;
John McCallf85e1932011-06-15 23:02:42 +0000477
John McCall265941b2011-09-13 18:31:23 +0000478 // These aren't valid lifetimes for object ivars; don't diagnose twice.
479 if (ivarLifetime == Qualifiers::OCL_None ||
480 ivarLifetime == Qualifiers::OCL_Autoreleasing)
481 return;
John McCallf85e1932011-06-15 23:02:42 +0000482
John McCall265941b2011-09-13 18:31:23 +0000483 switch (propertyLifetime) {
484 case Qualifiers::OCL_Strong:
485 S.Diag(propertyImplLoc, diag::err_arc_strong_property_ownership)
486 << property->getDeclName()
487 << ivar->getDeclName()
488 << ivarLifetime;
489 break;
John McCallf85e1932011-06-15 23:02:42 +0000490
John McCall265941b2011-09-13 18:31:23 +0000491 case Qualifiers::OCL_Weak:
492 S.Diag(propertyImplLoc, diag::error_weak_property)
493 << property->getDeclName()
494 << ivar->getDeclName();
495 break;
John McCallf85e1932011-06-15 23:02:42 +0000496
John McCall265941b2011-09-13 18:31:23 +0000497 case Qualifiers::OCL_ExplicitNone:
498 S.Diag(propertyImplLoc, diag::err_arc_assign_property_ownership)
499 << property->getDeclName()
500 << ivar->getDeclName()
501 << ((property->getPropertyAttributesAsWritten()
502 & ObjCPropertyDecl::OBJC_PR_assign) != 0);
503 break;
John McCallf85e1932011-06-15 23:02:42 +0000504
John McCall265941b2011-09-13 18:31:23 +0000505 case Qualifiers::OCL_Autoreleasing:
506 llvm_unreachable("properties cannot be autoreleasing");
John McCallf85e1932011-06-15 23:02:42 +0000507
John McCall265941b2011-09-13 18:31:23 +0000508 case Qualifiers::OCL_None:
509 // Any other property should be ignored.
John McCallf85e1932011-06-15 23:02:42 +0000510 return;
511 }
512
513 S.Diag(property->getLocation(), diag::note_property_declare);
514}
515
Ted Kremenek28685ab2010-03-12 00:46:40 +0000516
517/// ActOnPropertyImplDecl - This routine performs semantic checks and
518/// builds the AST node for a property implementation declaration; declared
519/// as @synthesize or @dynamic.
520///
John McCalld226f652010-08-21 09:40:31 +0000521Decl *Sema::ActOnPropertyImplDecl(Scope *S,
522 SourceLocation AtLoc,
523 SourceLocation PropertyLoc,
524 bool Synthesize,
John McCalld226f652010-08-21 09:40:31 +0000525 IdentifierInfo *PropertyId,
Douglas Gregora4ffd852010-11-17 01:03:52 +0000526 IdentifierInfo *PropertyIvar,
527 SourceLocation PropertyIvarLoc) {
Ted Kremeneke9686572010-04-05 23:45:09 +0000528 ObjCContainerDecl *ClassImpDecl =
Fariborz Jahanian84e0ccf2011-09-19 16:32:32 +0000529 dyn_cast<ObjCContainerDecl>(CurContext);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000530 // Make sure we have a context for the property implementation declaration.
531 if (!ClassImpDecl) {
532 Diag(AtLoc, diag::error_missing_property_context);
John McCalld226f652010-08-21 09:40:31 +0000533 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000534 }
535 ObjCPropertyDecl *property = 0;
536 ObjCInterfaceDecl* IDecl = 0;
537 // Find the class or category class where this property must have
538 // a declaration.
539 ObjCImplementationDecl *IC = 0;
540 ObjCCategoryImplDecl* CatImplClass = 0;
541 if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
542 IDecl = IC->getClassInterface();
543 // We always synthesize an interface for an implementation
544 // without an interface decl. So, IDecl is always non-zero.
545 assert(IDecl &&
546 "ActOnPropertyImplDecl - @implementation without @interface");
547
548 // Look for this property declaration in the @implementation's @interface
549 property = IDecl->FindPropertyDeclaration(PropertyId);
550 if (!property) {
551 Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName();
John McCalld226f652010-08-21 09:40:31 +0000552 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000553 }
Fariborz Jahaniandd4430e2010-12-17 22:28:16 +0000554 unsigned PIkind = property->getPropertyAttributesAsWritten();
Fariborz Jahanian45937ae2011-06-11 00:45:12 +0000555 if ((PIkind & (ObjCPropertyDecl::OBJC_PR_atomic |
556 ObjCPropertyDecl::OBJC_PR_nonatomic) ) == 0) {
Fariborz Jahaniandd4430e2010-12-17 22:28:16 +0000557 if (AtLoc.isValid())
558 Diag(AtLoc, diag::warn_implicit_atomic_property);
559 else
560 Diag(IC->getLocation(), diag::warn_auto_implicit_atomic_property);
561 Diag(property->getLocation(), diag::note_property_declare);
562 }
563
Ted Kremenek28685ab2010-03-12 00:46:40 +0000564 if (const ObjCCategoryDecl *CD =
565 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
566 if (!CD->IsClassExtension()) {
567 Diag(PropertyLoc, diag::error_category_property) << CD->getDeclName();
568 Diag(property->getLocation(), diag::note_property_declare);
John McCalld226f652010-08-21 09:40:31 +0000569 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000570 }
571 }
572 } else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
573 if (Synthesize) {
574 Diag(AtLoc, diag::error_synthesize_category_decl);
John McCalld226f652010-08-21 09:40:31 +0000575 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000576 }
577 IDecl = CatImplClass->getClassInterface();
578 if (!IDecl) {
579 Diag(AtLoc, diag::error_missing_property_interface);
John McCalld226f652010-08-21 09:40:31 +0000580 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000581 }
582 ObjCCategoryDecl *Category =
583 IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
584
585 // If category for this implementation not found, it is an error which
586 // has already been reported eralier.
587 if (!Category)
John McCalld226f652010-08-21 09:40:31 +0000588 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000589 // Look for this property declaration in @implementation's category
590 property = Category->FindPropertyDeclaration(PropertyId);
591 if (!property) {
592 Diag(PropertyLoc, diag::error_bad_category_property_decl)
593 << Category->getDeclName();
John McCalld226f652010-08-21 09:40:31 +0000594 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000595 }
596 } else {
597 Diag(AtLoc, diag::error_bad_property_context);
John McCalld226f652010-08-21 09:40:31 +0000598 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000599 }
600 ObjCIvarDecl *Ivar = 0;
601 // Check that we have a valid, previously declared ivar for @synthesize
602 if (Synthesize) {
603 // @synthesize
604 if (!PropertyIvar)
605 PropertyIvar = PropertyId;
John McCallf85e1932011-06-15 23:02:42 +0000606 ObjCPropertyDecl::PropertyAttributeKind kind
607 = property->getPropertyAttributes();
John McCall265941b2011-09-13 18:31:23 +0000608 QualType PropType = property->getType();
609
610 QualType PropertyIvarType = PropType.getNonReferenceType();
611
612 // Add GC __weak to the ivar type if the property is weak.
613 if ((kind & ObjCPropertyDecl::OBJC_PR_weak) &&
Douglas Gregore289d812011-09-13 17:21:33 +0000614 getLangOptions().getGC() != LangOptions::NonGC) {
John McCall265941b2011-09-13 18:31:23 +0000615 assert(!getLangOptions().ObjCAutoRefCount);
616 if (PropertyIvarType.isObjCGCStrong()) {
617 Diag(PropertyLoc, diag::err_gc_weak_property_strong_type);
618 Diag(property->getLocation(), diag::note_property_declare);
619 } else {
620 PropertyIvarType =
621 Context.getObjCGCQualType(PropertyIvarType, Qualifiers::Weak);
Fariborz Jahanianedc08822011-09-07 16:24:21 +0000622 }
Fariborz Jahanianedc08822011-09-07 16:24:21 +0000623 }
John McCall265941b2011-09-13 18:31:23 +0000624
Ted Kremenek28685ab2010-03-12 00:46:40 +0000625 // Check that this is a previously declared 'ivar' in 'IDecl' interface
626 ObjCInterfaceDecl *ClassDeclared;
627 Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
628 if (!Ivar) {
John McCall265941b2011-09-13 18:31:23 +0000629 // In ARC, give the ivar a lifetime qualifier based on the
John McCallf85e1932011-06-15 23:02:42 +0000630 // property attributes.
631 if (getLangOptions().ObjCAutoRefCount &&
John McCall265941b2011-09-13 18:31:23 +0000632 !PropertyIvarType.getObjCLifetime() &&
633 PropertyIvarType->isObjCRetainableType()) {
John McCallf85e1932011-06-15 23:02:42 +0000634
John McCall265941b2011-09-13 18:31:23 +0000635 // It's an error if we have to do this and the user didn't
636 // explicitly write an ownership attribute on the property.
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000637 if (!property->hasWrittenStorageAttribute() &&
John McCall265941b2011-09-13 18:31:23 +0000638 !(kind & ObjCPropertyDecl::OBJC_PR_strong)) {
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000639 Diag(PropertyLoc,
640 diag::err_arc_objc_property_default_assign_on_object);
641 Diag(property->getLocation(), diag::note_property_declare);
John McCall265941b2011-09-13 18:31:23 +0000642 } else {
643 Qualifiers::ObjCLifetime lifetime =
644 getImpliedARCOwnership(kind, PropertyIvarType);
645 assert(lifetime && "no lifetime for property?");
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000646
John McCall265941b2011-09-13 18:31:23 +0000647 if (lifetime == Qualifiers::OCL_Weak &&
648 !getLangOptions().ObjCRuntimeHasWeak) {
John McCallf85e1932011-06-15 23:02:42 +0000649 Diag(PropertyLoc, diag::err_arc_weak_no_runtime);
650 Diag(property->getLocation(), diag::note_property_declare);
651 }
John McCall265941b2011-09-13 18:31:23 +0000652
John McCallf85e1932011-06-15 23:02:42 +0000653 Qualifiers qs;
John McCall265941b2011-09-13 18:31:23 +0000654 qs.addObjCLifetime(lifetime);
John McCallf85e1932011-06-15 23:02:42 +0000655 PropertyIvarType = Context.getQualifiedType(PropertyIvarType, qs);
656 }
John McCallf85e1932011-06-15 23:02:42 +0000657 }
658
659 if (kind & ObjCPropertyDecl::OBJC_PR_weak &&
660 !getLangOptions().ObjCAutoRefCount &&
Douglas Gregore289d812011-09-13 17:21:33 +0000661 getLangOptions().getGC() == LangOptions::NonGC) {
John McCallf85e1932011-06-15 23:02:42 +0000662 Diag(PropertyLoc, diag::error_synthesize_weak_non_arc_or_gc);
663 Diag(property->getLocation(), diag::note_property_declare);
664 }
665
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000666 Ivar = ObjCIvarDecl::Create(Context, ClassImpDecl,
667 PropertyLoc, PropertyLoc, PropertyIvar,
Fariborz Jahanian14086762011-03-28 23:47:18 +0000668 PropertyIvarType, /*Dinfo=*/0,
Fariborz Jahanian75049662010-12-15 23:29:04 +0000669 ObjCIvarDecl::Private,
Fariborz Jahanianad51e742010-07-17 00:59:30 +0000670 (Expr *)0, true);
Daniel Dunbar29fa69a2010-04-02 19:44:54 +0000671 ClassImpDecl->addDecl(Ivar);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000672 IDecl->makeDeclVisibleInContext(Ivar, false);
673 property->setPropertyIvarDecl(Ivar);
674
675 if (!getLangOptions().ObjCNonFragileABI)
676 Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
677 // Note! I deliberately want it to fall thru so, we have a
678 // a property implementation and to avoid future warnings.
679 } else if (getLangOptions().ObjCNonFragileABI &&
680 ClassDeclared != IDecl) {
681 Diag(PropertyLoc, diag::error_ivar_in_superclass_use)
682 << property->getDeclName() << Ivar->getDeclName()
683 << ClassDeclared->getDeclName();
684 Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
Daniel Dunbar4087f272010-08-17 22:39:59 +0000685 << Ivar << Ivar->getName();
Ted Kremenek28685ab2010-03-12 00:46:40 +0000686 // Note! I deliberately want it to fall thru so more errors are caught.
687 }
688 QualType IvarType = Context.getCanonicalType(Ivar->getType());
689
690 // Check that type of property and its ivar are type compatible.
John McCall265941b2011-09-13 18:31:23 +0000691 if (Context.getCanonicalType(PropertyIvarType) != IvarType) {
Fariborz Jahanian62ac5d02010-05-18 23:04:17 +0000692 bool compat = false;
Fariborz Jahanian14086762011-03-28 23:47:18 +0000693 if (isa<ObjCObjectPointerType>(PropertyIvarType)
John McCallf85e1932011-06-15 23:02:42 +0000694 && isa<ObjCObjectPointerType>(IvarType))
Fariborz Jahanian62ac5d02010-05-18 23:04:17 +0000695 compat =
696 Context.canAssignObjCInterfaces(
Fariborz Jahanian14086762011-03-28 23:47:18 +0000697 PropertyIvarType->getAs<ObjCObjectPointerType>(),
Fariborz Jahanian62ac5d02010-05-18 23:04:17 +0000698 IvarType->getAs<ObjCObjectPointerType>());
Douglas Gregorb608b982011-01-28 02:26:04 +0000699 else {
700 SourceLocation Loc = PropertyIvarLoc;
701 if (Loc.isInvalid())
702 Loc = PropertyLoc;
Fariborz Jahanian14086762011-03-28 23:47:18 +0000703 compat = (CheckAssignmentConstraints(Loc, PropertyIvarType, IvarType)
John McCalldaa8e4e2010-11-15 09:13:47 +0000704 == Compatible);
Douglas Gregorb608b982011-01-28 02:26:04 +0000705 }
Fariborz Jahanian62ac5d02010-05-18 23:04:17 +0000706 if (!compat) {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000707 Diag(PropertyLoc, diag::error_property_ivar_type)
Ted Kremenekf921a482010-03-23 19:02:22 +0000708 << property->getDeclName() << PropType
709 << Ivar->getDeclName() << IvarType;
710 Diag(Ivar->getLocation(), diag::note_ivar_decl);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000711 // Note! I deliberately want it to fall thru so, we have a
712 // a property implementation and to avoid future warnings.
713 }
714
715 // FIXME! Rules for properties are somewhat different that those
716 // for assignments. Use a new routine to consolidate all cases;
717 // specifically for property redeclarations as well as for ivars.
Fariborz Jahanian14086762011-03-28 23:47:18 +0000718 QualType lhsType =Context.getCanonicalType(PropertyIvarType).getUnqualifiedType();
Ted Kremenek28685ab2010-03-12 00:46:40 +0000719 QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
720 if (lhsType != rhsType &&
721 lhsType->isArithmeticType()) {
722 Diag(PropertyLoc, diag::error_property_ivar_type)
Ted Kremenekf921a482010-03-23 19:02:22 +0000723 << property->getDeclName() << PropType
724 << Ivar->getDeclName() << IvarType;
725 Diag(Ivar->getLocation(), diag::note_ivar_decl);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000726 // Fall thru - see previous comment
727 }
728 // __weak is explicit. So it works on Canonical type.
John McCallf85e1932011-06-15 23:02:42 +0000729 if ((PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
Douglas Gregore289d812011-09-13 17:21:33 +0000730 getLangOptions().getGC() != LangOptions::NonGC)) {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000731 Diag(PropertyLoc, diag::error_weak_property)
732 << property->getDeclName() << Ivar->getDeclName();
Fariborz Jahanianedc08822011-09-07 16:24:21 +0000733 Diag(Ivar->getLocation(), diag::note_ivar_decl);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000734 // Fall thru - see previous comment
735 }
John McCallf85e1932011-06-15 23:02:42 +0000736 // Fall thru - see previous comment
Ted Kremenek28685ab2010-03-12 00:46:40 +0000737 if ((property->getType()->isObjCObjectPointerType() ||
738 PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() &&
Douglas Gregore289d812011-09-13 17:21:33 +0000739 getLangOptions().getGC() != LangOptions::NonGC) {
Ted Kremenek28685ab2010-03-12 00:46:40 +0000740 Diag(PropertyLoc, diag::error_strong_property)
741 << property->getDeclName() << Ivar->getDeclName();
742 // Fall thru - see previous comment
743 }
744 }
John McCallf85e1932011-06-15 23:02:42 +0000745 if (getLangOptions().ObjCAutoRefCount)
746 checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
Ted Kremenek28685ab2010-03-12 00:46:40 +0000747 } else if (PropertyIvar)
748 // @dynamic
749 Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
John McCallf85e1932011-06-15 23:02:42 +0000750
Ted Kremenek28685ab2010-03-12 00:46:40 +0000751 assert (property && "ActOnPropertyImplDecl - property declaration missing");
752 ObjCPropertyImplDecl *PIDecl =
753 ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc,
754 property,
755 (Synthesize ?
756 ObjCPropertyImplDecl::Synthesize
757 : ObjCPropertyImplDecl::Dynamic),
Douglas Gregora4ffd852010-11-17 01:03:52 +0000758 Ivar, PropertyIvarLoc);
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000759 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
760 getterMethod->createImplicitParams(Context, IDecl);
Fariborz Jahanian0313f442010-10-15 22:42:59 +0000761 if (getLangOptions().CPlusPlus && Synthesize &&
762 Ivar->getType()->isRecordType()) {
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000763 // For Objective-C++, need to synthesize the AST for the IVAR object to be
764 // returned by the getter as it must conform to C++'s copy-return rules.
765 // FIXME. Eventually we want to do this for Objective-C as well.
766 ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl();
767 DeclRefExpr *SelfExpr =
John McCallf89e55a2010-11-18 06:31:45 +0000768 new (Context) DeclRefExpr(SelfDecl, SelfDecl->getType(),
769 VK_RValue, SourceLocation());
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000770 Expr *IvarRefExpr =
771 new (Context) ObjCIvarRefExpr(Ivar, Ivar->getType(), AtLoc,
772 SelfExpr, true, true);
John McCall60d7b3a2010-08-24 06:29:42 +0000773 ExprResult Res =
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000774 PerformCopyInitialization(InitializedEntity::InitializeResult(
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000775 SourceLocation(),
776 getterMethod->getResultType(),
777 /*NRVO=*/false),
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000778 SourceLocation(),
779 Owned(IvarRefExpr));
780 if (!Res.isInvalid()) {
781 Expr *ResExpr = Res.takeAs<Expr>();
782 if (ResExpr)
John McCall4765fa02010-12-06 08:20:24 +0000783 ResExpr = MaybeCreateExprWithCleanups(ResExpr);
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000784 PIDecl->setGetterCXXConstructor(ResExpr);
785 }
786 }
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000787 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
788 !getterMethod->hasAttr<NSReturnsNotRetainedAttr>()) {
789 Diag(getterMethod->getLocation(),
790 diag::warn_property_getter_owning_mismatch);
791 Diag(property->getLocation(), diag::note_property_declare);
792 }
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000793 }
794 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
795 setterMethod->createImplicitParams(Context, IDecl);
Fariborz Jahanian0313f442010-10-15 22:42:59 +0000796 if (getLangOptions().CPlusPlus && Synthesize
797 && Ivar->getType()->isRecordType()) {
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000798 // FIXME. Eventually we want to do this for Objective-C as well.
799 ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl();
800 DeclRefExpr *SelfExpr =
John McCallf89e55a2010-11-18 06:31:45 +0000801 new (Context) DeclRefExpr(SelfDecl, SelfDecl->getType(),
802 VK_RValue, SourceLocation());
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000803 Expr *lhs =
804 new (Context) ObjCIvarRefExpr(Ivar, Ivar->getType(), AtLoc,
805 SelfExpr, true, true);
806 ObjCMethodDecl::param_iterator P = setterMethod->param_begin();
807 ParmVarDecl *Param = (*P);
John McCall3c3b7f92011-10-25 17:37:35 +0000808 QualType T = Param->getType().getNonReferenceType();
Fariborz Jahanian14086762011-03-28 23:47:18 +0000809 Expr *rhs = new (Context) DeclRefExpr(Param, T,
John McCallf89e55a2010-11-18 06:31:45 +0000810 VK_LValue, SourceLocation());
Fariborz Jahanianfa432392010-10-14 21:30:10 +0000811 ExprResult Res = BuildBinOp(S, lhs->getLocEnd(),
John McCall2de56d12010-08-25 11:45:40 +0000812 BO_Assign, lhs, rhs);
Fariborz Jahanian57e264e2011-10-06 18:38:18 +0000813 if (property->getPropertyAttributes() &
814 ObjCPropertyDecl::OBJC_PR_atomic) {
815 Expr *callExpr = Res.takeAs<Expr>();
816 if (const CXXOperatorCallExpr *CXXCE =
Fariborz Jahanian13bf6332011-10-07 21:08:14 +0000817 dyn_cast_or_null<CXXOperatorCallExpr>(callExpr))
818 if (const FunctionDecl *FuncDecl = CXXCE->getDirectCallee())
Fariborz Jahanian57e264e2011-10-06 18:38:18 +0000819 if (!FuncDecl->isTrivial())
820 Diag(PropertyLoc,
821 diag::warn_atomic_property_nontrivial_assign_op)
822 << property->getType();
Fariborz Jahanian57e264e2011-10-06 18:38:18 +0000823 }
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000824 PIDecl->setSetterCXXAssignment(Res.takeAs<Expr>());
825 }
826 }
827
Ted Kremenek28685ab2010-03-12 00:46:40 +0000828 if (IC) {
829 if (Synthesize)
830 if (ObjCPropertyImplDecl *PPIDecl =
831 IC->FindPropertyImplIvarDecl(PropertyIvar)) {
832 Diag(PropertyLoc, diag::error_duplicate_ivar_use)
833 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
834 << PropertyIvar;
835 Diag(PPIDecl->getLocation(), diag::note_previous_use);
836 }
837
838 if (ObjCPropertyImplDecl *PPIDecl
839 = IC->FindPropertyImplDecl(PropertyId)) {
840 Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
841 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
John McCalld226f652010-08-21 09:40:31 +0000842 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000843 }
844 IC->addPropertyImplementation(PIDecl);
Fariborz Jahaniane776f882011-01-03 18:08:02 +0000845 if (getLangOptions().ObjCDefaultSynthProperties &&
846 getLangOptions().ObjCNonFragileABI2) {
Fariborz Jahanianad51e742010-07-17 00:59:30 +0000847 // Diagnose if an ivar was lazily synthesdized due to a previous
848 // use and if 1) property is @dynamic or 2) property is synthesized
Fariborz Jahaniancdaa6a82010-08-24 18:48:05 +0000849 // but it requires an ivar of different name.
Fariborz Jahanian411c25c2011-01-20 23:34:25 +0000850 ObjCInterfaceDecl *ClassDeclared=0;
Fariborz Jahanianad51e742010-07-17 00:59:30 +0000851 ObjCIvarDecl *Ivar = 0;
852 if (!Synthesize)
853 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
854 else {
855 if (PropertyIvar && PropertyIvar != PropertyId)
856 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
857 }
Fariborz Jahaniancdaa6a82010-08-24 18:48:05 +0000858 // Issue diagnostics only if Ivar belongs to current class.
859 if (Ivar && Ivar->getSynthesize() &&
860 IC->getClassInterface() == ClassDeclared) {
Fariborz Jahanianad51e742010-07-17 00:59:30 +0000861 Diag(Ivar->getLocation(), diag::err_undeclared_var_use)
862 << PropertyId;
863 Ivar->setInvalidDecl();
864 }
865 }
Ted Kremenek28685ab2010-03-12 00:46:40 +0000866 } else {
867 if (Synthesize)
868 if (ObjCPropertyImplDecl *PPIDecl =
869 CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
870 Diag(PropertyLoc, diag::error_duplicate_ivar_use)
871 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
872 << PropertyIvar;
873 Diag(PPIDecl->getLocation(), diag::note_previous_use);
874 }
875
876 if (ObjCPropertyImplDecl *PPIDecl =
877 CatImplClass->FindPropertyImplDecl(PropertyId)) {
878 Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
879 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
John McCalld226f652010-08-21 09:40:31 +0000880 return 0;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000881 }
882 CatImplClass->addPropertyImplementation(PIDecl);
883 }
884
John McCalld226f652010-08-21 09:40:31 +0000885 return PIDecl;
Ted Kremenek28685ab2010-03-12 00:46:40 +0000886}
887
888//===----------------------------------------------------------------------===//
889// Helper methods.
890//===----------------------------------------------------------------------===//
891
Ted Kremenek9d64c152010-03-12 00:38:38 +0000892/// DiagnosePropertyMismatch - Compares two properties for their
893/// attributes and types and warns on a variety of inconsistencies.
894///
895void
896Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
897 ObjCPropertyDecl *SuperProperty,
898 const IdentifierInfo *inheritedName) {
899 ObjCPropertyDecl::PropertyAttributeKind CAttr =
900 Property->getPropertyAttributes();
901 ObjCPropertyDecl::PropertyAttributeKind SAttr =
902 SuperProperty->getPropertyAttributes();
903 if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
904 && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
905 Diag(Property->getLocation(), diag::warn_readonly_property)
906 << Property->getDeclName() << inheritedName;
907 if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
908 != (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
909 Diag(Property->getLocation(), diag::warn_property_attribute)
910 << Property->getDeclName() << "copy" << inheritedName;
Fariborz Jahanian1b46d8d2011-10-08 17:45:33 +0000911 else if (!(SAttr & ObjCPropertyDecl::OBJC_PR_readonly)){
John McCallf85e1932011-06-15 23:02:42 +0000912 unsigned CAttrRetain =
913 (CAttr &
914 (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_strong));
915 unsigned SAttrRetain =
916 (SAttr &
917 (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_strong));
918 bool CStrong = (CAttrRetain != 0);
919 bool SStrong = (SAttrRetain != 0);
920 if (CStrong != SStrong)
921 Diag(Property->getLocation(), diag::warn_property_attribute)
922 << Property->getDeclName() << "retain (or strong)" << inheritedName;
923 }
Ted Kremenek9d64c152010-03-12 00:38:38 +0000924
925 if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
926 != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
927 Diag(Property->getLocation(), diag::warn_property_attribute)
928 << Property->getDeclName() << "atomic" << inheritedName;
929 if (Property->getSetterName() != SuperProperty->getSetterName())
930 Diag(Property->getLocation(), diag::warn_property_attribute)
931 << Property->getDeclName() << "setter" << inheritedName;
932 if (Property->getGetterName() != SuperProperty->getGetterName())
933 Diag(Property->getLocation(), diag::warn_property_attribute)
934 << Property->getDeclName() << "getter" << inheritedName;
935
936 QualType LHSType =
937 Context.getCanonicalType(SuperProperty->getType());
938 QualType RHSType =
939 Context.getCanonicalType(Property->getType());
940
Fariborz Jahanianc286f382011-07-12 22:05:16 +0000941 if (!Context.propertyTypesAreCompatible(LHSType, RHSType)) {
Fariborz Jahanian8beb6a22011-07-13 17:55:01 +0000942 // Do cases not handled in above.
943 // FIXME. For future support of covariant property types, revisit this.
944 bool IncompatibleObjC = false;
945 QualType ConvertedType;
946 if (!isObjCPointerConversion(RHSType, LHSType,
947 ConvertedType, IncompatibleObjC) ||
Fariborz Jahanian13546a82011-10-12 00:00:57 +0000948 IncompatibleObjC) {
Fariborz Jahanian8beb6a22011-07-13 17:55:01 +0000949 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
950 << Property->getType() << SuperProperty->getType() << inheritedName;
Fariborz Jahanian13546a82011-10-12 00:00:57 +0000951 Diag(SuperProperty->getLocation(), diag::note_property_declare);
952 }
Ted Kremenek9d64c152010-03-12 00:38:38 +0000953 }
954}
955
956bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
957 ObjCMethodDecl *GetterMethod,
958 SourceLocation Loc) {
959 if (GetterMethod &&
John McCall3c3b7f92011-10-25 17:37:35 +0000960 !Context.hasSameType(GetterMethod->getResultType().getNonReferenceType(),
961 property->getType().getNonReferenceType())) {
Ted Kremenek9d64c152010-03-12 00:38:38 +0000962 AssignConvertType result = Incompatible;
John McCall1c23e912010-11-16 02:32:08 +0000963 if (property->getType()->isObjCObjectPointerType())
Douglas Gregorb608b982011-01-28 02:26:04 +0000964 result = CheckAssignmentConstraints(Loc, GetterMethod->getResultType(),
John McCall1c23e912010-11-16 02:32:08 +0000965 property->getType());
Ted Kremenek9d64c152010-03-12 00:38:38 +0000966 if (result != Compatible) {
967 Diag(Loc, diag::warn_accessor_property_type_mismatch)
968 << property->getDeclName()
969 << GetterMethod->getSelector();
970 Diag(GetterMethod->getLocation(), diag::note_declared_at);
971 return true;
972 }
973 }
974 return false;
975}
976
977/// ComparePropertiesInBaseAndSuper - This routine compares property
978/// declarations in base and its super class, if any, and issues
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000979/// diagnostics in a variety of inconsistent situations.
Ted Kremenek9d64c152010-03-12 00:38:38 +0000980///
981void Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) {
982 ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
983 if (!SDecl)
984 return;
985 // FIXME: O(N^2)
986 for (ObjCInterfaceDecl::prop_iterator S = SDecl->prop_begin(),
987 E = SDecl->prop_end(); S != E; ++S) {
988 ObjCPropertyDecl *SuperPDecl = (*S);
989 // Does property in super class has declaration in current class?
990 for (ObjCInterfaceDecl::prop_iterator I = IDecl->prop_begin(),
991 E = IDecl->prop_end(); I != E; ++I) {
992 ObjCPropertyDecl *PDecl = (*I);
993 if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
994 DiagnosePropertyMismatch(PDecl, SuperPDecl,
995 SDecl->getIdentifier());
996 }
997 }
998}
999
1000/// MatchOneProtocolPropertiesInClass - This routine goes thru the list
1001/// of properties declared in a protocol and compares their attribute against
1002/// the same property declared in the class or category.
1003void
1004Sema::MatchOneProtocolPropertiesInClass(Decl *CDecl,
1005 ObjCProtocolDecl *PDecl) {
1006 ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl);
1007 if (!IDecl) {
1008 // Category
1009 ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl);
1010 assert (CatDecl && "MatchOneProtocolPropertiesInClass");
1011 if (!CatDecl->IsClassExtension())
1012 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
1013 E = PDecl->prop_end(); P != E; ++P) {
1014 ObjCPropertyDecl *Pr = (*P);
1015 ObjCCategoryDecl::prop_iterator CP, CE;
1016 // Is this property already in category's list of properties?
Ted Kremenek2d2f9362010-03-12 00:49:00 +00001017 for (CP = CatDecl->prop_begin(), CE = CatDecl->prop_end(); CP!=CE; ++CP)
Ted Kremenek9d64c152010-03-12 00:38:38 +00001018 if ((*CP)->getIdentifier() == Pr->getIdentifier())
1019 break;
1020 if (CP != CE)
1021 // Property protocol already exist in class. Diagnose any mismatch.
1022 DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
1023 }
1024 return;
1025 }
1026 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
1027 E = PDecl->prop_end(); P != E; ++P) {
1028 ObjCPropertyDecl *Pr = (*P);
1029 ObjCInterfaceDecl::prop_iterator CP, CE;
1030 // Is this property already in class's list of properties?
1031 for (CP = IDecl->prop_begin(), CE = IDecl->prop_end(); CP != CE; ++CP)
1032 if ((*CP)->getIdentifier() == Pr->getIdentifier())
1033 break;
1034 if (CP != CE)
1035 // Property protocol already exist in class. Diagnose any mismatch.
1036 DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
1037 }
1038}
1039
1040/// CompareProperties - This routine compares properties
1041/// declared in 'ClassOrProtocol' objects (which can be a class or an
1042/// inherited protocol with the list of properties for class/category 'CDecl'
1043///
John McCalld226f652010-08-21 09:40:31 +00001044void Sema::CompareProperties(Decl *CDecl, Decl *ClassOrProtocol) {
1045 Decl *ClassDecl = ClassOrProtocol;
Ted Kremenek9d64c152010-03-12 00:38:38 +00001046 ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl);
1047
1048 if (!IDecl) {
1049 // Category
1050 ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl);
1051 assert (CatDecl && "CompareProperties");
1052 if (ObjCCategoryDecl *MDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
1053 for (ObjCCategoryDecl::protocol_iterator P = MDecl->protocol_begin(),
1054 E = MDecl->protocol_end(); P != E; ++P)
1055 // Match properties of category with those of protocol (*P)
1056 MatchOneProtocolPropertiesInClass(CatDecl, *P);
1057
1058 // Go thru the list of protocols for this category and recursively match
1059 // their properties with those in the category.
1060 for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(),
1061 E = CatDecl->protocol_end(); P != E; ++P)
John McCalld226f652010-08-21 09:40:31 +00001062 CompareProperties(CatDecl, *P);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001063 } else {
1064 ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
1065 for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
1066 E = MD->protocol_end(); P != E; ++P)
1067 MatchOneProtocolPropertiesInClass(CatDecl, *P);
1068 }
1069 return;
1070 }
1071
1072 if (ObjCInterfaceDecl *MDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
Ted Kremenek53b94412010-09-01 01:21:15 +00001073 for (ObjCInterfaceDecl::all_protocol_iterator
1074 P = MDecl->all_referenced_protocol_begin(),
1075 E = MDecl->all_referenced_protocol_end(); P != E; ++P)
Ted Kremenek9d64c152010-03-12 00:38:38 +00001076 // Match properties of class IDecl with those of protocol (*P).
1077 MatchOneProtocolPropertiesInClass(IDecl, *P);
1078
1079 // Go thru the list of protocols for this class and recursively match
1080 // their properties with those declared in the class.
Ted Kremenek53b94412010-09-01 01:21:15 +00001081 for (ObjCInterfaceDecl::all_protocol_iterator
1082 P = IDecl->all_referenced_protocol_begin(),
1083 E = IDecl->all_referenced_protocol_end(); P != E; ++P)
John McCalld226f652010-08-21 09:40:31 +00001084 CompareProperties(IDecl, *P);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001085 } else {
1086 ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
1087 for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
1088 E = MD->protocol_end(); P != E; ++P)
1089 MatchOneProtocolPropertiesInClass(IDecl, *P);
1090 }
1091}
1092
1093/// isPropertyReadonly - Return true if property is readonly, by searching
1094/// for the property in the class and in its categories and implementations
1095///
1096bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
1097 ObjCInterfaceDecl *IDecl) {
1098 // by far the most common case.
1099 if (!PDecl->isReadOnly())
1100 return false;
1101 // Even if property is ready only, if interface has a user defined setter,
1102 // it is not considered read only.
1103 if (IDecl->getInstanceMethod(PDecl->getSetterName()))
1104 return false;
1105
1106 // Main class has the property as 'readonly'. Must search
1107 // through the category list to see if the property's
1108 // attribute has been over-ridden to 'readwrite'.
1109 for (ObjCCategoryDecl *Category = IDecl->getCategoryList();
1110 Category; Category = Category->getNextClassCategory()) {
1111 // Even if property is ready only, if a category has a user defined setter,
1112 // it is not considered read only.
1113 if (Category->getInstanceMethod(PDecl->getSetterName()))
1114 return false;
1115 ObjCPropertyDecl *P =
1116 Category->FindPropertyDeclaration(PDecl->getIdentifier());
1117 if (P && !P->isReadOnly())
1118 return false;
1119 }
1120
1121 // Also, check for definition of a setter method in the implementation if
1122 // all else failed.
1123 if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(CurContext)) {
1124 if (ObjCImplementationDecl *IMD =
1125 dyn_cast<ObjCImplementationDecl>(OMD->getDeclContext())) {
1126 if (IMD->getInstanceMethod(PDecl->getSetterName()))
1127 return false;
1128 } else if (ObjCCategoryImplDecl *CIMD =
1129 dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) {
1130 if (CIMD->getInstanceMethod(PDecl->getSetterName()))
1131 return false;
1132 }
1133 }
1134 // Lastly, look through the implementation (if one is in scope).
1135 if (ObjCImplementationDecl *ImpDecl = IDecl->getImplementation())
1136 if (ImpDecl->getInstanceMethod(PDecl->getSetterName()))
1137 return false;
1138 // If all fails, look at the super class.
1139 if (ObjCInterfaceDecl *SIDecl = IDecl->getSuperClass())
1140 return isPropertyReadonly(PDecl, SIDecl);
1141 return true;
1142}
1143
1144/// CollectImmediateProperties - This routine collects all properties in
1145/// the class and its conforming protocols; but not those it its super class.
1146void Sema::CollectImmediateProperties(ObjCContainerDecl *CDecl,
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001147 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1148 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap) {
Ted Kremenek9d64c152010-03-12 00:38:38 +00001149 if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
1150 for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
1151 E = IDecl->prop_end(); P != E; ++P) {
1152 ObjCPropertyDecl *Prop = (*P);
1153 PropMap[Prop->getIdentifier()] = Prop;
1154 }
1155 // scan through class's protocols.
Ted Kremenek53b94412010-09-01 01:21:15 +00001156 for (ObjCInterfaceDecl::all_protocol_iterator
1157 PI = IDecl->all_referenced_protocol_begin(),
1158 E = IDecl->all_referenced_protocol_end(); PI != E; ++PI)
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001159 CollectImmediateProperties((*PI), PropMap, SuperPropMap);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001160 }
1161 if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
1162 if (!CATDecl->IsClassExtension())
1163 for (ObjCContainerDecl::prop_iterator P = CATDecl->prop_begin(),
1164 E = CATDecl->prop_end(); P != E; ++P) {
1165 ObjCPropertyDecl *Prop = (*P);
1166 PropMap[Prop->getIdentifier()] = Prop;
1167 }
1168 // scan through class's protocols.
Ted Kremenek53b94412010-09-01 01:21:15 +00001169 for (ObjCCategoryDecl::protocol_iterator PI = CATDecl->protocol_begin(),
Ted Kremenek9d64c152010-03-12 00:38:38 +00001170 E = CATDecl->protocol_end(); PI != E; ++PI)
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001171 CollectImmediateProperties((*PI), PropMap, SuperPropMap);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001172 }
1173 else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
1174 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
1175 E = PDecl->prop_end(); P != E; ++P) {
1176 ObjCPropertyDecl *Prop = (*P);
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001177 ObjCPropertyDecl *PropertyFromSuper = SuperPropMap[Prop->getIdentifier()];
1178 // Exclude property for protocols which conform to class's super-class,
1179 // as super-class has to implement the property.
Fariborz Jahaniana929ec72011-09-27 00:23:52 +00001180 if (!PropertyFromSuper ||
1181 PropertyFromSuper->getIdentifier() != Prop->getIdentifier()) {
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001182 ObjCPropertyDecl *&PropEntry = PropMap[Prop->getIdentifier()];
1183 if (!PropEntry)
1184 PropEntry = Prop;
1185 }
Ted Kremenek9d64c152010-03-12 00:38:38 +00001186 }
1187 // scan through protocol's protocols.
1188 for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
1189 E = PDecl->protocol_end(); PI != E; ++PI)
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001190 CollectImmediateProperties((*PI), PropMap, SuperPropMap);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001191 }
1192}
1193
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001194/// CollectClassPropertyImplementations - This routine collects list of
1195/// properties to be implemented in the class. This includes, class's
1196/// and its conforming protocols' properties.
1197static void CollectClassPropertyImplementations(ObjCContainerDecl *CDecl,
1198 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) {
1199 if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
1200 for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
1201 E = IDecl->prop_end(); P != E; ++P) {
1202 ObjCPropertyDecl *Prop = (*P);
1203 PropMap[Prop->getIdentifier()] = Prop;
1204 }
Ted Kremenek53b94412010-09-01 01:21:15 +00001205 for (ObjCInterfaceDecl::all_protocol_iterator
1206 PI = IDecl->all_referenced_protocol_begin(),
1207 E = IDecl->all_referenced_protocol_end(); PI != E; ++PI)
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001208 CollectClassPropertyImplementations((*PI), PropMap);
1209 }
1210 else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
1211 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
1212 E = PDecl->prop_end(); P != E; ++P) {
1213 ObjCPropertyDecl *Prop = (*P);
1214 PropMap[Prop->getIdentifier()] = Prop;
1215 }
1216 // scan through protocol's protocols.
1217 for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
1218 E = PDecl->protocol_end(); PI != E; ++PI)
1219 CollectClassPropertyImplementations((*PI), PropMap);
1220 }
1221}
1222
1223/// CollectSuperClassPropertyImplementations - This routine collects list of
1224/// properties to be implemented in super class(s) and also coming from their
1225/// conforming protocols.
1226static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
1227 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) {
1228 if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
1229 while (SDecl) {
1230 CollectClassPropertyImplementations(SDecl, PropMap);
1231 SDecl = SDecl->getSuperClass();
1232 }
1233 }
1234}
1235
Ted Kremenek9d64c152010-03-12 00:38:38 +00001236/// LookupPropertyDecl - Looks up a property in the current class and all
1237/// its protocols.
1238ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1239 IdentifierInfo *II) {
1240 if (const ObjCInterfaceDecl *IDecl =
1241 dyn_cast<ObjCInterfaceDecl>(CDecl)) {
1242 for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
1243 E = IDecl->prop_end(); P != E; ++P) {
1244 ObjCPropertyDecl *Prop = (*P);
1245 if (Prop->getIdentifier() == II)
1246 return Prop;
1247 }
1248 // scan through class's protocols.
Ted Kremenek53b94412010-09-01 01:21:15 +00001249 for (ObjCInterfaceDecl::all_protocol_iterator
1250 PI = IDecl->all_referenced_protocol_begin(),
1251 E = IDecl->all_referenced_protocol_end(); PI != E; ++PI) {
Ted Kremenek9d64c152010-03-12 00:38:38 +00001252 ObjCPropertyDecl *Prop = LookupPropertyDecl((*PI), II);
1253 if (Prop)
1254 return Prop;
1255 }
1256 }
1257 else if (const ObjCProtocolDecl *PDecl =
1258 dyn_cast<ObjCProtocolDecl>(CDecl)) {
1259 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
1260 E = PDecl->prop_end(); P != E; ++P) {
1261 ObjCPropertyDecl *Prop = (*P);
1262 if (Prop->getIdentifier() == II)
1263 return Prop;
1264 }
1265 // scan through protocol's protocols.
1266 for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
1267 E = PDecl->protocol_end(); PI != E; ++PI) {
1268 ObjCPropertyDecl *Prop = LookupPropertyDecl((*PI), II);
1269 if (Prop)
1270 return Prop;
1271 }
1272 }
1273 return 0;
1274}
1275
Ted Kremenekd2ee8092011-09-27 23:39:40 +00001276static IdentifierInfo * getDefaultSynthIvarName(ObjCPropertyDecl *Prop,
1277 ASTContext &Ctx) {
1278 llvm::SmallString<128> ivarName;
1279 {
1280 llvm::raw_svector_ostream os(ivarName);
1281 os << '_' << Prop->getIdentifier()->getName();
1282 }
1283 return &Ctx.Idents.get(ivarName.str());
1284}
1285
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001286/// DefaultSynthesizeProperties - This routine default synthesizes all
1287/// properties which must be synthesized in class's @implementation.
Ted Kremenekd2ee8092011-09-27 23:39:40 +00001288void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
1289 ObjCInterfaceDecl *IDecl) {
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001290
1291 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
1292 CollectClassPropertyImplementations(IDecl, PropMap);
1293 if (PropMap.empty())
1294 return;
1295 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> SuperPropMap;
1296 CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
1297
1298 for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator
1299 P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
1300 ObjCPropertyDecl *Prop = P->second;
1301 // If property to be implemented in the super class, ignore.
1302 if (SuperPropMap[Prop->getIdentifier()])
1303 continue;
1304 // Is there a matching propery synthesize/dynamic?
1305 if (Prop->isInvalidDecl() ||
1306 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional ||
1307 IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier()))
1308 continue;
Fariborz Jahaniand3635b92010-07-14 18:11:52 +00001309 // Property may have been synthesized by user.
1310 if (IMPDecl->FindPropertyImplDecl(Prop->getIdentifier()))
1311 continue;
Fariborz Jahanian95f1b862010-08-25 00:31:58 +00001312 if (IMPDecl->getInstanceMethod(Prop->getGetterName())) {
1313 if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly)
1314 continue;
1315 if (IMPDecl->getInstanceMethod(Prop->getSetterName()))
1316 continue;
1317 }
Fariborz Jahaniand3635b92010-07-14 18:11:52 +00001318
Ted Kremenek2a6af6b2010-09-24 01:23:01 +00001319
1320 // We use invalid SourceLocations for the synthesized ivars since they
1321 // aren't really synthesized at a particular location; they just exist.
1322 // Saying that they are located at the @implementation isn't really going
1323 // to help users.
1324 ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
Fariborz Jahaniana28948f2011-08-22 15:54:49 +00001325 true,
Ted Kremenekd2ee8092011-09-27 23:39:40 +00001326 /* property = */ Prop->getIdentifier(),
1327 /* ivar = */ getDefaultSynthIvarName(Prop, Context),
Douglas Gregora4ffd852010-11-17 01:03:52 +00001328 SourceLocation());
Ted Kremenek2a6af6b2010-09-24 01:23:01 +00001329 }
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001330}
Ted Kremenek9d64c152010-03-12 00:38:38 +00001331
Fariborz Jahanian8697d302011-08-31 22:24:06 +00001332void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) {
1333 if (!LangOpts.ObjCDefaultSynthProperties || !LangOpts.ObjCNonFragileABI2)
1334 return;
1335 ObjCImplementationDecl *IC=dyn_cast_or_null<ObjCImplementationDecl>(D);
1336 if (!IC)
1337 return;
1338 if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
1339 DefaultSynthesizeProperties(S, IC, IDecl);
1340}
1341
Fariborz Jahanian17cb3262010-05-05 21:52:17 +00001342void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001343 ObjCContainerDecl *CDecl,
1344 const llvm::DenseSet<Selector>& InsMap) {
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001345 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> SuperPropMap;
1346 if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl))
1347 CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
1348
Ted Kremenek9d64c152010-03-12 00:38:38 +00001349 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
Fariborz Jahaniancfa6a272010-06-29 18:12:32 +00001350 CollectImmediateProperties(CDecl, PropMap, SuperPropMap);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001351 if (PropMap.empty())
1352 return;
1353
1354 llvm::DenseSet<ObjCPropertyDecl *> PropImplMap;
1355 for (ObjCImplDecl::propimpl_iterator
1356 I = IMPDecl->propimpl_begin(),
1357 EI = IMPDecl->propimpl_end(); I != EI; ++I)
1358 PropImplMap.insert((*I)->getPropertyDecl());
1359
1360 for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator
1361 P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
1362 ObjCPropertyDecl *Prop = P->second;
1363 // Is there a matching propery synthesize/dynamic?
1364 if (Prop->isInvalidDecl() ||
1365 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional ||
Fariborz Jahanian327126e2011-06-24 20:31:37 +00001366 PropImplMap.count(Prop) || Prop->hasAttr<UnavailableAttr>())
Ted Kremenek9d64c152010-03-12 00:38:38 +00001367 continue;
Ted Kremenek9d64c152010-03-12 00:38:38 +00001368 if (!InsMap.count(Prop->getGetterName())) {
Fariborz Jahanianb8607392011-08-27 21:55:47 +00001369 Diag(IMPDecl->getLocation(),
Ted Kremenek9d64c152010-03-12 00:38:38 +00001370 isa<ObjCCategoryDecl>(CDecl) ?
1371 diag::warn_setter_getter_impl_required_in_category :
1372 diag::warn_setter_getter_impl_required)
1373 << Prop->getDeclName() << Prop->getGetterName();
Fariborz Jahanianb8607392011-08-27 21:55:47 +00001374 Diag(Prop->getLocation(),
1375 diag::note_property_declare);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001376 }
1377
1378 if (!Prop->isReadOnly() && !InsMap.count(Prop->getSetterName())) {
Fariborz Jahanianb8607392011-08-27 21:55:47 +00001379 Diag(IMPDecl->getLocation(),
Ted Kremenek9d64c152010-03-12 00:38:38 +00001380 isa<ObjCCategoryDecl>(CDecl) ?
1381 diag::warn_setter_getter_impl_required_in_category :
1382 diag::warn_setter_getter_impl_required)
1383 << Prop->getDeclName() << Prop->getSetterName();
Fariborz Jahanianb8607392011-08-27 21:55:47 +00001384 Diag(Prop->getLocation(),
1385 diag::note_property_declare);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001386 }
1387 }
1388}
1389
1390void
1391Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl,
1392 ObjCContainerDecl* IDecl) {
1393 // Rules apply in non-GC mode only
Douglas Gregore289d812011-09-13 17:21:33 +00001394 if (getLangOptions().getGC() != LangOptions::NonGC)
Ted Kremenek9d64c152010-03-12 00:38:38 +00001395 return;
1396 for (ObjCContainerDecl::prop_iterator I = IDecl->prop_begin(),
1397 E = IDecl->prop_end();
1398 I != E; ++I) {
1399 ObjCPropertyDecl *Property = (*I);
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001400 ObjCMethodDecl *GetterMethod = 0;
1401 ObjCMethodDecl *SetterMethod = 0;
1402 bool LookedUpGetterSetter = false;
1403
Ted Kremenek9d64c152010-03-12 00:38:38 +00001404 unsigned Attributes = Property->getPropertyAttributes();
John McCall265941b2011-09-13 18:31:23 +00001405 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001406
John McCall265941b2011-09-13 18:31:23 +00001407 if (!(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_atomic) &&
1408 !(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_nonatomic)) {
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001409 GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName());
1410 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1411 LookedUpGetterSetter = true;
1412 if (GetterMethod) {
1413 Diag(GetterMethod->getLocation(),
1414 diag::warn_default_atomic_custom_getter_setter)
Argyrios Kyrtzidis293a45e2011-01-31 23:20:03 +00001415 << Property->getIdentifier() << 0;
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001416 Diag(Property->getLocation(), diag::note_property_declare);
1417 }
1418 if (SetterMethod) {
1419 Diag(SetterMethod->getLocation(),
1420 diag::warn_default_atomic_custom_getter_setter)
Argyrios Kyrtzidis293a45e2011-01-31 23:20:03 +00001421 << Property->getIdentifier() << 1;
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001422 Diag(Property->getLocation(), diag::note_property_declare);
1423 }
1424 }
1425
Ted Kremenek9d64c152010-03-12 00:38:38 +00001426 // We only care about readwrite atomic property.
1427 if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) ||
1428 !(Attributes & ObjCPropertyDecl::OBJC_PR_readwrite))
1429 continue;
1430 if (const ObjCPropertyImplDecl *PIDecl
1431 = IMPDecl->FindPropertyImplDecl(Property->getIdentifier())) {
1432 if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
1433 continue;
Argyrios Kyrtzidis94659e42011-01-31 21:34:11 +00001434 if (!LookedUpGetterSetter) {
1435 GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName());
1436 SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName());
1437 LookedUpGetterSetter = true;
1438 }
Ted Kremenek9d64c152010-03-12 00:38:38 +00001439 if ((GetterMethod && !SetterMethod) || (!GetterMethod && SetterMethod)) {
1440 SourceLocation MethodLoc =
1441 (GetterMethod ? GetterMethod->getLocation()
1442 : SetterMethod->getLocation());
1443 Diag(MethodLoc, diag::warn_atomic_property_rule)
Fariborz Jahanian7d65f692011-10-06 23:47:58 +00001444 << Property->getIdentifier() << (GetterMethod != 0)
1445 << (SetterMethod != 0);
1446 Diag(MethodLoc, diag::note_atomic_property_fixup_suggest);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001447 Diag(Property->getLocation(), diag::note_property_declare);
1448 }
1449 }
1450 }
1451}
1452
John McCallf85e1932011-06-15 23:02:42 +00001453void Sema::DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D) {
Douglas Gregore289d812011-09-13 17:21:33 +00001454 if (getLangOptions().getGC() == LangOptions::GCOnly)
John McCallf85e1932011-06-15 23:02:42 +00001455 return;
1456
1457 for (ObjCImplementationDecl::propimpl_iterator
1458 i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) {
1459 ObjCPropertyImplDecl *PID = *i;
1460 if (PID->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
1461 continue;
1462
1463 const ObjCPropertyDecl *PD = PID->getPropertyDecl();
Fariborz Jahanian831fb962011-06-25 00:17:46 +00001464 if (PD && !PD->hasAttr<NSReturnsNotRetainedAttr>() &&
1465 !D->getInstanceMethod(PD->getGetterName())) {
John McCallf85e1932011-06-15 23:02:42 +00001466 ObjCMethodDecl *method = PD->getGetterMethodDecl();
1467 if (!method)
1468 continue;
1469 ObjCMethodFamily family = method->getMethodFamily();
1470 if (family == OMF_alloc || family == OMF_copy ||
1471 family == OMF_mutableCopy || family == OMF_new) {
1472 if (getLangOptions().ObjCAutoRefCount)
1473 Diag(PID->getLocation(), diag::err_ownin_getter_rule);
1474 else
Ted Kremenek920c9c12011-10-12 18:03:37 +00001475 Diag(PID->getLocation(), diag::warn_owning_getter_rule);
John McCallf85e1932011-06-15 23:02:42 +00001476 Diag(PD->getLocation(), diag::note_property_declare);
1477 }
1478 }
1479 }
1480}
1481
John McCall5de74d12010-11-10 07:01:40 +00001482/// AddPropertyAttrs - Propagates attributes from a property to the
1483/// implicitly-declared getter or setter for that property.
1484static void AddPropertyAttrs(Sema &S, ObjCMethodDecl *PropertyMethod,
1485 ObjCPropertyDecl *Property) {
1486 // Should we just clone all attributes over?
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00001487 for (Decl::attr_iterator A = Property->attr_begin(),
1488 AEnd = Property->attr_end();
1489 A != AEnd; ++A) {
1490 if (isa<DeprecatedAttr>(*A) ||
1491 isa<UnavailableAttr>(*A) ||
1492 isa<AvailabilityAttr>(*A))
1493 PropertyMethod->addAttr((*A)->clone(S.Context));
1494 }
John McCall5de74d12010-11-10 07:01:40 +00001495}
1496
Ted Kremenek9d64c152010-03-12 00:38:38 +00001497/// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods
1498/// have the property type and issue diagnostics if they don't.
1499/// Also synthesize a getter/setter method if none exist (and update the
1500/// appropriate lookup tables. FIXME: Should reconsider if adding synthesized
1501/// methods is the "right" thing to do.
1502void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
Ted Kremenek8254aa62010-09-21 18:28:43 +00001503 ObjCContainerDecl *CD,
1504 ObjCPropertyDecl *redeclaredProperty,
1505 ObjCContainerDecl *lexicalDC) {
1506
Ted Kremenek9d64c152010-03-12 00:38:38 +00001507 ObjCMethodDecl *GetterMethod, *SetterMethod;
1508
1509 GetterMethod = CD->getInstanceMethod(property->getGetterName());
1510 SetterMethod = CD->getInstanceMethod(property->getSetterName());
1511 DiagnosePropertyAccessorMismatch(property, GetterMethod,
1512 property->getLocation());
1513
1514 if (SetterMethod) {
1515 ObjCPropertyDecl::PropertyAttributeKind CAttr =
1516 property->getPropertyAttributes();
1517 if ((!(CAttr & ObjCPropertyDecl::OBJC_PR_readonly)) &&
1518 Context.getCanonicalType(SetterMethod->getResultType()) !=
1519 Context.VoidTy)
1520 Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
1521 if (SetterMethod->param_size() != 1 ||
Fariborz Jahanian2aac0c92011-09-26 22:59:09 +00001522 !Context.hasSameUnqualifiedType(
Fariborz Jahanianbb13c322011-10-15 17:36:49 +00001523 (*SetterMethod->param_begin())->getType().getNonReferenceType(),
1524 property->getType().getNonReferenceType())) {
Ted Kremenek9d64c152010-03-12 00:38:38 +00001525 Diag(property->getLocation(),
1526 diag::warn_accessor_property_type_mismatch)
1527 << property->getDeclName()
1528 << SetterMethod->getSelector();
1529 Diag(SetterMethod->getLocation(), diag::note_declared_at);
1530 }
1531 }
1532
1533 // Synthesize getter/setter methods if none exist.
1534 // Find the default getter and if one not found, add one.
1535 // FIXME: The synthesized property we set here is misleading. We almost always
1536 // synthesize these methods unless the user explicitly provided prototypes
1537 // (which is odd, but allowed). Sema should be typechecking that the
1538 // declarations jive in that situation (which it is not currently).
1539 if (!GetterMethod) {
1540 // No instance method of same name as property getter name was found.
1541 // Declare a getter method and add it to the list of methods
1542 // for this class.
Ted Kremeneka054fb42010-09-21 20:52:59 +00001543 SourceLocation Loc = redeclaredProperty ?
1544 redeclaredProperty->getLocation() :
1545 property->getLocation();
1546
1547 GetterMethod = ObjCMethodDecl::Create(Context, Loc, Loc,
1548 property->getGetterName(),
Argyrios Kyrtzidis75cf3e82011-08-17 19:25:08 +00001549 property->getType(), 0, CD, /*isInstance=*/true,
1550 /*isVariadic=*/false, /*isSynthesized=*/true,
1551 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001552 (property->getPropertyImplementation() ==
1553 ObjCPropertyDecl::Optional) ?
1554 ObjCMethodDecl::Optional :
1555 ObjCMethodDecl::Required);
1556 CD->addDecl(GetterMethod);
John McCall5de74d12010-11-10 07:01:40 +00001557
1558 AddPropertyAttrs(*this, GetterMethod, property);
1559
Ted Kremenek23173d72010-05-18 21:09:07 +00001560 // FIXME: Eventually this shouldn't be needed, as the lexical context
1561 // and the real context should be the same.
Ted Kremeneka054fb42010-09-21 20:52:59 +00001562 if (lexicalDC)
Ted Kremenek23173d72010-05-18 21:09:07 +00001563 GetterMethod->setLexicalDeclContext(lexicalDC);
Fariborz Jahanian831fb962011-06-25 00:17:46 +00001564 if (property->hasAttr<NSReturnsNotRetainedAttr>())
1565 GetterMethod->addAttr(
1566 ::new (Context) NSReturnsNotRetainedAttr(Loc, Context));
Ted Kremenek9d64c152010-03-12 00:38:38 +00001567 } else
1568 // A user declared getter will be synthesize when @synthesize of
1569 // the property with the same name is seen in the @implementation
1570 GetterMethod->setSynthesized(true);
1571 property->setGetterMethodDecl(GetterMethod);
1572
1573 // Skip setter if property is read-only.
1574 if (!property->isReadOnly()) {
1575 // Find the default setter and if one not found, add one.
1576 if (!SetterMethod) {
1577 // No instance method of same name as property setter name was found.
1578 // Declare a setter method and add it to the list of methods
1579 // for this class.
Ted Kremenek8254aa62010-09-21 18:28:43 +00001580 SourceLocation Loc = redeclaredProperty ?
1581 redeclaredProperty->getLocation() :
1582 property->getLocation();
1583
1584 SetterMethod =
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +00001585 ObjCMethodDecl::Create(Context, Loc, Loc,
Ted Kremenek8254aa62010-09-21 18:28:43 +00001586 property->getSetterName(), Context.VoidTy, 0,
Argyrios Kyrtzidis75cf3e82011-08-17 19:25:08 +00001587 CD, /*isInstance=*/true, /*isVariadic=*/false,
1588 /*isSynthesized=*/true,
1589 /*isImplicitlyDeclared=*/true,
1590 /*isDefined=*/false,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001591 (property->getPropertyImplementation() ==
1592 ObjCPropertyDecl::Optional) ?
Ted Kremenek8254aa62010-09-21 18:28:43 +00001593 ObjCMethodDecl::Optional :
1594 ObjCMethodDecl::Required);
1595
Ted Kremenek9d64c152010-03-12 00:38:38 +00001596 // Invent the arguments for the setter. We don't bother making a
1597 // nice name for the argument.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001598 ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod,
1599 Loc, Loc,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001600 property->getIdentifier(),
John McCallf85e1932011-06-15 23:02:42 +00001601 property->getType().getUnqualifiedType(),
Ted Kremenek9d64c152010-03-12 00:38:38 +00001602 /*TInfo=*/0,
John McCalld931b082010-08-26 03:08:43 +00001603 SC_None,
1604 SC_None,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001605 0);
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +00001606 SetterMethod->setMethodParams(Context, Argument,
1607 ArrayRef<SourceLocation>());
John McCall5de74d12010-11-10 07:01:40 +00001608
1609 AddPropertyAttrs(*this, SetterMethod, property);
1610
Ted Kremenek9d64c152010-03-12 00:38:38 +00001611 CD->addDecl(SetterMethod);
Ted Kremenek23173d72010-05-18 21:09:07 +00001612 // FIXME: Eventually this shouldn't be needed, as the lexical context
1613 // and the real context should be the same.
Ted Kremenek8254aa62010-09-21 18:28:43 +00001614 if (lexicalDC)
Ted Kremenek23173d72010-05-18 21:09:07 +00001615 SetterMethod->setLexicalDeclContext(lexicalDC);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001616 } else
1617 // A user declared setter will be synthesize when @synthesize of
1618 // the property with the same name is seen in the @implementation
1619 SetterMethod->setSynthesized(true);
1620 property->setSetterMethodDecl(SetterMethod);
1621 }
1622 // Add any synthesized methods to the global pool. This allows us to
1623 // handle the following, which is supported by GCC (and part of the design).
1624 //
1625 // @interface Foo
1626 // @property double bar;
1627 // @end
1628 //
1629 // void thisIsUnfortunate() {
1630 // id foo;
1631 // double bar = [foo bar];
1632 // }
1633 //
1634 if (GetterMethod)
1635 AddInstanceMethodToGlobalPool(GetterMethod);
1636 if (SetterMethod)
1637 AddInstanceMethodToGlobalPool(SetterMethod);
1638}
1639
John McCalld226f652010-08-21 09:40:31 +00001640void Sema::CheckObjCPropertyAttributes(Decl *PDecl,
Ted Kremenek9d64c152010-03-12 00:38:38 +00001641 SourceLocation Loc,
1642 unsigned &Attributes) {
1643 // FIXME: Improve the reported location.
John McCallf85e1932011-06-15 23:02:42 +00001644 if (!PDecl || PDecl->isInvalidDecl())
Ted Kremenek5fcd52a2010-04-05 22:39:42 +00001645 return;
1646
1647 ObjCPropertyDecl *PropertyDecl = cast<ObjCPropertyDecl>(PDecl);
Fariborz Jahanian842f07b2010-03-30 22:40:11 +00001648 QualType PropertyTy = PropertyDecl->getType();
Ted Kremenek9d64c152010-03-12 00:38:38 +00001649
1650 // readonly and readwrite/assign/retain/copy conflict.
1651 if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
1652 (Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
1653 ObjCDeclSpec::DQ_PR_assign |
John McCallf85e1932011-06-15 23:02:42 +00001654 ObjCDeclSpec::DQ_PR_unsafe_unretained |
Ted Kremenek9d64c152010-03-12 00:38:38 +00001655 ObjCDeclSpec::DQ_PR_copy |
John McCallf85e1932011-06-15 23:02:42 +00001656 ObjCDeclSpec::DQ_PR_retain |
1657 ObjCDeclSpec::DQ_PR_strong))) {
Ted Kremenek9d64c152010-03-12 00:38:38 +00001658 const char * which = (Attributes & ObjCDeclSpec::DQ_PR_readwrite) ?
1659 "readwrite" :
1660 (Attributes & ObjCDeclSpec::DQ_PR_assign) ?
1661 "assign" :
John McCallf85e1932011-06-15 23:02:42 +00001662 (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) ?
1663 "unsafe_unretained" :
Ted Kremenek9d64c152010-03-12 00:38:38 +00001664 (Attributes & ObjCDeclSpec::DQ_PR_copy) ?
1665 "copy" : "retain";
1666
1667 Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ?
1668 diag::err_objc_property_attr_mutually_exclusive :
1669 diag::warn_objc_property_attr_mutually_exclusive)
1670 << "readonly" << which;
1671 }
1672
1673 // Check for copy or retain on non-object types.
John McCallf85e1932011-06-15 23:02:42 +00001674 if ((Attributes & (ObjCDeclSpec::DQ_PR_weak | ObjCDeclSpec::DQ_PR_copy |
1675 ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong)) &&
1676 !PropertyTy->isObjCRetainableType() &&
Fariborz Jahanian842f07b2010-03-30 22:40:11 +00001677 !PropertyDecl->getAttr<ObjCNSObjectAttr>()) {
Ted Kremenek9d64c152010-03-12 00:38:38 +00001678 Diag(Loc, diag::err_objc_property_requires_object)
John McCallf85e1932011-06-15 23:02:42 +00001679 << (Attributes & ObjCDeclSpec::DQ_PR_weak ? "weak" :
1680 Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain (or strong)");
1681 Attributes &= ~(ObjCDeclSpec::DQ_PR_weak | ObjCDeclSpec::DQ_PR_copy |
1682 ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001683 }
1684
1685 // Check for more than one of { assign, copy, retain }.
1686 if (Attributes & ObjCDeclSpec::DQ_PR_assign) {
1687 if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
1688 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1689 << "assign" << "copy";
1690 Attributes &= ~ObjCDeclSpec::DQ_PR_copy;
1691 }
1692 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
1693 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1694 << "assign" << "retain";
1695 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
1696 }
John McCallf85e1932011-06-15 23:02:42 +00001697 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
1698 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1699 << "assign" << "strong";
1700 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
1701 }
1702 if (getLangOptions().ObjCAutoRefCount &&
1703 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
1704 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1705 << "assign" << "weak";
1706 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
1707 }
1708 } else if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) {
1709 if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
1710 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1711 << "unsafe_unretained" << "copy";
1712 Attributes &= ~ObjCDeclSpec::DQ_PR_copy;
1713 }
1714 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
1715 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1716 << "unsafe_unretained" << "retain";
1717 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
1718 }
1719 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
1720 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1721 << "unsafe_unretained" << "strong";
1722 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
1723 }
1724 if (getLangOptions().ObjCAutoRefCount &&
1725 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
1726 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1727 << "unsafe_unretained" << "weak";
1728 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
1729 }
Ted Kremenek9d64c152010-03-12 00:38:38 +00001730 } else if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
1731 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
1732 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1733 << "copy" << "retain";
1734 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
1735 }
John McCallf85e1932011-06-15 23:02:42 +00001736 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
1737 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1738 << "copy" << "strong";
1739 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
1740 }
1741 if (Attributes & ObjCDeclSpec::DQ_PR_weak) {
1742 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1743 << "copy" << "weak";
1744 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
1745 }
1746 }
1747 else if ((Attributes & ObjCDeclSpec::DQ_PR_retain) &&
1748 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
1749 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1750 << "retain" << "weak";
Fariborz Jahanian528a4992011-09-14 18:03:46 +00001751 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
John McCallf85e1932011-06-15 23:02:42 +00001752 }
1753 else if ((Attributes & ObjCDeclSpec::DQ_PR_strong) &&
1754 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
1755 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1756 << "strong" << "weak";
1757 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
Ted Kremenek9d64c152010-03-12 00:38:38 +00001758 }
1759
Fariborz Jahanian9d1bbea2011-10-10 21:53:24 +00001760 if ((Attributes & ObjCDeclSpec::DQ_PR_atomic) &&
1761 (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)) {
1762 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
1763 << "atomic" << "nonatomic";
1764 Attributes &= ~ObjCDeclSpec::DQ_PR_atomic;
1765 }
1766
Ted Kremenek9d64c152010-03-12 00:38:38 +00001767 // Warn if user supplied no assignment attribute, property is
1768 // readwrite, and this is an object type.
1769 if (!(Attributes & (ObjCDeclSpec::DQ_PR_assign | ObjCDeclSpec::DQ_PR_copy |
John McCallf85e1932011-06-15 23:02:42 +00001770 ObjCDeclSpec::DQ_PR_unsafe_unretained |
1771 ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong |
1772 ObjCDeclSpec::DQ_PR_weak)) &&
Ted Kremenek9d64c152010-03-12 00:38:38 +00001773 PropertyTy->isObjCObjectPointerType()) {
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001774 if (getLangOptions().ObjCAutoRefCount)
1775 // With arc, @property definitions should default to (strong) when
Fariborz Jahanianf21a92d2011-11-08 20:58:53 +00001776 // not specified; including when property is 'readonly'.
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001777 PropertyDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
Fariborz Jahanianf21a92d2011-11-08 20:58:53 +00001778 else if (!(Attributes & ObjCDeclSpec::DQ_PR_readonly)) {
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001779 // Skip this warning in gc-only mode.
Douglas Gregore289d812011-09-13 17:21:33 +00001780 if (getLangOptions().getGC() != LangOptions::GCOnly)
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001781 Diag(Loc, diag::warn_objc_property_no_assignment_attribute);
Ted Kremenek9d64c152010-03-12 00:38:38 +00001782
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001783 // If non-gc code warn that this is likely inappropriate.
Douglas Gregore289d812011-09-13 17:21:33 +00001784 if (getLangOptions().getGC() == LangOptions::NonGC)
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001785 Diag(Loc, diag::warn_objc_property_default_assign_on_object);
1786 }
Ted Kremenek9d64c152010-03-12 00:38:38 +00001787
1788 // FIXME: Implement warning dependent on NSCopying being
1789 // implemented. See also:
1790 // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496>
1791 // (please trim this list while you are at it).
1792 }
1793
1794 if (!(Attributes & ObjCDeclSpec::DQ_PR_copy)
Fariborz Jahanian2b77cb82011-01-05 23:00:04 +00001795 &&!(Attributes & ObjCDeclSpec::DQ_PR_readonly)
Douglas Gregore289d812011-09-13 17:21:33 +00001796 && getLangOptions().getGC() == LangOptions::GCOnly
Ted Kremenek9d64c152010-03-12 00:38:38 +00001797 && PropertyTy->isBlockPointerType())
1798 Diag(Loc, diag::warn_objc_property_copy_missing_on_block);
Fariborz Jahanian528a4992011-09-14 18:03:46 +00001799 else if (getLangOptions().ObjCAutoRefCount &&
1800 (Attributes & ObjCDeclSpec::DQ_PR_retain) &&
1801 !(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
1802 !(Attributes & ObjCDeclSpec::DQ_PR_strong) &&
1803 PropertyTy->isBlockPointerType())
1804 Diag(Loc, diag::warn_objc_property_retain_of_block);
Fariborz Jahanian48a98c72011-11-01 23:02:16 +00001805
1806 if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
1807 (Attributes & ObjCDeclSpec::DQ_PR_setter))
1808 Diag(Loc, diag::warn_objc_readonly_property_has_setter);
1809
Ted Kremenek9d64c152010-03-12 00:38:38 +00001810}