1 //===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DeclObjC interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_DECLOBJC_H
15 #define LLVM_CLANG_AST_DECLOBJC_H
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/SelectorLocationsKind.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/Compiler.h"
29 class ObjCProtocolDecl;
30 class ObjCCategoryDecl;
31 class ObjCPropertyDecl;
32 class ObjCPropertyImplDecl;
33 class CXXCtorInitializer;
36 ObjCListBase(const ObjCListBase &) = delete;
37 void operator=(const ObjCListBase &) = delete;
39 /// List is an array of pointers to objects that are not owned by this object.
44 ObjCListBase() : List(nullptr), NumElts(0) {}
45 unsigned size() const { return NumElts; }
46 bool empty() const { return NumElts == 0; }
49 void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
53 /// ObjCList - This is a simple template class used to hold various lists of
54 /// decls etc, which is heavily used by the ObjC front-end. This only use case
55 /// this supports is setting the list all at once and then reading elements out
58 class ObjCList : public ObjCListBase {
60 void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
61 ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
64 typedef T* const * iterator;
65 iterator begin() const { return (iterator)List; }
66 iterator end() const { return (iterator)List+NumElts; }
68 T* operator[](unsigned Idx) const {
69 assert(Idx < NumElts && "Invalid access");
74 /// \brief A list of Objective-C protocols, along with the source
75 /// locations at which they were referenced.
76 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
77 SourceLocation *Locations;
79 using ObjCList<ObjCProtocolDecl>::set;
82 ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(nullptr) { }
84 typedef const SourceLocation *loc_iterator;
85 loc_iterator loc_begin() const { return Locations; }
86 loc_iterator loc_end() const { return Locations + size(); }
88 void set(ObjCProtocolDecl* const* InList, unsigned Elts,
89 const SourceLocation *Locs, ASTContext &Ctx);
93 /// ObjCMethodDecl - Represents an instance or class method declaration.
94 /// ObjC methods can be declared within 4 contexts: class interfaces,
95 /// categories, protocols, and class implementations. While C++ member
96 /// functions leverage C syntax, Objective-C method syntax is modeled after
97 /// Smalltalk (using colons to specify argument types/expressions).
98 /// Here are some brief examples:
100 /// Setter/getter instance methods:
101 /// - (void)setMenu:(NSMenu *)menu;
102 /// - (NSMenu *)menu;
104 /// Instance method that takes 2 NSView arguments:
105 /// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
107 /// Getter class method:
108 /// + (NSMenu *)defaultMenu;
110 /// A selector represents a unique name for a method. The selector names for
111 /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
113 class ObjCMethodDecl : public NamedDecl, public DeclContext {
115 enum ImplementationControl { None, Required, Optional };
117 // The conventional meaning of this method; an ObjCMethodFamily.
118 // This is not serialized; instead, it is computed on demand and
120 mutable unsigned Family : ObjCMethodFamilyBitWidth;
122 /// instance (true) or class (false) method.
123 unsigned IsInstance : 1;
124 unsigned IsVariadic : 1;
126 /// True if this method is the getter or setter for an explicit property.
127 unsigned IsPropertyAccessor : 1;
129 // Method has a definition.
130 unsigned IsDefined : 1;
132 /// \brief Method redeclaration in the same interface.
133 unsigned IsRedeclaration : 1;
135 /// \brief Is redeclared in the same interface.
136 mutable unsigned HasRedeclaration : 1;
138 // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
139 /// \@required/\@optional
140 unsigned DeclImplementation : 2;
142 // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
144 unsigned objcDeclQualifier : 7;
146 /// \brief Indicates whether this method has a related result type.
147 unsigned RelatedResultType : 1;
149 /// \brief Whether the locations of the selector identifiers are in a
150 /// "standard" position, a enum SelectorLocationsKind.
151 unsigned SelLocsKind : 2;
153 /// \brief Whether this method overrides any other in the class hierarchy.
155 /// A method is said to override any method in the class's
156 /// base classes, its protocols, or its categories' protocols, that has
157 /// the same selector and is of the same kind (class or instance).
158 /// A method in an implementation is not considered as overriding the same
159 /// method in the interface or its categories.
160 unsigned IsOverriding : 1;
162 /// \brief Indicates if the method was a definition but its body was skipped.
163 unsigned HasSkippedBody : 1;
165 // Return type of this method.
166 QualType MethodDeclType;
168 // Type source information for the return type.
169 TypeSourceInfo *ReturnTInfo;
171 /// \brief Array of ParmVarDecls for the formal parameters of this method
172 /// and optionally followed by selector locations.
173 void *ParamsAndSelLocs;
176 /// List of attributes for this method declaration.
177 SourceLocation DeclEndLoc; // the location of the ';' or '{'.
179 // The following are only used for method definitions, null otherwise.
180 LazyDeclStmtPtr Body;
182 /// SelfDecl - Decl for the implicit self parameter. This is lazily
183 /// constructed by createImplicitParams.
184 ImplicitParamDecl *SelfDecl;
185 /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
186 /// constructed by createImplicitParams.
187 ImplicitParamDecl *CmdDecl;
189 SelectorLocationsKind getSelLocsKind() const {
190 return (SelectorLocationsKind)SelLocsKind;
192 bool hasStandardSelLocs() const {
193 return getSelLocsKind() != SelLoc_NonStandard;
196 /// \brief Get a pointer to the stored selector identifiers locations array.
197 /// No locations will be stored if HasStandardSelLocs is true.
198 SourceLocation *getStoredSelLocs() {
199 return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
201 const SourceLocation *getStoredSelLocs() const {
202 return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
205 /// \brief Get a pointer to the stored selector identifiers locations array.
206 /// No locations will be stored if HasStandardSelLocs is true.
207 ParmVarDecl **getParams() {
208 return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
210 const ParmVarDecl *const *getParams() const {
211 return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
214 /// \brief Get the number of stored selector identifiers locations.
215 /// No locations will be stored if HasStandardSelLocs is true.
216 unsigned getNumStoredSelLocs() const {
217 if (hasStandardSelLocs())
219 return getNumSelectorLocs();
222 void setParamsAndSelLocs(ASTContext &C,
223 ArrayRef<ParmVarDecl*> Params,
224 ArrayRef<SourceLocation> SelLocs);
226 ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
227 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
228 DeclContext *contextDecl, bool isInstance = true,
229 bool isVariadic = false, bool isPropertyAccessor = false,
230 bool isImplicitlyDeclared = false, bool isDefined = false,
231 ImplementationControl impControl = None,
232 bool HasRelatedResultType = false)
233 : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
234 DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
235 IsInstance(isInstance), IsVariadic(isVariadic),
236 IsPropertyAccessor(isPropertyAccessor), IsDefined(isDefined),
237 IsRedeclaration(0), HasRedeclaration(0), DeclImplementation(impControl),
238 objcDeclQualifier(OBJC_TQ_None),
239 RelatedResultType(HasRelatedResultType),
240 SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
241 MethodDeclType(T), ReturnTInfo(ReturnTInfo), ParamsAndSelLocs(nullptr),
242 NumParams(0), DeclEndLoc(endLoc), Body(), SelfDecl(nullptr),
244 setImplicit(isImplicitlyDeclared);
247 /// \brief A definition will return its interface declaration.
248 /// An interface declaration will return its definition.
249 /// Otherwise it will return itself.
250 ObjCMethodDecl *getNextRedeclarationImpl() override;
253 static ObjCMethodDecl *
254 Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
255 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
256 DeclContext *contextDecl, bool isInstance = true,
257 bool isVariadic = false, bool isPropertyAccessor = false,
258 bool isImplicitlyDeclared = false, bool isDefined = false,
259 ImplementationControl impControl = None,
260 bool HasRelatedResultType = false);
262 static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
264 ObjCMethodDecl *getCanonicalDecl() override;
265 const ObjCMethodDecl *getCanonicalDecl() const {
266 return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
269 ObjCDeclQualifier getObjCDeclQualifier() const {
270 return ObjCDeclQualifier(objcDeclQualifier);
272 void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
274 /// \brief Determine whether this method has a result type that is related
275 /// to the message receiver's type.
276 bool hasRelatedResultType() const { return RelatedResultType; }
278 /// \brief Note whether this method has a related result type.
279 void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
281 /// \brief True if this is a method redeclaration in the same interface.
282 bool isRedeclaration() const { return IsRedeclaration; }
283 void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
285 /// \brief Returns the location where the declarator ends. It will be
286 /// the location of ';' for a method declaration and the location of '{'
287 /// for a method definition.
288 SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
290 // Location information, modeled after the Stmt API.
291 SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
292 SourceLocation getLocEnd() const LLVM_READONLY;
293 SourceRange getSourceRange() const override LLVM_READONLY {
294 return SourceRange(getLocation(), getLocEnd());
297 SourceLocation getSelectorStartLoc() const {
299 return getLocStart();
300 return getSelectorLoc(0);
302 SourceLocation getSelectorLoc(unsigned Index) const {
303 assert(Index < getNumSelectorLocs() && "Index out of range!");
304 if (hasStandardSelLocs())
305 return getStandardSelectorLoc(Index, getSelector(),
306 getSelLocsKind() == SelLoc_StandardWithSpace,
309 return getStoredSelLocs()[Index];
312 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
314 unsigned getNumSelectorLocs() const {
317 Selector Sel = getSelector();
318 if (Sel.isUnarySelector())
320 return Sel.getNumArgs();
323 ObjCInterfaceDecl *getClassInterface();
324 const ObjCInterfaceDecl *getClassInterface() const {
325 return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
328 Selector getSelector() const { return getDeclName().getObjCSelector(); }
330 QualType getReturnType() const { return MethodDeclType; }
331 void setReturnType(QualType T) { MethodDeclType = T; }
332 SourceRange getReturnTypeSourceRange() const;
334 /// \brief Determine the type of an expression that sends a message to this
335 /// function. This replaces the type parameters with the types they would
336 /// get if the receiver was parameterless (e.g. it may replace the type
337 /// parameter with 'id').
338 QualType getSendResultType() const;
340 /// Determine the type of an expression that sends a message to this
341 /// function with the given receiver type.
342 QualType getSendResultType(QualType receiverType) const;
344 TypeSourceInfo *getReturnTypeSourceInfo() const { return ReturnTInfo; }
345 void setReturnTypeSourceInfo(TypeSourceInfo *TInfo) { ReturnTInfo = TInfo; }
347 // Iterator access to formal parameters.
348 unsigned param_size() const { return NumParams; }
349 typedef const ParmVarDecl *const *param_const_iterator;
350 typedef ParmVarDecl *const *param_iterator;
351 typedef llvm::iterator_range<param_iterator> param_range;
352 typedef llvm::iterator_range<param_const_iterator> param_const_range;
354 param_range params() { return param_range(param_begin(), param_end()); }
355 param_const_range params() const {
356 return param_const_range(param_begin(), param_end());
359 param_const_iterator param_begin() const {
360 return param_const_iterator(getParams());
362 param_const_iterator param_end() const {
363 return param_const_iterator(getParams() + NumParams);
365 param_iterator param_begin() { return param_iterator(getParams()); }
366 param_iterator param_end() { return param_iterator(getParams() + NumParams); }
368 // This method returns and of the parameters which are part of the selector
369 // name mangling requirements.
370 param_const_iterator sel_param_end() const {
371 return param_begin() + getSelector().getNumArgs();
374 // ArrayRef access to formal parameters. This should eventually
375 // replace the iterator interface above.
376 ArrayRef<ParmVarDecl*> parameters() const {
377 return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
381 /// \brief Sets the method's parameters and selector source locations.
382 /// If the method is implicit (not coming from source) \p SelLocs is
384 void setMethodParams(ASTContext &C,
385 ArrayRef<ParmVarDecl*> Params,
386 ArrayRef<SourceLocation> SelLocs = llvm::None);
388 // Iterator access to parameter types.
389 typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
390 typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
393 param_type_iterator param_type_begin() const {
394 return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
396 param_type_iterator param_type_end() const {
397 return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
400 /// createImplicitParams - Used to lazily create the self and cmd
401 /// implict parameters. This must be called prior to using getSelfDecl()
402 /// or getCmdDecl(). The call is ignored if the implicit paramters
403 /// have already been created.
404 void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
406 /// \return the type for \c self and set \arg selfIsPseudoStrong and
407 /// \arg selfIsConsumed accordingly.
408 QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID,
409 bool &selfIsPseudoStrong, bool &selfIsConsumed);
411 ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
412 void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
413 ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
414 void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
416 /// Determines the family of this method.
417 ObjCMethodFamily getMethodFamily() const;
419 bool isInstanceMethod() const { return IsInstance; }
420 void setInstanceMethod(bool isInst) { IsInstance = isInst; }
421 bool isVariadic() const { return IsVariadic; }
422 void setVariadic(bool isVar) { IsVariadic = isVar; }
424 bool isClassMethod() const { return !IsInstance; }
426 bool isPropertyAccessor() const { return IsPropertyAccessor; }
427 void setPropertyAccessor(bool isAccessor) { IsPropertyAccessor = isAccessor; }
429 bool isDefined() const { return IsDefined; }
430 void setDefined(bool isDefined) { IsDefined = isDefined; }
432 /// \brief Whether this method overrides any other in the class hierarchy.
434 /// A method is said to override any method in the class's
435 /// base classes, its protocols, or its categories' protocols, that has
436 /// the same selector and is of the same kind (class or instance).
437 /// A method in an implementation is not considered as overriding the same
438 /// method in the interface or its categories.
439 bool isOverriding() const { return IsOverriding; }
440 void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
442 /// \brief Return overridden methods for the given \p Method.
444 /// An ObjC method is considered to override any method in the class's
445 /// base classes (and base's categories), its protocols, or its categories'
446 /// protocols, that has
447 /// the same selector and is of the same kind (class or instance).
448 /// A method in an implementation is not considered as overriding the same
449 /// method in the interface or its categories.
450 void getOverriddenMethods(
451 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
453 /// \brief True if the method was a definition but its body was skipped.
454 bool hasSkippedBody() const { return HasSkippedBody; }
455 void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
457 /// \brief Returns the property associated with this method's selector.
459 /// Note that even if this particular method is not marked as a property
460 /// accessor, it is still possible for it to match a property declared in a
461 /// superclass. Pass \c false if you only want to check the current class.
462 const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
464 // Related to protocols declared in \@protocol
465 void setDeclImplementation(ImplementationControl ic) {
466 DeclImplementation = ic;
468 ImplementationControl getImplementationControl() const {
469 return ImplementationControl(DeclImplementation);
472 /// Returns true if this specific method declaration is marked with the
473 /// designated initializer attribute.
474 bool isThisDeclarationADesignatedInitializer() const;
476 /// Returns true if the method selector resolves to a designated initializer
477 /// in the class's interface.
479 /// \param InitMethod if non-null and the function returns true, it receives
480 /// the method declaration that was marked with the designated initializer
482 bool isDesignatedInitializerForTheInterface(
483 const ObjCMethodDecl **InitMethod = nullptr) const;
485 /// \brief Determine whether this method has a body.
486 bool hasBody() const override { return Body.isValid(); }
488 /// \brief Retrieve the body of this method, if it has one.
489 Stmt *getBody() const override;
491 void setLazyBody(uint64_t Offset) { Body = Offset; }
493 CompoundStmt *getCompoundBody() { return (CompoundStmt*)getBody(); }
494 void setBody(Stmt *B) { Body = B; }
496 /// \brief Returns whether this specific method is a definition.
497 bool isThisDeclarationADefinition() const { return hasBody(); }
499 // Implement isa/cast/dyncast/etc.
500 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
501 static bool classofKind(Kind K) { return K == ObjCMethod; }
502 static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
503 return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
505 static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
506 return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
509 friend class ASTDeclReader;
510 friend class ASTDeclWriter;
513 /// Describes the variance of a given generic parameter.
514 enum class ObjCTypeParamVariance : uint8_t {
515 /// The parameter is invariant: must match exactly.
517 /// The parameter is covariant, e.g., X<T> is a subtype of X<U> when
518 /// the type parameter is covariant and T is a subtype of U.
520 /// The parameter is contravariant, e.g., X<T> is a subtype of X<U>
521 /// when the type parameter is covariant and U is a subtype of T.
525 /// Represents the declaration of an Objective-C type parameter.
528 /// @interface NSDictionary<Key : id<NSCopying>, Value>
532 /// In the example above, both \c Key and \c Value are represented by
533 /// \c ObjCTypeParamDecl. \c Key has an explicit bound of \c id<NSCopying>,
534 /// while \c Value gets an implicit bound of \c id.
536 /// Objective-C type parameters are typedef-names in the grammar,
537 class ObjCTypeParamDecl : public TypedefNameDecl {
538 void anchor() override;
540 /// Index of this type parameter in the type parameter list.
543 /// The variance of the type parameter.
544 unsigned Variance : 2;
546 /// The location of the variance, if any.
547 SourceLocation VarianceLoc;
549 /// The location of the ':', which will be valid when the bound was
550 /// explicitly specified.
551 SourceLocation ColonLoc;
553 ObjCTypeParamDecl(ASTContext &ctx, DeclContext *dc,
554 ObjCTypeParamVariance variance, SourceLocation varianceLoc,
556 SourceLocation nameLoc, IdentifierInfo *name,
557 SourceLocation colonLoc, TypeSourceInfo *boundInfo)
558 : TypedefNameDecl(ObjCTypeParam, ctx, dc, nameLoc, nameLoc, name,
560 Index(index), Variance(static_cast<unsigned>(variance)),
561 VarianceLoc(varianceLoc), ColonLoc(colonLoc) { }
564 static ObjCTypeParamDecl *Create(ASTContext &ctx, DeclContext *dc,
565 ObjCTypeParamVariance variance,
566 SourceLocation varianceLoc,
568 SourceLocation nameLoc,
569 IdentifierInfo *name,
570 SourceLocation colonLoc,
571 TypeSourceInfo *boundInfo);
572 static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx, unsigned ID);
574 SourceRange getSourceRange() const override LLVM_READONLY;
576 /// Determine the variance of this type parameter.
577 ObjCTypeParamVariance getVariance() const {
578 return static_cast<ObjCTypeParamVariance>(Variance);
581 /// Set the variance of this type parameter.
582 void setVariance(ObjCTypeParamVariance variance) {
583 Variance = static_cast<unsigned>(variance);
586 /// Retrieve the location of the variance keyword.
587 SourceLocation getVarianceLoc() const { return VarianceLoc; }
589 /// Retrieve the index into its type parameter list.
590 unsigned getIndex() const { return Index; }
592 /// Whether this type parameter has an explicitly-written type bound, e.g.,
594 bool hasExplicitBound() const { return ColonLoc.isValid(); }
596 /// Retrieve the location of the ':' separating the type parameter name
597 /// from the explicitly-specified bound.
598 SourceLocation getColonLoc() const { return ColonLoc; }
600 // Implement isa/cast/dyncast/etc.
601 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
602 static bool classofKind(Kind K) { return K == ObjCTypeParam; }
604 friend class ASTDeclReader;
605 friend class ASTDeclWriter;
608 /// Stores a list of Objective-C type parameters for a parameterized class
609 /// or a category/extension thereof.
612 /// @interface NSArray<T> // stores the <T>
615 class ObjCTypeParamList {
616 /// Stores the components of a SourceRange as a POD.
617 struct PODSourceRange {
623 /// Location of the left and right angle brackets.
624 PODSourceRange Brackets;
626 // Used only for alignment.
627 ObjCTypeParamDecl *AlignmentHack;
630 /// The number of parameters in the list, which are tail-allocated.
633 ObjCTypeParamList(SourceLocation lAngleLoc,
634 ArrayRef<ObjCTypeParamDecl *> typeParams,
635 SourceLocation rAngleLoc);
638 /// Create a new Objective-C type parameter list.
639 static ObjCTypeParamList *create(ASTContext &ctx,
640 SourceLocation lAngleLoc,
641 ArrayRef<ObjCTypeParamDecl *> typeParams,
642 SourceLocation rAngleLoc);
644 /// Iterate through the type parameters in the list.
645 typedef ObjCTypeParamDecl **iterator;
647 iterator begin() { return reinterpret_cast<ObjCTypeParamDecl **>(this + 1); }
649 iterator end() { return begin() + size(); }
651 /// Determine the number of type parameters in this list.
652 unsigned size() const { return NumParams; }
654 // Iterate through the type parameters in the list.
655 typedef ObjCTypeParamDecl * const *const_iterator;
657 const_iterator begin() const {
658 return reinterpret_cast<ObjCTypeParamDecl * const *>(this + 1);
661 const_iterator end() const {
662 return begin() + size();
665 ObjCTypeParamDecl *front() const {
666 assert(size() > 0 && "empty Objective-C type parameter list");
670 ObjCTypeParamDecl *back() const {
671 assert(size() > 0 && "empty Objective-C type parameter list");
675 SourceLocation getLAngleLoc() const {
676 return SourceLocation::getFromRawEncoding(Brackets.Begin);
678 SourceLocation getRAngleLoc() const {
679 return SourceLocation::getFromRawEncoding(Brackets.End);
681 SourceRange getSourceRange() const {
682 return SourceRange(getLAngleLoc(), getRAngleLoc());
685 /// Gather the default set of type arguments to be substituted for
686 /// these type parameters when dealing with an unspecialized type.
687 void gatherDefaultTypeArgs(SmallVectorImpl<QualType> &typeArgs) const;
690 /// ObjCContainerDecl - Represents a container for method declarations.
691 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
692 /// ObjCProtocolDecl, and ObjCImplDecl.
694 class ObjCContainerDecl : public NamedDecl, public DeclContext {
695 void anchor() override;
697 SourceLocation AtStart;
699 // These two locations in the range mark the end of the method container.
700 // The first points to the '@' token, and the second to the 'end' token.
704 ObjCContainerDecl(Kind DK, DeclContext *DC,
705 IdentifierInfo *Id, SourceLocation nameLoc,
706 SourceLocation atStartLoc)
707 : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
709 // Iterator access to properties.
710 typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
711 typedef llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>
714 prop_range properties() const { return prop_range(prop_begin(), prop_end()); }
715 prop_iterator prop_begin() const {
716 return prop_iterator(decls_begin());
718 prop_iterator prop_end() const {
719 return prop_iterator(decls_end());
722 // Iterator access to instance/class methods.
723 typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
724 typedef llvm::iterator_range<specific_decl_iterator<ObjCMethodDecl>>
727 method_range methods() const {
728 return method_range(meth_begin(), meth_end());
730 method_iterator meth_begin() const {
731 return method_iterator(decls_begin());
733 method_iterator meth_end() const {
734 return method_iterator(decls_end());
737 typedef filtered_decl_iterator<ObjCMethodDecl,
738 &ObjCMethodDecl::isInstanceMethod>
740 typedef llvm::iterator_range<instmeth_iterator> instmeth_range;
742 instmeth_range instance_methods() const {
743 return instmeth_range(instmeth_begin(), instmeth_end());
745 instmeth_iterator instmeth_begin() const {
746 return instmeth_iterator(decls_begin());
748 instmeth_iterator instmeth_end() const {
749 return instmeth_iterator(decls_end());
752 typedef filtered_decl_iterator<ObjCMethodDecl,
753 &ObjCMethodDecl::isClassMethod>
755 typedef llvm::iterator_range<classmeth_iterator> classmeth_range;
757 classmeth_range class_methods() const {
758 return classmeth_range(classmeth_begin(), classmeth_end());
760 classmeth_iterator classmeth_begin() const {
761 return classmeth_iterator(decls_begin());
763 classmeth_iterator classmeth_end() const {
764 return classmeth_iterator(decls_end());
767 // Get the local instance/class method declared in this interface.
768 ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
769 bool AllowHidden = false) const;
770 ObjCMethodDecl *getInstanceMethod(Selector Sel,
771 bool AllowHidden = false) const {
772 return getMethod(Sel, true/*isInstance*/, AllowHidden);
774 ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
775 return getMethod(Sel, false/*isInstance*/, AllowHidden);
777 bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
778 ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
781 FindPropertyDeclaration(const IdentifierInfo *PropertyId) const;
783 typedef llvm::DenseMap<IdentifierInfo*, ObjCPropertyDecl*> PropertyMap;
785 typedef llvm::DenseMap<const ObjCProtocolDecl *, ObjCPropertyDecl*>
788 typedef llvm::SmallVector<ObjCPropertyDecl*, 8> PropertyDeclOrder;
790 /// This routine collects list of properties to be implemented in the class.
791 /// This includes, class's and its conforming protocols' properties.
792 /// Note, the superclass's properties are not included in the list.
793 virtual void collectPropertiesToImplement(PropertyMap &PM,
794 PropertyDeclOrder &PO) const {}
796 SourceLocation getAtStartLoc() const { return AtStart; }
797 void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
799 // Marks the end of the container.
800 SourceRange getAtEndRange() const {
803 void setAtEndRange(SourceRange atEnd) {
807 SourceRange getSourceRange() const override LLVM_READONLY {
808 return SourceRange(AtStart, getAtEndRange().getEnd());
811 // Implement isa/cast/dyncast/etc.
812 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
813 static bool classofKind(Kind K) {
814 return K >= firstObjCContainer &&
815 K <= lastObjCContainer;
818 static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
819 return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
821 static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
822 return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
826 /// \brief Represents an ObjC class declaration.
831 /// // MostPrimitive declares no super class (not particularly useful).
832 /// \@interface MostPrimitive
833 /// // no instance variables or methods.
836 /// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
837 /// \@interface NSResponder : NSObject \<NSCoding>
838 /// { // instance variables are represented by ObjCIvarDecl.
839 /// id nextResponder; // nextResponder instance variable.
841 /// - (NSResponder *)nextResponder; // return a pointer to NSResponder.
842 /// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
843 /// \@end // to an NSEvent.
846 /// Unlike C/C++, forward class declarations are accomplished with \@class.
847 /// Unlike C/C++, \@class allows for a list of classes to be forward declared.
848 /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
849 /// typically inherit from NSObject (an exception is NSProxy).
851 class ObjCInterfaceDecl : public ObjCContainerDecl
852 , public Redeclarable<ObjCInterfaceDecl> {
853 void anchor() override;
855 /// TypeForDecl - This indicates the Type object that represents this
856 /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType
857 mutable const Type *TypeForDecl;
858 friend class ASTContext;
860 struct DefinitionData {
861 /// \brief The definition of this class, for quick access from any
863 ObjCInterfaceDecl *Definition;
865 /// When non-null, this is always an ObjCObjectType.
866 TypeSourceInfo *SuperClassTInfo;
868 /// Protocols referenced in the \@interface declaration
869 ObjCProtocolList ReferencedProtocols;
871 /// Protocols reference in both the \@interface and class extensions.
872 ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
874 /// \brief List of categories and class extensions defined for this class.
876 /// Categories are stored as a linked list in the AST, since the categories
877 /// and class extensions come long after the initial interface declaration,
878 /// and we avoid dynamically-resized arrays in the AST wherever possible.
879 ObjCCategoryDecl *CategoryList;
881 /// IvarList - List of all ivars defined by this class; including class
882 /// extensions and implementation. This list is built lazily.
883 ObjCIvarDecl *IvarList;
885 /// \brief Indicates that the contents of this Objective-C class will be
886 /// completed by the external AST source when required.
887 mutable bool ExternallyCompleted : 1;
889 /// \brief Indicates that the ivar cache does not yet include ivars
890 /// declared in the implementation.
891 mutable bool IvarListMissingImplementation : 1;
893 /// Indicates that this interface decl contains at least one initializer
894 /// marked with the 'objc_designated_initializer' attribute.
895 bool HasDesignatedInitializers : 1;
897 enum InheritedDesignatedInitializersState {
898 /// We didn't calculate whether the designated initializers should be
899 /// inherited or not.
901 /// Designated initializers are inherited for the super class.
903 /// The class does not inherit designated initializers.
906 /// One of the \c InheritedDesignatedInitializersState enumeratos.
907 mutable unsigned InheritedDesignatedInitializers : 2;
909 /// \brief The location of the last location in this declaration, before
910 /// the properties/methods. For example, this will be the '>', '}', or
912 SourceLocation EndLoc;
914 DefinitionData() : Definition(), SuperClassTInfo(), CategoryList(), IvarList(),
915 ExternallyCompleted(),
916 IvarListMissingImplementation(true),
917 HasDesignatedInitializers(),
918 InheritedDesignatedInitializers(IDI_Unknown) { }
921 ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, SourceLocation AtLoc,
922 IdentifierInfo *Id, ObjCTypeParamList *typeParamList,
923 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
926 void LoadExternalDefinition() const;
928 /// The type parameters associated with this class, if any.
929 ObjCTypeParamList *TypeParamList;
931 /// \brief Contains a pointer to the data associated with this class,
932 /// which will be NULL if this class has not yet been defined.
934 /// The bit indicates when we don't need to check for out-of-date
935 /// declarations. It will be set unless modules are enabled.
936 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
938 DefinitionData &data() const {
939 assert(Data.getPointer() && "Declaration has no definition!");
940 return *Data.getPointer();
943 /// \brief Allocate the definition data for this class.
944 void allocateDefinitionData();
946 typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
947 ObjCInterfaceDecl *getNextRedeclarationImpl() override {
948 return getNextRedeclaration();
950 ObjCInterfaceDecl *getPreviousDeclImpl() override {
951 return getPreviousDecl();
953 ObjCInterfaceDecl *getMostRecentDeclImpl() override {
954 return getMostRecentDecl();
958 static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
959 SourceLocation atLoc,
961 ObjCTypeParamList *typeParamList,
962 ObjCInterfaceDecl *PrevDecl,
963 SourceLocation ClassLoc = SourceLocation(),
964 bool isInternal = false);
966 static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
968 /// Retrieve the type parameters of this class.
970 /// This function looks for a type parameter list for the given
971 /// class; if the class has been declared (with \c \@class) but not
972 /// defined (with \c \@interface), it will search for a declaration that
973 /// has type parameters, skipping any declarations that do not.
974 ObjCTypeParamList *getTypeParamList() const;
976 /// Set the type parameters of this class.
978 /// This function is used by the AST importer, which must import the type
979 /// parameters after creating their DeclContext to avoid loops.
980 void setTypeParamList(ObjCTypeParamList *TPL);
982 /// Retrieve the type parameters written on this particular declaration of
984 ObjCTypeParamList *getTypeParamListAsWritten() const {
985 return TypeParamList;
988 SourceRange getSourceRange() const override LLVM_READONLY {
989 if (isThisDeclarationADefinition())
990 return ObjCContainerDecl::getSourceRange();
992 return SourceRange(getAtStartLoc(), getLocation());
995 /// \brief Indicate that this Objective-C class is complete, but that
996 /// the external AST source will be responsible for filling in its contents
997 /// when a complete class is required.
998 void setExternallyCompleted();
1000 /// Indicate that this interface decl contains at least one initializer
1001 /// marked with the 'objc_designated_initializer' attribute.
1002 void setHasDesignatedInitializers();
1004 /// Returns true if this interface decl contains at least one initializer
1005 /// marked with the 'objc_designated_initializer' attribute.
1006 bool hasDesignatedInitializers() const;
1008 /// Returns true if this interface decl declares a designated initializer
1009 /// or it inherites one from its super class.
1010 bool declaresOrInheritsDesignatedInitializers() const {
1011 return hasDesignatedInitializers() || inheritsDesignatedInitializers();
1014 const ObjCProtocolList &getReferencedProtocols() const {
1015 assert(hasDefinition() && "Caller did not check for forward reference!");
1016 if (data().ExternallyCompleted)
1017 LoadExternalDefinition();
1019 return data().ReferencedProtocols;
1022 ObjCImplementationDecl *getImplementation() const;
1023 void setImplementation(ObjCImplementationDecl *ImplD);
1025 ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
1027 // Get the local instance/class method declared in a category.
1028 ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
1029 ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
1030 ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
1031 return isInstance ? getCategoryInstanceMethod(Sel)
1032 : getCategoryClassMethod(Sel);
1035 typedef ObjCProtocolList::iterator protocol_iterator;
1036 typedef llvm::iterator_range<protocol_iterator> protocol_range;
1038 protocol_range protocols() const {
1039 return protocol_range(protocol_begin(), protocol_end());
1041 protocol_iterator protocol_begin() const {
1042 // FIXME: Should make sure no callers ever do this.
1043 if (!hasDefinition())
1044 return protocol_iterator();
1046 if (data().ExternallyCompleted)
1047 LoadExternalDefinition();
1049 return data().ReferencedProtocols.begin();
1051 protocol_iterator protocol_end() const {
1052 // FIXME: Should make sure no callers ever do this.
1053 if (!hasDefinition())
1054 return protocol_iterator();
1056 if (data().ExternallyCompleted)
1057 LoadExternalDefinition();
1059 return data().ReferencedProtocols.end();
1062 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1063 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
1065 protocol_loc_range protocol_locs() const {
1066 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
1068 protocol_loc_iterator protocol_loc_begin() const {
1069 // FIXME: Should make sure no callers ever do this.
1070 if (!hasDefinition())
1071 return protocol_loc_iterator();
1073 if (data().ExternallyCompleted)
1074 LoadExternalDefinition();
1076 return data().ReferencedProtocols.loc_begin();
1079 protocol_loc_iterator protocol_loc_end() const {
1080 // FIXME: Should make sure no callers ever do this.
1081 if (!hasDefinition())
1082 return protocol_loc_iterator();
1084 if (data().ExternallyCompleted)
1085 LoadExternalDefinition();
1087 return data().ReferencedProtocols.loc_end();
1090 typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
1091 typedef llvm::iterator_range<all_protocol_iterator> all_protocol_range;
1093 all_protocol_range all_referenced_protocols() const {
1094 return all_protocol_range(all_referenced_protocol_begin(),
1095 all_referenced_protocol_end());
1097 all_protocol_iterator all_referenced_protocol_begin() const {
1098 // FIXME: Should make sure no callers ever do this.
1099 if (!hasDefinition())
1100 return all_protocol_iterator();
1102 if (data().ExternallyCompleted)
1103 LoadExternalDefinition();
1105 return data().AllReferencedProtocols.empty()
1107 : data().AllReferencedProtocols.begin();
1109 all_protocol_iterator all_referenced_protocol_end() const {
1110 // FIXME: Should make sure no callers ever do this.
1111 if (!hasDefinition())
1112 return all_protocol_iterator();
1114 if (data().ExternallyCompleted)
1115 LoadExternalDefinition();
1117 return data().AllReferencedProtocols.empty()
1119 : data().AllReferencedProtocols.end();
1122 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1123 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
1125 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
1126 ivar_iterator ivar_begin() const {
1127 if (const ObjCInterfaceDecl *Def = getDefinition())
1128 return ivar_iterator(Def->decls_begin());
1130 // FIXME: Should make sure no callers ever do this.
1131 return ivar_iterator();
1133 ivar_iterator ivar_end() const {
1134 if (const ObjCInterfaceDecl *Def = getDefinition())
1135 return ivar_iterator(Def->decls_end());
1137 // FIXME: Should make sure no callers ever do this.
1138 return ivar_iterator();
1141 unsigned ivar_size() const {
1142 return std::distance(ivar_begin(), ivar_end());
1145 bool ivar_empty() const { return ivar_begin() == ivar_end(); }
1147 ObjCIvarDecl *all_declared_ivar_begin();
1148 const ObjCIvarDecl *all_declared_ivar_begin() const {
1149 // Even though this modifies IvarList, it's conceptually const:
1150 // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
1151 return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
1153 void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
1155 /// setProtocolList - Set the list of protocols that this interface
1157 void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
1158 const SourceLocation *Locs, ASTContext &C) {
1159 data().ReferencedProtocols.set(List, Num, Locs, C);
1162 /// mergeClassExtensionProtocolList - Merge class extension's protocol list
1163 /// into the protocol list for this class.
1164 void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
1168 /// Produce a name to be used for class's metadata. It comes either via
1169 /// objc_runtime_name attribute or class name.
1170 StringRef getObjCRuntimeNameAsString() const;
1172 /// Returns the designated initializers for the interface.
1174 /// If this declaration does not have methods marked as designated
1175 /// initializers then the interface inherits the designated initializers of
1176 /// its super class.
1177 void getDesignatedInitializers(
1178 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const;
1180 /// Returns true if the given selector is a designated initializer for the
1183 /// If this declaration does not have methods marked as designated
1184 /// initializers then the interface inherits the designated initializers of
1185 /// its super class.
1187 /// \param InitMethod if non-null and the function returns true, it receives
1188 /// the method that was marked as a designated initializer.
1190 isDesignatedInitializer(Selector Sel,
1191 const ObjCMethodDecl **InitMethod = nullptr) const;
1193 /// \brief Determine whether this particular declaration of this class is
1194 /// actually also a definition.
1195 bool isThisDeclarationADefinition() const {
1196 return getDefinition() == this;
1199 /// \brief Determine whether this class has been defined.
1200 bool hasDefinition() const {
1201 // If the name of this class is out-of-date, bring it up-to-date, which
1202 // might bring in a definition.
1203 // Note: a null value indicates that we don't have a definition and that
1204 // modules are enabled.
1205 if (!Data.getOpaqueValue()) {
1206 if (IdentifierInfo *II = getIdentifier()) {
1207 if (II->isOutOfDate()) {
1208 updateOutOfDate(*II);
1213 return Data.getPointer();
1216 /// \brief Retrieve the definition of this class, or NULL if this class
1217 /// has been forward-declared (with \@class) but not yet defined (with
1219 ObjCInterfaceDecl *getDefinition() {
1220 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1223 /// \brief Retrieve the definition of this class, or NULL if this class
1224 /// has been forward-declared (with \@class) but not yet defined (with
1226 const ObjCInterfaceDecl *getDefinition() const {
1227 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1230 /// \brief Starts the definition of this Objective-C class, taking it from
1231 /// a forward declaration (\@class) to a definition (\@interface).
1232 void startDefinition();
1234 /// Retrieve the superclass type.
1235 const ObjCObjectType *getSuperClassType() const {
1236 if (TypeSourceInfo *TInfo = getSuperClassTInfo())
1237 return TInfo->getType()->castAs<ObjCObjectType>();
1242 // Retrieve the type source information for the superclass.
1243 TypeSourceInfo *getSuperClassTInfo() const {
1244 // FIXME: Should make sure no callers ever do this.
1245 if (!hasDefinition())
1248 if (data().ExternallyCompleted)
1249 LoadExternalDefinition();
1251 return data().SuperClassTInfo;
1254 // Retrieve the declaration for the superclass of this class, which
1255 // does not include any type arguments that apply to the superclass.
1256 ObjCInterfaceDecl *getSuperClass() const;
1258 void setSuperClass(TypeSourceInfo *superClass) {
1259 data().SuperClassTInfo = superClass;
1262 /// \brief Iterator that walks over the list of categories, filtering out
1263 /// those that do not meet specific criteria.
1265 /// This class template is used for the various permutations of category
1266 /// and extension iterators.
1267 template<bool (*Filter)(ObjCCategoryDecl *)>
1268 class filtered_category_iterator {
1269 ObjCCategoryDecl *Current;
1271 void findAcceptableCategory();
1274 typedef ObjCCategoryDecl * value_type;
1275 typedef value_type reference;
1276 typedef value_type pointer;
1277 typedef std::ptrdiff_t difference_type;
1278 typedef std::input_iterator_tag iterator_category;
1280 filtered_category_iterator() : Current(nullptr) { }
1281 explicit filtered_category_iterator(ObjCCategoryDecl *Current)
1284 findAcceptableCategory();
1287 reference operator*() const { return Current; }
1288 pointer operator->() const { return Current; }
1290 filtered_category_iterator &operator++();
1292 filtered_category_iterator operator++(int) {
1293 filtered_category_iterator Tmp = *this;
1298 friend bool operator==(filtered_category_iterator X,
1299 filtered_category_iterator Y) {
1300 return X.Current == Y.Current;
1303 friend bool operator!=(filtered_category_iterator X,
1304 filtered_category_iterator Y) {
1305 return X.Current != Y.Current;
1310 /// \brief Test whether the given category is visible.
1312 /// Used in the \c visible_categories_iterator.
1313 static bool isVisibleCategory(ObjCCategoryDecl *Cat);
1316 /// \brief Iterator that walks over the list of categories and extensions
1317 /// that are visible, i.e., not hidden in a non-imported submodule.
1318 typedef filtered_category_iterator<isVisibleCategory>
1319 visible_categories_iterator;
1321 typedef llvm::iterator_range<visible_categories_iterator>
1322 visible_categories_range;
1324 visible_categories_range visible_categories() const {
1325 return visible_categories_range(visible_categories_begin(),
1326 visible_categories_end());
1329 /// \brief Retrieve an iterator to the beginning of the visible-categories
1331 visible_categories_iterator visible_categories_begin() const {
1332 return visible_categories_iterator(getCategoryListRaw());
1335 /// \brief Retrieve an iterator to the end of the visible-categories list.
1336 visible_categories_iterator visible_categories_end() const {
1337 return visible_categories_iterator();
1340 /// \brief Determine whether the visible-categories list is empty.
1341 bool visible_categories_empty() const {
1342 return visible_categories_begin() == visible_categories_end();
1346 /// \brief Test whether the given category... is a category.
1348 /// Used in the \c known_categories_iterator.
1349 static bool isKnownCategory(ObjCCategoryDecl *) { return true; }
1352 /// \brief Iterator that walks over all of the known categories and
1353 /// extensions, including those that are hidden.
1354 typedef filtered_category_iterator<isKnownCategory> known_categories_iterator;
1355 typedef llvm::iterator_range<known_categories_iterator>
1356 known_categories_range;
1358 known_categories_range known_categories() const {
1359 return known_categories_range(known_categories_begin(),
1360 known_categories_end());
1363 /// \brief Retrieve an iterator to the beginning of the known-categories
1365 known_categories_iterator known_categories_begin() const {
1366 return known_categories_iterator(getCategoryListRaw());
1369 /// \brief Retrieve an iterator to the end of the known-categories list.
1370 known_categories_iterator known_categories_end() const {
1371 return known_categories_iterator();
1374 /// \brief Determine whether the known-categories list is empty.
1375 bool known_categories_empty() const {
1376 return known_categories_begin() == known_categories_end();
1380 /// \brief Test whether the given category is a visible extension.
1382 /// Used in the \c visible_extensions_iterator.
1383 static bool isVisibleExtension(ObjCCategoryDecl *Cat);
1386 /// \brief Iterator that walks over all of the visible extensions, skipping
1387 /// any that are known but hidden.
1388 typedef filtered_category_iterator<isVisibleExtension>
1389 visible_extensions_iterator;
1391 typedef llvm::iterator_range<visible_extensions_iterator>
1392 visible_extensions_range;
1394 visible_extensions_range visible_extensions() const {
1395 return visible_extensions_range(visible_extensions_begin(),
1396 visible_extensions_end());
1399 /// \brief Retrieve an iterator to the beginning of the visible-extensions
1401 visible_extensions_iterator visible_extensions_begin() const {
1402 return visible_extensions_iterator(getCategoryListRaw());
1405 /// \brief Retrieve an iterator to the end of the visible-extensions list.
1406 visible_extensions_iterator visible_extensions_end() const {
1407 return visible_extensions_iterator();
1410 /// \brief Determine whether the visible-extensions list is empty.
1411 bool visible_extensions_empty() const {
1412 return visible_extensions_begin() == visible_extensions_end();
1416 /// \brief Test whether the given category is an extension.
1418 /// Used in the \c known_extensions_iterator.
1419 static bool isKnownExtension(ObjCCategoryDecl *Cat);
1422 /// \brief Iterator that walks over all of the known extensions.
1423 typedef filtered_category_iterator<isKnownExtension>
1424 known_extensions_iterator;
1425 typedef llvm::iterator_range<known_extensions_iterator>
1426 known_extensions_range;
1428 known_extensions_range known_extensions() const {
1429 return known_extensions_range(known_extensions_begin(),
1430 known_extensions_end());
1433 /// \brief Retrieve an iterator to the beginning of the known-extensions
1435 known_extensions_iterator known_extensions_begin() const {
1436 return known_extensions_iterator(getCategoryListRaw());
1439 /// \brief Retrieve an iterator to the end of the known-extensions list.
1440 known_extensions_iterator known_extensions_end() const {
1441 return known_extensions_iterator();
1444 /// \brief Determine whether the known-extensions list is empty.
1445 bool known_extensions_empty() const {
1446 return known_extensions_begin() == known_extensions_end();
1449 /// \brief Retrieve the raw pointer to the start of the category/extension
1451 ObjCCategoryDecl* getCategoryListRaw() const {
1452 // FIXME: Should make sure no callers ever do this.
1453 if (!hasDefinition())
1456 if (data().ExternallyCompleted)
1457 LoadExternalDefinition();
1459 return data().CategoryList;
1462 /// \brief Set the raw pointer to the start of the category/extension
1464 void setCategoryListRaw(ObjCCategoryDecl *category) {
1465 data().CategoryList = category;
1469 *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
1471 void collectPropertiesToImplement(PropertyMap &PM,
1472 PropertyDeclOrder &PO) const override;
1474 /// isSuperClassOf - Return true if this class is the specified class or is a
1475 /// super class of the specified interface class.
1476 bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
1477 // If RHS is derived from LHS it is OK; else it is not OK.
1478 while (I != nullptr) {
1479 if (declaresSameEntity(this, I))
1482 I = I->getSuperClass();
1487 /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
1488 /// to be incompatible with __weak references. Returns true if it is.
1489 bool isArcWeakrefUnavailable() const;
1491 /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
1492 /// classes must not be auto-synthesized. Returns class decl. if it must not
1493 /// be; 0, otherwise.
1494 const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const;
1496 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
1497 ObjCInterfaceDecl *&ClassDeclared);
1498 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
1499 ObjCInterfaceDecl *ClassDeclared;
1500 return lookupInstanceVariable(IVarName, ClassDeclared);
1503 ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name);
1505 // Lookup a method. First, we search locally. If a method isn't
1506 // found, we search referenced protocols and class categories.
1507 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
1508 bool shallowCategoryLookup = false,
1509 bool followSuper = true,
1510 const ObjCCategoryDecl *C = nullptr) const;
1512 /// Lookup an instance method for a given selector.
1513 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1514 return lookupMethod(Sel, true/*isInstance*/);
1517 /// Lookup a class method for a given selector.
1518 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1519 return lookupMethod(Sel, false/*isInstance*/);
1521 ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
1523 /// \brief Lookup a method in the classes implementation hierarchy.
1524 ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
1525 bool Instance=true) const;
1527 ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) {
1528 return lookupPrivateMethod(Sel, false);
1531 /// \brief Lookup a setter or getter in the class hierarchy,
1532 /// including in all categories except for category passed
1534 ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel,
1535 const ObjCCategoryDecl *Cat) const {
1536 return lookupMethod(Sel, true/*isInstance*/,
1537 false/*shallowCategoryLookup*/,
1538 true /* followsSuper */,
1542 SourceLocation getEndOfDefinitionLoc() const {
1543 if (!hasDefinition())
1544 return getLocation();
1546 return data().EndLoc;
1549 void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
1551 /// Retrieve the starting location of the superclass.
1552 SourceLocation getSuperClassLoc() const;
1554 /// isImplicitInterfaceDecl - check that this is an implicitly declared
1555 /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
1556 /// declaration without an \@interface declaration.
1557 bool isImplicitInterfaceDecl() const {
1558 return hasDefinition() ? data().Definition->isImplicit() : isImplicit();
1561 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1562 /// has been implemented in IDecl class, its super class or categories (if
1563 /// lookupCategory is true).
1564 bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1565 bool lookupCategory,
1566 bool RHSIsQualifiedID = false);
1568 typedef redeclarable_base::redecl_range redecl_range;
1569 typedef redeclarable_base::redecl_iterator redecl_iterator;
1570 using redeclarable_base::redecls_begin;
1571 using redeclarable_base::redecls_end;
1572 using redeclarable_base::redecls;
1573 using redeclarable_base::getPreviousDecl;
1574 using redeclarable_base::getMostRecentDecl;
1575 using redeclarable_base::isFirstDecl;
1577 /// Retrieves the canonical declaration of this Objective-C class.
1578 ObjCInterfaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
1579 const ObjCInterfaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
1581 // Low-level accessor
1582 const Type *getTypeForDecl() const { return TypeForDecl; }
1583 void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
1585 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1586 static bool classofKind(Kind K) { return K == ObjCInterface; }
1588 friend class ASTReader;
1589 friend class ASTDeclReader;
1590 friend class ASTDeclWriter;
1593 const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const;
1594 bool inheritsDesignatedInitializers() const;
1597 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
1598 /// instance variables are identical to C. The only exception is Objective-C
1599 /// supports C++ style access control. For example:
1601 /// \@interface IvarExample : NSObject
1603 /// id defaultToProtected;
1605 /// id canBePublic; // same as C++.
1607 /// id canBeProtected; // same as C++.
1609 /// id canBePackage; // framework visibility (not available in C++).
1612 class ObjCIvarDecl : public FieldDecl {
1613 void anchor() override;
1616 enum AccessControl {
1617 None, Private, Protected, Public, Package
1621 ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1622 SourceLocation IdLoc, IdentifierInfo *Id,
1623 QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1625 : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1626 /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1627 NextIvar(nullptr), DeclAccess(ac), Synthesized(synthesized) {}
1630 static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1631 SourceLocation StartLoc, SourceLocation IdLoc,
1632 IdentifierInfo *Id, QualType T,
1633 TypeSourceInfo *TInfo,
1634 AccessControl ac, Expr *BW = nullptr,
1635 bool synthesized=false);
1637 static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1639 /// \brief Return the class interface that this ivar is logically contained
1640 /// in; this is either the interface where the ivar was declared, or the
1641 /// interface the ivar is conceptually a part of in the case of synthesized
1643 const ObjCInterfaceDecl *getContainingInterface() const;
1645 ObjCIvarDecl *getNextIvar() { return NextIvar; }
1646 const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
1647 void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
1649 void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1651 AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1653 AccessControl getCanonicalAccessControl() const {
1654 return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1657 void setSynthesize(bool synth) { Synthesized = synth; }
1658 bool getSynthesize() const { return Synthesized; }
1660 /// Retrieve the type of this instance variable when viewed as a member of a
1661 /// specific object type.
1662 QualType getUsageType(QualType objectType) const;
1664 // Implement isa/cast/dyncast/etc.
1665 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1666 static bool classofKind(Kind K) { return K == ObjCIvar; }
1668 /// NextIvar - Next Ivar in the list of ivars declared in class; class's
1669 /// extensions and class's implementation
1670 ObjCIvarDecl *NextIvar;
1672 // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1673 unsigned DeclAccess : 3;
1674 unsigned Synthesized : 1;
1678 /// \brief Represents a field declaration created by an \@defs(...).
1679 class ObjCAtDefsFieldDecl : public FieldDecl {
1680 void anchor() override;
1681 ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1682 SourceLocation IdLoc, IdentifierInfo *Id,
1683 QualType T, Expr *BW)
1684 : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1685 /*TInfo=*/nullptr, // FIXME: Do ObjCAtDefs have declarators ?
1686 BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
1689 static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1690 SourceLocation StartLoc,
1691 SourceLocation IdLoc, IdentifierInfo *Id,
1692 QualType T, Expr *BW);
1694 static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1696 // Implement isa/cast/dyncast/etc.
1697 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1698 static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
1701 /// \brief Represents an Objective-C protocol declaration.
1703 /// Objective-C protocols declare a pure abstract type (i.e., no instance
1704 /// variables are permitted). Protocols originally drew inspiration from
1705 /// C++ pure virtual functions (a C++ feature with nice semantics and lousy
1706 /// syntax:-). Here is an example:
1709 /// \@protocol NSDraggingInfo <refproto1, refproto2>
1710 /// - (NSWindow *)draggingDestinationWindow;
1711 /// - (NSImage *)draggedImage;
1715 /// This says that NSDraggingInfo requires two methods and requires everything
1716 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1720 /// \@interface ImplementsNSDraggingInfo : NSObject \<NSDraggingInfo>
1724 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
1725 /// protocols are in distinct namespaces. For example, Cocoa defines both
1726 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
1727 /// protocols are referenced using angle brackets as follows:
1729 /// id \<NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
1731 class ObjCProtocolDecl : public ObjCContainerDecl,
1732 public Redeclarable<ObjCProtocolDecl> {
1733 void anchor() override;
1735 struct DefinitionData {
1736 // \brief The declaration that defines this protocol.
1737 ObjCProtocolDecl *Definition;
1739 /// \brief Referenced protocols
1740 ObjCProtocolList ReferencedProtocols;
1743 /// \brief Contains a pointer to the data associated with this class,
1744 /// which will be NULL if this class has not yet been defined.
1746 /// The bit indicates when we don't need to check for out-of-date
1747 /// declarations. It will be set unless modules are enabled.
1748 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
1750 DefinitionData &data() const {
1751 assert(Data.getPointer() && "Objective-C protocol has no definition!");
1752 return *Data.getPointer();
1755 ObjCProtocolDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
1756 SourceLocation nameLoc, SourceLocation atStartLoc,
1757 ObjCProtocolDecl *PrevDecl);
1759 void allocateDefinitionData();
1761 typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
1762 ObjCProtocolDecl *getNextRedeclarationImpl() override {
1763 return getNextRedeclaration();
1765 ObjCProtocolDecl *getPreviousDeclImpl() override {
1766 return getPreviousDecl();
1768 ObjCProtocolDecl *getMostRecentDeclImpl() override {
1769 return getMostRecentDecl();
1773 static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
1775 SourceLocation nameLoc,
1776 SourceLocation atStartLoc,
1777 ObjCProtocolDecl *PrevDecl);
1779 static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1781 const ObjCProtocolList &getReferencedProtocols() const {
1782 assert(hasDefinition() && "No definition available!");
1783 return data().ReferencedProtocols;
1785 typedef ObjCProtocolList::iterator protocol_iterator;
1786 typedef llvm::iterator_range<protocol_iterator> protocol_range;
1788 protocol_range protocols() const {
1789 return protocol_range(protocol_begin(), protocol_end());
1791 protocol_iterator protocol_begin() const {
1792 if (!hasDefinition())
1793 return protocol_iterator();
1795 return data().ReferencedProtocols.begin();
1797 protocol_iterator protocol_end() const {
1798 if (!hasDefinition())
1799 return protocol_iterator();
1801 return data().ReferencedProtocols.end();
1803 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1804 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
1806 protocol_loc_range protocol_locs() const {
1807 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
1809 protocol_loc_iterator protocol_loc_begin() const {
1810 if (!hasDefinition())
1811 return protocol_loc_iterator();
1813 return data().ReferencedProtocols.loc_begin();
1815 protocol_loc_iterator protocol_loc_end() const {
1816 if (!hasDefinition())
1817 return protocol_loc_iterator();
1819 return data().ReferencedProtocols.loc_end();
1821 unsigned protocol_size() const {
1822 if (!hasDefinition())
1825 return data().ReferencedProtocols.size();
1828 /// setProtocolList - Set the list of protocols that this interface
1830 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
1831 const SourceLocation *Locs, ASTContext &C) {
1832 assert(hasDefinition() && "Protocol is not defined");
1833 data().ReferencedProtocols.set(List, Num, Locs, C);
1836 ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
1838 // Lookup a method. First, we search locally. If a method isn't
1839 // found, we search referenced protocols and class categories.
1840 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
1841 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1842 return lookupMethod(Sel, true/*isInstance*/);
1844 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1845 return lookupMethod(Sel, false/*isInstance*/);
1848 /// \brief Determine whether this protocol has a definition.
1849 bool hasDefinition() const {
1850 // If the name of this protocol is out-of-date, bring it up-to-date, which
1851 // might bring in a definition.
1852 // Note: a null value indicates that we don't have a definition and that
1853 // modules are enabled.
1854 if (!Data.getOpaqueValue()) {
1855 if (IdentifierInfo *II = getIdentifier()) {
1856 if (II->isOutOfDate()) {
1857 updateOutOfDate(*II);
1862 return Data.getPointer();
1865 /// \brief Retrieve the definition of this protocol, if any.
1866 ObjCProtocolDecl *getDefinition() {
1867 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1870 /// \brief Retrieve the definition of this protocol, if any.
1871 const ObjCProtocolDecl *getDefinition() const {
1872 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1875 /// \brief Determine whether this particular declaration is also the
1877 bool isThisDeclarationADefinition() const {
1878 return getDefinition() == this;
1881 /// \brief Starts the definition of this Objective-C protocol.
1882 void startDefinition();
1884 /// Produce a name to be used for protocol's metadata. It comes either via
1885 /// objc_runtime_name attribute or protocol name.
1886 StringRef getObjCRuntimeNameAsString() const;
1888 SourceRange getSourceRange() const override LLVM_READONLY {
1889 if (isThisDeclarationADefinition())
1890 return ObjCContainerDecl::getSourceRange();
1892 return SourceRange(getAtStartLoc(), getLocation());
1895 typedef redeclarable_base::redecl_range redecl_range;
1896 typedef redeclarable_base::redecl_iterator redecl_iterator;
1897 using redeclarable_base::redecls_begin;
1898 using redeclarable_base::redecls_end;
1899 using redeclarable_base::redecls;
1900 using redeclarable_base::getPreviousDecl;
1901 using redeclarable_base::getMostRecentDecl;
1902 using redeclarable_base::isFirstDecl;
1904 /// Retrieves the canonical declaration of this Objective-C protocol.
1905 ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); }
1906 const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); }
1908 void collectPropertiesToImplement(PropertyMap &PM,
1909 PropertyDeclOrder &PO) const override;
1911 void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property,
1912 ProtocolPropertyMap &PM) const;
1914 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1915 static bool classofKind(Kind K) { return K == ObjCProtocol; }
1917 friend class ASTReader;
1918 friend class ASTDeclReader;
1919 friend class ASTDeclWriter;
1922 /// ObjCCategoryDecl - Represents a category declaration. A category allows
1923 /// you to add methods to an existing class (without subclassing or modifying
1924 /// the original class interface or implementation:-). Categories don't allow
1925 /// you to add instance data. The following example adds "myMethod" to all
1926 /// NSView's within a process:
1928 /// \@interface NSView (MyViewMethods)
1932 /// Categories also allow you to split the implementation of a class across
1933 /// several files (a feature more naturally supported in C++).
1935 /// Categories were originally inspired by dynamic languages such as Common
1936 /// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
1937 /// don't support this level of dynamism, which is both powerful and dangerous.
1939 class ObjCCategoryDecl : public ObjCContainerDecl {
1940 void anchor() override;
1942 /// Interface belonging to this category
1943 ObjCInterfaceDecl *ClassInterface;
1945 /// The type parameters associated with this category, if any.
1946 ObjCTypeParamList *TypeParamList;
1948 /// referenced protocols in this category.
1949 ObjCProtocolList ReferencedProtocols;
1951 /// Next category belonging to this class.
1952 /// FIXME: this should not be a singly-linked list. Move storage elsewhere.
1953 ObjCCategoryDecl *NextClassCategory;
1955 /// \brief The location of the category name in this declaration.
1956 SourceLocation CategoryNameLoc;
1958 /// class extension may have private ivars.
1959 SourceLocation IvarLBraceLoc;
1960 SourceLocation IvarRBraceLoc;
1962 ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1963 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1964 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1965 ObjCTypeParamList *typeParamList,
1966 SourceLocation IvarLBraceLoc=SourceLocation(),
1967 SourceLocation IvarRBraceLoc=SourceLocation());
1971 static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1972 SourceLocation AtLoc,
1973 SourceLocation ClassNameLoc,
1974 SourceLocation CategoryNameLoc,
1976 ObjCInterfaceDecl *IDecl,
1977 ObjCTypeParamList *typeParamList,
1978 SourceLocation IvarLBraceLoc=SourceLocation(),
1979 SourceLocation IvarRBraceLoc=SourceLocation());
1980 static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1982 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1983 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1985 /// Retrieve the type parameter list associated with this category or
1987 ObjCTypeParamList *getTypeParamList() const { return TypeParamList; }
1989 /// Set the type parameters of this category.
1991 /// This function is used by the AST importer, which must import the type
1992 /// parameters after creating their DeclContext to avoid loops.
1993 void setTypeParamList(ObjCTypeParamList *TPL);
1996 ObjCCategoryImplDecl *getImplementation() const;
1997 void setImplementation(ObjCCategoryImplDecl *ImplD);
1999 /// setProtocolList - Set the list of protocols that this interface
2001 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2002 const SourceLocation *Locs, ASTContext &C) {
2003 ReferencedProtocols.set(List, Num, Locs, C);
2006 const ObjCProtocolList &getReferencedProtocols() const {
2007 return ReferencedProtocols;
2010 typedef ObjCProtocolList::iterator protocol_iterator;
2011 typedef llvm::iterator_range<protocol_iterator> protocol_range;
2013 protocol_range protocols() const {
2014 return protocol_range(protocol_begin(), protocol_end());
2016 protocol_iterator protocol_begin() const {
2017 return ReferencedProtocols.begin();
2019 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
2020 unsigned protocol_size() const { return ReferencedProtocols.size(); }
2021 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
2022 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
2024 protocol_loc_range protocol_locs() const {
2025 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2027 protocol_loc_iterator protocol_loc_begin() const {
2028 return ReferencedProtocols.loc_begin();
2030 protocol_loc_iterator protocol_loc_end() const {
2031 return ReferencedProtocols.loc_end();
2034 ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
2036 /// \brief Retrieve the pointer to the next stored category (or extension),
2037 /// which may be hidden.
2038 ObjCCategoryDecl *getNextClassCategoryRaw() const {
2039 return NextClassCategory;
2042 bool IsClassExtension() const { return getIdentifier() == nullptr; }
2044 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
2045 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
2047 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2048 ivar_iterator ivar_begin() const {
2049 return ivar_iterator(decls_begin());
2051 ivar_iterator ivar_end() const {
2052 return ivar_iterator(decls_end());
2054 unsigned ivar_size() const {
2055 return std::distance(ivar_begin(), ivar_end());
2057 bool ivar_empty() const {
2058 return ivar_begin() == ivar_end();
2061 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2062 void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
2064 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2065 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2066 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2067 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2069 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2070 static bool classofKind(Kind K) { return K == ObjCCategory; }
2072 friend class ASTDeclReader;
2073 friend class ASTDeclWriter;
2076 class ObjCImplDecl : public ObjCContainerDecl {
2077 void anchor() override;
2079 /// Class interface for this class/category implementation
2080 ObjCInterfaceDecl *ClassInterface;
2083 ObjCImplDecl(Kind DK, DeclContext *DC,
2084 ObjCInterfaceDecl *classInterface,
2085 SourceLocation nameLoc, SourceLocation atStartLoc)
2086 : ObjCContainerDecl(DK, DC,
2087 classInterface? classInterface->getIdentifier()
2089 nameLoc, atStartLoc),
2090 ClassInterface(classInterface) {}
2093 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2094 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2095 void setClassInterface(ObjCInterfaceDecl *IFace);
2097 void addInstanceMethod(ObjCMethodDecl *method) {
2098 // FIXME: Context should be set correctly before we get here.
2099 method->setLexicalDeclContext(this);
2102 void addClassMethod(ObjCMethodDecl *method) {
2103 // FIXME: Context should be set correctly before we get here.
2104 method->setLexicalDeclContext(this);
2108 void addPropertyImplementation(ObjCPropertyImplDecl *property);
2110 ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
2111 ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
2113 // Iterator access to properties.
2114 typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
2115 typedef llvm::iterator_range<specific_decl_iterator<ObjCPropertyImplDecl>>
2118 propimpl_range property_impls() const {
2119 return propimpl_range(propimpl_begin(), propimpl_end());
2121 propimpl_iterator propimpl_begin() const {
2122 return propimpl_iterator(decls_begin());
2124 propimpl_iterator propimpl_end() const {
2125 return propimpl_iterator(decls_end());
2128 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2129 static bool classofKind(Kind K) {
2130 return K >= firstObjCImpl && K <= lastObjCImpl;
2134 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
2135 /// \@implementation declaration. If a category class has declaration of a
2136 /// property, its implementation must be specified in the category's
2137 /// \@implementation declaration. Example:
2138 /// \@interface I \@end
2139 /// \@interface I(CATEGORY)
2140 /// \@property int p1, d1;
2142 /// \@implementation I(CATEGORY)
2143 /// \@dynamic p1,d1;
2146 /// ObjCCategoryImplDecl
2147 class ObjCCategoryImplDecl : public ObjCImplDecl {
2148 void anchor() override;
2153 // Category name location
2154 SourceLocation CategoryNameLoc;
2156 ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
2157 ObjCInterfaceDecl *classInterface,
2158 SourceLocation nameLoc, SourceLocation atStartLoc,
2159 SourceLocation CategoryNameLoc)
2160 : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
2161 Id(Id), CategoryNameLoc(CategoryNameLoc) {}
2163 static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
2165 ObjCInterfaceDecl *classInterface,
2166 SourceLocation nameLoc,
2167 SourceLocation atStartLoc,
2168 SourceLocation CategoryNameLoc);
2169 static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2171 /// getIdentifier - Get the identifier that names the category
2172 /// interface associated with this implementation.
2173 /// FIXME: This is a bad API, we are hiding NamedDecl::getIdentifier()
2174 /// with a different meaning. For example:
2175 /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
2176 /// returns the class interface name, whereas
2177 /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
2178 /// returns the category name.
2179 IdentifierInfo *getIdentifier() const {
2182 void setIdentifier(IdentifierInfo *II) { Id = II; }
2184 ObjCCategoryDecl *getCategoryDecl() const;
2186 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2188 /// getName - Get the name of identifier for the class interface associated
2189 /// with this implementation as a StringRef.
2191 // FIXME: This is a bad API, we are hiding NamedDecl::getName with a different
2193 StringRef getName() const { return Id ? Id->getName() : StringRef(); }
2195 /// @brief Get the name of the class associated with this interface.
2197 // FIXME: Deprecated, move clients to getName().
2198 std::string getNameAsString() const {
2202 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2203 static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
2205 friend class ASTDeclReader;
2206 friend class ASTDeclWriter;
2209 raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
2211 /// ObjCImplementationDecl - Represents a class definition - this is where
2212 /// method definitions are specified. For example:
2215 /// \@implementation MyClass
2216 /// - (void)myMethod { /* do something */ }
2220 /// In a non-fragile runtime, instance variables can appear in the class
2221 /// interface, class extensions (nameless categories), and in the implementation
2222 /// itself, as well as being synthesized as backing storage for properties.
2224 /// In a fragile runtime, instance variables are specified in the class
2225 /// interface, \em not in the implementation. Nevertheless (for legacy reasons),
2226 /// we allow instance variables to be specified in the implementation. When
2227 /// specified, they need to be \em identical to the interface.
2228 class ObjCImplementationDecl : public ObjCImplDecl {
2229 void anchor() override;
2230 /// Implementation Class's super class.
2231 ObjCInterfaceDecl *SuperClass;
2232 SourceLocation SuperLoc;
2234 /// \@implementation may have private ivars.
2235 SourceLocation IvarLBraceLoc;
2236 SourceLocation IvarRBraceLoc;
2238 /// Support for ivar initialization.
2239 /// \brief The arguments used to initialize the ivars
2240 LazyCXXCtorInitializersPtr IvarInitializers;
2241 unsigned NumIvarInitializers;
2243 /// Do the ivars of this class require initialization other than
2244 /// zero-initialization?
2245 bool HasNonZeroConstructors : 1;
2247 /// Do the ivars of this class require non-trivial destruction?
2248 bool HasDestructors : 1;
2250 ObjCImplementationDecl(DeclContext *DC,
2251 ObjCInterfaceDecl *classInterface,
2252 ObjCInterfaceDecl *superDecl,
2253 SourceLocation nameLoc, SourceLocation atStartLoc,
2254 SourceLocation superLoc = SourceLocation(),
2255 SourceLocation IvarLBraceLoc=SourceLocation(),
2256 SourceLocation IvarRBraceLoc=SourceLocation())
2257 : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
2258 SuperClass(superDecl), SuperLoc(superLoc), IvarLBraceLoc(IvarLBraceLoc),
2259 IvarRBraceLoc(IvarRBraceLoc),
2260 IvarInitializers(nullptr), NumIvarInitializers(0),
2261 HasNonZeroConstructors(false), HasDestructors(false) {}
2263 static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
2264 ObjCInterfaceDecl *classInterface,
2265 ObjCInterfaceDecl *superDecl,
2266 SourceLocation nameLoc,
2267 SourceLocation atStartLoc,
2268 SourceLocation superLoc = SourceLocation(),
2269 SourceLocation IvarLBraceLoc=SourceLocation(),
2270 SourceLocation IvarRBraceLoc=SourceLocation());
2272 static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2274 /// init_iterator - Iterates through the ivar initializer list.
2275 typedef CXXCtorInitializer **init_iterator;
2277 /// init_const_iterator - Iterates through the ivar initializer list.
2278 typedef CXXCtorInitializer * const * init_const_iterator;
2280 typedef llvm::iterator_range<init_iterator> init_range;
2281 typedef llvm::iterator_range<init_const_iterator> init_const_range;
2283 init_range inits() { return init_range(init_begin(), init_end()); }
2284 init_const_range inits() const {
2285 return init_const_range(init_begin(), init_end());
2288 /// init_begin() - Retrieve an iterator to the first initializer.
2289 init_iterator init_begin() {
2290 const auto *ConstThis = this;
2291 return const_cast<init_iterator>(ConstThis->init_begin());
2293 /// begin() - Retrieve an iterator to the first initializer.
2294 init_const_iterator init_begin() const;
2296 /// init_end() - Retrieve an iterator past the last initializer.
2297 init_iterator init_end() {
2298 return init_begin() + NumIvarInitializers;
2300 /// end() - Retrieve an iterator past the last initializer.
2301 init_const_iterator init_end() const {
2302 return init_begin() + NumIvarInitializers;
2304 /// getNumArgs - Number of ivars which must be initialized.
2305 unsigned getNumIvarInitializers() const {
2306 return NumIvarInitializers;
2309 void setNumIvarInitializers(unsigned numNumIvarInitializers) {
2310 NumIvarInitializers = numNumIvarInitializers;
2313 void setIvarInitializers(ASTContext &C,
2314 CXXCtorInitializer ** initializers,
2315 unsigned numInitializers);
2317 /// Do any of the ivars of this class (not counting its base classes)
2318 /// require construction other than zero-initialization?
2319 bool hasNonZeroConstructors() const { return HasNonZeroConstructors; }
2320 void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; }
2322 /// Do any of the ivars of this class (not counting its base classes)
2323 /// require non-trivial destruction?
2324 bool hasDestructors() const { return HasDestructors; }
2325 void setHasDestructors(bool val) { HasDestructors = val; }
2327 /// getIdentifier - Get the identifier that names the class
2328 /// interface associated with this implementation.
2329 IdentifierInfo *getIdentifier() const {
2330 return getClassInterface()->getIdentifier();
2333 /// getName - Get the name of identifier for the class interface associated
2334 /// with this implementation as a StringRef.
2336 // FIXME: This is a bad API, we are hiding NamedDecl::getName with a different
2338 StringRef getName() const {
2339 assert(getIdentifier() && "Name is not a simple identifier");
2340 return getIdentifier()->getName();
2343 /// @brief Get the name of the class associated with this interface.
2345 // FIXME: Move to StringRef API.
2346 std::string getNameAsString() const {
2350 /// Produce a name to be used for class's metadata. It comes either via
2351 /// class's objc_runtime_name attribute or class name.
2352 StringRef getObjCRuntimeNameAsString() const;
2354 const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
2355 ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
2356 SourceLocation getSuperClassLoc() const { return SuperLoc; }
2358 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
2360 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2361 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2362 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2363 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2365 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
2366 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
2368 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2369 ivar_iterator ivar_begin() const {
2370 return ivar_iterator(decls_begin());
2372 ivar_iterator ivar_end() const {
2373 return ivar_iterator(decls_end());
2375 unsigned ivar_size() const {
2376 return std::distance(ivar_begin(), ivar_end());
2378 bool ivar_empty() const {
2379 return ivar_begin() == ivar_end();
2382 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2383 static bool classofKind(Kind K) { return K == ObjCImplementation; }
2385 friend class ASTDeclReader;
2386 friend class ASTDeclWriter;
2389 raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
2391 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
2392 /// declared as \@compatibility_alias alias class.
2393 class ObjCCompatibleAliasDecl : public NamedDecl {
2394 void anchor() override;
2395 /// Class that this is an alias of.
2396 ObjCInterfaceDecl *AliasedClass;
2398 ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2399 ObjCInterfaceDecl* aliasedClass)
2400 : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
2402 static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
2403 SourceLocation L, IdentifierInfo *Id,
2404 ObjCInterfaceDecl* aliasedClass);
2406 static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
2409 const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
2410 ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
2411 void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
2413 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2414 static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
2418 /// \brief Represents one property declaration in an Objective-C interface.
2422 /// \@property (assign, readwrite) int MyProperty;
2424 class ObjCPropertyDecl : public NamedDecl {
2425 void anchor() override;
2427 enum PropertyAttributeKind {
2428 OBJC_PR_noattr = 0x00,
2429 OBJC_PR_readonly = 0x01,
2430 OBJC_PR_getter = 0x02,
2431 OBJC_PR_assign = 0x04,
2432 OBJC_PR_readwrite = 0x08,
2433 OBJC_PR_retain = 0x10,
2434 OBJC_PR_copy = 0x20,
2435 OBJC_PR_nonatomic = 0x40,
2436 OBJC_PR_setter = 0x80,
2437 OBJC_PR_atomic = 0x100,
2438 OBJC_PR_weak = 0x200,
2439 OBJC_PR_strong = 0x400,
2440 OBJC_PR_unsafe_unretained = 0x800,
2441 /// Indicates that the nullability of the type was spelled with a
2442 /// property attribute rather than a type qualifier.
2443 OBJC_PR_nullability = 0x1000,
2444 OBJC_PR_null_resettable = 0x2000
2445 // Adding a property should change NumPropertyAttrsBits
2449 /// \brief Number of bits fitting all the property attributes.
2450 NumPropertyAttrsBits = 14
2453 enum SetterKind { Assign, Retain, Copy, Weak };
2454 enum PropertyControl { None, Required, Optional };
2456 SourceLocation AtLoc; // location of \@property
2457 SourceLocation LParenLoc; // location of '(' starting attribute list or null.
2459 TypeSourceInfo *DeclTypeSourceInfo;
2460 unsigned PropertyAttributes : NumPropertyAttrsBits;
2461 unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
2462 // \@required/\@optional
2463 unsigned PropertyImplementation : 2;
2465 Selector GetterName; // getter name of NULL if no getter
2466 Selector SetterName; // setter name of NULL if no setter
2468 ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
2469 ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
2470 ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
2472 ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2473 SourceLocation AtLocation, SourceLocation LParenLocation,
2474 QualType T, TypeSourceInfo *TSI,
2475 PropertyControl propControl)
2476 : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
2477 LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI),
2478 PropertyAttributes(OBJC_PR_noattr),
2479 PropertyAttributesAsWritten(OBJC_PR_noattr),
2480 PropertyImplementation(propControl),
2481 GetterName(Selector()),
2482 SetterName(Selector()),
2483 GetterMethodDecl(nullptr), SetterMethodDecl(nullptr),
2484 PropertyIvarDecl(nullptr) {}
2487 static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
2489 IdentifierInfo *Id, SourceLocation AtLocation,
2490 SourceLocation LParenLocation,
2492 TypeSourceInfo *TSI,
2493 PropertyControl propControl = None);
2495 static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2497 SourceLocation getAtLoc() const { return AtLoc; }
2498 void setAtLoc(SourceLocation L) { AtLoc = L; }
2500 SourceLocation getLParenLoc() const { return LParenLoc; }
2501 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2503 TypeSourceInfo *getTypeSourceInfo() const { return DeclTypeSourceInfo; }
2505 QualType getType() const { return DeclType; }
2507 void setType(QualType T, TypeSourceInfo *TSI) {
2509 DeclTypeSourceInfo = TSI;
2512 /// Retrieve the type when this property is used with a specific base object
2514 QualType getUsageType(QualType objectType) const;
2516 PropertyAttributeKind getPropertyAttributes() const {
2517 return PropertyAttributeKind(PropertyAttributes);
2519 void setPropertyAttributes(PropertyAttributeKind PRVal) {
2520 PropertyAttributes |= PRVal;
2523 PropertyAttributeKind getPropertyAttributesAsWritten() const {
2524 return PropertyAttributeKind(PropertyAttributesAsWritten);
2527 bool hasWrittenStorageAttribute() const {
2528 return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
2529 OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
2533 void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
2534 PropertyAttributesAsWritten = PRVal;
2537 void makeitReadWriteAttribute() {
2538 PropertyAttributes &= ~OBJC_PR_readonly;
2539 PropertyAttributes |= OBJC_PR_readwrite;
2542 // Helper methods for accessing attributes.
2544 /// isReadOnly - Return true iff the property has a setter.
2545 bool isReadOnly() const {
2546 return (PropertyAttributes & OBJC_PR_readonly);
2549 /// isAtomic - Return true if the property is atomic.
2550 bool isAtomic() const {
2551 return (PropertyAttributes & OBJC_PR_atomic);
2554 /// isRetaining - Return true if the property retains its value.
2555 bool isRetaining() const {
2556 return (PropertyAttributes &
2557 (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
2560 /// getSetterKind - Return the method used for doing assignment in
2561 /// the property setter. This is only valid if the property has been
2562 /// defined to have a setter.
2563 SetterKind getSetterKind() const {
2564 if (PropertyAttributes & OBJC_PR_strong)
2565 return getType()->isBlockPointerType() ? Copy : Retain;
2566 if (PropertyAttributes & OBJC_PR_retain)
2568 if (PropertyAttributes & OBJC_PR_copy)
2570 if (PropertyAttributes & OBJC_PR_weak)
2575 Selector getGetterName() const { return GetterName; }
2576 void setGetterName(Selector Sel) { GetterName = Sel; }
2578 Selector getSetterName() const { return SetterName; }
2579 void setSetterName(Selector Sel) { SetterName = Sel; }
2581 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
2582 void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
2584 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
2585 void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
2587 // Related to \@optional/\@required declared in \@protocol
2588 void setPropertyImplementation(PropertyControl pc) {
2589 PropertyImplementation = pc;
2591 PropertyControl getPropertyImplementation() const {
2592 return PropertyControl(PropertyImplementation);
2595 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
2596 PropertyIvarDecl = Ivar;
2598 ObjCIvarDecl *getPropertyIvarDecl() const {
2599 return PropertyIvarDecl;
2602 SourceRange getSourceRange() const override LLVM_READONLY {
2603 return SourceRange(AtLoc, getLocation());
2606 /// Get the default name of the synthesized ivar.
2607 IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const;
2609 /// Lookup a property by name in the specified DeclContext.
2610 static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
2611 const IdentifierInfo *propertyID);
2613 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2614 static bool classofKind(Kind K) { return K == ObjCProperty; }
2617 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
2618 /// in a class or category implementation block. For example:
2619 /// \@synthesize prop1 = ivar1;
2621 class ObjCPropertyImplDecl : public Decl {
2628 SourceLocation AtLoc; // location of \@synthesize or \@dynamic
2630 /// \brief For \@synthesize, the location of the ivar, if it was written in
2631 /// the source code.
2634 /// \@synthesize int a = b
2636 SourceLocation IvarLoc;
2638 /// Property declaration being implemented
2639 ObjCPropertyDecl *PropertyDecl;
2641 /// Null for \@dynamic. Required for \@synthesize.
2642 ObjCIvarDecl *PropertyIvarDecl;
2644 /// Null for \@dynamic. Non-null if property must be copy-constructed in
2646 Expr *GetterCXXConstructor;
2648 /// Null for \@dynamic. Non-null if property has assignment operator to call
2649 /// in Setter synthesis.
2650 Expr *SetterCXXAssignment;
2652 ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
2653 ObjCPropertyDecl *property,
2655 ObjCIvarDecl *ivarDecl,
2656 SourceLocation ivarLoc)
2657 : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
2658 IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
2659 GetterCXXConstructor(nullptr), SetterCXXAssignment(nullptr) {
2660 assert (PK == Dynamic || PropertyIvarDecl);
2664 static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
2665 SourceLocation atLoc, SourceLocation L,
2666 ObjCPropertyDecl *property,
2668 ObjCIvarDecl *ivarDecl,
2669 SourceLocation ivarLoc);
2671 static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2673 SourceRange getSourceRange() const override LLVM_READONLY;
2675 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
2676 void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
2678 ObjCPropertyDecl *getPropertyDecl() const {
2679 return PropertyDecl;
2681 void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
2683 Kind getPropertyImplementation() const {
2684 return PropertyIvarDecl ? Synthesize : Dynamic;
2687 ObjCIvarDecl *getPropertyIvarDecl() const {
2688 return PropertyIvarDecl;
2690 SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
2692 void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
2693 SourceLocation IvarLoc) {
2694 PropertyIvarDecl = Ivar;
2695 this->IvarLoc = IvarLoc;
2698 /// \brief For \@synthesize, returns true if an ivar name was explicitly
2702 /// \@synthesize int a = b; // true
2703 /// \@synthesize int a; // false
2705 bool isIvarNameSpecified() const {
2706 return IvarLoc.isValid() && IvarLoc != getLocation();
2709 Expr *getGetterCXXConstructor() const {
2710 return GetterCXXConstructor;
2712 void setGetterCXXConstructor(Expr *getterCXXConstructor) {
2713 GetterCXXConstructor = getterCXXConstructor;
2716 Expr *getSetterCXXAssignment() const {
2717 return SetterCXXAssignment;
2719 void setSetterCXXAssignment(Expr *setterCXXAssignment) {
2720 SetterCXXAssignment = setterCXXAssignment;
2723 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2724 static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2726 friend class ASTDeclReader;
2729 template<bool (*Filter)(ObjCCategoryDecl *)>
2731 ObjCInterfaceDecl::filtered_category_iterator<Filter>::
2732 findAcceptableCategory() {
2733 while (Current && !Filter(Current))
2734 Current = Current->getNextClassCategoryRaw();
2737 template<bool (*Filter)(ObjCCategoryDecl *)>
2738 inline ObjCInterfaceDecl::filtered_category_iterator<Filter> &
2739 ObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() {
2740 Current = Current->getNextClassCategoryRaw();
2741 findAcceptableCategory();
2745 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
2746 return !Cat->isHidden();
2749 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
2750 return Cat->IsClassExtension() && !Cat->isHidden();
2753 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
2754 return Cat->IsClassExtension();
2757 } // end namespace clang