Coverage Report

Created: 2018-11-16 02:38

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