clang 10.0.0git

DeclObjC.cpp
Go to the documentation of this file.
1 //===- DeclObjC.cpp - ObjC Declaration AST Node Implementation ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Objective-C related Decl classes.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "clang/AST/DeclObjC.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ASTMutationListener.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"
22 #include "clang/Basic/IdentifierTable.h"
23 #include "clang/Basic/LLVM.h"
24 #include "clang/Basic/LangOptions.h"
25 #include "clang/Basic/SourceLocation.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
67 ObjCContainerDecl::ObjCContainerDecl(Kind DK, DeclContext *DC,
68 IdentifierInfo *Id, SourceLocation nameLoc,
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 ///
78 ObjCIvarDecl *
79 ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
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.
90 ObjCMethodDecl *
91 ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
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.
123 bool ObjCContainerDecl::HasUserDeclaredSetterMethod(
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
175 ObjCPropertyDecl *
176 ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
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())
191 if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext,
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.
204 if ((queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown &&
205 !PD->isClassProperty()) ||
206 (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_class &&
207 PD->isClassProperty()) ||
208 (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance &&
209 !PD->isClassProperty()))
210 return PD;
211
212 if (PD->isClassProperty())
213 classProp = PD;
214 }
215
216 if (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown)
217 // We can't find the instance property, return the class property.
218 return classProp;
219
220 return nullptr;
221 }
222
223 IdentifierInfo *
224 ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const {
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.
235 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
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
307 ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const {
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
328 void ObjCInterfaceDecl::setTypeParamList(ObjCTypeParamList *TPL) {
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
337 ObjCInterfaceDecl *ObjCInterfaceDecl::getSuperClass() const {
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
357 SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const {
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.
367 ObjCPropertyDecl *
368 ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
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
392 void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM,
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
412 bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const {
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
422 const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const {
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
432 void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
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.
447 SmallVector<ObjCProtocolDecl *, 8> ProtocolRefs;
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
486 static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
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
538 void ObjCInterfaceDecl::getDesignatedInitializers(
539 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const {
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
560 bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel,
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() &&
567 getCanonicalDecl()->getDefinition() == getDefinition())
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
610 void ObjCInterfaceDecl::startDefinition() {
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
620 ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
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.
651 ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
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
669 ObjCProtocolDecl *
670 ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) {
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.
682 ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
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.
739 ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
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(
779 SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo,
780 QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl,
781 bool isInstance, bool isVariadic, bool isPropertyAccessor,
782 bool isSynthesizedAccessorStub, bool isImplicitlyDeclared, bool isDefined,
783 ImplementationControl impControl, bool HasRelatedResultType)
784 : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
785 DeclContext(ObjCMethod), MethodDeclType(T), ReturnTInfo(ReturnTInfo),
786 DeclEndLoc(endLoc) {
787
788 // Initialized the bits stored in DeclContext.
789 ObjCMethodDeclBits.Family =
790 static_cast<ObjCMethodFamily>(InvalidObjCMethodFamily);
791 setInstanceMethod(isInstance);
792 setVariadic(isVariadic);
793 setPropertyAccessor(isPropertyAccessor);
794 setSynthesizedAccessorStub(isSynthesizedAccessorStub);
795 setDefined(isDefined);
796 setIsRedeclaration(false);
797 setHasRedeclaration(false);
798 setDeclImplementation(impControl);
799 setObjCDeclQualifier(OBJC_TQ_None);
800 setRelatedResultType(HasRelatedResultType);
801 setSelLocsKind(SelLoc_StandardNoSpace);
802 setOverriding(false);
803 setHasSkippedBody(false);
804
805 setImplicit(isImplicitlyDeclared);
806 }
807
808 ObjCMethodDecl *ObjCMethodDecl::Create(
809 ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
810 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
811 DeclContext *contextDecl, bool isInstance, bool isVariadic,
812 bool isPropertyAccessor, bool isSynthesizedAccessorStub,
813 bool isImplicitlyDeclared, bool isDefined, ImplementationControl impControl,
814 bool HasRelatedResultType) {
815 return new (C, contextDecl) ObjCMethodDecl(
816 beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance,
817 isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
818 isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
819 }
820
821 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
822 return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
823 Selector(), QualType(), nullptr, nullptr);
824 }
825
826 bool ObjCMethodDecl::isDirectMethod() const {
827 return hasAttr<ObjCDirectAttr>();
828 }
829
830 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
831 return getMethodFamily() == OMF_init &&
832 hasAttr<ObjCDesignatedInitializerAttr>();
833 }
834
835 bool ObjCMethodDecl::definedInNSObject(const ASTContext &Ctx) const {
836 if (const auto *PD = dyn_cast<const ObjCProtocolDecl>(getDeclContext()))
837 return PD->getIdentifier() == Ctx.getNSObjectName();
838 if (const auto *ID = dyn_cast<const ObjCInterfaceDecl>(getDeclContext()))
839 return ID->getIdentifier() == Ctx.getNSObjectName();
840 return false;
841 }
842
843 bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
844 const ObjCMethodDecl **InitMethod) const {
845 if (getMethodFamily() != OMF_init)
846 return false;
847 const DeclContext *DC = getDeclContext();
848 if (isa<ObjCProtocolDecl>(DC))
849 return false;
850 if (const ObjCInterfaceDecl *ID = getClassInterface())
851 return ID->isDesignatedInitializer(getSelector(), InitMethod);
852 return false;
853 }
854
855 Stmt *ObjCMethodDecl::getBody() const {
856 return Body.get(getASTContext().getExternalSource());
857 }
858
859 void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
860 assert(PrevMethod);
861 getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
862 setIsRedeclaration(true);
863 PrevMethod->setHasRedeclaration(true);
864 }
865
866 void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
867 ArrayRef<ParmVarDecl*> Params,
868 ArrayRef<SourceLocation> SelLocs) {
869 ParamsAndSelLocs = nullptr;
870 NumParams = Params.size();
871 if (Params.empty() && SelLocs.empty())
872 return;
873
874 static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation),
875 "Alignment not sufficient for SourceLocation");
876
877 unsigned Size = sizeof(ParmVarDecl *) * NumParams +
878 sizeof(SourceLocation) * SelLocs.size();
879 ParamsAndSelLocs = C.Allocate(Size);
880 std::copy(Params.begin(), Params.end(), getParams());
881 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
882 }
883
884 void ObjCMethodDecl::getSelectorLocs(
885 SmallVectorImpl<SourceLocation> &SelLocs) const {
886 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
887 SelLocs.push_back(getSelectorLoc(i));
888 }
889
890 void ObjCMethodDecl::setMethodParams(ASTContext &C,
891 ArrayRef<ParmVarDecl*> Params,
892 ArrayRef<SourceLocation> SelLocs) {
893 assert((!SelLocs.empty() || isImplicit()) &&
894 "No selector locs for non-implicit method");
895 if (isImplicit())
896 return setParamsAndSelLocs(C, Params, llvm::None);
897
898 setSelLocsKind(hasStandardSelectorLocs(getSelector(), SelLocs, Params,
899 DeclEndLoc));
900 if (getSelLocsKind() != SelLoc_NonStandard)
901 return setParamsAndSelLocs(C, Params, llvm::None);
902
903 setParamsAndSelLocs(C, Params, SelLocs);
904 }
905
906 /// A definition will return its interface declaration.
907 /// An interface declaration will return its definition.
908 /// Otherwise it will return itself.
909 ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
910 ASTContext &Ctx = getASTContext();
911 ObjCMethodDecl *Redecl = nullptr;
912 if (hasRedeclaration())
913 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
914 if (Redecl)
915 return Redecl;
916
917 auto *CtxD = cast<Decl>(getDeclContext());
918
919 if (!CtxD->isInvalidDecl()) {
920 if (auto *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
921 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
922 if (!ImplD->isInvalidDecl())
923 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
924
925 } else if (auto *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
926 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
927 if (!ImplD->isInvalidDecl())
928 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
929
930 } else if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
931 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
932 if (!IFD->isInvalidDecl())
933 Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
934
935 } else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
936 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
937 if (!CatD->isInvalidDecl())
938 Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
939 }
940 }
941
942 // Ensure that the discovered method redeclaration has a valid declaration
943 // context. Used to prevent infinite loops when iterating redeclarations in
944 // a partially invalid AST.
945 if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl())
946 Redecl = nullptr;
947
948 if (!Redecl && isRedeclaration()) {
949 // This is the last redeclaration, go back to the first method.
950 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
951 isInstanceMethod());
952 }
953
954 return Redecl ? Redecl : this;
955 }
956
957 ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
958 auto *CtxD = cast<Decl>(getDeclContext());
959 const auto &Sel = getSelector();
960
961 if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
962 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) {
963 // When the container is the ObjCImplementationDecl (the primary
964 // @implementation), then the canonical Decl is either in
965 // the class Interface, or in any of its extension.
966 //
967 // So when we don't find it in the ObjCInterfaceDecl,
968 // sift through extensions too.
969 if (ObjCMethodDecl *MD = IFD->getMethod(Sel, isInstanceMethod()))
970 return MD;
971 for (auto *Ext : IFD->known_extensions())
972 if (ObjCMethodDecl *MD = Ext->getMethod(Sel, isInstanceMethod()))
973 return MD;
974 }
975 } else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
976 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
977 if (ObjCMethodDecl *MD = CatD->getMethod(Sel, isInstanceMethod()))
978 return MD;
979 }
980
981 if (isRedeclaration()) {
982 // It is possible that we have not done deserializing the ObjCMethod yet.
983 ObjCMethodDecl *MD =
984 cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod());
985 return MD ? MD : this;
986 }
987
988 return this;
989 }
990
991 SourceLocation ObjCMethodDecl::getEndLoc() const {
992 if (Stmt *Body = getBody())
993 return Body->getEndLoc();
994 return DeclEndLoc;
995 }
996
997 ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
998 auto family = static_cast<ObjCMethodFamily>(ObjCMethodDeclBits.Family);
999 if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
1000 return family;
1001
1002 // Check for an explicit attribute.
1003 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) {
1004 // The unfortunate necessity of mapping between enums here is due
1005 // to the attributes framework.
1006 switch (attr->getFamily()) {
1007 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break;
1008 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break;
1009 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break;
1010 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break;
1011 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
1012 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
1013 }
1014 ObjCMethodDeclBits.Family = family;
1015 return family;
1016 }
1017
1018 family = getSelector().getMethodFamily();
1019 switch (family) {
1020 case OMF_None: break;
1021
1022 // init only has a conventional meaning for an instance method, and
1023 // it has to return an object.
1024 case OMF_init:
1025 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType())
1026 family = OMF_None;
1027 break;
1028
1029 // alloc/copy/new have a conventional meaning for both class and
1030 // instance methods, but they require an object return.
1031 case OMF_alloc:
1032 case OMF_copy:
1033 case OMF_mutableCopy:
1034 case OMF_new:
1035 if (!getReturnType()->isObjCObjectPointerType())
1036 family = OMF_None;
1037 break;
1038
1039 // These selectors have a conventional meaning only for instance methods.
1040 case OMF_dealloc:
1041 case OMF_finalize:
1042 case OMF_retain:
1043 case OMF_release:
1044 case OMF_autorelease:
1045 case OMF_retainCount:
1046 case OMF_self:
1047 if (!isInstanceMethod())
1048 family = OMF_None;
1049 break;
1050
1051 case OMF_initialize:
1052 if (isInstanceMethod() || !getReturnType()->isVoidType())
1053 family = OMF_None;
1054 break;
1055
1056 case OMF_performSelector:
1057 if (!isInstanceMethod() || !getReturnType()->isObjCIdType())
1058 family = OMF_None;
1059 else {
1060 unsigned noParams = param_size();
1061 if (noParams < 1 || noParams > 3)
1062 family = OMF_None;
1063 else {
1064 ObjCMethodDecl::param_type_iterator it = param_type_begin();
1065 QualType ArgT = (*it);
1066 if (!ArgT->isObjCSelType()) {
1067 family = OMF_None;
1068 break;
1069 }
1070 while (--noParams) {
1071 it++;
1072 ArgT = (*it);
1073 if (!ArgT->isObjCIdType()) {
1074 family = OMF_None;
1075 break;
1076 }
1077 }
1078 }
1079 }
1080 break;
1081
1082 }
1083
1084 // Cache the result.
1085 ObjCMethodDeclBits.Family = family;
1086 return family;
1087 }
1088
1089 QualType ObjCMethodDecl::getSelfType(ASTContext &Context,
1090 const ObjCInterfaceDecl *OID,
1091 bool &selfIsPseudoStrong,
1092 bool &selfIsConsumed) const {
1093 QualType selfTy;
1094 selfIsPseudoStrong = false;
1095 selfIsConsumed = false;
1096 if (isInstanceMethod()) {
1097 // There may be no interface context due to error in declaration
1098 // of the interface (which has been reported). Recover gracefully.
1099 if (OID) {
1100 selfTy = Context.getObjCInterfaceType(OID);
1101 selfTy = Context.getObjCObjectPointerType(selfTy);
1102 } else {
1103 selfTy = Context.getObjCIdType();
1104 }
1105 } else // we have a factory method.
1106 selfTy = Context.getObjCClassType();
1107
1108 if (Context.getLangOpts().ObjCAutoRefCount) {
1109 if (isInstanceMethod()) {
1110 selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
1111
1112 // 'self' is always __strong. It's actually pseudo-strong except
1113 // in init methods (or methods labeled ns_consumes_self), though.
1114 Qualifiers qs;
1115 qs.setObjCLifetime(Qualifiers::OCL_Strong);
1116 selfTy = Context.getQualifiedType(selfTy, qs);
1117
1118 // In addition, 'self' is const unless this is an init method.
1119 if (getMethodFamily() != OMF_init && !selfIsConsumed) {
1120 selfTy = selfTy.withConst();
1121 selfIsPseudoStrong = true;
1122 }
1123 }
1124 else {
1125 assert(isClassMethod());
1126 // 'self' is always const in class methods.
1127 selfTy = selfTy.withConst();
1128 selfIsPseudoStrong = true;
1129 }
1130 }
1131 return selfTy;
1132 }
1133
1134 void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
1135 const ObjCInterfaceDecl *OID) {
1136 bool selfIsPseudoStrong, selfIsConsumed;
1137 QualType selfTy =
1138 getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed);
1139 auto *Self = ImplicitParamDecl::Create(Context, this, SourceLocation(),
1140 &Context.Idents.get("self"), selfTy,
1141 ImplicitParamDecl::ObjCSelf);
1142 setSelfDecl(Self);
1143
1144 if (selfIsConsumed)
1145 Self->addAttr(NSConsumedAttr::CreateImplicit(Context));
1146
1147 if (selfIsPseudoStrong)
1148 Self->setARCPseudoStrong(true);
1149
1150 setCmdDecl(ImplicitParamDecl::Create(
1151 Context, this, SourceLocation(), &Context.Idents.get("_cmd"),
1152 Context.getObjCSelType(), ImplicitParamDecl::ObjCCmd));
1153 }
1154
1155 ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
1156 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
1157 return ID;
1158 if (auto *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
1159 return CD->getClassInterface();
1160 if (auto *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
1161 return IMD->getClassInterface();
1162 if (isa<ObjCProtocolDecl>(getDeclContext()))
1163 return nullptr;
1164 llvm_unreachable("unknown method context");
1165 }
1166
1167 SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
1168 const auto *TSI = getReturnTypeSourceInfo();
1169 if (TSI)
1170 return TSI->getTypeLoc().getSourceRange();
1171 return SourceRange();
1172 }
1173
1174 QualType ObjCMethodDecl::getSendResultType() const {
1175 ASTContext &Ctx = getASTContext();
1176 return getReturnType().getNonLValueExprType(Ctx)
1177 .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
1178 }
1179
1180 QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const {
1181 // FIXME: Handle related result types here.
1182
1183 return getReturnType().getNonLValueExprType(getASTContext())
1184 .substObjCMemberType(receiverType, getDeclContext(),
1185 ObjCSubstitutionContext::Result);
1186 }
1187
1188 static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
1189 const ObjCMethodDecl *Method,
1190 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
1191 bool MovedToSuper) {
1192 if (!Container)
1193 return;
1194
1195 // In categories look for overridden methods from protocols. A method from
1196 // category is not "overridden" since it is considered as the "same" method
1197 // (same USR) as the one from the interface.
1198 if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1199 // Check whether we have a matching method at this category but only if we
1200 // are at the super class level.
1201 if (MovedToSuper)
1202 if (ObjCMethodDecl *
1203 Overridden = Container->getMethod(Method->getSelector(),
1204 Method->isInstanceMethod(),
1205 /*AllowHidden=*/true))
1206 if (Method != Overridden) {
1207 // We found an override at this category; there is no need to look
1208 // into its protocols.
1209 Methods.push_back(Overridden);
1210 return;
1211 }
1212
1213 for (const auto *P : Category->protocols())
1214 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1215 return;
1216 }
1217
1218 // Check whether we have a matching method at this level.
1219 if (const ObjCMethodDecl *
1220 Overridden = Container->getMethod(Method->getSelector(),
1221 Method->isInstanceMethod(),
1222 /*AllowHidden=*/true))
1223 if (Method != Overridden) {
1224 // We found an override at this level; there is no need to look
1225 // into other protocols or categories.
1226 Methods.push_back(Overridden);
1227 return;
1228 }
1229
1230 if (const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
1231 for (const auto *P : Protocol->protocols())
1232 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1233 }
1234
1235 if (const auto *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
1236 for (const auto *P : Interface->protocols())
1237 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
1238
1239 for (const auto *Cat : Interface->known_categories())
1240 CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper);
1241
1242 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass())
1243 return CollectOverriddenMethodsRecurse(Super, Method, Methods,
1244 /*MovedToSuper=*/true);
1245 }
1246 }
1247
1248 static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container,
1249 const ObjCMethodDecl *Method,
1250 SmallVectorImpl<const ObjCMethodDecl *> &Methods) {
1251 CollectOverriddenMethodsRecurse(Container, Method, Methods,
1252 /*MovedToSuper=*/false);
1253 }
1254
1255 static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method,
1256 SmallVectorImpl<const ObjCMethodDecl *> &overridden) {
1257 assert(Method->isOverriding());
1258
1259 if (const auto *ProtD =
1260 dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
1261 CollectOverriddenMethods(ProtD, Method, overridden);
1262
1263 } else if (const auto *IMD =
1264 dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
1265 const ObjCInterfaceDecl *ID = IMD->getClassInterface();
1266 if (!ID)
1267 return;
1268 // Start searching for overridden methods using the method from the
1269 // interface as starting point.
1270 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1271 Method->isInstanceMethod(),
1272 /*AllowHidden=*/true))
1273 Method = IFaceMeth;
1274 CollectOverriddenMethods(ID, Method, overridden);
1275
1276 } else if (const auto *CatD =
1277 dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
1278 const ObjCInterfaceDecl *ID = CatD->getClassInterface();
1279 if (!ID)
1280 return;
1281 // Start searching for overridden methods using the method from the
1282 // interface as starting point.
1283 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
1284 Method->isInstanceMethod(),
1285 /*AllowHidden=*/true))
1286 Method = IFaceMeth;
1287 CollectOverriddenMethods(ID, Method, overridden);
1288
1289 } else {
1290 CollectOverriddenMethods(
1291 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
1292 Method, overridden);
1293 }
1294 }
1295
1296 void ObjCMethodDecl::getOverriddenMethods(
1297 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const {
1298 const ObjCMethodDecl *Method = this;
1299
1300 if (Method->isRedeclaration()) {
1301 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1302 getMethod(Method->getSelector(), Method->isInstanceMethod());
1303 }
1304
1305 if (Method->isOverriding()) {
1306 collectOverriddenMethodsSlow(Method, Overridden);
1307 assert(!Overridden.empty() &&
1308 "ObjCMethodDecl's overriding bit is not as expected");
1309 }
1310 }
1311
1312 const ObjCPropertyDecl *
1313 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
1314 Selector Sel = getSelector();
1315 unsigned NumArgs = Sel.getNumArgs();
1316 if (NumArgs > 1)
1317 return nullptr;
1318
1319 if (isPropertyAccessor()) {
1320 const auto *Container = cast<ObjCContainerDecl>(getParent());
1321 // For accessor stubs, go back to the interface.
1322 if (auto *ImplDecl = dyn_cast<ObjCImplDecl>(Container))
1323 if (isSynthesizedAccessorStub())
1324 Container = ImplDecl->getClassInterface();
1325
1326 bool IsGetter = (NumArgs == 0);
1327 bool IsInstance = isInstanceMethod();
1328
1329 /// Local function that attempts to find a matching property within the
1330 /// given Objective-C container.
1331 auto findMatchingProperty =
1332 [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {
1333 if (IsInstance) {
1334 for (const auto *I : Container->instance_properties()) {
1335 Selector NextSel = IsGetter ? I->getGetterName()
1336 : I->getSetterName();
1337 if (NextSel == Sel)
1338 return I;
1339 }
1340 } else {
1341 for (const auto *I : Container->class_properties()) {
1342 Selector NextSel = IsGetter ? I->getGetterName()
1343 : I->getSetterName();
1344 if (NextSel == Sel)
1345 return I;
1346 }
1347 }
1348
1349 return nullptr;
1350 };
1351
1352 // Look in the container we were given.
1353 if (const auto *Found = findMatchingProperty(Container))
1354 return Found;
1355
1356 // If we're in a category or extension, look in the main class.
1357 const ObjCInterfaceDecl *ClassDecl = nullptr;
1358 if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
1359 ClassDecl = Category->getClassInterface();
1360 if (const auto *Found = findMatchingProperty(ClassDecl))
1361 return Found;
1362 } else {
1363 // Determine whether the container is a class.
1364 ClassDecl = dyn_cast<ObjCInterfaceDecl>(Container);
1365 }
1366
1367 // If we have a class, check its visible extensions.
1368 if (ClassDecl) {
1369 for (const auto *Ext : ClassDecl->visible_extensions()) {
1370 if (Ext == Container)
1371 continue;
1372
1373 if (const auto *Found = findMatchingProperty(Ext))
1374 return Found;
1375 }
1376 }
1377
1378 assert(isSynthesizedAccessorStub() && "expected an accessor stub");
1379 for (const auto *Cat : ClassDecl->known_categories()) {
1380 if (Cat == Container)
1381 continue;
1382
1383 if (const auto *Found = findMatchingProperty(Cat))
1384 return Found;
1385 }
1386
1387 llvm_unreachable("Marked as a property accessor but no property found!");
1388 }
1389
1390 if (!CheckOverrides)
1391 return nullptr;
1392
1393 using OverridesTy = SmallVector<const ObjCMethodDecl *, 8>;
1394
1395 OverridesTy Overrides;
1396 getOverriddenMethods(Overrides);
1397 for (const auto *Override : Overrides)
1398 if (const ObjCPropertyDecl *Prop = Override->findPropertyDecl(false))
1399 return Prop;
1400
1401 return nullptr;
1402 }
1403
1404 //===----------------------------------------------------------------------===//
1405 // ObjCTypeParamDecl
1406 //===----------------------------------------------------------------------===//
1407
1408 void ObjCTypeParamDecl::anchor() {}
1409
1410 ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc,
1411 ObjCTypeParamVariance variance,
1412 SourceLocation varianceLoc,
1413 unsigned index,
1414 SourceLocation nameLoc,
1415 IdentifierInfo *name,
1416 SourceLocation colonLoc,
1417 TypeSourceInfo *boundInfo) {
1418 auto *TPDecl =
1419 new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
1420 nameLoc, name, colonLoc, boundInfo);
1421 QualType TPType = ctx.getObjCTypeParamType(TPDecl, {});
1422 TPDecl->setTypeForDecl(TPType.getTypePtr());
1423 return TPDecl;
1424 }
1425
1426 ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext &ctx,
1427 unsigned ID) {
1428 return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr,
1429 ObjCTypeParamVariance::Invariant,
1430 SourceLocation(), 0, SourceLocation(),
1431 nullptr, SourceLocation(), nullptr);
1432 }
1433
1434 SourceRange ObjCTypeParamDecl::getSourceRange() const {
1435 SourceLocation startLoc = VarianceLoc;
1436 if (startLoc.isInvalid())
1437 startLoc = getLocation();
1438
1439 if (hasExplicitBound()) {
1440 return SourceRange(startLoc,
1441 getTypeSourceInfo()->getTypeLoc().getEndLoc());
1442 }
1443
1444 return SourceRange(startLoc);
1445 }
1446
1447 //===----------------------------------------------------------------------===//
1448 // ObjCTypeParamList
1449 //===----------------------------------------------------------------------===//
1450 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
1451 ArrayRef<ObjCTypeParamDecl *> typeParams,
1452 SourceLocation rAngleLoc)
1453 : NumParams(typeParams.size()) {
1454 Brackets.Begin = lAngleLoc.getRawEncoding();
1455 Brackets.End = rAngleLoc.getRawEncoding();
1456 std::copy(typeParams.begin(), typeParams.end(), begin());
1457 }
1458
1459 ObjCTypeParamList *ObjCTypeParamList::create(
1460 ASTContext &ctx,
1461 SourceLocation lAngleLoc,
1462 ArrayRef<ObjCTypeParamDecl *> typeParams,
1463 SourceLocation rAngleLoc) {
1464 void *mem =
1465 ctx.Allocate(totalSizeToAlloc<ObjCTypeParamDecl *>(typeParams.size()),
1466 alignof(ObjCTypeParamList));
1467 return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc);
1468 }
1469
1470 void ObjCTypeParamList::gatherDefaultTypeArgs(
1471 SmallVectorImpl<QualType> &typeArgs) const {
1472 typeArgs.reserve(size());
1473 for (auto typeParam : *this)
1474 typeArgs.push_back(typeParam->getUnderlyingType());
1475 }
1476
1477 //===----------------------------------------------------------------------===//
1478 // ObjCInterfaceDecl
1479 //===----------------------------------------------------------------------===//
1480
1481 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
1482 DeclContext *DC,
1483 SourceLocation atLoc,
1484 IdentifierInfo *Id,
1485 ObjCTypeParamList *typeParamList,
1486 ObjCInterfaceDecl *PrevDecl,
1487 SourceLocation ClassLoc,
1488 bool isInternal){
1489 auto *Result = new (C, DC)
1490 ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl,
1491 isInternal);
1492 Result->Data.setInt(!C.getLangOpts().Modules);
1493 C.getObjCInterfaceType(Result, PrevDecl);
1494 return Result;
1495 }
1496
1497 ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C,
1498 unsigned ID) {
1499 auto *Result = new (C, ID)
1500 ObjCInterfaceDecl(C, nullptr, SourceLocation(), nullptr, nullptr,
1501 SourceLocation(), nullptr, false);
1502 Result->Data.setInt(!C.getLangOpts().Modules);
1503 return Result;
1504 }
1505
1506 ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
1507 SourceLocation AtLoc, IdentifierInfo *Id,
1508 ObjCTypeParamList *typeParamList,
1509 SourceLocation CLoc,
1510 ObjCInterfaceDecl *PrevDecl,
1511 bool IsInternal)
1512 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
1513 redeclarable_base(C) {
1514 setPreviousDecl(PrevDecl);
1515
1516 // Copy the 'data' pointer over.
1517 if (PrevDecl)
1518 Data = PrevDecl->Data;
1519
1520 setImplicit(IsInternal);
1521
1522 setTypeParamList(typeParamList);
1523 }
1524
1525 void ObjCInterfaceDecl::LoadExternalDefinition() const {
1526 assert(data().ExternallyCompleted && "Class is not externally completed");
1527 data().ExternallyCompleted = false;
1528 getASTContext().getExternalSource()->CompleteType(
1529 const_cast<ObjCInterfaceDecl *>(this));
1530 }
1531
1532 void ObjCInterfaceDecl::setExternallyCompleted() {
1533 assert(getASTContext().getExternalSource() &&
1534 "Class can't be externally completed without an external source");
1535 assert(hasDefinition() &&
1536 "Forward declarations can't be externally completed");
1537 data().ExternallyCompleted = true;
1538 }
1539
1540 void ObjCInterfaceDecl::setHasDesignatedInitializers() {
1541 // Check for a complete definition and recover if not so.
1542 if (!isThisDeclarationADefinition())
1543 return;
1544 data().HasDesignatedInitializers = true;
1545 }
1546
1547 bool ObjCInterfaceDecl::hasDesignatedInitializers() const {
1548 // Check for a complete definition and recover if not so.
1549 if (!isThisDeclarationADefinition())
1550 return false;
1551 if (data().ExternallyCompleted)
1552 LoadExternalDefinition();
1553
1554 return data().HasDesignatedInitializers;
1555 }
1556
1557 StringRef
1558 ObjCInterfaceDecl::getObjCRuntimeNameAsString() const {
1559 if (const auto *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1560 return ObjCRTName->getMetadataName();
1561
1562 return getName();
1563 }
1564
1565 StringRef
1566 ObjCImplementationDecl::getObjCRuntimeNameAsString() const {
1567 if (ObjCInterfaceDecl *ID =
1568 const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
1569 return ID->getObjCRuntimeNameAsString();
1570
1571 return getName();
1572 }
1573
1574 ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
1575 if (const ObjCInterfaceDecl *Def = getDefinition()) {
1576 if (data().ExternallyCompleted)
1577 LoadExternalDefinition();
1578
1579 return getASTContext().getObjCImplementation(
1580 const_cast<ObjCInterfaceDecl*>(Def));
1581 }
1582
1583 // FIXME: Should make sure no callers ever do this.
1584 return nullptr;
1585 }
1586
1587 void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
1588 getASTContext().setObjCImplementation(getDefinition(), ImplD);
1589 }
1590
1591 namespace {
1592
1593 struct SynthesizeIvarChunk {
1594 uint64_t Size;
1595 ObjCIvarDecl *Ivar;
1596
1597 SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
1598 : Size(size), Ivar(ivar) {}
1599 };
1600
1601 bool operator<(const SynthesizeIvarChunk & LHS,
1602 const SynthesizeIvarChunk &RHS) {
1603 return LHS.Size < RHS.Size;
1604 }
1605
1606 } // namespace
1607
1608 /// all_declared_ivar_begin - return first ivar declared in this class,
1609 /// its extensions and its implementation. Lazily build the list on first
1610 /// access.
1611 ///
1612 /// Caveat: The list returned by this method reflects the current
1613 /// state of the parser. The cache will be updated for every ivar
1614 /// added by an extension or the implementation when they are
1615 /// encountered.
1616 /// See also ObjCIvarDecl::Create().
1617 ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
1618 // FIXME: Should make sure no callers ever do this.
1619 if (!hasDefinition())
1620 return nullptr;
1621
1622 ObjCIvarDecl *curIvar = nullptr;
1623 if (!data().IvarList) {
1624 if (!ivar_empty()) {
1625 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
1626 data().IvarList = *I; ++I;
1627 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
1628 curIvar->setNextIvar(*I);
1629 }
1630
1631 for (const auto *Ext : known_extensions()) {
1632 if (!Ext->ivar_empty()) {
1633 ObjCCategoryDecl::ivar_iterator
1634 I = Ext->ivar_begin(),
1635 E = Ext->ivar_end();
1636 if (!data().IvarList) {
1637 data().IvarList = *I; ++I;
1638 curIvar = data().IvarList;
1639 }
1640 for ( ;I != E; curIvar = *I, ++I)
1641 curIvar->setNextIvar(*I);
1642 }
1643 }
1644 data().IvarListMissingImplementation = true;
1645 }
1646
1647 // cached and complete!
1648 if (!data().IvarListMissingImplementation)
1649 return data().IvarList;
1650
1651 if (ObjCImplementationDecl *ImplDecl = getImplementation()) {
1652 data().IvarListMissingImplementation = false;
1653 if (!ImplDecl->ivar_empty()) {
1654 SmallVector<SynthesizeIvarChunk, 16> layout;
1655 for (auto *IV : ImplDecl->ivars()) {
1656 if (IV->getSynthesize() && !IV->isInvalidDecl()) {
1657 layout.push_back(SynthesizeIvarChunk(
1658 IV->getASTContext().getTypeSize(IV->getType()), IV));
1659 continue;
1660 }
1661 if (!data().IvarList)
1662 data().IvarList = IV;
1663 else
1664 curIvar->setNextIvar(IV);
1665 curIvar = IV;
1666 }
1667
1668 if (!layout.empty()) {
1669 // Order synthesized ivars by their size.
1670 llvm::stable_sort(layout);
1671 unsigned Ix = 0, EIx = layout.size();
1672 if (!data().IvarList) {
1673 data().IvarList = layout[0].Ivar; Ix++;
1674 curIvar = data().IvarList;
1675 }
1676 for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
1677 curIvar->setNextIvar(layout[Ix].Ivar);
1678 }
1679 }
1680 }
1681 return data().IvarList;
1682 }
1683
1684 /// FindCategoryDeclaration - Finds category declaration in the list of
1685 /// categories for this class and returns it. Name of the category is passed
1686 /// in 'CategoryId'. If category not found, return 0;
1687 ///
1688 ObjCCategoryDecl *
1689 ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
1690 // FIXME: Should make sure no callers ever do this.
1691 if (!hasDefinition())
1692 return nullptr;
1693
1694 if (data().ExternallyCompleted)
1695 LoadExternalDefinition();
1696
1697 for (auto *Cat : visible_categories())
1698 if (Cat->getIdentifier() == CategoryId)
1699 return Cat;
1700
1701 return nullptr;
1702 }
1703
1704 ObjCMethodDecl *
1705 ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
1706 for (const auto *Cat : visible_categories()) {
1707 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1708 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
1709 return MD;
1710 }
1711
1712 return nullptr;
1713 }
1714
1715 ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
1716 for (const auto *Cat : visible_categories()) {
1717 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation())
1718 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
1719 return MD;
1720 }
1721
1722 return nullptr;
1723 }
1724
1725 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1726 /// has been implemented in IDecl class, its super class or categories (if
1727 /// lookupCategory is true).
1728 bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1729 bool lookupCategory,
1730 bool RHSIsQualifiedID) {
1731 if (!hasDefinition())
1732 return false;
1733
1734 ObjCInterfaceDecl *IDecl = this;
1735 // 1st, look up the class.
1736 for (auto *PI : IDecl->protocols()){
1737 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1738 return true;
1739 // This is dubious and is added to be compatible with gcc. In gcc, it is
1740 // also allowed assigning a protocol-qualified 'id' type to a LHS object
1741 // when protocol in qualified LHS is in list of protocols in the rhs 'id'
1742 // object. This IMO, should be a bug.
1743 // FIXME: Treat this as an extension, and flag this as an error when GCC
1744 // extensions are not enabled.
1745 if (RHSIsQualifiedID &&
1746 getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
1747 return true;
1748 }
1749
1750 // 2nd, look up the category.
1751 if (lookupCategory)
1752 for (const auto *Cat : visible_categories()) {
1753 for (auto *PI : Cat->protocols())
1754 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
1755 return true;
1756 }
1757
1758 // 3rd, look up the super class(s)
1759 if (IDecl->getSuperClass())
1760 return
1761 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
1762 RHSIsQualifiedID);
1763
1764 return false;
1765 }
1766
1767 //===----------------------------------------------------------------------===//
1768 // ObjCIvarDecl
1769 //===----------------------------------------------------------------------===//
1770
1771 void ObjCIvarDecl::anchor() {}
1772
1773 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
1774 SourceLocation StartLoc,
1775 SourceLocation IdLoc, IdentifierInfo *Id,
1776 QualType T, TypeSourceInfo *TInfo,
1777 AccessControl ac, Expr *BW,
1778 bool synthesized) {
1779 if (DC) {
1780 // Ivar's can only appear in interfaces, implementations (via synthesized
1781 // properties), and class extensions (via direct declaration, or synthesized
1782 // properties).
1783 //
1784 // FIXME: This should really be asserting this:
1785 // (isa<ObjCCategoryDecl>(DC) &&
1786 // cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
1787 // but unfortunately we sometimes place ivars into non-class extension
1788 // categories on error. This breaks an AST invariant, and should not be
1789 // fixed.
1790 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
1791 isa<ObjCCategoryDecl>(DC)) &&
1792 "Invalid ivar decl context!");
1793 // Once a new ivar is created in any of class/class-extension/implementation
1794 // decl contexts, the previously built IvarList must be rebuilt.
1795 auto *ID = dyn_cast<ObjCInterfaceDecl>(DC);
1796 if (!ID) {
1797 if (auto *IM = dyn_cast<ObjCImplementationDecl>(DC))
1798 ID = IM->getClassInterface();
1799 else
1800 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface();
1801 }
1802 ID->setIvarList(nullptr);
1803 }
1804
1805 return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
1806 synthesized);
1807 }
1808
1809 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1810 return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(),
1811 nullptr, QualType(), nullptr,
1812 ObjCIvarDecl::None, nullptr, false);
1813 }
1814
1815 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
1816 const auto *DC = cast<ObjCContainerDecl>(getDeclContext());
1817
1818 switch (DC->getKind()) {
1819 default:
1820 case ObjCCategoryImpl:
1821 case ObjCProtocol:
1822 llvm_unreachable("invalid ivar container!");
1823
1824 // Ivars can only appear in class extension categories.
1825 case ObjCCategory: {
1826 const auto *CD = cast<ObjCCategoryDecl>(DC);
1827 assert(CD->IsClassExtension() && "invalid container for ivar!");
1828 return CD->getClassInterface();
1829 }
1830
1831 case ObjCImplementation:
1832 return cast<ObjCImplementationDecl>(DC)->getClassInterface();
1833
1834 case ObjCInterface:
1835 return cast<ObjCInterfaceDecl>(DC);
1836 }
1837 }
1838
1839 QualType ObjCIvarDecl::getUsageType(QualType objectType) const {
1840 return getType().substObjCMemberType(objectType, getDeclContext(),
1841 ObjCSubstitutionContext::Property);
1842 }
1843
1844 //===----------------------------------------------------------------------===//
1845 // ObjCAtDefsFieldDecl
1846 //===----------------------------------------------------------------------===//
1847
1848 void ObjCAtDefsFieldDecl::anchor() {}
1849
1850 ObjCAtDefsFieldDecl
1851 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
1852 SourceLocation StartLoc, SourceLocation IdLoc,
1853 IdentifierInfo *Id, QualType T, Expr *BW) {
1854 return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
1855 }
1856
1857 ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
1858 unsigned ID) {
1859 return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(),
1860 SourceLocation(), nullptr, QualType(),
1861 nullptr);
1862 }
1863
1864 //===----------------------------------------------------------------------===//
1865 // ObjCProtocolDecl
1866 //===----------------------------------------------------------------------===//
1867
1868 void ObjCProtocolDecl::anchor() {}
1869
1870 ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
1871 IdentifierInfo *Id, SourceLocation nameLoc,
1872 SourceLocation atStartLoc,
1873 ObjCProtocolDecl *PrevDecl)
1874 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
1875 redeclarable_base(C) {
1876 setPreviousDecl(PrevDecl);
1877 if (PrevDecl)
1878 Data = PrevDecl->Data;
1879 }
1880
1881 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
1882 IdentifierInfo *Id,
1883 SourceLocation nameLoc,
1884 SourceLocation atStartLoc,
1885 ObjCProtocolDecl *PrevDecl) {
1886 auto *Result =
1887 new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl);
1888 Result->Data.setInt(!C.getLangOpts().Modules);
1889 return Result;
1890 }
1891
1892 ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
1893 unsigned ID) {
1894 ObjCProtocolDecl *Result =
1895 new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(),
1896 SourceLocation(), nullptr);
1897 Result->Data.setInt(!C.getLangOpts().Modules);
1898 return Result;
1899 }
1900
1901 ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
1902 ObjCProtocolDecl *PDecl = this;
1903
1904 if (Name == getIdentifier())
1905 return PDecl;
1906
1907 for (auto *I : protocols())
1908 if ((PDecl = I->lookupProtocolNamed(Name)))
1909 return PDecl;
1910
1911 return nullptr;
1912 }
1913
1914 // lookupMethod - Lookup a instance/class method in the protocol and protocols
1915 // it inherited.
1916 ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
1917 bool isInstance) const {
1918 ObjCMethodDecl *MethodDecl = nullptr;
1919
1920 // If there is no definition or the definition is hidden, we don't find
1921 // anything.
1922 const ObjCProtocolDecl *Def = getDefinition();
1923 if (!Def || Def->isHidden())
1924 return nullptr;
1925
1926 if ((MethodDecl = getMethod(Sel, isInstance)))
1927 return MethodDecl;
1928
1929 for (const auto *I : protocols())
1930 if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
1931 return MethodDecl;
1932 return nullptr;
1933 }
1934
1935 void ObjCProtocolDecl::allocateDefinitionData() {
1936 assert(!Data.getPointer() && "Protocol already has a definition!");
1937 Data.setPointer(new (getASTContext()) DefinitionData);
1938 Data.getPointer()->Definition = this;
1939 }
1940
1941 void ObjCProtocolDecl::startDefinition() {
1942 allocateDefinitionData();
1943
1944 // Update all of the declarations with a pointer to the definition.
1945 for (auto *RD : redecls())
1946 RD->Data = this->Data;
1947 }
1948
1949 void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
1950 PropertyDeclOrder &PO) const {
1951 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1952 for (auto *Prop : PDecl->properties()) {
1953 // Insert into PM if not there already.
1954 PM.insert(std::make_pair(
1955 std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()),
1956 Prop));
1957 PO.push_back(Prop);
1958 }
1959 // Scan through protocol's protocols.
1960 for (const auto *PI : PDecl->protocols())
1961 PI->collectPropertiesToImplement(PM, PO);
1962 }
1963 }
1964
1965 void ObjCProtocolDecl::collectInheritedProtocolProperties(
1966 const ObjCPropertyDecl *Property, ProtocolPropertySet &PS,
1967 PropertyDeclOrder &PO) const {
1968 if (const ObjCProtocolDecl *PDecl = getDefinition()) {
1969 if (!PS.insert(PDecl).second)
1970 return;
1971 for (auto *Prop : PDecl->properties()) {
1972 if (Prop == Property)
1973 continue;
1974 if (Prop->getIdentifier() == Property->getIdentifier()) {
1975 PO.push_back(Prop);
1976 return;
1977 }
1978 }
1979 // Scan through protocol's protocols which did not have a matching property.
1980 for (const auto *PI : PDecl->protocols())
1981 PI->collectInheritedProtocolProperties(Property, PS, PO);
1982 }
1983 }
1984
1985 StringRef
1986 ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
1987 if (const auto *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
1988 return ObjCRTName->getMetadataName();
1989
1990 return getName();
1991 }
1992
1993 //===----------------------------------------------------------------------===//
1994 // ObjCCategoryDecl
1995 //===----------------------------------------------------------------------===//
1996
1997 void ObjCCategoryDecl::anchor() {}
1998
1999 ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
2000 SourceLocation ClassNameLoc,
2001 SourceLocation CategoryNameLoc,
2002 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
2003 ObjCTypeParamList *typeParamList,
2004 SourceLocation IvarLBraceLoc,
2005 SourceLocation IvarRBraceLoc)
2006 : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
2007 ClassInterface(IDecl), CategoryNameLoc(CategoryNameLoc),
2008 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
2009 setTypeParamList(typeParamList);
2010 }
2011
2012 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
2013 SourceLocation AtLoc,
2014 SourceLocation ClassNameLoc,
2015 SourceLocation CategoryNameLoc,
2016 IdentifierInfo *Id,
2017 ObjCInterfaceDecl *IDecl,
2018 ObjCTypeParamList *typeParamList,
2019 SourceLocation IvarLBraceLoc,
2020 SourceLocation IvarRBraceLoc) {
2021 auto *CatDecl =
2022 new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
2023 IDecl, typeParamList, IvarLBraceLoc,
2024 IvarRBraceLoc);
2025 if (IDecl) {
2026 // Link this category into its class's category list.
2027 CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
2028 if (IDecl->hasDefinition()) {
2029 IDecl->setCategoryListRaw(CatDecl);
2030 if (ASTMutationListener *L = C.getASTMutationListener())
2031 L->AddedObjCCategoryToInterface(CatDecl, IDecl);
2032 }
2033 }
2034
2035 return CatDecl;
2036 }
2037
2038 ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
2039 unsigned ID) {
2040 return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(),
2041 SourceLocation(), SourceLocation(),
2042 nullptr, nullptr, nullptr);
2043 }
2044
2045 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
2046 return getASTContext().getObjCImplementation(
2047 const_cast<ObjCCategoryDecl*>(this));
2048 }
2049
2050 void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
2051 getASTContext().setObjCImplementation(this, ImplD);
2052 }
2053
2054 void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) {
2055 TypeParamList = TPL;
2056 if (!TPL)
2057 return;
2058 // Set the declaration context of each of the type parameters.
2059 for (auto *typeParam : *TypeParamList)
2060 typeParam->setDeclContext(this);
2061 }
2062
2063 //===----------------------------------------------------------------------===//
2064 // ObjCCategoryImplDecl
2065 //===----------------------------------------------------------------------===//
2066
2067 void ObjCCategoryImplDecl::anchor() {}
2068
2069 ObjCCategoryImplDecl *
2070 ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
2071 IdentifierInfo *Id,
2072 ObjCInterfaceDecl *ClassInterface,
2073 SourceLocation nameLoc,
2074 SourceLocation atStartLoc,
2075 SourceLocation CategoryNameLoc) {
2076 if (ClassInterface && ClassInterface->hasDefinition())
2077 ClassInterface = ClassInterface->getDefinition();
2078 return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
2079 atStartLoc, CategoryNameLoc);
2080 }
2081
2082 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C,
2083 unsigned ID) {
2084 return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr,
2085 SourceLocation(), SourceLocation(),
2086 SourceLocation());
2087 }
2088
2089 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
2090 // The class interface might be NULL if we are working with invalid code.
2091 if (const ObjCInterfaceDecl *ID = getClassInterface())
2092 return ID->FindCategoryDeclaration(getIdentifier());
2093 return nullptr;
2094 }
2095
2096 void ObjCImplDecl::anchor() {}
2097
2098 void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
2099 // FIXME: The context should be correct before we get here.
2100 property->setLexicalDeclContext(this);
2101 addDecl(property);
2102 }
2103
2104 void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
2105 ASTContext &Ctx = getASTContext();
2106
2107 if (auto *ImplD = dyn_cast_or_null<ObjCImplementationDecl>(this)) {
2108 if (IFace)
2109 Ctx.setObjCImplementation(IFace, ImplD);
2110
2111 } else if (auto *ImplD = dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
2112 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
2113 Ctx.setObjCImplementation(CD, ImplD);
2114 }
2115
2116 ClassInterface = IFace;
2117 }
2118
2119 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
2120 /// properties implemented in this \@implementation block and returns
2121 /// the implemented property that uses it.
2122 ObjCPropertyImplDecl *ObjCImplDecl::
2123 FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
2124 for (auto *PID : property_impls())
2125 if (PID->getPropertyIvarDecl() &&
2126 PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
2127 return PID;
2128 return nullptr;
2129 }
2130
2131 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
2132 /// added to the list of those properties \@synthesized/\@dynamic in this
2133 /// category \@implementation block.
2134 ObjCPropertyImplDecl *ObjCImplDecl::
2135 FindPropertyImplDecl(IdentifierInfo *Id,
2136 ObjCPropertyQueryKind QueryKind) const {
2137 ObjCPropertyImplDecl *ClassPropImpl = nullptr;
2138 for (auto *PID : property_impls())
2139 // If queryKind is unknown, we return the instance property if one
2140 // exists; otherwise we return the class property.
2141 if (PID->getPropertyDecl()->getIdentifier() == Id) {
2142 if ((QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown &&
2143 !PID->getPropertyDecl()->isClassProperty()) ||
2144 (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_class &&
2145 PID->getPropertyDecl()->isClassProperty()) ||
2146 (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance &&
2147 !PID->getPropertyDecl()->isClassProperty()))
2148 return PID;
2149
2150 if (PID->getPropertyDecl()->isClassProperty())
2151 ClassPropImpl = PID;
2152 }
2153
2154 if (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown)
2155 // We can't find the instance property, return the class property.
2156 return ClassPropImpl;
2157
2158 return nullptr;
2159 }
2160
2161 raw_ostream &clang::operator<<(raw_ostream &OS,
2162 const ObjCCategoryImplDecl &CID) {
2163 OS << CID.getName();
2164 return OS;
2165 }
2166
2167 //===----------------------------------------------------------------------===//
2168 // ObjCImplementationDecl
2169 //===----------------------------------------------------------------------===//
2170
2171 void ObjCImplementationDecl::anchor() {}
2172
2173 ObjCImplementationDecl *
2174 ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
2175 ObjCInterfaceDecl *ClassInterface,
2176 ObjCInterfaceDecl *SuperDecl,
2177 SourceLocation nameLoc,
2178 SourceLocation atStartLoc,
2179 SourceLocation superLoc,
2180 SourceLocation IvarLBraceLoc,
2181 SourceLocation IvarRBraceLoc) {
2182 if (ClassInterface && ClassInterface->hasDefinition())
2183 ClassInterface = ClassInterface->getDefinition();
2184 return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
2185 nameLoc, atStartLoc, superLoc,
2186 IvarLBraceLoc, IvarRBraceLoc);
2187 }
2188
2189 ObjCImplementationDecl *
2190 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2191 return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr,
2192 SourceLocation(), SourceLocation());
2193 }
2194
2195 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
2196 CXXCtorInitializer ** initializers,
2197 unsigned numInitializers) {
2198 if (numInitializers > 0) {
2199 NumIvarInitializers = numInitializers;
2200 auto **ivarInitializers = new (C) CXXCtorInitializer*[NumIvarInitializers];
2201 memcpy(ivarInitializers, initializers,
2202 numInitializers * sizeof(CXXCtorInitializer*));
2203 IvarInitializers = ivarInitializers;
2204 }
2205 }
2206
2207 ObjCImplementationDecl::init_const_iterator
2208 ObjCImplementationDecl::init_begin() const {
2209 return IvarInitializers.get(getASTContext().getExternalSource());
2210 }
2211
2212 raw_ostream &clang::operator<<(raw_ostream &OS,
2213 const ObjCImplementationDecl &ID) {
2214 OS << ID.getName();
2215 return OS;
2216 }
2217
2218 //===----------------------------------------------------------------------===//
2219 // ObjCCompatibleAliasDecl
2220 //===----------------------------------------------------------------------===//
2221
2222 void ObjCCompatibleAliasDecl::anchor() {}
2223
2224 ObjCCompatibleAliasDecl *
2225 ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
2226 SourceLocation L,
2227 IdentifierInfo *Id,
2228 ObjCInterfaceDecl* AliasedClass) {
2229 return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
2230 }
2231
2232 ObjCCompatibleAliasDecl *
2233 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2234 return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(),
2235 nullptr, nullptr);
2236 }
2237
2238 //===----------------------------------------------------------------------===//
2239 // ObjCPropertyDecl
2240 //===----------------------------------------------------------------------===//
2241
2242 void ObjCPropertyDecl::anchor() {}
2243
2244 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
2245 SourceLocation L,
2246 IdentifierInfo *Id,
2247 SourceLocation AtLoc,
2248 SourceLocation LParenLoc,
2249 QualType T,
2250 TypeSourceInfo *TSI,
2251 PropertyControl propControl) {
2252 return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI,
2253 propControl);
2254 }
2255
2256 ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
2257 unsigned ID) {
2258 return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr,
2259 SourceLocation(), SourceLocation(),
2260 QualType(), nullptr, None);
2261 }
2262
2263 QualType ObjCPropertyDecl::getUsageType(QualType objectType) const {
2264 return DeclType.substObjCMemberType(objectType, getDeclContext(),
2265 ObjCSubstitutionContext::Property);
2266 }
2267
2268 //===----------------------------------------------------------------------===//
2269 // ObjCPropertyImplDecl
2270 //===----------------------------------------------------------------------===//
2271
2272 ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
2273 DeclContext *DC,
2274 SourceLocation atLoc,
2275 SourceLocation L,
2276 ObjCPropertyDecl *property,
2277 Kind PK,
2278 ObjCIvarDecl *ivar,
2279 SourceLocation ivarLoc) {
2280 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
2281 ivarLoc);
2282 }
2283
2284 ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
2285 unsigned ID) {
2286 return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(),
2287 SourceLocation(), nullptr, Dynamic,
2288 nullptr, SourceLocation());
2289 }
2290
2291 SourceRange ObjCPropertyImplDecl::getSourceRange() const {
2292 SourceLocation EndLoc = getLocation();
2293 if (IvarLoc.isValid())
2294 EndLoc = IvarLoc;
2295
2296 return SourceRange(AtLoc, EndLoc);
2297 }
clang::OMF_finalize
Definition: IdentifierTable.h:641
clang::Decl::OBJC_TQ_None
Definition: DeclBase.h:201
clang::Builtin::ID
ID
Definition: Builtins.h:46
clang::ObjCProtocolDecl::lookupMethod
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance) const
Definition: DeclObjC.cpp:1916
ASTContext.h
Defines the clang::ASTContext interface.
clang::OMF_self
Definition: IdentifierTable.h:645
clang::ObjCInterfaceDecl::hasDefinition
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1549
clang::ObjCInterfaceDecl::setExternallyCompleted
void setExternallyCompleted()
Indicate that this Objective-C class is complete, but that the external AST source will be responsibl...
Definition: DeclObjC.cpp:1532
clang::Decl::setImplicit
void setImplicit(bool I=true)
Definition: DeclBase.h:559
clang::ObjCInterfaceDecl::protocols
protocol_range protocols() const
Definition: DeclObjC.h:1380
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:685
clang::ASTContext::getObjCIdType
QualType getObjCIdType() const
Represents the Objective-CC id type.
Definition: ASTContext.h:1874
clang::SourceLocation::getRawEncoding
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
Definition: SourceLocation.h:144
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:654
clang::ObjCIvarDecl::CreateDeserialized
static ObjCIvarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1809
clang::ObjCInterfaceDecl::getDesignatedInitializers
void getDesignatedInitializers(llvm::SmallVectorImpl< const ObjCMethodDecl *> &Methods) const
Returns the designated initializers for the interface.
Definition: DeclObjC.cpp:538
clang::ObjCMethodDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1155
clang::ObjCInterfaceDecl::startDefinition
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:610
clang::Decl::getBody
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
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::ObjCInterfaceDecl::getSuperClassLoc
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:357
Type.h
C Language Family Type Representation.
clang::SelLoc_NonStandard
Non-standard.
Definition: SelectorLocationsKind.h:29
clang::Qualifiers::setObjCLifetime
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:336
clang::ObjCMethodDecl::param_type_iterator
llvm::mapped_iterator< param_const_iterator, GetTypeFn > param_type_iterator
Definition: DeclObjC.h:394
clang::ASTContext::getQualifiedType
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1958
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
clang::ObjCPropertyImplDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.cpp:2291
P
StringRef P
Definition: ASTMatchersInternal.cpp:485
clang::NamedDecl::NamedDecl
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition: Decl.h:235
clang::ObjCMethodDecl::Create
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isSynthesizedAccessorStub=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:808
clang::ObjCProtocolDecl::Create
static ObjCProtocolDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl)
Definition: DeclObjC.cpp:1881
clang::ObjCInterfaceDecl::known_categories
known_categories_range known_categories() const
Definition: DeclObjC.h:1701
clang::ObjCPropertyDecl::Create
static ObjCPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation AtLocation, SourceLocation LParenLocation, QualType T, TypeSourceInfo *TSI, PropertyControl propControl=None)
Definition: DeclObjC.cpp:2244
clang::ObjCInterfaceDecl::getTypeParamList
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameters of this class.
Definition: DeclObjC.cpp:307
clang::ObjCListBase::List
void ** List
List is an array of pointers to objects that are not owned by this object.
Definition: DeclObjC.h:62
clang::operator<<
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:346
clang::ObjCInterfaceDecl::lookupNestedProtocol
ObjCProtocolDecl * lookupNestedProtocol(IdentifierInfo *Name)
Definition: DeclObjC.cpp:670
clang::ObjCInterfaceDecl::isDesignatedInitializer
bool isDesignatedInitializer(Selector Sel, const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the given selector is a designated initializer for the interface. ...
Definition: DeclObjC.cpp:560
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:425
clang::QualType::withConst
QualType withConst() const
Definition: Type.h:826
DeclObjC.h
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6227
clang::ObjCMethodDecl::isOverriding
bool isOverriding() const
Whether this method overrides any other in the class hierarchy.
Definition: DeclObjC.h:459
clang::ObjCMethodDecl::createImplicitParams
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implict parameters. ...
Definition: DeclObjC.cpp:1134
clang::ObjCImplementationDecl::init_const_iterator
CXXCtorInitializer *const * init_const_iterator
init_const_iterator - Iterates through the ivar initializer list.
Definition: DeclObjC.h:2623
clang::ObjCCategoryDecl::setImplementation
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2050
clang::ObjCCategoryDecl::getImplementation
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:2045
clang::ImplicitParamDecl::ObjCCmd
Parameter for Objective-C &#39;_cmd&#39; argument.
Definition: Decl.h:1543
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
clang::ASTContext::getObjCImplementation
ObjCImplementationDecl * getObjCImplementation(ObjCInterfaceDecl *D)
Get the implementation of the ObjCInterfaceDecl D, or nullptr if none exists.
Definition: ASTContext.cpp:2726
clang::ObjCInterfaceDecl::ClassImplementsProtocol
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:1728
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:553
clang::ASTContext::getObjCClassType
QualType getObjCClassType() const
Represents the Objective-C Class type.
Definition: ASTContext.h:1896
clang::ObjCPropertyDecl::findPropertyDecl
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Definition: DeclObjC.cpp:176
getDefinition
static const NamedDecl * getDefinition(const Decl *D)
Definition: SemaDecl.cpp:2613
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1595
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:143
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
clang::Redeclarable< ObjCInterfaceDecl >
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:57
clang::ObjCObjectType
Represents a class type in Objective C.
Definition: Type.h:5694
clang::ObjCMethodDecl::getSelfType
QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID, bool &selfIsPseudoStrong, bool &selfIsConsumed) const
Definition: DeclObjC.cpp:1089
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1195
clang::ObjCMethodFamily
ObjCMethodFamily
A family of Objective-C methods.
Definition: IdentifierTable.h:623
clang::Type::isObjCIdType
bool isObjCIdType() const
Definition: Type.h:6651
clang::OMF_retainCount
Definition: IdentifierTable.h:644
clang::ObjCInterfaceDecl::setTypeParamList
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:328
clang::ObjCMethodDecl::getReturnTypeSourceRange
SourceRange getReturnTypeSourceRange() const
Definition: DeclObjC.cpp:1167
clang::ObjCContainerDecl::instance_methods
instmeth_range instance_methods() const
Definition: DeclObjC.h:1068
clang::ObjCProtocolDecl::getObjCRuntimeNameAsString
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for protocol&#39;s metadata.
Definition: DeclObjC.cpp:1986
clang::DeclContextLookupResult::end
iterator end() const
Definition: DeclBase.h:1237
clang::ObjCContainerDecl::properties
prop_range properties() const
Definition: DeclObjC.h:1002
Category
int Category
Definition: Format.cpp:1828
clang::Type::isObjCSelType
bool isObjCSelType() const
Definition: Type.h:6663
clang::ObjCProtocolDecl::startDefinition
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:1941
clang::ObjCInterfaceDecl::visible_categories
visible_categories_range visible_categories() const
Definition: DeclObjC.h:1667
llvm::SmallVectorImpl
Definition: LLVM.h:36
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:580
clang::ObjCIvarDecl::AccessControl
AccessControl
Definition: DeclObjC.h:1963
clang::ObjCProtocolList::set
void set(ObjCProtocolDecl *const *InList, unsigned Elts, const SourceLocation *Locs, ASTContext &Ctx)
Definition: DeclObjC.cpp:53
clang::ASTContext::ProtocolCompatibleWithProtocol
bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, ObjCProtocolDecl *rProto) const
ProtocolCompatibleWithProtocol - return &#39;true&#39; if &#39;lProto&#39; is in the inheritance hierarchy of &#39;rProto...
Definition: ASTContext.cpp:8161
clang::ObjCMethodDecl::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:997
clang::ObjCMethodDecl::isThisDeclarationADesignatedInitializer
bool isThisDeclarationADesignatedInitializer() const
Returns true if this specific method declaration is marked with the designated initializer attribute...
Definition: DeclObjC.cpp:830
clang::ObjCInterfaceDecl::collectPropertiesToImplement
void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:392
clang::ObjCMethodDecl::isDirectMethod
bool isDirectMethod() const
True if the method is tagged as objc_direct.
Definition: DeclObjC.cpp:826
clang::InvalidObjCMethodFamily
Definition: IdentifierTable.h:657
clang::ObjCInterfaceDecl::Create
static ObjCInterfaceDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, ObjCTypeParamList *typeParamList, ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc=SourceLocation(), bool isInternal=false)
Definition: DeclObjC.cpp:1481
clang::ObjCListBase::set
void set(void *const *InList, unsigned Elts, ASTContext &Ctx)
Definition: DeclObjC.cpp:44
clang::ObjCContainerDecl
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:983
clang::ObjCCategoryDecl::Create
static ObjCCategoryDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation AtLoc, SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, IdentifierInfo *Id, ObjCInterfaceDecl *IDecl, ObjCTypeParamList *typeParamList, SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:2012
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::ObjCPropertyImplDecl::Create
static ObjCPropertyImplDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation atLoc, SourceLocation L, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc)
Definition: DeclObjC.cpp:2272
clang::ObjCInterfaceDecl::isObjCRequiresPropertyDefs
const ObjCInterfaceDecl * isObjCRequiresPropertyDefs() const
isObjCRequiresPropertyDefs - Checks that a class or one of its super classes must not be auto-synthes...
Definition: DeclObjC.cpp:422
clang::ObjCAtDefsFieldDecl::Create
static ObjCAtDefsFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, Expr *BW)
Definition: DeclObjC.cpp:1851
clang::ObjCCategoryImplDecl::CreateDeserialized
static ObjCCategoryImplDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2082
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
Definition: RangeSelector.cpp:186
clang::ObjCInterfaceDecl::getCategoryListRaw
ObjCCategoryDecl * getCategoryListRaw() const
Retrieve the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1798
clang::ObjCProtocolDecl::getDefinition
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2224
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6256
clang::ObjCMethodDecl::getOverriddenMethods
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
Definition: DeclObjC.cpp:1296
clang::ObjCMethodDecl::setAsRedeclaration
void setAsRedeclaration(const ObjCMethodDecl *PrevMethod)
Definition: DeclObjC.cpp:859
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2078
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1186
llvm::ArrayRef
Definition: LLVM.h:31
llvm::SmallString< 128 >
ASTMutationListener.h
clang::ObjCMethodDecl::setMethodParams
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:890
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:877
clang::ObjCMethodDecl::getCanonicalDecl
ObjCMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclObjC.cpp:957
clang::ASTContext::getObjCTypeParamType
QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, ArrayRef< ObjCProtocolDecl *> protocols) const
Definition: ASTContext.cpp:4875
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1612
clang::ObjCMethodDecl::getSelectorLocs
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:884
clang::ImplicitParamDecl::Create
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:4685
clang::ObjCPropertyImplDecl
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2773
clang::OMF_initialize
Definition: IdentifierTable.h:646
clang::ObjCInterfaceDecl::getCategoryInstanceMethod
ObjCMethodDecl * getCategoryInstanceMethod(Selector Sel) const
Definition: DeclObjC.cpp:1705
clang::ObjCInterfaceDecl::getCategoryClassMethod
ObjCMethodDecl * getCategoryClassMethod(Selector Sel) const
Definition: DeclObjC.cpp:1715
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:542
clang::ObjCContainerDecl::ObjCContainerDecl
ObjCContainerDecl(Kind DK, DeclContext *DC, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc)
Definition: DeclObjC.cpp:67
clang::ObjCInterfaceDecl::visible_extensions
visible_extensions_range visible_extensions() const
Definition: DeclObjC.h:1737
clang::ObjCProtocolDecl::lookupProtocolNamed
ObjCProtocolDecl * lookupProtocolNamed(IdentifierInfo *PName)
Definition: DeclObjC.cpp:1901
clang::ObjCCompatibleAliasDecl::CreateDeserialized
static ObjCCompatibleAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2233
clang::ASTContext::getNSObjectName
IdentifierInfo * getNSObjectName() const
Retrieve the identifier &#39;NSObject&#39;.
Definition: ASTContext.h:1699
clang::ObjCCategoryDecl::setTypeParamList
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2054
clang::ObjCPropertyQueryKind::OBJC_PR_query_unknown
clang::ObjCMethodDecl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:991
clang::ObjCIvarDecl::getUsageType
QualType getUsageType(QualType objectType) const
Retrieve the type of this instance variable when viewed as a member of a specific object type...
Definition: DeclObjC.cpp:1839
clang::ObjCIvarDecl::setNextIvar
void setNextIvar(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1994
clang::Expr
This represents one expression.
Definition: Expr.h:108
LangOptions.h
Defines the clang::LangOptions interface.
clang::ObjCPropertyDecl::getSetterName
Selector getSetterName() const
Definition: DeclObjC.h:928
Id
int Id
Definition: ASTDiff.cpp:190
clang::ObjCContainerDecl::HasUserDeclaredSetterMethod
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
clang::ObjCPropertyDecl::getDefaultSynthIvarName
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
Definition: DeclObjC.cpp:224
collectOverriddenMethodsSlow
static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &overridden)
Definition: DeclObjC.cpp:1255
clang::OMF_new
Definition: IdentifierTable.h:635
clang::OMF_retain
Definition: IdentifierTable.h:643
clang::ASTContext::setObjCMethodRedeclaration
void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, const ObjCMethodDecl *Redecl)
Definition: ASTContext.cpp:2763
clang::OMF_copy
Definition: IdentifierTable.h:632
clang::ast_matchers::decl
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchersInternal.cpp:607
clang::OMF_performSelector
Definition: IdentifierTable.h:649
DeclBase.h
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:558
clang::OMF_dealloc
Definition: IdentifierTable.h:640
clang::ObjCTypeParamDecl::Create
static ObjCTypeParamDecl * Create(ASTContext &ctx, DeclContext *dc, ObjCTypeParamVariance variance, SourceLocation varianceLoc, unsigned index, SourceLocation nameLoc, IdentifierInfo *name, SourceLocation colonLoc, TypeSourceInfo *boundInfo)
Definition: DeclObjC.cpp:1410
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:438
clang::OMF_mutableCopy
Definition: IdentifierTable.h:634
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:337
clang::ASTMutationListener
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Definition: ASTMutationListener.h:46
clang::ObjCTypeParamList::create
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl *> typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1459
clang::OMF_release
Definition: IdentifierTable.h:642
clang::ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass
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
TypeLoc.h
Defines the clang::TypeLoc interface and its subclasses.
clang::ASTContext::setObjCImplementation
void setObjCImplementation(ObjCInterfaceDecl *IFaceD, ObjCImplementationDecl *ImplD)
Set the implementation of ObjCInterfaceDecl.
Definition: ASTContext.cpp:2745
clang::ObjCInterfaceDecl::setImplementation
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1587
IdentifierTable.h
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
clang::ObjCInterfaceDecl::mergeClassExtensionProtocolList
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
clang::ObjCInterfaceDecl::lookupInstanceVariable
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:620
Stmt.h
clang::ASTContext::getObjCMethodRedeclaration
const ObjCMethodDecl * getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const
Get the duplicate declaration of a ObjCMethod in the same interface, or null if none exists...
Definition: ASTContext.cpp:2759
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1784
clang::QualType::substObjCMemberType
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1422
clang::ObjCContainerDecl::ProtocolPropertySet
llvm::SmallDenseSet< const ObjCProtocolDecl *, 8 > ProtocolPropertySet
Definition: DeclObjC.h:1120
clang::ASTContext::getObjCInterfaceType
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
Definition: ASTContext.cpp:5003
hasDefinition
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
Definition: DynamicTypeChecker.cpp:145
clang::ObjCMethodDecl::isInstanceMethod
bool isInstanceMethod() const
Definition: DeclObjC.h:423
clang::Selector::getNumArgs
unsigned getNumArgs() const
Definition: IdentifierTable.cpp:430
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:322
clang::ObjCSubstitutionContext::Result
The result type of a method or function.
clang::ObjCTypeParamDecl::CreateDeserialized
static ObjCTypeParamDecl * CreateDeserialized(ASTContext &ctx, unsigned ID)
Definition: DeclObjC.cpp:1426
clang::ObjCPropertyQueryKind::OBJC_PR_query_instance
clang::ObjCTypeParamVariance
ObjCTypeParamVariance
Describes the variance of a given generic parameter.
Definition: DeclObjC.h:546
isIntroducingInitializers
static bool isIntroducingInitializers(const ObjCInterfaceDecl *D)
Definition: DeclObjC.cpp:486
clang::ObjCMethodDecl::CreateDeserialized
static ObjCMethodDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:821
clang::ObjCImplementationDecl::init_begin
init_iterator init_begin()
init_begin() - Retrieve an iterator to the first initializer.
Definition: DeclObjC.h:2635
clang::ObjCIvarDecl::None
Definition: DeclObjC.h:1964
clang::ObjCPropertyDecl::PropertyControl
PropertyControl
Definition: DeclObjC.h:774
clang::ObjCCompatibleAliasDecl::Create
static ObjCCompatibleAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, ObjCInterfaceDecl *aliasedClass)
Definition: DeclObjC.cpp:2225
clang::ObjCMethodDecl::definedInNSObject
bool definedInNSObject(const ASTContext &) const
Is this method defined in the NSObject base class?
Definition: DeclObjC.cpp:835
clang::ObjCProtocolDecl::CreateDeserialized
static ObjCProtocolDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1892
clang::Qualifiers::OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained...
Definition: Type.h:171
Attr.h
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:529
clang::ObjCPropertyQueryKind
ObjCPropertyQueryKind
Definition: DeclObjC.h:729
clang::ObjCContainerDecl::setAtStartLoc
void setAtStartLoc(SourceLocation Loc)
Definition: DeclObjC.h:1131
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:377
clang::ObjCCategoryImplDecl::getCategoryDecl
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2089
clang::ObjCList< ObjCProtocolDecl >
clang::ASTContext::getObjCSelType
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C &#39;SEL&#39; type.
Definition: ASTContext.h:1884
clang::ObjCMethodDecl::getBody
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:855
CollectOverriddenMethodsRecurse
static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &Methods, bool MovedToSuper)
Definition: DeclObjC.cpp:1188
clang::ObjCInterfaceDecl::lookupInheritedClass
ObjCInterfaceDecl * lookupInheritedClass(const IdentifierInfo *ICName)
lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super class whose name is passe...
Definition: DeclObjC.cpp:651
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2294
clang::DeclContext::DeclContext
DeclContext(Decl::Kind K)
Definition: DeclBase.cpp:1006
llvm::SmallVector
Definition: LLVM.h:35
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:741
clang::ObjCImplDecl::FindPropertyImplIvarDecl
ObjCPropertyImplDecl * FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const
FindPropertyImplIvarDecl - This method lookup the ivar in the list of properties implemented in this ...
Definition: DeclObjC.cpp:2123
clang::operator<
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
Definition: DeclarationName.h:540
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1632
clang::ObjCInterfaceDecl::getImplementation
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1574
clang::MultiVersionKind::None
clang::ObjCMethodDecl::isDesignatedInitializerForTheInterface
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:843
clang::ASTContext::Allocate
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:686
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:155
clang::ObjCPropertyDecl::getUsageType
QualType getUsageType(QualType objectType) const
Retrieve the type when this property is used with a specific base object type.
Definition: DeclObjC.cpp:2263
clang::ObjCSubstitutionContext::Property
The type of a property.
clang::Decl::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:948
clang::ObjCProtocolDecl::collectInheritedProtocolProperties
void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property, ProtocolPropertySet &PS, PropertyDeclOrder &PO) const
Definition: DeclObjC.cpp:1965
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ObjCInterfaceDecl::lookupPrivateMethod
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
Definition: DeclObjC.cpp:739
clang::ObjCContainerDecl::FindPropertyDeclaration
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
clang::ObjCTypeParamDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.cpp:1434
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
clang::ImplicitParamDecl::ObjCSelf
Parameter for Objective-C &#39;self&#39; argument.
Definition: Decl.h:1540
clang::ObjCInterfaceDecl::getDefinition
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1563
clang::ObjCTypeParamDecl
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:571
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:432
clang::ObjCImplementationDecl::Create
static ObjCImplementationDecl * Create(ASTContext &C, DeclContext *DC, ObjCInterfaceDecl *classInterface, ObjCInterfaceDecl *superDecl, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation superLoc=SourceLocation(), SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:2174
clang::ObjCCategoryDecl::CreateDeserialized
static ObjCCategoryDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2038
clang::ObjCListBase::NumElts
unsigned NumElts
Definition: DeclObjC.h:63
clang::ObjCIvarDecl::getContainingInterface
const ObjCInterfaceDecl * getContainingInterface() const
Return the class interface that this ivar is logically contained in; this is either the interface whe...
Definition: DeclObjC.cpp:1815
clang::ObjCContainerDecl::getIvarDecl
ObjCIvarDecl * getIvarDecl(IdentifierInfo *Id) const
getIvarDecl - This method looks up an ivar in this ContextDecl.
Definition: DeclObjC.cpp:79
clang::ObjCContainerDecl::PropertyMap
llvm::DenseMap< std::pair< IdentifierInfo *, unsigned >, ObjCPropertyDecl * > PropertyMap
Definition: DeclObjC.h:1119
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1086
clang::Decl::isHidden
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:774
clang::DeclContext::specific_decl_iterator
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:2053
clang::ObjCInterfaceDecl::hasDesignatedInitializers
bool hasDesignatedInitializers() const
Returns true if this interface decl contains at least one initializer marked with the &#39;objc_designate...
Definition: DeclObjC.cpp:1547
clang::ObjCIvarDecl::Create
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
Definition: DeclObjC.cpp:1773
clang::ObjCAtDefsFieldDecl::CreateDeserialized
static ObjCAtDefsFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1857
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2566
clang::ObjCInterfaceDecl::getObjCRuntimeNameAsString
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for class&#39;s metadata.
Definition: DeclObjC.cpp:1558
clang::CXXCtorInitializer
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2155
clang::ExternalASTSource::CompleteType
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Definition: ExternalASTSource.cpp:62
clang::ObjCImplementationDecl::getObjCRuntimeNameAsString
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for class&#39;s metadata.
Definition: DeclObjC.cpp:1566
clang::ObjCInterfaceDecl::setCategoryListRaw
void setCategoryListRaw(ObjCCategoryDecl *category)
Set the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1811
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1524
clang::ObjCInterfaceDecl::lookupMethod
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const
lookupMethod - This method returns an instance/class method by looking in the class, its categories, and its super classes (using a linear search).
Definition: DeclObjC.cpp:682
clang::QualType::getNonLValueExprType
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2915
clang::DeclContext::ObjCMethodDeclBits
ObjCMethodDeclBitfields ObjCMethodDeclBits
Definition: DeclBase.h:1727
clang::ASTContext::getASTMutationListener
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any...
Definition: ASTContext.h:1101
clang::ObjCPropertyDecl::OBJC_PR_readwrite
Definition: DeclObjC.h:750
clang::ObjCTypeParamList::gatherDefaultTypeArgs
void gatherDefaultTypeArgs(SmallVectorImpl< QualType > &typeArgs) const
Gather the default set of type arguments to be substituted for these type parameters when dealing wit...
Definition: DeclObjC.cpp:1470
clang::OMF_None
No particular method family.
Definition: IdentifierTable.h:625
clang::ObjCMethodDecl::findPropertyDecl
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method&#39;s selector.
Definition: DeclObjC.cpp:1313
clang::ObjCAtDefsFieldDecl
Represents a field declaration created by an @defs(...).
Definition: DeclObjC.h:2026
SourceLocation.h
Defines the clang::SourceLocation class and associated facilities.
isInstanceMethod
static bool isInstanceMethod(const Decl *D)
Definition: SemaDeclAttr.cpp:144
clang::ObjCImplementationDecl::setIvarInitializers
void setIvarInitializers(ASTContext &C, CXXCtorInitializer **initializers, unsigned numInitializers)
Definition: DeclObjC.cpp:2195
clang::ObjCImplDecl::FindPropertyImplDecl
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2135
clang::ObjCImplementationDecl::CreateDeserialized
static ObjCImplementationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2190
clang::ObjCMethodDecl::setHasRedeclaration
void setHasRedeclaration(bool HRD) const
Definition: DeclObjC.h:274
clang::ObjCImplDecl::setClassInterface
void setClassInterface(ObjCInterfaceDecl *IFace)
Definition: DeclObjC.cpp:2104
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:107
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1959
clang::AttrSyntax::C
clang::ObjCMethodDecl::getSendResultType
QualType getSendResultType() const
Determine the type of an expression that sends a message to this function.
Definition: DeclObjC.cpp:1174
clang::ObjCTypeParamList
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:649
clang::DeclContextLookupResult::begin
iterator begin() const
Definition: DeclBase.h:1236
clang::OMF_init
Definition: IdentifierTable.h:633
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250
clang::Decl::Kind
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:91
clang::ObjCImplementationDecl::getName
StringRef getName() const
getName - Get the name of identifier for the class interface associated with this implementation as a...
Definition: DeclObjC.h:2687
clang::ObjCInterfaceDecl::isArcWeakrefUnavailable
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:412
clang::ObjCInterfaceDecl::CreateDeserialized
static ObjCInterfaceDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1497
clang::SelLoc_StandardNoSpace
For nullary selectors, immediately before the end: "[foo release]" / "-(void)release;" Or immediately...
Definition: SelectorLocationsKind.h:35
clang::NamedDecl::getMostRecentDecl
NamedDecl * getMostRecentDecl()
Definition: Decl.h:428
clang::ObjCPropertyImplDecl::CreateDeserialized
static ObjCPropertyImplDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2284
clang::ObjCImplDecl::addPropertyImplementation
void addPropertyImplementation(ObjCPropertyImplDecl *property)
Definition: DeclObjC.cpp:2098
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:207
clang::DeclContextLookupResult::iterator
Definition: DeclBase.h:1220
clang::ObjCContainerDecl::getMethod
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
Definition: DeclObjC.cpp:91
clang::ObjCMethodDecl::isRedeclaration
bool isRedeclaration() const
True if this is a method redeclaration in the same interface.
Definition: DeclObjC.h:268
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
clang::ObjCInterfaceDecl::all_declared_ivar_begin
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
Definition: DeclObjC.cpp:1617
clang::ASTContext::getObjCObjectPointerType
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
Definition: ASTContext.cpp:4973
clang::ObjCCategoryImplDecl::Create
static ObjCCategoryImplDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, ObjCInterfaceDecl *classInterface, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation CategoryNameLoc)
Definition: DeclObjC.cpp:2070
clang::ObjCContainerDecl::getInstanceMethod
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1101
clang::ObjCPropertyDecl::CreateDeserialized
static ObjCPropertyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2256
clang::ObjCInterfaceDecl::setHasDesignatedInitializers
void setHasDesignatedInitializers()
Indicate that this interface decl contains at least one initializer marked with the &#39;objc_designated_...
Definition: DeclObjC.cpp:1540
clang::ObjCProtocolDecl::collectPropertiesToImplement
void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:1949
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:724
clang::ObjCCategoryImplDecl
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2513
clang::ObjCTypeParamVariance::Invariant
The parameter is invariant: must match exactly.
clang::OMF_alloc
Definition: IdentifierTable.h:631
clang::ObjCPropertyQueryKind::OBJC_PR_query_class
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:429
clang::ObjCCompatibleAliasDecl
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2743
CollectOverriddenMethods
static void CollectOverriddenMethods(const ObjCContainerDecl *Container, const ObjCMethodDecl *Method, SmallVectorImpl< const ObjCMethodDecl *> &Methods)
Definition: DeclObjC.cpp:1248
clang::OMF_autorelease
Definition: IdentifierTable.h:639
clang::ObjCInterfaceDecl::FindCategoryDeclaration
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1689
clang::ObjCMethodDecl::ImplementationControl
ImplementationControl
Definition: DeclObjC.h:143
clang::hasStandardSelectorLocs
SelectorLocationsKind hasStandardSelectorLocs(Selector Sel, ArrayRef< SourceLocation > SelLocs, ArrayRef< Expr *> Args, SourceLocation EndLoc)
Returns true if all SelLocs are in a "standard" location.
Definition: SelectorLocationsKind.cpp:96