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