clang  6.0.0svn
DeclObjC.cpp
Go to the documentation of this file.
1 //===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Objective-C related Decl classes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/DeclObjC.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Stmt.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallString.h"
21 using namespace clang;
22 
23 //===----------------------------------------------------------------------===//
24 // ObjCListBase
25 //===----------------------------------------------------------------------===//
26 
27 void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
28  List = nullptr;
29  if (Elts == 0) return; // Setting to an empty list is a noop.
30 
31 
32  List = new (Ctx) void*[Elts];
33  NumElts = Elts;
34  memcpy(List, InList, sizeof(void*)*Elts);
35 }
36 
37 void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
38  const SourceLocation *Locs, ASTContext &Ctx) {
39  if (Elts == 0)
40  return;
41 
42  Locations = new (Ctx) SourceLocation[Elts];
43  memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
44  set(InList, Elts, Ctx);
45 }
46 
47 //===----------------------------------------------------------------------===//
48 // ObjCInterfaceDecl
49 //===----------------------------------------------------------------------===//
50 
51 void ObjCContainerDecl::anchor() { }
52 
53 /// getIvarDecl - This method looks up an ivar in this ContextDecl.
54 ///
57  lookup_result R = lookup(Id);
58  for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end();
59  Ivar != IvarEnd; ++Ivar) {
60  if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
61  return ivar;
62  }
63  return nullptr;
64 }
65 
66 // Get the local instance/class method declared in this interface.
69  bool AllowHidden) const {
70  // If this context is a hidden protocol definition, don't find any
71  // methods there.
72  if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
73  if (const ObjCProtocolDecl *Def = Proto->getDefinition())
74  if (Def->isHidden() && !AllowHidden)
75  return nullptr;
76  }
77 
78  // Since instance & class methods can have the same name, the loop below
79  // ensures we get the correct method.
80  //
81  // @interface Whatever
82  // - (int) class_method;
83  // + (float) class_method;
84  // @end
85  //
86  lookup_result R = lookup(Sel);
87  for (lookup_iterator Meth = R.begin(), MethEnd = R.end();
88  Meth != MethEnd; ++Meth) {
89  ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
90  if (MD && MD->isInstanceMethod() == isInstance)
91  return MD;
92  }
93  return nullptr;
94 }
95 
96 /// \brief This routine returns 'true' if a user declared setter method was
97 /// found in the class, its protocols, its super classes or categories.
98 /// It also returns 'true' if one of its categories has declared a 'readwrite'
99 /// property. This is because, user must provide a setter method for the
100 /// category's 'readwrite' property.
102  const ObjCPropertyDecl *Property) const {
103  Selector Sel = Property->getSetterName();
104  lookup_result R = lookup(Sel);
105  for (lookup_iterator Meth = R.begin(), MethEnd = R.end();
106  Meth != MethEnd; ++Meth) {
107  ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
108  if (MD && MD->isInstanceMethod() && !MD->isImplicit())
109  return true;
110  }
111 
112  if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(this)) {
113  // Also look into categories, including class extensions, looking
114  // for a user declared instance method.
115  for (const auto *Cat : ID->visible_categories()) {
116  if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel))
117  if (!MD->isImplicit())
118  return true;
119  if (Cat->IsClassExtension())
120  continue;
121  // Also search through the categories looking for a 'readwrite'
122  // declaration of this property. If one found, presumably a setter will
123  // be provided (properties declared in categories will not get
124  // auto-synthesized).
125  for (const auto *P : Cat->properties())
126  if (P->getIdentifier() == Property->getIdentifier()) {
127  if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite)
128  return true;
129  break;
130  }
131  }
132 
133  // Also look into protocols, for a user declared instance method.
134  for (const auto *Proto : ID->all_referenced_protocols())
135  if (Proto->HasUserDeclaredSetterMethod(Property))
136  return true;
137 
138  // And in its super class.
139  ObjCInterfaceDecl *OSC = ID->getSuperClass();
140  while (OSC) {
141  if (OSC->HasUserDeclaredSetterMethod(Property))
142  return true;
143  OSC = OSC->getSuperClass();
144  }
145  }
146  if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this))
147  for (const auto *PI : PD->protocols())
148  if (PI->HasUserDeclaredSetterMethod(Property))
149  return true;
150  return false;
151 }
152 
155  const IdentifierInfo *propertyID,
156  ObjCPropertyQueryKind queryKind) {
157  // If this context is a hidden protocol definition, don't find any
158  // property.
159  if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) {
160  if (const ObjCProtocolDecl *Def = Proto->getDefinition())
161  if (Def->isHidden())
162  return nullptr;
163  }
164 
165  // If context is class, then lookup property in its visible extensions.
166  // This comes before property is looked up in primary class.
167  if (auto *IDecl = dyn_cast<ObjCInterfaceDecl>(DC)) {
168  for (const auto *Ext : IDecl->visible_extensions())
170  propertyID,
171  queryKind))
172  return PD;
173  }
174 
175  DeclContext::lookup_result R = DC->lookup(propertyID);
176  ObjCPropertyDecl *classProp = nullptr;
177  for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
178  ++I)
179  if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) {
180  // If queryKind is unknown, we return the instance property if one
181  // exists; otherwise we return the class property.
183  !PD->isClassProperty()) ||
185  PD->isClassProperty()) ||
187  !PD->isClassProperty()))
188  return PD;
189 
190  if (PD->isClassProperty())
191  classProp = PD;
192  }
193 
195  // We can't find the instance property, return the class property.
196  return classProp;
197 
198  return nullptr;
199 }
200 
203  SmallString<128> ivarName;
204  {
205  llvm::raw_svector_ostream os(ivarName);
206  os << '_' << getIdentifier()->getName();
207  }
208  return &Ctx.Idents.get(ivarName.str());
209 }
210 
211 /// FindPropertyDeclaration - Finds declaration of the property given its name
212 /// in 'PropertyId' and returns it. It returns 0, if not found.
214  const IdentifierInfo *PropertyId,
215  ObjCPropertyQueryKind QueryKind) const {
216  // Don't find properties within hidden protocol definitions.
217  if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
218  if (const ObjCProtocolDecl *Def = Proto->getDefinition())
219  if (Def->isHidden())
220  return nullptr;
221  }
222 
223  // Search the extensions of a class first; they override what's in
224  // the class itself.
225  if (const auto *ClassDecl = dyn_cast<ObjCInterfaceDecl>(this)) {
226  for (const auto *Ext : ClassDecl->visible_extensions()) {
227  if (auto *P = Ext->FindPropertyDeclaration(PropertyId, QueryKind))
228  return P;
229  }
230  }
231 
232  if (ObjCPropertyDecl *PD =
233  ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
234  QueryKind))
235  return PD;
236 
237  switch (getKind()) {
238  default:
239  break;
240  case Decl::ObjCProtocol: {
241  const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
242  for (const auto *I : PID->protocols())
243  if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
244  QueryKind))
245  return P;
246  break;
247  }
248  case Decl::ObjCInterface: {
249  const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
250  // Look through categories (but not extensions; they were handled above).
251  for (const auto *Cat : OID->visible_categories()) {
252  if (!Cat->IsClassExtension())
253  if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(
254  PropertyId, QueryKind))
255  return P;
256  }
257 
258  // Look through protocols.
259  for (const auto *I : OID->all_referenced_protocols())
260  if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
261  QueryKind))
262  return P;
263 
264  // Finally, check the super class.
265  if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
266  return superClass->FindPropertyDeclaration(PropertyId, QueryKind);
267  break;
268  }
269  case Decl::ObjCCategory: {
270  const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
271  // Look through protocols.
272  if (!OCD->IsClassExtension())
273  for (const auto *I : OCD->protocols())
274  if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
275  QueryKind))
276  return P;
277  break;
278  }
279  }
280  return nullptr;
281 }
282 
283 void ObjCInterfaceDecl::anchor() { }
284 
286  // If this particular declaration has a type parameter list, return it.
287  if (ObjCTypeParamList *written = getTypeParamListAsWritten())
288  return written;
289 
290  // If there is a definition, return its type parameter list.
291  if (const ObjCInterfaceDecl *def = getDefinition())
292  return def->getTypeParamListAsWritten();
293 
294  // Otherwise, look at previous declarations to determine whether any
295  // of them has a type parameter list, skipping over those
296  // declarations that do not.
297  for (auto decl = getMostRecentDecl(); decl; decl = decl->getPreviousDecl()) {
298  if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten())
299  return written;
300  }
301 
302  return nullptr;
303 }
304 
306  TypeParamList = TPL;
307  if (!TPL)
308  return;
309  // Set the declaration context of each of the type parameters.
310  for (auto typeParam : *TypeParamList)
311  typeParam->setDeclContext(this);
312 }
313 
315  // FIXME: Should make sure no callers ever do this.
316  if (!hasDefinition())
317  return nullptr;
318 
319  if (data().ExternallyCompleted)
320  LoadExternalDefinition();
321 
322  if (const ObjCObjectType *superType = getSuperClassType()) {
323  if (ObjCInterfaceDecl *superDecl = superType->getInterface()) {
324  if (ObjCInterfaceDecl *superDef = superDecl->getDefinition())
325  return superDef;
326 
327  return superDecl;
328  }
329  }
330 
331  return nullptr;
332 }
333 
335  if (TypeSourceInfo *superTInfo = getSuperClassTInfo())
336  return superTInfo->getTypeLoc().getLocStart();
337 
338  return SourceLocation();
339 }
340 
341 /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
342 /// with name 'PropertyId' in the primary class; including those in protocols
343 /// (direct or indirect) used by the primary class.
344 ///
347  IdentifierInfo *PropertyId,
348  ObjCPropertyQueryKind QueryKind) const {
349  // FIXME: Should make sure no callers ever do this.
350  if (!hasDefinition())
351  return nullptr;
352 
353  if (data().ExternallyCompleted)
354  LoadExternalDefinition();
355 
356  if (ObjCPropertyDecl *PD =
357  ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
358  QueryKind))
359  return PD;
360 
361  // Look through protocols.
362  for (const auto *I : all_referenced_protocols())
363  if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId,
364  QueryKind))
365  return P;
366 
367  return nullptr;
368 }
369 
371  PropertyDeclOrder &PO) const {
372  for (auto *Prop : properties()) {
373  PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
374  PO.push_back(Prop);
375  }
376  for (const auto *Ext : known_extensions()) {
377  const ObjCCategoryDecl *ClassExt = Ext;
378  for (auto *Prop : ClassExt->properties()) {
379  PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
380  PO.push_back(Prop);
381  }
382  }
383  for (const auto *PI : all_referenced_protocols())
384  PI->collectPropertiesToImplement(PM, PO);
385  // Note, the properties declared only in class extensions are still copied
386  // into the main @interface's property list, and therefore we don't
387  // explicitly, have to search class extension properties.
388 }
389 
391  const ObjCInterfaceDecl *Class = this;
392  while (Class) {
393  if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
394  return true;
395  Class = Class->getSuperClass();
396  }
397  return false;
398 }
399 
401  const ObjCInterfaceDecl *Class = this;
402  while (Class) {
403  if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
404  return Class;
405  Class = Class->getSuperClass();
406  }
407  return nullptr;
408 }
409 
411  ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
412  ASTContext &C)
413 {
414  if (data().ExternallyCompleted)
415  LoadExternalDefinition();
416 
417  if (data().AllReferencedProtocols.empty() &&
418  data().ReferencedProtocols.empty()) {
419  data().AllReferencedProtocols.set(ExtList, ExtNum, C);
420  return;
421  }
422 
423  // Check for duplicate protocol in class's protocol list.
424  // This is O(n*m). But it is extremely rare and number of protocols in
425  // class or its extension are very few.
427  for (unsigned i = 0; i < ExtNum; i++) {
428  bool protocolExists = false;
429  ObjCProtocolDecl *ProtoInExtension = ExtList[i];
430  for (auto *Proto : all_referenced_protocols()) {
431  if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
432  protocolExists = true;
433  break;
434  }
435  }
436  // Do we want to warn on a protocol in extension class which
437  // already exist in the class? Probably not.
438  if (!protocolExists)
439  ProtocolRefs.push_back(ProtoInExtension);
440  }
441 
442  if (ProtocolRefs.empty())
443  return;
444 
445  // Merge ProtocolRefs into class's protocol list;
446  ProtocolRefs.append(all_referenced_protocol_begin(),
447  all_referenced_protocol_end());
448 
449  data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C);
450 }
451 
452 const ObjCInterfaceDecl *
453 ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const {
454  const ObjCInterfaceDecl *IFace = this;
455  while (IFace) {
456  if (IFace->hasDesignatedInitializers())
457  return IFace;
458  if (!IFace->inheritsDesignatedInitializers())
459  break;
460  IFace = IFace->getSuperClass();
461  }
462  return nullptr;
463 }
464 
466  for (const auto *MD : D->instance_methods()) {
467  if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
468  return true;
469  }
470  for (const auto *Ext : D->visible_extensions()) {
471  for (const auto *MD : Ext->instance_methods()) {
472  if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
473  return true;
474  }
475  }
476  if (const auto *ImplD = D->getImplementation()) {
477  for (const auto *MD : ImplD->instance_methods()) {
478  if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
479  return true;
480  }
481  }
482  return false;
483 }
484 
485 bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
486  switch (data().InheritedDesignatedInitializers) {
487  case DefinitionData::IDI_Inherited:
488  return true;
489  case DefinitionData::IDI_NotInherited:
490  return false;
491  case DefinitionData::IDI_Unknown: {
492  // If the class introduced initializers we conservatively assume that we
493  // don't know if any of them is a designated initializer to avoid possible
494  // misleading warnings.
495  if (isIntroducingInitializers(this)) {
496  data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited;
497  } else {
498  if (auto SuperD = getSuperClass()) {
499  data().InheritedDesignatedInitializers =
500  SuperD->declaresOrInheritsDesignatedInitializers() ?
501  DefinitionData::IDI_Inherited :
502  DefinitionData::IDI_NotInherited;
503  } else {
504  data().InheritedDesignatedInitializers =
505  DefinitionData::IDI_NotInherited;
506  }
507  }
508  assert(data().InheritedDesignatedInitializers
509  != DefinitionData::IDI_Unknown);
510  return data().InheritedDesignatedInitializers ==
511  DefinitionData::IDI_Inherited;
512  }
513  }
514 
515  llvm_unreachable("unexpected InheritedDesignatedInitializers value");
516 }
517 
520  // Check for a complete definition and recover if not so.
521  if (!isThisDeclarationADefinition())
522  return;
523  if (data().ExternallyCompleted)
524  LoadExternalDefinition();
525 
526  const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
527  if (!IFace)
528  return;
529 
530  for (const auto *MD : IFace->instance_methods())
531  if (MD->isThisDeclarationADesignatedInitializer())
532  Methods.push_back(MD);
533  for (const auto *Ext : IFace->visible_extensions()) {
534  for (const auto *MD : Ext->instance_methods())
535  if (MD->isThisDeclarationADesignatedInitializer())
536  Methods.push_back(MD);
537  }
538 }
539 
541  const ObjCMethodDecl **InitMethod) const {
542  bool HasCompleteDef = isThisDeclarationADefinition();
543  // During deserialization the data record for the ObjCInterfaceDecl could
544  // be made invariant by reusing the canonical decl. Take this into account
545  // when checking for the complete definition.
546  if (!HasCompleteDef && getCanonicalDecl()->hasDefinition() &&
548  HasCompleteDef = true;
549 
550  // Check for a complete definition and recover if not so.
551  if (!HasCompleteDef)
552  return false;
553 
554  if (data().ExternallyCompleted)
555  LoadExternalDefinition();
556 
557  const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers();
558  if (!IFace)
559  return false;
560 
561  if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) {
562  if (MD->isThisDeclarationADesignatedInitializer()) {
563  if (InitMethod)
564  *InitMethod = MD;
565  return true;
566  }
567  }
568  for (const auto *Ext : IFace->visible_extensions()) {
569  if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) {
570  if (MD->isThisDeclarationADesignatedInitializer()) {
571  if (InitMethod)
572  *InitMethod = MD;
573  return true;
574  }
575  }
576  }
577  return false;
578 }
579 
580 void ObjCInterfaceDecl::allocateDefinitionData() {
581  assert(!hasDefinition() && "ObjC class already has a definition");
582  Data.setPointer(new (getASTContext()) DefinitionData());
583  Data.getPointer()->Definition = this;
584 
585  // Make the type point at the definition, now that we have one.
586  if (TypeForDecl)
587  cast<ObjCInterfaceType>(TypeForDecl)->Decl = this;
588 }
589 
591  allocateDefinitionData();
592 
593  // Update all of the declarations with a pointer to the definition.
594  for (auto RD : redecls()) {
595  if (RD != this)
596  RD->Data = Data;
597  }
598 }
599 
601  ObjCInterfaceDecl *&clsDeclared) {
602  // FIXME: Should make sure no callers ever do this.
603  if (!hasDefinition())
604  return nullptr;
605 
606  if (data().ExternallyCompleted)
607  LoadExternalDefinition();
608 
609  ObjCInterfaceDecl* ClassDecl = this;
610  while (ClassDecl != nullptr) {
611  if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
612  clsDeclared = ClassDecl;
613  return I;
614  }
615 
616  for (const auto *Ext : ClassDecl->visible_extensions()) {
617  if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) {
618  clsDeclared = ClassDecl;
619  return I;
620  }
621  }
622 
623  ClassDecl = ClassDecl->getSuperClass();
624  }
625  return nullptr;
626 }
627 
628 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
629 /// class whose name is passed as argument. If it is not one of the super classes
630 /// the it returns NULL.
632  const IdentifierInfo*ICName) {
633  // FIXME: Should make sure no callers ever do this.
634  if (!hasDefinition())
635  return nullptr;
636 
637  if (data().ExternallyCompleted)
638  LoadExternalDefinition();
639 
640  ObjCInterfaceDecl* ClassDecl = this;
641  while (ClassDecl != nullptr) {
642  if (ClassDecl->getIdentifier() == ICName)
643  return ClassDecl;
644  ClassDecl = ClassDecl->getSuperClass();
645  }
646  return nullptr;
647 }
648 
651  for (auto *P : all_referenced_protocols())
652  if (P->lookupProtocolNamed(Name))
653  return P;
654  ObjCInterfaceDecl *SuperClass = getSuperClass();
655  return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr;
656 }
657 
658 /// lookupMethod - This method returns an instance/class method by looking in
659 /// the class, its categories, and its super classes (using a linear search).
660 /// When argument category "C" is specified, any implicit method found
661 /// in this category is ignored.
663  bool isInstance,
664  bool shallowCategoryLookup,
665  bool followSuper,
666  const ObjCCategoryDecl *C) const
667 {
668  // FIXME: Should make sure no callers ever do this.
669  if (!hasDefinition())
670  return nullptr;
671 
672  const ObjCInterfaceDecl* ClassDecl = this;
673  ObjCMethodDecl *MethodDecl = nullptr;
674 
675  if (data().ExternallyCompleted)
676  LoadExternalDefinition();
677 
678  while (ClassDecl) {
679  // 1. Look through primary class.
680  if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
681  return MethodDecl;
682 
683  // 2. Didn't find one yet - now look through categories.
684  for (const auto *Cat : ClassDecl->visible_categories())
685  if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
686  if (C != Cat || !MethodDecl->isImplicit())
687  return MethodDecl;
688 
689  // 3. Didn't find one yet - look through primary class's protocols.
690  for (const auto *I : ClassDecl->protocols())
691  if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
692  return MethodDecl;
693 
694  // 4. Didn't find one yet - now look through categories' protocols
695  if (!shallowCategoryLookup)
696  for (const auto *Cat : ClassDecl->visible_categories()) {
697  // Didn't find one yet - look through protocols.
698  const ObjCList<ObjCProtocolDecl> &Protocols =
699  Cat->getReferencedProtocols();
700  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
701  E = Protocols.end(); I != E; ++I)
702  if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
703  if (C != Cat || !MethodDecl->isImplicit())
704  return MethodDecl;
705  }
706 
707 
708  if (!followSuper)
709  return nullptr;
710 
711  // 5. Get to the super class (if any).
712  ClassDecl = ClassDecl->getSuperClass();
713  }
714  return nullptr;
715 }
716 
717 // Will search "local" class/category implementations for a method decl.
718 // If failed, then we search in class's root for an instance method.
719 // Returns 0 if no method is found.
721  const Selector &Sel,
722  bool Instance) const {
723  // FIXME: Should make sure no callers ever do this.
724  if (!hasDefinition())
725  return nullptr;
726 
727  if (data().ExternallyCompleted)
728  LoadExternalDefinition();
729 
730  ObjCMethodDecl *Method = nullptr;
731  if (ObjCImplementationDecl *ImpDecl = getImplementation())
732  Method = Instance ? ImpDecl->getInstanceMethod(Sel)
733  : ImpDecl->getClassMethod(Sel);
734 
735  // Look through local category implementations associated with the class.
736  if (!Method)
737  Method = getCategoryMethod(Sel, Instance);
738 
739  // Before we give up, check if the selector is an instance method.
740  // But only in the root. This matches gcc's behavior and what the
741  // runtime expects.
742  if (!Instance && !Method && !getSuperClass()) {
743  Method = lookupInstanceMethod(Sel);
744  // Look through local category implementations associated
745  // with the root class.
746  if (!Method)
747  Method = lookupPrivateMethod(Sel, true);
748  }
749 
750  if (!Method && getSuperClass())
751  return getSuperClass()->lookupPrivateMethod(Sel, Instance);
752  return Method;
753 }
754 
755 //===----------------------------------------------------------------------===//
756 // ObjCMethodDecl
757 //===----------------------------------------------------------------------===//
758 
760  ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
761  Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
762  DeclContext *contextDecl, bool isInstance, bool isVariadic,
763  bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined,
764  ImplementationControl impControl, bool HasRelatedResultType) {
765  return new (C, contextDecl) ObjCMethodDecl(
766  beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance,
767  isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined,
768  impControl, HasRelatedResultType);
769 }
770 
772  return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
773  Selector(), QualType(), nullptr, nullptr);
774 }
775 
777  return getMethodFamily() == OMF_init &&
778  hasAttr<ObjCDesignatedInitializerAttr>();
779 }
780 
782  const ObjCMethodDecl **InitMethod) const {
783  if (getMethodFamily() != OMF_init)
784  return false;
785  const DeclContext *DC = getDeclContext();
786  if (isa<ObjCProtocolDecl>(DC))
787  return false;
788  if (const ObjCInterfaceDecl *ID = getClassInterface())
789  return ID->isDesignatedInitializer(getSelector(), InitMethod);
790  return false;
791 }
792 
794  return Body.get(getASTContext().getExternalSource());
795 }
796 
798  assert(PrevMethod);
799  getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
800  IsRedeclaration = true;
801  PrevMethod->HasRedeclaration = true;
802 }
803 
804 void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
805  ArrayRef<ParmVarDecl*> Params,
806  ArrayRef<SourceLocation> SelLocs) {
807  ParamsAndSelLocs = nullptr;
808  NumParams = Params.size();
809  if (Params.empty() && SelLocs.empty())
810  return;
811 
812  static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation),
813  "Alignment not sufficient for SourceLocation");
814 
815  unsigned Size = sizeof(ParmVarDecl *) * NumParams +
816  sizeof(SourceLocation) * SelLocs.size();
817  ParamsAndSelLocs = C.Allocate(Size);
818  std::copy(Params.begin(), Params.end(), getParams());
819  std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
820 }
821 
823  SmallVectorImpl<SourceLocation> &SelLocs) const {
824  for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
825  SelLocs.push_back(getSelectorLoc(i));
826 }
827 
829  ArrayRef<ParmVarDecl*> Params,
830  ArrayRef<SourceLocation> SelLocs) {
831  assert((!SelLocs.empty() || isImplicit()) &&
832  "No selector locs for non-implicit method");
833  if (isImplicit())
834  return setParamsAndSelLocs(C, Params, llvm::None);
835 
836  SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
837  DeclEndLoc);
838  if (SelLocsKind != SelLoc_NonStandard)
839  return setParamsAndSelLocs(C, Params, llvm::None);
840 
841  setParamsAndSelLocs(C, Params, SelLocs);
842 }
843 
844 /// \brief A definition will return its interface declaration.
845 /// An interface declaration will return its definition.
846 /// Otherwise it will return itself.
847 ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
848  ASTContext &Ctx = getASTContext();
849  ObjCMethodDecl *Redecl = nullptr;
850  if (HasRedeclaration)
851  Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
852  if (Redecl)
853  return Redecl;
854 
855  Decl *CtxD = cast<Decl>(getDeclContext());
856 
857  if (!CtxD->isInvalidDecl()) {
858  if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
859  if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
860  if (!ImplD->isInvalidDecl())
861  Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
862 
863  } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
864  if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
865  if (!ImplD->isInvalidDecl())
866  Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
867 
868  } else if (ObjCImplementationDecl *ImplD =
869  dyn_cast<ObjCImplementationDecl>(CtxD)) {
870  if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
871  if (!IFD->isInvalidDecl())
872  Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
873 
874  } else if (ObjCCategoryImplDecl *CImplD =
875  dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
876  if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
877  if (!CatD->isInvalidDecl())
878  Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
879  }
880  }
881 
882  // Ensure that the discovered method redeclaration has a valid declaration
883  // context. Used to prevent infinite loops when iterating redeclarations in
884  // a partially invalid AST.
885  if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl())
886  Redecl = nullptr;
887 
888  if (!Redecl && isRedeclaration()) {
889  // This is the last redeclaration, go back to the first method.
890  return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
891  isInstanceMethod());
892  }
893 
894  return Redecl ? Redecl : this;
895 }
896 
898  Decl *CtxD = cast<Decl>(getDeclContext());
899 
900  if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
901  if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
902  if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
903  isInstanceMethod()))
904  return MD;
905 
906  } else if (ObjCCategoryImplDecl *CImplD =
907  dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
908  if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
909  if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
910  isInstanceMethod()))
911  return MD;
912  }
913 
914  if (isRedeclaration()) {
915  // It is possible that we have not done deserializing the ObjCMethod yet.
916  ObjCMethodDecl *MD =
917  cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
918  isInstanceMethod());
919  return MD ? MD : this;
920  }
921 
922  return this;
923 }
924 
926  if (Stmt *Body = getBody())
927  return Body->getLocEnd();
928  return DeclEndLoc;
929 }
930 
932  ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
933  if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
934  return family;
935 
936  // Check for an explicit attribute.
937  if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
938  // The unfortunate necessity of mapping between enums here is due
939  // to the attributes framework.
940  switch (attr->getFamily()) {
941  case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
942  case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
943  case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
944  case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
946  case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
947  }
948  Family = static_cast<unsigned>(family);
949  return family;
950  }
951 
952  family = getSelector().getMethodFamily();
953  switch (family) {
954  case OMF_None: break;
955 
956  // init only has a conventional meaning for an instance method, and
957  // it has to return an object.
958  case OMF_init:
959  if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
960  family = OMF_None;
961  break;
962 
963  // alloc/copy/new have a conventional meaning for both class and
964  // instance methods, but they require an object return.
965  case OMF_alloc:
966  case OMF_copy:
967  case OMF_mutableCopy:
968  case OMF_new:
969  if (!getReturnType()->isObjCObjectPointerType())
970  family = OMF_None;
971  break;
972 
973  // These selectors have a conventional meaning only for instance methods.
974  case OMF_dealloc:
975  case OMF_finalize:
976  case OMF_retain:
977  case OMF_release:
978  case OMF_autorelease:
979  case OMF_retainCount:
980  case OMF_self:
981  if (!isInstanceMethod())
982  family = OMF_None;
983  break;
984 
985  case OMF_initialize:
986  if (isInstanceMethod() || !getReturnType()->isVoidType())
987  family = OMF_None;
988  break;
989 
990  case OMF_performSelector:
991  if (!isInstanceMethod() || !getReturnType()->isObjCIdType())
992  family = OMF_None;
993  else {
994  unsigned noParams = param_size();
995  if (noParams < 1 || noParams > 3)
996  family = OMF_None;
997  else {
998  ObjCMethodDecl::param_type_iterator it = param_type_begin();
999  QualType ArgT = (*it);
1000  if (!ArgT->isObjCSelType()) {
1001  family = OMF_None;
1002  break;
1003  }
1004  while (--noParams) {
1005  it++;
1006  ArgT = (*it);
1007  if (!ArgT->isObjCIdType()) {
1008  family = OMF_None;
1009  break;
1010  }
1011  }
1012  }
1013  }
1014  break;
1015 
1016  }
1017 
1018  // Cache the result.
1019  Family = static_cast<unsigned>(family);
1020  return family;
1021 }
1022 
1024  const ObjCInterfaceDecl *OID,
1025  bool &selfIsPseudoStrong,
1026  bool &selfIsConsumed) {
1027  QualType selfTy;
1028  selfIsPseudoStrong = false;
1029  selfIsConsumed = false;
1030  if (isInstanceMethod()) {
1031  // There may be no interface context due to error in declaration
1032  // of the interface (which has been reported). Recover gracefully.
1033  if (OID) {
1034  selfTy = Context.getObjCInterfaceType(OID);
1035  selfTy = Context.getObjCObjectPointerType(selfTy);
1036  } else {
1037  selfTy = Context.getObjCIdType();
1038  }
1039  } else // we have a factory method.
1040  selfTy = Context.getObjCClassType();
1041 
1042  if (Context.getLangOpts().ObjCAutoRefCount) {
1043  if (isInstanceMethod()) {
1044  selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
1045 
1046  // 'self' is always __strong. It's actually pseudo-strong except
1047  // in init methods (or methods labeled ns_consumes_self), though.
1048  Qualifiers qs;
1050  selfTy = Context.getQualifiedType(selfTy, qs);
1051 
1052  // In addition, 'self' is const unless this is an init method.
1053  if (getMethodFamily() != OMF_init && !selfIsConsumed) {
1054  selfTy = selfTy.withConst();
1055  selfIsPseudoStrong = true;
1056  }
1057  }
1058  else {
1059  assert(isClassMethod());
1060  // 'self' is always const in class methods.
1061  selfTy = selfTy.withConst();
1062  selfIsPseudoStrong = true;
1063  }
1064  }
1065  return selfTy;
1066 }
1067 
1069  const ObjCInterfaceDecl *OID) {
1070  bool selfIsPseudoStrong, selfIsConsumed;
1071  QualType selfTy =
1072  getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed);
1073  auto *Self = ImplicitParamDecl::Create(Context, this, SourceLocation(),
1074  &Context.Idents.get("self"), selfTy,
1076  setSelfDecl(Self);
1077 
1078  if (selfIsConsumed)
1079  Self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1080 
1081  if (selfIsPseudoStrong)
1082  Self->setARCPseudoStrong(true);
1083 
1084  setCmdDecl(ImplicitParamDecl::Create(
1085  Context, this, SourceLocation(), &Context.Idents.get("_cmd"),
1087 }
1088 
1090  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
1091  return ID;
1092  if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
1093  return CD->getClassInterface();
1094  if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
1095  return IMD->getClassInterface();
1096  if (isa<ObjCProtocolDecl>(getDeclContext()))
1097  return nullptr;
1098  llvm_unreachable("unknown method context");
1099 }
1100 
1102  const auto *TSI = getReturnTypeSourceInfo();
1103  if (TSI)
1104  return TSI->getTypeLoc().getSourceRange();
1105  return SourceRange();
1106 }
1107 
1109  ASTContext &Ctx = getASTContext();
1110  return getReturnType().getNonLValueExprType(Ctx)
1111  .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
1112 }
1113 
1115  // FIXME: Handle related result types here.
1116 
1117  return getReturnType().getNonLValueExprType(getASTContext())
1118  .substObjCMemberType(receiverType, getDeclContext(),
1120 }
1121 
1123  const ObjCMethodDecl *Method,
1125  bool MovedToSuper) {
1126  if (!Container)
1127  return;
1128 
1129  // In categories look for overriden methods from protocols. A method from
1130  // category is not "overriden" since it is considered as the "same" method
1131  // (same USR) as the one from the interface.
1132  if (const ObjCCategoryDecl *
1133  Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1134  // Check whether we have a matching method at this category but only if we
1135  // are at the super class level.
1136  if (MovedToSuper)
1137  if (ObjCMethodDecl *
1138  Overridden = Container->getMethod(Method->getSelector(),
1139  Method->isInstanceMethod(),
1140  /*AllowHidden=*/true))
1141  if (Method != Overridden) {
1142  // We found an override at this category; there is no need to look
1143  // into its protocols.
1144  Methods.push_back(Overridden);
1145  return;
1146  }
1147 
1148  for (const auto *P : Category->protocols())
1149  CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1150  return;
1151  }
1152 
1153  // Check whether we have a matching method at this level.
1154  if (const ObjCMethodDecl *
1155  Overridden = Container->getMethod(Method->getSelector(),
1156  Method->isInstanceMethod(),
1157  /*AllowHidden=*/true))
1158  if (Method != Overridden) {
1159  // We found an override at this level; there is no need to look
1160  // into other protocols or categories.
1161  Methods.push_back(Overridden);
1162  return;
1163  }
1164 
1165  if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
1166  for (const auto *P : Protocol->protocols())
1167  CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1168  }
1169 
1170  if (const ObjCInterfaceDecl *
1171  Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
1172  for (const auto *P : Interface->protocols())
1173  CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1174 
1175  for (const auto *Cat : Interface->known_categories())
1176  CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper);
1177 
1178  if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1179  return CollectOverriddenMethodsRecurse(Super, Method, Methods,
1180  /*MovedToSuper=*/true);
1181  }
1182 }
1183 
1184 static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
1185  const ObjCMethodDecl *Method,
1187  CollectOverriddenMethodsRecurse(Container, Method, Methods,
1188  /*MovedToSuper=*/false);
1189 }
1190 
1193  assert(Method->isOverriding());
1194 
1195  if (const ObjCProtocolDecl *
1196  ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1197  CollectOverriddenMethods(ProtD, Method, overridden);
1198 
1199  } else if (const ObjCImplDecl *
1200  IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1201  const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1202  if (!ID)
1203  return;
1204  // Start searching for overridden methods using the method from the
1205  // interface as starting point.
1206  if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1207  Method->isInstanceMethod(),
1208  /*AllowHidden=*/true))
1209  Method = IFaceMeth;
1210  CollectOverriddenMethods(ID, Method, overridden);
1211 
1212  } else if (const ObjCCategoryDecl *
1213  CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1214  const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1215  if (!ID)
1216  return;
1217  // Start searching for overridden methods using the method from the
1218  // interface as starting point.
1219  if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1220  Method->isInstanceMethod(),
1221  /*AllowHidden=*/true))
1222  Method = IFaceMeth;
1223  CollectOverriddenMethods(ID, Method, overridden);
1224 
1225  } else {
1227  dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1228  Method, overridden);
1229  }
1230 }
1231 
1233  SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
1234  const ObjCMethodDecl *Method = this;
1235 
1236  if (Method->isRedeclaration()) {
1237  Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1238  getMethod(Method->getSelector(), Method->isInstanceMethod());
1239  }
1240 
1241  if (Method->isOverriding()) {
1242  collectOverriddenMethodsSlow(Method, Overridden);
1243  assert(!Overridden.empty() &&
1244  "ObjCMethodDecl's overriding bit is not as expected");
1245  }
1246 }
1247 
1248 const ObjCPropertyDecl *
1249 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1250  Selector Sel = getSelector();
1251  unsigned NumArgs = Sel.getNumArgs();
1252  if (NumArgs > 1)
1253  return nullptr;
1254 
1255  if (isPropertyAccessor()) {
1256  const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
1257  bool IsGetter = (NumArgs == 0);
1258  bool IsInstance = isInstanceMethod();
1259 
1260  /// Local function that attempts to find a matching property within the
1261  /// given Objective-C container.
1262  auto findMatchingProperty =
1263  [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {
1264  if (IsInstance) {
1265  for (const auto *I : Container->instance_properties()) {
1266  Selector NextSel = IsGetter ? I->getGetterName()
1267  : I->getSetterName();
1268  if (NextSel == Sel)
1269  return I;
1270  }
1271  } else {
1272  for (const auto *I : Container->class_properties()) {
1273  Selector NextSel = IsGetter ? I->getGetterName()
1274  : I->getSetterName();
1275  if (NextSel == Sel)
1276  return I;
1277  }
1278  }
1279 
1280  return nullptr;
1281  };
1282 
1283  // Look in the container we were given.
1284  if (const auto *Found = findMatchingProperty(Container))
1285  return Found;
1286 
1287  // If we're in a category or extension, look in the main class.
1288  const ObjCInterfaceDecl *ClassDecl = nullptr;
1289  if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1290  ClassDecl = Category->getClassInterface();
1291  if (const auto *Found = findMatchingProperty(ClassDecl))
1292  return Found;
1293  } else {
1294  // Determine whether the container is a class.
1295  ClassDecl = dyn_cast<ObjCInterfaceDecl>(Container);
1296  }
1297 
1298  // If we have a class, check its visible extensions.
1299  if (ClassDecl) {
1300  for (const auto *Ext : ClassDecl->visible_extensions()) {
1301  if (Ext == Container)
1302  continue;
1303 
1304  if (const auto *Found = findMatchingProperty(Ext))
1305  return Found;
1306  }
1307  }
1308 
1309  llvm_unreachable("Marked as a property accessor but no property found!");
1310  }
1311 
1312  if (!CheckOverrides)
1313  return nullptr;
1314 
1315  typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy;
1316  OverridesTy Overrides;
1317  getOverriddenMethods(Overrides);
1318  for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
1319  I != E; ++I) {
1320  if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false))
1321  return Prop;
1322  }
1323 
1324  return nullptr;
1325 }
1326 
1327 //===----------------------------------------------------------------------===//
1328 // ObjCTypeParamDecl
1329 //===----------------------------------------------------------------------===//
1330 
1331 void ObjCTypeParamDecl::anchor() { }
1332 
1334  ObjCTypeParamVariance variance,
1335  SourceLocation varianceLoc,
1336  unsigned index,
1337  SourceLocation nameLoc,
1338  IdentifierInfo *name,
1339  SourceLocation colonLoc,
1340  TypeSourceInfo *boundInfo) {
1341  auto *TPDecl =
1342  new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
1343  nameLoc, name, colonLoc, boundInfo);
1344  QualType TPType = ctx.getObjCTypeParamType(TPDecl, {});
1345  TPDecl->setTypeForDecl(TPType.getTypePtr());
1346  return TPDecl;
1347 }
1348 
1350  unsigned ID) {
1351  return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr,
1354  nullptr, SourceLocation(), nullptr);
1355 }
1356 
1358  SourceLocation startLoc = VarianceLoc;
1359  if (startLoc.isInvalid())
1360  startLoc = getLocation();
1361 
1362  if (hasExplicitBound()) {
1363  return SourceRange(startLoc,
1364  getTypeSourceInfo()->getTypeLoc().getEndLoc());
1365  }
1366 
1367  return SourceRange(startLoc);
1368 }
1369 
1370 //===----------------------------------------------------------------------===//
1371 // ObjCTypeParamList
1372 //===----------------------------------------------------------------------===//
1373 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
1374  ArrayRef<ObjCTypeParamDecl *> typeParams,
1375  SourceLocation rAngleLoc)
1376  : NumParams(typeParams.size())
1377 {
1378  Brackets.Begin = lAngleLoc.getRawEncoding();
1379  Brackets.End = rAngleLoc.getRawEncoding();
1380  std::copy(typeParams.begin(), typeParams.end(), begin());
1381 }
1382 
1383 
1385  ASTContext &ctx,
1386  SourceLocation lAngleLoc,
1387  ArrayRef<ObjCTypeParamDecl *> typeParams,
1388  SourceLocation rAngleLoc) {
1389  void *mem =
1390  ctx.Allocate(totalSizeToAlloc<ObjCTypeParamDecl *>(typeParams.size()),
1391  alignof(ObjCTypeParamList));
1392  return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc);
1393 }
1394 
1396  SmallVectorImpl<QualType> &typeArgs) const {
1397  typeArgs.reserve(size());
1398  for (auto typeParam : *this)
1399  typeArgs.push_back(typeParam->getUnderlyingType());
1400 }
1401 
1402 //===----------------------------------------------------------------------===//
1403 // ObjCInterfaceDecl
1404 //===----------------------------------------------------------------------===//
1405 
1407  DeclContext *DC,
1408  SourceLocation atLoc,
1409  IdentifierInfo *Id,
1410  ObjCTypeParamList *typeParamList,
1411  ObjCInterfaceDecl *PrevDecl,
1412  SourceLocation ClassLoc,
1413  bool isInternal){
1414  ObjCInterfaceDecl *Result = new (C, DC)
1415  ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl,
1416  isInternal);
1417  Result->Data.setInt(!C.getLangOpts().Modules);
1418  C.getObjCInterfaceType(Result, PrevDecl);
1419  return Result;
1420 }
1421 
1423  unsigned ID) {
1424  ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr,
1425  SourceLocation(),
1426  nullptr,
1427  nullptr,
1428  SourceLocation(),
1429  nullptr, false);
1430  Result->Data.setInt(!C.getLangOpts().Modules);
1431  return Result;
1432 }
1433 
1434 ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
1436  ObjCTypeParamList *typeParamList,
1437  SourceLocation CLoc,
1438  ObjCInterfaceDecl *PrevDecl,
1439  bool IsInternal)
1440  : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
1441  redeclarable_base(C), TypeForDecl(nullptr), TypeParamList(nullptr),
1442  Data() {
1443  setPreviousDecl(PrevDecl);
1444 
1445  // Copy the 'data' pointer over.
1446  if (PrevDecl)
1447  Data = PrevDecl->Data;
1448 
1449  setImplicit(IsInternal);
1450 
1451  setTypeParamList(typeParamList);
1452 }
1453 
1454 void ObjCInterfaceDecl::LoadExternalDefinition() const {
1455  assert(data().ExternallyCompleted && "Class is not externally completed");
1456  data().ExternallyCompleted = false;
1457  getASTContext().getExternalSource()->CompleteType(
1458  const_cast<ObjCInterfaceDecl *>(this));
1459 }
1460 
1462  assert(getASTContext().getExternalSource() &&
1463  "Class can't be externally completed without an external source");
1464  assert(hasDefinition() &&
1465  "Forward declarations can't be externally completed");
1466  data().ExternallyCompleted = true;
1467 }
1468 
1470  // Check for a complete definition and recover if not so.
1471  if (!isThisDeclarationADefinition())
1472  return;
1473  data().HasDesignatedInitializers = true;
1474 }
1475 
1477  // Check for a complete definition and recover if not so.
1478  if (!isThisDeclarationADefinition())
1479  return false;
1480  if (data().ExternallyCompleted)
1481  LoadExternalDefinition();
1482 
1483  return data().HasDesignatedInitializers;
1484 }
1485 
1486 StringRef
1488  if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1489  return ObjCRTName->getMetadataName();
1490 
1491  return getName();
1492 }
1493 
1494 StringRef
1496  if (ObjCInterfaceDecl *ID =
1497  const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1498  return ID->getObjCRuntimeNameAsString();
1499 
1500  return getName();
1501 }
1502 
1504  if (const ObjCInterfaceDecl *Def = getDefinition()) {
1505  if (data().ExternallyCompleted)
1506  LoadExternalDefinition();
1507 
1508  return getASTContext().getObjCImplementation(
1509  const_cast<ObjCInterfaceDecl*>(Def));
1510  }
1511 
1512  // FIXME: Should make sure no callers ever do this.
1513  return nullptr;
1514 }
1515 
1517  getASTContext().setObjCImplementation(getDefinition(), ImplD);
1518 }
1519 
1520 namespace {
1521  struct SynthesizeIvarChunk {
1522  uint64_t Size;
1523  ObjCIvarDecl *Ivar;
1524  SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
1525  : Size(size), Ivar(ivar) {}
1526  };
1527 
1528  bool operator<(const SynthesizeIvarChunk & LHS,
1529  const SynthesizeIvarChunk &RHS) {
1530  return LHS.Size < RHS.Size;
1531  }
1532 }
1533 
1534 /// all_declared_ivar_begin - return first ivar declared in this class,
1535 /// its extensions and its implementation. Lazily build the list on first
1536 /// access.
1537 ///
1538 /// Caveat: The list returned by this method reflects the current
1539 /// state of the parser. The cache will be updated for every ivar
1540 /// added by an extension or the implementation when they are
1541 /// encountered.
1542 /// See also ObjCIvarDecl::Create().
1544  // FIXME: Should make sure no callers ever do this.
1545  if (!hasDefinition())
1546  return nullptr;
1547 
1548  ObjCIvarDecl *curIvar = nullptr;
1549  if (!data().IvarList) {
1550  if (!ivar_empty()) {
1551  ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
1552  data().IvarList = *I; ++I;
1553  for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1554  curIvar->setNextIvar(*I);
1555  }
1556 
1557  for (const auto *Ext : known_extensions()) {
1558  if (!Ext->ivar_empty()) {
1560  I = Ext->ivar_begin(),
1561  E = Ext->ivar_end();
1562  if (!data().IvarList) {
1563  data().IvarList = *I; ++I;
1564  curIvar = data().IvarList;
1565  }
1566  for ( ;I != E; curIvar = *I, ++I)
1567  curIvar->setNextIvar(*I);
1568  }
1569  }
1570  data().IvarListMissingImplementation = true;
1571  }
1572 
1573  // cached and complete!
1574  if (!data().IvarListMissingImplementation)
1575  return data().IvarList;
1576 
1577  if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
1578  data().IvarListMissingImplementation = false;
1579  if (!ImplDecl->ivar_empty()) {
1581  for (auto *IV : ImplDecl->ivars()) {
1582  if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1583  layout.push_back(SynthesizeIvarChunk(
1584  IV->getASTContext().getTypeSize(IV->getType()), IV));
1585  continue;
1586  }
1587  if (!data().IvarList)
1588  data().IvarList = IV;
1589  else
1590  curIvar->setNextIvar(IV);
1591  curIvar = IV;
1592  }
1593 
1594  if (!layout.empty()) {
1595  // Order synthesized ivars by their size.
1596  std::stable_sort(layout.begin(), layout.end());
1597  unsigned Ix = 0, EIx = layout.size();
1598  if (!data().IvarList) {
1599  data().IvarList = layout[0].Ivar; Ix++;
1600  curIvar = data().IvarList;
1601  }
1602  for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
1603  curIvar->setNextIvar(layout[Ix].Ivar);
1604  }
1605  }
1606  }
1607  return data().IvarList;
1608 }
1609 
1610 /// FindCategoryDeclaration - Finds category declaration in the list of
1611 /// categories for this class and returns it. Name of the category is passed
1612 /// in 'CategoryId'. If category not found, return 0;
1613 ///
1616  // FIXME: Should make sure no callers ever do this.
1617  if (!hasDefinition())
1618  return nullptr;
1619 
1620  if (data().ExternallyCompleted)
1621  LoadExternalDefinition();
1622 
1623  for (auto *Cat : visible_categories())
1624  if (Cat->getIdentifier() == CategoryId)
1625  return Cat;
1626 
1627  return nullptr;
1628 }
1629 
1632  for (const auto *Cat : visible_categories()) {
1633  if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1634  if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1635  return MD;
1636  }
1637 
1638  return nullptr;
1639 }
1640 
1642  for (const auto *Cat : visible_categories()) {
1643  if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1644  if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1645  return MD;
1646  }
1647 
1648  return nullptr;
1649 }
1650 
1651 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1652 /// has been implemented in IDecl class, its super class or categories (if
1653 /// lookupCategory is true).
1655  bool lookupCategory,
1656  bool RHSIsQualifiedID) {
1657  if (!hasDefinition())
1658  return false;
1659 
1660  ObjCInterfaceDecl *IDecl = this;
1661  // 1st, look up the class.
1662  for (auto *PI : IDecl->protocols()){
1663  if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1664  return true;
1665  // This is dubious and is added to be compatible with gcc. In gcc, it is
1666  // also allowed assigning a protocol-qualified 'id' type to a LHS object
1667  // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1668  // object. This IMO, should be a bug.
1669  // FIXME: Treat this as an extension, and flag this as an error when GCC
1670  // extensions are not enabled.
1671  if (RHSIsQualifiedID &&
1672  getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
1673  return true;
1674  }
1675 
1676  // 2nd, look up the category.
1677  if (lookupCategory)
1678  for (const auto *Cat : visible_categories()) {
1679  for (auto *PI : Cat->protocols())
1680  if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1681  return true;
1682  }
1683 
1684  // 3rd, look up the super class(s)
1685  if (IDecl->getSuperClass())
1686  return
1687  IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1688  RHSIsQualifiedID);
1689 
1690  return false;
1691 }
1692 
1693 //===----------------------------------------------------------------------===//
1694 // ObjCIvarDecl
1695 //===----------------------------------------------------------------------===//
1696 
1697 void ObjCIvarDecl::anchor() { }
1698 
1700  SourceLocation StartLoc,
1701  SourceLocation IdLoc, IdentifierInfo *Id,
1702  QualType T, TypeSourceInfo *TInfo,
1703  AccessControl ac, Expr *BW,
1704  bool synthesized) {
1705  if (DC) {
1706  // Ivar's can only appear in interfaces, implementations (via synthesized
1707  // properties), and class extensions (via direct declaration, or synthesized
1708  // properties).
1709  //
1710  // FIXME: This should really be asserting this:
1711  // (isa<ObjCCategoryDecl>(DC) &&
1712  // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1713  // but unfortunately we sometimes place ivars into non-class extension
1714  // categories on error. This breaks an AST invariant, and should not be
1715  // fixed.
1716  assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
1717  isa<ObjCCategoryDecl>(DC)) &&
1718  "Invalid ivar decl context!");
1719  // Once a new ivar is created in any of class/class-extension/implementation
1720  // decl contexts, the previously built IvarList must be rebuilt.
1721  ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1722  if (!ID) {
1723  if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
1724  ID = IM->getClassInterface();
1725  else
1726  ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1727  }
1728  ID->setIvarList(nullptr);
1729  }
1730 
1731  return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
1732  synthesized);
1733 }
1734 
1736  return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(),
1737  nullptr, QualType(), nullptr,
1738  ObjCIvarDecl::None, nullptr, false);
1739 }
1740 
1742  const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
1743 
1744  switch (DC->getKind()) {
1745  default:
1746  case ObjCCategoryImpl:
1747  case ObjCProtocol:
1748  llvm_unreachable("invalid ivar container!");
1749 
1750  // Ivars can only appear in class extension categories.
1751  case ObjCCategory: {
1752  const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
1753  assert(CD->IsClassExtension() && "invalid container for ivar!");
1754  return CD->getClassInterface();
1755  }
1756 
1757  case ObjCImplementation:
1758  return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1759 
1760  case ObjCInterface:
1761  return cast<ObjCInterfaceDecl>(DC);
1762  }
1763 }
1764 
1766  return getType().substObjCMemberType(objectType, getDeclContext(),
1768 }
1769 
1770 //===----------------------------------------------------------------------===//
1771 // ObjCAtDefsFieldDecl
1772 //===----------------------------------------------------------------------===//
1773 
1774 void ObjCAtDefsFieldDecl::anchor() { }
1775 
1778  SourceLocation StartLoc, SourceLocation IdLoc,
1779  IdentifierInfo *Id, QualType T, Expr *BW) {
1780  return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
1781 }
1782 
1784  unsigned ID) {
1785  return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(),
1786  SourceLocation(), nullptr, QualType(),
1787  nullptr);
1788 }
1789 
1790 //===----------------------------------------------------------------------===//
1791 // ObjCProtocolDecl
1792 //===----------------------------------------------------------------------===//
1793 
1794 void ObjCProtocolDecl::anchor() { }
1795 
1796 ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
1797  IdentifierInfo *Id, SourceLocation nameLoc,
1798  SourceLocation atStartLoc,
1799  ObjCProtocolDecl *PrevDecl)
1800  : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
1801  redeclarable_base(C), Data() {
1802  setPreviousDecl(PrevDecl);
1803  if (PrevDecl)
1804  Data = PrevDecl->Data;
1805 }
1806 
1808  IdentifierInfo *Id,
1809  SourceLocation nameLoc,
1810  SourceLocation atStartLoc,
1811  ObjCProtocolDecl *PrevDecl) {
1813  new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl);
1814  Result->Data.setInt(!C.getLangOpts().Modules);
1815  return Result;
1816 }
1817 
1819  unsigned ID) {
1821  new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(),
1822  SourceLocation(), nullptr);
1823  Result->Data.setInt(!C.getLangOpts().Modules);
1824  return Result;
1825 }
1826 
1828  ObjCProtocolDecl *PDecl = this;
1829 
1830  if (Name == getIdentifier())
1831  return PDecl;
1832 
1833  for (auto *I : protocols())
1834  if ((PDecl = I->lookupProtocolNamed(Name)))
1835  return PDecl;
1836 
1837  return nullptr;
1838 }
1839 
1840 // lookupMethod - Lookup a instance/class method in the protocol and protocols
1841 // it inherited.
1843  bool isInstance) const {
1844  ObjCMethodDecl *MethodDecl = nullptr;
1845 
1846  // If there is no definition or the definition is hidden, we don't find
1847  // anything.
1848  const ObjCProtocolDecl *Def = getDefinition();
1849  if (!Def || Def->isHidden())
1850  return nullptr;
1851 
1852  if ((MethodDecl = getMethod(Sel, isInstance)))
1853  return MethodDecl;
1854 
1855  for (const auto *I : protocols())
1856  if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
1857  return MethodDecl;
1858  return nullptr;
1859 }
1860 
1861 void ObjCProtocolDecl::allocateDefinitionData() {
1862  assert(!Data.getPointer() && "Protocol already has a definition!");
1863  Data.setPointer(new (getASTContext()) DefinitionData);
1864  Data.getPointer()->Definition = this;
1865 }
1866 
1868  allocateDefinitionData();
1869 
1870  // Update all of the declarations with a pointer to the definition.
1871  for (auto RD : redecls())
1872  RD->Data = this->Data;
1873 }
1874 
1876  PropertyDeclOrder &PO) const {
1877 
1878  if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1879  for (auto *Prop : PDecl->properties()) {
1880  // Insert into PM if not there already.
1881  PM.insert(std::make_pair(
1882  std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()),
1883  Prop));
1884  PO.push_back(Prop);
1885  }
1886  // Scan through protocol's protocols.
1887  for (const auto *PI : PDecl->protocols())
1888  PI->collectPropertiesToImplement(PM, PO);
1889  }
1890 }
1891 
1894  PropertyDeclOrder &PO) const {
1895  if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1896  if (!PS.insert(PDecl).second)
1897  return;
1898  for (auto *Prop : PDecl->properties()) {
1899  if (Prop == Property)
1900  continue;
1901  if (Prop->getIdentifier() == Property->getIdentifier()) {
1902  PO.push_back(Prop);
1903  return;
1904  }
1905  }
1906  // Scan through protocol's protocols which did not have a matching property.
1907  for (const auto *PI : PDecl->protocols())
1908  PI->collectInheritedProtocolProperties(Property, PS, PO);
1909  }
1910 }
1911 
1912 StringRef
1914  if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1915  return ObjCRTName->getMetadataName();
1916 
1917  return getName();
1918 }
1919 
1920 //===----------------------------------------------------------------------===//
1921 // ObjCCategoryDecl
1922 //===----------------------------------------------------------------------===//
1923 
1924 void ObjCCategoryDecl::anchor() { }
1925 
1926 ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1927  SourceLocation ClassNameLoc,
1928  SourceLocation CategoryNameLoc,
1929  IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1930  ObjCTypeParamList *typeParamList,
1931  SourceLocation IvarLBraceLoc,
1932  SourceLocation IvarRBraceLoc)
1933  : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1934  ClassInterface(IDecl), TypeParamList(nullptr),
1935  NextClassCategory(nullptr), CategoryNameLoc(CategoryNameLoc),
1936  IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc)
1937 {
1938  setTypeParamList(typeParamList);
1939 }
1940 
1942  SourceLocation AtLoc,
1943  SourceLocation ClassNameLoc,
1944  SourceLocation CategoryNameLoc,
1945  IdentifierInfo *Id,
1946  ObjCInterfaceDecl *IDecl,
1947  ObjCTypeParamList *typeParamList,
1948  SourceLocation IvarLBraceLoc,
1949  SourceLocation IvarRBraceLoc) {
1950  ObjCCategoryDecl *CatDecl =
1951  new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
1952  IDecl, typeParamList, IvarLBraceLoc,
1953  IvarRBraceLoc);
1954  if (IDecl) {
1955  // Link this category into its class's category list.
1956  CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
1957  if (IDecl->hasDefinition()) {
1958  IDecl->setCategoryListRaw(CatDecl);
1960  L->AddedObjCCategoryToInterface(CatDecl, IDecl);
1961  }
1962  }
1963 
1964  return CatDecl;
1965 }
1966 
1968  unsigned ID) {
1969  return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(),
1971  nullptr, nullptr, nullptr);
1972 }
1973 
1975  return getASTContext().getObjCImplementation(
1976  const_cast<ObjCCategoryDecl*>(this));
1977 }
1978 
1980  getASTContext().setObjCImplementation(this, ImplD);
1981 }
1982 
1984  TypeParamList = TPL;
1985  if (!TPL)
1986  return;
1987  // Set the declaration context of each of the type parameters.
1988  for (auto typeParam : *TypeParamList)
1989  typeParam->setDeclContext(this);
1990 }
1991 
1992 
1993 //===----------------------------------------------------------------------===//
1994 // ObjCCategoryImplDecl
1995 //===----------------------------------------------------------------------===//
1996 
1997 void ObjCCategoryImplDecl::anchor() { }
1998 
2001  IdentifierInfo *Id,
2002  ObjCInterfaceDecl *ClassInterface,
2003  SourceLocation nameLoc,
2004  SourceLocation atStartLoc,
2005  SourceLocation CategoryNameLoc) {
2006  if (ClassInterface && ClassInterface->hasDefinition())
2007  ClassInterface = ClassInterface->getDefinition();
2008  return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
2009  atStartLoc, CategoryNameLoc);
2010 }
2011 
2013  unsigned ID) {
2014  return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr,
2016  SourceLocation());
2017 }
2018 
2020  // The class interface might be NULL if we are working with invalid code.
2021  if (const ObjCInterfaceDecl *ID = getClassInterface())
2022  return ID->FindCategoryDeclaration(getIdentifier());
2023  return nullptr;
2024 }
2025 
2026 
2027 void ObjCImplDecl::anchor() { }
2028 
2030  // FIXME: The context should be correct before we get here.
2031  property->setLexicalDeclContext(this);
2032  addDecl(property);
2033 }
2034 
2036  ASTContext &Ctx = getASTContext();
2037 
2038  if (ObjCImplementationDecl *ImplD
2039  = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
2040  if (IFace)
2041  Ctx.setObjCImplementation(IFace, ImplD);
2042 
2043  } else if (ObjCCategoryImplDecl *ImplD =
2044  dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
2046  Ctx.setObjCImplementation(CD, ImplD);
2047  }
2048 
2049  ClassInterface = IFace;
2050 }
2051 
2052 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
2053 /// properties implemented in this \@implementation block and returns
2054 /// the implemented property that uses it.
2055 ///
2058  for (auto *PID : property_impls())
2059  if (PID->getPropertyIvarDecl() &&
2060  PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
2061  return PID;
2062  return nullptr;
2063 }
2064 
2065 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
2066 /// added to the list of those properties \@synthesized/\@dynamic in this
2067 /// category \@implementation block.
2068 ///
2071  ObjCPropertyQueryKind QueryKind) const {
2072  ObjCPropertyImplDecl *ClassPropImpl = nullptr;
2073  for (auto *PID : property_impls())
2074  // If queryKind is unknown, we return the instance property if one
2075  // exists; otherwise we return the class property.
2076  if (PID->getPropertyDecl()->getIdentifier() == Id) {
2078  !PID->getPropertyDecl()->isClassProperty()) ||
2080  PID->getPropertyDecl()->isClassProperty()) ||
2082  !PID->getPropertyDecl()->isClassProperty()))
2083  return PID;
2084 
2085  if (PID->getPropertyDecl()->isClassProperty())
2086  ClassPropImpl = PID;
2087  }
2088 
2090  // We can't find the instance property, return the class property.
2091  return ClassPropImpl;
2092 
2093  return nullptr;
2094 }
2095 
2096 raw_ostream &clang::operator<<(raw_ostream &OS,
2097  const ObjCCategoryImplDecl &CID) {
2098  OS << CID.getName();
2099  return OS;
2100 }
2101 
2102 //===----------------------------------------------------------------------===//
2103 // ObjCImplementationDecl
2104 //===----------------------------------------------------------------------===//
2105 
2106 void ObjCImplementationDecl::anchor() { }
2107 
2110  ObjCInterfaceDecl *ClassInterface,
2111  ObjCInterfaceDecl *SuperDecl,
2112  SourceLocation nameLoc,
2113  SourceLocation atStartLoc,
2114  SourceLocation superLoc,
2115  SourceLocation IvarLBraceLoc,
2116  SourceLocation IvarRBraceLoc) {
2117  if (ClassInterface && ClassInterface->hasDefinition())
2118  ClassInterface = ClassInterface->getDefinition();
2119  return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
2120  nameLoc, atStartLoc, superLoc,
2121  IvarLBraceLoc, IvarRBraceLoc);
2122 }
2123 
2126  return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr,
2128 }
2129 
2131  CXXCtorInitializer ** initializers,
2132  unsigned numInitializers) {
2133  if (numInitializers > 0) {
2134  NumIvarInitializers = numInitializers;
2135  CXXCtorInitializer **ivarInitializers =
2136  new (C) CXXCtorInitializer*[NumIvarInitializers];
2137  memcpy(ivarInitializers, initializers,
2138  numInitializers * sizeof(CXXCtorInitializer*));
2139  IvarInitializers = ivarInitializers;
2140  }
2141 }
2142 
2145  return IvarInitializers.get(getASTContext().getExternalSource());
2146 }
2147 
2148 raw_ostream &clang::operator<<(raw_ostream &OS,
2149  const ObjCImplementationDecl &ID) {
2150  OS << ID.getName();
2151  return OS;
2152 }
2153 
2154 //===----------------------------------------------------------------------===//
2155 // ObjCCompatibleAliasDecl
2156 //===----------------------------------------------------------------------===//
2157 
2158 void ObjCCompatibleAliasDecl::anchor() { }
2159 
2162  SourceLocation L,
2163  IdentifierInfo *Id,
2164  ObjCInterfaceDecl* AliasedClass) {
2165  return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
2166 }
2167 
2170  return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(),
2171  nullptr, nullptr);
2172 }
2173 
2174 //===----------------------------------------------------------------------===//
2175 // ObjCPropertyDecl
2176 //===----------------------------------------------------------------------===//
2177 
2178 void ObjCPropertyDecl::anchor() { }
2179 
2181  SourceLocation L,
2182  IdentifierInfo *Id,
2183  SourceLocation AtLoc,
2184  SourceLocation LParenLoc,
2185  QualType T,
2186  TypeSourceInfo *TSI,
2187  PropertyControl propControl) {
2188  return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI,
2189  propControl);
2190 }
2191 
2193  unsigned ID) {
2194  return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr,
2196  QualType(), nullptr, None);
2197 }
2198 
2200  return DeclType.substObjCMemberType(objectType, getDeclContext(),
2202 }
2203 
2204 //===----------------------------------------------------------------------===//
2205 // ObjCPropertyImplDecl
2206 //===----------------------------------------------------------------------===//
2207 
2209  DeclContext *DC,
2210  SourceLocation atLoc,
2211  SourceLocation L,
2212  ObjCPropertyDecl *property,
2213  Kind PK,
2214  ObjCIvarDecl *ivar,
2215  SourceLocation ivarLoc) {
2216  return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
2217  ivarLoc);
2218 }
2219 
2221  unsigned ID) {
2222  return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(),
2223  SourceLocation(), nullptr, Dynamic,
2224  nullptr, SourceLocation());
2225 }
2226 
2228  SourceLocation EndLoc = getLocation();
2229  if (IvarLoc.isValid())
2230  EndLoc = IvarLoc;
2231 
2232  return SourceRange(AtLoc, EndLoc);
2233 }
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance) const
Definition: DeclObjC.cpp:1842
Defines the clang::ASTContext interface.
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1457
static const Decl * getCanonicalDecl(const Decl *D)
void setExternallyCompleted()
Indicate that this Objective-C class is complete, but that the external AST source will be responsibl...
Definition: DeclObjC.cpp:1461
protocol_range protocols() const
Definition: DeclObjC.h:1295
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
Definition: ASTContext.h:1761
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Definition: Type.h:614
static ObjCIvarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1735
void getDesignatedInitializers(llvm::SmallVectorImpl< const ObjCMethodDecl *> &Methods) const
Returns the designated initializers for the interface.
Definition: DeclObjC.cpp:518
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2232
all_protocol_range all_referenced_protocols() const
Definition: DeclObjC.h:1350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1089
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:590
iterator begin() const
Definition: DeclObjC.h:65
Stmt - This represents one statement.
Definition: Stmt.h:66
llvm::DenseMap< std::pair< IdentifierInfo *, unsigned >, ObjCPropertyDecl * > PropertyMap
Definition: DeclObjC.h:1041
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:334
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:308
CXXCtorInitializer *const * init_const_iterator
init_const_iterator - Iterates through the ivar initializer list.
Definition: DeclObjC.h:2501
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1841
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.cpp:2227
StringRef P
static ObjCProtocolDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl)
Definition: DeclObjC.cpp:1807
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:2180
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameters of this class.
Definition: DeclObjC.cpp:285
void ** List
List is an array of pointers to objects that are not owned by this object.
Definition: DeclObjC.h:40
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:195
ObjCProtocolDecl * lookupNestedProtocol(IdentifierInfo *Name)
Definition: DeclObjC.cpp:650
bool isDesignatedInitializer(Selector Sel, const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the given selector is a designated initializer for the interface. ...
Definition: DeclObjC.cpp:540
QualType withConst() const
Definition: Type.h:784
A container of type source information.
Definition: Decl.h:86
bool isOverriding() const
Whether this method overrides any other in the class hierarchy.
Definition: DeclObjC.h:436
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implict parameters. ...
Definition: DeclObjC.cpp:1068
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:1979
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:1974
Parameter for Objective-C &#39;_cmd&#39; argument.
Definition: Decl.h:1462
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
ObjCImplementationDecl * getObjCImplementation(ObjCInterfaceDecl *D)
Get the implementation of the ObjCInterfaceDecl D, or NULL if none exists.
bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, bool lookupCategory, bool RHSIsQualifiedID=false)
ClassImplementsProtocol - Checks that &#39;lProto&#39; protocol has been implemented in IDecl class...
Definition: DeclObjC.cpp:1654
bool isInvalidDecl() const
Definition: DeclBase.h:546
QualType getObjCClassType() const
Represents the Objective-C Class type.
Definition: ASTContext.h:1783
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Definition: DeclObjC.cpp:154
protocol_range protocols() const
Definition: DeclObjC.h:2042
static const NamedDecl * getDefinition(const Decl *D)
Definition: SemaDecl.cpp:2512
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1514
The collection of all-type qualifiers we support.
Definition: Type.h:116
iterator end() const
Definition: DeclObjC.h:66
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:265
instprop_range instance_properties() const
Definition: DeclObjC.h:952
One of these records is kept for each identifier that is lexed.
Represents a class type in Objective C.
Definition: Type.h:5029
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1178
ObjCMethodFamily
A family of Objective-C methods.
bool isObjCIdType() const
Definition: Type.h:5871
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:305
SourceRange getReturnTypeSourceRange() const
Definition: DeclObjC.cpp:1101
instmeth_range instance_methods() const
Definition: DeclObjC.h:997
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for protocol&#39;s metadata.
Definition: DeclObjC.cpp:1913
llvm::SmallDenseSet< const ObjCProtocolDecl *, 8 > ProtocolPropertySet
Definition: DeclObjC.h:1043
prop_range properties() const
Definition: DeclObjC.h:939
int Category
Definition: Format.cpp:1338
bool isObjCSelType() const
Definition: Type.h:5881
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:1867
visible_categories_range visible_categories() const
Definition: DeclObjC.h:1576
IdentifierTable & Idents
Definition: ASTContext.h:515
void set(ObjCProtocolDecl *const *InList, unsigned Elts, const SourceLocation *Locs, ASTContext &Ctx)
Definition: DeclObjC.cpp:37
bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, ObjCProtocolDecl *rProto) const
ProtocolCompatibleWithProtocol - return &#39;true&#39; if &#39;lProto&#39; is in the inheritance hierarchy of &#39;rProto...
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:931
bool isThisDeclarationADesignatedInitializer() const
Returns true if this specific method declaration is marked with the designated initializer attribute...
Definition: DeclObjC.cpp:776
void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:370
static ObjCInterfaceDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, ObjCTypeParamList *typeParamList, ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc=SourceLocation(), bool isInternal=false)
Definition: DeclObjC.cpp:1406
void set(void *const *InList, unsigned Elts, ASTContext &Ctx)
Definition: DeclObjC.cpp:27
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:919
static ObjCCategoryDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation AtLoc, SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, IdentifierInfo *Id, ObjCInterfaceDecl *IDecl, ObjCTypeParamList *typeParamList, SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:1941
static ObjCPropertyImplDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation atLoc, SourceLocation L, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc)
Definition: DeclObjC.cpp:2208
const ObjCInterfaceDecl * isObjCRequiresPropertyDefs() const
isObjCRequiresPropertyDefs - Checks that a class or one of its super classes must not be auto-synthes...
Definition: DeclObjC.cpp:400
static ObjCAtDefsFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, Expr *BW)
Definition: DeclObjC.cpp:1777
static ObjCCategoryImplDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2012
ObjCCategoryDecl * getCategoryListRaw() const
Retrieve the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1703
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2115
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5549
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
Definition: DeclObjC.cpp:1232
void setAsRedeclaration(const ObjCMethodDecl *PrevMethod)
Definition: DeclObjC.cpp:797
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1985
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
SourceLocation getLocEnd() const LLVM_READONLY
Definition: DeclObjC.cpp:925
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl *> Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method&#39;s parameters and selector source locations.
Definition: DeclObjC.cpp:828
ObjCMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclObjC.cpp:897
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1521
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:822
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:4174
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2645
ObjCMethodDecl * getCategoryInstanceMethod(Selector Sel) const
Definition: DeclObjC.cpp:1631
ObjCMethodDecl * getCategoryClassMethod(Selector Sel) const
Definition: DeclObjC.cpp:1641
bool hasAttr() const
Definition: DeclBase.h:535
llvm::mapped_iterator< param_const_iterator, GetTypeFn > param_type_iterator
Definition: DeclObjC.h:388
visible_extensions_range visible_extensions() const
Definition: DeclObjC.h:1646
ObjCProtocolDecl * lookupProtocolNamed(IdentifierInfo *PName)
Definition: DeclObjC.cpp:1827
static ObjCCompatibleAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2169
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:1983
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:1765
void setNextIvar(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1901
classprop_range class_properties() const
Definition: DeclObjC.h:967
Expr - This represents one expression.
Definition: Expr.h:119
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 isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:759
Selector getSetterName() const
Definition: DeclObjC.h:868
int Id
Definition: ASTDiff.cpp:191
bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const
This routine returns &#39;true&#39; if a user declared setter method was found in the class, its protocols, its super classes or categories.
Definition: DeclObjC.cpp:101
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
Definition: DeclObjC.cpp:202
const FunctionProtoType * T
static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &overridden)
Definition: DeclObjC.cpp:1191
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:551
static ObjCTypeParamDecl * Create(ASTContext &ctx, DeclContext *dc, ObjCTypeParamVariance variance, SourceLocation varianceLoc, unsigned index, SourceLocation nameLoc, IdentifierInfo *name, SourceLocation colonLoc, TypeSourceInfo *boundInfo)
Definition: DeclObjC.cpp:1333
DeclContext * getDeclContext()
Definition: DeclBase.h:425
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:314
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl *> typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1384
ObjCPropertyDecl * FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyVisibleInPrimaryClass - Finds declaration of the property with name &#39;PropertyId&#39; in the p...
Definition: DeclObjC.cpp:346
void setObjCImplementation(ObjCInterfaceDecl *IFaceD, ObjCImplementationDecl *ImplD)
Set the implementation of ObjCInterfaceDecl.
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1516
void mergeClassExtensionProtocolList(ObjCProtocolDecl *const *List, unsigned Num, ASTContext &C)
mergeClassExtensionProtocolList - Merge class extension&#39;s protocol list into the protocol list for th...
Definition: DeclObjC.cpp:410
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:600
const ObjCMethodDecl * getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const
Get the duplicate declaration of a ObjCMethod in the same interface, or null if none exists...
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1285
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
bool isInstanceMethod() const
Definition: DeclObjC.h:416
unsigned getNumArgs() const
Selector getSelector() const
Definition: DeclObjC.h:328
The result type of a method or function.
static ObjCTypeParamDecl * CreateDeserialized(ASTContext &ctx, unsigned ID)
Definition: DeclObjC.cpp:1349
ObjCTypeParamVariance
Describes the variance of a given generic parameter.
Definition: DeclObjC.h:514
static bool isIntroducingInitializers(const ObjCInterfaceDecl *D)
Definition: DeclObjC.cpp:465
static StringRef getIdentifier(const Token &Tok)
static ObjCMethodDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:771
init_iterator init_begin()
init_begin() - Retrieve an iterator to the first initializer.
Definition: DeclObjC.h:2512
static ObjCCompatibleAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, ObjCInterfaceDecl *aliasedClass)
Definition: DeclObjC.cpp:2161
static ObjCProtocolDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1818
Assigning into this object requires the old value to be released and the new value to be retained...
Definition: Type.h:144
QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID, bool &selfIsPseudoStrong, bool &selfIsConsumed)
Definition: DeclObjC.cpp:1023
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ObjCPropertyQueryKind
Definition: DeclObjC.h:692
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2019
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C &#39;SEL&#39; type.
Definition: ASTContext.h:1771
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:793
static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &Methods, bool MovedToSuper)
Definition: DeclObjC.cpp:1122
ObjCInterfaceDecl * lookupInheritedClass(const IdentifierInfo *ICName)
lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super class whose name is passe...
Definition: DeclObjC.cpp:631
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2189
QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, ArrayRef< ObjCProtocolDecl *> protocols, QualType Canonical=QualType()) const
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:704
ObjCPropertyImplDecl * FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const
FindPropertyImplIvarDecl - This method lookup the ivar in the list of properties implemented in this ...
Definition: DeclObjC.cpp:2057
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1503
bool isDesignatedInitializerForTheInterface(const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the method selector resolves to a designated initializer in the class&#39;s interface...
Definition: DeclObjC.cpp:781
protocol_range protocols() const
Definition: DeclObjC.h:2263
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:625
QualType getUsageType(QualType objectType) const
Retrieve the type when this property is used with a specific base object type.
Definition: DeclObjC.cpp:2199
void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property, ProtocolPropertySet &PS, PropertyDeclOrder &PO) const
Definition: DeclObjC.cpp:1892
Dataflow Directional Tag Classes.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
Definition: DeclObjC.cpp:720
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in &#39;PropertyId&#39; and return...
Definition: DeclObjC.cpp:213
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.cpp:1357
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
Parameter for Objective-C &#39;self&#39; argument.
Definition: Decl.h:1459
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1471
void setIvarList(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1410
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:537
Kind getKind() const
Definition: DeclBase.h:419
unsigned size() const
Definition: DeclObjC.h:45
static ObjCImplementationDecl * Create(ASTContext &C, DeclContext *DC, ObjCInterfaceDecl *classInterface, ObjCInterfaceDecl *superDecl, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation superLoc=SourceLocation(), SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:2109
static ObjCCategoryDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1967
unsigned NumElts
Definition: DeclObjC.h:41
const ObjCInterfaceDecl * getContainingInterface() const
Return the class interface that this ivar is logically contained in; this is either the interface whe...
Definition: DeclObjC.cpp:1741
ObjCIvarDecl * getIvarDecl(IdentifierInfo *Id) const
getIvarDecl - This method looks up an ivar in this ContextDecl.
Definition: DeclObjC.cpp:56
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:766
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:1596
bool hasDesignatedInitializers() const
Returns true if this interface decl contains at least one initializer marked with the &#39;objc_designate...
Definition: DeclObjC.cpp:1476
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:1699
static ObjCAtDefsFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1783
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2448
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for class&#39;s metadata.
Definition: DeclObjC.cpp:1487
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2172
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for class&#39;s metadata.
Definition: DeclObjC.cpp:1495
void setCategoryListRaw(ObjCCategoryDecl *category)
Set the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1716
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, its categories, and its super classes (using a linear search).
Definition: DeclObjC.cpp:662
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2786
bool IsClassExtension() const
Definition: DeclObjC.h:2292
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any...
Definition: ASTContext.h:1032
void gatherDefaultTypeArgs(SmallVectorImpl< QualType > &typeArgs) const
Gather the default set of type arguments to be substituted for these type parameters when dealing wit...
Definition: DeclObjC.cpp:1395
No particular method family.
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method&#39;s selector.
Definition: DeclObjC.cpp:1249
Represents a field declaration created by an @defs(...).
Definition: DeclObjC.h:1933
static bool isInstanceMethod(const Decl *D)
void setIvarInitializers(ASTContext &C, CXXCtorInitializer **initializers, unsigned numInitializers)
Definition: DeclObjC.cpp:2130
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2070
static ObjCImplementationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2125
void setClassInterface(ObjCInterfaceDecl *IFace)
Definition: DeclObjC.cpp:2035
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1866
QualType getSendResultType() const
Determine the type of an expression that sends a message to this function.
Definition: DeclObjC.cpp:1108
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:615
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
StringRef getName() const
getName - Get the name of identifier for the class interface associated with this implementation as a...
Definition: DeclObjC.h:2561
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:390
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:915
static ObjCInterfaceDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1422
static ObjCPropertyImplDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2220
void addPropertyImplementation(ObjCPropertyImplDecl *property)
Definition: DeclObjC.cpp:2029
A trivial tuple used to represent a source range.
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
Definition: DeclObjC.cpp:68
bool isRedeclaration() const
True if this is a method redeclaration in the same interface.
Definition: DeclObjC.h:282
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
Definition: DeclObjC.cpp:1543
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
static ObjCCategoryImplDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, ObjCInterfaceDecl *classInterface, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation CategoryNameLoc)
Definition: DeclObjC.cpp:2000
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1025
static ObjCPropertyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2192
void setHasDesignatedInitializers()
Indicate that this interface decl contains at least one initializer marked with the &#39;objc_designated_...
Definition: DeclObjC.cpp:1469
void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:1875
const LangOptions & getLangOpts() const
Definition: ASTContext.h:661
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2396
The parameter is invariant: must match exactly.
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2616
static void CollectOverriddenMethods(const ObjCContainerDecl *Container, const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &Methods)
Definition: DeclObjC.cpp:1184
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1615
SelectorLocationsKind hasStandardSelectorLocs(Selector Sel, ArrayRef< SourceLocation > SelLocs, ArrayRef< Expr *> Args, SourceLocation EndLoc)
Returns true if all SelLocs are in a "standard" location.