clang  16.0.0git
SemaObjCProperty.cpp
Go to the documentation of this file.
1 //===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements semantic analysis for Objective C @property and
10 // @synthesize declarations.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "clang/AST/DeclObjC.h"
17 #include "clang/AST/ExprCXX.h"
18 #include "clang/AST/ExprObjC.h"
20 #include "clang/Lex/Lexer.h"
21 #include "clang/Lex/Preprocessor.h"
23 #include "llvm/ADT/DenseSet.h"
24 #include "llvm/ADT/SmallString.h"
25 
26 using namespace clang;
27 
28 //===----------------------------------------------------------------------===//
29 // Grammar actions.
30 //===----------------------------------------------------------------------===//
31 
32 /// getImpliedARCOwnership - Given a set of property attributes and a
33 /// type, infer an expected lifetime. The type's ownership qualification
34 /// is not considered.
35 ///
36 /// Returns OCL_None if the attributes as stated do not imply an ownership.
37 /// Never returns OCL_Autoreleasing.
40  // retain, strong, copy, weak, and unsafe_unretained are only legal
41  // on properties of retainable pointer type.
42  if (attrs &
46  } else if (attrs & ObjCPropertyAttribute::kind_weak) {
47  return Qualifiers::OCL_Weak;
50  }
51 
52  // assign can appear on other types, so we have to check the
53  // property type.
55  type->isObjCRetainableType()) {
57  }
58 
59  return Qualifiers::OCL_None;
60 }
61 
62 /// Check the internal consistency of a property declaration with
63 /// an explicit ownership qualifier.
65  ObjCPropertyDecl *property) {
66  if (property->isInvalidDecl()) return;
67 
68  ObjCPropertyAttribute::Kind propertyKind = property->getPropertyAttributes();
69  Qualifiers::ObjCLifetime propertyLifetime
70  = property->getType().getObjCLifetime();
71 
72  assert(propertyLifetime != Qualifiers::OCL_None);
73 
74  Qualifiers::ObjCLifetime expectedLifetime
75  = getImpliedARCOwnership(propertyKind, property->getType());
76  if (!expectedLifetime) {
77  // We have a lifetime qualifier but no dominating property
78  // attribute. That's okay, but restore reasonable invariants by
79  // setting the property attribute according to the lifetime
80  // qualifier.
82  if (propertyLifetime == Qualifiers::OCL_Strong) {
84  } else if (propertyLifetime == Qualifiers::OCL_Weak) {
86  } else {
87  assert(propertyLifetime == Qualifiers::OCL_ExplicitNone);
89  }
90  property->setPropertyAttributes(attr);
91  return;
92  }
93 
94  if (propertyLifetime == expectedLifetime) return;
95 
96  property->setInvalidDecl();
97  S.Diag(property->getLocation(),
98  diag::err_arc_inconsistent_property_ownership)
99  << property->getDeclName()
100  << expectedLifetime
101  << propertyLifetime;
102 }
103 
104 /// Check this Objective-C property against a property declared in the
105 /// given protocol.
106 static void
108  ObjCProtocolDecl *Proto,
109  llvm::SmallPtrSetImpl<ObjCProtocolDecl *> &Known) {
110  // Have we seen this protocol before?
111  if (!Known.insert(Proto).second)
112  return;
113 
114  // Look for a property with the same name.
115  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
116  Prop->getIdentifier(), Prop->isInstanceProperty())) {
117  S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
118  return;
119  }
120 
121  // Check this property against any protocols we inherit.
122  for (auto *P : Proto->protocols())
123  CheckPropertyAgainstProtocol(S, Prop, P, Known);
124 }
125 
127  // In GC mode, just look for the __weak qualifier.
128  if (S.getLangOpts().getGC() != LangOptions::NonGC) {
129  if (T.isObjCGCWeak())
131 
132  // In ARC/MRC, look for an explicit ownership qualifier.
133  // For some reason, this only applies to __weak.
134  } else if (auto ownership = T.getObjCLifetime()) {
135  switch (ownership) {
144  return 0;
145  }
146  llvm_unreachable("bad qualifier");
147  }
148 
149  return 0;
150 }
151 
152 static const unsigned OwnershipMask =
157 
158 static unsigned getOwnershipRule(unsigned attr) {
159  unsigned result = attr & OwnershipMask;
160 
161  // From an ownership perspective, assign and unsafe_unretained are
162  // identical; make sure one also implies the other.
163  if (result & (ObjCPropertyAttribute::kind_assign |
167  }
168 
169  return result;
170 }
171 
173  SourceLocation LParenLoc,
174  FieldDeclarator &FD,
175  ObjCDeclSpec &ODS,
176  Selector GetterSel,
177  Selector SetterSel,
178  tok::ObjCKeywordKind MethodImplKind,
179  DeclContext *lexicalDC) {
180  unsigned Attributes = ODS.getPropertyAttributes();
182  0);
183  TypeSourceInfo *TSI = GetTypeForDeclarator(FD.D, S);
184  QualType T = TSI->getType();
185  if (!getOwnershipRule(Attributes)) {
186  Attributes |= deducePropertyOwnershipFromType(*this, T);
187  }
188  bool isReadWrite = ((Attributes & ObjCPropertyAttribute::kind_readwrite) ||
189  // default is readwrite!
190  !(Attributes & ObjCPropertyAttribute::kind_readonly));
191 
192  // Proceed with constructing the ObjCPropertyDecls.
193  ObjCContainerDecl *ClassDecl = cast<ObjCContainerDecl>(CurContext);
194  ObjCPropertyDecl *Res = nullptr;
195  if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
196  if (CDecl->IsClassExtension()) {
197  Res = HandlePropertyInClassExtension(S, AtLoc, LParenLoc,
198  FD,
199  GetterSel, ODS.getGetterNameLoc(),
200  SetterSel, ODS.getSetterNameLoc(),
201  isReadWrite, Attributes,
202  ODS.getPropertyAttributes(),
203  T, TSI, MethodImplKind);
204  if (!Res)
205  return nullptr;
206  }
207  }
208 
209  if (!Res) {
210  Res = CreatePropertyDecl(S, ClassDecl, AtLoc, LParenLoc, FD,
211  GetterSel, ODS.getGetterNameLoc(), SetterSel,
212  ODS.getSetterNameLoc(), isReadWrite, Attributes,
213  ODS.getPropertyAttributes(), T, TSI,
214  MethodImplKind);
215  if (lexicalDC)
216  Res->setLexicalDeclContext(lexicalDC);
217  }
218 
219  // Validate the attributes on the @property.
220  CheckObjCPropertyAttributes(Res, AtLoc, Attributes,
221  (isa<ObjCInterfaceDecl>(ClassDecl) ||
222  isa<ObjCProtocolDecl>(ClassDecl)));
223 
224  // Check consistency if the type has explicit ownership qualification.
225  if (Res->getType().getObjCLifetime())
226  checkPropertyDeclWithOwnership(*this, Res);
227 
229  if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
230  // For a class, compare the property against a property in our superclass.
231  bool FoundInSuper = false;
232  ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
233  while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
234  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
235  Res->getIdentifier(), Res->isInstanceProperty())) {
236  DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
237  FoundInSuper = true;
238  break;
239  }
240  CurrentInterfaceDecl = Super;
241  }
242 
243  if (FoundInSuper) {
244  // Also compare the property against a property in our protocols.
245  for (auto *P : CurrentInterfaceDecl->protocols()) {
246  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
247  }
248  } else {
249  // Slower path: look in all protocols we referenced.
250  for (auto *P : IFace->all_referenced_protocols()) {
251  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
252  }
253  }
254  } else if (ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
255  // We don't check if class extension. Because properties in class extension
256  // are meant to override some of the attributes and checking has already done
257  // when property in class extension is constructed.
258  if (!Cat->IsClassExtension())
259  for (auto *P : Cat->protocols())
260  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
261  } else {
262  ObjCProtocolDecl *Proto = cast<ObjCProtocolDecl>(ClassDecl);
263  for (auto *P : Proto->protocols())
264  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
265  }
266 
268  return Res;
269 }
270 
272 makePropertyAttributesAsWritten(unsigned Attributes) {
273  unsigned attributesAsWritten = 0;
274  if (Attributes & ObjCPropertyAttribute::kind_readonly)
275  attributesAsWritten |= ObjCPropertyAttribute::kind_readonly;
276  if (Attributes & ObjCPropertyAttribute::kind_readwrite)
277  attributesAsWritten |= ObjCPropertyAttribute::kind_readwrite;
278  if (Attributes & ObjCPropertyAttribute::kind_getter)
279  attributesAsWritten |= ObjCPropertyAttribute::kind_getter;
280  if (Attributes & ObjCPropertyAttribute::kind_setter)
281  attributesAsWritten |= ObjCPropertyAttribute::kind_setter;
282  if (Attributes & ObjCPropertyAttribute::kind_assign)
283  attributesAsWritten |= ObjCPropertyAttribute::kind_assign;
284  if (Attributes & ObjCPropertyAttribute::kind_retain)
285  attributesAsWritten |= ObjCPropertyAttribute::kind_retain;
286  if (Attributes & ObjCPropertyAttribute::kind_strong)
287  attributesAsWritten |= ObjCPropertyAttribute::kind_strong;
288  if (Attributes & ObjCPropertyAttribute::kind_weak)
289  attributesAsWritten |= ObjCPropertyAttribute::kind_weak;
290  if (Attributes & ObjCPropertyAttribute::kind_copy)
291  attributesAsWritten |= ObjCPropertyAttribute::kind_copy;
293  attributesAsWritten |= ObjCPropertyAttribute::kind_unsafe_unretained;
294  if (Attributes & ObjCPropertyAttribute::kind_nonatomic)
295  attributesAsWritten |= ObjCPropertyAttribute::kind_nonatomic;
296  if (Attributes & ObjCPropertyAttribute::kind_atomic)
297  attributesAsWritten |= ObjCPropertyAttribute::kind_atomic;
298  if (Attributes & ObjCPropertyAttribute::kind_class)
299  attributesAsWritten |= ObjCPropertyAttribute::kind_class;
300  if (Attributes & ObjCPropertyAttribute::kind_direct)
301  attributesAsWritten |= ObjCPropertyAttribute::kind_direct;
302 
303  return (ObjCPropertyAttribute::Kind)attributesAsWritten;
304 }
305 
306 static bool LocPropertyAttribute( ASTContext &Context, const char *attrName,
307  SourceLocation LParenLoc, SourceLocation &Loc) {
308  if (LParenLoc.isMacroID())
309  return false;
310 
311  SourceManager &SM = Context.getSourceManager();
312  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(LParenLoc);
313  // Try to load the file buffer.
314  bool invalidTemp = false;
315  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
316  if (invalidTemp)
317  return false;
318  const char *tokenBegin = file.data() + locInfo.second;
319 
320  // Lex from the start of the given location.
321  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
322  Context.getLangOpts(),
323  file.begin(), tokenBegin, file.end());
324  Token Tok;
325  do {
326  lexer.LexFromRawLexer(Tok);
327  if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == attrName) {
328  Loc = Tok.getLocation();
329  return true;
330  }
331  } while (Tok.isNot(tok::r_paren));
332  return false;
333 }
334 
335 /// Check for a mismatch in the atomicity of the given properties.
337  ObjCPropertyDecl *OldProperty,
338  ObjCPropertyDecl *NewProperty,
339  bool PropagateAtomicity) {
340  // If the atomicity of both matches, we're done.
341  bool OldIsAtomic = (OldProperty->getPropertyAttributes() &
343  bool NewIsAtomic = (NewProperty->getPropertyAttributes() &
345  if (OldIsAtomic == NewIsAtomic) return;
346 
347  // Determine whether the given property is readonly and implicitly
348  // atomic.
349  auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
350  // Is it readonly?
351  auto Attrs = Property->getPropertyAttributes();
352  if ((Attrs & ObjCPropertyAttribute::kind_readonly) == 0)
353  return false;
354 
355  // Is it nonatomic?
357  return false;
358 
359  // Was 'atomic' specified directly?
360  if (Property->getPropertyAttributesAsWritten() &
362  return false;
363 
364  return true;
365  };
366 
367  // If we're allowed to propagate atomicity, and the new property did
368  // not specify atomicity at all, propagate.
369  const unsigned AtomicityMask = (ObjCPropertyAttribute::kind_atomic |
371  if (PropagateAtomicity &&
372  ((NewProperty->getPropertyAttributesAsWritten() & AtomicityMask) == 0)) {
373  unsigned Attrs = NewProperty->getPropertyAttributes();
374  Attrs = Attrs & ~AtomicityMask;
375  if (OldIsAtomic)
377  else
379 
380  NewProperty->overwritePropertyAttributes(Attrs);
381  return;
382  }
383 
384  // One of the properties is atomic; if it's a readonly property, and
385  // 'atomic' wasn't explicitly specified, we're okay.
386  if ((OldIsAtomic && isImplicitlyReadonlyAtomic(OldProperty)) ||
387  (NewIsAtomic && isImplicitlyReadonlyAtomic(NewProperty)))
388  return;
389 
390  // Diagnose the conflict.
391  const IdentifierInfo *OldContextName;
392  auto *OldDC = OldProperty->getDeclContext();
393  if (auto Category = dyn_cast<ObjCCategoryDecl>(OldDC))
394  OldContextName = Category->getClassInterface()->getIdentifier();
395  else
396  OldContextName = cast<ObjCContainerDecl>(OldDC)->getIdentifier();
397 
398  S.Diag(NewProperty->getLocation(), diag::warn_property_attribute)
399  << NewProperty->getDeclName() << "atomic"
400  << OldContextName;
401  S.Diag(OldProperty->getLocation(), diag::note_property_declare);
402 }
403 
406  SourceLocation AtLoc,
407  SourceLocation LParenLoc,
408  FieldDeclarator &FD,
409  Selector GetterSel,
410  SourceLocation GetterNameLoc,
411  Selector SetterSel,
412  SourceLocation SetterNameLoc,
413  const bool isReadWrite,
414  unsigned &Attributes,
415  const unsigned AttributesAsWritten,
416  QualType T,
417  TypeSourceInfo *TSI,
418  tok::ObjCKeywordKind MethodImplKind) {
419  ObjCCategoryDecl *CDecl = cast<ObjCCategoryDecl>(CurContext);
420  // Diagnose if this property is already in continuation class.
421  DeclContext *DC = CurContext;
422  IdentifierInfo *PropertyId = FD.D.getIdentifier();
423  ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
424 
425  // We need to look in the @interface to see if the @property was
426  // already declared.
427  if (!CCPrimary) {
428  Diag(CDecl->getLocation(), diag::err_continuation_class);
429  return nullptr;
430  }
431 
432  bool isClassProperty =
433  (AttributesAsWritten & ObjCPropertyAttribute::kind_class) ||
434  (Attributes & ObjCPropertyAttribute::kind_class);
435 
436  // Find the property in the extended class's primary class or
437  // extensions.
439  PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty));
440 
441  // If we found a property in an extension, complain.
442  if (PIDecl && isa<ObjCCategoryDecl>(PIDecl->getDeclContext())) {
443  Diag(AtLoc, diag::err_duplicate_property);
444  Diag(PIDecl->getLocation(), diag::note_property_declare);
445  return nullptr;
446  }
447 
448  // Check for consistency with the previous declaration, if there is one.
449  if (PIDecl) {
450  // A readonly property declared in the primary class can be refined
451  // by adding a readwrite property within an extension.
452  // Anything else is an error.
453  if (!(PIDecl->isReadOnly() && isReadWrite)) {
454  // Tailor the diagnostics for the common case where a readwrite
455  // property is declared both in the @interface and the continuation.
456  // This is a common error where the user often intended the original
457  // declaration to be readonly.
458  unsigned diag =
459  (Attributes & ObjCPropertyAttribute::kind_readwrite) &&
460  (PIDecl->getPropertyAttributesAsWritten() &
462  ? diag::err_use_continuation_class_redeclaration_readwrite
463  : diag::err_use_continuation_class;
464  Diag(AtLoc, diag)
465  << CCPrimary->getDeclName();
466  Diag(PIDecl->getLocation(), diag::note_property_declare);
467  return nullptr;
468  }
469 
470  // Check for consistency of getters.
471  if (PIDecl->getGetterName() != GetterSel) {
472  // If the getter was written explicitly, complain.
473  if (AttributesAsWritten & ObjCPropertyAttribute::kind_getter) {
474  Diag(AtLoc, diag::warn_property_redecl_getter_mismatch)
475  << PIDecl->getGetterName() << GetterSel;
476  Diag(PIDecl->getLocation(), diag::note_property_declare);
477  }
478 
479  // Always adopt the getter from the original declaration.
480  GetterSel = PIDecl->getGetterName();
482  }
483 
484  // Check consistency of ownership.
485  unsigned ExistingOwnership
487  unsigned NewOwnership = getOwnershipRule(Attributes);
488  if (ExistingOwnership && NewOwnership != ExistingOwnership) {
489  // If the ownership was written explicitly, complain.
490  if (getOwnershipRule(AttributesAsWritten)) {
491  Diag(AtLoc, diag::warn_property_attr_mismatch);
492  Diag(PIDecl->getLocation(), diag::note_property_declare);
493  }
494 
495  // Take the ownership from the original property.
496  Attributes = (Attributes & ~OwnershipMask) | ExistingOwnership;
497  }
498 
499  // If the redeclaration is 'weak' but the original property is not,
500  if ((Attributes & ObjCPropertyAttribute::kind_weak) &&
501  !(PIDecl->getPropertyAttributesAsWritten() &
503  PIDecl->getType()->getAs<ObjCObjectPointerType>() &&
505  Diag(AtLoc, diag::warn_property_implicitly_mismatched);
506  Diag(PIDecl->getLocation(), diag::note_property_declare);
507  }
508  }
509 
510  // Create a new ObjCPropertyDecl with the DeclContext being
511  // the class extension.
512  ObjCPropertyDecl *PDecl = CreatePropertyDecl(S, CDecl, AtLoc, LParenLoc,
513  FD, GetterSel, GetterNameLoc,
514  SetterSel, SetterNameLoc,
515  isReadWrite,
516  Attributes, AttributesAsWritten,
517  T, TSI, MethodImplKind, DC);
518 
519  // If there was no declaration of a property with the same name in
520  // the primary class, we're done.
521  if (!PIDecl) {
522  ProcessPropertyDecl(PDecl);
523  return PDecl;
524  }
525 
526  if (!Context.hasSameType(PIDecl->getType(), PDecl->getType())) {
527  bool IncompatibleObjC = false;
528  QualType ConvertedType;
529  // Relax the strict type matching for property type in continuation class.
530  // Allow property object type of continuation class to be different as long
531  // as it narrows the object type in its primary class property. Note that
532  // this conversion is safe only because the wider type is for a 'readonly'
533  // property in primary class and 'narrowed' type for a 'readwrite' property
534  // in continuation class.
535  QualType PrimaryClassPropertyT = Context.getCanonicalType(PIDecl->getType());
536  QualType ClassExtPropertyT = Context.getCanonicalType(PDecl->getType());
537  if (!isa<ObjCObjectPointerType>(PrimaryClassPropertyT) ||
538  !isa<ObjCObjectPointerType>(ClassExtPropertyT) ||
539  (!isObjCPointerConversion(ClassExtPropertyT, PrimaryClassPropertyT,
540  ConvertedType, IncompatibleObjC))
541  || IncompatibleObjC) {
542  Diag(AtLoc,
543  diag::err_type_mismatch_continuation_class) << PDecl->getType();
544  Diag(PIDecl->getLocation(), diag::note_property_declare);
545  return nullptr;
546  }
547  }
548 
549  // Check that atomicity of property in class extension matches the previous
550  // declaration.
551  checkAtomicPropertyMismatch(*this, PIDecl, PDecl, true);
552 
553  // Make sure getter/setter are appropriately synthesized.
554  ProcessPropertyDecl(PDecl);
555  return PDecl;
556 }
557 
559  ObjCContainerDecl *CDecl,
560  SourceLocation AtLoc,
561  SourceLocation LParenLoc,
562  FieldDeclarator &FD,
563  Selector GetterSel,
564  SourceLocation GetterNameLoc,
565  Selector SetterSel,
566  SourceLocation SetterNameLoc,
567  const bool isReadWrite,
568  const unsigned Attributes,
569  const unsigned AttributesAsWritten,
570  QualType T,
571  TypeSourceInfo *TInfo,
572  tok::ObjCKeywordKind MethodImplKind,
573  DeclContext *lexicalDC){
574  IdentifierInfo *PropertyId = FD.D.getIdentifier();
575 
576  // Property defaults to 'assign' if it is readwrite, unless this is ARC
577  // and the type is retainable.
578  bool isAssign;
579  if (Attributes & (ObjCPropertyAttribute::kind_assign |
581  isAssign = true;
582  } else if (getOwnershipRule(Attributes) || !isReadWrite) {
583  isAssign = false;
584  } else {
585  isAssign = (!getLangOpts().ObjCAutoRefCount ||
586  !T->isObjCRetainableType());
587  }
588 
589  // Issue a warning if property is 'assign' as default and its
590  // object, which is gc'able conforms to NSCopying protocol
591  if (getLangOpts().getGC() != LangOptions::NonGC && isAssign &&
592  !(Attributes & ObjCPropertyAttribute::kind_assign)) {
593  if (const ObjCObjectPointerType *ObjPtrTy =
595  ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
596  if (IDecl)
597  if (ObjCProtocolDecl* PNSCopying =
598  LookupProtocol(&Context.Idents.get("NSCopying"), AtLoc))
599  if (IDecl->ClassImplementsProtocol(PNSCopying, true))
600  Diag(AtLoc, diag::warn_implements_nscopying) << PropertyId;
601  }
602  }
603 
604  if (T->isObjCObjectType()) {
605  SourceLocation StarLoc = TInfo->getTypeLoc().getEndLoc();
606  StarLoc = getLocForEndOfToken(StarLoc);
607  Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object)
608  << FixItHint::CreateInsertion(StarLoc, "*");
610  SourceLocation TLoc = TInfo->getTypeLoc().getBeginLoc();
611  TInfo = Context.getTrivialTypeSourceInfo(T, TLoc);
612  }
613 
614  DeclContext *DC = CDecl;
616  FD.D.getIdentifierLoc(),
617  PropertyId, AtLoc,
618  LParenLoc, T, TInfo);
619 
620  bool isClassProperty =
621  (AttributesAsWritten & ObjCPropertyAttribute::kind_class) ||
622  (Attributes & ObjCPropertyAttribute::kind_class);
623  // Class property and instance property can have the same name.
625  DC, PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty))) {
626  Diag(PDecl->getLocation(), diag::err_duplicate_property);
627  Diag(prevDecl->getLocation(), diag::note_property_declare);
628  PDecl->setInvalidDecl();
629  }
630  else {
631  DC->addDecl(PDecl);
632  if (lexicalDC)
633  PDecl->setLexicalDeclContext(lexicalDC);
634  }
635 
636  if (T->isArrayType() || T->isFunctionType()) {
637  Diag(AtLoc, diag::err_property_type) << T;
638  PDecl->setInvalidDecl();
639  }
640 
641  ProcessDeclAttributes(S, PDecl, FD.D);
642 
643  // Regardless of setter/getter attribute, we save the default getter/setter
644  // selector names in anticipation of declaration of setter/getter methods.
645  PDecl->setGetterName(GetterSel, GetterNameLoc);
646  PDecl->setSetterName(SetterSel, SetterNameLoc);
648  makePropertyAttributesAsWritten(AttributesAsWritten));
649 
650  if (Attributes & ObjCPropertyAttribute::kind_readonly)
652 
653  if (Attributes & ObjCPropertyAttribute::kind_getter)
655 
656  if (Attributes & ObjCPropertyAttribute::kind_setter)
658 
659  if (isReadWrite)
661 
662  if (Attributes & ObjCPropertyAttribute::kind_retain)
664 
665  if (Attributes & ObjCPropertyAttribute::kind_strong)
667 
668  if (Attributes & ObjCPropertyAttribute::kind_weak)
670 
671  if (Attributes & ObjCPropertyAttribute::kind_copy)
673 
676 
677  if (isAssign)
679 
680  // In the semantic attributes, one of nonatomic or atomic is always set.
681  if (Attributes & ObjCPropertyAttribute::kind_nonatomic)
683  else
685 
686  // 'unsafe_unretained' is alias for 'assign'.
689  if (isAssign)
691 
692  if (MethodImplKind == tok::objc_required)
694  else if (MethodImplKind == tok::objc_optional)
696 
699 
702 
703  if (Attributes & ObjCPropertyAttribute::kind_class)
705 
706  if ((Attributes & ObjCPropertyAttribute::kind_direct) ||
707  CDecl->hasAttr<ObjCDirectMembersAttr>()) {
708  if (isa<ObjCProtocolDecl>(CDecl)) {
709  Diag(PDecl->getLocation(), diag::err_objc_direct_on_protocol) << true;
712  } else {
713  Diag(PDecl->getLocation(), diag::warn_objc_direct_property_ignored)
714  << PDecl->getDeclName();
715  }
716  }
717 
718  return PDecl;
719 }
720 
721 static void checkARCPropertyImpl(Sema &S, SourceLocation propertyImplLoc,
722  ObjCPropertyDecl *property,
723  ObjCIvarDecl *ivar) {
724  if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
725 
726  QualType ivarType = ivar->getType();
727  Qualifiers::ObjCLifetime ivarLifetime = ivarType.getObjCLifetime();
728 
729  // The lifetime implied by the property's attributes.
730  Qualifiers::ObjCLifetime propertyLifetime =
732  property->getType());
733 
734  // We're fine if they match.
735  if (propertyLifetime == ivarLifetime) return;
736 
737  // None isn't a valid lifetime for an object ivar in ARC, and
738  // __autoreleasing is never valid; don't diagnose twice.
739  if ((ivarLifetime == Qualifiers::OCL_None &&
740  S.getLangOpts().ObjCAutoRefCount) ||
741  ivarLifetime == Qualifiers::OCL_Autoreleasing)
742  return;
743 
744  // If the ivar is private, and it's implicitly __unsafe_unretained
745  // because of its type, then pretend it was actually implicitly
746  // __strong. This is only sound because we're processing the
747  // property implementation before parsing any method bodies.
748  if (ivarLifetime == Qualifiers::OCL_ExplicitNone &&
749  propertyLifetime == Qualifiers::OCL_Strong &&
751  SplitQualType split = ivarType.split();
752  if (split.Quals.hasObjCLifetime()) {
753  assert(ivarType->isObjCARCImplicitlyUnretainedType());
755  ivarType = S.Context.getQualifiedType(split);
756  ivar->setType(ivarType);
757  return;
758  }
759  }
760 
761  switch (propertyLifetime) {
763  S.Diag(ivar->getLocation(), diag::err_arc_strong_property_ownership)
764  << property->getDeclName()
765  << ivar->getDeclName()
766  << ivarLifetime;
767  break;
768 
770  S.Diag(ivar->getLocation(), diag::err_weak_property)
771  << property->getDeclName()
772  << ivar->getDeclName();
773  break;
774 
776  S.Diag(ivar->getLocation(), diag::err_arc_assign_property_ownership)
777  << property->getDeclName() << ivar->getDeclName()
778  << ((property->getPropertyAttributesAsWritten() &
780  break;
781 
783  llvm_unreachable("properties cannot be autoreleasing");
784 
786  // Any other property should be ignored.
787  return;
788  }
789 
790  S.Diag(property->getLocation(), diag::note_property_declare);
791  if (propertyImplLoc.isValid())
792  S.Diag(propertyImplLoc, diag::note_property_synthesize);
793 }
794 
795 /// setImpliedPropertyAttributeForReadOnlyProperty -
796 /// This routine evaludates life-time attributes for a 'readonly'
797 /// property with no known lifetime of its own, using backing
798 /// 'ivar's attribute, if any. If no backing 'ivar', property's
799 /// life-time is assumed 'strong'.
801  ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
802  Qualifiers::ObjCLifetime propertyLifetime =
804  property->getType());
805  if (propertyLifetime != Qualifiers::OCL_None)
806  return;
807 
808  if (!ivar) {
809  // if no backing ivar, make property 'strong'.
810  property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
811  return;
812  }
813  // property assumes owenership of backing ivar.
814  QualType ivarType = ivar->getType();
815  Qualifiers::ObjCLifetime ivarLifetime = ivarType.getObjCLifetime();
816  if (ivarLifetime == Qualifiers::OCL_Strong)
817  property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
818  else if (ivarLifetime == Qualifiers::OCL_Weak)
819  property->setPropertyAttributes(ObjCPropertyAttribute::kind_weak);
820 }
821 
822 static bool isIncompatiblePropertyAttribute(unsigned Attr1, unsigned Attr2,
824  return (Attr1 & Kind) != (Attr2 & Kind);
825 }
826 
827 static bool areIncompatiblePropertyAttributes(unsigned Attr1, unsigned Attr2,
828  unsigned Kinds) {
829  return ((Attr1 & Kinds) != 0) != ((Attr2 & Kinds) != 0);
830 }
831 
832 /// SelectPropertyForSynthesisFromProtocols - Finds the most appropriate
833 /// property declaration that should be synthesised in all of the inherited
834 /// protocols. It also diagnoses properties declared in inherited protocols with
835 /// mismatched types or attributes, since any of them can be candidate for
836 /// synthesis.
837 static ObjCPropertyDecl *
839  ObjCInterfaceDecl *ClassDecl,
840  ObjCPropertyDecl *Property) {
841  assert(isa<ObjCProtocolDecl>(Property->getDeclContext()) &&
842  "Expected a property from a protocol");
845  for (const auto *PI : ClassDecl->all_referenced_protocols()) {
846  if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
847  PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
848  Properties);
849  }
850  if (ObjCInterfaceDecl *SDecl = ClassDecl->getSuperClass()) {
851  while (SDecl) {
852  for (const auto *PI : SDecl->all_referenced_protocols()) {
853  if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
854  PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
855  Properties);
856  }
857  SDecl = SDecl->getSuperClass();
858  }
859  }
860 
861  if (Properties.empty())
862  return Property;
863 
864  ObjCPropertyDecl *OriginalProperty = Property;
865  size_t SelectedIndex = 0;
866  for (const auto &Prop : llvm::enumerate(Properties)) {
867  // Select the 'readwrite' property if such property exists.
868  if (Property->isReadOnly() && !Prop.value()->isReadOnly()) {
869  Property = Prop.value();
870  SelectedIndex = Prop.index();
871  }
872  }
873  if (Property != OriginalProperty) {
874  // Check that the old property is compatible with the new one.
875  Properties[SelectedIndex] = OriginalProperty;
876  }
877 
878  QualType RHSType = S.Context.getCanonicalType(Property->getType());
879  unsigned OriginalAttributes = Property->getPropertyAttributesAsWritten();
880  enum MismatchKind {
881  IncompatibleType = 0,
882  HasNoExpectedAttribute,
883  HasUnexpectedAttribute,
884  DifferentGetter,
885  DifferentSetter
886  };
887  // Represents a property from another protocol that conflicts with the
888  // selected declaration.
889  struct MismatchingProperty {
890  const ObjCPropertyDecl *Prop;
891  MismatchKind Kind;
892  StringRef AttributeName;
893  };
895  for (ObjCPropertyDecl *Prop : Properties) {
896  // Verify the property attributes.
897  unsigned Attr = Prop->getPropertyAttributesAsWritten();
898  if (Attr != OriginalAttributes) {
899  auto Diag = [&](bool OriginalHasAttribute, StringRef AttributeName) {
900  MismatchKind Kind = OriginalHasAttribute ? HasNoExpectedAttribute
901  : HasUnexpectedAttribute;
902  Mismatches.push_back({Prop, Kind, AttributeName});
903  };
904  // The ownership might be incompatible unless the property has no explicit
905  // ownership.
906  bool HasOwnership =
913  if (HasOwnership &&
914  isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
916  Diag(OriginalAttributes & ObjCPropertyAttribute::kind_copy, "copy");
917  continue;
918  }
919  if (HasOwnership && areIncompatiblePropertyAttributes(
920  OriginalAttributes, Attr,
923  Diag(OriginalAttributes & (ObjCPropertyAttribute::kind_retain |
925  "retain (or strong)");
926  continue;
927  }
928  if (isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
930  Diag(OriginalAttributes & ObjCPropertyAttribute::kind_atomic, "atomic");
931  continue;
932  }
933  }
934  if (Property->getGetterName() != Prop->getGetterName()) {
935  Mismatches.push_back({Prop, DifferentGetter, ""});
936  continue;
937  }
938  if (!Property->isReadOnly() && !Prop->isReadOnly() &&
939  Property->getSetterName() != Prop->getSetterName()) {
940  Mismatches.push_back({Prop, DifferentSetter, ""});
941  continue;
942  }
943  QualType LHSType = S.Context.getCanonicalType(Prop->getType());
944  if (!S.Context.propertyTypesAreCompatible(LHSType, RHSType)) {
945  bool IncompatibleObjC = false;
946  QualType ConvertedType;
947  if (!S.isObjCPointerConversion(RHSType, LHSType, ConvertedType, IncompatibleObjC)
948  || IncompatibleObjC) {
949  Mismatches.push_back({Prop, IncompatibleType, ""});
950  continue;
951  }
952  }
953  }
954 
955  if (Mismatches.empty())
956  return Property;
957 
958  // Diagnose incompability.
959  {
960  bool HasIncompatibleAttributes = false;
961  for (const auto &Note : Mismatches)
962  HasIncompatibleAttributes =
963  Note.Kind != IncompatibleType ? true : HasIncompatibleAttributes;
964  // Promote the warning to an error if there are incompatible attributes or
965  // incompatible types together with readwrite/readonly incompatibility.
966  auto Diag = S.Diag(Property->getLocation(),
967  Property != OriginalProperty || HasIncompatibleAttributes
968  ? diag::err_protocol_property_mismatch
969  : diag::warn_protocol_property_mismatch);
970  Diag << Mismatches[0].Kind;
971  switch (Mismatches[0].Kind) {
972  case IncompatibleType:
973  Diag << Property->getType();
974  break;
975  case HasNoExpectedAttribute:
976  case HasUnexpectedAttribute:
977  Diag << Mismatches[0].AttributeName;
978  break;
979  case DifferentGetter:
980  Diag << Property->getGetterName();
981  break;
982  case DifferentSetter:
983  Diag << Property->getSetterName();
984  break;
985  }
986  }
987  for (const auto &Note : Mismatches) {
988  auto Diag =
989  S.Diag(Note.Prop->getLocation(), diag::note_protocol_property_declare)
990  << Note.Kind;
991  switch (Note.Kind) {
992  case IncompatibleType:
993  Diag << Note.Prop->getType();
994  break;
995  case HasNoExpectedAttribute:
996  case HasUnexpectedAttribute:
997  Diag << Note.AttributeName;
998  break;
999  case DifferentGetter:
1000  Diag << Note.Prop->getGetterName();
1001  break;
1002  case DifferentSetter:
1003  Diag << Note.Prop->getSetterName();
1004  break;
1005  }
1006  }
1007  if (AtLoc.isValid())
1008  S.Diag(AtLoc, diag::note_property_synthesize);
1009 
1010  return Property;
1011 }
1012 
1013 /// Determine whether any storage attributes were written on the property.
1015  ObjCPropertyQueryKind QueryKind) {
1016  if (Prop->getPropertyAttributesAsWritten() & OwnershipMask) return true;
1017 
1018  // If this is a readwrite property in a class extension that refines
1019  // a readonly property in the original class definition, check it as
1020  // well.
1021 
1022  // If it's a readonly property, we're not interested.
1023  if (Prop->isReadOnly()) return false;
1024 
1025  // Is it declared in an extension?
1026  auto Category = dyn_cast<ObjCCategoryDecl>(Prop->getDeclContext());
1027  if (!Category || !Category->IsClassExtension()) return false;
1028 
1029  // Find the corresponding property in the primary class definition.
1030  auto OrigClass = Category->getClassInterface();
1031  for (auto *Found : OrigClass->lookup(Prop->getDeclName())) {
1032  if (ObjCPropertyDecl *OrigProp = dyn_cast<ObjCPropertyDecl>(Found))
1033  return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1034  }
1035 
1036  // Look through all of the protocols.
1037  for (const auto *Proto : OrigClass->all_referenced_protocols()) {
1038  if (ObjCPropertyDecl *OrigProp = Proto->FindPropertyDeclaration(
1039  Prop->getIdentifier(), QueryKind))
1040  return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1041  }
1042 
1043  return false;
1044 }
1045 
1046 /// Create a synthesized property accessor stub inside the \@implementation.
1047 static ObjCMethodDecl *
1049  ObjCMethodDecl *AccessorDecl, SourceLocation AtLoc,
1050  SourceLocation PropertyLoc) {
1051  ObjCMethodDecl *Decl = AccessorDecl;
1053  Context, AtLoc.isValid() ? AtLoc : Decl->getBeginLoc(),
1054  PropertyLoc.isValid() ? PropertyLoc : Decl->getEndLoc(),
1055  Decl->getSelector(), Decl->getReturnType(),
1056  Decl->getReturnTypeSourceInfo(), Impl, Decl->isInstanceMethod(),
1057  Decl->isVariadic(), Decl->isPropertyAccessor(),
1058  /* isSynthesized*/ true, Decl->isImplicit(), Decl->isDefined(),
1059  Decl->getImplementationControl(), Decl->hasRelatedResultType());
1060  ImplDecl->getMethodFamily();
1061  if (Decl->hasAttrs())
1062  ImplDecl->setAttrs(Decl->getAttrs());
1063  ImplDecl->setSelfDecl(Decl->getSelfDecl());
1064  ImplDecl->setCmdDecl(Decl->getCmdDecl());
1066  Decl->getSelectorLocs(SelLocs);
1067  ImplDecl->setMethodParams(Context, Decl->parameters(), SelLocs);
1068  ImplDecl->setLexicalDeclContext(Impl);
1069  ImplDecl->setDefined(false);
1070  return ImplDecl;
1071 }
1072 
1073 /// ActOnPropertyImplDecl - This routine performs semantic checks and
1074 /// builds the AST node for a property implementation declaration; declared
1075 /// as \@synthesize or \@dynamic.
1076 ///
1078  SourceLocation AtLoc,
1079  SourceLocation PropertyLoc,
1080  bool Synthesize,
1081  IdentifierInfo *PropertyId,
1082  IdentifierInfo *PropertyIvar,
1083  SourceLocation PropertyIvarLoc,
1084  ObjCPropertyQueryKind QueryKind) {
1085  ObjCContainerDecl *ClassImpDecl =
1086  dyn_cast<ObjCContainerDecl>(CurContext);
1087  // Make sure we have a context for the property implementation declaration.
1088  if (!ClassImpDecl) {
1089  Diag(AtLoc, diag::err_missing_property_context);
1090  return nullptr;
1091  }
1092  if (PropertyIvarLoc.isInvalid())
1093  PropertyIvarLoc = PropertyLoc;
1094  SourceLocation PropertyDiagLoc = PropertyLoc;
1095  if (PropertyDiagLoc.isInvalid())
1096  PropertyDiagLoc = ClassImpDecl->getBeginLoc();
1097  ObjCPropertyDecl *property = nullptr;
1098  ObjCInterfaceDecl *IDecl = nullptr;
1099  // Find the class or category class where this property must have
1100  // a declaration.
1101  ObjCImplementationDecl *IC = nullptr;
1102  ObjCCategoryImplDecl *CatImplClass = nullptr;
1103  if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
1104  IDecl = IC->getClassInterface();
1105  // We always synthesize an interface for an implementation
1106  // without an interface decl. So, IDecl is always non-zero.
1107  assert(IDecl &&
1108  "ActOnPropertyImplDecl - @implementation without @interface");
1109 
1110  // Look for this property declaration in the @implementation's @interface
1111  property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind);
1112  if (!property) {
1113  Diag(PropertyLoc, diag::err_bad_property_decl) << IDecl->getDeclName();
1114  return nullptr;
1115  }
1116  if (property->isClassProperty() && Synthesize) {
1117  Diag(PropertyLoc, diag::err_synthesize_on_class_property) << PropertyId;
1118  return nullptr;
1119  }
1120  unsigned PIkind = property->getPropertyAttributesAsWritten();
1121  if ((PIkind & (ObjCPropertyAttribute::kind_atomic |
1123  if (AtLoc.isValid())
1124  Diag(AtLoc, diag::warn_implicit_atomic_property);
1125  else
1126  Diag(IC->getLocation(), diag::warn_auto_implicit_atomic_property);
1127  Diag(property->getLocation(), diag::note_property_declare);
1128  }
1129 
1130  if (const ObjCCategoryDecl *CD =
1131  dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
1132  if (!CD->IsClassExtension()) {
1133  Diag(PropertyLoc, diag::err_category_property) << CD->getDeclName();
1134  Diag(property->getLocation(), diag::note_property_declare);
1135  return nullptr;
1136  }
1137  }
1138  if (Synthesize && (PIkind & ObjCPropertyAttribute::kind_readonly) &&
1139  property->hasAttr<IBOutletAttr>() && !AtLoc.isValid()) {
1140  bool ReadWriteProperty = false;
1141  // Search into the class extensions and see if 'readonly property is
1142  // redeclared 'readwrite', then no warning is to be issued.
1143  for (auto *Ext : IDecl->known_extensions()) {
1144  DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
1145  if (auto *ExtProp = R.find_first<ObjCPropertyDecl>()) {
1146  PIkind = ExtProp->getPropertyAttributesAsWritten();
1148  ReadWriteProperty = true;
1149  break;
1150  }
1151  }
1152  }
1153 
1154  if (!ReadWriteProperty) {
1155  Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
1156  << property;
1157  SourceLocation readonlyLoc;
1158  if (LocPropertyAttribute(Context, "readonly",
1159  property->getLParenLoc(), readonlyLoc)) {
1160  SourceLocation endLoc =
1161  readonlyLoc.getLocWithOffset(strlen("readonly")-1);
1162  SourceRange ReadonlySourceRange(readonlyLoc, endLoc);
1163  Diag(property->getLocation(),
1164  diag::note_auto_readonly_iboutlet_fixup_suggest) <<
1165  FixItHint::CreateReplacement(ReadonlySourceRange, "readwrite");
1166  }
1167  }
1168  }
1169  if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
1170  property = SelectPropertyForSynthesisFromProtocols(*this, AtLoc, IDecl,
1171  property);
1172 
1173  } else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
1174  if (Synthesize) {
1175  Diag(AtLoc, diag::err_synthesize_category_decl);
1176  return nullptr;
1177  }
1178  IDecl = CatImplClass->getClassInterface();
1179  if (!IDecl) {
1180  Diag(AtLoc, diag::err_missing_property_interface);
1181  return nullptr;
1182  }
1184  IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
1185 
1186  // If category for this implementation not found, it is an error which
1187  // has already been reported eralier.
1188  if (!Category)
1189  return nullptr;
1190  // Look for this property declaration in @implementation's category
1191  property = Category->FindPropertyDeclaration(PropertyId, QueryKind);
1192  if (!property) {
1193  Diag(PropertyLoc, diag::err_bad_category_property_decl)
1194  << Category->getDeclName();
1195  return nullptr;
1196  }
1197  } else {
1198  Diag(AtLoc, diag::err_bad_property_context);
1199  return nullptr;
1200  }
1201  ObjCIvarDecl *Ivar = nullptr;
1202  bool CompleteTypeErr = false;
1203  bool compat = true;
1204  // Check that we have a valid, previously declared ivar for @synthesize
1205  if (Synthesize) {
1206  // @synthesize
1207  if (!PropertyIvar)
1208  PropertyIvar = PropertyId;
1209  // Check that this is a previously declared 'ivar' in 'IDecl' interface
1210  ObjCInterfaceDecl *ClassDeclared;
1211  Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
1212  QualType PropType = property->getType();
1213  QualType PropertyIvarType = PropType.getNonReferenceType();
1214 
1215  if (RequireCompleteType(PropertyDiagLoc, PropertyIvarType,
1216  diag::err_incomplete_synthesized_property,
1217  property->getDeclName())) {
1218  Diag(property->getLocation(), diag::note_property_declare);
1219  CompleteTypeErr = true;
1220  }
1221 
1222  if (getLangOpts().ObjCAutoRefCount &&
1223  (property->getPropertyAttributesAsWritten() &
1225  PropertyIvarType->isObjCRetainableType()) {
1227  }
1228 
1229  ObjCPropertyAttribute::Kind kind = property->getPropertyAttributes();
1230 
1231  bool isARCWeak = false;
1233  // Add GC __weak to the ivar type if the property is weak.
1234  if (getLangOpts().getGC() != LangOptions::NonGC) {
1235  assert(!getLangOpts().ObjCAutoRefCount);
1236  if (PropertyIvarType.isObjCGCStrong()) {
1237  Diag(PropertyDiagLoc, diag::err_gc_weak_property_strong_type);
1238  Diag(property->getLocation(), diag::note_property_declare);
1239  } else {
1240  PropertyIvarType =
1241  Context.getObjCGCQualType(PropertyIvarType, Qualifiers::Weak);
1242  }
1243 
1244  // Otherwise, check whether ARC __weak is enabled and works with
1245  // the property type.
1246  } else {
1247  if (!getLangOpts().ObjCWeak) {
1248  // Only complain here when synthesizing an ivar.
1249  if (!Ivar) {
1250  Diag(PropertyDiagLoc,
1251  getLangOpts().ObjCWeakRuntime
1252  ? diag::err_synthesizing_arc_weak_property_disabled
1253  : diag::err_synthesizing_arc_weak_property_no_runtime);
1254  Diag(property->getLocation(), diag::note_property_declare);
1255  }
1256  CompleteTypeErr = true; // suppress later diagnostics about the ivar
1257  } else {
1258  isARCWeak = true;
1259  if (const ObjCObjectPointerType *ObjT =
1260  PropertyIvarType->getAs<ObjCObjectPointerType>()) {
1261  const ObjCInterfaceDecl *ObjI = ObjT->getInterfaceDecl();
1262  if (ObjI && ObjI->isArcWeakrefUnavailable()) {
1263  Diag(property->getLocation(),
1264  diag::err_arc_weak_unavailable_property)
1265  << PropertyIvarType;
1266  Diag(ClassImpDecl->getLocation(), diag::note_implemented_by_class)
1267  << ClassImpDecl->getName();
1268  }
1269  }
1270  }
1271  }
1272  }
1273 
1274  if (AtLoc.isInvalid()) {
1275  // Check when default synthesizing a property that there is
1276  // an ivar matching property name and issue warning; since this
1277  // is the most common case of not using an ivar used for backing
1278  // property in non-default synthesis case.
1279  ObjCInterfaceDecl *ClassDeclared=nullptr;
1280  ObjCIvarDecl *originalIvar =
1281  IDecl->lookupInstanceVariable(property->getIdentifier(),
1282  ClassDeclared);
1283  if (originalIvar) {
1284  Diag(PropertyDiagLoc,
1285  diag::warn_autosynthesis_property_ivar_match)
1286  << PropertyId << (Ivar == nullptr) << PropertyIvar
1287  << originalIvar->getIdentifier();
1288  Diag(property->getLocation(), diag::note_property_declare);
1289  Diag(originalIvar->getLocation(), diag::note_ivar_decl);
1290  }
1291  }
1292 
1293  if (!Ivar) {
1294  // In ARC, give the ivar a lifetime qualifier based on the
1295  // property attributes.
1296  if ((getLangOpts().ObjCAutoRefCount || isARCWeak) &&
1297  !PropertyIvarType.getObjCLifetime() &&
1298  PropertyIvarType->isObjCRetainableType()) {
1299 
1300  // It's an error if we have to do this and the user didn't
1301  // explicitly write an ownership attribute on the property.
1302  if (!hasWrittenStorageAttribute(property, QueryKind) &&
1304  Diag(PropertyDiagLoc,
1305  diag::err_arc_objc_property_default_assign_on_object);
1306  Diag(property->getLocation(), diag::note_property_declare);
1307  } else {
1308  Qualifiers::ObjCLifetime lifetime =
1309  getImpliedARCOwnership(kind, PropertyIvarType);
1310  assert(lifetime && "no lifetime for property?");
1311 
1312  Qualifiers qs;
1313  qs.addObjCLifetime(lifetime);
1314  PropertyIvarType = Context.getQualifiedType(PropertyIvarType, qs);
1315  }
1316  }
1317 
1318  Ivar = ObjCIvarDecl::Create(Context, ClassImpDecl,
1319  PropertyIvarLoc,PropertyIvarLoc, PropertyIvar,
1320  PropertyIvarType, /*TInfo=*/nullptr,
1322  (Expr *)nullptr, true);
1323  if (RequireNonAbstractType(PropertyIvarLoc,
1324  PropertyIvarType,
1325  diag::err_abstract_type_in_decl,
1327  Diag(property->getLocation(), diag::note_property_declare);
1328  // An abstract type is as bad as an incomplete type.
1329  CompleteTypeErr = true;
1330  }
1331  if (!CompleteTypeErr) {
1332  const RecordType *RecordTy = PropertyIvarType->getAs<RecordType>();
1333  if (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember()) {
1334  Diag(PropertyIvarLoc, diag::err_synthesize_variable_sized_ivar)
1335  << PropertyIvarType;
1336  CompleteTypeErr = true; // suppress later diagnostics about the ivar
1337  }
1338  }
1339  if (CompleteTypeErr)
1340  Ivar->setInvalidDecl();
1341  ClassImpDecl->addDecl(Ivar);
1342  IDecl->makeDeclVisibleInContext(Ivar);
1343 
1345  Diag(PropertyDiagLoc, diag::err_missing_property_ivar_decl)
1346  << PropertyId;
1347  // Note! I deliberately want it to fall thru so, we have a
1348  // a property implementation and to avoid future warnings.
1349  } else if (getLangOpts().ObjCRuntime.isNonFragile() &&
1350  !declaresSameEntity(ClassDeclared, IDecl)) {
1351  Diag(PropertyDiagLoc, diag::err_ivar_in_superclass_use)
1352  << property->getDeclName() << Ivar->getDeclName()
1353  << ClassDeclared->getDeclName();
1354  Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
1355  << Ivar << Ivar->getName();
1356  // Note! I deliberately want it to fall thru so more errors are caught.
1357  }
1358  property->setPropertyIvarDecl(Ivar);
1359 
1360  QualType IvarType = Context.getCanonicalType(Ivar->getType());
1361 
1362  // Check that type of property and its ivar are type compatible.
1363  if (!Context.hasSameType(PropertyIvarType, IvarType)) {
1364  if (isa<ObjCObjectPointerType>(PropertyIvarType)
1365  && isa<ObjCObjectPointerType>(IvarType))
1366  compat =
1368  PropertyIvarType->getAs<ObjCObjectPointerType>(),
1369  IvarType->getAs<ObjCObjectPointerType>());
1370  else {
1371  compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
1372  IvarType)
1373  == Compatible);
1374  }
1375  if (!compat) {
1376  Diag(PropertyDiagLoc, diag::err_property_ivar_type)
1377  << property->getDeclName() << PropType
1378  << Ivar->getDeclName() << IvarType;
1379  Diag(Ivar->getLocation(), diag::note_ivar_decl);
1380  // Note! I deliberately want it to fall thru so, we have a
1381  // a property implementation and to avoid future warnings.
1382  }
1383  else {
1384  // FIXME! Rules for properties are somewhat different that those
1385  // for assignments. Use a new routine to consolidate all cases;
1386  // specifically for property redeclarations as well as for ivars.
1387  QualType lhsType =Context.getCanonicalType(PropertyIvarType).getUnqualifiedType();
1388  QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
1389  if (lhsType != rhsType &&
1390  lhsType->isArithmeticType()) {
1391  Diag(PropertyDiagLoc, diag::err_property_ivar_type)
1392  << property->getDeclName() << PropType
1393  << Ivar->getDeclName() << IvarType;
1394  Diag(Ivar->getLocation(), diag::note_ivar_decl);
1395  // Fall thru - see previous comment
1396  }
1397  }
1398  // __weak is explicit. So it works on Canonical type.
1399  if ((PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
1400  getLangOpts().getGC() != LangOptions::NonGC)) {
1401  Diag(PropertyDiagLoc, diag::err_weak_property)
1402  << property->getDeclName() << Ivar->getDeclName();
1403  Diag(Ivar->getLocation(), diag::note_ivar_decl);
1404  // Fall thru - see previous comment
1405  }
1406  // Fall thru - see previous comment
1407  if ((property->getType()->isObjCObjectPointerType() ||
1408  PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() &&
1409  getLangOpts().getGC() != LangOptions::NonGC) {
1410  Diag(PropertyDiagLoc, diag::err_strong_property)
1411  << property->getDeclName() << Ivar->getDeclName();
1412  // Fall thru - see previous comment
1413  }
1414  }
1415  if (getLangOpts().ObjCAutoRefCount || isARCWeak ||
1416  Ivar->getType().getObjCLifetime())
1417  checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
1418  } else if (PropertyIvar)
1419  // @dynamic
1420  Diag(PropertyDiagLoc, diag::err_dynamic_property_ivar_decl);
1421 
1422  assert (property && "ActOnPropertyImplDecl - property declaration missing");
1423  ObjCPropertyImplDecl *PIDecl =
1424  ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc,
1425  property,
1426  (Synthesize ?
1429  Ivar, PropertyIvarLoc);
1430 
1431  if (CompleteTypeErr || !compat)
1432  PIDecl->setInvalidDecl();
1433 
1434  if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1435  getterMethod->createImplicitParams(Context, IDecl);
1436 
1437  // Redeclare the getter within the implementation as DeclContext.
1438  if (Synthesize) {
1439  // If the method hasn't been overridden, create a synthesized implementation.
1440  ObjCMethodDecl *OMD = ClassImpDecl->getMethod(
1441  getterMethod->getSelector(), getterMethod->isInstanceMethod());
1442  if (!OMD)
1443  OMD = RedeclarePropertyAccessor(Context, IC, getterMethod, AtLoc,
1444  PropertyLoc);
1445  PIDecl->setGetterMethodDecl(OMD);
1446  }
1447 
1448  if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
1449  Ivar->getType()->isRecordType()) {
1450  // For Objective-C++, need to synthesize the AST for the IVAR object to be
1451  // returned by the getter as it must conform to C++'s copy-return rules.
1452  // FIXME. Eventually we want to do this for Objective-C as well.
1453  SynthesizedFunctionScope Scope(*this, getterMethod);
1454  ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl();
1455  DeclRefExpr *SelfExpr = new (Context)
1456  DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1457  PropertyDiagLoc);
1458  MarkDeclRefReferenced(SelfExpr);
1459  Expr *LoadSelfExpr = ImplicitCastExpr::Create(
1460  Context, SelfDecl->getType(), CK_LValueToRValue, SelfExpr, nullptr,
1462  Expr *IvarRefExpr =
1463  new (Context) ObjCIvarRefExpr(Ivar,
1464  Ivar->getUsageType(SelfDecl->getType()),
1465  PropertyDiagLoc,
1466  Ivar->getLocation(),
1467  LoadSelfExpr, true, true);
1469  InitializedEntity::InitializeResult(PropertyDiagLoc,
1470  getterMethod->getReturnType()),
1471  PropertyDiagLoc, IvarRefExpr);
1472  if (!Res.isInvalid()) {
1473  Expr *ResExpr = Res.getAs<Expr>();
1474  if (ResExpr)
1475  ResExpr = MaybeCreateExprWithCleanups(ResExpr);
1476  PIDecl->setGetterCXXConstructor(ResExpr);
1477  }
1478  }
1479  if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1480  !getterMethod->hasAttr<NSReturnsNotRetainedAttr>()) {
1481  Diag(getterMethod->getLocation(),
1482  diag::warn_property_getter_owning_mismatch);
1483  Diag(property->getLocation(), diag::note_property_declare);
1484  }
1485  if (getLangOpts().ObjCAutoRefCount && Synthesize)
1486  switch (getterMethod->getMethodFamily()) {
1487  case OMF_retain:
1488  case OMF_retainCount:
1489  case OMF_release:
1490  case OMF_autorelease:
1491  Diag(getterMethod->getLocation(), diag::err_arc_illegal_method_def)
1492  << 1 << getterMethod->getSelector();
1493  break;
1494  default:
1495  break;
1496  }
1497  }
1498 
1499  if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1500  setterMethod->createImplicitParams(Context, IDecl);
1501 
1502  // Redeclare the setter within the implementation as DeclContext.
1503  if (Synthesize) {
1504  ObjCMethodDecl *OMD = ClassImpDecl->getMethod(
1505  setterMethod->getSelector(), setterMethod->isInstanceMethod());
1506  if (!OMD)
1507  OMD = RedeclarePropertyAccessor(Context, IC, setterMethod,
1508  AtLoc, PropertyLoc);
1509  PIDecl->setSetterMethodDecl(OMD);
1510  }
1511 
1512  if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
1513  Ivar->getType()->isRecordType()) {
1514  // FIXME. Eventually we want to do this for Objective-C as well.
1515  SynthesizedFunctionScope Scope(*this, setterMethod);
1516  ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl();
1517  DeclRefExpr *SelfExpr = new (Context)
1518  DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1519  PropertyDiagLoc);
1520  MarkDeclRefReferenced(SelfExpr);
1521  Expr *LoadSelfExpr = ImplicitCastExpr::Create(
1522  Context, SelfDecl->getType(), CK_LValueToRValue, SelfExpr, nullptr,
1524  Expr *lhs =
1525  new (Context) ObjCIvarRefExpr(Ivar,
1526  Ivar->getUsageType(SelfDecl->getType()),
1527  PropertyDiagLoc,
1528  Ivar->getLocation(),
1529  LoadSelfExpr, true, true);
1530  ObjCMethodDecl::param_iterator P = setterMethod->param_begin();
1531  ParmVarDecl *Param = (*P);
1532  QualType T = Param->getType().getNonReferenceType();
1533  DeclRefExpr *rhs = new (Context)
1534  DeclRefExpr(Context, Param, false, T, VK_LValue, PropertyDiagLoc);
1535  MarkDeclRefReferenced(rhs);
1536  ExprResult Res = BuildBinOp(S, PropertyDiagLoc,
1537  BO_Assign, lhs, rhs);
1538  if (property->getPropertyAttributes() &
1540  Expr *callExpr = Res.getAs<Expr>();
1541  if (const CXXOperatorCallExpr *CXXCE =
1542  dyn_cast_or_null<CXXOperatorCallExpr>(callExpr))
1543  if (const FunctionDecl *FuncDecl = CXXCE->getDirectCallee())
1544  if (!FuncDecl->isTrivial())
1545  if (property->getType()->isReferenceType()) {
1546  Diag(PropertyDiagLoc,
1547  diag::err_atomic_property_nontrivial_assign_op)
1548  << property->getType();
1549  Diag(FuncDecl->getBeginLoc(), diag::note_callee_decl)
1550  << FuncDecl;
1551  }
1552  }
1553  PIDecl->setSetterCXXAssignment(Res.getAs<Expr>());
1554  }
1555  }
1556 
1557  if (IC) {
1558  if (Synthesize)
1559  if (ObjCPropertyImplDecl *PPIDecl =
1560  IC->FindPropertyImplIvarDecl(PropertyIvar)) {
1561  Diag(PropertyLoc, diag::err_duplicate_ivar_use)
1562  << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1563  << PropertyIvar;
1564  Diag(PPIDecl->getLocation(), diag::note_previous_use);
1565  }
1566 
1567  if (ObjCPropertyImplDecl *PPIDecl
1568  = IC->FindPropertyImplDecl(PropertyId, QueryKind)) {
1569  Diag(PropertyLoc, diag::err_property_implemented) << PropertyId;
1570  Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1571  return nullptr;
1572  }
1573  IC->addPropertyImplementation(PIDecl);
1574  if (getLangOpts().ObjCDefaultSynthProperties &&
1576  !IDecl->isObjCRequiresPropertyDefs()) {
1577  // Diagnose if an ivar was lazily synthesdized due to a previous
1578  // use and if 1) property is @dynamic or 2) property is synthesized
1579  // but it requires an ivar of different name.
1580  ObjCInterfaceDecl *ClassDeclared=nullptr;
1581  ObjCIvarDecl *Ivar = nullptr;
1582  if (!Synthesize)
1583  Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1584  else {
1585  if (PropertyIvar && PropertyIvar != PropertyId)
1586  Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1587  }
1588  // Issue diagnostics only if Ivar belongs to current class.
1589  if (Ivar && Ivar->getSynthesize() &&
1590  declaresSameEntity(IC->getClassInterface(), ClassDeclared)) {
1591  Diag(Ivar->getLocation(), diag::err_undeclared_var_use)
1592  << PropertyId;
1593  Ivar->setInvalidDecl();
1594  }
1595  }
1596  } else {
1597  if (Synthesize)
1598  if (ObjCPropertyImplDecl *PPIDecl =
1599  CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
1600  Diag(PropertyDiagLoc, diag::err_duplicate_ivar_use)
1601  << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1602  << PropertyIvar;
1603  Diag(PPIDecl->getLocation(), diag::note_previous_use);
1604  }
1605 
1606  if (ObjCPropertyImplDecl *PPIDecl =
1607  CatImplClass->FindPropertyImplDecl(PropertyId, QueryKind)) {
1608  Diag(PropertyDiagLoc, diag::err_property_implemented) << PropertyId;
1609  Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1610  return nullptr;
1611  }
1612  CatImplClass->addPropertyImplementation(PIDecl);
1613  }
1614 
1616  PIDecl->getPropertyDecl() &&
1617  PIDecl->getPropertyDecl()->isDirectProperty()) {
1618  Diag(PropertyLoc, diag::err_objc_direct_dynamic_property);
1619  Diag(PIDecl->getPropertyDecl()->getLocation(),
1620  diag::note_previous_declaration);
1621  return nullptr;
1622  }
1623 
1624  return PIDecl;
1625 }
1626 
1627 //===----------------------------------------------------------------------===//
1628 // Helper methods.
1629 //===----------------------------------------------------------------------===//
1630 
1631 /// DiagnosePropertyMismatch - Compares two properties for their
1632 /// attributes and types and warns on a variety of inconsistencies.
1633 ///
1634 void
1636  ObjCPropertyDecl *SuperProperty,
1637  const IdentifierInfo *inheritedName,
1638  bool OverridingProtocolProperty) {
1639  ObjCPropertyAttribute::Kind CAttr = Property->getPropertyAttributes();
1640  ObjCPropertyAttribute::Kind SAttr = SuperProperty->getPropertyAttributes();
1641 
1642  // We allow readonly properties without an explicit ownership
1643  // (assign/unsafe_unretained/weak/retain/strong/copy) in super class
1644  // to be overridden by a property with any explicit ownership in the subclass.
1645  if (!OverridingProtocolProperty &&
1646  !getOwnershipRule(SAttr) && getOwnershipRule(CAttr))
1647  ;
1648  else {
1649  if ((CAttr & ObjCPropertyAttribute::kind_readonly) &&
1651  Diag(Property->getLocation(), diag::warn_readonly_property)
1652  << Property->getDeclName() << inheritedName;
1653  if ((CAttr & ObjCPropertyAttribute::kind_copy) !=
1655  Diag(Property->getLocation(), diag::warn_property_attribute)
1656  << Property->getDeclName() << "copy" << inheritedName;
1657  else if (!(SAttr & ObjCPropertyAttribute::kind_readonly)) {
1658  unsigned CAttrRetain = (CAttr & (ObjCPropertyAttribute::kind_retain |
1660  unsigned SAttrRetain = (SAttr & (ObjCPropertyAttribute::kind_retain |
1662  bool CStrong = (CAttrRetain != 0);
1663  bool SStrong = (SAttrRetain != 0);
1664  if (CStrong != SStrong)
1665  Diag(Property->getLocation(), diag::warn_property_attribute)
1666  << Property->getDeclName() << "retain (or strong)" << inheritedName;
1667  }
1668  }
1669 
1670  // Check for nonatomic; note that nonatomic is effectively
1671  // meaningless for readonly properties, so don't diagnose if the
1672  // atomic property is 'readonly'.
1673  checkAtomicPropertyMismatch(*this, SuperProperty, Property, false);
1674  // Readonly properties from protocols can be implemented as "readwrite"
1675  // with a custom setter name.
1676  if (Property->getSetterName() != SuperProperty->getSetterName() &&
1677  !(SuperProperty->isReadOnly() &&
1678  isa<ObjCProtocolDecl>(SuperProperty->getDeclContext()))) {
1679  Diag(Property->getLocation(), diag::warn_property_attribute)
1680  << Property->getDeclName() << "setter" << inheritedName;
1681  Diag(SuperProperty->getLocation(), diag::note_property_declare);
1682  }
1683  if (Property->getGetterName() != SuperProperty->getGetterName()) {
1684  Diag(Property->getLocation(), diag::warn_property_attribute)
1685  << Property->getDeclName() << "getter" << inheritedName;
1686  Diag(SuperProperty->getLocation(), diag::note_property_declare);
1687  }
1688 
1689  QualType LHSType =
1690  Context.getCanonicalType(SuperProperty->getType());
1691  QualType RHSType =
1692  Context.getCanonicalType(Property->getType());
1693 
1694  if (!Context.propertyTypesAreCompatible(LHSType, RHSType)) {
1695  // Do cases not handled in above.
1696  // FIXME. For future support of covariant property types, revisit this.
1697  bool IncompatibleObjC = false;
1698  QualType ConvertedType;
1699  if (!isObjCPointerConversion(RHSType, LHSType,
1700  ConvertedType, IncompatibleObjC) ||
1701  IncompatibleObjC) {
1702  Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1703  << Property->getType() << SuperProperty->getType() << inheritedName;
1704  Diag(SuperProperty->getLocation(), diag::note_property_declare);
1705  }
1706  }
1707 }
1708 
1710  ObjCMethodDecl *GetterMethod,
1711  SourceLocation Loc) {
1712  if (!GetterMethod)
1713  return false;
1714  QualType GetterType = GetterMethod->getReturnType().getNonReferenceType();
1715  QualType PropertyRValueType =
1716  property->getType().getNonReferenceType().getAtomicUnqualifiedType();
1717  bool compat = Context.hasSameType(PropertyRValueType, GetterType);
1718  if (!compat) {
1719  const ObjCObjectPointerType *propertyObjCPtr = nullptr;
1720  const ObjCObjectPointerType *getterObjCPtr = nullptr;
1721  if ((propertyObjCPtr =
1722  PropertyRValueType->getAs<ObjCObjectPointerType>()) &&
1723  (getterObjCPtr = GetterType->getAs<ObjCObjectPointerType>()))
1724  compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr);
1725  else if (CheckAssignmentConstraints(Loc, GetterType, PropertyRValueType)
1726  != Compatible) {
1727  Diag(Loc, diag::err_property_accessor_type)
1728  << property->getDeclName() << PropertyRValueType
1729  << GetterMethod->getSelector() << GetterType;
1730  Diag(GetterMethod->getLocation(), diag::note_declared_at);
1731  return true;
1732  } else {
1733  compat = true;
1734  QualType lhsType = Context.getCanonicalType(PropertyRValueType);
1735  QualType rhsType =Context.getCanonicalType(GetterType).getUnqualifiedType();
1736  if (lhsType != rhsType && lhsType->isArithmeticType())
1737  compat = false;
1738  }
1739  }
1740 
1741  if (!compat) {
1742  Diag(Loc, diag::warn_accessor_property_type_mismatch)
1743  << property->getDeclName()
1744  << GetterMethod->getSelector();
1745  Diag(GetterMethod->getLocation(), diag::note_declared_at);
1746  return true;
1747  }
1748 
1749  return false;
1750 }
1751 
1752 /// CollectImmediateProperties - This routine collects all properties in
1753 /// the class and its conforming protocols; but not those in its super class.
1754 static void
1757  ObjCContainerDecl::PropertyMap &SuperPropMap,
1758  bool CollectClassPropsOnly = false,
1759  bool IncludeProtocols = true) {
1760  if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
1761  for (auto *Prop : IDecl->properties()) {
1762  if (CollectClassPropsOnly && !Prop->isClassProperty())
1763  continue;
1764  PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1765  Prop;
1766  }
1767 
1768  // Collect the properties from visible extensions.
1769  for (auto *Ext : IDecl->visible_extensions())
1770  CollectImmediateProperties(Ext, PropMap, SuperPropMap,
1771  CollectClassPropsOnly, IncludeProtocols);
1772 
1773  if (IncludeProtocols) {
1774  // Scan through class's protocols.
1775  for (auto *PI : IDecl->all_referenced_protocols())
1776  CollectImmediateProperties(PI, PropMap, SuperPropMap,
1777  CollectClassPropsOnly);
1778  }
1779  }
1780  if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
1781  for (auto *Prop : CATDecl->properties()) {
1782  if (CollectClassPropsOnly && !Prop->isClassProperty())
1783  continue;
1784  PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1785  Prop;
1786  }
1787  if (IncludeProtocols) {
1788  // Scan through class's protocols.
1789  for (auto *PI : CATDecl->protocols())
1790  CollectImmediateProperties(PI, PropMap, SuperPropMap,
1791  CollectClassPropsOnly);
1792  }
1793  }
1794  else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
1795  for (auto *Prop : PDecl->properties()) {
1796  if (CollectClassPropsOnly && !Prop->isClassProperty())
1797  continue;
1798  ObjCPropertyDecl *PropertyFromSuper =
1799  SuperPropMap[std::make_pair(Prop->getIdentifier(),
1800  Prop->isClassProperty())];
1801  // Exclude property for protocols which conform to class's super-class,
1802  // as super-class has to implement the property.
1803  if (!PropertyFromSuper ||
1804  PropertyFromSuper->getIdentifier() != Prop->getIdentifier()) {
1805  ObjCPropertyDecl *&PropEntry =
1806  PropMap[std::make_pair(Prop->getIdentifier(),
1807  Prop->isClassProperty())];
1808  if (!PropEntry)
1809  PropEntry = Prop;
1810  }
1811  }
1812  // Scan through protocol's protocols.
1813  for (auto *PI : PDecl->protocols())
1814  CollectImmediateProperties(PI, PropMap, SuperPropMap,
1815  CollectClassPropsOnly);
1816  }
1817 }
1818 
1819 /// CollectSuperClassPropertyImplementations - This routine collects list of
1820 /// properties to be implemented in super class(s) and also coming from their
1821 /// conforming protocols.
1823  ObjCInterfaceDecl::PropertyMap &PropMap) {
1824  if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
1825  while (SDecl) {
1826  SDecl->collectPropertiesToImplement(PropMap);
1827  SDecl = SDecl->getSuperClass();
1828  }
1829  }
1830 }
1831 
1832 /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
1833 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1834 /// declared in class 'IFace'.
1835 bool
1837  ObjCMethodDecl *Method, ObjCIvarDecl *IV) {
1838  if (!IV->getSynthesize())
1839  return false;
1840  ObjCMethodDecl *IMD = IFace->lookupMethod(Method->getSelector(),
1841  Method->isInstanceMethod());
1842  if (!IMD || !IMD->isPropertyAccessor())
1843  return false;
1844 
1845  // look up a property declaration whose one of its accessors is implemented
1846  // by this method.
1847  for (const auto *Property : IFace->instance_properties()) {
1848  if ((Property->getGetterName() == IMD->getSelector() ||
1849  Property->getSetterName() == IMD->getSelector()) &&
1850  (Property->getPropertyIvarDecl() == IV))
1851  return true;
1852  }
1853  // Also look up property declaration in class extension whose one of its
1854  // accessors is implemented by this method.
1855  for (const auto *Ext : IFace->known_extensions())
1856  for (const auto *Property : Ext->instance_properties())
1857  if ((Property->getGetterName() == IMD->getSelector() ||
1858  Property->getSetterName() == IMD->getSelector()) &&
1859  (Property->getPropertyIvarDecl() == IV))
1860  return true;
1861  return false;
1862 }
1863 
1865  ObjCPropertyDecl *Prop) {
1866  bool SuperClassImplementsGetter = false;
1867  bool SuperClassImplementsSetter = false;
1869  SuperClassImplementsSetter = true;
1870 
1871  while (IDecl->getSuperClass()) {
1872  ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
1873  if (!SuperClassImplementsGetter && SDecl->getInstanceMethod(Prop->getGetterName()))
1874  SuperClassImplementsGetter = true;
1875 
1876  if (!SuperClassImplementsSetter && SDecl->getInstanceMethod(Prop->getSetterName()))
1877  SuperClassImplementsSetter = true;
1878  if (SuperClassImplementsGetter && SuperClassImplementsSetter)
1879  return true;
1880  IDecl = IDecl->getSuperClass();
1881  }
1882  return false;
1883 }
1884 
1885 /// Default synthesizes all properties which must be synthesized
1886 /// in class's \@implementation.
1888  ObjCInterfaceDecl *IDecl,
1889  SourceLocation AtEnd) {
1891  IDecl->collectPropertiesToImplement(PropMap);
1892  if (PropMap.empty())
1893  return;
1894  ObjCInterfaceDecl::PropertyMap SuperPropMap;
1895  CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
1896 
1897  for (const auto &PropEntry : PropMap) {
1898  ObjCPropertyDecl *Prop = PropEntry.second;
1899  // Is there a matching property synthesize/dynamic?
1900  if (Prop->isInvalidDecl() ||
1901  Prop->isClassProperty() ||
1903  continue;
1904  // Property may have been synthesized by user.
1905  if (IMPDecl->FindPropertyImplDecl(
1906  Prop->getIdentifier(), Prop->getQueryKind()))
1907  continue;
1908  ObjCMethodDecl *ImpMethod = IMPDecl->getInstanceMethod(Prop->getGetterName());
1909  if (ImpMethod && !ImpMethod->getBody()) {
1911  continue;
1912  ImpMethod = IMPDecl->getInstanceMethod(Prop->getSetterName());
1913  if (ImpMethod && !ImpMethod->getBody())
1914  continue;
1915  }
1916  if (ObjCPropertyImplDecl *PID =
1917  IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
1918  Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
1919  << Prop->getIdentifier();
1920  if (PID->getLocation().isValid())
1921  Diag(PID->getLocation(), diag::note_property_synthesize);
1922  continue;
1923  }
1924  ObjCPropertyDecl *PropInSuperClass =
1925  SuperPropMap[std::make_pair(Prop->getIdentifier(),
1926  Prop->isClassProperty())];
1927  if (ObjCProtocolDecl *Proto =
1928  dyn_cast<ObjCProtocolDecl>(Prop->getDeclContext())) {
1929  // We won't auto-synthesize properties declared in protocols.
1930  // Suppress the warning if class's superclass implements property's
1931  // getter and implements property's setter (if readwrite property).
1932  // Or, if property is going to be implemented in its super class.
1933  if (!SuperClassImplementsProperty(IDecl, Prop) && !PropInSuperClass) {
1934  Diag(IMPDecl->getLocation(),
1935  diag::warn_auto_synthesizing_protocol_property)
1936  << Prop << Proto;
1937  Diag(Prop->getLocation(), diag::note_property_declare);
1938  std::string FixIt =
1939  (Twine("@synthesize ") + Prop->getName() + ";\n\n").str();
1940  Diag(AtEnd, diag::note_add_synthesize_directive)
1941  << FixItHint::CreateInsertion(AtEnd, FixIt);
1942  }
1943  continue;
1944  }
1945  // If property to be implemented in the super class, ignore.
1946  if (PropInSuperClass) {
1947  if ((Prop->getPropertyAttributes() &
1949  (PropInSuperClass->getPropertyAttributes() &
1951  !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
1952  !IDecl->HasUserDeclaredSetterMethod(Prop)) {
1953  Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
1954  << Prop->getIdentifier();
1955  Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1956  } else {
1957  Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
1958  << Prop->getIdentifier();
1959  Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1960  Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1961  }
1962  continue;
1963  }
1964  // We use invalid SourceLocations for the synthesized ivars since they
1965  // aren't really synthesized at a particular location; they just exist.
1966  // Saying that they are located at the @implementation isn't really going
1967  // to help users.
1968  ObjCPropertyImplDecl *PIDecl = dyn_cast_or_null<ObjCPropertyImplDecl>(
1970  true,
1971  /* property = */ Prop->getIdentifier(),
1972  /* ivar = */ Prop->getDefaultSynthIvarName(Context),
1973  Prop->getLocation(), Prop->getQueryKind()));
1974  if (PIDecl && !Prop->isUnavailable()) {
1975  Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
1976  Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1977  }
1978  }
1979 }
1980 
1982  SourceLocation AtEnd) {
1983  if (!LangOpts.ObjCDefaultSynthProperties || LangOpts.ObjCRuntime.isFragile())
1984  return;
1985  ObjCImplementationDecl *IC=dyn_cast_or_null<ObjCImplementationDecl>(D);
1986  if (!IC)
1987  return;
1988  if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
1989  if (!IDecl->isObjCRequiresPropertyDefs())
1990  DefaultSynthesizeProperties(S, IC, IDecl, AtEnd);
1991 }
1992 
1994  Sema &S, ObjCInterfaceDecl *PrimaryClass, Selector Method,
1995  ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, ObjCCategoryDecl *C,
1996  ObjCPropertyDecl *Prop,
1998  // Check to see if we have a corresponding selector in SMap and with the
1999  // right method type.
2000  auto I = llvm::find_if(SMap, [&](const ObjCMethodDecl *x) {
2001  return x->getSelector() == Method &&
2002  x->isClassMethod() == Prop->isClassProperty();
2003  });
2004  // When reporting on missing property setter/getter implementation in
2005  // categories, do not report when they are declared in primary class,
2006  // class's protocol, or one of it super classes. This is because,
2007  // the class is going to implement them.
2008  if (I == SMap.end() &&
2009  (PrimaryClass == nullptr ||
2010  !PrimaryClass->lookupPropertyAccessor(Method, C,
2011  Prop->isClassProperty()))) {
2012  unsigned diag =
2013  isa<ObjCCategoryDecl>(CDecl)
2014  ? (Prop->isClassProperty()
2015  ? diag::warn_impl_required_in_category_for_class_property
2016  : diag::warn_setter_getter_impl_required_in_category)
2017  : (Prop->isClassProperty()
2018  ? diag::warn_impl_required_for_class_property
2019  : diag::warn_setter_getter_impl_required);
2020  S.Diag(IMPDecl->getLocation(), diag) << Prop->getDeclName() << Method;
2021  S.Diag(Prop->getLocation(), diag::note_property_declare);
2022  if (S.LangOpts.ObjCDefaultSynthProperties &&
2024  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(CDecl))
2025  if (const ObjCInterfaceDecl *RID = ID->isObjCRequiresPropertyDefs())
2026  S.Diag(RID->getLocation(), diag::note_suppressed_class_declare);
2027  }
2028 }
2029 
2031  ObjCContainerDecl *CDecl,
2032  bool SynthesizeProperties) {
2034  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
2035 
2036  // Since we don't synthesize class properties, we should emit diagnose even
2037  // if SynthesizeProperties is true.
2038  ObjCContainerDecl::PropertyMap NoNeedToImplPropMap;
2039  // Gather properties which need not be implemented in this class
2040  // or category.
2041  if (!IDecl)
2042  if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) {
2043  // For categories, no need to implement properties declared in
2044  // its primary class (and its super classes) if property is
2045  // declared in one of those containers.
2046  if ((IDecl = C->getClassInterface())) {
2047  IDecl->collectPropertiesToImplement(NoNeedToImplPropMap);
2048  }
2049  }
2050  if (IDecl)
2051  CollectSuperClassPropertyImplementations(IDecl, NoNeedToImplPropMap);
2052 
2053  // When SynthesizeProperties is true, we only check class properties.
2054  CollectImmediateProperties(CDecl, PropMap, NoNeedToImplPropMap,
2055  SynthesizeProperties/*CollectClassPropsOnly*/);
2056 
2057  // Scan the @interface to see if any of the protocols it adopts
2058  // require an explicit implementation, via attribute
2059  // 'objc_protocol_requires_explicit_implementation'.
2060  if (IDecl) {
2061  std::unique_ptr<ObjCContainerDecl::PropertyMap> LazyMap;
2062 
2063  for (auto *PDecl : IDecl->all_referenced_protocols()) {
2064  if (!PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
2065  continue;
2066  // Lazily construct a set of all the properties in the @interface
2067  // of the class, without looking at the superclass. We cannot
2068  // use the call to CollectImmediateProperties() above as that
2069  // utilizes information from the super class's properties as well
2070  // as scans the adopted protocols. This work only triggers for protocols
2071  // with the attribute, which is very rare, and only occurs when
2072  // analyzing the @implementation.
2073  if (!LazyMap) {
2074  ObjCContainerDecl::PropertyMap NoNeedToImplPropMap;
2075  LazyMap.reset(new ObjCContainerDecl::PropertyMap());
2076  CollectImmediateProperties(CDecl, *LazyMap, NoNeedToImplPropMap,
2077  /* CollectClassPropsOnly */ false,
2078  /* IncludeProtocols */ false);
2079  }
2080  // Add the properties of 'PDecl' to the list of properties that
2081  // need to be implemented.
2082  for (auto *PropDecl : PDecl->properties()) {
2083  if ((*LazyMap)[std::make_pair(PropDecl->getIdentifier(),
2084  PropDecl->isClassProperty())])
2085  continue;
2086  PropMap[std::make_pair(PropDecl->getIdentifier(),
2087  PropDecl->isClassProperty())] = PropDecl;
2088  }
2089  }
2090  }
2091 
2092  if (PropMap.empty())
2093  return;
2094 
2096  for (const auto *I : IMPDecl->property_impls())
2097  PropImplMap.insert(I->getPropertyDecl());
2098 
2100  // Collect property accessors implemented in current implementation.
2101  for (const auto *I : IMPDecl->methods())
2102  InsMap.insert(I);
2103 
2104  ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
2105  ObjCInterfaceDecl *PrimaryClass = nullptr;
2106  if (C && !C->IsClassExtension())
2107  if ((PrimaryClass = C->getClassInterface()))
2108  // Report unimplemented properties in the category as well.
2109  if (ObjCImplDecl *IMP = PrimaryClass->getImplementation()) {
2110  // When reporting on missing setter/getters, do not report when
2111  // setter/getter is implemented in category's primary class
2112  // implementation.
2113  for (const auto *I : IMP->methods())
2114  InsMap.insert(I);
2115  }
2116 
2117  for (ObjCContainerDecl::PropertyMap::iterator
2118  P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
2119  ObjCPropertyDecl *Prop = P->second;
2120  // Is there a matching property synthesize/dynamic?
2121  if (Prop->isInvalidDecl() ||
2123  PropImplMap.count(Prop) ||
2124  Prop->getAvailability() == AR_Unavailable)
2125  continue;
2126 
2127  // Diagnose unimplemented getters and setters.
2129  PrimaryClass, Prop->getGetterName(), IMPDecl, CDecl, C, Prop, InsMap);
2130  if (!Prop->isReadOnly())
2132  PrimaryClass, Prop->getSetterName(),
2133  IMPDecl, CDecl, C, Prop, InsMap);
2134  }
2135 }
2136 
2138  for (const auto *propertyImpl : impDecl->property_impls()) {
2139  const auto *property = propertyImpl->getPropertyDecl();
2140  // Warn about null_resettable properties with synthesized setters,
2141  // because the setter won't properly handle nil.
2142  if (propertyImpl->getPropertyImplementation() ==
2144  (property->getPropertyAttributes() &
2146  property->getGetterMethodDecl() && property->getSetterMethodDecl()) {
2147  auto *getterImpl = propertyImpl->getGetterMethodDecl();
2148  auto *setterImpl = propertyImpl->getSetterMethodDecl();
2149  if ((!getterImpl || getterImpl->isSynthesizedAccessorStub()) &&
2150  (!setterImpl || setterImpl->isSynthesizedAccessorStub())) {
2151  SourceLocation loc = propertyImpl->getLocation();
2152  if (loc.isInvalid())
2153  loc = impDecl->getBeginLoc();
2154 
2155  Diag(loc, diag::warn_null_resettable_setter)
2156  << setterImpl->getSelector() << property->getDeclName();
2157  }
2158  }
2159  }
2160 }
2161 
2162 void
2164  ObjCInterfaceDecl* IDecl) {
2165  // Rules apply in non-GC mode only
2166  if (getLangOpts().getGC() != LangOptions::NonGC)
2167  return;
2169  for (auto *Prop : IDecl->properties())
2170  PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2171  for (const auto *Ext : IDecl->known_extensions())
2172  for (auto *Prop : Ext->properties())
2173  PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2174 
2175  for (ObjCContainerDecl::PropertyMap::iterator I = PM.begin(), E = PM.end();
2176  I != E; ++I) {
2177  const ObjCPropertyDecl *Property = I->second;
2178  ObjCMethodDecl *GetterMethod = nullptr;
2179  ObjCMethodDecl *SetterMethod = nullptr;
2180 
2181  unsigned Attributes = Property->getPropertyAttributes();
2182  unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
2183 
2184  if (!(AttributesAsWritten & ObjCPropertyAttribute::kind_atomic) &&
2185  !(AttributesAsWritten & ObjCPropertyAttribute::kind_nonatomic)) {
2186  GetterMethod = Property->isClassProperty() ?
2187  IMPDecl->getClassMethod(Property->getGetterName()) :
2188  IMPDecl->getInstanceMethod(Property->getGetterName());
2189  SetterMethod = Property->isClassProperty() ?
2190  IMPDecl->getClassMethod(Property->getSetterName()) :
2191  IMPDecl->getInstanceMethod(Property->getSetterName());
2192  if (GetterMethod && GetterMethod->isSynthesizedAccessorStub())
2193  GetterMethod = nullptr;
2194  if (SetterMethod && SetterMethod->isSynthesizedAccessorStub())
2195  SetterMethod = nullptr;
2196  if (GetterMethod) {
2197  Diag(GetterMethod->getLocation(),
2198  diag::warn_default_atomic_custom_getter_setter)
2199  << Property->getIdentifier() << 0;
2200  Diag(Property->getLocation(), diag::note_property_declare);
2201  }
2202  if (SetterMethod) {
2203  Diag(SetterMethod->getLocation(),
2204  diag::warn_default_atomic_custom_getter_setter)
2205  << Property->getIdentifier() << 1;
2206  Diag(Property->getLocation(), diag::note_property_declare);
2207  }
2208  }
2209 
2210  // We only care about readwrite atomic property.
2211  if ((Attributes & ObjCPropertyAttribute::kind_nonatomic) ||
2212  !(Attributes & ObjCPropertyAttribute::kind_readwrite))
2213  continue;
2214  if (const ObjCPropertyImplDecl *PIDecl = IMPDecl->FindPropertyImplDecl(
2215  Property->getIdentifier(), Property->getQueryKind())) {
2216  if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
2217  continue;
2218  GetterMethod = PIDecl->getGetterMethodDecl();
2219  SetterMethod = PIDecl->getSetterMethodDecl();
2220  if (GetterMethod && GetterMethod->isSynthesizedAccessorStub())
2221  GetterMethod = nullptr;
2222  if (SetterMethod && SetterMethod->isSynthesizedAccessorStub())
2223  SetterMethod = nullptr;
2224  if ((bool)GetterMethod ^ (bool)SetterMethod) {
2225  SourceLocation MethodLoc =
2226  (GetterMethod ? GetterMethod->getLocation()
2227  : SetterMethod->getLocation());
2228  Diag(MethodLoc, diag::warn_atomic_property_rule)
2229  << Property->getIdentifier() << (GetterMethod != nullptr)
2230  << (SetterMethod != nullptr);
2231  // fixit stuff.
2232  if (Property->getLParenLoc().isValid() &&
2233  !(AttributesAsWritten & ObjCPropertyAttribute::kind_atomic)) {
2234  // @property () ... case.
2235  SourceLocation AfterLParen =
2236  getLocForEndOfToken(Property->getLParenLoc());
2237  StringRef NonatomicStr = AttributesAsWritten? "nonatomic, "
2238  : "nonatomic";
2239  Diag(Property->getLocation(),
2240  diag::note_atomic_property_fixup_suggest)
2241  << FixItHint::CreateInsertion(AfterLParen, NonatomicStr);
2242  } else if (Property->getLParenLoc().isInvalid()) {
2243  //@property id etc.
2244  SourceLocation startLoc =
2245  Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
2246  Diag(Property->getLocation(),
2247  diag::note_atomic_property_fixup_suggest)
2248  << FixItHint::CreateInsertion(startLoc, "(nonatomic) ");
2249  } else
2250  Diag(MethodLoc, diag::note_atomic_property_fixup_suggest);
2251  Diag(Property->getLocation(), diag::note_property_declare);
2252  }
2253  }
2254  }
2255 }
2256 
2258  if (getLangOpts().getGC() == LangOptions::GCOnly)
2259  return;
2260 
2261  for (const auto *PID : D->property_impls()) {
2262  const ObjCPropertyDecl *PD = PID->getPropertyDecl();
2263  if (PD && !PD->hasAttr<NSReturnsNotRetainedAttr>() &&
2264  !PD->isClassProperty()) {
2265  ObjCMethodDecl *IM = PID->getGetterMethodDecl();
2266  if (IM && !IM->isSynthesizedAccessorStub())
2267  continue;
2268  ObjCMethodDecl *method = PD->getGetterMethodDecl();
2269  if (!method)
2270  continue;
2271  ObjCMethodFamily family = method->getMethodFamily();
2272  if (family == OMF_alloc || family == OMF_copy ||
2273  family == OMF_mutableCopy || family == OMF_new) {
2274  if (getLangOpts().ObjCAutoRefCount)
2275  Diag(PD->getLocation(), diag::err_cocoa_naming_owned_rule);
2276  else
2277  Diag(PD->getLocation(), diag::warn_cocoa_naming_owned_rule);
2278 
2279  // Look for a getter explicitly declared alongside the property.
2280  // If we find one, use its location for the note.
2281  SourceLocation noteLoc = PD->getLocation();
2282  SourceLocation fixItLoc;
2283  for (auto *getterRedecl : method->redecls()) {
2284  if (getterRedecl->isImplicit())
2285  continue;
2286  if (getterRedecl->getDeclContext() != PD->getDeclContext())
2287  continue;
2288  noteLoc = getterRedecl->getLocation();
2289  fixItLoc = getterRedecl->getEndLoc();
2290  }
2291 
2293  TokenValue tokens[] = {
2294  tok::kw___attribute, tok::l_paren, tok::l_paren,
2295  PP.getIdentifierInfo("objc_method_family"), tok::l_paren,
2296  PP.getIdentifierInfo("none"), tok::r_paren,
2297  tok::r_paren, tok::r_paren
2298  };
2299  StringRef spelling = "__attribute__((objc_method_family(none)))";
2300  StringRef macroName = PP.getLastMacroWithSpelling(noteLoc, tokens);
2301  if (!macroName.empty())
2302  spelling = macroName;
2303 
2304  auto noteDiag = Diag(noteLoc, diag::note_cocoa_naming_declare_family)
2305  << method->getDeclName() << spelling;
2306  if (fixItLoc.isValid()) {
2307  SmallString<64> fixItText(" ");
2308  fixItText += spelling;
2309  noteDiag << FixItHint::CreateInsertion(fixItLoc, fixItText);
2310  }
2311  }
2312  }
2313  }
2314 }
2315 
2317  const ObjCImplementationDecl *ImplD,
2318  const ObjCInterfaceDecl *IFD) {
2319  assert(IFD->hasDesignatedInitializers());
2320  const ObjCInterfaceDecl *SuperD = IFD->getSuperClass();
2321  if (!SuperD)
2322  return;
2323 
2324  SelectorSet InitSelSet;
2325  for (const auto *I : ImplD->instance_methods())
2326  if (I->getMethodFamily() == OMF_init)
2327  InitSelSet.insert(I->getSelector());
2328 
2330  SuperD->getDesignatedInitializers(DesignatedInits);
2332  I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) {
2333  const ObjCMethodDecl *MD = *I;
2334  if (!InitSelSet.count(MD->getSelector())) {
2335  // Don't emit a diagnostic if the overriding method in the subclass is
2336  // marked as unavailable.
2337  bool Ignore = false;
2338  if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) {
2339  Ignore = IMD->isUnavailable();
2340  } else {
2341  // Check the methods declared in the class extensions too.
2342  for (auto *Ext : IFD->visible_extensions())
2343  if (auto *IMD = Ext->getInstanceMethod(MD->getSelector())) {
2344  Ignore = IMD->isUnavailable();
2345  break;
2346  }
2347  }
2348  if (!Ignore) {
2349  Diag(ImplD->getLocation(),
2350  diag::warn_objc_implementation_missing_designated_init_override)
2351  << MD->getSelector();
2352  Diag(MD->getLocation(), diag::note_objc_designated_init_marked_here);
2353  }
2354  }
2355  }
2356 }
2357 
2358 /// AddPropertyAttrs - Propagates attributes from a property to the
2359 /// implicitly-declared getter or setter for that property.
2360 static void AddPropertyAttrs(Sema &S, ObjCMethodDecl *PropertyMethod,
2361  ObjCPropertyDecl *Property) {
2362  // Should we just clone all attributes over?
2363  for (const auto *A : Property->attrs()) {
2364  if (isa<DeprecatedAttr>(A) ||
2365  isa<UnavailableAttr>(A) ||
2366  isa<AvailabilityAttr>(A))
2367  PropertyMethod->addAttr(A->clone(S.Context));
2368  }
2369 }
2370 
2371 /// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods
2372 /// have the property type and issue diagnostics if they don't.
2373 /// Also synthesize a getter/setter method if none exist (and update the
2374 /// appropriate lookup tables.
2376  ObjCMethodDecl *GetterMethod, *SetterMethod;
2377  ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2378  if (CD->isInvalidDecl())
2379  return;
2380 
2381  bool IsClassProperty = property->isClassProperty();
2382  GetterMethod = IsClassProperty ?
2383  CD->getClassMethod(property->getGetterName()) :
2384  CD->getInstanceMethod(property->getGetterName());
2385 
2386  // if setter or getter is not found in class extension, it might be
2387  // in the primary class.
2388  if (!GetterMethod)
2389  if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD))
2390  if (CatDecl->IsClassExtension())
2391  GetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2392  getClassMethod(property->getGetterName()) :
2393  CatDecl->getClassInterface()->
2394  getInstanceMethod(property->getGetterName());
2395 
2396  SetterMethod = IsClassProperty ?
2397  CD->getClassMethod(property->getSetterName()) :
2398  CD->getInstanceMethod(property->getSetterName());
2399  if (!SetterMethod)
2400  if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD))
2401  if (CatDecl->IsClassExtension())
2402  SetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2403  getClassMethod(property->getSetterName()) :
2404  CatDecl->getClassInterface()->
2405  getInstanceMethod(property->getSetterName());
2406  DiagnosePropertyAccessorMismatch(property, GetterMethod,
2407  property->getLocation());
2408 
2409  // synthesizing accessors must not result in a direct method that is not
2410  // monomorphic
2411  if (!GetterMethod) {
2412  if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD)) {
2413  auto *ExistingGetter = CatDecl->getClassInterface()->lookupMethod(
2414  property->getGetterName(), !IsClassProperty, true, false, CatDecl);
2415  if (ExistingGetter) {
2416  if (ExistingGetter->isDirectMethod() || property->isDirectProperty()) {
2417  Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2418  << property->isDirectProperty() << 1 /* property */
2419  << ExistingGetter->isDirectMethod()
2420  << ExistingGetter->getDeclName();
2421  Diag(ExistingGetter->getLocation(), diag::note_previous_declaration);
2422  }
2423  }
2424  }
2425  }
2426 
2427  if (!property->isReadOnly() && !SetterMethod) {
2428  if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD)) {
2429  auto *ExistingSetter = CatDecl->getClassInterface()->lookupMethod(
2430  property->getSetterName(), !IsClassProperty, true, false, CatDecl);
2431  if (ExistingSetter) {
2432  if (ExistingSetter->isDirectMethod() || property->isDirectProperty()) {
2433  Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2434  << property->isDirectProperty() << 1 /* property */
2435  << ExistingSetter->isDirectMethod()
2436  << ExistingSetter->getDeclName();
2437  Diag(ExistingSetter->getLocation(), diag::note_previous_declaration);
2438  }
2439  }
2440  }
2441  }
2442 
2443  if (!property->isReadOnly() && SetterMethod) {
2444  if (Context.getCanonicalType(SetterMethod->getReturnType()) !=
2445  Context.VoidTy)
2446  Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
2447  if (SetterMethod->param_size() != 1 ||
2449  (*SetterMethod->param_begin())->getType().getNonReferenceType(),
2450  property->getType().getNonReferenceType())) {
2451  Diag(property->getLocation(),
2452  diag::warn_accessor_property_type_mismatch)
2453  << property->getDeclName()
2454  << SetterMethod->getSelector();
2455  Diag(SetterMethod->getLocation(), diag::note_declared_at);
2456  }
2457  }
2458 
2459  // Synthesize getter/setter methods if none exist.
2460  // Find the default getter and if one not found, add one.
2461  // FIXME: The synthesized property we set here is misleading. We almost always
2462  // synthesize these methods unless the user explicitly provided prototypes
2463  // (which is odd, but allowed). Sema should be typechecking that the
2464  // declarations jive in that situation (which it is not currently).
2465  if (!GetterMethod) {
2466  // No instance/class method of same name as property getter name was found.
2467  // Declare a getter method and add it to the list of methods
2468  // for this class.
2469  SourceLocation Loc = property->getLocation();
2470 
2471  // The getter returns the declared property type with all qualifiers
2472  // removed.
2473  QualType resultTy = property->getType().getAtomicUnqualifiedType();
2474 
2475  // If the property is null_resettable, the getter returns nonnull.
2476  if (property->getPropertyAttributes() &
2478  QualType modifiedTy = resultTy;
2479  if (auto nullability = AttributedType::stripOuterNullability(modifiedTy)) {
2480  if (*nullability == NullabilityKind::Unspecified)
2481  resultTy = Context.getAttributedType(attr::TypeNonNull,
2482  modifiedTy, modifiedTy);
2483  }
2484  }
2485 
2486  GetterMethod = ObjCMethodDecl::Create(
2487  Context, Loc, Loc, property->getGetterName(), resultTy, nullptr, CD,
2488  !IsClassProperty, /*isVariadic=*/false,
2489  /*isPropertyAccessor=*/true, /*isSynthesizedAccessorStub=*/false,
2490  /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
2494  CD->addDecl(GetterMethod);
2495 
2496  AddPropertyAttrs(*this, GetterMethod, property);
2497 
2498  if (property->isDirectProperty())
2499  GetterMethod->addAttr(ObjCDirectAttr::CreateImplicit(Context, Loc));
2500 
2501  if (property->hasAttr<NSReturnsNotRetainedAttr>())
2502  GetterMethod->addAttr(NSReturnsNotRetainedAttr::CreateImplicit(Context,
2503  Loc));
2504 
2505  if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2506  GetterMethod->addAttr(
2507  ObjCReturnsInnerPointerAttr::CreateImplicit(Context, Loc));
2508 
2509  if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2510  GetterMethod->addAttr(SectionAttr::CreateImplicit(
2511  Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU,
2512  SectionAttr::GNU_section));
2513 
2514  if (getLangOpts().ObjCAutoRefCount)
2515  CheckARCMethodDecl(GetterMethod);
2516  } else
2517  // A user declared getter will be synthesize when @synthesize of
2518  // the property with the same name is seen in the @implementation
2519  GetterMethod->setPropertyAccessor(true);
2520 
2521  GetterMethod->createImplicitParams(Context,
2522  GetterMethod->getClassInterface());
2523  property->setGetterMethodDecl(GetterMethod);
2524 
2525  // Skip setter if property is read-only.
2526  if (!property->isReadOnly()) {
2527  // Find the default setter and if one not found, add one.
2528  if (!SetterMethod) {
2529  // No instance/class method of same name as property setter name was
2530  // found.
2531  // Declare a setter method and add it to the list of methods
2532  // for this class.
2533  SourceLocation Loc = property->getLocation();
2534 
2535  SetterMethod =
2536  ObjCMethodDecl::Create(Context, Loc, Loc,
2537  property->getSetterName(), Context.VoidTy,
2538  nullptr, CD, !IsClassProperty,
2539  /*isVariadic=*/false,
2540  /*isPropertyAccessor=*/true,
2541  /*isSynthesizedAccessorStub=*/false,
2542  /*isImplicitlyDeclared=*/true,
2543  /*isDefined=*/false,
2544  (property->getPropertyImplementation() ==
2548 
2549  // Remove all qualifiers from the setter's parameter type.
2550  QualType paramTy =
2551  property->getType().getUnqualifiedType().getAtomicUnqualifiedType();
2552 
2553  // If the property is null_resettable, the setter accepts a
2554  // nullable value.
2555  if (property->getPropertyAttributes() &
2557  QualType modifiedTy = paramTy;
2558  if (auto nullability = AttributedType::stripOuterNullability(modifiedTy)){
2559  if (*nullability == NullabilityKind::Unspecified)
2560  paramTy = Context.getAttributedType(attr::TypeNullable,
2561  modifiedTy, modifiedTy);
2562  }
2563  }
2564 
2565  // Invent the arguments for the setter. We don't bother making a
2566  // nice name for the argument.
2567  ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod,
2568  Loc, Loc,
2569  property->getIdentifier(),
2570  paramTy,
2571  /*TInfo=*/nullptr,
2572  SC_None,
2573  nullptr);
2574  SetterMethod->setMethodParams(Context, Argument, None);
2575 
2576  AddPropertyAttrs(*this, SetterMethod, property);
2577 
2578  if (property->isDirectProperty())
2579  SetterMethod->addAttr(ObjCDirectAttr::CreateImplicit(Context, Loc));
2580 
2581  CD->addDecl(SetterMethod);
2582  if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2583  SetterMethod->addAttr(SectionAttr::CreateImplicit(
2584  Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU,
2585  SectionAttr::GNU_section));
2586  // It's possible for the user to have set a very odd custom
2587  // setter selector that causes it to have a method family.
2588  if (getLangOpts().ObjCAutoRefCount)
2589  CheckARCMethodDecl(SetterMethod);
2590  } else
2591  // A user declared setter will be synthesize when @synthesize of
2592  // the property with the same name is seen in the @implementation
2593  SetterMethod->setPropertyAccessor(true);
2594 
2595  SetterMethod->createImplicitParams(Context,
2596  SetterMethod->getClassInterface());
2597  property->setSetterMethodDecl(SetterMethod);
2598  }
2599  // Add any synthesized methods to the global pool. This allows us to
2600  // handle the following, which is supported by GCC (and part of the design).
2601  //
2602  // @interface Foo
2603  // @property double bar;
2604  // @end
2605  //
2606  // void thisIsUnfortunate() {
2607  // id foo;
2608  // double bar = [foo bar];
2609  // }
2610  //
2611  if (!IsClassProperty) {
2612  if (GetterMethod)
2613  AddInstanceMethodToGlobalPool(GetterMethod);
2614  if (SetterMethod)
2615  AddInstanceMethodToGlobalPool(SetterMethod);
2616  } else {
2617  if (GetterMethod)
2618  AddFactoryMethodToGlobalPool(GetterMethod);
2619  if (SetterMethod)
2620  AddFactoryMethodToGlobalPool(SetterMethod);
2621  }
2622 
2623  ObjCInterfaceDecl *CurrentClass = dyn_cast<ObjCInterfaceDecl>(CD);
2624  if (!CurrentClass) {
2625  if (ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CD))
2626  CurrentClass = Cat->getClassInterface();
2627  else if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(CD))
2628  CurrentClass = Impl->getClassInterface();
2629  }
2630  if (GetterMethod)
2631  CheckObjCMethodOverrides(GetterMethod, CurrentClass, Sema::RTC_Unknown);
2632  if (SetterMethod)
2633  CheckObjCMethodOverrides(SetterMethod, CurrentClass, Sema::RTC_Unknown);
2634 }
2635 
2637  SourceLocation Loc,
2638  unsigned &Attributes,
2639  bool propertyInPrimaryClass) {
2640  // FIXME: Improve the reported location.
2641  if (!PDecl || PDecl->isInvalidDecl())
2642  return;
2643 
2644  if ((Attributes & ObjCPropertyAttribute::kind_readonly) &&
2646  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2647  << "readonly" << "readwrite";
2648 
2649  ObjCPropertyDecl *PropertyDecl = cast<ObjCPropertyDecl>(PDecl);
2650  QualType PropertyTy = PropertyDecl->getType();
2651 
2652  // Check for copy or retain on non-object types.
2653  if ((Attributes &
2657  !PropertyTy->isObjCRetainableType() &&
2658  !PropertyDecl->hasAttr<ObjCNSObjectAttr>()) {
2659  Diag(Loc, diag::err_objc_property_requires_object)
2660  << (Attributes & ObjCPropertyAttribute::kind_weak
2661  ? "weak"
2662  : Attributes & ObjCPropertyAttribute::kind_copy
2663  ? "copy"
2664  : "retain (or strong)");
2665  Attributes &=
2669  PropertyDecl->setInvalidDecl();
2670  }
2671 
2672  // Check for assign on object types.
2673  if ((Attributes & ObjCPropertyAttribute::kind_assign) &&
2675  PropertyTy->isObjCRetainableType() &&
2676  !PropertyTy->isObjCARCImplicitlyUnretainedType()) {
2677  Diag(Loc, diag::warn_objc_property_assign_on_object);
2678  }
2679 
2680  // Check for more than one of { assign, copy, retain }.
2681  if (Attributes & ObjCPropertyAttribute::kind_assign) {
2682  if (Attributes & ObjCPropertyAttribute::kind_copy) {
2683  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2684  << "assign" << "copy";
2685  Attributes &= ~ObjCPropertyAttribute::kind_copy;
2686  }
2687  if (Attributes & ObjCPropertyAttribute::kind_retain) {
2688  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2689  << "assign" << "retain";
2690  Attributes &= ~ObjCPropertyAttribute::kind_retain;
2691  }
2692  if (Attributes & ObjCPropertyAttribute::kind_strong) {
2693  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2694  << "assign" << "strong";
2695  Attributes &= ~ObjCPropertyAttribute::kind_strong;
2696  }
2697  if (getLangOpts().ObjCAutoRefCount &&
2698  (Attributes & ObjCPropertyAttribute::kind_weak)) {
2699  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2700  << "assign" << "weak";
2701  Attributes &= ~ObjCPropertyAttribute::kind_weak;
2702  }
2703  if (PropertyDecl->hasAttr<IBOutletCollectionAttr>())
2704  Diag(Loc, diag::warn_iboutletcollection_property_assign);
2705  } else if (Attributes & ObjCPropertyAttribute::kind_unsafe_unretained) {
2706  if (Attributes & ObjCPropertyAttribute::kind_copy) {
2707  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2708  << "unsafe_unretained" << "copy";
2709  Attributes &= ~ObjCPropertyAttribute::kind_copy;
2710  }
2711  if (Attributes & ObjCPropertyAttribute::kind_retain) {
2712  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2713  << "unsafe_unretained" << "retain";
2714  Attributes &= ~ObjCPropertyAttribute::kind_retain;
2715  }
2716  if (Attributes & ObjCPropertyAttribute::kind_strong) {
2717  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2718  << "unsafe_unretained" << "strong";
2719  Attributes &= ~ObjCPropertyAttribute::kind_strong;
2720  }
2721  if (getLangOpts().ObjCAutoRefCount &&
2722  (Attributes & ObjCPropertyAttribute::kind_weak)) {
2723  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2724  << "unsafe_unretained" << "weak";
2725  Attributes &= ~ObjCPropertyAttribute::kind_weak;
2726  }
2727  } else if (Attributes & ObjCPropertyAttribute::kind_copy) {
2728  if (Attributes & ObjCPropertyAttribute::kind_retain) {
2729  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2730  << "copy" << "retain";
2731  Attributes &= ~ObjCPropertyAttribute::kind_retain;
2732  }
2733  if (Attributes & ObjCPropertyAttribute::kind_strong) {
2734  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2735  << "copy" << "strong";
2736  Attributes &= ~ObjCPropertyAttribute::kind_strong;
2737  }
2738  if (Attributes & ObjCPropertyAttribute::kind_weak) {
2739  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2740  << "copy" << "weak";
2741  Attributes &= ~ObjCPropertyAttribute::kind_weak;
2742  }
2743  } else if ((Attributes & ObjCPropertyAttribute::kind_retain) &&
2744  (Attributes & ObjCPropertyAttribute::kind_weak)) {
2745  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "retain"
2746  << "weak";
2747  Attributes &= ~ObjCPropertyAttribute::kind_retain;
2748  } else if ((Attributes & ObjCPropertyAttribute::kind_strong) &&
2749  (Attributes & ObjCPropertyAttribute::kind_weak)) {
2750  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "strong"
2751  << "weak";
2752  Attributes &= ~ObjCPropertyAttribute::kind_weak;
2753  }
2754 
2755  if (Attributes & ObjCPropertyAttribute::kind_weak) {
2756  // 'weak' and 'nonnull' are mutually exclusive.
2757  if (auto nullability = PropertyTy->getNullability(Context)) {
2758  if (*nullability == NullabilityKind::NonNull)
2759  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2760  << "nonnull" << "weak";
2761  }
2762  }
2763 
2764  if ((Attributes & ObjCPropertyAttribute::kind_atomic) &&
2765  (Attributes & ObjCPropertyAttribute::kind_nonatomic)) {
2766  Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "atomic"
2767  << "nonatomic";
2768  Attributes &= ~ObjCPropertyAttribute::kind_atomic;
2769  }
2770 
2771  // Warn if user supplied no assignment attribute, property is
2772  // readwrite, and this is an object type.
2773  if (!getOwnershipRule(Attributes) && PropertyTy->isObjCRetainableType()) {
2774  if (Attributes & ObjCPropertyAttribute::kind_readonly) {
2775  // do nothing
2776  } else if (getLangOpts().ObjCAutoRefCount) {
2777  // With arc, @property definitions should default to strong when
2778  // not specified.
2780  } else if (PropertyTy->isObjCObjectPointerType()) {
2781  bool isAnyClassTy = (PropertyTy->isObjCClassType() ||
2782  PropertyTy->isObjCQualifiedClassType());
2783  // In non-gc, non-arc mode, 'Class' is treated as a 'void *' no need to
2784  // issue any warning.
2785  if (isAnyClassTy && getLangOpts().getGC() == LangOptions::NonGC)
2786  ;
2787  else if (propertyInPrimaryClass) {
2788  // Don't issue warning on property with no life time in class
2789  // extension as it is inherited from property in primary class.
2790  // Skip this warning in gc-only mode.
2791  if (getLangOpts().getGC() != LangOptions::GCOnly)
2792  Diag(Loc, diag::warn_objc_property_no_assignment_attribute);
2793 
2794  // If non-gc code warn that this is likely inappropriate.
2795  if (getLangOpts().getGC() == LangOptions::NonGC)
2796  Diag(Loc, diag::warn_objc_property_default_assign_on_object);
2797  }
2798  }
2799 
2800  // FIXME: Implement warning dependent on NSCopying being
2801  // implemented. See also:
2802  // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496>
2803  // (please trim this list while you are at it).
2804  }
2805 
2806  if (!(Attributes & ObjCPropertyAttribute::kind_copy) &&
2807  !(Attributes & ObjCPropertyAttribute::kind_readonly) &&
2808  getLangOpts().getGC() == LangOptions::GCOnly &&
2809  PropertyTy->isBlockPointerType())
2810  Diag(Loc, diag::warn_objc_property_copy_missing_on_block);
2811  else if ((Attributes & ObjCPropertyAttribute::kind_retain) &&
2812  !(Attributes & ObjCPropertyAttribute::kind_readonly) &&
2813  !(Attributes & ObjCPropertyAttribute::kind_strong) &&
2814  PropertyTy->isBlockPointerType())
2815  Diag(Loc, diag::warn_objc_property_retain_of_block);
2816 
2817  if ((Attributes & ObjCPropertyAttribute::kind_readonly) &&
2818  (Attributes & ObjCPropertyAttribute::kind_setter))
2819  Diag(Loc, diag::warn_objc_readonly_property_has_setter);
2820 }
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
clang::ObjCMethodDecl::Required
@ Required
Definition: DeclObjC.h:144
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1149
clang::RecordDecl::hasFlexibleArrayMember
bool hasFlexibleArrayMember() const
Definition: Decl.h:4037
clang::Sema::CurContext
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:421
clang::Type::getNullability
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:4146
clang::ASTContext::getQualifiedType
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2139
clang::ObjCPropertyDecl::isReadOnly
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
Definition: DeclObjC.h:834
clang::InitializedEntity::InitializeResult
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type)
Create the initialization entity for the result of a function.
Definition: Initialization.h:299
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6973
clang::TokenValue
Stores token information for comparing actual tokens with predefined values.
Definition: Preprocessor.h:90
clang::ObjCDeclSpec
Captures information about "declaration specifiers" specific to Objective-C.
Definition: DeclSpec.h:845
clang::QualType::getObjCLifetime
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1193
clang::Decl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:424
clang::Decl::isUnavailable
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked 'unavailable'.
Definition: DeclBase.h:729
clang::Sema::CheckObjCPropertyAttributes
void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc, unsigned &Attributes, bool propertyInPrimaryClass)
Ensure attributes are consistent with type.
Definition: SemaObjCProperty.cpp:2636
clang::OMF_autorelease
@ OMF_autorelease
Definition: IdentifierTable.h:713
clang::ObjCProtocolDecl::protocols
protocol_range protocols() const
Definition: DeclObjC.h:2126
clang::Sema::DiagnoseUnimplementedProperties
void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, bool SynthesizeProperties)
DiagnoseUnimplementedProperties - This routine warns on those properties which must be implemented by...
Definition: SemaObjCProperty.cpp:2030
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6891
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6604
clang::ObjCContainerDecl::getProperty
ObjCPropertyDecl * getProperty(const IdentifierInfo *Id, bool IsInstance) const
Definition: DeclObjC.cpp:236
clang::Sema::HandlePropertyInClassExtension
ObjCPropertyDecl * HandlePropertyInClassExtension(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, unsigned &Attributes, const unsigned AttributesAsWritten, QualType T, TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind)
Called by ActOnProperty to handle @property declarations in class extensions.
Definition: SemaObjCProperty.cpp:405
clang::ObjCPropertyDecl::setPropertyAttributesAsWritten
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:827
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:428
clang::ObjCInterfaceDecl::lookupMethod
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const
lookupMethod - This method returns an instance/class method by looking in the class,...
Definition: DeclObjC.cpp:690
isIncompatiblePropertyAttribute
static bool isIncompatiblePropertyAttribute(unsigned Attr1, unsigned Attr2, ObjCPropertyAttribute::Kind Kind)
Definition: SemaObjCProperty.cpp:822
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4385
clang::ObjCMethodDecl::setPropertyAccessor
void setPropertyAccessor(bool isAccessor)
Definition: DeclObjC.h:445
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::ObjCDeclSpec::getSetterNameLoc
SourceLocation getSetterNameLoc() const
Definition: DeclSpec.h:922
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ObjCMethodFamily
ObjCMethodFamily
A family of Objective-C methods.
Definition: IdentifierTable.h:697
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::Preprocessor::getLastMacroWithSpelling
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
Definition: Preprocessor.cpp:356
clang::ObjCPropertyDecl::getGetterMethodDecl
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:897
clang::FixItHint::CreateInsertion
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:97
clang::ObjCPropertyAttribute::kind_direct
@ kind_direct
Definition: DeclObjCCommon.h:41
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2566
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:79
clang::Sema::AddInstanceMethodToGlobalPool
void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false)
AddInstanceMethodToGlobalPool - All instance methods in a translation unit are added to a global pool...
Definition: Sema.h:4892
clang::Qualifiers::OCL_Weak
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:178
SemaInternal.h
clang::ObjCPropertyAttribute::kind_class
@ kind_class
Definition: DeclObjCCommon.h:40
checkPropertyDeclWithOwnership
static void checkPropertyDeclWithOwnership(Sema &S, ObjCPropertyDecl *property)
Check the internal consistency of a property declaration with an explicit ownership qualifier.
Definition: SemaObjCProperty.cpp:64
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1107
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:597
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::ObjCInterfaceDecl::hasDesignatedInitializers
bool hasDesignatedInitializers() const
Returns true if this interface decl contains at least one initializer marked with the 'objc_designate...
Definition: DeclObjC.cpp:1571
clang::OMF_release
@ OMF_release
Definition: IdentifierTable.h:716
clang::ActionResult::getAs
T * getAs()
Definition: Ownership.h:170
clang::Sema::AtomicPropertySetterGetterRules
void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl, ObjCInterfaceDecl *IDecl)
AtomicPropertySetterGetterRules - This routine enforces the rule (via warning) when atomic property h...
Definition: SemaObjCProperty.cpp:2163
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::Qualifiers::addObjCLifetime
void addObjCLifetime(ObjCLifetime type)
Definition: Type.h:359
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6831
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::ObjCPropertyDecl::isClassProperty
bool isClassProperty() const
Definition: DeclObjC.h:851
clang::ObjCInterfaceDecl::isArcWeakrefUnavailable
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:424
clang::Declarator::getIdentifier
IdentifierInfo * getIdentifier() const
Definition: DeclSpec.h:2251
clang::ObjCIvarDecl::getAccessControl
AccessControl getAccessControl() const
Definition: DeclObjC.h:1970
clang::OMF_init
@ OMF_init
Definition: IdentifierTable.h:707
clang::Sema::BuildBinOp
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15405
clang::ObjCPropertyDecl::isInstanceProperty
bool isInstanceProperty() const
Definition: DeclObjC.h:850
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:773
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1887
clang::Sema::GetTypeForDeclarator
TypeSourceInfo * GetTypeForDeclarator(Declarator &D, Scope *S)
GetTypeForDeclarator - Convert the type for the specified declarator to Type instances.
Definition: SemaType.cpp:5915
clang::ObjCContainerDecl::instance_methods
instmeth_range instance_methods() const
Definition: DeclObjC.h:1029
clang::ObjCCategoryDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2339
clang::ObjCMethodDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1174
clang::ObjCPropertyDecl::isDirectProperty
bool isDirectProperty() const
Definition: DeclObjC.cpp:2355
clang::OMF_retainCount
@ OMF_retainCount
Definition: IdentifierTable.h:718
clang::ObjCPropertyImplDecl
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2771
clang::Sema::DefaultSynthesizeProperties
void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, ObjCInterfaceDecl *IDecl, SourceLocation AtEnd)
DefaultSynthesizeProperties - This routine default synthesizes all properties which must be synthesiz...
Definition: SemaObjCProperty.cpp:1887
clang::Qualifiers::OCL_ExplicitNone
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:168
clang::TypeLoc::getEndLoc
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:234
llvm::SmallPtrSet
Definition: ASTContext.h:82
SourceManager.h
clang::ObjCContainerDecl::HasUserDeclaredSetterMethod
bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const
This routine returns 'true' if a user declared setter method was found in the class,...
Definition: DeclObjC.cpp:125
clang::Sema::DiagnoseOwningPropertyGetterSynthesis
void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D)
Definition: SemaObjCProperty.cpp:2257
clang::ObjCPropertyDecl::setPropertyAttributes
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:815
DiagnoseUnimplementedAccessor
static void DiagnoseUnimplementedAccessor(Sema &S, ObjCInterfaceDecl *PrimaryClass, Selector Method, ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, ObjCCategoryDecl *C, ObjCPropertyDecl *Prop, llvm::SmallPtrSet< const ObjCMethodDecl *, 8 > &SMap)
Definition: SemaObjCProperty.cpp:1993
clang::ObjCContainerDecl::ProtocolPropertySet
llvm::SmallDenseSet< const ObjCProtocolDecl *, 8 > ProtocolPropertySet
Definition: DeclObjC.h:1084
clang::ObjCInterfaceDecl::visible_extensions
visible_extensions_range visible_extensions() const
Definition: DeclObjC.h:1700
clang::LangOptions::GCOnly
@ GCOnly
Definition: LangOptions.h:86
clang::Decl::getAttr
T * getAttr() const
Definition: DeclBase.h:556
clang::Sema::ActOnPropertyImplDecl
Decl * ActOnPropertyImplDecl(Scope *S, SourceLocation AtLoc, SourceLocation PropertyLoc, bool ImplKind, IdentifierInfo *PropertyId, IdentifierInfo *PropertyIvar, SourceLocation PropertyIvarLoc, ObjCPropertyQueryKind QueryKind)
ActOnPropertyImplDecl - This routine performs semantic checks and builds the AST node for a property ...
Definition: SemaObjCProperty.cpp:1077
clang::ObjCPropertyDecl::getPropertyImplementation
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:908
clang::Lexer::LexFromRawLexer
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Definition: Lexer.h:236
clang::ObjCPropertyDecl::Optional
@ Optional
Definition: DeclObjC.h:737
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::ObjCMethodDecl::Create
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isSynthesizedAccessorStub=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:816
clang::Sema::LookupProtocol
ObjCProtocolDecl * LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, RedeclarationKind Redecl=NotForRedeclaration)
Find the protocol with the given name, if any.
Definition: SemaLookup.cpp:3285
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:721
clang::AttributeCommonInfo::AS_GNU
@ AS_GNU
attribute((...))
Definition: AttributeCommonInfo.h:27
clang::Declarator::getIdentifierLoc
SourceLocation getIdentifierLoc() const
Definition: DeclSpec.h:2257
clang::ObjCInterfaceDecl::known_extensions
known_extensions_range known_extensions() const
Definition: DeclObjC.h:1738
clang::Sema::CheckObjCMethodOverrides
void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, ObjCInterfaceDecl *CurrentClass, ResultTypeCompatibilityKind RTC)
Definition: SemaDeclObjC.cpp:4436
clang::ObjCPropertyAttribute::kind_strong
@ kind_strong
Definition: DeclObjCCommon.h:34
clang::ObjCImplDecl::getClassInterface
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2454
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:636
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:409
Preprocessor.h
clang::ObjCMethodDecl::createImplicitParams
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1153
clang::Decl::getAvailability
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:636
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:78
DeclObjC.h
SelectPropertyForSynthesisFromProtocols
static ObjCPropertyDecl * SelectPropertyForSynthesisFromProtocols(Sema &S, SourceLocation AtLoc, ObjCInterfaceDecl *ClassDecl, ObjCPropertyDecl *Property)
SelectPropertyForSynthesisFromProtocols - Finds the most appropriate property declaration that should...
Definition: SemaObjCProperty.cpp:838
clang::ASTContext::getObjCGCQualType
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const
Return the uniqued reference to the type for an Objective-C gc-qualified type.
Definition: ASTContext.cpp:3148
OwnershipMask
static const unsigned OwnershipMask
Definition: SemaObjCProperty.cpp:152
makePropertyAttributesAsWritten
static ObjCPropertyAttribute::Kind makePropertyAttributesAsWritten(unsigned Attributes)
Definition: SemaObjCProperty.cpp:272
clang::TypeLoc::getBeginLoc
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:191
clang::ObjCRuntime::isFragile
bool isFragile() const
The inverse of isNonFragile(): does this runtime follow the set of implied behaviors for a "fragile" ...
Definition: ObjCRuntime.h:97
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1630
clang::Type::isObjCARCImplicitlyUnretainedType
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:4354
clang::Sema::DiagnosePropertyAccessorMismatch
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc)
Definition: SemaObjCProperty.cpp:1709
clang::OMF_copy
@ OMF_copy
Definition: IdentifierTable.h:706
clang::ObjCInterfaceDecl::getDesignatedInitializers
void getDesignatedInitializers(llvm::SmallVectorImpl< const ObjCMethodDecl * > &Methods) const
Returns the designated initializers for the interface.
Definition: DeclObjC.cpp:550
clang::ObjCPropertyAttribute::kind_atomic
@ kind_atomic
Definition: DeclObjCCommon.h:32
clang::Sema::RequireCompleteType
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:8700
clang::ObjCPropertyAttribute::kind_copy
@ kind_copy
Definition: DeclObjCCommon.h:29
clang::Sema::DiagnoseMissingDesignatedInitOverrides
void DiagnoseMissingDesignatedInitOverrides(const ObjCImplementationDecl *ImplD, const ObjCInterfaceDecl *IFD)
Definition: SemaObjCProperty.cpp:2316
clang::Type::isObjCClassType
bool isObjCClassType() const
Definition: Type.h:7050
clang::ast_matchers::attr
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Definition: ASTMatchersInternal.cpp:1031
clang::ObjCMethodDecl::setSelfDecl
void setSelfDecl(ImplicitParamDecl *SD)
Definition: DeclObjC.h:424
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
clang::ObjCPropertyImplDecl::setGetterCXXConstructor
void setGetterCXXConstructor(Expr *getterCXXConstructor)
Definition: DeclObjC.h:2876
clang::ObjCPropertyDecl::setPropertyImplementation
void setPropertyImplementation(PropertyControl pc)
Definition: DeclObjC.h:904
clang::LangOptions::ObjCRuntime
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:414
clang::OMF_retain
@ OMF_retain
Definition: IdentifierTable.h:717
checkARCPropertyImpl
static void checkARCPropertyImpl(Sema &S, SourceLocation propertyImplLoc, ObjCPropertyDecl *property, ObjCIvarDecl *ivar)
Definition: SemaObjCProperty.cpp:721
clang::Sema::CreatePropertyDecl
ObjCPropertyDecl * CreatePropertyDecl(Scope *S, ObjCContainerDecl *CDecl, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, const unsigned Attributes, const unsigned AttributesAsWritten, QualType T, TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind, DeclContext *lexicalDC=nullptr)
Called by ActOnProperty and HandlePropertyInClassExtension to handle creating the ObjcPropertyDecl fo...
Definition: SemaObjCProperty.cpp:558
clang::ObjCInterfaceDecl::getImplementation
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1598
clang::QualType::isObjCGCStrong
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition: Type.h:1188
clang::ObjCInterfaceDecl::protocols
protocol_range protocols() const
Definition: DeclObjC.h:1343
clang::Qualifiers::OCL_Strong
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:175
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::ObjCPropertyImplDecl::Create
static ObjCPropertyImplDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation atLoc, SourceLocation L, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc)
Definition: DeclObjC.cpp:2364
clang::ObjCInterfaceDecl::ClassImplementsProtocol
bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, bool lookupCategory, bool RHSIsQualifiedID=false)
ClassImplementsProtocol - Checks that 'lProto' protocol has been implemented in IDecl class,...
Definition: DeclObjC.cpp:1757
clang::Sema::RequireNonAbstractType
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Definition: SemaDeclCXX.cpp:5827
clang::AttributedType::stripOuterNullability
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4300
clang::Decl::setAttrs
void setAttrs(const AttrVec &Attrs)
Definition: DeclBase.h:504
clang::ObjCPropertyImplDecl::Synthesize
@ Synthesize
Definition: DeclObjC.h:2774
clang::ObjCPropertyAttribute::kind_weak
@ kind_weak
Definition: DeclObjCCommon.h:33
clang::ObjCMethodDecl::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:1016
AddPropertyAttrs
static void AddPropertyAttrs(Sema &S, ObjCMethodDecl *PropertyMethod, ObjCPropertyDecl *Property)
AddPropertyAttrs - Propagates attributes from a property to the implicitly-declared getter or setter ...
Definition: SemaObjCProperty.cpp:2360
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:803
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ObjCPropertyAttribute::kind_unsafe_unretained
@ kind_unsafe_unretained
Definition: DeclObjCCommon.h:35
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::ObjCPropertyAttribute::kind_null_resettable
@ kind_null_resettable
Definition: DeclObjCCommon.h:39
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::DeclContext::makeDeclVisibleInContext
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1883
clang::ObjCContainerDecl::methods
method_range methods() const
Definition: DeclObjC.h:1012
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:571
clang::ObjCPropertyDecl::getSetterName
Selector getSetterName() const
Definition: DeclObjC.h:889
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:330
clang::ObjCInterfaceDecl::lookupInstanceVariable
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:628
clang::ObjCDeclSpec::getGetterNameLoc
SourceLocation getGetterNameLoc() const
Definition: DeclSpec.h:914
clang::ObjCInterfaceDecl::lookupPropertyAccessor
ObjCMethodDecl * lookupPropertyAccessor(const Selector Sel, const ObjCCategoryDecl *Cat, bool IsClassProperty) const
Lookup a setter or getter in the class hierarchy, including in all categories except for category pas...
Definition: DeclObjC.h:1845
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:98
clang::ObjCIvarDecl::getSynthesize
bool getSynthesize() const
Definition: DeclObjC.h:1977
clang::ImplicitCastExpr::Create
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2062
clang::ObjCImplDecl::addPropertyImplementation
void addPropertyImplementation(ObjCPropertyImplDecl *property)
Definition: DeclObjC.cpp:2185
clang::Type::isFunctionType
bool isFunctionType() const
Definition: Type.h:6879
CollectSuperClassPropertyImplementations
static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl, ObjCInterfaceDecl::PropertyMap &PropMap)
CollectSuperClassPropertyImplementations - This routine collects list of properties to be implemented...
Definition: SemaObjCProperty.cpp:1822
clang::ObjCMethodDecl::setDefined
void setDefined(bool isDefined)
Definition: DeclObjC.h:458
clang::ImplicitParamDecl
Definition: Decl.h:1645
clang::Qualifiers::hasObjCLifetime
bool hasObjCLifetime() const
Definition: Type.h:351
llvm::SmallString
Definition: LLVM.h:37
CollectImmediateProperties
static void CollectImmediateProperties(ObjCContainerDecl *CDecl, ObjCContainerDecl::PropertyMap &PropMap, ObjCContainerDecl::PropertyMap &SuperPropMap, bool CollectClassPropsOnly=false, bool IncludeProtocols=true)
CollectImmediateProperties - This routine collects all properties in the class and its conforming pro...
Definition: SemaObjCProperty.cpp:1755
clang::ObjCMethodDecl::getReturnType
QualType getReturnType() const
Definition: DeclObjC.h:332
clang::ASTContext::canAssignObjCInterfaces
bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT)
canAssignObjCInterfaces - Return true if the two interface types are compatible for assignment from R...
Definition: ASTContext.cpp:9702
Category
int Category
Definition: Format.cpp:2718
clang::FieldDeclarator::D
Declarator D
Definition: DeclSpec.h:2678
clang::ObjCIvarDecl::Private
@ Private
Definition: DeclObjC.h:1926
clang::ObjCCategoryImplDecl
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2513
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2528
llvm::DenseSet
Definition: Sema.h:77
clang::tok::ObjCKeywordKind
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:41
clang::Sema::getLocForEndOfToken
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:56
clang::Decl::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1014
clang::ObjCPropertyDecl::overwritePropertyAttributes
void overwritePropertyAttributes(unsigned PRVal)
Definition: DeclObjC.h:819
clang::DeclContextLookupResult::find_first
T * find_first() const
Definition: DeclBase.h:1363
clang::ObjCPropertyAttribute::kind_readonly
@ kind_readonly
Definition: DeclObjCCommon.h:24
ExprObjC.h
SMap
llvm::DenseMap< const Stmt *, CFGBlock * > SMap
Definition: CFGStmtMap.cpp:21
ExprCXX.h
clang::ObjCPropertyDecl::getType
QualType getType() const
Definition: DeclObjC.h:800
CheckPropertyAgainstProtocol
static void CheckPropertyAgainstProtocol(Sema &S, ObjCPropertyDecl *Prop, ObjCProtocolDecl *Proto, llvm::SmallPtrSetImpl< ObjCProtocolDecl * > &Known)
Check this Objective-C property against a property declared in the given protocol.
Definition: SemaObjCProperty.cpp:107
clang::ObjCMethodDecl::Optional
@ Optional
Definition: DeclObjC.h:144
clang::ObjCContainerDecl::properties
prop_range properties() const
Definition: DeclObjC.h:963
clang::ObjCPropertyDecl::setSetterName
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:892
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:99
x
IRgen optimization opportunities The common pattern of short x
Definition: README.txt:7
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:576
clang::Qualifiers::OCL_Autoreleasing
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:181
clang::QualType::split
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6643
clang::Qualifiers::setObjCLifetime
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:355
clang::Sema::SynthesizedFunctionScope
RAII object to handle the state changes required to synthesize a function body.
Definition: Sema.h:1051
clang::Qualifiers::ObjCLifetime
ObjCLifetime
Definition: Type.h:162
clang::Token::getRawIdentifier
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
Definition: Token.h:207
clang::Sema::LangOpts
const LangOptions & LangOpts
Definition: Sema.h:407
clang::Type::isObjCObjectPointerType
bool isObjCObjectPointerType() const
Definition: Type.h:7011
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2294
clang::ObjCRuntime::allowsDirectDispatch
bool allowsDirectDispatch() const
Does this runtime supports direct dispatch.
Definition: ObjCRuntime.h:451
clang::ObjCInterfaceDecl::isObjCRequiresPropertyDefs
const ObjCInterfaceDecl * isObjCRequiresPropertyDefs() const
isObjCRequiresPropertyDefs - Checks that a class or one of its super classes must not be auto-synthes...
Definition: DeclObjC.cpp:434
clang::VK_LValue
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:127
clang::Type::isArithmeticType
bool isArithmeticType() const
Definition: Type.cpp:2153
checkAtomicPropertyMismatch
static void checkAtomicPropertyMismatch(Sema &S, ObjCPropertyDecl *OldProperty, ObjCPropertyDecl *NewProperty, bool PropagateAtomicity)
Check for a mismatch in the atomicity of the given properties.
Definition: SemaObjCProperty.cpp:336
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:6270
clang::ObjCMethodDecl::param_iterator
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:353
clang::ObjCImplDecl::property_impls
propimpl_range property_impls() const
Definition: DeclObjC.h:2481
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Sema::AddFactoryMethodToGlobalPool
void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false)
AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Definition: Sema.h:4897
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:123
clang::Sema::Compatible
@ Compatible
Compatible - the types are compatible according to the standard.
Definition: Sema.h:12250
clang::ObjCImplDecl::FindPropertyImplIvarDecl
ObjCPropertyImplDecl * FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const
FindPropertyImplIvarDecl - This method lookup the ivar in the list of properties implemented in this ...
Definition: DeclObjC.cpp:2210
clang::ObjCPropertyDecl::getDefaultSynthIvarName
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
Definition: DeclObjC.cpp:227
clang::Decl::hasAttrs
bool hasAttrs() const
Definition: DeclBase.h:502
clang::Sema::PerformCopyInitialization
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Definition: SemaInit.cpp:9989
clang::ASTContext::getAttributedType
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
Definition: ASTContext.cpp:4801
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::NullabilityKind::Unspecified
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
clang::LangOptions::NonGC
@ NonGC
Definition: LangOptions.h:86
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1606
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:660
clang::ObjCImplDecl
Definition: DeclObjC.h:2439
clang::ObjCMethodDecl::isSynthesizedAccessorStub
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:449
clang::frontend::FixIt
@ FixIt
Parse and apply any fixits to the source.
Definition: FrontendOptions.h:82
Lexer.h
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::Sema::ProcessDeclAttributes
void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)
ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in it, apply them to D.
Definition: SemaDeclAttr.cpp:9475
clang::ObjCPropertyQueryKind
ObjCPropertyQueryKind
Definition: DeclObjC.h:720
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:732
clang::ObjCMethodDecl::isInstanceMethod
bool isInstanceMethod() const
Definition: DeclObjC.h:431
clang::QualType::isObjCGCWeak
bool isObjCGCWeak() const
true when Type is objc's weak.
Definition: Type.h:1183
ASTMutationListener.h
clang::ObjCContainerDecl::getMethod
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
Definition: DeclObjC.cpp:93
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
clang::ActionResult::isInvalid
bool isInvalid() const
Definition: Ownership.h:165
clang::Sema::DiagnosePropertyMismatch
void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, ObjCPropertyDecl *SuperProperty, const IdentifierInfo *Name, bool OverridingProtocolProperty)
DiagnosePropertyMismatch - Compares two properties for their attributes and types and warns on a vari...
Definition: SemaObjCProperty.cpp:1635
clang::ObjCPropertyAttribute::kind_assign
@ kind_assign
Definition: DeclObjCCommon.h:26
clang::Sema::IvarBacksCurrentMethodAccessor
bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, ObjCMethodDecl *Method, ObjCIvarDecl *IV)
IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is an ivar synthesized for 'Meth...
Definition: SemaObjCProperty.cpp:1836
clang::ObjCPropertyDecl::setGetterName
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:884
clang::ObjCPropertyImplDecl::Dynamic
@ Dynamic
Definition: DeclObjC.h:2775
clang::ObjCPropertyDecl::getQueryKind
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:856
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:352
setImpliedPropertyAttributeForReadOnlyProperty
static void setImpliedPropertyAttributeForReadOnlyProperty(ObjCPropertyDecl *property, ObjCIvarDecl *ivar)
setImpliedPropertyAttributeForReadOnlyProperty - This routine evaludates life-time attributes for a '...
Definition: SemaObjCProperty.cpp:800
clang::ObjCPropertyImplDecl::getPropertyImplementation
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2840
clang::ast_matchers::callExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
Definition: ASTMatchersInternal.cpp:817
clang::SplitQualType
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:670
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::ObjCRuntime
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
clang::Sema::CheckAssignmentConstraints
AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, QualType LHSType, QualType RHSType)
CheckAssignmentConstraints - Perform type checking for assignment, argument passing,...
Definition: SemaExpr.cpp:9478
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::Type::isObjCQualifiedClassType
bool isObjCQualifiedClassType() const
Definition: Type.h:7038
clang::ObjCPropertyImplDecl::getPropertyDecl
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2835
RedeclarePropertyAccessor
static ObjCMethodDecl * RedeclarePropertyAccessor(ASTContext &Context, ObjCImplementationDecl *Impl, ObjCMethodDecl *AccessorDecl, SourceLocation AtLoc, SourceLocation PropertyLoc)
Create a synthesized property accessor stub inside the @implementation.
Definition: SemaObjCProperty.cpp:1048
clang::Sema::MarkDeclRefReferenced
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:19724
clang::SourceLocation::isMacroID
bool isMacroID() const
Definition: SourceLocation.h:103
clang::OMF_new
@ OMF_new
Definition: IdentifierTable.h:709
clang::ObjCPropertyDecl::getPropertyAttributesAsWritten
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:823
clang::ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass
ObjCPropertyDecl * FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyVisibleInPrimaryClass - Finds declaration of the property with name 'PropertyId' in the p...
Definition: DeclObjC.cpp:383
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Sema::MaybeCreateExprWithCleanups
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
Definition: SemaExprCXX.cpp:7328
hasWrittenStorageAttribute
static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop, ObjCPropertyQueryKind QueryKind)
Determine whether any storage attributes were written on the property.
Definition: SemaObjCProperty.cpp:1014
clang::ObjCPropertyDecl::getGetterName
Selector getGetterName() const
Definition: DeclObjC.h:881
clang::ActionResult< Expr * >
clang::Type::isObjCObjectType
bool isObjCObjectType() const
Definition: Type.h:7015
clang::ObjCMethodDecl::getBody
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:872
clang::Sema::getPreprocessor
Preprocessor & getPreprocessor() const
Definition: Sema.h:1636
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::ObjCImplDecl::FindPropertyImplDecl
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2222
clang::ObjCInterfaceDecl::FindCategoryDeclaration
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1718
clang::Qualifiers::OCL_None
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:164
clang::CanQual::getUnqualifiedType
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Definition: CanonicalType.h:619
clang::ObjCMethodDecl::param_begin
param_const_iterator param_begin() const
Definition: DeclObjC.h:357
clang::ObjCPropertyAttribute::kind_readwrite
@ kind_readwrite
Definition: DeclObjCCommon.h:27
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang::Sema::diagnoseNullResettableSynthesizedSetters
void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl)
Diagnose any null-resettable synthesized setters.
Definition: SemaObjCProperty.cpp:2137
clang::ObjCIvarDecl::Create
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
Definition: DeclObjC.cpp:1802
clang::AR_Unavailable
@ AR_Unavailable
Definition: DeclBase.h:73
clang
Definition: CalledOnceCheck.h:17
clang::ObjCContainerDecl::getInstanceMethod
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1062
clang::ObjCPropertyDecl::Required
@ Required
Definition: DeclObjC.h:737
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:759
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:6949
clang::Sema::ActOnDocumentableDecl
void ActOnDocumentableDecl(Decl *D)
Should be called on all declarations that might have attached documentation comments.
Definition: SemaDecl.cpp:14341
areIncompatiblePropertyAttributes
static bool areIncompatiblePropertyAttributes(unsigned Attr1, unsigned Attr2, unsigned Kinds)
Definition: SemaObjCProperty.cpp:827
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1921
clang::ObjCPropertyAttribute::kind_nonatomic
@ kind_nonatomic
Definition: DeclObjCCommon.h:30
clang::Qualifiers::Weak
@ Weak
Definition: Type.h:158
clang::OMF_alloc
@ OMF_alloc
Definition: IdentifierTable.h:705
clang::ObjCContainerDecl::PropertyDeclOrder
llvm::SmallVector< ObjCPropertyDecl *, 8 > PropertyDeclOrder
Definition: DeclObjC.h:1085
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2050
clang::FieldDeclarator
This little struct is used to capture information about structure field declarators,...
Definition: DeclSpec.h:2677
clang::ObjCPropertyImplDecl::setSetterCXXAssignment
void setSetterCXXAssignment(Expr *setterCXXAssignment)
Definition: DeclObjC.h:2884
clang::Sema::ProcessPropertyDecl
void ProcessPropertyDecl(ObjCPropertyDecl *property)
Process the specified property declaration and create decls for the setters and getters as needed.
Definition: SemaObjCProperty.cpp:2375
clang::ObjCPropertyImplDecl::setSetterMethodDecl
void setSetterMethodDecl(ObjCMethodDecl *MD)
Definition: DeclObjC.h:2870
clang::Sema::RTC_Unknown
@ RTC_Unknown
Definition: Sema.h:10464
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::OMF_mutableCopy
@ OMF_mutableCopy
Definition: IdentifierTable.h:708
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:40
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6593
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
clang::ObjCSubstitutionContext::Property
@ Property
The type of a property.
clang::ObjCContainerDecl::FindPropertyDeclaration
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in 'PropertyId' and return...
Definition: DeclObjC.cpp:250
clang::ObjCDeclSpec::getPropertyAttributes
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclSpec.h:879
clang::ObjCInterfaceDecl::all_referenced_protocols
all_protocol_range all_referenced_protocols() const
Definition: DeclObjC.h:1401
clang::Decl::getAttrs
AttrVec & getAttrs()
Definition: DeclBase.h:508
clang::Sema::isObjCPointerConversion
bool isObjCPointerConversion(QualType FromType, QualType ToType, QualType &ConvertedType, bool &IncompatibleObjC)
isObjCPointerConversion - Determines whether this is an Objective-C pointer conversion.
Definition: SemaOverload.cpp:2612
clang::ObjCContainerDecl
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:944
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1334
clang::ObjCContainerDecl::instance_properties
instprop_range instance_properties() const
Definition: DeclObjC.h:978
clang::ObjCMethodDecl::isPropertyAccessor
bool isPropertyAccessor() const
Definition: DeclObjC.h:441
clang::ObjCPropertyAttribute::kind_nullability
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
Definition: DeclObjCCommon.h:38
clang::ASTContext::getTrivialTypeSourceInfo
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
Definition: ASTContext.cpp:3030
getImpliedARCOwnership
static Qualifiers::ObjCLifetime getImpliedARCOwnership(ObjCPropertyAttribute::Kind attrs, QualType type)
getImpliedARCOwnership - Given a set of property attributes and a type, infer an expected lifetime.
Definition: SemaObjCProperty.cpp:39
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4826
clang::ObjCPropertyAttribute::kind_getter
@ kind_getter
Definition: DeclObjCCommon.h:25
LocPropertyAttribute
static bool LocPropertyAttribute(ASTContext &Context, const char *attrName, SourceLocation LParenLoc, SourceLocation &Loc)
Definition: SemaObjCProperty.cpp:306
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
clang::Declarator::setObjCWeakProperty
void setObjCWeakProperty(bool Val=true)
Definition: DeclSpec.h:2623
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2544
clang::ObjCRuntime::isNonFragile
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Definition: ObjCRuntime.h:82
clang::ObjCIvarDecl::getUsageType
QualType getUsageType(QualType objectType) const
Retrieve the type of this instance variable when viewed as a member of a specific object type.
Definition: DeclObjC.cpp:1868
clang::SC_None
@ SC_None
Definition: Specifiers.h:238
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
true
#define true
Definition: stdbool.h:21
clang::Sema::AbstractSynthesizedIvarType
@ AbstractSynthesizedIvarType
Definition: Sema.h:7885
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2571
clang::Sema::ActOnProperty
Decl * ActOnProperty(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, ObjCDeclSpec &ODS, Selector GetterSel, Selector SetterSel, tok::ObjCKeywordKind MethodImplKind, DeclContext *lexicalDC=nullptr)
Definition: SemaObjCProperty.cpp:172
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:129
deducePropertyOwnershipFromType
static unsigned deducePropertyOwnershipFromType(Sema &S, QualType T)
Definition: SemaObjCProperty.cpp:126
getOwnershipRule
static unsigned getOwnershipRule(unsigned attr)
Definition: SemaObjCProperty.cpp:158
SM
#define SM(sm)
Definition: Cuda.cpp:79
clang::ObjCContainerDecl::getClassMethod
ObjCMethodDecl * getClassMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1067
clang::ParmVarDecl::Create
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2831
clang::ObjCMethodDecl::setCmdDecl
void setCmdDecl(ImplicitParamDecl *CD)
Definition: DeclObjC.h:426
clang::ObjCMethodDecl::setMethodParams
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:907
clang::Sema::PP
Preprocessor & PP
Definition: Sema.h:408
clang::ASTContext::propertyTypesAreCompatible
bool propertyTypesAreCompatible(QualType, QualType)
Definition: ASTContext.cpp:10160
clang::ASTContext::getObjCObjectPointerType
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
Definition: ASTContext.cpp:5598
clang::ObjCPropertyDecl::getPropertyAttributes
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:811
clang::NullabilityKind::NonNull
@ NonNull
Values of this type can never be null.
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::SplitQualType::Quals
Qualifiers Quals
The local qualifiers.
Definition: Type.h:675
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:902
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::diag::kind
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:62
clang::CXXOperatorCallExpr
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:82
clang::ObjCPropertyDecl::findPropertyDecl
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Definition: DeclObjC.cpp:179
clang::ObjCPropertyAttribute::kind_retain
@ kind_retain
Definition: DeclObjCCommon.h:28
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:791
clang::ObjCPropertyDecl::Create
static ObjCPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation AtLocation, SourceLocation LParenLocation, QualType T, TypeSourceInfo *TSI, PropertyControl propControl=None)
Definition: DeclObjC.cpp:2331
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1383
clang::ObjCProtocolDecl::getDefinition
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2215
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
clang::ObjCInterfaceDecl::collectPropertiesToImplement
void collectPropertiesToImplement(PropertyMap &PM) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:407
clang::Sema::CheckARCMethodDecl
bool CheckARCMethodDecl(ObjCMethodDecl *method)
Check a method declaration for compatibility with the Objective-C ARC conventions.
Definition: SemaDeclObjC.cpp:225
clang::ObjCMethodDecl::param_size
unsigned param_size() const
Definition: DeclObjC.h:350
clang::declaresSameEntity
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1240
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:244
clang::ValueDecl::setType
void setType(QualType newType)
Definition: Decl.h:713
SuperClassImplementsProperty
static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl, ObjCPropertyDecl *Prop)
Definition: SemaObjCProperty.cpp:1864
clang::ObjCPropertyAttribute::kind_setter
@ kind_setter
Definition: DeclObjCCommon.h:31
Initialization.h
clang::ObjCPropertyImplDecl::setGetterMethodDecl
void setGetterMethodDecl(ObjCMethodDecl *MD)
Definition: DeclObjC.h:2867
clang::ObjCContainerDecl::PropertyMap
llvm::MapVector< std::pair< IdentifierInfo *, unsigned >, ObjCPropertyDecl * > PropertyMap
Definition: DeclObjC.h:1083
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:441
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274