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