clang  8.0.0
DeclObjC.h
Go to the documentation of this file.
1 //===- DeclObjC.h - Classes for representing declarations -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the DeclObjC interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_DECLOBJC_H
15 #define LLVM_CLANG_AST_DECLOBJC_H
16 
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclBase.h"
20 #include "clang/AST/Redeclarable.h"
22 #include "clang/AST/Type.h"
24 #include "clang/Basic/LLVM.h"
26 #include "clang/Basic/Specifiers.h"
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/ADT/DenseSet.h"
30 #include "llvm/ADT/None.h"
31 #include "llvm/ADT/PointerIntPair.h"
32 #include "llvm/ADT/STLExtras.h"
33 #include "llvm/ADT/StringRef.h"
34 #include "llvm/ADT/iterator_range.h"
35 #include "llvm/Support/Compiler.h"
36 #include "llvm/Support/TrailingObjects.h"
37 #include <cassert>
38 #include <cstddef>
39 #include <cstdint>
40 #include <iterator>
41 #include <string>
42 #include <utility>
43 
44 namespace clang {
45 
46 class ASTContext;
47 class CompoundStmt;
48 class CXXCtorInitializer;
49 class Expr;
50 class ObjCCategoryDecl;
51 class ObjCCategoryImplDecl;
52 class ObjCImplementationDecl;
53 class ObjCInterfaceDecl;
54 class ObjCIvarDecl;
55 class ObjCPropertyDecl;
56 class ObjCPropertyImplDecl;
57 class ObjCProtocolDecl;
58 class Stmt;
59 
60 class ObjCListBase {
61 protected:
62  /// List is an array of pointers to objects that are not owned by this object.
63  void **List = nullptr;
64  unsigned NumElts = 0;
65 
66 public:
67  ObjCListBase() = default;
68  ObjCListBase(const ObjCListBase &) = delete;
69  ObjCListBase &operator=(const ObjCListBase &) = delete;
70 
71  unsigned size() const { return NumElts; }
72  bool empty() const { return NumElts == 0; }
73 
74 protected:
75  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
76 };
77 
78 /// ObjCList - This is a simple template class used to hold various lists of
79 /// decls etc, which is heavily used by the ObjC front-end. This only use case
80 /// this supports is setting the list all at once and then reading elements out
81 /// of it.
82 template <typename T>
83 class ObjCList : public ObjCListBase {
84 public:
85  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
86  ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
87  }
88 
89  using iterator = T* const *;
90 
91  iterator begin() const { return (iterator)List; }
92  iterator end() const { return (iterator)List+NumElts; }
93 
94  T* operator[](unsigned Idx) const {
95  assert(Idx < NumElts && "Invalid access");
96  return (T*)List[Idx];
97  }
98 };
99 
100 /// A list of Objective-C protocols, along with the source
101 /// locations at which they were referenced.
102 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
103  SourceLocation *Locations = nullptr;
104 
106 
107 public:
108  ObjCProtocolList() = default;
109 
110  using loc_iterator = const SourceLocation *;
111 
112  loc_iterator loc_begin() const { return Locations; }
113  loc_iterator loc_end() const { return Locations + size(); }
114 
115  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
116  const SourceLocation *Locs, ASTContext &Ctx);
117 };
118 
119 /// ObjCMethodDecl - Represents an instance or class method declaration.
120 /// ObjC methods can be declared within 4 contexts: class interfaces,
121 /// categories, protocols, and class implementations. While C++ member
122 /// functions leverage C syntax, Objective-C method syntax is modeled after
123 /// Smalltalk (using colons to specify argument types/expressions).
124 /// Here are some brief examples:
125 ///
126 /// Setter/getter instance methods:
127 /// - (void)setMenu:(NSMenu *)menu;
128 /// - (NSMenu *)menu;
129 ///
130 /// Instance method that takes 2 NSView arguments:
131 /// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
132 ///
133 /// Getter class method:
134 /// + (NSMenu *)defaultMenu;
135 ///
136 /// A selector represents a unique name for a method. The selector names for
137 /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
138 ///
139 class ObjCMethodDecl : public NamedDecl, public DeclContext {
140  // This class stores some data in DeclContext::ObjCMethodDeclBits
141  // to save some space. Use the provided accessors to access it.
142 
143 public:
145 
146 private:
147  /// Return type of this method.
148  QualType MethodDeclType;
149 
150  /// Type source information for the return type.
151  TypeSourceInfo *ReturnTInfo;
152 
153  /// Array of ParmVarDecls for the formal parameters of this method
154  /// and optionally followed by selector locations.
155  void *ParamsAndSelLocs = nullptr;
156  unsigned NumParams = 0;
157 
158  /// List of attributes for this method declaration.
159  SourceLocation DeclEndLoc; // the location of the ';' or '{'.
160 
161  /// The following are only used for method definitions, null otherwise.
162  LazyDeclStmtPtr Body;
163 
164  /// SelfDecl - Decl for the implicit self parameter. This is lazily
165  /// constructed by createImplicitParams.
166  ImplicitParamDecl *SelfDecl = nullptr;
167 
168  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
169  /// constructed by createImplicitParams.
170  ImplicitParamDecl *CmdDecl = nullptr;
171 
173  Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
174  DeclContext *contextDecl, bool isInstance = true,
175  bool isVariadic = false, bool isPropertyAccessor = false,
176  bool isImplicitlyDeclared = false, bool isDefined = false,
177  ImplementationControl impControl = None,
178  bool HasRelatedResultType = false);
179 
180  SelectorLocationsKind getSelLocsKind() const {
181  return static_cast<SelectorLocationsKind>(ObjCMethodDeclBits.SelLocsKind);
182  }
183 
184  void setSelLocsKind(SelectorLocationsKind Kind) {
185  ObjCMethodDeclBits.SelLocsKind = Kind;
186  }
187 
188  bool hasStandardSelLocs() const {
189  return getSelLocsKind() != SelLoc_NonStandard;
190  }
191 
192  /// Get a pointer to the stored selector identifiers locations array.
193  /// No locations will be stored if HasStandardSelLocs is true.
194  SourceLocation *getStoredSelLocs() {
195  return reinterpret_cast<SourceLocation *>(getParams() + NumParams);
196  }
197  const SourceLocation *getStoredSelLocs() const {
198  return reinterpret_cast<const SourceLocation *>(getParams() + NumParams);
199  }
200 
201  /// Get a pointer to the stored selector identifiers locations array.
202  /// No locations will be stored if HasStandardSelLocs is true.
203  ParmVarDecl **getParams() {
204  return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
205  }
206  const ParmVarDecl *const *getParams() const {
207  return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
208  }
209 
210  /// Get the number of stored selector identifiers locations.
211  /// No locations will be stored if HasStandardSelLocs is true.
212  unsigned getNumStoredSelLocs() const {
213  if (hasStandardSelLocs())
214  return 0;
215  return getNumSelectorLocs();
216  }
217 
218  void setParamsAndSelLocs(ASTContext &C,
219  ArrayRef<ParmVarDecl*> Params,
220  ArrayRef<SourceLocation> SelLocs);
221 
222  /// A definition will return its interface declaration.
223  /// An interface declaration will return its definition.
224  /// Otherwise it will return itself.
225  ObjCMethodDecl *getNextRedeclarationImpl() override;
226 
227 public:
228  friend class ASTDeclReader;
229  friend class ASTDeclWriter;
230 
231  static ObjCMethodDecl *
232  Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
233  Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
234  DeclContext *contextDecl, bool isInstance = true,
235  bool isVariadic = false, bool isPropertyAccessor = false,
236  bool isImplicitlyDeclared = false, bool isDefined = false,
237  ImplementationControl impControl = None,
238  bool HasRelatedResultType = false);
239 
240  static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
241 
242  ObjCMethodDecl *getCanonicalDecl() override;
244  return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
245  }
246 
248  return static_cast<ObjCDeclQualifier>(ObjCMethodDeclBits.objcDeclQualifier);
249  }
250 
252  ObjCMethodDeclBits.objcDeclQualifier = QV;
253  }
254 
255  /// Determine whether this method has a result type that is related
256  /// to the message receiver's type.
257  bool hasRelatedResultType() const {
258  return ObjCMethodDeclBits.RelatedResultType;
259  }
260 
261  /// Note whether this method has a related result type.
262  void setRelatedResultType(bool RRT = true) {
263  ObjCMethodDeclBits.RelatedResultType = RRT;
264  }
265 
266  /// True if this is a method redeclaration in the same interface.
267  bool isRedeclaration() const { return ObjCMethodDeclBits.IsRedeclaration; }
268  void setIsRedeclaration(bool RD) { ObjCMethodDeclBits.IsRedeclaration = RD; }
269  void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
270 
271  /// True if redeclared in the same interface.
272  bool hasRedeclaration() const { return ObjCMethodDeclBits.HasRedeclaration; }
273  void setHasRedeclaration(bool HRD) const {
274  ObjCMethodDeclBits.HasRedeclaration = HRD;
275  }
276 
277  /// Returns the location where the declarator ends. It will be
278  /// the location of ';' for a method declaration and the location of '{'
279  /// for a method definition.
280  SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
281 
282  // Location information, modeled after the Stmt API.
283  SourceLocation getBeginLoc() const LLVM_READONLY { return getLocation(); }
284  SourceLocation getEndLoc() const LLVM_READONLY;
285  SourceRange getSourceRange() const override LLVM_READONLY {
286  return SourceRange(getLocation(), getEndLoc());
287  }
288 
290  if (isImplicit())
291  return getBeginLoc();
292  return getSelectorLoc(0);
293  }
294 
295  SourceLocation getSelectorLoc(unsigned Index) const {
296  assert(Index < getNumSelectorLocs() && "Index out of range!");
297  if (hasStandardSelLocs())
298  return getStandardSelectorLoc(Index, getSelector(),
299  getSelLocsKind() == SelLoc_StandardWithSpace,
300  parameters(),
301  DeclEndLoc);
302  return getStoredSelLocs()[Index];
303  }
304 
305  void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
306 
307  unsigned getNumSelectorLocs() const {
308  if (isImplicit())
309  return 0;
310  Selector Sel = getSelector();
311  if (Sel.isUnarySelector())
312  return 1;
313  return Sel.getNumArgs();
314  }
315 
316  ObjCInterfaceDecl *getClassInterface();
318  return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
319  }
320 
321  Selector getSelector() const { return getDeclName().getObjCSelector(); }
322 
323  QualType getReturnType() const { return MethodDeclType; }
324  void setReturnType(QualType T) { MethodDeclType = T; }
325  SourceRange getReturnTypeSourceRange() const;
326 
327  /// Determine the type of an expression that sends a message to this
328  /// function. This replaces the type parameters with the types they would
329  /// get if the receiver was parameterless (e.g. it may replace the type
330  /// parameter with 'id').
331  QualType getSendResultType() const;
332 
333  /// Determine the type of an expression that sends a message to this
334  /// function with the given receiver type.
335  QualType getSendResultType(QualType receiverType) const;
336 
337  TypeSourceInfo *getReturnTypeSourceInfo() const { return ReturnTInfo; }
338  void setReturnTypeSourceInfo(TypeSourceInfo *TInfo) { ReturnTInfo = TInfo; }
339 
340  // Iterator access to formal parameters.
341  unsigned param_size() const { return NumParams; }
342 
343  using param_const_iterator = const ParmVarDecl *const *;
344  using param_iterator = ParmVarDecl *const *;
345  using param_range = llvm::iterator_range<param_iterator>;
346  using param_const_range = llvm::iterator_range<param_const_iterator>;
347 
349  return param_const_iterator(getParams());
350  }
351 
353  return param_const_iterator(getParams() + NumParams);
354  }
355 
356  param_iterator param_begin() { return param_iterator(getParams()); }
357  param_iterator param_end() { return param_iterator(getParams() + NumParams); }
358 
359  // This method returns and of the parameters which are part of the selector
360  // name mangling requirements.
362  return param_begin() + getSelector().getNumArgs();
363  }
364 
365  // ArrayRef access to formal parameters. This should eventually
366  // replace the iterator interface above.
368  return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
369  NumParams);
370  }
371 
372  ParmVarDecl *getParamDecl(unsigned Idx) {
373  assert(Idx < NumParams && "Index out of bounds!");
374  return getParams()[Idx];
375  }
376  const ParmVarDecl *getParamDecl(unsigned Idx) const {
377  return const_cast<ObjCMethodDecl *>(this)->getParamDecl(Idx);
378  }
379 
380  /// Sets the method's parameters and selector source locations.
381  /// If the method is implicit (not coming from source) \p SelLocs is
382  /// ignored.
383  void setMethodParams(ASTContext &C,
384  ArrayRef<ParmVarDecl*> Params,
386 
387  // Iterator access to parameter types.
388  struct GetTypeFn {
389  QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); }
390  };
391 
392  using param_type_iterator =
393  llvm::mapped_iterator<param_const_iterator, GetTypeFn>;
394 
396  return llvm::map_iterator(param_begin(), GetTypeFn());
397  }
398 
400  return llvm::map_iterator(param_end(), GetTypeFn());
401  }
402 
403  /// createImplicitParams - Used to lazily create the self and cmd
404  /// implict parameters. This must be called prior to using getSelfDecl()
405  /// or getCmdDecl(). The call is ignored if the implicit parameters
406  /// have already been created.
407  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
408 
409  /// \return the type for \c self and set \arg selfIsPseudoStrong and
410  /// \arg selfIsConsumed accordingly.
411  QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID,
412  bool &selfIsPseudoStrong, bool &selfIsConsumed);
413 
414  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
415  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
416  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
417  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
418 
419  /// Determines the family of this method.
420  ObjCMethodFamily getMethodFamily() const;
421 
422  bool isInstanceMethod() const { return ObjCMethodDeclBits.IsInstance; }
423  void setInstanceMethod(bool isInst) {
424  ObjCMethodDeclBits.IsInstance = isInst;
425  }
426 
427  bool isVariadic() const { return ObjCMethodDeclBits.IsVariadic; }
428  void setVariadic(bool isVar) { ObjCMethodDeclBits.IsVariadic = isVar; }
429 
430  bool isClassMethod() const { return !isInstanceMethod(); }
431 
432  bool isPropertyAccessor() const {
433  return ObjCMethodDeclBits.IsPropertyAccessor;
434  }
435 
436  void setPropertyAccessor(bool isAccessor) {
437  ObjCMethodDeclBits.IsPropertyAccessor = isAccessor;
438  }
439 
440  bool isDefined() const { return ObjCMethodDeclBits.IsDefined; }
441  void setDefined(bool isDefined) { ObjCMethodDeclBits.IsDefined = isDefined; }
442 
443  /// Whether this method overrides any other in the class hierarchy.
444  ///
445  /// A method is said to override any method in the class's
446  /// base classes, its protocols, or its categories' protocols, that has
447  /// the same selector and is of the same kind (class or instance).
448  /// A method in an implementation is not considered as overriding the same
449  /// method in the interface or its categories.
450  bool isOverriding() const { return ObjCMethodDeclBits.IsOverriding; }
451  void setOverriding(bool IsOver) { ObjCMethodDeclBits.IsOverriding = IsOver; }
452 
453  /// Return overridden methods for the given \p Method.
454  ///
455  /// An ObjC method is considered to override any method in the class's
456  /// base classes (and base's categories), its protocols, or its categories'
457  /// protocols, that has
458  /// the same selector and is of the same kind (class or instance).
459  /// A method in an implementation is not considered as overriding the same
460  /// method in the interface or its categories.
461  void getOverriddenMethods(
462  SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
463 
464  /// True if the method was a definition but its body was skipped.
465  bool hasSkippedBody() const { return ObjCMethodDeclBits.HasSkippedBody; }
466  void setHasSkippedBody(bool Skipped = true) {
467  ObjCMethodDeclBits.HasSkippedBody = Skipped;
468  }
469 
470  /// Returns the property associated with this method's selector.
471  ///
472  /// Note that even if this particular method is not marked as a property
473  /// accessor, it is still possible for it to match a property declared in a
474  /// superclass. Pass \c false if you only want to check the current class.
475  const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
476 
477  // Related to protocols declared in \@protocol
479  ObjCMethodDeclBits.DeclImplementation = ic;
480  }
481 
483  return ImplementationControl(ObjCMethodDeclBits.DeclImplementation);
484  }
485 
486  bool isOptional() const {
487  return getImplementationControl() == Optional;
488  }
489 
490  /// Returns true if this specific method declaration is marked with the
491  /// designated initializer attribute.
492  bool isThisDeclarationADesignatedInitializer() const;
493 
494  /// Returns true if the method selector resolves to a designated initializer
495  /// in the class's interface.
496  ///
497  /// \param InitMethod if non-null and the function returns true, it receives
498  /// the method declaration that was marked with the designated initializer
499  /// attribute.
500  bool isDesignatedInitializerForTheInterface(
501  const ObjCMethodDecl **InitMethod = nullptr) const;
502 
503  /// Determine whether this method has a body.
504  bool hasBody() const override { return Body.isValid(); }
505 
506  /// Retrieve the body of this method, if it has one.
507  Stmt *getBody() const override;
508 
509  void setLazyBody(uint64_t Offset) { Body = Offset; }
510 
511  CompoundStmt *getCompoundBody() { return (CompoundStmt*)getBody(); }
512  void setBody(Stmt *B) { Body = B; }
513 
514  /// Returns whether this specific method is a definition.
515  bool isThisDeclarationADefinition() const { return hasBody(); }
516 
517  /// Is this method defined in the NSObject base class?
518  bool definedInNSObject(const ASTContext &) const;
519 
520  // Implement isa/cast/dyncast/etc.
521  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
522  static bool classofKind(Kind K) { return K == ObjCMethod; }
523 
525  return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
526  }
527 
529  return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
530  }
531 };
532 
533 /// Describes the variance of a given generic parameter.
534 enum class ObjCTypeParamVariance : uint8_t {
535  /// The parameter is invariant: must match exactly.
536  Invariant,
537 
538  /// The parameter is covariant, e.g., X<T> is a subtype of X<U> when
539  /// the type parameter is covariant and T is a subtype of U.
540  Covariant,
541 
542  /// The parameter is contravariant, e.g., X<T> is a subtype of X<U>
543  /// when the type parameter is covariant and U is a subtype of T.
545 };
546 
547 /// Represents the declaration of an Objective-C type parameter.
548 ///
549 /// \code
550 /// @interface NSDictionary<Key : id<NSCopying>, Value>
551 /// @end
552 /// \endcode
553 ///
554 /// In the example above, both \c Key and \c Value are represented by
555 /// \c ObjCTypeParamDecl. \c Key has an explicit bound of \c id<NSCopying>,
556 /// while \c Value gets an implicit bound of \c id.
557 ///
558 /// Objective-C type parameters are typedef-names in the grammar,
560  /// Index of this type parameter in the type parameter list.
561  unsigned Index : 14;
562 
563  /// The variance of the type parameter.
564  unsigned Variance : 2;
565 
566  /// The location of the variance, if any.
567  SourceLocation VarianceLoc;
568 
569  /// The location of the ':', which will be valid when the bound was
570  /// explicitly specified.
572 
574  ObjCTypeParamVariance variance, SourceLocation varianceLoc,
575  unsigned index,
576  SourceLocation nameLoc, IdentifierInfo *name,
577  SourceLocation colonLoc, TypeSourceInfo *boundInfo)
578  : TypedefNameDecl(ObjCTypeParam, ctx, dc, nameLoc, nameLoc, name,
579  boundInfo),
580  Index(index), Variance(static_cast<unsigned>(variance)),
581  VarianceLoc(varianceLoc), ColonLoc(colonLoc) {}
582 
583  void anchor() override;
584 
585 public:
586  friend class ASTDeclReader;
587  friend class ASTDeclWriter;
588 
590  ObjCTypeParamVariance variance,
591  SourceLocation varianceLoc,
592  unsigned index,
593  SourceLocation nameLoc,
594  IdentifierInfo *name,
595  SourceLocation colonLoc,
596  TypeSourceInfo *boundInfo);
597  static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx, unsigned ID);
598 
599  SourceRange getSourceRange() const override LLVM_READONLY;
600 
601  /// Determine the variance of this type parameter.
602  ObjCTypeParamVariance getVariance() const {
603  return static_cast<ObjCTypeParamVariance>(Variance);
604  }
605 
606  /// Set the variance of this type parameter.
608  Variance = static_cast<unsigned>(variance);
609  }
610 
611  /// Retrieve the location of the variance keyword.
612  SourceLocation getVarianceLoc() const { return VarianceLoc; }
613 
614  /// Retrieve the index into its type parameter list.
615  unsigned getIndex() const { return Index; }
616 
617  /// Whether this type parameter has an explicitly-written type bound, e.g.,
618  /// "T : NSView".
619  bool hasExplicitBound() const { return ColonLoc.isValid(); }
620 
621  /// Retrieve the location of the ':' separating the type parameter name
622  /// from the explicitly-specified bound.
623  SourceLocation getColonLoc() const { return ColonLoc; }
624 
625  // Implement isa/cast/dyncast/etc.
626  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
627  static bool classofKind(Kind K) { return K == ObjCTypeParam; }
628 };
629 
630 /// Stores a list of Objective-C type parameters for a parameterized class
631 /// or a category/extension thereof.
632 ///
633 /// \code
634 /// @interface NSArray<T> // stores the <T>
635 /// @end
636 /// \endcode
637 class ObjCTypeParamList final
638  : private llvm::TrailingObjects<ObjCTypeParamList, ObjCTypeParamDecl *> {
639  /// Stores the components of a SourceRange as a POD.
640  struct PODSourceRange {
641  unsigned Begin;
642  unsigned End;
643  };
644 
645  union {
646  /// Location of the left and right angle brackets.
647  PODSourceRange Brackets;
648 
649  // Used only for alignment.
651  };
652 
653  /// The number of parameters in the list, which are tail-allocated.
654  unsigned NumParams;
655 
658  SourceLocation rAngleLoc);
659 
660 public:
662 
663  /// Create a new Objective-C type parameter list.
664  static ObjCTypeParamList *create(ASTContext &ctx,
665  SourceLocation lAngleLoc,
667  SourceLocation rAngleLoc);
668 
669  /// Iterate through the type parameters in the list.
671 
672  iterator begin() { return getTrailingObjects<ObjCTypeParamDecl *>(); }
673 
674  iterator end() { return begin() + size(); }
675 
676  /// Determine the number of type parameters in this list.
677  unsigned size() const { return NumParams; }
678 
679  // Iterate through the type parameters in the list.
681 
683  return getTrailingObjects<ObjCTypeParamDecl *>();
684  }
685 
686  const_iterator end() const {
687  return begin() + size();
688  }
689 
691  assert(size() > 0 && "empty Objective-C type parameter list");
692  return *begin();
693  }
694 
696  assert(size() > 0 && "empty Objective-C type parameter list");
697  return *(end() - 1);
698  }
699 
701  return SourceLocation::getFromRawEncoding(Brackets.Begin);
702  }
703 
705  return SourceLocation::getFromRawEncoding(Brackets.End);
706  }
707 
709  return SourceRange(getLAngleLoc(), getRAngleLoc());
710  }
711 
712  /// Gather the default set of type arguments to be substituted for
713  /// these type parameters when dealing with an unspecialized type.
714  void gatherDefaultTypeArgs(SmallVectorImpl<QualType> &typeArgs) const;
715 };
716 
717 enum class ObjCPropertyQueryKind : uint8_t {
718  OBJC_PR_query_unknown = 0x00,
721 };
722 
723 /// Represents one property declaration in an Objective-C interface.
724 ///
725 /// For example:
726 /// \code{.mm}
727 /// \@property (assign, readwrite) int MyProperty;
728 /// \endcode
729 class ObjCPropertyDecl : public NamedDecl {
730  void anchor() override;
731 
732 public:
734  OBJC_PR_noattr = 0x00,
735  OBJC_PR_readonly = 0x01,
736  OBJC_PR_getter = 0x02,
737  OBJC_PR_assign = 0x04,
738  OBJC_PR_readwrite = 0x08,
739  OBJC_PR_retain = 0x10,
740  OBJC_PR_copy = 0x20,
741  OBJC_PR_nonatomic = 0x40,
742  OBJC_PR_setter = 0x80,
743  OBJC_PR_atomic = 0x100,
744  OBJC_PR_weak = 0x200,
745  OBJC_PR_strong = 0x400,
746  OBJC_PR_unsafe_unretained = 0x800,
747  /// Indicates that the nullability of the type was spelled with a
748  /// property attribute rather than a type qualifier.
749  OBJC_PR_nullability = 0x1000,
750  OBJC_PR_null_resettable = 0x2000,
751  OBJC_PR_class = 0x4000
752  // Adding a property should change NumPropertyAttrsBits
753  };
754 
755  enum {
756  /// Number of bits fitting all the property attributes.
757  NumPropertyAttrsBits = 15
758  };
759 
760  enum SetterKind { Assign, Retain, Copy, Weak };
762 
763 private:
764  // location of \@property
765  SourceLocation AtLoc;
766 
767  // location of '(' starting attribute list or null.
768  SourceLocation LParenLoc;
769 
770  QualType DeclType;
771  TypeSourceInfo *DeclTypeSourceInfo;
772  unsigned PropertyAttributes : NumPropertyAttrsBits;
773  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
774 
775  // \@required/\@optional
776  unsigned PropertyImplementation : 2;
777 
778  // getter name of NULL if no getter
779  Selector GetterName;
780 
781  // setter name of NULL if no setter
782  Selector SetterName;
783 
784  // location of the getter attribute's value
785  SourceLocation GetterNameLoc;
786 
787  // location of the setter attribute's value
788  SourceLocation SetterNameLoc;
789 
790  // Declaration of getter instance method
791  ObjCMethodDecl *GetterMethodDecl = nullptr;
792 
793  // Declaration of setter instance method
794  ObjCMethodDecl *SetterMethodDecl = nullptr;
795 
796  // Synthesize ivar for this property
797  ObjCIvarDecl *PropertyIvarDecl = nullptr;
798 
800  SourceLocation AtLocation, SourceLocation LParenLocation,
801  QualType T, TypeSourceInfo *TSI,
802  PropertyControl propControl)
803  : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
804  LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI),
805  PropertyAttributes(OBJC_PR_noattr),
806  PropertyAttributesAsWritten(OBJC_PR_noattr),
807  PropertyImplementation(propControl), GetterName(Selector()),
808  SetterName(Selector()) {}
809 
810 public:
812  SourceLocation L,
813  IdentifierInfo *Id, SourceLocation AtLocation,
814  SourceLocation LParenLocation,
815  QualType T,
816  TypeSourceInfo *TSI,
817  PropertyControl propControl = None);
818 
819  static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
820 
821  SourceLocation getAtLoc() const { return AtLoc; }
822  void setAtLoc(SourceLocation L) { AtLoc = L; }
823 
824  SourceLocation getLParenLoc() const { return LParenLoc; }
825  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
826 
827  TypeSourceInfo *getTypeSourceInfo() const { return DeclTypeSourceInfo; }
828 
829  QualType getType() const { return DeclType; }
830 
832  DeclType = T;
833  DeclTypeSourceInfo = TSI;
834  }
835 
836  /// Retrieve the type when this property is used with a specific base object
837  /// type.
838  QualType getUsageType(QualType objectType) const;
839 
841  return PropertyAttributeKind(PropertyAttributes);
842  }
843 
845  PropertyAttributes |= PRVal;
846  }
847 
848  void overwritePropertyAttributes(unsigned PRVal) {
849  PropertyAttributes = PRVal;
850  }
851 
853  return PropertyAttributeKind(PropertyAttributesAsWritten);
854  }
855 
857  PropertyAttributesAsWritten = PRVal;
858  }
859 
860  // Helper methods for accessing attributes.
861 
862  /// isReadOnly - Return true iff the property has a setter.
863  bool isReadOnly() const {
864  return (PropertyAttributes & OBJC_PR_readonly);
865  }
866 
867  /// isAtomic - Return true if the property is atomic.
868  bool isAtomic() const {
869  return (PropertyAttributes & OBJC_PR_atomic);
870  }
871 
872  /// isRetaining - Return true if the property retains its value.
873  bool isRetaining() const {
874  return (PropertyAttributes &
875  (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
876  }
877 
878  bool isInstanceProperty() const { return !isClassProperty(); }
879  bool isClassProperty() const { return PropertyAttributes & OBJC_PR_class; }
880 
882  return isClassProperty() ? ObjCPropertyQueryKind::OBJC_PR_query_class :
884  }
885 
886  static ObjCPropertyQueryKind getQueryKind(bool isClassProperty) {
887  return isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class :
889  }
890 
891  /// getSetterKind - Return the method used for doing assignment in
892  /// the property setter. This is only valid if the property has been
893  /// defined to have a setter.
895  if (PropertyAttributes & OBJC_PR_strong)
896  return getType()->isBlockPointerType() ? Copy : Retain;
897  if (PropertyAttributes & OBJC_PR_retain)
898  return Retain;
899  if (PropertyAttributes & OBJC_PR_copy)
900  return Copy;
901  if (PropertyAttributes & OBJC_PR_weak)
902  return Weak;
903  return Assign;
904  }
905 
906  Selector getGetterName() const { return GetterName; }
907  SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
908 
910  GetterName = Sel;
911  GetterNameLoc = Loc;
912  }
913 
914  Selector getSetterName() const { return SetterName; }
915  SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
916 
918  SetterName = Sel;
919  SetterNameLoc = Loc;
920  }
921 
922  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
923  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
924 
925  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
926  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
927 
928  // Related to \@optional/\@required declared in \@protocol
930  PropertyImplementation = pc;
931  }
932 
934  return PropertyControl(PropertyImplementation);
935  }
936 
937  bool isOptional() const {
938  return getPropertyImplementation() == PropertyControl::Optional;
939  }
940 
942  PropertyIvarDecl = Ivar;
943  }
944 
946  return PropertyIvarDecl;
947  }
948 
949  SourceRange getSourceRange() const override LLVM_READONLY {
950  return SourceRange(AtLoc, getLocation());
951  }
952 
953  /// Get the default name of the synthesized ivar.
954  IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const;
955 
956  /// Lookup a property by name in the specified DeclContext.
957  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
958  const IdentifierInfo *propertyID,
959  ObjCPropertyQueryKind queryKind);
960 
961  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
962  static bool classofKind(Kind K) { return K == ObjCProperty; }
963 };
964 
965 /// ObjCContainerDecl - Represents a container for method declarations.
966 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
967 /// ObjCProtocolDecl, and ObjCImplDecl.
968 ///
969 class ObjCContainerDecl : public NamedDecl, public DeclContext {
970  // This class stores some data in DeclContext::ObjCContainerDeclBits
971  // to save some space. Use the provided accessors to access it.
972 
973  // These two locations in the range mark the end of the method container.
974  // The first points to the '@' token, and the second to the 'end' token.
975  SourceRange AtEnd;
976 
977  void anchor() override;
978 
979 public:
981  SourceLocation nameLoc, SourceLocation atStartLoc);
982 
983  // Iterator access to instance/class properties.
985  using prop_range =
986  llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>;
987 
988  prop_range properties() const { return prop_range(prop_begin(), prop_end()); }
989 
991  return prop_iterator(decls_begin());
992  }
993 
995  return prop_iterator(decls_end());
996  }
997 
998  using instprop_iterator =
1001  using instprop_range = llvm::iterator_range<instprop_iterator>;
1002 
1004  return instprop_range(instprop_begin(), instprop_end());
1005  }
1006 
1008  return instprop_iterator(decls_begin());
1009  }
1010 
1012  return instprop_iterator(decls_end());
1013  }
1014 
1015  using classprop_iterator =
1016  filtered_decl_iterator<ObjCPropertyDecl,
1018  using classprop_range = llvm::iterator_range<classprop_iterator>;
1019 
1021  return classprop_range(classprop_begin(), classprop_end());
1022  }
1023 
1025  return classprop_iterator(decls_begin());
1026  }
1027 
1029  return classprop_iterator(decls_end());
1030  }
1031 
1032  // Iterator access to instance/class methods.
1034  using method_range =
1035  llvm::iterator_range<specific_decl_iterator<ObjCMethodDecl>>;
1036 
1038  return method_range(meth_begin(), meth_end());
1039  }
1040 
1042  return method_iterator(decls_begin());
1043  }
1044 
1046  return method_iterator(decls_end());
1047  }
1048 
1049  using instmeth_iterator =
1052  using instmeth_range = llvm::iterator_range<instmeth_iterator>;
1053 
1055  return instmeth_range(instmeth_begin(), instmeth_end());
1056  }
1057 
1059  return instmeth_iterator(decls_begin());
1060  }
1061 
1063  return instmeth_iterator(decls_end());
1064  }
1065 
1066  using classmeth_iterator =
1067  filtered_decl_iterator<ObjCMethodDecl,
1069  using classmeth_range = llvm::iterator_range<classmeth_iterator>;
1070 
1072  return classmeth_range(classmeth_begin(), classmeth_end());
1073  }
1074 
1076  return classmeth_iterator(decls_begin());
1077  }
1078 
1080  return classmeth_iterator(decls_end());
1081  }
1082 
1083  // Get the local instance/class method declared in this interface.
1084  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
1085  bool AllowHidden = false) const;
1086 
1087  ObjCMethodDecl *getInstanceMethod(Selector Sel,
1088  bool AllowHidden = false) const {
1089  return getMethod(Sel, true/*isInstance*/, AllowHidden);
1090  }
1091 
1092  ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
1093  return getMethod(Sel, false/*isInstance*/, AllowHidden);
1094  }
1095 
1096  bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
1097  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
1098 
1099  ObjCPropertyDecl *
1100  FindPropertyDeclaration(const IdentifierInfo *PropertyId,
1101  ObjCPropertyQueryKind QueryKind) const;
1102 
1103  using PropertyMap =
1104  llvm::DenseMap<std::pair<IdentifierInfo *, unsigned/*isClassProperty*/>,
1105  ObjCPropertyDecl *>;
1106  using ProtocolPropertySet = llvm::SmallDenseSet<const ObjCProtocolDecl *, 8>;
1108 
1109  /// This routine collects list of properties to be implemented in the class.
1110  /// This includes, class's and its conforming protocols' properties.
1111  /// Note, the superclass's properties are not included in the list.
1113  PropertyDeclOrder &PO) const {}
1114 
1115  SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; }
1116 
1118  ObjCContainerDeclBits.AtStart = Loc;
1119  }
1120 
1121  // Marks the end of the container.
1122  SourceRange getAtEndRange() const { return AtEnd; }
1123 
1124  void setAtEndRange(SourceRange atEnd) { AtEnd = atEnd; }
1125 
1126  SourceRange getSourceRange() const override LLVM_READONLY {
1127  return SourceRange(getAtStartLoc(), getAtEndRange().getEnd());
1128  }
1129 
1130  // Implement isa/cast/dyncast/etc.
1131  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1132 
1133  static bool classofKind(Kind K) {
1134  return K >= firstObjCContainer &&
1135  K <= lastObjCContainer;
1136  }
1137 
1139  return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
1140  }
1141 
1143  return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
1144  }
1145 };
1146 
1147 /// Represents an ObjC class declaration.
1148 ///
1149 /// For example:
1150 ///
1151 /// \code
1152 /// // MostPrimitive declares no super class (not particularly useful).
1153 /// \@interface MostPrimitive
1154 /// // no instance variables or methods.
1155 /// \@end
1156 ///
1157 /// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
1158 /// \@interface NSResponder : NSObject <NSCoding>
1159 /// { // instance variables are represented by ObjCIvarDecl.
1160 /// id nextResponder; // nextResponder instance variable.
1161 /// }
1162 /// - (NSResponder *)nextResponder; // return a pointer to NSResponder.
1163 /// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
1164 /// \@end // to an NSEvent.
1165 /// \endcode
1166 ///
1167 /// Unlike C/C++, forward class declarations are accomplished with \@class.
1168 /// Unlike C/C++, \@class allows for a list of classes to be forward declared.
1169 /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
1170 /// typically inherit from NSObject (an exception is NSProxy).
1171 ///
1173  , public Redeclarable<ObjCInterfaceDecl> {
1174  friend class ASTContext;
1175 
1176  /// TypeForDecl - This indicates the Type object that represents this
1177  /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType
1178  mutable const Type *TypeForDecl = nullptr;
1179 
1180  struct DefinitionData {
1181  /// The definition of this class, for quick access from any
1182  /// declaration.
1183  ObjCInterfaceDecl *Definition = nullptr;
1184 
1185  /// When non-null, this is always an ObjCObjectType.
1186  TypeSourceInfo *SuperClassTInfo = nullptr;
1187 
1188  /// Protocols referenced in the \@interface declaration
1189  ObjCProtocolList ReferencedProtocols;
1190 
1191  /// Protocols reference in both the \@interface and class extensions.
1192  ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
1193 
1194  /// List of categories and class extensions defined for this class.
1195  ///
1196  /// Categories are stored as a linked list in the AST, since the categories
1197  /// and class extensions come long after the initial interface declaration,
1198  /// and we avoid dynamically-resized arrays in the AST wherever possible.
1199  ObjCCategoryDecl *CategoryList = nullptr;
1200 
1201  /// IvarList - List of all ivars defined by this class; including class
1202  /// extensions and implementation. This list is built lazily.
1203  ObjCIvarDecl *IvarList = nullptr;
1204 
1205  /// Indicates that the contents of this Objective-C class will be
1206  /// completed by the external AST source when required.
1207  mutable unsigned ExternallyCompleted : 1;
1208 
1209  /// Indicates that the ivar cache does not yet include ivars
1210  /// declared in the implementation.
1211  mutable unsigned IvarListMissingImplementation : 1;
1212 
1213  /// Indicates that this interface decl contains at least one initializer
1214  /// marked with the 'objc_designated_initializer' attribute.
1215  unsigned HasDesignatedInitializers : 1;
1216 
1217  enum InheritedDesignatedInitializersState {
1218  /// We didn't calculate whether the designated initializers should be
1219  /// inherited or not.
1220  IDI_Unknown = 0,
1221 
1222  /// Designated initializers are inherited for the super class.
1223  IDI_Inherited = 1,
1224 
1225  /// The class does not inherit designated initializers.
1226  IDI_NotInherited = 2
1227  };
1228 
1229  /// One of the \c InheritedDesignatedInitializersState enumeratos.
1230  mutable unsigned InheritedDesignatedInitializers : 2;
1231 
1232  /// The location of the last location in this declaration, before
1233  /// the properties/methods. For example, this will be the '>', '}', or
1234  /// identifier,
1235  SourceLocation EndLoc;
1236 
1237  DefinitionData()
1238  : ExternallyCompleted(false), IvarListMissingImplementation(true),
1239  HasDesignatedInitializers(false),
1240  InheritedDesignatedInitializers(IDI_Unknown) {}
1241  };
1242 
1243  /// The type parameters associated with this class, if any.
1244  ObjCTypeParamList *TypeParamList = nullptr;
1245 
1246  /// Contains a pointer to the data associated with this class,
1247  /// which will be NULL if this class has not yet been defined.
1248  ///
1249  /// The bit indicates when we don't need to check for out-of-date
1250  /// declarations. It will be set unless modules are enabled.
1251  llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
1252 
1254  IdentifierInfo *Id, ObjCTypeParamList *typeParamList,
1255  SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
1256  bool IsInternal);
1257 
1258  void anchor() override;
1259 
1260  void LoadExternalDefinition() const;
1261 
1262  DefinitionData &data() const {
1263  assert(Data.getPointer() && "Declaration has no definition!");
1264  return *Data.getPointer();
1265  }
1266 
1267  /// Allocate the definition data for this class.
1268  void allocateDefinitionData();
1269 
1271 
1272  ObjCInterfaceDecl *getNextRedeclarationImpl() override {
1273  return getNextRedeclaration();
1274  }
1275 
1276  ObjCInterfaceDecl *getPreviousDeclImpl() override {
1277  return getPreviousDecl();
1278  }
1279 
1280  ObjCInterfaceDecl *getMostRecentDeclImpl() override {
1281  return getMostRecentDecl();
1282  }
1283 
1284 public:
1285  static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
1286  SourceLocation atLoc,
1287  IdentifierInfo *Id,
1288  ObjCTypeParamList *typeParamList,
1289  ObjCInterfaceDecl *PrevDecl,
1290  SourceLocation ClassLoc = SourceLocation(),
1291  bool isInternal = false);
1292 
1293  static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
1294 
1295  /// Retrieve the type parameters of this class.
1296  ///
1297  /// This function looks for a type parameter list for the given
1298  /// class; if the class has been declared (with \c \@class) but not
1299  /// defined (with \c \@interface), it will search for a declaration that
1300  /// has type parameters, skipping any declarations that do not.
1301  ObjCTypeParamList *getTypeParamList() const;
1302 
1303  /// Set the type parameters of this class.
1304  ///
1305  /// This function is used by the AST importer, which must import the type
1306  /// parameters after creating their DeclContext to avoid loops.
1307  void setTypeParamList(ObjCTypeParamList *TPL);
1308 
1309  /// Retrieve the type parameters written on this particular declaration of
1310  /// the class.
1312  return TypeParamList;
1313  }
1314 
1315  SourceRange getSourceRange() const override LLVM_READONLY {
1316  if (isThisDeclarationADefinition())
1318 
1319  return SourceRange(getAtStartLoc(), getLocation());
1320  }
1321 
1322  /// Indicate that this Objective-C class is complete, but that
1323  /// the external AST source will be responsible for filling in its contents
1324  /// when a complete class is required.
1325  void setExternallyCompleted();
1326 
1327  /// Indicate that this interface decl contains at least one initializer
1328  /// marked with the 'objc_designated_initializer' attribute.
1329  void setHasDesignatedInitializers();
1330 
1331  /// Returns true if this interface decl contains at least one initializer
1332  /// marked with the 'objc_designated_initializer' attribute.
1333  bool hasDesignatedInitializers() const;
1334 
1335  /// Returns true if this interface decl declares a designated initializer
1336  /// or it inherites one from its super class.
1338  return hasDesignatedInitializers() || inheritsDesignatedInitializers();
1339  }
1340 
1342  assert(hasDefinition() && "Caller did not check for forward reference!");
1343  if (data().ExternallyCompleted)
1344  LoadExternalDefinition();
1345 
1346  return data().ReferencedProtocols;
1347  }
1348 
1349  ObjCImplementationDecl *getImplementation() const;
1350  void setImplementation(ObjCImplementationDecl *ImplD);
1351 
1352  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
1353 
1354  // Get the local instance/class method declared in a category.
1355  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
1356  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
1357 
1358  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
1359  return isInstance ? getCategoryInstanceMethod(Sel)
1360  : getCategoryClassMethod(Sel);
1361  }
1362 
1364  using protocol_range = llvm::iterator_range<protocol_iterator>;
1365 
1367  return protocol_range(protocol_begin(), protocol_end());
1368  }
1369 
1371  // FIXME: Should make sure no callers ever do this.
1372  if (!hasDefinition())
1373  return protocol_iterator();
1374 
1375  if (data().ExternallyCompleted)
1376  LoadExternalDefinition();
1377 
1378  return data().ReferencedProtocols.begin();
1379  }
1380 
1382  // FIXME: Should make sure no callers ever do this.
1383  if (!hasDefinition())
1384  return protocol_iterator();
1385 
1386  if (data().ExternallyCompleted)
1387  LoadExternalDefinition();
1388 
1389  return data().ReferencedProtocols.end();
1390  }
1391 
1393  using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
1394 
1396  return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
1397  }
1398 
1400  // FIXME: Should make sure no callers ever do this.
1401  if (!hasDefinition())
1402  return protocol_loc_iterator();
1403 
1404  if (data().ExternallyCompleted)
1405  LoadExternalDefinition();
1406 
1407  return data().ReferencedProtocols.loc_begin();
1408  }
1409 
1411  // FIXME: Should make sure no callers ever do this.
1412  if (!hasDefinition())
1413  return protocol_loc_iterator();
1414 
1415  if (data().ExternallyCompleted)
1416  LoadExternalDefinition();
1417 
1418  return data().ReferencedProtocols.loc_end();
1419  }
1420 
1422  using all_protocol_range = llvm::iterator_range<all_protocol_iterator>;
1423 
1425  return all_protocol_range(all_referenced_protocol_begin(),
1426  all_referenced_protocol_end());
1427  }
1428 
1430  // FIXME: Should make sure no callers ever do this.
1431  if (!hasDefinition())
1432  return all_protocol_iterator();
1433 
1434  if (data().ExternallyCompleted)
1435  LoadExternalDefinition();
1436 
1437  return data().AllReferencedProtocols.empty()
1438  ? protocol_begin()
1439  : data().AllReferencedProtocols.begin();
1440  }
1441 
1443  // FIXME: Should make sure no callers ever do this.
1444  if (!hasDefinition())
1445  return all_protocol_iterator();
1446 
1447  if (data().ExternallyCompleted)
1448  LoadExternalDefinition();
1449 
1450  return data().AllReferencedProtocols.empty()
1451  ? protocol_end()
1452  : data().AllReferencedProtocols.end();
1453  }
1454 
1456  using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
1457 
1458  ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
1459 
1461  if (const ObjCInterfaceDecl *Def = getDefinition())
1462  return ivar_iterator(Def->decls_begin());
1463 
1464  // FIXME: Should make sure no callers ever do this.
1465  return ivar_iterator();
1466  }
1467 
1469  if (const ObjCInterfaceDecl *Def = getDefinition())
1470  return ivar_iterator(Def->decls_end());
1471 
1472  // FIXME: Should make sure no callers ever do this.
1473  return ivar_iterator();
1474  }
1475 
1476  unsigned ivar_size() const {
1477  return std::distance(ivar_begin(), ivar_end());
1478  }
1479 
1480  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
1481 
1482  ObjCIvarDecl *all_declared_ivar_begin();
1484  // Even though this modifies IvarList, it's conceptually const:
1485  // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
1486  return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
1487  }
1488  void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
1489 
1490  /// setProtocolList - Set the list of protocols that this interface
1491  /// implements.
1492  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
1493  const SourceLocation *Locs, ASTContext &C) {
1494  data().ReferencedProtocols.set(List, Num, Locs, C);
1495  }
1496 
1497  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
1498  /// into the protocol list for this class.
1499  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
1500  unsigned Num,
1501  ASTContext &C);
1502 
1503  /// Produce a name to be used for class's metadata. It comes either via
1504  /// objc_runtime_name attribute or class name.
1505  StringRef getObjCRuntimeNameAsString() const;
1506 
1507  /// Returns the designated initializers for the interface.
1508  ///
1509  /// If this declaration does not have methods marked as designated
1510  /// initializers then the interface inherits the designated initializers of
1511  /// its super class.
1512  void getDesignatedInitializers(
1514 
1515  /// Returns true if the given selector is a designated initializer for the
1516  /// interface.
1517  ///
1518  /// If this declaration does not have methods marked as designated
1519  /// initializers then the interface inherits the designated initializers of
1520  /// its super class.
1521  ///
1522  /// \param InitMethod if non-null and the function returns true, it receives
1523  /// the method that was marked as a designated initializer.
1524  bool
1525  isDesignatedInitializer(Selector Sel,
1526  const ObjCMethodDecl **InitMethod = nullptr) const;
1527 
1528  /// Determine whether this particular declaration of this class is
1529  /// actually also a definition.
1531  return getDefinition() == this;
1532  }
1533 
1534  /// Determine whether this class has been defined.
1535  bool hasDefinition() const {
1536  // If the name of this class is out-of-date, bring it up-to-date, which
1537  // might bring in a definition.
1538  // Note: a null value indicates that we don't have a definition and that
1539  // modules are enabled.
1540  if (!Data.getOpaqueValue())
1541  getMostRecentDecl();
1542 
1543  return Data.getPointer();
1544  }
1545 
1546  /// Retrieve the definition of this class, or NULL if this class
1547  /// has been forward-declared (with \@class) but not yet defined (with
1548  /// \@interface).
1550  return hasDefinition()? Data.getPointer()->Definition : nullptr;
1551  }
1552 
1553  /// Retrieve the definition of this class, or NULL if this class
1554  /// has been forward-declared (with \@class) but not yet defined (with
1555  /// \@interface).
1557  return hasDefinition()? Data.getPointer()->Definition : nullptr;
1558  }
1559 
1560  /// Starts the definition of this Objective-C class, taking it from
1561  /// a forward declaration (\@class) to a definition (\@interface).
1562  void startDefinition();
1563 
1564  /// Retrieve the superclass type.
1566  if (TypeSourceInfo *TInfo = getSuperClassTInfo())
1567  return TInfo->getType()->castAs<ObjCObjectType>();
1568 
1569  return nullptr;
1570  }
1571 
1572  // Retrieve the type source information for the superclass.
1574  // FIXME: Should make sure no callers ever do this.
1575  if (!hasDefinition())
1576  return nullptr;
1577 
1578  if (data().ExternallyCompleted)
1579  LoadExternalDefinition();
1580 
1581  return data().SuperClassTInfo;
1582  }
1583 
1584  // Retrieve the declaration for the superclass of this class, which
1585  // does not include any type arguments that apply to the superclass.
1586  ObjCInterfaceDecl *getSuperClass() const;
1587 
1588  void setSuperClass(TypeSourceInfo *superClass) {
1589  data().SuperClassTInfo = superClass;
1590  }
1591 
1592  /// Iterator that walks over the list of categories, filtering out
1593  /// those that do not meet specific criteria.
1594  ///
1595  /// This class template is used for the various permutations of category
1596  /// and extension iterators.
1597  template<bool (*Filter)(ObjCCategoryDecl *)>
1599  ObjCCategoryDecl *Current = nullptr;
1600 
1601  void findAcceptableCategory();
1602 
1603  public:
1608  using iterator_category = std::input_iterator_tag;
1609 
1610  filtered_category_iterator() = default;
1612  : Current(Current) {
1613  findAcceptableCategory();
1614  }
1615 
1616  reference operator*() const { return Current; }
1617  pointer operator->() const { return Current; }
1618 
1619  filtered_category_iterator &operator++();
1620 
1622  filtered_category_iterator Tmp = *this;
1623  ++(*this);
1624  return Tmp;
1625  }
1626 
1629  return X.Current == Y.Current;
1630  }
1631 
1634  return X.Current != Y.Current;
1635  }
1636  };
1637 
1638 private:
1639  /// Test whether the given category is visible.
1640  ///
1641  /// Used in the \c visible_categories_iterator.
1642  static bool isVisibleCategory(ObjCCategoryDecl *Cat);
1643 
1644 public:
1645  /// Iterator that walks over the list of categories and extensions
1646  /// that are visible, i.e., not hidden in a non-imported submodule.
1649 
1650  using visible_categories_range =
1651  llvm::iterator_range<visible_categories_iterator>;
1652 
1654  return visible_categories_range(visible_categories_begin(),
1655  visible_categories_end());
1656  }
1657 
1658  /// Retrieve an iterator to the beginning of the visible-categories
1659  /// list.
1661  return visible_categories_iterator(getCategoryListRaw());
1662  }
1663 
1664  /// Retrieve an iterator to the end of the visible-categories list.
1666  return visible_categories_iterator();
1667  }
1668 
1669  /// Determine whether the visible-categories list is empty.
1671  return visible_categories_begin() == visible_categories_end();
1672  }
1673 
1674 private:
1675  /// Test whether the given category... is a category.
1676  ///
1677  /// Used in the \c known_categories_iterator.
1678  static bool isKnownCategory(ObjCCategoryDecl *) { return true; }
1679 
1680 public:
1681  /// Iterator that walks over all of the known categories and
1682  /// extensions, including those that are hidden.
1684  using known_categories_range =
1685  llvm::iterator_range<known_categories_iterator>;
1686 
1688  return known_categories_range(known_categories_begin(),
1689  known_categories_end());
1690  }
1691 
1692  /// Retrieve an iterator to the beginning of the known-categories
1693  /// list.
1695  return known_categories_iterator(getCategoryListRaw());
1696  }
1697 
1698  /// Retrieve an iterator to the end of the known-categories list.
1700  return known_categories_iterator();
1701  }
1702 
1703  /// Determine whether the known-categories list is empty.
1704  bool known_categories_empty() const {
1705  return known_categories_begin() == known_categories_end();
1706  }
1707 
1708 private:
1709  /// Test whether the given category is a visible extension.
1710  ///
1711  /// Used in the \c visible_extensions_iterator.
1712  static bool isVisibleExtension(ObjCCategoryDecl *Cat);
1713 
1714 public:
1715  /// Iterator that walks over all of the visible extensions, skipping
1716  /// any that are known but hidden.
1719 
1720  using visible_extensions_range =
1721  llvm::iterator_range<visible_extensions_iterator>;
1722 
1724  return visible_extensions_range(visible_extensions_begin(),
1725  visible_extensions_end());
1726  }
1727 
1728  /// Retrieve an iterator to the beginning of the visible-extensions
1729  /// list.
1731  return visible_extensions_iterator(getCategoryListRaw());
1732  }
1733 
1734  /// Retrieve an iterator to the end of the visible-extensions list.
1736  return visible_extensions_iterator();
1737  }
1738 
1739  /// Determine whether the visible-extensions list is empty.
1741  return visible_extensions_begin() == visible_extensions_end();
1742  }
1743 
1744 private:
1745  /// Test whether the given category is an extension.
1746  ///
1747  /// Used in the \c known_extensions_iterator.
1748  static bool isKnownExtension(ObjCCategoryDecl *Cat);
1749 
1750 public:
1751  friend class ASTDeclReader;
1752  friend class ASTDeclWriter;
1753  friend class ASTReader;
1754 
1755  /// Iterator that walks over all of the known extensions.
1758  using known_extensions_range =
1759  llvm::iterator_range<known_extensions_iterator>;
1760 
1762  return known_extensions_range(known_extensions_begin(),
1763  known_extensions_end());
1764  }
1765 
1766  /// Retrieve an iterator to the beginning of the known-extensions
1767  /// list.
1769  return known_extensions_iterator(getCategoryListRaw());
1770  }
1771 
1772  /// Retrieve an iterator to the end of the known-extensions list.
1774  return known_extensions_iterator();
1775  }
1776 
1777  /// Determine whether the known-extensions list is empty.
1778  bool known_extensions_empty() const {
1779  return known_extensions_begin() == known_extensions_end();
1780  }
1781 
1782  /// Retrieve the raw pointer to the start of the category/extension
1783  /// list.
1785  // FIXME: Should make sure no callers ever do this.
1786  if (!hasDefinition())
1787  return nullptr;
1788 
1789  if (data().ExternallyCompleted)
1790  LoadExternalDefinition();
1791 
1792  return data().CategoryList;
1793  }
1794 
1795  /// Set the raw pointer to the start of the category/extension
1796  /// list.
1798  data().CategoryList = category;
1799  }
1800 
1802  *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId,
1803  ObjCPropertyQueryKind QueryKind) const;
1804 
1805  void collectPropertiesToImplement(PropertyMap &PM,
1806  PropertyDeclOrder &PO) const override;
1807 
1808  /// isSuperClassOf - Return true if this class is the specified class or is a
1809  /// super class of the specified interface class.
1810  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
1811  // If RHS is derived from LHS it is OK; else it is not OK.
1812  while (I != nullptr) {
1813  if (declaresSameEntity(this, I))
1814  return true;
1815 
1816  I = I->getSuperClass();
1817  }
1818  return false;
1819  }
1820 
1821  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
1822  /// to be incompatible with __weak references. Returns true if it is.
1823  bool isArcWeakrefUnavailable() const;
1824 
1825  /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
1826  /// classes must not be auto-synthesized. Returns class decl. if it must not
1827  /// be; 0, otherwise.
1828  const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const;
1829 
1830  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
1831  ObjCInterfaceDecl *&ClassDeclared);
1833  ObjCInterfaceDecl *ClassDeclared;
1834  return lookupInstanceVariable(IVarName, ClassDeclared);
1835  }
1836 
1837  ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name);
1838 
1839  // Lookup a method. First, we search locally. If a method isn't
1840  // found, we search referenced protocols and class categories.
1841  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
1842  bool shallowCategoryLookup = false,
1843  bool followSuper = true,
1844  const ObjCCategoryDecl *C = nullptr) const;
1845 
1846  /// Lookup an instance method for a given selector.
1848  return lookupMethod(Sel, true/*isInstance*/);
1849  }
1850 
1851  /// Lookup a class method for a given selector.
1853  return lookupMethod(Sel, false/*isInstance*/);
1854  }
1855 
1856  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
1857 
1858  /// Lookup a method in the classes implementation hierarchy.
1859  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
1860  bool Instance=true) const;
1861 
1863  return lookupPrivateMethod(Sel, false);
1864  }
1865 
1866  /// Lookup a setter or getter in the class hierarchy,
1867  /// including in all categories except for category passed
1868  /// as argument.
1870  const ObjCCategoryDecl *Cat,
1871  bool IsClassProperty) const {
1872  return lookupMethod(Sel, !IsClassProperty/*isInstance*/,
1873  false/*shallowCategoryLookup*/,
1874  true /* followsSuper */,
1875  Cat);
1876  }
1877 
1879  if (!hasDefinition())
1880  return getLocation();
1881 
1882  return data().EndLoc;
1883  }
1884 
1885  void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
1886 
1887  /// Retrieve the starting location of the superclass.
1888  SourceLocation getSuperClassLoc() const;
1889 
1890  /// isImplicitInterfaceDecl - check that this is an implicitly declared
1891  /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
1892  /// declaration without an \@interface declaration.
1894  return hasDefinition() ? data().Definition->isImplicit() : isImplicit();
1895  }
1896 
1897  /// ClassImplementsProtocol - Checks that 'lProto' protocol
1898  /// has been implemented in IDecl class, its super class or categories (if
1899  /// lookupCategory is true).
1900  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1901  bool lookupCategory,
1902  bool RHSIsQualifiedID = false);
1903 
1905  using redecl_iterator = redeclarable_base::redecl_iterator;
1906 
1907  using redeclarable_base::redecls_begin;
1908  using redeclarable_base::redecls_end;
1909  using redeclarable_base::redecls;
1910  using redeclarable_base::getPreviousDecl;
1911  using redeclarable_base::getMostRecentDecl;
1912  using redeclarable_base::isFirstDecl;
1913 
1914  /// Retrieves the canonical declaration of this Objective-C class.
1915  ObjCInterfaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
1916  const ObjCInterfaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
1917 
1918  // Low-level accessor
1919  const Type *getTypeForDecl() const { return TypeForDecl; }
1920  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
1921 
1922  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1923  static bool classofKind(Kind K) { return K == ObjCInterface; }
1924 
1925 private:
1926  const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const;
1927  bool inheritsDesignatedInitializers() const;
1928 };
1929 
1930 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
1931 /// instance variables are identical to C. The only exception is Objective-C
1932 /// supports C++ style access control. For example:
1933 ///
1934 /// \@interface IvarExample : NSObject
1935 /// {
1936 /// id defaultToProtected;
1937 /// \@public:
1938 /// id canBePublic; // same as C++.
1939 /// \@protected:
1940 /// id canBeProtected; // same as C++.
1941 /// \@package:
1942 /// id canBePackage; // framework visibility (not available in C++).
1943 /// }
1944 ///
1945 class ObjCIvarDecl : public FieldDecl {
1946  void anchor() override;
1947 
1948 public:
1950  None, Private, Protected, Public, Package
1951  };
1952 
1953 private:
1955  SourceLocation IdLoc, IdentifierInfo *Id,
1956  QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1957  bool synthesized)
1958  : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1959  /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1960  DeclAccess(ac), Synthesized(synthesized) {}
1961 
1962 public:
1964  SourceLocation StartLoc, SourceLocation IdLoc,
1965  IdentifierInfo *Id, QualType T,
1966  TypeSourceInfo *TInfo,
1967  AccessControl ac, Expr *BW = nullptr,
1968  bool synthesized=false);
1969 
1970  static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1971 
1972  /// Return the class interface that this ivar is logically contained
1973  /// in; this is either the interface where the ivar was declared, or the
1974  /// interface the ivar is conceptually a part of in the case of synthesized
1975  /// ivars.
1976  const ObjCInterfaceDecl *getContainingInterface() const;
1977 
1978  ObjCIvarDecl *getNextIvar() { return NextIvar; }
1979  const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
1980  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
1981 
1982  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1983 
1984  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1985 
1987  return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1988  }
1989 
1990  void setSynthesize(bool synth) { Synthesized = synth; }
1991  bool getSynthesize() const { return Synthesized; }
1992 
1993  /// Retrieve the type of this instance variable when viewed as a member of a
1994  /// specific object type.
1995  QualType getUsageType(QualType objectType) const;
1996 
1997  // Implement isa/cast/dyncast/etc.
1998  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1999  static bool classofKind(Kind K) { return K == ObjCIvar; }
2000 
2001 private:
2002  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
2003  /// extensions and class's implementation
2004  ObjCIvarDecl *NextIvar = nullptr;
2005 
2006  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
2007  unsigned DeclAccess : 3;
2008  unsigned Synthesized : 1;
2009 };
2010 
2011 /// Represents a field declaration created by an \@defs(...).
2014  SourceLocation IdLoc, IdentifierInfo *Id,
2015  QualType T, Expr *BW)
2016  : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
2017  /*TInfo=*/nullptr, // FIXME: Do ObjCAtDefs have declarators ?
2018  BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
2019 
2020  void anchor() override;
2021 
2022 public:
2024  SourceLocation StartLoc,
2025  SourceLocation IdLoc, IdentifierInfo *Id,
2026  QualType T, Expr *BW);
2027 
2028  static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2029 
2030  // Implement isa/cast/dyncast/etc.
2031  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2032  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
2033 };
2034 
2035 /// Represents an Objective-C protocol declaration.
2036 ///
2037 /// Objective-C protocols declare a pure abstract type (i.e., no instance
2038 /// variables are permitted). Protocols originally drew inspiration from
2039 /// C++ pure virtual functions (a C++ feature with nice semantics and lousy
2040 /// syntax:-). Here is an example:
2041 ///
2042 /// \code
2043 /// \@protocol NSDraggingInfo <refproto1, refproto2>
2044 /// - (NSWindow *)draggingDestinationWindow;
2045 /// - (NSImage *)draggedImage;
2046 /// \@end
2047 /// \endcode
2048 ///
2049 /// This says that NSDraggingInfo requires two methods and requires everything
2050 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
2051 /// well.
2052 ///
2053 /// \code
2054 /// \@interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
2055 /// \@end
2056 /// \endcode
2057 ///
2058 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
2059 /// protocols are in distinct namespaces. For example, Cocoa defines both
2060 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
2061 /// protocols are referenced using angle brackets as follows:
2062 ///
2063 /// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
2065  public Redeclarable<ObjCProtocolDecl> {
2066  struct DefinitionData {
2067  // The declaration that defines this protocol.
2068  ObjCProtocolDecl *Definition;
2069 
2070  /// Referenced protocols
2071  ObjCProtocolList ReferencedProtocols;
2072  };
2073 
2074  /// Contains a pointer to the data associated with this class,
2075  /// which will be NULL if this class has not yet been defined.
2076  ///
2077  /// The bit indicates when we don't need to check for out-of-date
2078  /// declarations. It will be set unless modules are enabled.
2079  llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
2080 
2082  SourceLocation nameLoc, SourceLocation atStartLoc,
2083  ObjCProtocolDecl *PrevDecl);
2084 
2085  void anchor() override;
2086 
2087  DefinitionData &data() const {
2088  assert(Data.getPointer() && "Objective-C protocol has no definition!");
2089  return *Data.getPointer();
2090  }
2091 
2092  void allocateDefinitionData();
2093 
2095 
2096  ObjCProtocolDecl *getNextRedeclarationImpl() override {
2097  return getNextRedeclaration();
2098  }
2099 
2100  ObjCProtocolDecl *getPreviousDeclImpl() override {
2101  return getPreviousDecl();
2102  }
2103 
2104  ObjCProtocolDecl *getMostRecentDeclImpl() override {
2105  return getMostRecentDecl();
2106  }
2107 
2108 public:
2109  friend class ASTDeclReader;
2110  friend class ASTDeclWriter;
2111  friend class ASTReader;
2112 
2114  IdentifierInfo *Id,
2115  SourceLocation nameLoc,
2116  SourceLocation atStartLoc,
2117  ObjCProtocolDecl *PrevDecl);
2118 
2119  static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2120 
2122  assert(hasDefinition() && "No definition available!");
2123  return data().ReferencedProtocols;
2124  }
2125 
2127  using protocol_range = llvm::iterator_range<protocol_iterator>;
2128 
2130  return protocol_range(protocol_begin(), protocol_end());
2131  }
2132 
2134  if (!hasDefinition())
2135  return protocol_iterator();
2136 
2137  return data().ReferencedProtocols.begin();
2138  }
2139 
2141  if (!hasDefinition())
2142  return protocol_iterator();
2143 
2144  return data().ReferencedProtocols.end();
2145  }
2146 
2148  using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
2149 
2151  return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2152  }
2153 
2155  if (!hasDefinition())
2156  return protocol_loc_iterator();
2157 
2158  return data().ReferencedProtocols.loc_begin();
2159  }
2160 
2162  if (!hasDefinition())
2163  return protocol_loc_iterator();
2164 
2165  return data().ReferencedProtocols.loc_end();
2166  }
2167 
2168  unsigned protocol_size() const {
2169  if (!hasDefinition())
2170  return 0;
2171 
2172  return data().ReferencedProtocols.size();
2173  }
2174 
2175  /// setProtocolList - Set the list of protocols that this interface
2176  /// implements.
2177  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2178  const SourceLocation *Locs, ASTContext &C) {
2179  assert(hasDefinition() && "Protocol is not defined");
2180  data().ReferencedProtocols.set(List, Num, Locs, C);
2181  }
2182 
2183  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
2184 
2185  // Lookup a method. First, we search locally. If a method isn't
2186  // found, we search referenced protocols and class categories.
2187  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
2188 
2190  return lookupMethod(Sel, true/*isInstance*/);
2191  }
2192 
2194  return lookupMethod(Sel, false/*isInstance*/);
2195  }
2196 
2197  /// Determine whether this protocol has a definition.
2198  bool hasDefinition() const {
2199  // If the name of this protocol is out-of-date, bring it up-to-date, which
2200  // might bring in a definition.
2201  // Note: a null value indicates that we don't have a definition and that
2202  // modules are enabled.
2203  if (!Data.getOpaqueValue())
2204  getMostRecentDecl();
2205 
2206  return Data.getPointer();
2207  }
2208 
2209  /// Retrieve the definition of this protocol, if any.
2211  return hasDefinition()? Data.getPointer()->Definition : nullptr;
2212  }
2213 
2214  /// Retrieve the definition of this protocol, if any.
2216  return hasDefinition()? Data.getPointer()->Definition : nullptr;
2217  }
2218 
2219  /// Determine whether this particular declaration is also the
2220  /// definition.
2222  return getDefinition() == this;
2223  }
2224 
2225  /// Starts the definition of this Objective-C protocol.
2226  void startDefinition();
2227 
2228  /// Produce a name to be used for protocol's metadata. It comes either via
2229  /// objc_runtime_name attribute or protocol name.
2230  StringRef getObjCRuntimeNameAsString() const;
2231 
2232  SourceRange getSourceRange() const override LLVM_READONLY {
2233  if (isThisDeclarationADefinition())
2235 
2236  return SourceRange(getAtStartLoc(), getLocation());
2237  }
2238 
2240  using redecl_iterator = redeclarable_base::redecl_iterator;
2241 
2242  using redeclarable_base::redecls_begin;
2243  using redeclarable_base::redecls_end;
2244  using redeclarable_base::redecls;
2245  using redeclarable_base::getPreviousDecl;
2246  using redeclarable_base::getMostRecentDecl;
2247  using redeclarable_base::isFirstDecl;
2248 
2249  /// Retrieves the canonical declaration of this Objective-C protocol.
2250  ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); }
2251  const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); }
2252 
2253  void collectPropertiesToImplement(PropertyMap &PM,
2254  PropertyDeclOrder &PO) const override;
2255 
2256  void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property,
2257  ProtocolPropertySet &PS,
2258  PropertyDeclOrder &PO) const;
2259 
2260  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2261  static bool classofKind(Kind K) { return K == ObjCProtocol; }
2262 };
2263 
2264 /// ObjCCategoryDecl - Represents a category declaration. A category allows
2265 /// you to add methods to an existing class (without subclassing or modifying
2266 /// the original class interface or implementation:-). Categories don't allow
2267 /// you to add instance data. The following example adds "myMethod" to all
2268 /// NSView's within a process:
2269 ///
2270 /// \@interface NSView (MyViewMethods)
2271 /// - myMethod;
2272 /// \@end
2273 ///
2274 /// Categories also allow you to split the implementation of a class across
2275 /// several files (a feature more naturally supported in C++).
2276 ///
2277 /// Categories were originally inspired by dynamic languages such as Common
2278 /// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
2279 /// don't support this level of dynamism, which is both powerful and dangerous.
2281  /// Interface belonging to this category
2282  ObjCInterfaceDecl *ClassInterface;
2283 
2284  /// The type parameters associated with this category, if any.
2285  ObjCTypeParamList *TypeParamList = nullptr;
2286 
2287  /// referenced protocols in this category.
2288  ObjCProtocolList ReferencedProtocols;
2289 
2290  /// Next category belonging to this class.
2291  /// FIXME: this should not be a singly-linked list. Move storage elsewhere.
2292  ObjCCategoryDecl *NextClassCategory = nullptr;
2293 
2294  /// The location of the category name in this declaration.
2295  SourceLocation CategoryNameLoc;
2296 
2297  /// class extension may have private ivars.
2298  SourceLocation IvarLBraceLoc;
2299  SourceLocation IvarRBraceLoc;
2300 
2302  SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
2303  IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
2304  ObjCTypeParamList *typeParamList,
2305  SourceLocation IvarLBraceLoc = SourceLocation(),
2306  SourceLocation IvarRBraceLoc = SourceLocation());
2307 
2308  void anchor() override;
2309 
2310 public:
2311  friend class ASTDeclReader;
2312  friend class ASTDeclWriter;
2313 
2315  SourceLocation AtLoc,
2316  SourceLocation ClassNameLoc,
2317  SourceLocation CategoryNameLoc,
2318  IdentifierInfo *Id,
2319  ObjCInterfaceDecl *IDecl,
2320  ObjCTypeParamList *typeParamList,
2321  SourceLocation IvarLBraceLoc=SourceLocation(),
2322  SourceLocation IvarRBraceLoc=SourceLocation());
2323  static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2324 
2325  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2326  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2327 
2328  /// Retrieve the type parameter list associated with this category or
2329  /// extension.
2330  ObjCTypeParamList *getTypeParamList() const { return TypeParamList; }
2331 
2332  /// Set the type parameters of this category.
2333  ///
2334  /// This function is used by the AST importer, which must import the type
2335  /// parameters after creating their DeclContext to avoid loops.
2336  void setTypeParamList(ObjCTypeParamList *TPL);
2337 
2338 
2339  ObjCCategoryImplDecl *getImplementation() const;
2340  void setImplementation(ObjCCategoryImplDecl *ImplD);
2341 
2342  /// setProtocolList - Set the list of protocols that this interface
2343  /// implements.
2344  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2345  const SourceLocation *Locs, ASTContext &C) {
2346  ReferencedProtocols.set(List, Num, Locs, C);
2347  }
2348 
2350  return ReferencedProtocols;
2351  }
2352 
2354  using protocol_range = llvm::iterator_range<protocol_iterator>;
2355 
2357  return protocol_range(protocol_begin(), protocol_end());
2358  }
2359 
2361  return ReferencedProtocols.begin();
2362  }
2363 
2364  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
2365  unsigned protocol_size() const { return ReferencedProtocols.size(); }
2366 
2368  using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
2369 
2371  return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2372  }
2373 
2375  return ReferencedProtocols.loc_begin();
2376  }
2377 
2379  return ReferencedProtocols.loc_end();
2380  }
2381 
2382  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
2383 
2384  /// Retrieve the pointer to the next stored category (or extension),
2385  /// which may be hidden.
2387  return NextClassCategory;
2388  }
2389 
2390  bool IsClassExtension() const { return getIdentifier() == nullptr; }
2391 
2393  using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
2394 
2395  ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2396 
2398  return ivar_iterator(decls_begin());
2399  }
2400 
2402  return ivar_iterator(decls_end());
2403  }
2404 
2405  unsigned ivar_size() const {
2406  return std::distance(ivar_begin(), ivar_end());
2407  }
2408 
2409  bool ivar_empty() const {
2410  return ivar_begin() == ivar_end();
2411  }
2412 
2413  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2414  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
2415 
2416  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2417  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2418  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2419  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2420 
2421  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2422  static bool classofKind(Kind K) { return K == ObjCCategory; }
2423 };
2424 
2426  /// Class interface for this class/category implementation
2427  ObjCInterfaceDecl *ClassInterface;
2428 
2429  void anchor() override;
2430 
2431 protected:
2433  ObjCInterfaceDecl *classInterface,
2434  IdentifierInfo *Id,
2435  SourceLocation nameLoc, SourceLocation atStartLoc)
2436  : ObjCContainerDecl(DK, DC, Id, nameLoc, atStartLoc),
2437  ClassInterface(classInterface) {}
2438 
2439 public:
2440  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2441  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2442  void setClassInterface(ObjCInterfaceDecl *IFace);
2443 
2445  // FIXME: Context should be set correctly before we get here.
2446  method->setLexicalDeclContext(this);
2447  addDecl(method);
2448  }
2449 
2451  // FIXME: Context should be set correctly before we get here.
2452  method->setLexicalDeclContext(this);
2453  addDecl(method);
2454  }
2455 
2456  void addPropertyImplementation(ObjCPropertyImplDecl *property);
2457 
2458  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId,
2459  ObjCPropertyQueryKind queryKind) const;
2460  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
2461 
2462  // Iterator access to properties.
2464  using propimpl_range =
2465  llvm::iterator_range<specific_decl_iterator<ObjCPropertyImplDecl>>;
2466 
2468  return propimpl_range(propimpl_begin(), propimpl_end());
2469  }
2470 
2472  return propimpl_iterator(decls_begin());
2473  }
2474 
2476  return propimpl_iterator(decls_end());
2477  }
2478 
2479  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2480 
2481  static bool classofKind(Kind K) {
2482  return K >= firstObjCImpl && K <= lastObjCImpl;
2483  }
2484 };
2485 
2486 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
2487 /// \@implementation declaration. If a category class has declaration of a
2488 /// property, its implementation must be specified in the category's
2489 /// \@implementation declaration. Example:
2490 /// \@interface I \@end
2491 /// \@interface I(CATEGORY)
2492 /// \@property int p1, d1;
2493 /// \@end
2494 /// \@implementation I(CATEGORY)
2495 /// \@dynamic p1,d1;
2496 /// \@end
2497 ///
2498 /// ObjCCategoryImplDecl
2500  // Category name location
2501  SourceLocation CategoryNameLoc;
2502 
2504  ObjCInterfaceDecl *classInterface,
2505  SourceLocation nameLoc, SourceLocation atStartLoc,
2506  SourceLocation CategoryNameLoc)
2507  : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, Id,
2508  nameLoc, atStartLoc),
2509  CategoryNameLoc(CategoryNameLoc) {}
2510 
2511  void anchor() override;
2512 
2513 public:
2514  friend class ASTDeclReader;
2515  friend class ASTDeclWriter;
2516 
2518  IdentifierInfo *Id,
2519  ObjCInterfaceDecl *classInterface,
2520  SourceLocation nameLoc,
2521  SourceLocation atStartLoc,
2522  SourceLocation CategoryNameLoc);
2523  static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2524 
2525  ObjCCategoryDecl *getCategoryDecl() const;
2526 
2527  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2528 
2529  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2530  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
2531 };
2532 
2533 raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
2534 
2535 /// ObjCImplementationDecl - Represents a class definition - this is where
2536 /// method definitions are specified. For example:
2537 ///
2538 /// @code
2539 /// \@implementation MyClass
2540 /// - (void)myMethod { /* do something */ }
2541 /// \@end
2542 /// @endcode
2543 ///
2544 /// In a non-fragile runtime, instance variables can appear in the class
2545 /// interface, class extensions (nameless categories), and in the implementation
2546 /// itself, as well as being synthesized as backing storage for properties.
2547 ///
2548 /// In a fragile runtime, instance variables are specified in the class
2549 /// interface, \em not in the implementation. Nevertheless (for legacy reasons),
2550 /// we allow instance variables to be specified in the implementation. When
2551 /// specified, they need to be \em identical to the interface.
2553  /// Implementation Class's super class.
2554  ObjCInterfaceDecl *SuperClass;
2555  SourceLocation SuperLoc;
2556 
2557  /// \@implementation may have private ivars.
2558  SourceLocation IvarLBraceLoc;
2559  SourceLocation IvarRBraceLoc;
2560 
2561  /// Support for ivar initialization.
2562  /// The arguments used to initialize the ivars
2563  LazyCXXCtorInitializersPtr IvarInitializers;
2564  unsigned NumIvarInitializers = 0;
2565 
2566  /// Do the ivars of this class require initialization other than
2567  /// zero-initialization?
2568  bool HasNonZeroConstructors : 1;
2569 
2570  /// Do the ivars of this class require non-trivial destruction?
2571  bool HasDestructors : 1;
2572 
2574  ObjCInterfaceDecl *classInterface,
2575  ObjCInterfaceDecl *superDecl,
2576  SourceLocation nameLoc, SourceLocation atStartLoc,
2577  SourceLocation superLoc = SourceLocation(),
2578  SourceLocation IvarLBraceLoc=SourceLocation(),
2579  SourceLocation IvarRBraceLoc=SourceLocation())
2580  : ObjCImplDecl(ObjCImplementation, DC, classInterface,
2581  classInterface ? classInterface->getIdentifier()
2582  : nullptr,
2583  nameLoc, atStartLoc),
2584  SuperClass(superDecl), SuperLoc(superLoc),
2585  IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc),
2586  HasNonZeroConstructors(false), HasDestructors(false) {}
2587 
2588  void anchor() override;
2589 
2590 public:
2591  friend class ASTDeclReader;
2592  friend class ASTDeclWriter;
2593 
2595  ObjCInterfaceDecl *classInterface,
2596  ObjCInterfaceDecl *superDecl,
2597  SourceLocation nameLoc,
2598  SourceLocation atStartLoc,
2599  SourceLocation superLoc = SourceLocation(),
2600  SourceLocation IvarLBraceLoc=SourceLocation(),
2601  SourceLocation IvarRBraceLoc=SourceLocation());
2602 
2603  static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2604 
2605  /// init_iterator - Iterates through the ivar initializer list.
2607 
2608  /// init_const_iterator - Iterates through the ivar initializer list.
2610 
2611  using init_range = llvm::iterator_range<init_iterator>;
2612  using init_const_range = llvm::iterator_range<init_const_iterator>;
2613 
2614  init_range inits() { return init_range(init_begin(), init_end()); }
2615 
2617  return init_const_range(init_begin(), init_end());
2618  }
2619 
2620  /// init_begin() - Retrieve an iterator to the first initializer.
2622  const auto *ConstThis = this;
2623  return const_cast<init_iterator>(ConstThis->init_begin());
2624  }
2625 
2626  /// begin() - Retrieve an iterator to the first initializer.
2627  init_const_iterator init_begin() const;
2628 
2629  /// init_end() - Retrieve an iterator past the last initializer.
2631  return init_begin() + NumIvarInitializers;
2632  }
2633 
2634  /// end() - Retrieve an iterator past the last initializer.
2636  return init_begin() + NumIvarInitializers;
2637  }
2638 
2639  /// getNumArgs - Number of ivars which must be initialized.
2640  unsigned getNumIvarInitializers() const {
2641  return NumIvarInitializers;
2642  }
2643 
2644  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
2645  NumIvarInitializers = numNumIvarInitializers;
2646  }
2647 
2648  void setIvarInitializers(ASTContext &C,
2649  CXXCtorInitializer ** initializers,
2650  unsigned numInitializers);
2651 
2652  /// Do any of the ivars of this class (not counting its base classes)
2653  /// require construction other than zero-initialization?
2654  bool hasNonZeroConstructors() const { return HasNonZeroConstructors; }
2655  void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; }
2656 
2657  /// Do any of the ivars of this class (not counting its base classes)
2658  /// require non-trivial destruction?
2659  bool hasDestructors() const { return HasDestructors; }
2660  void setHasDestructors(bool val) { HasDestructors = val; }
2661 
2662  /// getIdentifier - Get the identifier that names the class
2663  /// interface associated with this implementation.
2665  return getClassInterface()->getIdentifier();
2666  }
2667 
2668  /// getName - Get the name of identifier for the class interface associated
2669  /// with this implementation as a StringRef.
2670  //
2671  // FIXME: This is a bad API, we are hiding NamedDecl::getName with a different
2672  // meaning.
2673  StringRef getName() const {
2674  assert(getIdentifier() && "Name is not a simple identifier");
2675  return getIdentifier()->getName();
2676  }
2677 
2678  /// Get the name of the class associated with this interface.
2679  //
2680  // FIXME: Move to StringRef API.
2681  std::string getNameAsString() const {
2682  return getName();
2683  }
2684 
2685  /// Produce a name to be used for class's metadata. It comes either via
2686  /// class's objc_runtime_name attribute or class name.
2687  StringRef getObjCRuntimeNameAsString() const;
2688 
2689  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
2690  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
2691  SourceLocation getSuperClassLoc() const { return SuperLoc; }
2692 
2693  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
2694 
2695  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2696  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2697  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2698  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2699 
2701  using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
2702 
2703  ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2704 
2706  return ivar_iterator(decls_begin());
2707  }
2708 
2710  return ivar_iterator(decls_end());
2711  }
2712 
2713  unsigned ivar_size() const {
2714  return std::distance(ivar_begin(), ivar_end());
2715  }
2716 
2717  bool ivar_empty() const {
2718  return ivar_begin() == ivar_end();
2719  }
2720 
2721  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2722  static bool classofKind(Kind K) { return K == ObjCImplementation; }
2723 };
2724 
2725 raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
2726 
2727 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
2728 /// declared as \@compatibility_alias alias class.
2730  /// Class that this is an alias of.
2731  ObjCInterfaceDecl *AliasedClass;
2732 
2734  ObjCInterfaceDecl* aliasedClass)
2735  : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
2736 
2737  void anchor() override;
2738 
2739 public:
2742  ObjCInterfaceDecl* aliasedClass);
2743 
2744  static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
2745  unsigned ID);
2746 
2747  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
2748  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
2749  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
2750 
2751  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2752  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
2753 };
2754 
2755 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
2756 /// in a class or category implementation block. For example:
2757 /// \@synthesize prop1 = ivar1;
2758 ///
2759 class ObjCPropertyImplDecl : public Decl {
2760 public:
2761  enum Kind {
2763  Dynamic
2764  };
2765 
2766 private:
2767  SourceLocation AtLoc; // location of \@synthesize or \@dynamic
2768 
2769  /// For \@synthesize, the location of the ivar, if it was written in
2770  /// the source code.
2771  ///
2772  /// \code
2773  /// \@synthesize int a = b
2774  /// \endcode
2775  SourceLocation IvarLoc;
2776 
2777  /// Property declaration being implemented
2778  ObjCPropertyDecl *PropertyDecl;
2779 
2780  /// Null for \@dynamic. Required for \@synthesize.
2781  ObjCIvarDecl *PropertyIvarDecl;
2782 
2783  /// Null for \@dynamic. Non-null if property must be copy-constructed in
2784  /// getter.
2785  Expr *GetterCXXConstructor = nullptr;
2786 
2787  /// Null for \@dynamic. Non-null if property has assignment operator to call
2788  /// in Setter synthesis.
2789  Expr *SetterCXXAssignment = nullptr;
2790 
2792  ObjCPropertyDecl *property,
2793  Kind PK,
2794  ObjCIvarDecl *ivarDecl,
2795  SourceLocation ivarLoc)
2796  : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
2797  IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
2798  assert(PK == Dynamic || PropertyIvarDecl);
2799  }
2800 
2801 public:
2802  friend class ASTDeclReader;
2803 
2805  SourceLocation atLoc, SourceLocation L,
2806  ObjCPropertyDecl *property,
2807  Kind PK,
2808  ObjCIvarDecl *ivarDecl,
2809  SourceLocation ivarLoc);
2810 
2811  static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2812 
2813  SourceRange getSourceRange() const override LLVM_READONLY;
2814 
2815  SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
2816  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
2817 
2819  return PropertyDecl;
2820  }
2821  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
2822 
2824  return PropertyIvarDecl ? Synthesize : Dynamic;
2825  }
2826 
2828  return PropertyIvarDecl;
2829  }
2830  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
2831 
2833  SourceLocation IvarLoc) {
2834  PropertyIvarDecl = Ivar;
2835  this->IvarLoc = IvarLoc;
2836  }
2837 
2838  /// For \@synthesize, returns true if an ivar name was explicitly
2839  /// specified.
2840  ///
2841  /// \code
2842  /// \@synthesize int a = b; // true
2843  /// \@synthesize int a; // false
2844  /// \endcode
2845  bool isIvarNameSpecified() const {
2846  return IvarLoc.isValid() && IvarLoc != getLocation();
2847  }
2848 
2850  return GetterCXXConstructor;
2851  }
2852 
2853  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
2854  GetterCXXConstructor = getterCXXConstructor;
2855  }
2856 
2858  return SetterCXXAssignment;
2859  }
2860 
2861  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
2862  SetterCXXAssignment = setterCXXAssignment;
2863  }
2864 
2865  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2866  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2867 };
2868 
2869 template<bool (*Filter)(ObjCCategoryDecl *)>
2870 void
2873  while (Current && !Filter(Current))
2874  Current = Current->getNextClassCategoryRaw();
2875 }
2876 
2877 template<bool (*Filter)(ObjCCategoryDecl *)>
2880  Current = Current->getNextClassCategoryRaw();
2881  findAcceptableCategory();
2882  return *this;
2883 }
2884 
2885 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
2886  return !Cat->isHidden();
2887 }
2888 
2889 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
2890  return Cat->IsClassExtension() && !Cat->isHidden();
2891 }
2892 
2893 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
2894  return Cat->IsClassExtension();
2895 }
2896 
2897 } // namespace clang
2898 
2899 #endif // LLVM_CLANG_AST_DECLOBJC_H
llvm::iterator_range< param_const_iterator > param_const_range
Definition: DeclObjC.h:346
known_extensions_iterator known_extensions_begin() const
Retrieve an iterator to the beginning of the known-extensions list.
Definition: DeclObjC.h:1768
SourceLocation getGetterNameLoc() const
Definition: DeclObjC.h:907
void setCategoryNameLoc(SourceLocation Loc)
Definition: DeclObjC.h:2414
For nullary selectors, immediately before the end: "[foo release]" / "-(void)release;" Or with a spac...
ObjCMethodDecl * lookupPrivateClassMethod(const Selector &Sel)
Definition: DeclObjC.h:1862
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1535
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:881
llvm::iterator_range< visible_categories_iterator > visible_categories_range
Definition: DeclObjC.h:1651
const Type * getTypeForDecl() const
Definition: DeclObjC.h:1919
bool isClassMethod() const
Definition: DeclObjC.h:430
static const Decl * getCanonicalDecl(const Decl *D)
unsigned ivar_size() const
Definition: DeclObjC.h:2405
param_type_iterator param_type_end() const
Definition: DeclObjC.h:399
void setEndOfDefinitionLoc(SourceLocation LE)
Definition: DeclObjC.h:1885
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Definition: DeclObjC.h:515
propimpl_iterator propimpl_end() const
Definition: DeclObjC.h:2475
llvm::iterator_range< redecl_iterator > redecl_range
Definition: DeclBase.h:937
protocol_range protocols() const
Definition: DeclObjC.h:1366
Smart pointer class that efficiently represents Objective-C method names.
const ObjCInterfaceDecl * getDefinition() const
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1556
ObjCListBase & operator=(const ObjCListBase &)=delete
A (possibly-)qualified type.
Definition: Type.h:638
visible_extensions_iterator visible_extensions_begin() const
Retrieve an iterator to the beginning of the visible-extensions list.
Definition: DeclObjC.h:1730
static bool classof(const Decl *D)
Definition: DeclObjC.h:521
unsigned param_size() const
Definition: DeclObjC.h:341
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2325
all_protocol_range all_referenced_protocols() const
Definition: DeclObjC.h:1424
bool ivar_empty() const
Definition: DeclObjC.h:2409
llvm::iterator_range< init_const_iterator > init_const_range
Definition: DeclObjC.h:2612
iterator begin() const
Definition: DeclObjC.h:91
static ClassTemplateDecl * getDefinition(ClassTemplateDecl *D)
void setLParenLoc(SourceLocation L)
Definition: DeclObjC.h:825
static bool classof(const Decl *D)
Definition: DeclObjC.h:961
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1530
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Definition: DeclObjC.h:2189
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2827
const ParmVarDecl * getParamDecl(unsigned Idx) const
Definition: DeclObjC.h:376
init_const_range inits() const
Definition: DeclObjC.h:2616
ObjCMethodDecl * getCategoryMethod(Selector Sel, bool isInstance) const
Definition: DeclObjC.h:1358
llvm::iterator_range< instmeth_iterator > instmeth_range
Definition: DeclObjC.h:1052
Stmt - This represents one statement.
Definition: Stmt.h:66
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:2349
method_iterator meth_end() const
Definition: DeclObjC.h:1045
C Language Family Type Representation.
llvm::mapped_iterator< param_const_iterator, GetTypeFn > param_type_iterator
Definition: DeclObjC.h:393
llvm::iterator_range< protocol_iterator > protocol_range
Definition: DeclObjC.h:2354
redeclarable_base::redecl_iterator redecl_iterator
Definition: DeclObjC.h:2240
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
classprop_iterator classprop_end() const
Definition: DeclObjC.h:1028
AccessControl getCanonicalAccessControl() const
Definition: DeclObjC.h:1986
StringRef P
ivar_range ivars() const
Definition: DeclObjC.h:1458
llvm::iterator_range< classmeth_iterator > classmeth_range
Definition: DeclObjC.h:1069
all_protocol_iterator all_referenced_protocol_begin() const
Definition: DeclObjC.h:1429
static bool classofKind(Kind K)
Definition: DeclObjC.h:1133
known_categories_range known_categories() const
Definition: DeclObjC.h:1687
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2748
Expr * getSetterCXXAssignment() const
Definition: DeclObjC.h:2857
void setNumIvarInitializers(unsigned numNumIvarInitializers)
Definition: DeclObjC.h:2644
void ** List
List is an array of pointers to objects that are not owned by this object.
Definition: DeclObjC.h:63
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:336
The base class of the type hierarchy.
Definition: Type.h:1407
unsigned getNumSelectorLocs() const
Definition: DeclObjC.h:307
The parameter is covariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant and ...
visible_extensions_iterator visible_extensions_end() const
Retrieve an iterator to the end of the visible-extensions list.
Definition: DeclObjC.h:1735
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:1126
bool hasDestructors() const
Do any of the ivars of this class (not counting its base classes) require non-trivial destruction...
Definition: DeclObjC.h:2659
void setPropertyImplementation(PropertyControl pc)
Definition: DeclObjC.h:929
bool hasRedeclaration() const
True if redeclared in the same interface.
Definition: DeclObjC.h:272
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1370
void setPropertyIvarDecl(ObjCIvarDecl *Ivar, SourceLocation IvarLoc)
Definition: DeclObjC.h:2832
static bool classofKind(Kind K)
Definition: DeclObjC.h:2752
ObjCCategoryDecl * getNextClassCategoryRaw() const
Retrieve the pointer to the next stored category (or extension), which may be hidden.
Definition: DeclObjC.h:2386
const ObjCInterfaceDecl * getCanonicalDecl() const
Definition: DeclObjC.h:1916
A container of type source information.
Definition: Decl.h:87
static ObjCMethodDecl * castFromDeclContext(const DeclContext *DC)
Definition: DeclObjC.h:528
bool isOptional() const
Definition: DeclObjC.h:937
instmeth_iterator instmeth_end() const
Definition: DeclObjC.h:1062
void setPropertyAccessor(bool isAccessor)
Definition: DeclObjC.h:436
SourceLocation getColonLoc() const
Retrieve the location of the &#39;:&#39; separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:623
Iterates over a filtered subrange of declarations stored in a DeclContext.
Definition: DeclBase.h:2093
static bool classof(const Decl *D)
Definition: DeclObjC.h:2721
param_const_iterator param_end() const
Definition: DeclObjC.h:352
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
bool isOverriding() const
Whether this method overrides any other in the class hierarchy.
Definition: DeclObjC.h:450
static bool classofKind(Decl::Kind K)
Definition: DeclObjC.h:2866
static bool classofKind(Kind K)
Definition: DeclObjC.h:627
CXXCtorInitializer *const * init_const_iterator
init_const_iterator - Iterates through the ivar initializer list.
Definition: DeclObjC.h:2609
llvm::iterator_range< param_iterator > param_range
Definition: DeclObjC.h:345
llvm::iterator_range< classprop_iterator > classprop_range
Definition: DeclObjC.h:1018
method_iterator meth_begin() const
Definition: DeclObjC.h:1041
static bool classof(const Decl *D)
Definition: DeclObjC.h:1998
static bool classofKind(Kind K)
Definition: DeclObjC.h:522
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
void setSelfDecl(ImplicitParamDecl *SD)
Definition: DeclObjC.h:415
classmeth_range class_methods() const
Definition: DeclObjC.h:1071
protocol_range protocols() const
Definition: DeclObjC.h:2129
Represents a parameter to a function.
Definition: Decl.h:1550
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
iterator end() const
Definition: DeclObjC.h:92
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2689
static DeclContext * castToDeclContext(const ObjCMethodDecl *D)
Definition: DeclObjC.h:524
SourceLocation getDeclaratorEndLoc() const
Returns the location where the declarator ends.
Definition: DeclObjC.h:280
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:612
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:85
ObjCProtocolDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C protocol.
Definition: DeclObjC.h:2250
instprop_range instance_properties() const
Definition: DeclObjC.h:1003
One of these records is kept for each identifier that is lexed.
llvm::iterator_range< init_iterator > init_range
Definition: DeclObjC.h:2611
bool declaresOrInheritsDesignatedInitializers() const
Returns true if this interface decl declares a designated initializer or it inherites one from its su...
Definition: DeclObjC.h:1337
const ObjCProtocolDecl * getCanonicalDecl() const
Definition: DeclObjC.h:2251
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:2121
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2696
llvm::iterator_range< specific_decl_iterator< ObjCIvarDecl > > ivar_range
Definition: DeclObjC.h:2393
Expr * getGetterCXXConstructor() const
Definition: DeclObjC.h:2849
Represents a class type in Objective C.
Definition: Type.h:5538
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
Definition: DeclObjC.h:1847
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
ObjCMethodDecl * getClassMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1092
const ParmVarDecl *const * param_const_iterator
Definition: DeclObjC.h:343
ObjCMethodFamily
A family of Objective-C methods.
The parameter is contravariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant ...
QualType operator()(const ParmVarDecl *PD) const
Definition: DeclObjC.h:389
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
ObjCImplDecl(Kind DK, DeclContext *DC, ObjCInterfaceDecl *classInterface, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc)
Definition: DeclObjC.h:2432
SetterKind getSetterKind() const
getSetterKind - Return the method used for doing assignment in the property setter.
Definition: DeclObjC.h:894
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:317
Represents a member of a struct/union/class.
Definition: Decl.h:2579
const_iterator end() const
Definition: DeclObjC.h:686
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2133
llvm::iterator_range< protocol_iterator > protocol_range
Definition: DeclObjC.h:2127
instmeth_range instance_methods() const
Definition: DeclObjC.h:1054
bool isDefined() const
Definition: DeclObjC.h:440
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names the class interface associated with this implementation...
Definition: DeclObjC.h:2664
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1588
method_range methods() const
Definition: DeclObjC.h:1037
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition: DeclObjC.h:2681
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:925
llvm::iterator_range< specific_decl_iterator< ObjCIvarDecl > > ivar_range
Definition: DeclObjC.h:2701
SourceRange getSourceRange() const
Definition: DeclObjC.h:708
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Definition: DeclObjC.h:1311
loc_iterator loc_begin() const
Definition: DeclObjC.h:112
prop_range properties() const
Definition: DeclObjC.h:988
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1381
static bool classofKind(Kind K)
Definition: DeclObjC.h:962
void setReturnType(QualType T)
Definition: DeclObjC.h:324
visible_categories_range visible_categories() const
Definition: DeclObjC.h:1653
static bool classof(const Decl *D)
Definition: DeclObjC.h:2865
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:615
static bool classof(const Decl *D)
Definition: DeclObjC.h:2031
void setDeclImplementation(ImplementationControl ic)
Definition: DeclObjC.h:478
static ObjCContainerDecl * castFromDeclContext(const DeclContext *DC)
Definition: DeclObjC.h:1142
void set(ObjCProtocolDecl *const *InList, unsigned Elts, const SourceLocation *Locs, ASTContext &Ctx)
Definition: DeclObjC.cpp:54
bool isUnarySelector() const
bool isClassProperty() const
Definition: DeclObjC.h:879
T * operator[](unsigned Idx) const
Definition: DeclObjC.h:94
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2698
llvm::iterator_range< protocol_loc_iterator > protocol_loc_range
Definition: DeclObjC.h:2148
bool hasNonZeroConstructors() const
Do any of the ivars of this class (not counting its base classes) require construction other than zer...
Definition: DeclObjC.h:2654
SelectorLocationsKind
Whether all locations of the selector identifiers are in a "standard" position.
ObjCTypeParamDecl * AlignmentHack
Definition: DeclObjC.h:650
void set(void *const *InList, unsigned Elts, ASTContext &Ctx)
Definition: DeclObjC.cpp:45
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:969
void setAccessControl(AccessControl ac)
Definition: DeclObjC.h:1982
void setAtLoc(SourceLocation L)
Definition: DeclObjC.h:822
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
unsigned ivar_size() const
Definition: DeclObjC.h:2713
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:2232
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:840
protocol_loc_iterator protocol_loc_end() const
Definition: DeclObjC.h:2378
void setSuperClass(ObjCInterfaceDecl *superCls)
Definition: DeclObjC.h:2693
void setLazyBody(uint64_t Offset)
Definition: DeclObjC.h:509
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
Definition: DeclObjC.h:863
void setClassInterface(ObjCInterfaceDecl *D)
Definition: DeclObjC.h:2749
ObjCCategoryDecl * getCategoryListRaw() const
Retrieve the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1784
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2210
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1158
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Lookup a class method for a given selector.
Definition: DeclObjC.h:1852
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2830
CompoundStmt * getCompoundBody()
Definition: DeclObjC.h:511
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2064
ivar_range ivars() const
Definition: DeclObjC.h:2395
filtered_category_iterator operator++(int)
Definition: DeclObjC.h:1621
ObjCInterfaceDecl * getSuperClass()
Definition: DeclObjC.h:2690
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2177
void addInstanceMethod(ObjCMethodDecl *method)
Definition: DeclObjC.h:2444
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:933
bool hasExplicitBound() const
Whether this type parameter has an explicitly-written type bound, e.g., "T : NSView".
Definition: DeclObjC.h:619
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
QualType getReturnType() const
Definition: DeclObjC.h:323
all_protocol_iterator all_referenced_protocol_end() const
Definition: DeclObjC.h:1442
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2441
bool isAtomic() const
isAtomic - Return true if the property is atomic.
Definition: DeclObjC.h:868
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1115
bool isInstanceProperty() const
Definition: DeclObjC.h:878
void setGetterCXXConstructor(Expr *getterCXXConstructor)
Definition: DeclObjC.h:2853
Iterator that walks over the list of categories, filtering out those that do not meet specific criter...
Definition: DeclObjC.h:1598
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2759
visible_categories_iterator visible_categories_end() const
Retrieve an iterator to the end of the visible-categories list.
Definition: DeclObjC.h:1665
void setVariadic(bool isVar)
Definition: DeclObjC.h:428
classprop_iterator classprop_begin() const
Definition: DeclObjC.h:1024
protocol_loc_range protocol_locs() const
Definition: DeclObjC.h:1395
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1241
visible_extensions_range visible_extensions() const
Definition: DeclObjC.h:1723
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1565
void setHasDestructors(bool val)
Definition: DeclObjC.h:2660
bool empty() const
Definition: DeclObjC.h:72
void setIvarRBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2697
unsigned ivar_size() const
Definition: DeclObjC.h:1476
static bool classofKind(Kind K)
Definition: DeclObjC.h:1999
void setNextIvar(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1980
bool hasDefinition() const
Determine whether this protocol has a definition.
Definition: DeclObjC.h:2198
void setSynthesize(bool synth)
Definition: DeclObjC.h:1990
unsigned Offset
Definition: Format.cpp:1631
void setType(QualType T, TypeSourceInfo *TSI)
Definition: DeclObjC.h:831
classprop_range class_properties() const
Definition: DeclObjC.h:1020
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:923
ObjCTypeParamDecl *const * const_iterator
Definition: DeclObjC.h:680
This represents one expression.
Definition: Expr.h:106
ivar_iterator ivar_end() const
Definition: DeclObjC.h:2709
SourceLocation End
known_extensions_range known_extensions() const
Definition: DeclObjC.h:1761
Selector getSetterName() const
Definition: DeclObjC.h:914
static bool classof(const Decl *D)
Definition: DeclObjC.h:2751
ivar_iterator ivar_begin() const
Definition: DeclObjC.h:1460
int Id
Definition: ASTDiff.cpp:191
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1573
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:926
static bool classof(const Decl *D)
Definition: DeclObjC.h:2479
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:827
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6811
param_iterator param_end()
Definition: DeclObjC.h:357
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver&#39;s type...
Definition: DeclObjC.h:257
SourceLocation getStandardSelectorLoc(unsigned Index, Selector Sel, bool WithArgSpace, ArrayRef< Expr *> Args, SourceLocation EndLoc)
Get the "standard" location of a selector identifier, e.g: For nullary selectors, immediately before ...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2221
SourceLocation getSelectorStartLoc() const
Definition: DeclObjC.h:289
void setAtEndRange(SourceRange atEnd)
Definition: DeclObjC.h:1124
propimpl_iterator propimpl_begin() const
Definition: DeclObjC.h:2471
bool known_categories_empty() const
Determine whether the known-categories list is empty.
Definition: DeclObjC.h:1704
bool ivar_empty() const
Definition: DeclObjC.h:1480
void setRelatedResultType(bool RRT=true)
Note whether this method has a related result type.
Definition: DeclObjC.h:262
redeclarable_base::redecl_iterator redecl_iterator
Definition: DeclObjC.h:1905
loc_iterator loc_end() const
Definition: DeclObjC.h:113
void addClassMethod(ObjCMethodDecl *method)
Definition: DeclObjC.h:2450
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:338
SourceLocation Begin
void setDefined(bool isDefined)
Definition: DeclObjC.h:441
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:344
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1399
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
protocol_loc_iterator protocol_loc_end() const
Definition: DeclObjC.h:1410
propimpl_range property_impls() const
Definition: DeclObjC.h:2467
const_iterator begin() const
Definition: DeclObjC.h:682
static bool classofKind(Kind K)
Definition: DeclObjC.h:2722
llvm::SmallDenseSet< const ObjCProtocolDecl *, 8 > ProtocolPropertySet
Definition: DeclObjC.h:1106
static bool classof(const Decl *D)
Definition: DeclObjC.h:2529
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
bool isInstanceMethod() const
Definition: DeclObjC.h:422
static DeclContext * castToDeclContext(const ObjCContainerDecl *D)
Definition: DeclObjC.h:1138
static bool classof(const Decl *D)
Definition: DeclObjC.h:2260
unsigned getNumArgs() const
void setIvarRBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2418
void setIsRedeclaration(bool RD)
Definition: DeclObjC.h:268
Selector getSelector() const
Definition: DeclObjC.h:321
llvm::iterator_range< protocol_loc_iterator > protocol_loc_range
Definition: DeclObjC.h:2368
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:414
llvm::iterator_range< known_extensions_iterator > known_extensions_range
Definition: DeclObjC.h:1759
ObjCTypeParamVariance
Describes the variance of a given generic parameter.
Definition: DeclObjC.h:534
void setHasSkippedBody(bool Skipped=true)
Definition: DeclObjC.h:466
QualType getType() const
Definition: DeclObjC.h:829
static StringRef getIdentifier(const Token &Tok)
bool hasSkippedBody() const
True if the method was a definition but its body was skipped.
Definition: DeclObjC.h:465
init_iterator init_begin()
init_begin() - Retrieve an iterator to the first initializer.
Definition: DeclObjC.h:2621
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1363
filtered_category_iterator(ObjCCategoryDecl *Current)
Definition: DeclObjC.h:1611
void setBody(Stmt *B)
Definition: DeclObjC.h:512
llvm::iterator_range< instprop_iterator > instprop_range
Definition: DeclObjC.h:1001
protocol_loc_range protocol_locs() const
Definition: DeclObjC.h:2370
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:337
PODSourceRange Brackets
Location of the left and right angle brackets.
Definition: DeclObjC.h:647
unsigned protocol_size() const
Definition: DeclObjC.h:2168
const ObjCIvarDecl * all_declared_ivar_begin() const
Definition: DeclObjC.h:1483
llvm::cl::opt< std::string > Filter
ivar_iterator ivar_end() const
Definition: DeclObjC.h:2401
#define false
Definition: stdbool.h:33
Kind
ivar_iterator ivar_begin() const
Definition: DeclObjC.h:2705
classmeth_iterator classmeth_end() const
Definition: DeclObjC.h:1079
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2326
Encodes a location in the source.
bool getSynthesize() const
Definition: DeclObjC.h:1991
ivar_iterator ivar_end() const
Definition: DeclObjC.h:1468
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2353
ObjCPropertyQueryKind
Definition: DeclObjC.h:717
clang::ObjCProtocolDecl *const * iterator
Definition: DeclObjC.h:89
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2691
void setIvarLBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2416
bool isOptional() const
Definition: DeclObjC.h:486
void setAtStartLoc(SourceLocation Loc)
Definition: DeclObjC.h:1117
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2330
static bool classof(const Decl *D)
Definition: DeclObjC.h:1131
void setObjCDeclQualifier(ObjCDeclQualifier QV)
Definition: DeclObjC.h:251
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2527
ObjCList - This is a simple template class used to hold various lists of decls etc, which is heavily used by the ObjC front-end.
Definition: DeclObjC.h:83
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:856
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1492
ObjCTypeParamDecl * front() const
Definition: DeclObjC.h:690
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2280
llvm::iterator_range< specific_decl_iterator< ObjCPropertyImplDecl > > propimpl_range
Definition: DeclObjC.h:2465
void setOverriding(bool IsOver)
Definition: DeclObjC.h:451
init_iterator init_end()
init_end() - Retrieve an iterator past the last initializer.
Definition: DeclObjC.h:2630
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2344
ObjCMethodDecl * lookupPropertyAccessor(const Selector Sel, const ObjCCategoryDecl *Cat, bool IsClassProperty) const
Lookup a setter or getter in the class hierarchy, including in all categories except for category pas...
Definition: DeclObjC.h:1869
bool isIvarNameSpecified() const
For @synthesize, returns true if an ivar name was explicitly specified.
Definition: DeclObjC.h:2845
param_type_iterator param_type_begin() const
Definition: DeclObjC.h:395
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
isSuperClassOf - Return true if this class is the specified class or is a super class of the specifie...
Definition: DeclObjC.h:1810
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: DeclObjC.h:247
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
Definition: DeclObjC.h:1893
prop_iterator prop_end() const
Definition: DeclObjC.h:994
classmeth_iterator classmeth_begin() const
Definition: DeclObjC.h:1075
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:285
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Definition: opencl-c.h:76
bool isValid() const
Whether this pointer is non-NULL.
const ObjCIvarDecl * getNextIvar() const
Definition: DeclObjC.h:1979
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2417
const SourceLocation * loc_iterator
Definition: DeclObjC.h:110
protocol_range protocols() const
Definition: DeclObjC.h:2356
ObjCTypeParamDecl * back() const
Definition: DeclObjC.h:695
visible_categories_iterator visible_categories_begin() const
Retrieve an iterator to the beginning of the visible-categories list.
Definition: DeclObjC.h:1660
virtual void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.h:1112
Defines various enumerations that describe declaration and type specifiers.
void setSetterCXXAssignment(Expr *setterCXXAssignment)
Definition: DeclObjC.h:2861
ObjCIvarDecl * getNextIvar()
Definition: DeclObjC.h:1978
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
void setPropertyDecl(ObjCPropertyDecl *Prop)
Definition: DeclObjC.h:2821
static bool classofKind(Kind K)
Definition: DeclObjC.h:2261
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2140
param_iterator param_begin()
Definition: DeclObjC.h:356
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2440
bool known_extensions_empty() const
Determine whether the known-extensions list is empty.
Definition: DeclObjC.h:1778
static bool classofKind(Kind K)
Definition: DeclObjC.h:2481
static bool classof(const Decl *D)
Definition: DeclObjC.h:2421
Dataflow Directional Tag Classes.
llvm::iterator_range< specific_decl_iterator< ObjCIvarDecl > > ivar_range
Definition: DeclObjC.h:1456
bool isValid() const
Return true if this is a valid SourceLocation object.
ivar_range ivars() const
Definition: DeclObjC.h:2703
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:909
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
PropertyAttributeKind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:852
instprop_iterator instprop_end() const
Definition: DeclObjC.h:1011
llvm::iterator_range< visible_extensions_iterator > visible_extensions_range
Definition: DeclObjC.h:1721
const ObjCMethodDecl * getCanonicalDecl() const
Definition: DeclObjC.h:243
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2823
llvm::iterator_range< protocol_iterator > protocol_range
Definition: DeclObjC.h:1364
SourceLocation getAtLoc() const
Definition: DeclObjC.h:821
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:949
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
ObjCList< ObjCProtocolDecl >::iterator all_protocol_iterator
Definition: DeclObjC.h:1421
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:355
llvm::iterator_range< specific_decl_iterator< ObjCMethodDecl > > method_range
Definition: DeclObjC.h:1035
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1341
ObjCListBase()=default
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1549
void setIvarList(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1488
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
filtered_category_iterator & operator++()
Definition: DeclObjC.h:2879
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:559
Kind getKind() const
Definition: DeclBase.h:421
unsigned size() const
Definition: DeclObjC.h:71
unsigned NumElts
Definition: DeclObjC.h:64
friend bool operator!=(filtered_category_iterator X, filtered_category_iterator Y)
Definition: DeclObjC.h:1632
static bool classofKind(Kind K)
Definition: DeclObjC.h:2422
llvm::iterator_range< all_protocol_iterator > all_protocol_range
Definition: DeclObjC.h:1422
llvm::iterator_range< redecl_iterator > redecl_range
Definition: Redeclarable.h:291
llvm::DenseMap< std::pair< IdentifierInfo *, unsigned >, ObjCPropertyDecl * > PropertyMap
Definition: DeclObjC.h:1105
init_const_iterator init_end() const
end() - Retrieve an iterator past the last initializer.
Definition: DeclObjC.h:2635
SourceLocation getSetterNameLoc() const
Definition: DeclObjC.h:915
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2747
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:767
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:2017
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2552
void setHasNonZeroConstructors(bool val)
Definition: DeclObjC.h:2655
void overwritePropertyAttributes(unsigned PRVal)
Definition: DeclObjC.h:848
protocol_loc_range protocol_locs() const
Definition: DeclObjC.h:2150
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2256
SourceLocation getSelectorLoc(unsigned Index) const
Definition: DeclObjC.h:295
friend TrailingObjects
Definition: OpenMPClause.h:99
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:1315
bool isRetaining() const
isRetaining - Return true if the property retains its value.
Definition: DeclObjC.h:873
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2360
const ObjCProtocolDecl * getDefinition() const
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2215
friend bool operator==(filtered_category_iterator X, filtered_category_iterator Y)
Definition: DeclObjC.h:1627
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:504
param_const_iterator param_begin() const
Definition: DeclObjC.h:348
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1915
A list of Objective-C protocols, along with the source locations at which they were referenced...
Definition: DeclObjC.h:102
void setCategoryListRaw(ObjCCategoryDecl *category)
Set the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1797
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Definition: DeclObjC.h:2193
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:917
llvm::iterator_range< known_categories_iterator > known_categories_range
Definition: DeclObjC.h:1685
bool IsClassExtension() const
Definition: DeclObjC.h:2390
ImplementationControl getImplementationControl() const
Definition: DeclObjC.h:482
SourceRange getAtEndRange() const
Definition: DeclObjC.h:1122
prop_iterator prop_begin() const
Definition: DeclObjC.h:990
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13954
known_categories_iterator known_categories_end() const
Retrieve an iterator to the end of the known-categories list.
Definition: DeclObjC.h:1699
static bool classofKind(Kind K)
Definition: DeclObjC.h:2032
Represents a field declaration created by an @defs(...).
Definition: DeclObjC.h:2012
Defines the clang::SourceLocation class and associated facilities.
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2413
static bool isInstanceMethod(const Decl *D)
instprop_iterator instprop_begin() const
Definition: DeclObjC.h:1007
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName)
Definition: DeclObjC.h:1832
ObjCDeclQualifier
ObjCDeclQualifier - &#39;Qualifiers&#39; written next to the return and parameter types in method declaration...
Definition: DeclBase.h:196
void setInstanceMethod(bool isInst)
Definition: DeclObjC.h:423
void setHasRedeclaration(bool HRD) const
Definition: DeclObjC.h:273
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1945
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:945
void setReturnTypeSourceInfo(TypeSourceInfo *TInfo)
Definition: DeclObjC.h:338
ObjCCategoryDecl * getNextClassCategory() const
Definition: DeclObjC.h:2382
void setIvarLBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2695
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:637
ImplicitParamDecl * getCmdDecl() const
Definition: DeclObjC.h:416
bool isVariadic() const
Definition: DeclObjC.h:427
void setPropertyAttributes(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:844
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2364
param_const_iterator sel_param_end() const
Definition: DeclObjC.h:361
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:283
static bool classofKind(Kind K)
Definition: DeclObjC.h:2530
unsigned protocol_size() const
Definition: DeclObjC.h:2365
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:90
StringRef getName() const
getName - Get the name of identifier for the class interface associated with this implementation as a...
Definition: DeclObjC.h:2673
static ObjCPropertyQueryKind getQueryKind(bool isClassProperty)
Definition: DeclObjC.h:886
known_extensions_iterator known_extensions_end() const
Retrieve an iterator to the end of the known-extensions list.
Definition: DeclObjC.h:1773
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2818
bool visible_categories_empty() const
Determine whether the visible-categories list is empty.
Definition: DeclObjC.h:1670
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:704
void setAtLoc(SourceLocation Loc)
Definition: DeclObjC.h:2816
QualType getType() const
Definition: Decl.h:648
#define true
Definition: stdbool.h:32
llvm::iterator_range< specific_decl_iterator< ObjCPropertyDecl > > prop_range
Definition: DeclObjC.h:986
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2154
static bool classof(const Decl *D)
Definition: DeclObjC.h:1922
A trivial tuple used to represent a source range.
instmeth_iterator instmeth_begin() const
Definition: DeclObjC.h:1058
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:299
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:922
known_categories_iterator known_categories_begin() const
Retrieve an iterator to the beginning of the known-categories list.
Definition: DeclObjC.h:1694
bool isRedeclaration() const
True if this is a method redeclaration in the same interface.
Definition: DeclObjC.h:267
This represents a decl that may have a name.
Definition: Decl.h:249
static bool classof(const Decl *D)
Definition: DeclObjC.h:626
void setVariance(ObjCTypeParamVariance variance)
Set the variance of this type parameter.
Definition: DeclObjC.h:607
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2374
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1087
AccessControl getAccessControl() const
Definition: DeclObjC.h:1984
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2419
static bool classofKind(Kind K)
Definition: DeclObjC.h:1923
ivar_iterator ivar_begin() const
Definition: DeclObjC.h:2397
bool isPropertyAccessor() const
Definition: DeclObjC.h:432
Selector getGetterName() const
Definition: DeclObjC.h:906
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:824
SourceLocation getEndOfDefinitionLoc() const
Definition: DeclObjC.h:1878
bool visible_extensions_empty() const
Determine whether the visible-extensions list is empty.
Definition: DeclObjC.h:1740
protocol_loc_iterator protocol_loc_end() const
Definition: DeclObjC.h:2161
void setTypeForDecl(const Type *TD) const
Definition: DeclObjC.h:1920
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:700
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2126
SourceLocation ColonLoc
Location of &#39;:&#39;.
Definition: OpenMPClause.h:108
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:372
unsigned getNumIvarInitializers() const
getNumArgs - Number of ivars which must be initialized.
Definition: DeclObjC.h:2640
unsigned size() const
Determine the number of type parameters in this list.
Definition: DeclObjC.h:677
void setCmdDecl(ImplicitParamDecl *CD)
Definition: DeclObjC.h:417
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2499
No in-class initializer.
Definition: Specifiers.h:230
The parameter is invariant: must match exactly.
llvm::iterator_range< protocol_loc_iterator > protocol_loc_range
Definition: DeclObjC.h:1393
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:941
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:367
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2729
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.