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