Coverage Report

Created: 2020-02-25 14:32

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