Coverage Report

Created: 2019-02-20 07:29

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