Coverage Report

Created: 2021-08-24 07:12

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