Coverage Report

Created: 2018-07-19 20:53

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