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