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_const_iterator param_begin() const {
355 return param_const_iterator(getParams());
357 param_const_iterator param_end() const {
358 return param_const_iterator(getParams() + NumParams);
360 param_iterator param_begin() { return param_iterator(getParams()); }
361 param_iterator param_end() { return param_iterator(getParams() + NumParams); }
363 // This method returns and of the parameters which are part of the selector
364 // name mangling requirements.
365 param_const_iterator sel_param_end() const {
366 return param_begin() + getSelector().getNumArgs();
369 // ArrayRef access to formal parameters. This should eventually
370 // replace the iterator interface above.
371 ArrayRef<ParmVarDecl*> parameters() const {
372 return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
376 /// \brief Sets the method's parameters and selector source locations.
377 /// If the method is implicit (not coming from source) \p SelLocs is
379 void setMethodParams(ASTContext &C,
380 ArrayRef<ParmVarDecl*> Params,
381 ArrayRef<SourceLocation> SelLocs = llvm::None);
383 // Iterator access to parameter types.
385 QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); }
387 typedef llvm::mapped_iterator<param_const_iterator, GetTypeFn>
390 param_type_iterator param_type_begin() const {
391 return llvm::map_iterator(param_begin(), GetTypeFn());
393 param_type_iterator param_type_end() const {
394 return llvm::map_iterator(param_end(), GetTypeFn());
397 /// createImplicitParams - Used to lazily create the self and cmd
398 /// implict parameters. This must be called prior to using getSelfDecl()
399 /// or getCmdDecl(). The call is ignored if the implicit parameters
400 /// have already been created.
401 void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
403 /// \return the type for \c self and set \arg selfIsPseudoStrong and
404 /// \arg selfIsConsumed accordingly.
405 QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID,
406 bool &selfIsPseudoStrong, bool &selfIsConsumed);
408 ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
409 void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
410 ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
411 void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
413 /// Determines the family of this method.
414 ObjCMethodFamily getMethodFamily() const;
416 bool isInstanceMethod() const { return IsInstance; }
417 void setInstanceMethod(bool isInst) { IsInstance = isInst; }
418 bool isVariadic() const { return IsVariadic; }
419 void setVariadic(bool isVar) { IsVariadic = isVar; }
421 bool isClassMethod() const { return !IsInstance; }
423 bool isPropertyAccessor() const { return IsPropertyAccessor; }
424 void setPropertyAccessor(bool isAccessor) { IsPropertyAccessor = isAccessor; }
426 bool isDefined() const { return IsDefined; }
427 void setDefined(bool isDefined) { IsDefined = isDefined; }
429 /// \brief Whether this method overrides any other in the class hierarchy.
431 /// A method is said to override any method in the class's
432 /// base classes, its protocols, or its categories' protocols, that has
433 /// the same selector and is of the same kind (class or instance).
434 /// A method in an implementation is not considered as overriding the same
435 /// method in the interface or its categories.
436 bool isOverriding() const { return IsOverriding; }
437 void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
439 /// \brief Return overridden methods for the given \p Method.
441 /// An ObjC method is considered to override any method in the class's
442 /// base classes (and base's categories), its protocols, or its categories'
443 /// protocols, that has
444 /// the same selector and is of the same kind (class or instance).
445 /// A method in an implementation is not considered as overriding the same
446 /// method in the interface or its categories.
447 void getOverriddenMethods(
448 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
450 /// \brief True if the method was a definition but its body was skipped.
451 bool hasSkippedBody() const { return HasSkippedBody; }
452 void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
454 /// \brief Returns the property associated with this method's selector.
456 /// Note that even if this particular method is not marked as a property
457 /// accessor, it is still possible for it to match a property declared in a
458 /// superclass. Pass \c false if you only want to check the current class.
459 const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
461 // Related to protocols declared in \@protocol
462 void setDeclImplementation(ImplementationControl ic) {
463 DeclImplementation = ic;
465 ImplementationControl getImplementationControl() const {
466 return ImplementationControl(DeclImplementation);
468 bool isOptional() const {
469 return getImplementationControl() == Optional;
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 final
616 : private llvm::TrailingObjects<ObjCTypeParamList, ObjCTypeParamDecl *> {
617 /// Stores the components of a SourceRange as a POD.
618 struct PODSourceRange {
624 /// Location of the left and right angle brackets.
625 PODSourceRange Brackets;
627 // Used only for alignment.
628 ObjCTypeParamDecl *AlignmentHack;
631 /// The number of parameters in the list, which are tail-allocated.
634 ObjCTypeParamList(SourceLocation lAngleLoc,
635 ArrayRef<ObjCTypeParamDecl *> typeParams,
636 SourceLocation rAngleLoc);
639 /// Create a new Objective-C type parameter list.
640 static ObjCTypeParamList *create(ASTContext &ctx,
641 SourceLocation lAngleLoc,
642 ArrayRef<ObjCTypeParamDecl *> typeParams,
643 SourceLocation rAngleLoc);
645 /// Iterate through the type parameters in the list.
646 typedef ObjCTypeParamDecl **iterator;
648 iterator begin() { return getTrailingObjects<ObjCTypeParamDecl *>(); }
650 iterator end() { return begin() + size(); }
652 /// Determine the number of type parameters in this list.
653 unsigned size() const { return NumParams; }
655 // Iterate through the type parameters in the list.
656 typedef ObjCTypeParamDecl * const *const_iterator;
658 const_iterator begin() const {
659 return getTrailingObjects<ObjCTypeParamDecl *>();
662 const_iterator end() const {
663 return begin() + size();
666 ObjCTypeParamDecl *front() const {
667 assert(size() > 0 && "empty Objective-C type parameter list");
671 ObjCTypeParamDecl *back() const {
672 assert(size() > 0 && "empty Objective-C type parameter list");
676 SourceLocation getLAngleLoc() const {
677 return SourceLocation::getFromRawEncoding(Brackets.Begin);
679 SourceLocation getRAngleLoc() const {
680 return SourceLocation::getFromRawEncoding(Brackets.End);
682 SourceRange getSourceRange() const {
683 return SourceRange(getLAngleLoc(), getRAngleLoc());
686 /// Gather the default set of type arguments to be substituted for
687 /// these type parameters when dealing with an unspecialized type.
688 void gatherDefaultTypeArgs(SmallVectorImpl<QualType> &typeArgs) const;
689 friend TrailingObjects;
692 enum class ObjCPropertyQueryKind : uint8_t {
693 OBJC_PR_query_unknown = 0x00,
694 OBJC_PR_query_instance,
698 /// \brief Represents one property declaration in an Objective-C interface.
702 /// \@property (assign, readwrite) int MyProperty;
704 class ObjCPropertyDecl : public NamedDecl {
705 void anchor() override;
707 enum PropertyAttributeKind {
708 OBJC_PR_noattr = 0x00,
709 OBJC_PR_readonly = 0x01,
710 OBJC_PR_getter = 0x02,
711 OBJC_PR_assign = 0x04,
712 OBJC_PR_readwrite = 0x08,
713 OBJC_PR_retain = 0x10,
715 OBJC_PR_nonatomic = 0x40,
716 OBJC_PR_setter = 0x80,
717 OBJC_PR_atomic = 0x100,
718 OBJC_PR_weak = 0x200,
719 OBJC_PR_strong = 0x400,
720 OBJC_PR_unsafe_unretained = 0x800,
721 /// Indicates that the nullability of the type was spelled with a
722 /// property attribute rather than a type qualifier.
723 OBJC_PR_nullability = 0x1000,
724 OBJC_PR_null_resettable = 0x2000,
725 OBJC_PR_class = 0x4000
726 // Adding a property should change NumPropertyAttrsBits
730 /// \brief Number of bits fitting all the property attributes.
731 NumPropertyAttrsBits = 15
734 enum SetterKind { Assign, Retain, Copy, Weak };
735 enum PropertyControl { None, Required, Optional };
737 SourceLocation AtLoc; // location of \@property
738 SourceLocation LParenLoc; // location of '(' starting attribute list or null.
740 TypeSourceInfo *DeclTypeSourceInfo;
741 unsigned PropertyAttributes : NumPropertyAttrsBits;
742 unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
743 // \@required/\@optional
744 unsigned PropertyImplementation : 2;
746 Selector GetterName; // getter name of NULL if no getter
747 Selector SetterName; // setter name of NULL if no setter
748 SourceLocation GetterNameLoc; // location of the getter attribute's value
749 SourceLocation SetterNameLoc; // location of the setter attribute's value
751 ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
752 ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
753 ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
755 ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
756 SourceLocation AtLocation, SourceLocation LParenLocation,
757 QualType T, TypeSourceInfo *TSI,
758 PropertyControl propControl)
759 : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
760 LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI),
761 PropertyAttributes(OBJC_PR_noattr),
762 PropertyAttributesAsWritten(OBJC_PR_noattr),
763 PropertyImplementation(propControl),
764 GetterName(Selector()),
765 SetterName(Selector()),
766 GetterMethodDecl(nullptr), SetterMethodDecl(nullptr),
767 PropertyIvarDecl(nullptr) {}
770 static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
772 IdentifierInfo *Id, SourceLocation AtLocation,
773 SourceLocation LParenLocation,
776 PropertyControl propControl = None);
778 static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
780 SourceLocation getAtLoc() const { return AtLoc; }
781 void setAtLoc(SourceLocation L) { AtLoc = L; }
783 SourceLocation getLParenLoc() const { return LParenLoc; }
784 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
786 TypeSourceInfo *getTypeSourceInfo() const { return DeclTypeSourceInfo; }
788 QualType getType() const { return DeclType; }
790 void setType(QualType T, TypeSourceInfo *TSI) {
792 DeclTypeSourceInfo = TSI;
795 /// Retrieve the type when this property is used with a specific base object
797 QualType getUsageType(QualType objectType) const;
799 PropertyAttributeKind getPropertyAttributes() const {
800 return PropertyAttributeKind(PropertyAttributes);
802 void setPropertyAttributes(PropertyAttributeKind PRVal) {
803 PropertyAttributes |= PRVal;
805 void overwritePropertyAttributes(unsigned PRVal) {
806 PropertyAttributes = PRVal;
809 PropertyAttributeKind getPropertyAttributesAsWritten() const {
810 return PropertyAttributeKind(PropertyAttributesAsWritten);
813 void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
814 PropertyAttributesAsWritten = PRVal;
817 // Helper methods for accessing attributes.
819 /// isReadOnly - Return true iff the property has a setter.
820 bool isReadOnly() const {
821 return (PropertyAttributes & OBJC_PR_readonly);
824 /// isAtomic - Return true if the property is atomic.
825 bool isAtomic() const {
826 return (PropertyAttributes & OBJC_PR_atomic);
829 /// isRetaining - Return true if the property retains its value.
830 bool isRetaining() const {
831 return (PropertyAttributes &
832 (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
835 bool isInstanceProperty() const { return !isClassProperty(); }
836 bool isClassProperty() const { return PropertyAttributes & OBJC_PR_class; }
837 ObjCPropertyQueryKind getQueryKind() const {
838 return isClassProperty() ? ObjCPropertyQueryKind::OBJC_PR_query_class :
839 ObjCPropertyQueryKind::OBJC_PR_query_instance;
841 static ObjCPropertyQueryKind getQueryKind(bool isClassProperty) {
842 return isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class :
843 ObjCPropertyQueryKind::OBJC_PR_query_instance;
846 /// getSetterKind - Return the method used for doing assignment in
847 /// the property setter. This is only valid if the property has been
848 /// defined to have a setter.
849 SetterKind getSetterKind() const {
850 if (PropertyAttributes & OBJC_PR_strong)
851 return getType()->isBlockPointerType() ? Copy : Retain;
852 if (PropertyAttributes & OBJC_PR_retain)
854 if (PropertyAttributes & OBJC_PR_copy)
856 if (PropertyAttributes & OBJC_PR_weak)
861 Selector getGetterName() const { return GetterName; }
862 SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
863 void setGetterName(Selector Sel, SourceLocation Loc = SourceLocation()) {
868 Selector getSetterName() const { return SetterName; }
869 SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
870 void setSetterName(Selector Sel, SourceLocation Loc = SourceLocation()) {
875 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
876 void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
878 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
879 void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
881 // Related to \@optional/\@required declared in \@protocol
882 void setPropertyImplementation(PropertyControl pc) {
883 PropertyImplementation = pc;
885 PropertyControl getPropertyImplementation() const {
886 return PropertyControl(PropertyImplementation);
888 bool isOptional() const {
889 return getPropertyImplementation() == PropertyControl::Optional;
892 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
893 PropertyIvarDecl = Ivar;
895 ObjCIvarDecl *getPropertyIvarDecl() const {
896 return PropertyIvarDecl;
899 SourceRange getSourceRange() const override LLVM_READONLY {
900 return SourceRange(AtLoc, getLocation());
903 /// Get the default name of the synthesized ivar.
904 IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const;
906 /// Lookup a property by name in the specified DeclContext.
907 static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
908 const IdentifierInfo *propertyID,
909 ObjCPropertyQueryKind queryKind);
911 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
912 static bool classofKind(Kind K) { return K == ObjCProperty; }
915 /// ObjCContainerDecl - Represents a container for method declarations.
916 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
917 /// ObjCProtocolDecl, and ObjCImplDecl.
919 class ObjCContainerDecl : public NamedDecl, public DeclContext {
920 void anchor() override;
922 SourceLocation AtStart;
924 // These two locations in the range mark the end of the method container.
925 // The first points to the '@' token, and the second to the 'end' token.
929 ObjCContainerDecl(Kind DK, DeclContext *DC,
930 IdentifierInfo *Id, SourceLocation nameLoc,
931 SourceLocation atStartLoc)
932 : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
934 // Iterator access to instance/class properties.
935 typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
936 typedef llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>
939 prop_range properties() const { return prop_range(prop_begin(), prop_end()); }
940 prop_iterator prop_begin() const {
941 return prop_iterator(decls_begin());
943 prop_iterator prop_end() const {
944 return prop_iterator(decls_end());
947 typedef filtered_decl_iterator<ObjCPropertyDecl,
948 &ObjCPropertyDecl::isInstanceProperty>
950 typedef llvm::iterator_range<instprop_iterator> instprop_range;
952 instprop_range instance_properties() const {
953 return instprop_range(instprop_begin(), instprop_end());
955 instprop_iterator instprop_begin() const {
956 return instprop_iterator(decls_begin());
958 instprop_iterator instprop_end() const {
959 return instprop_iterator(decls_end());
962 typedef filtered_decl_iterator<ObjCPropertyDecl,
963 &ObjCPropertyDecl::isClassProperty>
965 typedef llvm::iterator_range<classprop_iterator> classprop_range;
967 classprop_range class_properties() const {
968 return classprop_range(classprop_begin(), classprop_end());
970 classprop_iterator classprop_begin() const {
971 return classprop_iterator(decls_begin());
973 classprop_iterator classprop_end() const {
974 return classprop_iterator(decls_end());
977 // Iterator access to instance/class methods.
978 typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
979 typedef llvm::iterator_range<specific_decl_iterator<ObjCMethodDecl>>
982 method_range methods() const {
983 return method_range(meth_begin(), meth_end());
985 method_iterator meth_begin() const {
986 return method_iterator(decls_begin());
988 method_iterator meth_end() const {
989 return method_iterator(decls_end());
992 typedef filtered_decl_iterator<ObjCMethodDecl,
993 &ObjCMethodDecl::isInstanceMethod>
995 typedef llvm::iterator_range<instmeth_iterator> instmeth_range;
997 instmeth_range instance_methods() const {
998 return instmeth_range(instmeth_begin(), instmeth_end());
1000 instmeth_iterator instmeth_begin() const {
1001 return instmeth_iterator(decls_begin());
1003 instmeth_iterator instmeth_end() const {
1004 return instmeth_iterator(decls_end());
1007 typedef filtered_decl_iterator<ObjCMethodDecl,
1008 &ObjCMethodDecl::isClassMethod>
1010 typedef llvm::iterator_range<classmeth_iterator> classmeth_range;
1012 classmeth_range class_methods() const {
1013 return classmeth_range(classmeth_begin(), classmeth_end());
1015 classmeth_iterator classmeth_begin() const {
1016 return classmeth_iterator(decls_begin());
1018 classmeth_iterator classmeth_end() const {
1019 return classmeth_iterator(decls_end());
1022 // Get the local instance/class method declared in this interface.
1023 ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
1024 bool AllowHidden = false) const;
1025 ObjCMethodDecl *getInstanceMethod(Selector Sel,
1026 bool AllowHidden = false) const {
1027 return getMethod(Sel, true/*isInstance*/, AllowHidden);
1029 ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
1030 return getMethod(Sel, false/*isInstance*/, AllowHidden);
1032 bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
1033 ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
1036 FindPropertyDeclaration(const IdentifierInfo *PropertyId,
1037 ObjCPropertyQueryKind QueryKind) const;
1039 typedef llvm::DenseMap<std::pair<IdentifierInfo*,
1040 unsigned/*isClassProperty*/>,
1041 ObjCPropertyDecl*> PropertyMap;
1043 typedef llvm::DenseMap<const ObjCProtocolDecl *, ObjCPropertyDecl*>
1044 ProtocolPropertyMap;
1046 typedef llvm::SmallVector<ObjCPropertyDecl*, 8> PropertyDeclOrder;
1048 /// This routine collects list of properties to be implemented in the class.
1049 /// This includes, class's and its conforming protocols' properties.
1050 /// Note, the superclass's properties are not included in the list.
1051 virtual void collectPropertiesToImplement(PropertyMap &PM,
1052 PropertyDeclOrder &PO) const {}
1054 SourceLocation getAtStartLoc() const { return AtStart; }
1055 void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
1057 // Marks the end of the container.
1058 SourceRange getAtEndRange() const {
1061 void setAtEndRange(SourceRange atEnd) {
1065 SourceRange getSourceRange() const override LLVM_READONLY {
1066 return SourceRange(AtStart, getAtEndRange().getEnd());
1069 // Implement isa/cast/dyncast/etc.
1070 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1071 static bool classofKind(Kind K) {
1072 return K >= firstObjCContainer &&
1073 K <= lastObjCContainer;
1076 static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
1077 return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
1079 static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
1080 return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
1084 /// \brief Represents an ObjC class declaration.
1089 /// // MostPrimitive declares no super class (not particularly useful).
1090 /// \@interface MostPrimitive
1091 /// // no instance variables or methods.
1094 /// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
1095 /// \@interface NSResponder : NSObject \<NSCoding>
1096 /// { // instance variables are represented by ObjCIvarDecl.
1097 /// id nextResponder; // nextResponder instance variable.
1099 /// - (NSResponder *)nextResponder; // return a pointer to NSResponder.
1100 /// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
1101 /// \@end // to an NSEvent.
1104 /// Unlike C/C++, forward class declarations are accomplished with \@class.
1105 /// Unlike C/C++, \@class allows for a list of classes to be forward declared.
1106 /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
1107 /// typically inherit from NSObject (an exception is NSProxy).
1109 class ObjCInterfaceDecl : public ObjCContainerDecl
1110 , public Redeclarable<ObjCInterfaceDecl> {
1111 void anchor() override;
1113 /// TypeForDecl - This indicates the Type object that represents this
1114 /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType
1115 mutable const Type *TypeForDecl;
1116 friend class ASTContext;
1118 struct DefinitionData {
1119 /// \brief The definition of this class, for quick access from any
1121 ObjCInterfaceDecl *Definition;
1123 /// When non-null, this is always an ObjCObjectType.
1124 TypeSourceInfo *SuperClassTInfo;
1126 /// Protocols referenced in the \@interface declaration
1127 ObjCProtocolList ReferencedProtocols;
1129 /// Protocols reference in both the \@interface and class extensions.
1130 ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
1132 /// \brief List of categories and class extensions defined for this class.
1134 /// Categories are stored as a linked list in the AST, since the categories
1135 /// and class extensions come long after the initial interface declaration,
1136 /// and we avoid dynamically-resized arrays in the AST wherever possible.
1137 ObjCCategoryDecl *CategoryList;
1139 /// IvarList - List of all ivars defined by this class; including class
1140 /// extensions and implementation. This list is built lazily.
1141 ObjCIvarDecl *IvarList;
1143 /// \brief Indicates that the contents of this Objective-C class will be
1144 /// completed by the external AST source when required.
1145 mutable unsigned ExternallyCompleted : 1;
1147 /// \brief Indicates that the ivar cache does not yet include ivars
1148 /// declared in the implementation.
1149 mutable unsigned IvarListMissingImplementation : 1;
1151 /// Indicates that this interface decl contains at least one initializer
1152 /// marked with the 'objc_designated_initializer' attribute.
1153 unsigned HasDesignatedInitializers : 1;
1155 enum InheritedDesignatedInitializersState {
1156 /// We didn't calculate whether the designated initializers should be
1157 /// inherited or not.
1159 /// Designated initializers are inherited for the super class.
1161 /// The class does not inherit designated initializers.
1162 IDI_NotInherited = 2
1164 /// One of the \c InheritedDesignatedInitializersState enumeratos.
1165 mutable unsigned InheritedDesignatedInitializers : 2;
1167 /// \brief The location of the last location in this declaration, before
1168 /// the properties/methods. For example, this will be the '>', '}', or
1170 SourceLocation EndLoc;
1172 DefinitionData() : Definition(), SuperClassTInfo(), CategoryList(), IvarList(),
1173 ExternallyCompleted(),
1174 IvarListMissingImplementation(true),
1175 HasDesignatedInitializers(),
1176 InheritedDesignatedInitializers(IDI_Unknown) { }
1179 ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, SourceLocation AtLoc,
1180 IdentifierInfo *Id, ObjCTypeParamList *typeParamList,
1181 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
1184 void LoadExternalDefinition() const;
1186 /// The type parameters associated with this class, if any.
1187 ObjCTypeParamList *TypeParamList;
1189 /// \brief Contains a pointer to the data associated with this class,
1190 /// which will be NULL if this class has not yet been defined.
1192 /// The bit indicates when we don't need to check for out-of-date
1193 /// declarations. It will be set unless modules are enabled.
1194 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
1196 DefinitionData &data() const {
1197 assert(Data.getPointer() && "Declaration has no definition!");
1198 return *Data.getPointer();
1201 /// \brief Allocate the definition data for this class.
1202 void allocateDefinitionData();
1204 typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
1205 ObjCInterfaceDecl *getNextRedeclarationImpl() override {
1206 return getNextRedeclaration();
1208 ObjCInterfaceDecl *getPreviousDeclImpl() override {
1209 return getPreviousDecl();
1211 ObjCInterfaceDecl *getMostRecentDeclImpl() override {
1212 return getMostRecentDecl();
1216 static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
1217 SourceLocation atLoc,
1219 ObjCTypeParamList *typeParamList,
1220 ObjCInterfaceDecl *PrevDecl,
1221 SourceLocation ClassLoc = SourceLocation(),
1222 bool isInternal = false);
1224 static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
1226 /// Retrieve the type parameters of this class.
1228 /// This function looks for a type parameter list for the given
1229 /// class; if the class has been declared (with \c \@class) but not
1230 /// defined (with \c \@interface), it will search for a declaration that
1231 /// has type parameters, skipping any declarations that do not.
1232 ObjCTypeParamList *getTypeParamList() const;
1234 /// Set the type parameters of this class.
1236 /// This function is used by the AST importer, which must import the type
1237 /// parameters after creating their DeclContext to avoid loops.
1238 void setTypeParamList(ObjCTypeParamList *TPL);
1240 /// Retrieve the type parameters written on this particular declaration of
1242 ObjCTypeParamList *getTypeParamListAsWritten() const {
1243 return TypeParamList;
1246 SourceRange getSourceRange() const override LLVM_READONLY {
1247 if (isThisDeclarationADefinition())
1248 return ObjCContainerDecl::getSourceRange();
1250 return SourceRange(getAtStartLoc(), getLocation());
1253 /// \brief Indicate that this Objective-C class is complete, but that
1254 /// the external AST source will be responsible for filling in its contents
1255 /// when a complete class is required.
1256 void setExternallyCompleted();
1258 /// Indicate that this interface decl contains at least one initializer
1259 /// marked with the 'objc_designated_initializer' attribute.
1260 void setHasDesignatedInitializers();
1262 /// Returns true if this interface decl contains at least one initializer
1263 /// marked with the 'objc_designated_initializer' attribute.
1264 bool hasDesignatedInitializers() const;
1266 /// Returns true if this interface decl declares a designated initializer
1267 /// or it inherites one from its super class.
1268 bool declaresOrInheritsDesignatedInitializers() const {
1269 return hasDesignatedInitializers() || inheritsDesignatedInitializers();
1272 const ObjCProtocolList &getReferencedProtocols() const {
1273 assert(hasDefinition() && "Caller did not check for forward reference!");
1274 if (data().ExternallyCompleted)
1275 LoadExternalDefinition();
1277 return data().ReferencedProtocols;
1280 ObjCImplementationDecl *getImplementation() const;
1281 void setImplementation(ObjCImplementationDecl *ImplD);
1283 ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
1285 // Get the local instance/class method declared in a category.
1286 ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
1287 ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
1288 ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
1289 return isInstance ? getCategoryInstanceMethod(Sel)
1290 : getCategoryClassMethod(Sel);
1293 typedef ObjCProtocolList::iterator protocol_iterator;
1294 typedef llvm::iterator_range<protocol_iterator> protocol_range;
1296 protocol_range protocols() const {
1297 return protocol_range(protocol_begin(), protocol_end());
1299 protocol_iterator protocol_begin() const {
1300 // FIXME: Should make sure no callers ever do this.
1301 if (!hasDefinition())
1302 return protocol_iterator();
1304 if (data().ExternallyCompleted)
1305 LoadExternalDefinition();
1307 return data().ReferencedProtocols.begin();
1309 protocol_iterator protocol_end() const {
1310 // FIXME: Should make sure no callers ever do this.
1311 if (!hasDefinition())
1312 return protocol_iterator();
1314 if (data().ExternallyCompleted)
1315 LoadExternalDefinition();
1317 return data().ReferencedProtocols.end();
1320 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1321 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
1323 protocol_loc_range protocol_locs() const {
1324 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
1326 protocol_loc_iterator protocol_loc_begin() const {
1327 // FIXME: Should make sure no callers ever do this.
1328 if (!hasDefinition())
1329 return protocol_loc_iterator();
1331 if (data().ExternallyCompleted)
1332 LoadExternalDefinition();
1334 return data().ReferencedProtocols.loc_begin();
1337 protocol_loc_iterator protocol_loc_end() const {
1338 // FIXME: Should make sure no callers ever do this.
1339 if (!hasDefinition())
1340 return protocol_loc_iterator();
1342 if (data().ExternallyCompleted)
1343 LoadExternalDefinition();
1345 return data().ReferencedProtocols.loc_end();
1348 typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
1349 typedef llvm::iterator_range<all_protocol_iterator> all_protocol_range;
1351 all_protocol_range all_referenced_protocols() const {
1352 return all_protocol_range(all_referenced_protocol_begin(),
1353 all_referenced_protocol_end());
1355 all_protocol_iterator all_referenced_protocol_begin() const {
1356 // FIXME: Should make sure no callers ever do this.
1357 if (!hasDefinition())
1358 return all_protocol_iterator();
1360 if (data().ExternallyCompleted)
1361 LoadExternalDefinition();
1363 return data().AllReferencedProtocols.empty()
1365 : data().AllReferencedProtocols.begin();
1367 all_protocol_iterator all_referenced_protocol_end() const {
1368 // FIXME: Should make sure no callers ever do this.
1369 if (!hasDefinition())
1370 return all_protocol_iterator();
1372 if (data().ExternallyCompleted)
1373 LoadExternalDefinition();
1375 return data().AllReferencedProtocols.empty()
1377 : data().AllReferencedProtocols.end();
1380 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1381 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
1383 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
1384 ivar_iterator ivar_begin() const {
1385 if (const ObjCInterfaceDecl *Def = getDefinition())
1386 return ivar_iterator(Def->decls_begin());
1388 // FIXME: Should make sure no callers ever do this.
1389 return ivar_iterator();
1391 ivar_iterator ivar_end() const {
1392 if (const ObjCInterfaceDecl *Def = getDefinition())
1393 return ivar_iterator(Def->decls_end());
1395 // FIXME: Should make sure no callers ever do this.
1396 return ivar_iterator();
1399 unsigned ivar_size() const {
1400 return std::distance(ivar_begin(), ivar_end());
1403 bool ivar_empty() const { return ivar_begin() == ivar_end(); }
1405 ObjCIvarDecl *all_declared_ivar_begin();
1406 const ObjCIvarDecl *all_declared_ivar_begin() const {
1407 // Even though this modifies IvarList, it's conceptually const:
1408 // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
1409 return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
1411 void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
1413 /// setProtocolList - Set the list of protocols that this interface
1415 void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
1416 const SourceLocation *Locs, ASTContext &C) {
1417 data().ReferencedProtocols.set(List, Num, Locs, C);
1420 /// mergeClassExtensionProtocolList - Merge class extension's protocol list
1421 /// into the protocol list for this class.
1422 void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
1426 /// Produce a name to be used for class's metadata. It comes either via
1427 /// objc_runtime_name attribute or class name.
1428 StringRef getObjCRuntimeNameAsString() const;
1430 /// Returns the designated initializers for the interface.
1432 /// If this declaration does not have methods marked as designated
1433 /// initializers then the interface inherits the designated initializers of
1434 /// its super class.
1435 void getDesignatedInitializers(
1436 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const;
1438 /// Returns true if the given selector is a designated initializer for the
1441 /// If this declaration does not have methods marked as designated
1442 /// initializers then the interface inherits the designated initializers of
1443 /// its super class.
1445 /// \param InitMethod if non-null and the function returns true, it receives
1446 /// the method that was marked as a designated initializer.
1448 isDesignatedInitializer(Selector Sel,
1449 const ObjCMethodDecl **InitMethod = nullptr) const;
1451 /// \brief Determine whether this particular declaration of this class is
1452 /// actually also a definition.
1453 bool isThisDeclarationADefinition() const {
1454 return getDefinition() == this;
1457 /// \brief Determine whether this class has been defined.
1458 bool hasDefinition() const {
1459 // If the name of this class is out-of-date, bring it up-to-date, which
1460 // might bring in a definition.
1461 // Note: a null value indicates that we don't have a definition and that
1462 // modules are enabled.
1463 if (!Data.getOpaqueValue())
1464 getMostRecentDecl();
1466 return Data.getPointer();
1469 /// \brief Retrieve the definition of this class, or NULL if this class
1470 /// has been forward-declared (with \@class) but not yet defined (with
1472 ObjCInterfaceDecl *getDefinition() {
1473 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1476 /// \brief Retrieve the definition of this class, or NULL if this class
1477 /// has been forward-declared (with \@class) but not yet defined (with
1479 const ObjCInterfaceDecl *getDefinition() const {
1480 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1483 /// \brief Starts the definition of this Objective-C class, taking it from
1484 /// a forward declaration (\@class) to a definition (\@interface).
1485 void startDefinition();
1487 /// Retrieve the superclass type.
1488 const ObjCObjectType *getSuperClassType() const {
1489 if (TypeSourceInfo *TInfo = getSuperClassTInfo())
1490 return TInfo->getType()->castAs<ObjCObjectType>();
1495 // Retrieve the type source information for the superclass.
1496 TypeSourceInfo *getSuperClassTInfo() const {
1497 // FIXME: Should make sure no callers ever do this.
1498 if (!hasDefinition())
1501 if (data().ExternallyCompleted)
1502 LoadExternalDefinition();
1504 return data().SuperClassTInfo;
1507 // Retrieve the declaration for the superclass of this class, which
1508 // does not include any type arguments that apply to the superclass.
1509 ObjCInterfaceDecl *getSuperClass() const;
1511 void setSuperClass(TypeSourceInfo *superClass) {
1512 data().SuperClassTInfo = superClass;
1515 /// \brief Iterator that walks over the list of categories, filtering out
1516 /// those that do not meet specific criteria.
1518 /// This class template is used for the various permutations of category
1519 /// and extension iterators.
1520 template<bool (*Filter)(ObjCCategoryDecl *)>
1521 class filtered_category_iterator {
1522 ObjCCategoryDecl *Current;
1524 void findAcceptableCategory();
1527 typedef ObjCCategoryDecl * value_type;
1528 typedef value_type reference;
1529 typedef value_type pointer;
1530 typedef std::ptrdiff_t difference_type;
1531 typedef std::input_iterator_tag iterator_category;
1533 filtered_category_iterator() : Current(nullptr) { }
1534 explicit filtered_category_iterator(ObjCCategoryDecl *Current)
1537 findAcceptableCategory();
1540 reference operator*() const { return Current; }
1541 pointer operator->() const { return Current; }
1543 filtered_category_iterator &operator++();
1545 filtered_category_iterator operator++(int) {
1546 filtered_category_iterator Tmp = *this;
1551 friend bool operator==(filtered_category_iterator X,
1552 filtered_category_iterator Y) {
1553 return X.Current == Y.Current;
1556 friend bool operator!=(filtered_category_iterator X,
1557 filtered_category_iterator Y) {
1558 return X.Current != Y.Current;
1563 /// \brief Test whether the given category is visible.
1565 /// Used in the \c visible_categories_iterator.
1566 static bool isVisibleCategory(ObjCCategoryDecl *Cat);
1569 /// \brief Iterator that walks over the list of categories and extensions
1570 /// that are visible, i.e., not hidden in a non-imported submodule.
1571 typedef filtered_category_iterator<isVisibleCategory>
1572 visible_categories_iterator;
1574 typedef llvm::iterator_range<visible_categories_iterator>
1575 visible_categories_range;
1577 visible_categories_range visible_categories() const {
1578 return visible_categories_range(visible_categories_begin(),
1579 visible_categories_end());
1582 /// \brief Retrieve an iterator to the beginning of the visible-categories
1584 visible_categories_iterator visible_categories_begin() const {
1585 return visible_categories_iterator(getCategoryListRaw());
1588 /// \brief Retrieve an iterator to the end of the visible-categories list.
1589 visible_categories_iterator visible_categories_end() const {
1590 return visible_categories_iterator();
1593 /// \brief Determine whether the visible-categories list is empty.
1594 bool visible_categories_empty() const {
1595 return visible_categories_begin() == visible_categories_end();
1599 /// \brief Test whether the given category... is a category.
1601 /// Used in the \c known_categories_iterator.
1602 static bool isKnownCategory(ObjCCategoryDecl *) { return true; }
1605 /// \brief Iterator that walks over all of the known categories and
1606 /// extensions, including those that are hidden.
1607 typedef filtered_category_iterator<isKnownCategory> known_categories_iterator;
1608 typedef llvm::iterator_range<known_categories_iterator>
1609 known_categories_range;
1611 known_categories_range known_categories() const {
1612 return known_categories_range(known_categories_begin(),
1613 known_categories_end());
1616 /// \brief Retrieve an iterator to the beginning of the known-categories
1618 known_categories_iterator known_categories_begin() const {
1619 return known_categories_iterator(getCategoryListRaw());
1622 /// \brief Retrieve an iterator to the end of the known-categories list.
1623 known_categories_iterator known_categories_end() const {
1624 return known_categories_iterator();
1627 /// \brief Determine whether the known-categories list is empty.
1628 bool known_categories_empty() const {
1629 return known_categories_begin() == known_categories_end();
1633 /// \brief Test whether the given category is a visible extension.
1635 /// Used in the \c visible_extensions_iterator.
1636 static bool isVisibleExtension(ObjCCategoryDecl *Cat);
1639 /// \brief Iterator that walks over all of the visible extensions, skipping
1640 /// any that are known but hidden.
1641 typedef filtered_category_iterator<isVisibleExtension>
1642 visible_extensions_iterator;
1644 typedef llvm::iterator_range<visible_extensions_iterator>
1645 visible_extensions_range;
1647 visible_extensions_range visible_extensions() const {
1648 return visible_extensions_range(visible_extensions_begin(),
1649 visible_extensions_end());
1652 /// \brief Retrieve an iterator to the beginning of the visible-extensions
1654 visible_extensions_iterator visible_extensions_begin() const {
1655 return visible_extensions_iterator(getCategoryListRaw());
1658 /// \brief Retrieve an iterator to the end of the visible-extensions list.
1659 visible_extensions_iterator visible_extensions_end() const {
1660 return visible_extensions_iterator();
1663 /// \brief Determine whether the visible-extensions list is empty.
1664 bool visible_extensions_empty() const {
1665 return visible_extensions_begin() == visible_extensions_end();
1669 /// \brief Test whether the given category is an extension.
1671 /// Used in the \c known_extensions_iterator.
1672 static bool isKnownExtension(ObjCCategoryDecl *Cat);
1675 /// \brief Iterator that walks over all of the known extensions.
1676 typedef filtered_category_iterator<isKnownExtension>
1677 known_extensions_iterator;
1678 typedef llvm::iterator_range<known_extensions_iterator>
1679 known_extensions_range;
1681 known_extensions_range known_extensions() const {
1682 return known_extensions_range(known_extensions_begin(),
1683 known_extensions_end());
1686 /// \brief Retrieve an iterator to the beginning of the known-extensions
1688 known_extensions_iterator known_extensions_begin() const {
1689 return known_extensions_iterator(getCategoryListRaw());
1692 /// \brief Retrieve an iterator to the end of the known-extensions list.
1693 known_extensions_iterator known_extensions_end() const {
1694 return known_extensions_iterator();
1697 /// \brief Determine whether the known-extensions list is empty.
1698 bool known_extensions_empty() const {
1699 return known_extensions_begin() == known_extensions_end();
1702 /// \brief Retrieve the raw pointer to the start of the category/extension
1704 ObjCCategoryDecl* getCategoryListRaw() const {
1705 // FIXME: Should make sure no callers ever do this.
1706 if (!hasDefinition())
1709 if (data().ExternallyCompleted)
1710 LoadExternalDefinition();
1712 return data().CategoryList;
1715 /// \brief Set the raw pointer to the start of the category/extension
1717 void setCategoryListRaw(ObjCCategoryDecl *category) {
1718 data().CategoryList = category;
1722 *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId,
1723 ObjCPropertyQueryKind QueryKind) const;
1725 void collectPropertiesToImplement(PropertyMap &PM,
1726 PropertyDeclOrder &PO) const override;
1728 /// isSuperClassOf - Return true if this class is the specified class or is a
1729 /// super class of the specified interface class.
1730 bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
1731 // If RHS is derived from LHS it is OK; else it is not OK.
1732 while (I != nullptr) {
1733 if (declaresSameEntity(this, I))
1736 I = I->getSuperClass();
1741 /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
1742 /// to be incompatible with __weak references. Returns true if it is.
1743 bool isArcWeakrefUnavailable() const;
1745 /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
1746 /// classes must not be auto-synthesized. Returns class decl. if it must not
1747 /// be; 0, otherwise.
1748 const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const;
1750 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
1751 ObjCInterfaceDecl *&ClassDeclared);
1752 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
1753 ObjCInterfaceDecl *ClassDeclared;
1754 return lookupInstanceVariable(IVarName, ClassDeclared);
1757 ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name);
1759 // Lookup a method. First, we search locally. If a method isn't
1760 // found, we search referenced protocols and class categories.
1761 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
1762 bool shallowCategoryLookup = false,
1763 bool followSuper = true,
1764 const ObjCCategoryDecl *C = nullptr) const;
1766 /// Lookup an instance method for a given selector.
1767 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1768 return lookupMethod(Sel, true/*isInstance*/);
1771 /// Lookup a class method for a given selector.
1772 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1773 return lookupMethod(Sel, false/*isInstance*/);
1775 ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
1777 /// \brief Lookup a method in the classes implementation hierarchy.
1778 ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
1779 bool Instance=true) const;
1781 ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) {
1782 return lookupPrivateMethod(Sel, false);
1785 /// \brief Lookup a setter or getter in the class hierarchy,
1786 /// including in all categories except for category passed
1788 ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel,
1789 const ObjCCategoryDecl *Cat,
1790 bool IsClassProperty) const {
1791 return lookupMethod(Sel, !IsClassProperty/*isInstance*/,
1792 false/*shallowCategoryLookup*/,
1793 true /* followsSuper */,
1797 SourceLocation getEndOfDefinitionLoc() const {
1798 if (!hasDefinition())
1799 return getLocation();
1801 return data().EndLoc;
1804 void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
1806 /// Retrieve the starting location of the superclass.
1807 SourceLocation getSuperClassLoc() const;
1809 /// isImplicitInterfaceDecl - check that this is an implicitly declared
1810 /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
1811 /// declaration without an \@interface declaration.
1812 bool isImplicitInterfaceDecl() const {
1813 return hasDefinition() ? data().Definition->isImplicit() : isImplicit();
1816 /// ClassImplementsProtocol - Checks that 'lProto' protocol
1817 /// has been implemented in IDecl class, its super class or categories (if
1818 /// lookupCategory is true).
1819 bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1820 bool lookupCategory,
1821 bool RHSIsQualifiedID = false);
1823 typedef redeclarable_base::redecl_range redecl_range;
1824 typedef redeclarable_base::redecl_iterator redecl_iterator;
1825 using redeclarable_base::redecls_begin;
1826 using redeclarable_base::redecls_end;
1827 using redeclarable_base::redecls;
1828 using redeclarable_base::getPreviousDecl;
1829 using redeclarable_base::getMostRecentDecl;
1830 using redeclarable_base::isFirstDecl;
1832 /// Retrieves the canonical declaration of this Objective-C class.
1833 ObjCInterfaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
1834 const ObjCInterfaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
1836 // Low-level accessor
1837 const Type *getTypeForDecl() const { return TypeForDecl; }
1838 void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
1840 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1841 static bool classofKind(Kind K) { return K == ObjCInterface; }
1843 friend class ASTReader;
1844 friend class ASTDeclReader;
1845 friend class ASTDeclWriter;
1848 const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const;
1849 bool inheritsDesignatedInitializers() const;
1852 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
1853 /// instance variables are identical to C. The only exception is Objective-C
1854 /// supports C++ style access control. For example:
1856 /// \@interface IvarExample : NSObject
1858 /// id defaultToProtected;
1860 /// id canBePublic; // same as C++.
1862 /// id canBeProtected; // same as C++.
1864 /// id canBePackage; // framework visibility (not available in C++).
1867 class ObjCIvarDecl : public FieldDecl {
1868 void anchor() override;
1871 enum AccessControl {
1872 None, Private, Protected, Public, Package
1876 ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1877 SourceLocation IdLoc, IdentifierInfo *Id,
1878 QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1880 : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1881 /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1882 NextIvar(nullptr), DeclAccess(ac), Synthesized(synthesized) {}
1885 static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1886 SourceLocation StartLoc, SourceLocation IdLoc,
1887 IdentifierInfo *Id, QualType T,
1888 TypeSourceInfo *TInfo,
1889 AccessControl ac, Expr *BW = nullptr,
1890 bool synthesized=false);
1892 static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1894 /// \brief Return the class interface that this ivar is logically contained
1895 /// in; this is either the interface where the ivar was declared, or the
1896 /// interface the ivar is conceptually a part of in the case of synthesized
1898 const ObjCInterfaceDecl *getContainingInterface() const;
1900 ObjCIvarDecl *getNextIvar() { return NextIvar; }
1901 const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
1902 void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
1904 void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1906 AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1908 AccessControl getCanonicalAccessControl() const {
1909 return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1912 void setSynthesize(bool synth) { Synthesized = synth; }
1913 bool getSynthesize() const { return Synthesized; }
1915 /// Retrieve the type of this instance variable when viewed as a member of a
1916 /// specific object type.
1917 QualType getUsageType(QualType objectType) const;
1919 // Implement isa/cast/dyncast/etc.
1920 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1921 static bool classofKind(Kind K) { return K == ObjCIvar; }
1923 /// NextIvar - Next Ivar in the list of ivars declared in class; class's
1924 /// extensions and class's implementation
1925 ObjCIvarDecl *NextIvar;
1927 // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1928 unsigned DeclAccess : 3;
1929 unsigned Synthesized : 1;
1933 /// \brief Represents a field declaration created by an \@defs(...).
1934 class ObjCAtDefsFieldDecl : public FieldDecl {
1935 void anchor() override;
1936 ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1937 SourceLocation IdLoc, IdentifierInfo *Id,
1938 QualType T, Expr *BW)
1939 : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1940 /*TInfo=*/nullptr, // FIXME: Do ObjCAtDefs have declarators ?
1941 BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
1944 static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1945 SourceLocation StartLoc,
1946 SourceLocation IdLoc, IdentifierInfo *Id,
1947 QualType T, Expr *BW);
1949 static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1951 // Implement isa/cast/dyncast/etc.
1952 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1953 static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
1956 /// \brief Represents an Objective-C protocol declaration.
1958 /// Objective-C protocols declare a pure abstract type (i.e., no instance
1959 /// variables are permitted). Protocols originally drew inspiration from
1960 /// C++ pure virtual functions (a C++ feature with nice semantics and lousy
1961 /// syntax:-). Here is an example:
1964 /// \@protocol NSDraggingInfo <refproto1, refproto2>
1965 /// - (NSWindow *)draggingDestinationWindow;
1966 /// - (NSImage *)draggedImage;
1970 /// This says that NSDraggingInfo requires two methods and requires everything
1971 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1975 /// \@interface ImplementsNSDraggingInfo : NSObject \<NSDraggingInfo>
1979 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
1980 /// protocols are in distinct namespaces. For example, Cocoa defines both
1981 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
1982 /// protocols are referenced using angle brackets as follows:
1984 /// id \<NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
1986 class ObjCProtocolDecl : public ObjCContainerDecl,
1987 public Redeclarable<ObjCProtocolDecl> {
1988 void anchor() override;
1990 struct DefinitionData {
1991 // \brief The declaration that defines this protocol.
1992 ObjCProtocolDecl *Definition;
1994 /// \brief Referenced protocols
1995 ObjCProtocolList ReferencedProtocols;
1998 /// \brief Contains a pointer to the data associated with this class,
1999 /// which will be NULL if this class has not yet been defined.
2001 /// The bit indicates when we don't need to check for out-of-date
2002 /// declarations. It will be set unless modules are enabled.
2003 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
2005 DefinitionData &data() const {
2006 assert(Data.getPointer() && "Objective-C protocol has no definition!");
2007 return *Data.getPointer();
2010 ObjCProtocolDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
2011 SourceLocation nameLoc, SourceLocation atStartLoc,
2012 ObjCProtocolDecl *PrevDecl);
2014 void allocateDefinitionData();
2016 typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
2017 ObjCProtocolDecl *getNextRedeclarationImpl() override {
2018 return getNextRedeclaration();
2020 ObjCProtocolDecl *getPreviousDeclImpl() override {
2021 return getPreviousDecl();
2023 ObjCProtocolDecl *getMostRecentDeclImpl() override {
2024 return getMostRecentDecl();
2028 static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
2030 SourceLocation nameLoc,
2031 SourceLocation atStartLoc,
2032 ObjCProtocolDecl *PrevDecl);
2034 static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2036 const ObjCProtocolList &getReferencedProtocols() const {
2037 assert(hasDefinition() && "No definition available!");
2038 return data().ReferencedProtocols;
2040 typedef ObjCProtocolList::iterator protocol_iterator;
2041 typedef llvm::iterator_range<protocol_iterator> protocol_range;
2043 protocol_range protocols() const {
2044 return protocol_range(protocol_begin(), protocol_end());
2046 protocol_iterator protocol_begin() const {
2047 if (!hasDefinition())
2048 return protocol_iterator();
2050 return data().ReferencedProtocols.begin();
2052 protocol_iterator protocol_end() const {
2053 if (!hasDefinition())
2054 return protocol_iterator();
2056 return data().ReferencedProtocols.end();
2058 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
2059 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
2061 protocol_loc_range protocol_locs() const {
2062 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2064 protocol_loc_iterator protocol_loc_begin() const {
2065 if (!hasDefinition())
2066 return protocol_loc_iterator();
2068 return data().ReferencedProtocols.loc_begin();
2070 protocol_loc_iterator protocol_loc_end() const {
2071 if (!hasDefinition())
2072 return protocol_loc_iterator();
2074 return data().ReferencedProtocols.loc_end();
2076 unsigned protocol_size() const {
2077 if (!hasDefinition())
2080 return data().ReferencedProtocols.size();
2083 /// setProtocolList - Set the list of protocols that this interface
2085 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2086 const SourceLocation *Locs, ASTContext &C) {
2087 assert(hasDefinition() && "Protocol is not defined");
2088 data().ReferencedProtocols.set(List, Num, Locs, C);
2091 ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
2093 // Lookup a method. First, we search locally. If a method isn't
2094 // found, we search referenced protocols and class categories.
2095 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
2096 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
2097 return lookupMethod(Sel, true/*isInstance*/);
2099 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
2100 return lookupMethod(Sel, false/*isInstance*/);
2103 /// \brief Determine whether this protocol has a definition.
2104 bool hasDefinition() const {
2105 // If the name of this protocol is out-of-date, bring it up-to-date, which
2106 // might bring in a definition.
2107 // Note: a null value indicates that we don't have a definition and that
2108 // modules are enabled.
2109 if (!Data.getOpaqueValue())
2110 getMostRecentDecl();
2112 return Data.getPointer();
2115 /// \brief Retrieve the definition of this protocol, if any.
2116 ObjCProtocolDecl *getDefinition() {
2117 return hasDefinition()? Data.getPointer()->Definition : nullptr;
2120 /// \brief Retrieve the definition of this protocol, if any.
2121 const ObjCProtocolDecl *getDefinition() const {
2122 return hasDefinition()? Data.getPointer()->Definition : nullptr;
2125 /// \brief Determine whether this particular declaration is also the
2127 bool isThisDeclarationADefinition() const {
2128 return getDefinition() == this;
2131 /// \brief Starts the definition of this Objective-C protocol.
2132 void startDefinition();
2134 /// Produce a name to be used for protocol's metadata. It comes either via
2135 /// objc_runtime_name attribute or protocol name.
2136 StringRef getObjCRuntimeNameAsString() const;
2138 SourceRange getSourceRange() const override LLVM_READONLY {
2139 if (isThisDeclarationADefinition())
2140 return ObjCContainerDecl::getSourceRange();
2142 return SourceRange(getAtStartLoc(), getLocation());
2145 typedef redeclarable_base::redecl_range redecl_range;
2146 typedef redeclarable_base::redecl_iterator redecl_iterator;
2147 using redeclarable_base::redecls_begin;
2148 using redeclarable_base::redecls_end;
2149 using redeclarable_base::redecls;
2150 using redeclarable_base::getPreviousDecl;
2151 using redeclarable_base::getMostRecentDecl;
2152 using redeclarable_base::isFirstDecl;
2154 /// Retrieves the canonical declaration of this Objective-C protocol.
2155 ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); }
2156 const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); }
2158 void collectPropertiesToImplement(PropertyMap &PM,
2159 PropertyDeclOrder &PO) const override;
2161 void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property,
2162 ProtocolPropertyMap &PM) const;
2164 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2165 static bool classofKind(Kind K) { return K == ObjCProtocol; }
2167 friend class ASTReader;
2168 friend class ASTDeclReader;
2169 friend class ASTDeclWriter;
2172 /// ObjCCategoryDecl - Represents a category declaration. A category allows
2173 /// you to add methods to an existing class (without subclassing or modifying
2174 /// the original class interface or implementation:-). Categories don't allow
2175 /// you to add instance data. The following example adds "myMethod" to all
2176 /// NSView's within a process:
2178 /// \@interface NSView (MyViewMethods)
2182 /// Categories also allow you to split the implementation of a class across
2183 /// several files (a feature more naturally supported in C++).
2185 /// Categories were originally inspired by dynamic languages such as Common
2186 /// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
2187 /// don't support this level of dynamism, which is both powerful and dangerous.
2189 class ObjCCategoryDecl : public ObjCContainerDecl {
2190 void anchor() override;
2192 /// Interface belonging to this category
2193 ObjCInterfaceDecl *ClassInterface;
2195 /// The type parameters associated with this category, if any.
2196 ObjCTypeParamList *TypeParamList;
2198 /// referenced protocols in this category.
2199 ObjCProtocolList ReferencedProtocols;
2201 /// Next category belonging to this class.
2202 /// FIXME: this should not be a singly-linked list. Move storage elsewhere.
2203 ObjCCategoryDecl *NextClassCategory;
2205 /// \brief The location of the category name in this declaration.
2206 SourceLocation CategoryNameLoc;
2208 /// class extension may have private ivars.
2209 SourceLocation IvarLBraceLoc;
2210 SourceLocation IvarRBraceLoc;
2212 ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
2213 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
2214 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
2215 ObjCTypeParamList *typeParamList,
2216 SourceLocation IvarLBraceLoc=SourceLocation(),
2217 SourceLocation IvarRBraceLoc=SourceLocation());
2221 static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
2222 SourceLocation AtLoc,
2223 SourceLocation ClassNameLoc,
2224 SourceLocation CategoryNameLoc,
2226 ObjCInterfaceDecl *IDecl,
2227 ObjCTypeParamList *typeParamList,
2228 SourceLocation IvarLBraceLoc=SourceLocation(),
2229 SourceLocation IvarRBraceLoc=SourceLocation());
2230 static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2232 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2233 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2235 /// Retrieve the type parameter list associated with this category or
2237 ObjCTypeParamList *getTypeParamList() const { return TypeParamList; }
2239 /// Set the type parameters of this category.
2241 /// This function is used by the AST importer, which must import the type
2242 /// parameters after creating their DeclContext to avoid loops.
2243 void setTypeParamList(ObjCTypeParamList *TPL);
2246 ObjCCategoryImplDecl *getImplementation() const;
2247 void setImplementation(ObjCCategoryImplDecl *ImplD);
2249 /// setProtocolList - Set the list of protocols that this interface
2251 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2252 const SourceLocation *Locs, ASTContext &C) {
2253 ReferencedProtocols.set(List, Num, Locs, C);
2256 const ObjCProtocolList &getReferencedProtocols() const {
2257 return ReferencedProtocols;
2260 typedef ObjCProtocolList::iterator protocol_iterator;
2261 typedef llvm::iterator_range<protocol_iterator> protocol_range;
2263 protocol_range protocols() const {
2264 return protocol_range(protocol_begin(), protocol_end());
2266 protocol_iterator protocol_begin() const {
2267 return ReferencedProtocols.begin();
2269 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
2270 unsigned protocol_size() const { return ReferencedProtocols.size(); }
2271 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
2272 typedef llvm::iterator_range<protocol_loc_iterator> protocol_loc_range;
2274 protocol_loc_range protocol_locs() const {
2275 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2277 protocol_loc_iterator protocol_loc_begin() const {
2278 return ReferencedProtocols.loc_begin();
2280 protocol_loc_iterator protocol_loc_end() const {
2281 return ReferencedProtocols.loc_end();
2284 ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
2286 /// \brief Retrieve the pointer to the next stored category (or extension),
2287 /// which may be hidden.
2288 ObjCCategoryDecl *getNextClassCategoryRaw() const {
2289 return NextClassCategory;
2292 bool IsClassExtension() const { return getIdentifier() == nullptr; }
2294 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
2295 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
2297 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2298 ivar_iterator ivar_begin() const {
2299 return ivar_iterator(decls_begin());
2301 ivar_iterator ivar_end() const {
2302 return ivar_iterator(decls_end());
2304 unsigned ivar_size() const {
2305 return std::distance(ivar_begin(), ivar_end());
2307 bool ivar_empty() const {
2308 return ivar_begin() == ivar_end();
2311 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2312 void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
2314 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2315 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2316 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2317 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2319 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2320 static bool classofKind(Kind K) { return K == ObjCCategory; }
2322 friend class ASTDeclReader;
2323 friend class ASTDeclWriter;
2326 class ObjCImplDecl : public ObjCContainerDecl {
2327 void anchor() override;
2329 /// Class interface for this class/category implementation
2330 ObjCInterfaceDecl *ClassInterface;
2333 ObjCImplDecl(Kind DK, DeclContext *DC,
2334 ObjCInterfaceDecl *classInterface,
2336 SourceLocation nameLoc, SourceLocation atStartLoc)
2337 : ObjCContainerDecl(DK, DC, Id, nameLoc, atStartLoc),
2338 ClassInterface(classInterface) {}
2341 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2342 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2343 void setClassInterface(ObjCInterfaceDecl *IFace);
2345 void addInstanceMethod(ObjCMethodDecl *method) {
2346 // FIXME: Context should be set correctly before we get here.
2347 method->setLexicalDeclContext(this);
2350 void addClassMethod(ObjCMethodDecl *method) {
2351 // FIXME: Context should be set correctly before we get here.
2352 method->setLexicalDeclContext(this);
2356 void addPropertyImplementation(ObjCPropertyImplDecl *property);
2358 ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId,
2359 ObjCPropertyQueryKind queryKind) const;
2360 ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
2362 // Iterator access to properties.
2363 typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
2364 typedef llvm::iterator_range<specific_decl_iterator<ObjCPropertyImplDecl>>
2367 propimpl_range property_impls() const {
2368 return propimpl_range(propimpl_begin(), propimpl_end());
2370 propimpl_iterator propimpl_begin() const {
2371 return propimpl_iterator(decls_begin());
2373 propimpl_iterator propimpl_end() const {
2374 return propimpl_iterator(decls_end());
2377 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2378 static bool classofKind(Kind K) {
2379 return K >= firstObjCImpl && K <= lastObjCImpl;
2383 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
2384 /// \@implementation declaration. If a category class has declaration of a
2385 /// property, its implementation must be specified in the category's
2386 /// \@implementation declaration. Example:
2387 /// \@interface I \@end
2388 /// \@interface I(CATEGORY)
2389 /// \@property int p1, d1;
2391 /// \@implementation I(CATEGORY)
2392 /// \@dynamic p1,d1;
2395 /// ObjCCategoryImplDecl
2396 class ObjCCategoryImplDecl : public ObjCImplDecl {
2397 void anchor() override;
2399 // Category name location
2400 SourceLocation CategoryNameLoc;
2402 ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
2403 ObjCInterfaceDecl *classInterface,
2404 SourceLocation nameLoc, SourceLocation atStartLoc,
2405 SourceLocation CategoryNameLoc)
2406 : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, Id,
2407 nameLoc, atStartLoc),
2408 CategoryNameLoc(CategoryNameLoc) {}
2410 static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
2412 ObjCInterfaceDecl *classInterface,
2413 SourceLocation nameLoc,
2414 SourceLocation atStartLoc,
2415 SourceLocation CategoryNameLoc);
2416 static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2418 ObjCCategoryDecl *getCategoryDecl() const;
2420 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2422 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2423 static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
2425 friend class ASTDeclReader;
2426 friend class ASTDeclWriter;
2429 raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
2431 /// ObjCImplementationDecl - Represents a class definition - this is where
2432 /// method definitions are specified. For example:
2435 /// \@implementation MyClass
2436 /// - (void)myMethod { /* do something */ }
2440 /// In a non-fragile runtime, instance variables can appear in the class
2441 /// interface, class extensions (nameless categories), and in the implementation
2442 /// itself, as well as being synthesized as backing storage for properties.
2444 /// In a fragile runtime, instance variables are specified in the class
2445 /// interface, \em not in the implementation. Nevertheless (for legacy reasons),
2446 /// we allow instance variables to be specified in the implementation. When
2447 /// specified, they need to be \em identical to the interface.
2448 class ObjCImplementationDecl : public ObjCImplDecl {
2449 void anchor() override;
2450 /// Implementation Class's super class.
2451 ObjCInterfaceDecl *SuperClass;
2452 SourceLocation SuperLoc;
2454 /// \@implementation may have private ivars.
2455 SourceLocation IvarLBraceLoc;
2456 SourceLocation IvarRBraceLoc;
2458 /// Support for ivar initialization.
2459 /// \brief The arguments used to initialize the ivars
2460 LazyCXXCtorInitializersPtr IvarInitializers;
2461 unsigned NumIvarInitializers;
2463 /// Do the ivars of this class require initialization other than
2464 /// zero-initialization?
2465 bool HasNonZeroConstructors : 1;
2467 /// Do the ivars of this class require non-trivial destruction?
2468 bool HasDestructors : 1;
2470 ObjCImplementationDecl(DeclContext *DC,
2471 ObjCInterfaceDecl *classInterface,
2472 ObjCInterfaceDecl *superDecl,
2473 SourceLocation nameLoc, SourceLocation atStartLoc,
2474 SourceLocation superLoc = SourceLocation(),
2475 SourceLocation IvarLBraceLoc=SourceLocation(),
2476 SourceLocation IvarRBraceLoc=SourceLocation())
2477 : ObjCImplDecl(ObjCImplementation, DC, classInterface,
2478 classInterface ? classInterface->getIdentifier()
2480 nameLoc, atStartLoc),
2481 SuperClass(superDecl), SuperLoc(superLoc), IvarLBraceLoc(IvarLBraceLoc),
2482 IvarRBraceLoc(IvarRBraceLoc),
2483 IvarInitializers(nullptr), NumIvarInitializers(0),
2484 HasNonZeroConstructors(false), HasDestructors(false) {}
2486 static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
2487 ObjCInterfaceDecl *classInterface,
2488 ObjCInterfaceDecl *superDecl,
2489 SourceLocation nameLoc,
2490 SourceLocation atStartLoc,
2491 SourceLocation superLoc = SourceLocation(),
2492 SourceLocation IvarLBraceLoc=SourceLocation(),
2493 SourceLocation IvarRBraceLoc=SourceLocation());
2495 static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2497 /// init_iterator - Iterates through the ivar initializer list.
2498 typedef CXXCtorInitializer **init_iterator;
2500 /// init_const_iterator - Iterates through the ivar initializer list.
2501 typedef CXXCtorInitializer * const * init_const_iterator;
2503 typedef llvm::iterator_range<init_iterator> init_range;
2504 typedef llvm::iterator_range<init_const_iterator> init_const_range;
2506 init_range inits() { return init_range(init_begin(), init_end()); }
2507 init_const_range inits() const {
2508 return init_const_range(init_begin(), init_end());
2511 /// init_begin() - Retrieve an iterator to the first initializer.
2512 init_iterator init_begin() {
2513 const auto *ConstThis = this;
2514 return const_cast<init_iterator>(ConstThis->init_begin());
2516 /// begin() - Retrieve an iterator to the first initializer.
2517 init_const_iterator init_begin() const;
2519 /// init_end() - Retrieve an iterator past the last initializer.
2520 init_iterator init_end() {
2521 return init_begin() + NumIvarInitializers;
2523 /// end() - Retrieve an iterator past the last initializer.
2524 init_const_iterator init_end() const {
2525 return init_begin() + NumIvarInitializers;
2527 /// getNumArgs - Number of ivars which must be initialized.
2528 unsigned getNumIvarInitializers() const {
2529 return NumIvarInitializers;
2532 void setNumIvarInitializers(unsigned numNumIvarInitializers) {
2533 NumIvarInitializers = numNumIvarInitializers;
2536 void setIvarInitializers(ASTContext &C,
2537 CXXCtorInitializer ** initializers,
2538 unsigned numInitializers);
2540 /// Do any of the ivars of this class (not counting its base classes)
2541 /// require construction other than zero-initialization?
2542 bool hasNonZeroConstructors() const { return HasNonZeroConstructors; }
2543 void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; }
2545 /// Do any of the ivars of this class (not counting its base classes)
2546 /// require non-trivial destruction?
2547 bool hasDestructors() const { return HasDestructors; }
2548 void setHasDestructors(bool val) { HasDestructors = val; }
2550 /// getIdentifier - Get the identifier that names the class
2551 /// interface associated with this implementation.
2552 IdentifierInfo *getIdentifier() const {
2553 return getClassInterface()->getIdentifier();
2556 /// getName - Get the name of identifier for the class interface associated
2557 /// with this implementation as a StringRef.
2559 // FIXME: This is a bad API, we are hiding NamedDecl::getName with a different
2561 StringRef getName() const {
2562 assert(getIdentifier() && "Name is not a simple identifier");
2563 return getIdentifier()->getName();
2566 /// @brief Get the name of the class associated with this interface.
2568 // FIXME: Move to StringRef API.
2569 std::string getNameAsString() const {
2573 /// Produce a name to be used for class's metadata. It comes either via
2574 /// class's objc_runtime_name attribute or class name.
2575 StringRef getObjCRuntimeNameAsString() const;
2577 const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
2578 ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
2579 SourceLocation getSuperClassLoc() const { return SuperLoc; }
2581 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
2583 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2584 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2585 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2586 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2588 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
2589 typedef llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>> ivar_range;
2591 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2592 ivar_iterator ivar_begin() const {
2593 return ivar_iterator(decls_begin());
2595 ivar_iterator ivar_end() const {
2596 return ivar_iterator(decls_end());
2598 unsigned ivar_size() const {
2599 return std::distance(ivar_begin(), ivar_end());
2601 bool ivar_empty() const {
2602 return ivar_begin() == ivar_end();
2605 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2606 static bool classofKind(Kind K) { return K == ObjCImplementation; }
2608 friend class ASTDeclReader;
2609 friend class ASTDeclWriter;
2612 raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
2614 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
2615 /// declared as \@compatibility_alias alias class.
2616 class ObjCCompatibleAliasDecl : public NamedDecl {
2617 void anchor() override;
2618 /// Class that this is an alias of.
2619 ObjCInterfaceDecl *AliasedClass;
2621 ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2622 ObjCInterfaceDecl* aliasedClass)
2623 : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
2625 static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
2626 SourceLocation L, IdentifierInfo *Id,
2627 ObjCInterfaceDecl* aliasedClass);
2629 static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
2632 const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
2633 ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
2634 void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
2636 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2637 static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
2641 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
2642 /// in a class or category implementation block. For example:
2643 /// \@synthesize prop1 = ivar1;
2645 class ObjCPropertyImplDecl : public Decl {
2652 SourceLocation AtLoc; // location of \@synthesize or \@dynamic
2654 /// \brief For \@synthesize, the location of the ivar, if it was written in
2655 /// the source code.
2658 /// \@synthesize int a = b
2660 SourceLocation IvarLoc;
2662 /// Property declaration being implemented
2663 ObjCPropertyDecl *PropertyDecl;
2665 /// Null for \@dynamic. Required for \@synthesize.
2666 ObjCIvarDecl *PropertyIvarDecl;
2668 /// Null for \@dynamic. Non-null if property must be copy-constructed in
2670 Expr *GetterCXXConstructor;
2672 /// Null for \@dynamic. Non-null if property has assignment operator to call
2673 /// in Setter synthesis.
2674 Expr *SetterCXXAssignment;
2676 ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
2677 ObjCPropertyDecl *property,
2679 ObjCIvarDecl *ivarDecl,
2680 SourceLocation ivarLoc)
2681 : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
2682 IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
2683 GetterCXXConstructor(nullptr), SetterCXXAssignment(nullptr) {
2684 assert (PK == Dynamic || PropertyIvarDecl);
2688 static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
2689 SourceLocation atLoc, SourceLocation L,
2690 ObjCPropertyDecl *property,
2692 ObjCIvarDecl *ivarDecl,
2693 SourceLocation ivarLoc);
2695 static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2697 SourceRange getSourceRange() const override LLVM_READONLY;
2699 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
2700 void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
2702 ObjCPropertyDecl *getPropertyDecl() const {
2703 return PropertyDecl;
2705 void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
2707 Kind getPropertyImplementation() const {
2708 return PropertyIvarDecl ? Synthesize : Dynamic;
2711 ObjCIvarDecl *getPropertyIvarDecl() const {
2712 return PropertyIvarDecl;
2714 SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
2716 void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
2717 SourceLocation IvarLoc) {
2718 PropertyIvarDecl = Ivar;
2719 this->IvarLoc = IvarLoc;
2722 /// \brief For \@synthesize, returns true if an ivar name was explicitly
2726 /// \@synthesize int a = b; // true
2727 /// \@synthesize int a; // false
2729 bool isIvarNameSpecified() const {
2730 return IvarLoc.isValid() && IvarLoc != getLocation();
2733 Expr *getGetterCXXConstructor() const {
2734 return GetterCXXConstructor;
2736 void setGetterCXXConstructor(Expr *getterCXXConstructor) {
2737 GetterCXXConstructor = getterCXXConstructor;
2740 Expr *getSetterCXXAssignment() const {
2741 return SetterCXXAssignment;
2743 void setSetterCXXAssignment(Expr *setterCXXAssignment) {
2744 SetterCXXAssignment = setterCXXAssignment;
2747 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2748 static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2750 friend class ASTDeclReader;
2753 template<bool (*Filter)(ObjCCategoryDecl *)>
2755 ObjCInterfaceDecl::filtered_category_iterator<Filter>::
2756 findAcceptableCategory() {
2757 while (Current && !Filter(Current))
2758 Current = Current->getNextClassCategoryRaw();
2761 template<bool (*Filter)(ObjCCategoryDecl *)>
2762 inline ObjCInterfaceDecl::filtered_category_iterator<Filter> &
2763 ObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() {
2764 Current = Current->getNextClassCategoryRaw();
2765 findAcceptableCategory();
2769 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
2770 return !Cat->isHidden();
2773 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
2774 return Cat->IsClassExtension() && !Cat->isHidden();
2777 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
2778 return Cat->IsClassExtension();
2781 } // end namespace clang