Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Decl.h
Line
Count
Source (jump to first uncovered line)
1
//===- Decl.h - Classes for representing declarations -----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the Decl subclasses.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_DECL_H
15
#define LLVM_CLANG_AST_DECL_H
16
17
#include "clang/AST/APValue.h"
18
#include "clang/AST/DeclBase.h"
19
#include "clang/AST/DeclarationName.h"
20
#include "clang/AST/ExternalASTSource.h"
21
#include "clang/AST/NestedNameSpecifier.h"
22
#include "clang/AST/Redeclarable.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/AddressSpaces.h"
25
#include "clang/Basic/Diagnostic.h"
26
#include "clang/Basic/IdentifierTable.h"
27
#include "clang/Basic/LLVM.h"
28
#include "clang/Basic/Linkage.h"
29
#include "clang/Basic/OperatorKinds.h"
30
#include "clang/Basic/PartialDiagnostic.h"
31
#include "clang/Basic/PragmaKinds.h"
32
#include "clang/Basic/SourceLocation.h"
33
#include "clang/Basic/Specifiers.h"
34
#include "clang/Basic/Visibility.h"
35
#include "llvm/ADT/APSInt.h"
36
#include "llvm/ADT/ArrayRef.h"
37
#include "llvm/ADT/Optional.h"
38
#include "llvm/ADT/PointerIntPair.h"
39
#include "llvm/ADT/PointerUnion.h"
40
#include "llvm/ADT/StringRef.h"
41
#include "llvm/ADT/iterator_range.h"
42
#include "llvm/Support/Casting.h"
43
#include "llvm/Support/Compiler.h"
44
#include "llvm/Support/TrailingObjects.h"
45
#include <cassert>
46
#include <cstddef>
47
#include <cstdint>
48
#include <string>
49
#include <utility>
50
51
namespace clang {
52
53
class ASTContext;
54
struct ASTTemplateArgumentListInfo;
55
class Attr;
56
class CompoundStmt;
57
class DependentFunctionTemplateSpecializationInfo;
58
class EnumDecl;
59
class Expr;
60
class FunctionTemplateDecl;
61
class FunctionTemplateSpecializationInfo;
62
class LabelStmt;
63
class MemberSpecializationInfo;
64
class Module;
65
class NamespaceDecl;
66
class ParmVarDecl;
67
class RecordDecl;
68
class Stmt;
69
class StringLiteral;
70
class TagDecl;
71
class TemplateArgumentList;
72
class TemplateArgumentListInfo;
73
class TemplateParameterList;
74
class TypeAliasTemplateDecl;
75
class TypeLoc;
76
class UnresolvedSetImpl;
77
class VarTemplateDecl;
78
79
/// A container of type source information.
80
///
81
/// A client can read the relevant info using TypeLoc wrappers, e.g:
82
/// @code
83
/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
84
/// TL.getBeginLoc().print(OS, SrcMgr);
85
/// @endcode
86
class alignas(8) TypeSourceInfo {
87
  // Contains a memory block after the class, used for type source information,
88
  // allocated by ASTContext.
89
  friend class ASTContext;
90
91
  QualType Ty;
92
93
49.2M
  TypeSourceInfo(QualType ty) : Ty(ty) {}
94
95
public:
96
  /// Return the type wrapped by this type source info.
97
193M
  QualType getType() const { return Ty; }
98
99
  /// Return the TypeLoc wrapper for the type source info.
100
  TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
101
102
  /// Override the type stored in this TypeSourceInfo. Use with caution!
103
44.6k
  void overrideType(QualType T) { Ty = T; }
104
};
105
106
/// The top declaration context.
107
class TranslationUnitDecl : public Decl, public DeclContext {
108
  ASTContext &Ctx;
109
110
  /// The (most recently entered) anonymous namespace for this
111
  /// translation unit, if one has been created.
112
  NamespaceDecl *AnonymousNamespace = nullptr;
113
114
  explicit TranslationUnitDecl(ASTContext &ctx);
115
116
  virtual void anchor();
117
118
public:
119
696M
  ASTContext &getASTContext() const { return Ctx; }
120
121
3.95k
  NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
122
450
  void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
123
124
  static TranslationUnitDecl *Create(ASTContext &C);
125
126
  // Implement isa/cast/dyncast/etc.
127
674M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
128
734M
  static bool classofKind(Kind K) { return K == TranslationUnit; }
129
10.8k
  static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
130
10.8k
    return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
131
10.8k
  }
132
0
  static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
133
0
    return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
134
0
  }
135
};
136
137
/// Represents a `#pragma comment` line. Always a child of
138
/// TranslationUnitDecl.
139
class PragmaCommentDecl final
140
    : public Decl,
141
      private llvm::TrailingObjects<PragmaCommentDecl, char> {
142
  friend class ASTDeclReader;
143
  friend class ASTDeclWriter;
144
  friend TrailingObjects;
145
146
  PragmaMSCommentKind CommentKind;
147
148
  PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc,
149
                    PragmaMSCommentKind CommentKind)
150
53
      : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
151
152
  virtual void anchor();
153
154
public:
155
  static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC,
156
                                   SourceLocation CommentLoc,
157
                                   PragmaMSCommentKind CommentKind,
158
                                   StringRef Arg);
159
  static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID,
160
                                               unsigned ArgSize);
161
162
43
  PragmaMSCommentKind getCommentKind() const { return CommentKind; }
163
164
43
  StringRef getArg() const { return getTrailingObjects<char>(); }
165
166
  // Implement isa/cast/dyncast/etc.
167
353k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
168
353k
  static bool classofKind(Kind K) { return K == PragmaComment; }
169
};
170
171
/// Represents a `#pragma detect_mismatch` line. Always a child of
172
/// TranslationUnitDecl.
173
class PragmaDetectMismatchDecl final
174
    : public Decl,
175
      private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
176
  friend class ASTDeclReader;
177
  friend class ASTDeclWriter;
178
  friend TrailingObjects;
179
180
  size_t ValueStart;
181
182
  PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
183
                           size_t ValueStart)
184
12
      : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
185
186
  virtual void anchor();
187
188
public:
189
  static PragmaDetectMismatchDecl *Create(const ASTContext &C,
190
                                          TranslationUnitDecl *DC,
191
                                          SourceLocation Loc, StringRef Name,
192
                                          StringRef Value);
193
  static PragmaDetectMismatchDecl *
194
  CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
195
196
10
  StringRef getName() const { return getTrailingObjects<char>(); }
197
10
  StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
198
199
  // Implement isa/cast/dyncast/etc.
200
353k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
201
353k
  static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
202
};
203
204
/// Declaration context for names declared as extern "C" in C++. This
205
/// is neither the semantic nor lexical context for such declarations, but is
206
/// used to check for conflicts with other extern "C" declarations. Example:
207
///
208
/// \code
209
///   namespace N { extern "C" void f(); } // #1
210
///   void N::f() {}                       // #2
211
///   namespace M { extern "C" void f(); } // #3
212
/// \endcode
213
///
214
/// The semantic context of #1 is namespace N and its lexical context is the
215
/// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
216
/// context is the TU. However, both declarations are also visible in the
217
/// extern "C" context.
218
///
219
/// The declaration at #3 finds it is a redeclaration of \c N::f through
220
/// lookup in the extern "C" context.
221
class ExternCContextDecl : public Decl, public DeclContext {
222
  explicit ExternCContextDecl(TranslationUnitDecl *TU)
223
    : Decl(ExternCContext, TU, SourceLocation()),
224
29.0k
      DeclContext(ExternCContext) {}
225
226
  virtual void anchor();
227
228
public:
229
  static ExternCContextDecl *Create(const ASTContext &C,
230
                                    TranslationUnitDecl *TU);
231
232
  // Implement isa/cast/dyncast/etc.
233
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
234
0
  static bool classofKind(Kind K) { return K == ExternCContext; }
235
0
  static DeclContext *castToDeclContext(const ExternCContextDecl *D) {
236
0
    return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
237
0
  }
238
0
  static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) {
239
0
    return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
240
0
  }
241
};
242
243
/// This represents a decl that may have a name.  Many decls have names such
244
/// as ObjCMethodDecl, but not \@class, etc.
245
///
246
/// Note that not every NamedDecl is actually named (e.g., a struct might
247
/// be anonymous), and not every name is an identifier.
248
class NamedDecl : public Decl {
249
  /// The name of this declaration, which is typically a normal
250
  /// identifier but may also be a special kind of name (C++
251
  /// constructor, Objective-C selector, etc.)
252
  DeclarationName Name;
253
254
  virtual void anchor();
255
256
private:
257
  NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
258
259
protected:
260
  NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
261
40.6M
      : Decl(DK, DC, L), Name(N) {}
262
263
public:
264
  /// Get the identifier that names this declaration, if there is one.
265
  ///
266
  /// This will return NULL if this declaration has no name (e.g., for
267
  /// an unnamed class) or if the name is a special name (C++ constructor,
268
  /// Objective-C selector, etc.).
269
171M
  IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
270
271
  /// Get the name of identifier for this declaration as a StringRef.
272
  ///
273
  /// This requires that the declaration have a name and that it be a simple
274
  /// identifier.
275
3.47M
  StringRef getName() const {
276
3.47M
    assert(Name.isIdentifier() && "Name is not a simple identifier");
277
3.47M
    return getIdentifier() ? 
getIdentifier()->getName()3.37M
:
""98.2k
;
278
3.47M
  }
279
280
  /// Get a human-readable name for the declaration, even if it is one of the
281
  /// special kinds of names (C++ constructor, Objective-C selector, etc).
282
  ///
283
  /// Creating this name requires expensive string manipulation, so it should
284
  /// be called only when performance doesn't matter. For simple declarations,
285
  /// getNameAsCString() should suffice.
286
  //
287
  // FIXME: This function should be renamed to indicate that it is not just an
288
  // alternate form of getName(), and clients should move as appropriate.
289
  //
290
  // FIXME: Deprecated, move clients to getName().
291
30.9k
  std::string getNameAsString() const { return Name.getAsString(); }
292
293
  virtual void printName(raw_ostream &os) const;
294
295
  /// Get the actual, stored name of the declaration, which may be a special
296
  /// name.
297
466M
  DeclarationName getDeclName() const { return Name; }
298
299
  /// Set the name of this declaration.
300
528k
  void setDeclName(DeclarationName N) { Name = N; }
301
302
  /// Returns a human-readable qualified name for this declaration, like
303
  /// A::B::i, for i being member of namespace A::B.
304
  ///
305
  /// If the declaration is not a member of context which can be named (record,
306
  /// namespace), it will return the same result as printName().
307
  ///
308
  /// Creating this name is expensive, so it should be called only when
309
  /// performance doesn't matter.
310
  void printQualifiedName(raw_ostream &OS) const;
311
  void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
312
313
  // FIXME: Remove string version.
314
  std::string getQualifiedNameAsString() const;
315
316
  /// Appends a human-readable name for this declaration into the given stream.
317
  ///
318
  /// This is the method invoked by Sema when displaying a NamedDecl
319
  /// in a diagnostic.  It does not necessarily produce the same
320
  /// result as printName(); for example, class template
321
  /// specializations are printed with their template arguments.
322
  virtual void getNameForDiagnostic(raw_ostream &OS,
323
                                    const PrintingPolicy &Policy,
324
                                    bool Qualified) const;
325
326
  /// Determine whether this declaration, if known to be well-formed within
327
  /// its context, will replace the declaration OldD if introduced into scope.
328
  ///
329
  /// A declaration will replace another declaration if, for example, it is
330
  /// a redeclaration of the same variable or function, but not if it is a
331
  /// declaration of a different kind (function vs. class) or an overloaded
332
  /// function.
333
  ///
334
  /// \param IsKnownNewer \c true if this declaration is known to be newer
335
  /// than \p OldD (for instance, if this declaration is newly-created).
336
  bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
337
338
  /// Determine whether this declaration has linkage.
339
  bool hasLinkage() const;
340
341
  using Decl::isModulePrivate;
342
  using Decl::setModulePrivate;
343
344
  /// Determine whether this declaration is a C++ class member.
345
32.2M
  bool isCXXClassMember() const {
346
32.2M
    const DeclContext *DC = getDeclContext();
347
32.2M
348
32.2M
    // C++0x [class.mem]p1:
349
32.2M
    //   The enumerators of an unscoped enumeration defined in
350
32.2M
    //   the class are members of the class.
351
32.2M
    if (isa<EnumDecl>(DC))
352
319k
      DC = DC->getRedeclContext();
353
32.2M
354
32.2M
    return DC->isRecord();
355
32.2M
  }
356
357
  /// Determine whether the given declaration is an instance member of
358
  /// a C++ class.
359
  bool isCXXInstanceMember() const;
360
361
  /// Determine what kind of linkage this entity has.
362
  ///
363
  /// This is not the linkage as defined by the standard or the codegen notion
364
  /// of linkage. It is just an implementation detail that is used to compute
365
  /// those.
366
  Linkage getLinkageInternal() const;
367
368
  /// Get the linkage from a semantic point of view. Entities in
369
  /// anonymous namespaces are external (in c++98).
370
7.20M
  Linkage getFormalLinkage() const {
371
7.20M
    return clang::getFormalLinkage(getLinkageInternal());
372
7.20M
  }
373
374
  /// True if this decl has external linkage.
375
20.4M
  bool hasExternalFormalLinkage() const {
376
20.4M
    return isExternalFormalLinkage(getLinkageInternal());
377
20.4M
  }
378
379
23.5M
  bool isExternallyVisible() const {
380
23.5M
    return clang::isExternallyVisible(getLinkageInternal());
381
23.5M
  }
382
383
  /// Determine whether this declaration can be redeclared in a
384
  /// different translation unit.
385
2.79k
  bool isExternallyDeclarable() const {
386
2.79k
    return isExternallyVisible() && 
!getOwningModuleForLinkage()2.69k
;
387
2.79k
  }
388
389
  /// Determines the visibility of this entity.
390
29.8k
  Visibility getVisibility() const {
391
29.8k
    return getLinkageAndVisibility().getVisibility();
392
29.8k
  }
393
394
  /// Determines the linkage and visibility of this entity.
395
  LinkageInfo getLinkageAndVisibility() const;
396
397
  /// Kinds of explicit visibility.
398
  enum ExplicitVisibilityKind {
399
    /// Do an LV computation for, ultimately, a type.
400
    /// Visibility may be restricted by type visibility settings and
401
    /// the visibility of template arguments.
402
    VisibilityForType,
403
404
    /// Do an LV computation for, ultimately, a non-type declaration.
405
    /// Visibility may be restricted by value visibility settings and
406
    /// the visibility of template arguments.
407
    VisibilityForValue
408
  };
409
410
  /// If visibility was explicitly specified for this
411
  /// declaration, return that visibility.
412
  Optional<Visibility>
413
  getExplicitVisibility(ExplicitVisibilityKind kind) const;
414
415
  /// True if the computed linkage is valid. Used for consistency
416
  /// checking. Should always return true.
417
  bool isLinkageValid() const;
418
419
  /// True if something has required us to compute the linkage
420
  /// of this declaration.
421
  ///
422
  /// Language features which can retroactively change linkage (like a
423
  /// typedef name for linkage purposes) may need to consider this,
424
  /// but hopefully only in transitory ways during parsing.
425
100k
  bool hasLinkageBeenComputed() const {
426
100k
    return hasCachedLinkage();
427
100k
  }
428
429
  /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
430
  /// the underlying named decl.
431
248M
  NamedDecl *getUnderlyingDecl() {
432
248M
    // Fast-path the common case.
433
248M
    if (this->getKind() != UsingShadow &&
434
248M
        
this->getKind() != ConstructorUsingShadow245M
&&
435
248M
        
this->getKind() != ObjCCompatibleAlias245M
&&
436
248M
        
this->getKind() != NamespaceAlias245M
)
437
245M
      return this;
438
2.42M
439
2.42M
    return getUnderlyingDeclImpl();
440
2.42M
  }
441
2.21M
  const NamedDecl *getUnderlyingDecl() const {
442
2.21M
    return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
443
2.21M
  }
444
445
24.7M
  NamedDecl *getMostRecentDecl() {
446
24.7M
    return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
447
24.7M
  }
448
18.3M
  const NamedDecl *getMostRecentDecl() const {
449
18.3M
    return const_cast<NamedDecl*>(this)->getMostRecentDecl();
450
18.3M
  }
451
452
  ObjCStringFormatFamily getObjCFStringFormattingFamily() const;
453
454
50.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
455
53.0M
  static bool classofKind(Kind K) { return K >= firstNamed && 
K <= lastNamed51.6M
; }
456
};
457
458
432k
inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
459
432k
  ND.printName(OS);
460
432k
  return OS;
461
432k
}
462
463
/// Represents the declaration of a label.  Labels also have a
464
/// corresponding LabelStmt, which indicates the position that the label was
465
/// defined at.  For normal labels, the location of the decl is the same as the
466
/// location of the statement.  For GNU local labels (__label__), the decl
467
/// location is where the __label__ is.
468
class LabelDecl : public NamedDecl {
469
  LabelStmt *TheStmt;
470
  StringRef MSAsmName;
471
  bool MSAsmNameResolved = false;
472
473
  /// For normal labels, this is the same as the main declaration
474
  /// label, i.e., the location of the identifier; for GNU local labels,
475
  /// this is the location of the __label__ keyword.
476
  SourceLocation LocStart;
477
478
  LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
479
            LabelStmt *S, SourceLocation StartL)
480
4.27k
      : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
481
482
  void anchor() override;
483
484
public:
485
  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
486
                           SourceLocation IdentL, IdentifierInfo *II);
487
  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
488
                           SourceLocation IdentL, IdentifierInfo *II,
489
                           SourceLocation GnuLabelL);
490
  static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
491
492
21.1k
  LabelStmt *getStmt() const { return TheStmt; }
493
4.00k
  void setStmt(LabelStmt *T) { TheStmt = T; }
494
495
7.97k
  bool isGnuLocal() const { return LocStart != getLocation(); }
496
3.99k
  void setLocStart(SourceLocation L) { LocStart = L; }
497
498
416
  SourceRange getSourceRange() const override LLVM_READONLY {
499
416
    return SourceRange(LocStart, getLocation());
500
416
  }
501
502
11.5k
  bool isMSAsmLabel() const { return !MSAsmName.empty(); }
503
28
  bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
504
  void setMSAsmLabel(StringRef Name);
505
43
  StringRef getMSAsmLabel() const { return MSAsmName; }
506
18
  void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
507
508
  // Implement isa/cast/dyncast/etc.
509
56.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
510
56.1M
  static bool classofKind(Kind K) { return K == Label; }
511
};
512
513
/// Represent a C++ namespace.
514
class NamespaceDecl : public NamedDecl, public DeclContext,
515
                      public Redeclarable<NamespaceDecl>
516
{
517
  /// The starting location of the source range, pointing
518
  /// to either the namespace or the inline keyword.
519
  SourceLocation LocStart;
520
521
  /// The ending location of the source range.
522
  SourceLocation RBraceLoc;
523
524
  /// A pointer to either the anonymous namespace that lives just inside
525
  /// this namespace or to the first namespace in the chain (the latter case
526
  /// only when this is not the first in the chain), along with a
527
  /// boolean value indicating whether this is an inline namespace.
528
  llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
529
530
  NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
531
                SourceLocation StartLoc, SourceLocation IdLoc,
532
                IdentifierInfo *Id, NamespaceDecl *PrevDecl);
533
534
  using redeclarable_base = Redeclarable<NamespaceDecl>;
535
536
  NamespaceDecl *getNextRedeclarationImpl() override;
537
  NamespaceDecl *getPreviousDeclImpl() override;
538
  NamespaceDecl *getMostRecentDeclImpl() override;
539
540
public:
541
  friend class ASTDeclReader;
542
  friend class ASTDeclWriter;
543
544
  static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
545
                               bool Inline, SourceLocation StartLoc,
546
                               SourceLocation IdLoc, IdentifierInfo *Id,
547
                               NamespaceDecl *PrevDecl);
548
549
  static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
550
551
  using redecl_range = redeclarable_base::redecl_range;
552
  using redecl_iterator = redeclarable_base::redecl_iterator;
553
554
  using redeclarable_base::redecls_begin;
555
  using redeclarable_base::redecls_end;
556
  using redeclarable_base::redecls;
557
  using redeclarable_base::getPreviousDecl;
558
  using redeclarable_base::getMostRecentDecl;
559
  using redeclarable_base::isFirstDecl;
560
561
  /// Returns true if this is an anonymous namespace declaration.
562
  ///
563
  /// For example:
564
  /// \code
565
  ///   namespace {
566
  ///     ...
567
  ///   };
568
  /// \endcode
569
  /// q.v. C++ [namespace.unnamed]
570
4.94M
  bool isAnonymousNamespace() const {
571
4.94M
    return !getIdentifier();
572
4.94M
  }
573
574
  /// Returns true if this is an inline namespace declaration.
575
3.94M
  bool isInline() const {
576
3.94M
    return AnonOrFirstNamespaceAndInline.getInt();
577
3.94M
  }
578
579
  /// Set whether this is an inline namespace declaration.
580
951
  void setInline(bool Inline) {
581
951
    AnonOrFirstNamespaceAndInline.setInt(Inline);
582
951
  }
583
584
  /// Get the original (first) namespace declaration.
585
  NamespaceDecl *getOriginalNamespace();
586
587
  /// Get the original (first) namespace declaration.
588
  const NamespaceDecl *getOriginalNamespace() const;
589
590
  /// Return true if this declaration is an original (first) declaration
591
  /// of the namespace. This is false for non-original (subsequent) namespace
592
  /// declarations and anonymous namespaces.
593
  bool isOriginalNamespace() const;
594
595
  /// Retrieve the anonymous namespace nested inside this namespace,
596
  /// if any.
597
1.20k
  NamespaceDecl *getAnonymousNamespace() const {
598
1.20k
    return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
599
1.20k
  }
600
601
635
  void setAnonymousNamespace(NamespaceDecl *D) {
602
635
    getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
603
635
  }
604
605
  /// Retrieves the canonical declaration of this namespace.
606
9.32M
  NamespaceDecl *getCanonicalDecl() override {
607
9.32M
    return getOriginalNamespace();
608
9.32M
  }
609
0
  const NamespaceDecl *getCanonicalDecl() const {
610
0
    return getOriginalNamespace();
611
0
  }
612
613
715
  SourceRange getSourceRange() const override LLVM_READONLY {
614
715
    return SourceRange(LocStart, RBraceLoc);
615
715
  }
616
617
769
  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
618
707
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
619
0
  void setLocStart(SourceLocation L) { LocStart = L; }
620
120k
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
621
622
  // Implement isa/cast/dyncast/etc.
623
67.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
624
81.9M
  static bool classofKind(Kind K) { return K == Namespace; }
625
4.67k
  static DeclContext *castToDeclContext(const NamespaceDecl *D) {
626
4.67k
    return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
627
4.67k
  }
628
0
  static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
629
0
    return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
630
0
  }
631
};
632
633
/// Represent the declaration of a variable (in which case it is
634
/// an lvalue) a function (in which case it is a function designator) or
635
/// an enum constant.
636
class ValueDecl : public NamedDecl {
637
  QualType DeclType;
638
639
  void anchor() override;
640
641
protected:
642
  ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
643
            DeclarationName N, QualType T)
644
29.8M
    : NamedDecl(DK, DC, L, N), DeclType(T) {}
645
646
public:
647
541M
  QualType getType() const { return DeclType; }
648
2.13M
  void setType(QualType newType) { DeclType = newType; }
649
650
  /// Determine whether this symbol is weakly-imported,
651
  ///        or declared with the weak or weak-ref attr.
652
  bool isWeak() const;
653
654
  // Implement isa/cast/dyncast/etc.
655
22.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
656
22.8M
  static bool classofKind(Kind K) { return K >= firstValue && 
K <= lastValue22.5M
; }
657
};
658
659
/// A struct with extended info about a syntactic
660
/// name qualifier, to be used for the case of out-of-line declarations.
661
struct QualifierInfo {
662
  NestedNameSpecifierLoc QualifierLoc;
663
664
  /// The number of "outer" template parameter lists.
665
  /// The count includes all of the template parameter lists that were matched
666
  /// against the template-ids occurring into the NNS and possibly (in the
667
  /// case of an explicit specialization) a final "template <>".
668
  unsigned NumTemplParamLists = 0;
669
670
  /// A new-allocated array of size NumTemplParamLists,
671
  /// containing pointers to the "outer" template parameter lists.
672
  /// It includes all of the template parameter lists that were matched
673
  /// against the template-ids occurring into the NNS and possibly (in the
674
  /// case of an explicit specialization) a final "template <>".
675
  TemplateParameterList** TemplParamLists = nullptr;
676
677
375k
  QualifierInfo() = default;
678
  QualifierInfo(const QualifierInfo &) = delete;
679
  QualifierInfo& operator=(const QualifierInfo &) = delete;
680
681
  /// Sets info about "outer" template parameter lists.
682
  void setTemplateParameterListsInfo(ASTContext &Context,
683
                                     ArrayRef<TemplateParameterList *> TPLists);
684
};
685
686
/// Represents a ValueDecl that came out of a declarator.
687
/// Contains type source information through TypeSourceInfo.
688
class DeclaratorDecl : public ValueDecl {
689
  // A struct representing both a TInfo and a syntactic qualifier,
690
  // to be used for the (uncommon) case of out-of-line declarations.
691
  struct ExtInfo : public QualifierInfo {
692
    TypeSourceInfo *TInfo;
693
  };
694
695
  llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
696
697
  /// The start of the source range for this declaration,
698
  /// ignoring outer template declarations.
699
  SourceLocation InnerLocStart;
700
701
48.3M
  bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
702
878k
  ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
703
1.41M
  const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
704
705
protected:
706
  DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
707
                 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
708
                 SourceLocation StartL)
709
29.4M
      : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
710
711
public:
712
  friend class ASTDeclReader;
713
  friend class ASTDeclWriter;
714
715
36.3M
  TypeSourceInfo *getTypeSourceInfo() const {
716
36.3M
    return hasExtInfo()
717
36.3M
      ? 
getExtInfo()->TInfo688k
718
36.3M
      : 
DeclInfo.get<TypeSourceInfo*>()35.6M
;
719
36.3M
  }
720
721
179k
  void setTypeSourceInfo(TypeSourceInfo *TI) {
722
179k
    if (hasExtInfo())
723
405
      getExtInfo()->TInfo = TI;
724
178k
    else
725
178k
      DeclInfo = TI;
726
179k
  }
727
728
  /// Return start of source range ignoring outer template declarations.
729
11.3M
  SourceLocation getInnerLocStart() const { return InnerLocStart; }
730
469k
  void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
731
732
  /// Return start of source range taking into account any outer template
733
  /// declarations.
734
  SourceLocation getOuterLocStart() const;
735
736
  SourceRange getSourceRange() const override LLVM_READONLY;
737
738
84.7k
  SourceLocation getBeginLoc() const LLVM_READONLY {
739
84.7k
    return getOuterLocStart();
740
84.7k
  }
741
742
  /// Retrieve the nested-name-specifier that qualifies the name of this
743
  /// declaration, if it was present in the source.
744
1.13M
  NestedNameSpecifier *getQualifier() const {
745
1.13M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc.getNestedNameSpecifier()509k
746
1.13M
                        : 
nullptr629k
;
747
1.13M
  }
748
749
  /// Retrieve the nested-name-specifier (with source-location
750
  /// information) that qualifies the name of this declaration, if it was
751
  /// present in the source.
752
2.53M
  NestedNameSpecifierLoc getQualifierLoc() const {
753
2.53M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc64.0k
754
2.53M
                        : 
NestedNameSpecifierLoc()2.47M
;
755
2.53M
  }
756
757
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
758
759
6.57M
  unsigned getNumTemplateParameterLists() const {
760
6.57M
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists128k
:
06.45M
;
761
6.57M
  }
762
763
19.7k
  TemplateParameterList *getTemplateParameterList(unsigned index) const {
764
19.7k
    assert(index < getNumTemplateParameterLists());
765
19.7k
    return getExtInfo()->TemplParamLists[index];
766
19.7k
  }
767
768
  void setTemplateParameterListsInfo(ASTContext &Context,
769
                                     ArrayRef<TemplateParameterList *> TPLists);
770
771
  SourceLocation getTypeSpecStartLoc() const;
772
773
  // Implement isa/cast/dyncast/etc.
774
8.77M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
775
8.77M
  static bool classofKind(Kind K) {
776
8.77M
    return K >= firstDeclarator && 
K <= lastDeclarator7.10M
;
777
8.77M
  }
778
};
779
780
/// Structure used to store a statement, the constant value to
781
/// which it was evaluated (if any), and whether or not the statement
782
/// is an integral constant expression (if known).
783
struct EvaluatedStmt {
784
  /// Whether this statement was already evaluated.
785
  bool WasEvaluated : 1;
786
787
  /// Whether this statement is being evaluated.
788
  bool IsEvaluating : 1;
789
790
  /// Whether we already checked whether this statement was an
791
  /// integral constant expression.
792
  bool CheckedICE : 1;
793
794
  /// Whether we are checking whether this statement is an
795
  /// integral constant expression.
796
  bool CheckingICE : 1;
797
798
  /// Whether this statement is an integral constant expression,
799
  /// or in C++11, whether the statement is a constant expression. Only
800
  /// valid if CheckedICE is true.
801
  bool IsICE : 1;
802
803
  Stmt *Value;
804
  APValue Evaluated;
805
806
  EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false),
807
456k
                    CheckingICE(false), IsICE(false) {}
808
809
};
810
811
/// Represents a variable declaration or definition.
812
class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
813
public:
814
  /// Initialization styles.
815
  enum InitializationStyle {
816
    /// C-style initialization with assignment
817
    CInit,
818
819
    /// Call-style initialization (C++98)
820
    CallInit,
821
822
    /// Direct list-initialization (C++11)
823
    ListInit
824
  };
825
826
  /// Kinds of thread-local storage.
827
  enum TLSKind {
828
    /// Not a TLS variable.
829
    TLS_None,
830
831
    /// TLS with a known-constant initializer.
832
    TLS_Static,
833
834
    /// TLS with a dynamic initializer.
835
    TLS_Dynamic
836
  };
837
838
  /// Return the string used to specify the storage class \p SC.
839
  ///
840
  /// It is illegal to call this function with SC == None.
841
  static const char *getStorageClassSpecifierString(StorageClass SC);
842
843
protected:
844
  // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
845
  // have allocated the auxiliary struct of information there.
846
  //
847
  // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
848
  // this as *many* VarDecls are ParmVarDecls that don't have default
849
  // arguments. We could save some space by moving this pointer union to be
850
  // allocated in trailing space when necessary.
851
  using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
852
853
  /// The initializer for this variable or, for a ParmVarDecl, the
854
  /// C++ default argument.
855
  mutable InitType Init;
856
857
private:
858
  friend class ASTDeclReader;
859
  friend class ASTNodeImporter;
860
  friend class StmtIteratorBase;
861
862
  class VarDeclBitfields {
863
    friend class ASTDeclReader;
864
    friend class VarDecl;
865
866
    unsigned SClass : 3;
867
    unsigned TSCSpec : 2;
868
    unsigned InitStyle : 2;
869
  };
870
  enum { NumVarDeclBits = 7 };
871
872
protected:
873
  enum { NumParameterIndexBits = 8 };
874
875
  enum DefaultArgKind {
876
    DAK_None,
877
    DAK_Unparsed,
878
    DAK_Uninstantiated,
879
    DAK_Normal
880
  };
881
882
  class ParmVarDeclBitfields {
883
    friend class ASTDeclReader;
884
    friend class ParmVarDecl;
885
886
    unsigned : NumVarDeclBits;
887
888
    /// Whether this parameter inherits a default argument from a
889
    /// prior declaration.
890
    unsigned HasInheritedDefaultArg : 1;
891
892
    /// Describes the kind of default argument for this parameter. By default
893
    /// this is none. If this is normal, then the default argument is stored in
894
    /// the \c VarDecl initializer expression unless we were unable to parse
895
    /// (even an invalid) expression for the default argument.
896
    unsigned DefaultArgKind : 2;
897
898
    /// Whether this parameter undergoes K&R argument promotion.
899
    unsigned IsKNRPromoted : 1;
900
901
    /// Whether this parameter is an ObjC method parameter or not.
902
    unsigned IsObjCMethodParam : 1;
903
904
    /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
905
    /// Otherwise, the number of function parameter scopes enclosing
906
    /// the function parameter scope in which this parameter was
907
    /// declared.
908
    unsigned ScopeDepthOrObjCQuals : 7;
909
910
    /// The number of parameters preceding this parameter in the
911
    /// function parameter scope in which it was declared.
912
    unsigned ParameterIndex : NumParameterIndexBits;
913
  };
914
915
  class NonParmVarDeclBitfields {
916
    friend class ASTDeclReader;
917
    friend class ImplicitParamDecl;
918
    friend class VarDecl;
919
920
    unsigned : NumVarDeclBits;
921
922
    // FIXME: We need something similar to CXXRecordDecl::DefinitionData.
923
    /// Whether this variable is a definition which was demoted due to
924
    /// module merge.
925
    unsigned IsThisDeclarationADemotedDefinition : 1;
926
927
    /// Whether this variable is the exception variable in a C++ catch
928
    /// or an Objective-C @catch statement.
929
    unsigned ExceptionVar : 1;
930
931
    /// Whether this local variable could be allocated in the return
932
    /// slot of its function, enabling the named return value optimization
933
    /// (NRVO).
934
    unsigned NRVOVariable : 1;
935
936
    /// Whether this variable is the for-range-declaration in a C++0x
937
    /// for-range statement.
938
    unsigned CXXForRangeDecl : 1;
939
940
    /// Whether this variable is the for-in loop declaration in Objective-C.
941
    unsigned ObjCForDecl : 1;
942
943
    /// Whether this variable is an ARC pseudo-__strong
944
    /// variable;  see isARCPseudoStrong() for details.
945
    unsigned ARCPseudoStrong : 1;
946
947
    /// Whether this variable is (C++1z) inline.
948
    unsigned IsInline : 1;
949
950
    /// Whether this variable has (C++1z) inline explicitly specified.
951
    unsigned IsInlineSpecified : 1;
952
953
    /// Whether this variable is (C++0x) constexpr.
954
    unsigned IsConstexpr : 1;
955
956
    /// Whether this variable is the implicit variable for a lambda
957
    /// init-capture.
958
    unsigned IsInitCapture : 1;
959
960
    /// Whether this local extern variable's previous declaration was
961
    /// declared in the same block scope. This controls whether we should merge
962
    /// the type of this declaration with its previous declaration.
963
    unsigned PreviousDeclInSameBlockScope : 1;
964
965
    /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
966
    /// something else.
967
    unsigned ImplicitParamKind : 3;
968
969
    unsigned EscapingByref : 1;
970
  };
971
972
  union {
973
    unsigned AllBits;
974
    VarDeclBitfields VarDeclBits;
975
    ParmVarDeclBitfields ParmVarDeclBits;
976
    NonParmVarDeclBitfields NonParmVarDeclBits;
977
  };
978
979
  VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
980
          SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
981
          TypeSourceInfo *TInfo, StorageClass SC);
982
983
  using redeclarable_base = Redeclarable<VarDecl>;
984
985
8.25M
  VarDecl *getNextRedeclarationImpl() override {
986
8.25M
    return getNextRedeclaration();
987
8.25M
  }
988
989
21.0k
  VarDecl *getPreviousDeclImpl() override {
990
21.0k
    return getPreviousDecl();
991
21.0k
  }
992
993
38.1M
  VarDecl *getMostRecentDeclImpl() override {
994
38.1M
    return getMostRecentDecl();
995
38.1M
  }
996
997
public:
998
  using redecl_range = redeclarable_base::redecl_range;
999
  using redecl_iterator = redeclarable_base::redecl_iterator;
1000
1001
  using redeclarable_base::redecls_begin;
1002
  using redeclarable_base::redecls_end;
1003
  using redeclarable_base::redecls;
1004
  using redeclarable_base::getPreviousDecl;
1005
  using redeclarable_base::getMostRecentDecl;
1006
  using redeclarable_base::isFirstDecl;
1007
1008
  static VarDecl *Create(ASTContext &C, DeclContext *DC,
1009
                         SourceLocation StartLoc, SourceLocation IdLoc,
1010
                         IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
1011
                         StorageClass S);
1012
1013
  static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1014
1015
  SourceRange getSourceRange() const override LLVM_READONLY;
1016
1017
  /// Returns the storage class as written in the source. For the
1018
  /// computed linkage of symbol, see getLinkage.
1019
124M
  StorageClass getStorageClass() const {
1020
124M
    return (StorageClass) VarDeclBits.SClass;
1021
124M
  }
1022
  void setStorageClass(StorageClass SC);
1023
1024
325k
  void setTSCSpec(ThreadStorageClassSpecifier TSC) {
1025
325k
    VarDeclBits.TSCSpec = TSC;
1026
325k
    assert(VarDeclBits.TSCSpec == TSC && "truncation");
1027
325k
  }
1028
42.4M
  ThreadStorageClassSpecifier getTSCSpec() const {
1029
42.4M
    return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1030
42.4M
  }
1031
  TLSKind getTLSKind() const;
1032
1033
  /// Returns true if a variable with function scope is a non-static local
1034
  /// variable.
1035
47.3M
  bool hasLocalStorage() const {
1036
47.3M
    if (getStorageClass() == SC_None) {
1037
39.5M
      // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1038
39.5M
      // used to describe variables allocated in global memory and which are
1039
39.5M
      // accessed inside a kernel(s) as read-only variables. As such, variables
1040
39.5M
      // in constant address space cannot have local storage.
1041
39.5M
      if (getType().getAddressSpace() == LangAS::opencl_constant)
1042
1.12k
        return false;
1043
39.5M
      // Second check is for C++11 [dcl.stc]p4.
1044
39.5M
      return !isFileVarDecl() && 
getTSCSpec() == TSCS_unspecified35.2M
;
1045
39.5M
    }
1046
7.77M
1047
7.77M
    // Global Named Register (GNU extension)
1048
7.77M
    if (getStorageClass() == SC_Register && 
!isLocalVarDeclOrParm()103k
)
1049
814
      return false;
1050
7.77M
1051
7.77M
    // Return true for:  Auto, Register.
1052
7.77M
    // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1053
7.77M
1054
7.77M
    return getStorageClass() >= SC_Auto;
1055
7.77M
  }
1056
1057
  /// Returns true if a variable with function scope is a static local
1058
  /// variable.
1059
8.19M
  bool isStaticLocal() const {
1060
8.19M
    return (getStorageClass() == SC_Static ||
1061
8.19M
            // C++11 [dcl.stc]p4
1062
8.19M
            
(6.95M
getStorageClass() == SC_None6.95M
&&
getTSCSpec() == TSCS_thread_local6.62M
))
1063
8.19M
      && 
!isFileVarDecl()1.23M
;
1064
8.19M
  }
1065
1066
  /// Returns true if a variable has extern or __private_extern__
1067
  /// storage.
1068
18.2M
  bool hasExternalStorage() const {
1069
18.2M
    return getStorageClass() == SC_Extern ||
1070
18.2M
           
getStorageClass() == SC_PrivateExtern17.3M
;
1071
18.2M
  }
1072
1073
  /// Returns true for all variables that do not have local storage.
1074
  ///
1075
  /// This includes all global variables as well as static variables declared
1076
  /// within a function.
1077
12.0M
  bool hasGlobalStorage() const { return !hasLocalStorage(); }
1078
1079
  /// Get the storage duration of this variable, per C++ [basic.stc].
1080
846k
  StorageDuration getStorageDuration() const {
1081
846k
    return hasLocalStorage() ? 
SD_Automatic826k
:
1082
846k
           
getTSCSpec() 20.2k
?
SD_Thread178
:
SD_Static20.0k
;
1083
846k
  }
1084
1085
  /// Compute the language linkage.
1086
  LanguageLinkage getLanguageLinkage() const;
1087
1088
  /// Determines whether this variable is a variable with external, C linkage.
1089
  bool isExternC() const;
1090
1091
  /// Determines whether this variable's context is, or is nested within,
1092
  /// a C++ extern "C" linkage spec.
1093
  bool isInExternCContext() const;
1094
1095
  /// Determines whether this variable's context is, or is nested within,
1096
  /// a C++ extern "C++" linkage spec.
1097
  bool isInExternCXXContext() const;
1098
1099
  /// Returns true for local variable declarations other than parameters.
1100
  /// Note that this includes static variables inside of functions. It also
1101
  /// includes variables inside blocks.
1102
  ///
1103
  ///   void foo() { int x; static int y; extern int z; }
1104
9.55M
  bool isLocalVarDecl() const {
1105
9.55M
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition1.01M
)
1106
1.01M
      return false;
1107
8.53M
    if (const DeclContext *DC = getLexicalDeclContext())
1108
8.53M
      return DC->getRedeclContext()->isFunctionOrMethod();
1109
0
    return false;
1110
0
  }
1111
1112
  /// Similar to isLocalVarDecl but also includes parameters.
1113
187k
  bool isLocalVarDeclOrParm() const {
1114
187k
    return isLocalVarDecl() || 
getKind() == Decl::ParmVar88.9k
;
1115
187k
  }
1116
1117
  /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1118
220k
  bool isFunctionOrMethodVarDecl() const {
1119
220k
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition65.3k
)
1120
65.3k
      return false;
1121
155k
    const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
1122
155k
    return DC->isFunctionOrMethod() && 
DC->getDeclKind() != Decl::Block140k
;
1123
155k
  }
1124
1125
  /// Determines whether this is a static data member.
1126
  ///
1127
  /// This will only be true in C++, and applies to, e.g., the
1128
  /// variable 'x' in:
1129
  /// \code
1130
  /// struct S {
1131
  ///   static int x;
1132
  /// };
1133
  /// \endcode
1134
206M
  bool isStaticDataMember() const {
1135
206M
    // If it wasn't static, it would be a FieldDecl.
1136
206M
    return getKind() != Decl::ParmVar && 
getDeclContext()->isRecord()184M
;
1137
206M
  }
1138
1139
  VarDecl *getCanonicalDecl() override;
1140
13.3M
  const VarDecl *getCanonicalDecl() const {
1141
13.3M
    return const_cast<VarDecl*>(this)->getCanonicalDecl();
1142
13.3M
  }
1143
1144
  enum DefinitionKind {
1145
    /// This declaration is only a declaration.
1146
    DeclarationOnly,
1147
1148
    /// This declaration is a tentative definition.
1149
    TentativeDefinition,
1150
1151
    /// This declaration is definitely a definition.
1152
    Definition
1153
  };
1154
1155
  /// Check whether this declaration is a definition. If this could be
1156
  /// a tentative definition (in C), don't check whether there's an overriding
1157
  /// definition.
1158
  DefinitionKind isThisDeclarationADefinition(ASTContext &) const;
1159
13.3M
  DefinitionKind isThisDeclarationADefinition() const {
1160
13.3M
    return isThisDeclarationADefinition(getASTContext());
1161
13.3M
  }
1162
1163
  /// Check whether this variable is defined in this translation unit.
1164
  DefinitionKind hasDefinition(ASTContext &) const;
1165
39.9k
  DefinitionKind hasDefinition() const {
1166
39.9k
    return hasDefinition(getASTContext());
1167
39.9k
  }
1168
1169
  /// Get the tentative definition that acts as the real definition in a TU.
1170
  /// Returns null if there is a proper definition available.
1171
  VarDecl *getActingDefinition();
1172
584
  const VarDecl *getActingDefinition() const {
1173
584
    return const_cast<VarDecl*>(this)->getActingDefinition();
1174
584
  }
1175
1176
  /// Get the real (not just tentative) definition for this declaration.
1177
  VarDecl *getDefinition(ASTContext &);
1178
6.87M
  const VarDecl *getDefinition(ASTContext &C) const {
1179
6.87M
    return const_cast<VarDecl*>(this)->getDefinition(C);
1180
6.87M
  }
1181
4.54M
  VarDecl *getDefinition() {
1182
4.54M
    return getDefinition(getASTContext());
1183
4.54M
  }
1184
4.42k
  const VarDecl *getDefinition() const {
1185
4.42k
    return const_cast<VarDecl*>(this)->getDefinition();
1186
4.42k
  }
1187
1188
  /// Determine whether this is or was instantiated from an out-of-line
1189
  /// definition of a static data member.
1190
  bool isOutOfLine() const override;
1191
1192
  /// Returns true for file scoped variable declaration.
1193
52.9M
  bool isFileVarDecl() const {
1194
52.9M
    Kind K = getKind();
1195
52.9M
    if (K == ParmVar || 
K == ImplicitParam44.6M
)
1196
8.80M
      return false;
1197
44.1M
1198
44.1M
    if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1199
7.03M
      return true;
1200
37.0M
1201
37.0M
    if (isStaticDataMember())
1202
1.81M
      return true;
1203
35.2M
1204
35.2M
    return false;
1205
35.2M
  }
1206
1207
  /// Get the initializer for this variable, no matter which
1208
  /// declaration it is attached to.
1209
2.07M
  const Expr *getAnyInitializer() const {
1210
2.07M
    const VarDecl *D;
1211
2.07M
    return getAnyInitializer(D);
1212
2.07M
  }
1213
1214
  /// Get the initializer for this variable, no matter which
1215
  /// declaration it is attached to. Also get that declaration.
1216
  const Expr *getAnyInitializer(const VarDecl *&D) const;
1217
1218
  bool hasInit() const;
1219
3.36M
  const Expr *getInit() const {
1220
3.36M
    return const_cast<VarDecl *>(this)->getInit();
1221
3.36M
  }
1222
  Expr *getInit();
1223
1224
  /// Retrieve the address of the initializer expression.
1225
  Stmt **getInitAddress();
1226
1227
  void setInit(Expr *I);
1228
1229
  /// Determine whether this variable's value can be used in a
1230
  /// constant expression, according to the relevant language standard.
1231
  /// This only checks properties of the declaration, and does not check
1232
  /// whether the initializer is in fact a constant expression.
1233
  bool isUsableInConstantExpressions(ASTContext &C) const;
1234
1235
  EvaluatedStmt *ensureEvaluatedStmt() const;
1236
1237
  /// Attempt to evaluate the value of the initializer attached to this
1238
  /// declaration, and produce notes explaining why it cannot be evaluated or is
1239
  /// not a constant expression. Returns a pointer to the value if evaluation
1240
  /// succeeded, 0 otherwise.
1241
  APValue *evaluateValue() const;
1242
  APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
1243
1244
  /// Return the already-evaluated value of this variable's
1245
  /// initializer, or NULL if the value is not yet known. Returns pointer
1246
  /// to untyped APValue if the value could not be evaluated.
1247
  APValue *getEvaluatedValue() const;
1248
1249
  /// Determines whether it is already known whether the
1250
  /// initializer is an integral constant expression or not.
1251
  bool isInitKnownICE() const;
1252
1253
  /// Determines whether the initializer is an integral constant
1254
  /// expression, or in C++11, whether the initializer is a constant
1255
  /// expression.
1256
  ///
1257
  /// \pre isInitKnownICE()
1258
  bool isInitICE() const;
1259
1260
  /// Determine whether the value of the initializer attached to this
1261
  /// declaration is an integral constant expression.
1262
  bool checkInitIsICE() const;
1263
1264
489k
  void setInitStyle(InitializationStyle Style) {
1265
489k
    VarDeclBits.InitStyle = Style;
1266
489k
  }
1267
1268
  /// The style of initialization for this declaration.
1269
  ///
1270
  /// C-style initialization is "int x = 1;". Call-style initialization is
1271
  /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1272
  /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1273
  /// expression for class types. List-style initialization is C++11 syntax,
1274
  /// e.g. "int x{1};". Clients can distinguish between different forms of
1275
  /// initialization by checking this value. In particular, "int x = {1};" is
1276
  /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1277
  /// Init expression in all three cases is an InitListExpr.
1278
1.44M
  InitializationStyle getInitStyle() const {
1279
1.44M
    return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1280
1.44M
  }
1281
1282
  /// Whether the initializer is a direct-initializer (list or call).
1283
292k
  bool isDirectInit() const {
1284
292k
    return getInitStyle() != CInit;
1285
292k
  }
1286
1287
  /// If this definition should pretend to be a declaration.
1288
35.3M
  bool isThisDeclarationADemotedDefinition() const {
1289
35.3M
    return isa<ParmVarDecl>(this) ? 
false5.94M
:
1290
35.3M
      
NonParmVarDeclBits.IsThisDeclarationADemotedDefinition29.4M
;
1291
35.3M
  }
1292
1293
  /// This is a definition which should be demoted to a declaration.
1294
  ///
1295
  /// In some cases (mostly module merging) we can end up with two visible
1296
  /// definitions one of which needs to be demoted to a declaration to keep
1297
  /// the AST invariants.
1298
26
  void demoteThisDefinitionToDeclaration() {
1299
26
    assert(isThisDeclarationADefinition() && "Not a definition!");
1300
26
    assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1301
26
    NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1302
26
  }
1303
1304
  /// Determine whether this variable is the exception variable in a
1305
  /// C++ catch statememt or an Objective-C \@catch statement.
1306
2.34M
  bool isExceptionVariable() const {
1307
2.34M
    return isa<ParmVarDecl>(this) ? 
false3.32k
:
NonParmVarDeclBits.ExceptionVar2.33M
;
1308
2.34M
  }
1309
916
  void setExceptionVariable(bool EV) {
1310
916
    assert(!isa<ParmVarDecl>(this));
1311
916
    NonParmVarDeclBits.ExceptionVar = EV;
1312
916
  }
1313
1314
  /// Determine whether this local variable can be used with the named
1315
  /// return value optimization (NRVO).
1316
  ///
1317
  /// The named return value optimization (NRVO) works by marking certain
1318
  /// non-volatile local variables of class type as NRVO objects. These
1319
  /// locals can be allocated within the return slot of their containing
1320
  /// function, in which case there is no need to copy the object to the
1321
  /// return slot when returning from the function. Within the function body,
1322
  /// each return that returns the NRVO object will have this variable as its
1323
  /// NRVO candidate.
1324
899k
  bool isNRVOVariable() const {
1325
899k
    return isa<ParmVarDecl>(this) ? 
false938
:
NonParmVarDeclBits.NRVOVariable898k
;
1326
899k
  }
1327
38.6k
  void setNRVOVariable(bool NRVO) {
1328
38.6k
    assert(!isa<ParmVarDecl>(this));
1329
38.6k
    NonParmVarDeclBits.NRVOVariable = NRVO;
1330
38.6k
  }
1331
1332
  /// Determine whether this variable is the for-range-declaration in
1333
  /// a C++0x for-range statement.
1334
504k
  bool isCXXForRangeDecl() const {
1335
504k
    return isa<ParmVarDecl>(this) ? 
false0
: NonParmVarDeclBits.CXXForRangeDecl;
1336
504k
  }
1337
327k
  void setCXXForRangeDecl(bool FRD) {
1338
327k
    assert(!isa<ParmVarDecl>(this));
1339
327k
    NonParmVarDeclBits.CXXForRangeDecl = FRD;
1340
327k
  }
1341
1342
  /// Determine whether this variable is a for-loop declaration for a
1343
  /// for-in statement in Objective-C.
1344
472k
  bool isObjCForDecl() const {
1345
472k
    return NonParmVarDeclBits.ObjCForDecl;
1346
472k
  }
1347
1348
325k
  void setObjCForDecl(bool FRD) {
1349
325k
    NonParmVarDeclBits.ObjCForDecl = FRD;
1350
325k
  }
1351
1352
  /// Determine whether this variable is an ARC pseudo-__strong
1353
  /// variable.  A pseudo-__strong variable has a __strong-qualified
1354
  /// type but does not actually retain the object written into it.
1355
  /// Generally such variables are also 'const' for safety.
1356
127k
  bool isARCPseudoStrong() const {
1357
127k
    return isa<ParmVarDecl>(this) ? 
false186
:
NonParmVarDeclBits.ARCPseudoStrong127k
;
1358
127k
  }
1359
1.99k
  void setARCPseudoStrong(bool ps) {
1360
1.99k
    assert(!isa<ParmVarDecl>(this));
1361
1.99k
    NonParmVarDeclBits.ARCPseudoStrong = ps;
1362
1.99k
  }
1363
1364
  /// Whether this variable is (C++1z) inline.
1365
18.6M
  bool isInline() const {
1366
18.6M
    return isa<ParmVarDecl>(this) ? 
false938
:
NonParmVarDeclBits.IsInline18.6M
;
1367
18.6M
  }
1368
452k
  bool isInlineSpecified() const {
1369
452k
    return isa<ParmVarDecl>(this) ? 
false0
1370
452k
                                  : NonParmVarDeclBits.IsInlineSpecified;
1371
452k
  }
1372
140
  void setInlineSpecified() {
1373
140
    assert(!isa<ParmVarDecl>(this));
1374
140
    NonParmVarDeclBits.IsInline = true;
1375
140
    NonParmVarDeclBits.IsInlineSpecified = true;
1376
140
  }
1377
190
  void setImplicitlyInline() {
1378
190
    assert(!isa<ParmVarDecl>(this));
1379
190
    NonParmVarDeclBits.IsInline = true;
1380
190
  }
1381
1382
  /// Whether this variable is (C++11) constexpr.
1383
18.4M
  bool isConstexpr() const {
1384
18.4M
    return isa<ParmVarDecl>(this) ? 
false1.76M
:
NonParmVarDeclBits.IsConstexpr16.7M
;
1385
18.4M
  }
1386
503k
  void setConstexpr(bool IC) {
1387
503k
    assert(!isa<ParmVarDecl>(this));
1388
503k
    NonParmVarDeclBits.IsConstexpr = IC;
1389
503k
  }
1390
1391
  /// Whether this variable is the implicit variable for a lambda init-capture.
1392
38.4M
  bool isInitCapture() const {
1393
38.4M
    return isa<ParmVarDecl>(this) ? 
false18.7M
:
NonParmVarDeclBits.IsInitCapture19.6M
;
1394
38.4M
  }
1395
325k
  void setInitCapture(bool IC) {
1396
325k
    assert(!isa<ParmVarDecl>(this));
1397
325k
    NonParmVarDeclBits.IsInitCapture = IC;
1398
325k
  }
1399
1400
  /// Whether this local extern variable declaration's previous declaration
1401
  /// was declared in the same block scope. Only correct in C++.
1402
528k
  bool isPreviousDeclInSameBlockScope() const {
1403
528k
    return isa<ParmVarDecl>(this)
1404
528k
               ? 
false0
1405
528k
               : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1406
528k
  }
1407
325k
  void setPreviousDeclInSameBlockScope(bool Same) {
1408
325k
    assert(!isa<ParmVarDecl>(this));
1409
325k
    NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1410
325k
  }
1411
1412
  /// Indicates the capture is a __block variable that is captured by a block
1413
  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
1414
  /// returns false).
1415
  bool isEscapingByref() const;
1416
1417
  /// Indicates the capture is a __block variable that is never captured by an
1418
  /// escaping block.
1419
  bool isNonEscapingByref() const;
1420
1421
668
  void setEscapingByref() {
1422
668
    NonParmVarDeclBits.EscapingByref = true;
1423
668
  }
1424
1425
  /// Retrieve the variable declaration from which this variable could
1426
  /// be instantiated, if it is an instantiation (rather than a non-template).
1427
  VarDecl *getTemplateInstantiationPattern() const;
1428
1429
  /// If this variable is an instantiated static data member of a
1430
  /// class template specialization, returns the templated static data member
1431
  /// from which it was instantiated.
1432
  VarDecl *getInstantiatedFromStaticDataMember() const;
1433
1434
  /// If this variable is an instantiation of a variable template or a
1435
  /// static data member of a class template, determine what kind of
1436
  /// template specialization or instantiation this is.
1437
  TemplateSpecializationKind getTemplateSpecializationKind() const;
1438
1439
  /// If this variable is an instantiation of a variable template or a
1440
  /// static data member of a class template, determine its point of
1441
  /// instantiation.
1442
  SourceLocation getPointOfInstantiation() const;
1443
1444
  /// If this variable is an instantiation of a static data member of a
1445
  /// class template specialization, retrieves the member specialization
1446
  /// information.
1447
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1448
1449
  /// For a static data member that was instantiated from a static
1450
  /// data member of a class template, set the template specialiation kind.
1451
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
1452
                        SourceLocation PointOfInstantiation = SourceLocation());
1453
1454
  /// Specify that this variable is an instantiation of the
1455
  /// static data member VD.
1456
  void setInstantiationOfStaticDataMember(VarDecl *VD,
1457
                                          TemplateSpecializationKind TSK);
1458
1459
  /// Retrieves the variable template that is described by this
1460
  /// variable declaration.
1461
  ///
1462
  /// Every variable template is represented as a VarTemplateDecl and a
1463
  /// VarDecl. The former contains template properties (such as
1464
  /// the template parameter lists) while the latter contains the
1465
  /// actual description of the template's
1466
  /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1467
  /// VarDecl that from a VarTemplateDecl, while
1468
  /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1469
  /// a VarDecl.
1470
  VarTemplateDecl *getDescribedVarTemplate() const;
1471
1472
  void setDescribedVarTemplate(VarTemplateDecl *Template);
1473
1474
  // Is this variable known to have a definition somewhere in the complete
1475
  // program? This may be true even if the declaration has internal linkage and
1476
  // has no definition within this source file.
1477
  bool isKnownToBeDefined() const;
1478
1479
  /// Do we need to emit an exit-time destructor for this variable?
1480
  bool isNoDestroy(const ASTContext &) const;
1481
1482
  // Implement isa/cast/dyncast/etc.
1483
235M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1484
235M
  static bool classofKind(Kind K) { return K >= firstVar && 
K <= lastVar117M
; }
1485
};
1486
1487
class ImplicitParamDecl : public VarDecl {
1488
  void anchor() override;
1489
1490
public:
1491
  /// Defines the kind of the implicit parameter: is this an implicit parameter
1492
  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1493
  /// context or something else.
1494
  enum ImplicitParamKind : unsigned {
1495
    /// Parameter for Objective-C 'self' argument
1496
    ObjCSelf,
1497
1498
    /// Parameter for Objective-C '_cmd' argument
1499
    ObjCCmd,
1500
1501
    /// Parameter for C++ 'this' argument
1502
    CXXThis,
1503
1504
    /// Parameter for C++ virtual table pointers
1505
    CXXVTT,
1506
1507
    /// Parameter for captured context
1508
    CapturedContext,
1509
1510
    /// Other implicit parameter
1511
    Other,
1512
  };
1513
1514
  /// Create implicit parameter.
1515
  static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
1516
                                   SourceLocation IdLoc, IdentifierInfo *Id,
1517
                                   QualType T, ImplicitParamKind ParamKind);
1518
  static ImplicitParamDecl *Create(ASTContext &C, QualType T,
1519
                                   ImplicitParamKind ParamKind);
1520
1521
  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1522
1523
  ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
1524
                    IdentifierInfo *Id, QualType Type,
1525
                    ImplicitParamKind ParamKind)
1526
      : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1527
1.23M
                /*TInfo=*/nullptr, SC_None) {
1528
1.23M
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1529
1.23M
    setImplicit();
1530
1.23M
  }
1531
1532
  ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
1533
      : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1534
                SourceLocation(), /*Id=*/nullptr, Type,
1535
68.1k
                /*TInfo=*/nullptr, SC_None) {
1536
68.1k
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1537
68.1k
    setImplicit();
1538
68.1k
  }
1539
1540
  /// Returns the implicit parameter kind.
1541
69.0k
  ImplicitParamKind getParameterKind() const {
1542
69.0k
    return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1543
69.0k
  }
1544
1545
  // Implement isa/cast/dyncast/etc.
1546
1.05M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1547
1.05M
  static bool classofKind(Kind K) { return K == ImplicitParam; }
1548
};
1549
1550
/// Represents a parameter to a function.
1551
class ParmVarDecl : public VarDecl {
1552
public:
1553
  enum { MaxFunctionScopeDepth = 255 };
1554
  enum { MaxFunctionScopeIndex = 255 };
1555
1556
protected:
1557
  ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1558
              SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
1559
              TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1560
13.3M
      : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1561
13.3M
    assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1562
13.3M
    assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1563
13.3M
    assert(ParmVarDeclBits.IsKNRPromoted == false);
1564
13.3M
    assert(ParmVarDeclBits.IsObjCMethodParam == false);
1565
13.3M
    setDefaultArg(DefArg);
1566
13.3M
  }
1567
1568
public:
1569
  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1570
                             SourceLocation StartLoc,
1571
                             SourceLocation IdLoc, IdentifierInfo *Id,
1572
                             QualType T, TypeSourceInfo *TInfo,
1573
                             StorageClass S, Expr *DefArg);
1574
1575
  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1576
1577
  SourceRange getSourceRange() const override LLVM_READONLY;
1578
1579
65.3k
  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1580
65.3k
    ParmVarDeclBits.IsObjCMethodParam = true;
1581
65.3k
    setParameterIndex(parameterIndex);
1582
65.3k
  }
1583
1584
12.9M
  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1585
12.9M
    assert(!ParmVarDeclBits.IsObjCMethodParam);
1586
12.9M
1587
12.9M
    ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1588
12.9M
    assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1589
12.9M
           && "truncation!");
1590
12.9M
1591
12.9M
    setParameterIndex(parameterIndex);
1592
12.9M
  }
1593
1594
147k
  bool isObjCMethodParameter() const {
1595
147k
    return ParmVarDeclBits.IsObjCMethodParam;
1596
147k
  }
1597
1598
2.62M
  unsigned getFunctionScopeDepth() const {
1599
2.62M
    if (ParmVarDeclBits.IsObjCMethodParam) 
return 0263
;
1600
2.62M
    return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1601
2.62M
  }
1602
1603
  /// Returns the index of this parameter in its prototype or method scope.
1604
8.21M
  unsigned getFunctionScopeIndex() const {
1605
8.21M
    return getParameterIndex();
1606
8.21M
  }
1607
1608
249k
  ObjCDeclQualifier getObjCDeclQualifier() const {
1609
249k
    if (!ParmVarDeclBits.IsObjCMethodParam) 
return OBJC_TQ_None242k
;
1610
7.36k
    return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1611
7.36k
  }
1612
65.1k
  void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
1613
65.1k
    assert(ParmVarDeclBits.IsObjCMethodParam);
1614
65.1k
    ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1615
65.1k
  }
1616
1617
  /// True if the value passed to this parameter must undergo
1618
  /// K&R-style default argument promotion:
1619
  ///
1620
  /// C99 6.5.2.2.
1621
  ///   If the expression that denotes the called function has a type
1622
  ///   that does not include a prototype, the integer promotions are
1623
  ///   performed on each argument, and arguments that have type float
1624
  ///   are promoted to double.
1625
641k
  bool isKNRPromoted() const {
1626
641k
    return ParmVarDeclBits.IsKNRPromoted;
1627
641k
  }
1628
537
  void setKNRPromoted(bool promoted) {
1629
537
    ParmVarDeclBits.IsKNRPromoted = promoted;
1630
537
  }
1631
1632
  Expr *getDefaultArg();
1633
2.66k
  const Expr *getDefaultArg() const {
1634
2.66k
    return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1635
2.66k
  }
1636
1637
  void setDefaultArg(Expr *defarg);
1638
1639
  /// Retrieve the source range that covers the entire default
1640
  /// argument.
1641
  SourceRange getDefaultArgRange() const;
1642
  void setUninstantiatedDefaultArg(Expr *arg);
1643
  Expr *getUninstantiatedDefaultArg();
1644
1
  const Expr *getUninstantiatedDefaultArg() const {
1645
1
    return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1646
1
  }
1647
1648
  /// Determines whether this parameter has a default argument,
1649
  /// either parsed or not.
1650
  bool hasDefaultArg() const;
1651
1652
  /// Determines whether this parameter has a default argument that has not
1653
  /// yet been parsed. This will occur during the processing of a C++ class
1654
  /// whose member functions have default arguments, e.g.,
1655
  /// @code
1656
  ///   class X {
1657
  ///   public:
1658
  ///     void f(int x = 17); // x has an unparsed default argument now
1659
  ///   }; // x has a regular default argument now
1660
  /// @endcode
1661
44.9M
  bool hasUnparsedDefaultArg() const {
1662
44.9M
    return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1663
44.9M
  }
1664
1665
42.9M
  bool hasUninstantiatedDefaultArg() const {
1666
42.9M
    return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1667
42.9M
  }
1668
1669
  /// Specify that this parameter has an unparsed default argument.
1670
  /// The argument will be replaced with a real default argument via
1671
  /// setDefaultArg when the class definition enclosing the function
1672
  /// declaration that owns this default argument is completed.
1673
87.0k
  void setUnparsedDefaultArg() {
1674
87.0k
    ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1675
87.0k
  }
1676
1677
2.57M
  bool hasInheritedDefaultArg() const {
1678
2.57M
    return ParmVarDeclBits.HasInheritedDefaultArg;
1679
2.57M
  }
1680
1681
2.31M
  void setHasInheritedDefaultArg(bool I = true) {
1682
2.31M
    ParmVarDeclBits.HasInheritedDefaultArg = I;
1683
2.31M
  }
1684
1685
  QualType getOriginalType() const;
1686
1687
  /// Determine whether this parameter is actually a function
1688
  /// parameter pack.
1689
  bool isParameterPack() const;
1690
1691
  /// Sets the function declaration that owns this
1692
  /// ParmVarDecl. Since ParmVarDecls are often created before the
1693
  /// FunctionDecls that own them, this routine is required to update
1694
  /// the DeclContext appropriately.
1695
6.76M
  void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
1696
1697
  // Implement isa/cast/dyncast/etc.
1698
259M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1699
259M
  static bool classofKind(Kind K) { return K == ParmVar; }
1700
1701
private:
1702
  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1703
1704
12.9M
  void setParameterIndex(unsigned parameterIndex) {
1705
12.9M
    if (parameterIndex >= ParameterIndexSentinel) {
1706
47
      setParameterIndexLarge(parameterIndex);
1707
47
      return;
1708
47
    }
1709
12.9M
1710
12.9M
    ParmVarDeclBits.ParameterIndex = parameterIndex;
1711
12.9M
    assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1712
12.9M
  }
1713
8.21M
  unsigned getParameterIndex() const {
1714
8.21M
    unsigned d = ParmVarDeclBits.ParameterIndex;
1715
8.21M
    return d == ParameterIndexSentinel ? 
getParameterIndexLarge()2
:
d8.21M
;
1716
8.21M
  }
1717
1718
  void setParameterIndexLarge(unsigned parameterIndex);
1719
  unsigned getParameterIndexLarge() const;
1720
};
1721
1722
/// Represents a function declaration or definition.
1723
///
1724
/// Since a given function can be declared several times in a program,
1725
/// there may be several FunctionDecls that correspond to that
1726
/// function. Only one of those FunctionDecls will be found when
1727
/// traversing the list of declarations in the context of the
1728
/// FunctionDecl (e.g., the translation unit); this FunctionDecl
1729
/// contains all of the information known about the function. Other,
1730
/// previous declarations of the function are available via the
1731
/// getPreviousDecl() chain.
1732
class FunctionDecl : public DeclaratorDecl,
1733
                     public DeclContext,
1734
                     public Redeclarable<FunctionDecl> {
1735
  // This class stores some data in DeclContext::FunctionDeclBits
1736
  // to save some space. Use the provided accessors to access it.
1737
public:
1738
  /// The kind of templated function a FunctionDecl can be.
1739
  enum TemplatedKind {
1740
    TK_NonTemplate,
1741
    TK_FunctionTemplate,
1742
    TK_MemberSpecialization,
1743
    TK_FunctionTemplateSpecialization,
1744
    TK_DependentFunctionTemplateSpecialization
1745
  };
1746
1747
private:
1748
  /// A new[]'d array of pointers to VarDecls for the formal
1749
  /// parameters of this function.  This is null if a prototype or if there are
1750
  /// no formals.
1751
  ParmVarDecl **ParamInfo = nullptr;
1752
1753
  LazyDeclStmtPtr Body;
1754
1755
  unsigned ODRHash;
1756
1757
  /// End part of this FunctionDecl's source range.
1758
  ///
1759
  /// We could compute the full range in getSourceRange(). However, when we're
1760
  /// dealing with a function definition deserialized from a PCH/AST file,
1761
  /// we can only compute the full range once the function body has been
1762
  /// de-serialized, so it's far better to have the (sometimes-redundant)
1763
  /// EndRangeLoc.
1764
  SourceLocation EndRangeLoc;
1765
1766
  /// The template or declaration that this declaration
1767
  /// describes or was instantiated from, respectively.
1768
  ///
1769
  /// For non-templates, this value will be NULL. For function
1770
  /// declarations that describe a function template, this will be a
1771
  /// pointer to a FunctionTemplateDecl. For member functions
1772
  /// of class template specializations, this will be a MemberSpecializationInfo
1773
  /// pointer containing information about the specialization.
1774
  /// For function template specializations, this will be a
1775
  /// FunctionTemplateSpecializationInfo, which contains information about
1776
  /// the template being specialized and the template arguments involved in
1777
  /// that specialization.
1778
  llvm::PointerUnion4<FunctionTemplateDecl *,
1779
                      MemberSpecializationInfo *,
1780
                      FunctionTemplateSpecializationInfo *,
1781
                      DependentFunctionTemplateSpecializationInfo *>
1782
    TemplateOrSpecialization;
1783
1784
  /// Provides source/type location info for the declaration name embedded in
1785
  /// the DeclaratorDecl base class.
1786
  DeclarationNameLoc DNLoc;
1787
1788
  /// Specify that this function declaration is actually a function
1789
  /// template specialization.
1790
  ///
1791
  /// \param C the ASTContext.
1792
  ///
1793
  /// \param Template the function template that this function template
1794
  /// specialization specializes.
1795
  ///
1796
  /// \param TemplateArgs the template arguments that produced this
1797
  /// function template specialization from the template.
1798
  ///
1799
  /// \param InsertPos If non-NULL, the position in the function template
1800
  /// specialization set where the function template specialization data will
1801
  /// be inserted.
1802
  ///
1803
  /// \param TSK the kind of template specialization this is.
1804
  ///
1805
  /// \param TemplateArgsAsWritten location info of template arguments.
1806
  ///
1807
  /// \param PointOfInstantiation point at which the function template
1808
  /// specialization was first instantiated.
1809
  void setFunctionTemplateSpecialization(ASTContext &C,
1810
                                         FunctionTemplateDecl *Template,
1811
                                       const TemplateArgumentList *TemplateArgs,
1812
                                         void *InsertPos,
1813
                                         TemplateSpecializationKind TSK,
1814
                          const TemplateArgumentListInfo *TemplateArgsAsWritten,
1815
                                         SourceLocation PointOfInstantiation);
1816
1817
  /// Specify that this record is an instantiation of the
1818
  /// member function FD.
1819
  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1820
                                        TemplateSpecializationKind TSK);
1821
1822
  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1823
1824
  // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
1825
  // need to access this bit but we want to avoid making ASTDeclWriter
1826
  // a friend of FunctionDeclBitfields just for this.
1827
95.5k
  bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
1828
1829
  /// Whether an ODRHash has been stored.
1830
104k
  bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
1831
1832
  /// State that an ODRHash has been stored.
1833
8.42M
  void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
1834
1835
protected:
1836
  FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1837
               const DeclarationNameInfo &NameInfo, QualType T,
1838
               TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
1839
               bool isConstexprSpecified);
1840
1841
  using redeclarable_base = Redeclarable<FunctionDecl>;
1842
1843
2.00M
  FunctionDecl *getNextRedeclarationImpl() override {
1844
2.00M
    return getNextRedeclaration();
1845
2.00M
  }
1846
1847
3.83M
  FunctionDecl *getPreviousDeclImpl() override {
1848
3.83M
    return getPreviousDecl();
1849
3.83M
  }
1850
1851
25.2M
  FunctionDecl *getMostRecentDeclImpl() override {
1852
25.2M
    return getMostRecentDecl();
1853
25.2M
  }
1854
1855
public:
1856
  friend class ASTDeclReader;
1857
  friend class ASTDeclWriter;
1858
1859
  using redecl_range = redeclarable_base::redecl_range;
1860
  using redecl_iterator = redeclarable_base::redecl_iterator;
1861
1862
  using redeclarable_base::redecls_begin;
1863
  using redeclarable_base::redecls_end;
1864
  using redeclarable_base::redecls;
1865
  using redeclarable_base::getPreviousDecl;
1866
  using redeclarable_base::getMostRecentDecl;
1867
  using redeclarable_base::isFirstDecl;
1868
1869
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1870
                              SourceLocation StartLoc, SourceLocation NLoc,
1871
                              DeclarationName N, QualType T,
1872
                              TypeSourceInfo *TInfo,
1873
                              StorageClass SC,
1874
                              bool isInlineSpecified = false,
1875
                              bool hasWrittenPrototype = true,
1876
514k
                              bool isConstexprSpecified = false) {
1877
514k
    DeclarationNameInfo NameInfo(N, NLoc);
1878
514k
    return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
1879
514k
                                SC,
1880
514k
                                isInlineSpecified, hasWrittenPrototype,
1881
514k
                                isConstexprSpecified);
1882
514k
  }
1883
1884
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1885
                              SourceLocation StartLoc,
1886
                              const DeclarationNameInfo &NameInfo,
1887
                              QualType T, TypeSourceInfo *TInfo,
1888
                              StorageClass SC,
1889
                              bool isInlineSpecified,
1890
                              bool hasWrittenPrototype,
1891
                              bool isConstexprSpecified = false);
1892
1893
  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1894
1895
1.74M
  DeclarationNameInfo getNameInfo() const {
1896
1.74M
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
1897
1.74M
  }
1898
1899
  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1900
                            bool Qualified) const override;
1901
1902
7.25M
  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
1903
1904
  SourceRange getSourceRange() const override LLVM_READONLY;
1905
1906
  // Function definitions.
1907
  //
1908
  // A function declaration may be:
1909
  // - a non defining declaration,
1910
  // - a definition. A function may be defined because:
1911
  //   - it has a body, or will have it in the case of late parsing.
1912
  //   - it has an uninstantiated body. The body does not exist because the
1913
  //     function is not used yet, but the declaration is considered a
1914
  //     definition and does not allow other definition of this function.
1915
  //   - it does not have a user specified body, but it does not allow
1916
  //     redefinition, because it is deleted/defaulted or is defined through
1917
  //     some other mechanism (alias, ifunc).
1918
1919
  /// Returns true if the function has a body.
1920
  ///
1921
  /// The function body might be in any of the (re-)declarations of this
1922
  /// function. The variant that accepts a FunctionDecl pointer will set that
1923
  /// function declaration to the actual declaration containing the body (if
1924
  /// there is one).
1925
  bool hasBody(const FunctionDecl *&Definition) const;
1926
1927
887k
  bool hasBody() const override {
1928
887k
    const FunctionDecl* Definition;
1929
887k
    return hasBody(Definition);
1930
887k
  }
1931
1932
  /// Returns whether the function has a trivial body that does not require any
1933
  /// specific codegen.
1934
  bool hasTrivialBody() const;
1935
1936
  /// Returns true if the function has a definition that does not need to be
1937
  /// instantiated.
1938
  ///
1939
  /// The variant that accepts a FunctionDecl pointer will set that function
1940
  /// declaration to the declaration that is a definition (if there is one).
1941
  bool isDefined(const FunctionDecl *&Definition) const;
1942
1943
3.34M
  virtual bool isDefined() const {
1944
3.34M
    const FunctionDecl* Definition;
1945
3.34M
    return isDefined(Definition);
1946
3.34M
  }
1947
1948
  /// Get the definition for this declaration.
1949
4.54M
  FunctionDecl *getDefinition() {
1950
4.54M
    const FunctionDecl *Definition;
1951
4.54M
    if (isDefined(Definition))
1952
4.29M
      return const_cast<FunctionDecl *>(Definition);
1953
245k
    return nullptr;
1954
245k
  }
1955
432k
  const FunctionDecl *getDefinition() const {
1956
432k
    return const_cast<FunctionDecl *>(this)->getDefinition();
1957
432k
  }
1958
1959
  /// Retrieve the body (definition) of the function. The function body might be
1960
  /// in any of the (re-)declarations of this function. The variant that accepts
1961
  /// a FunctionDecl pointer will set that function declaration to the actual
1962
  /// declaration containing the body (if there is one).
1963
  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
1964
  /// unnecessary AST de-serialization of the body.
1965
  Stmt *getBody(const FunctionDecl *&Definition) const;
1966
1967
5.50M
  Stmt *getBody() const override {
1968
5.50M
    const FunctionDecl* Definition;
1969
5.50M
    return getBody(Definition);
1970
5.50M
  }
1971
1972
  /// Returns whether this specific declaration of the function is also a
1973
  /// definition that does not contain uninstantiated body.
1974
  ///
1975
  /// This does not determine whether the function has been defined (e.g., in a
1976
  /// previous definition); for that information, use isDefined.
1977
15.1M
  bool isThisDeclarationADefinition() const {
1978
15.1M
    return isDeletedAsWritten() || 
isDefaulted()15.0M
||
Body14.9M
||
hasSkippedBody()8.34M
||
1979
15.1M
           
isLateTemplateParsed()8.34M
||
willHaveBody()8.34M
||
hasDefiningAttr()8.31M
;
1980
15.1M
  }
1981
1982
  /// Returns whether this specific declaration of the function has a body.
1983
20.0M
  bool doesThisDeclarationHaveABody() const {
1984
20.0M
    return Body || 
isLateTemplateParsed()8.26M
;
1985
20.0M
  }
1986
1987
  void setBody(Stmt *B);
1988
10.3k
  void setLazyBody(uint64_t Offset) { Body = Offset; }
1989
1990
  /// Whether this function is variadic.
1991
  bool isVariadic() const;
1992
1993
  /// Whether this function is marked as virtual explicitly.
1994
11.0M
  bool isVirtualAsWritten() const {
1995
11.0M
    return FunctionDeclBits.IsVirtualAsWritten;
1996
11.0M
  }
1997
1998
  /// State that this function is marked as virtual explicitly.
1999
8.46M
  void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2000
2001
  /// Whether this virtual function is pure, i.e. makes the containing class
2002
  /// abstract.
2003
12.0M
  bool isPure() const { return FunctionDeclBits.IsPure; }
2004
  void setPure(bool P = true);
2005
2006
  /// Whether this templated function will be late parsed.
2007
19.1M
  bool isLateTemplateParsed() const {
2008
19.1M
    return FunctionDeclBits.IsLateTemplateParsed;
2009
19.1M
  }
2010
2011
  /// State that this templated function will be late parsed.
2012
8.32M
  void setLateTemplateParsed(bool ILT = true) {
2013
8.32M
    FunctionDeclBits.IsLateTemplateParsed = ILT;
2014
8.32M
  }
2015
2016
  /// Whether this function is "trivial" in some specialized C++ senses.
2017
  /// Can only be true for default constructors, copy constructors,
2018
  /// copy assignment operators, and destructors.  Not meaningful until
2019
  /// the class has been fully built by Sema.
2020
2.40M
  bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2021
9.14M
  void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2022
2023
797k
  bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2024
8.83M
  void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2025
2026
  /// Whether this function is defaulted per C++0x. Only valid for
2027
  /// special member functions.
2028
36.0M
  bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2029
8.92M
  void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2030
2031
  /// Whether this function is explicitly defaulted per C++0x. Only valid
2032
  /// for special member functions.
2033
5.72M
  bool isExplicitlyDefaulted() const {
2034
5.72M
    return FunctionDeclBits.IsExplicitlyDefaulted;
2035
5.72M
  }
2036
2037
  /// State that this function is explicitly defaulted per C++0x. Only valid
2038
  /// for special member functions.
2039
8.35M
  void setExplicitlyDefaulted(bool ED = true) {
2040
8.35M
    FunctionDeclBits.IsExplicitlyDefaulted = ED;
2041
8.35M
  }
2042
2043
  /// Whether falling off this function implicitly returns null/zero.
2044
  /// If a more specific implicit return value is required, front-ends
2045
  /// should synthesize the appropriate return statements.
2046
3.81M
  bool hasImplicitReturnZero() const {
2047
3.81M
    return FunctionDeclBits.HasImplicitReturnZero;
2048
3.81M
  }
2049
2050
  /// State that falling off this function implicitly returns null/zero.
2051
  /// If a more specific implicit return value is required, front-ends
2052
  /// should synthesize the appropriate return statements.
2053
8.33M
  void setHasImplicitReturnZero(bool IRZ) {
2054
8.33M
    FunctionDeclBits.HasImplicitReturnZero = IRZ;
2055
8.33M
  }
2056
2057
  /// Whether this function has a prototype, either because one
2058
  /// was explicitly written or because it was "inherited" by merging
2059
  /// a declaration without a prototype with a declaration that has a
2060
  /// prototype.
2061
1.35M
  bool hasPrototype() const {
2062
1.35M
    return hasWrittenPrototype() || 
hasInheritedPrototype()119k
;
2063
1.35M
  }
2064
2065
  /// Whether this function has a written prototype.
2066
1.73M
  bool hasWrittenPrototype() const {
2067
1.73M
    return FunctionDeclBits.HasWrittenPrototype;
2068
1.73M
  }
2069
2070
  /// State that this function has a written prototype.
2071
12.7M
  void setHasWrittenPrototype(bool P = true) {
2072
12.7M
    FunctionDeclBits.HasWrittenPrototype = P;
2073
12.7M
  }
2074
2075
  /// Whether this function inherited its prototype from a
2076
  /// previous declaration.
2077
216k
  bool hasInheritedPrototype() const {
2078
216k
    return FunctionDeclBits.HasInheritedPrototype;
2079
216k
  }
2080
2081
  /// State that this function inherited its prototype from a
2082
  /// previous declaration.
2083
8.32M
  void setHasInheritedPrototype(bool P = true) {
2084
8.32M
    FunctionDeclBits.HasInheritedPrototype = P;
2085
8.32M
  }
2086
2087
  /// Whether this is a (C++11) constexpr function or constexpr constructor.
2088
11.2M
  bool isConstexpr() const { return FunctionDeclBits.IsConstexpr; }
2089
8.35M
  void setConstexpr(bool IC) { FunctionDeclBits.IsConstexpr = IC; }
2090
2091
  /// Whether the instantiation of this function is pending.
2092
  /// This bit is set when the decision to instantiate this function is made
2093
  /// and unset if and when the function body is created. That leaves out
2094
  /// cases where instantiation did not happen because the template definition
2095
  /// was not seen in this TU. This bit remains set in those cases, under the
2096
  /// assumption that the instantiation will happen in some other TU.
2097
0
  bool instantiationIsPending() const {
2098
0
    return FunctionDeclBits.InstantiationIsPending;
2099
0
  }
2100
2101
  /// State that the instantiation of this function is pending.
2102
  /// (see instantiationIsPending)
2103
8.85M
  void setInstantiationIsPending(bool IC) {
2104
8.85M
    FunctionDeclBits.InstantiationIsPending = IC;
2105
8.85M
  }
2106
2107
  /// Indicates the function uses __try.
2108
543k
  bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2109
8.32M
  void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2110
2111
  /// Whether this function has been deleted.
2112
  ///
2113
  /// A function that is "deleted" (via the C++0x "= delete" syntax)
2114
  /// acts like a normal function, except that it cannot actually be
2115
  /// called or have its address taken. Deleted functions are
2116
  /// typically used in C++ overload resolution to attract arguments
2117
  /// whose type or lvalue/rvalue-ness would permit the use of a
2118
  /// different overload that would behave incorrectly. For example,
2119
  /// one might use deleted functions to ban implicit conversion from
2120
  /// a floating-point number to an Integer type:
2121
  ///
2122
  /// @code
2123
  /// struct Integer {
2124
  ///   Integer(long); // construct from a long
2125
  ///   Integer(double) = delete; // no construction from float or double
2126
  ///   Integer(long double) = delete; // no construction from long double
2127
  /// };
2128
  /// @endcode
2129
  // If a function is deleted, its first declaration must be.
2130
23.2M
  bool isDeleted() const {
2131
23.2M
    return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2132
23.2M
  }
2133
2134
16.6M
  bool isDeletedAsWritten() const {
2135
16.6M
    return FunctionDeclBits.IsDeleted && 
!isDefaulted()103k
;
2136
16.6M
  }
2137
2138
8.41M
  void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
2139
2140
  /// Determines whether this function is "main", which is the
2141
  /// entry point into an executable program.
2142
  bool isMain() const;
2143
2144
  /// Determines whether this function is a MSVCRT user defined entry
2145
  /// point.
2146
  bool isMSVCRTEntryPoint() const;
2147
2148
  /// Determines whether this operator new or delete is one
2149
  /// of the reserved global placement operators:
2150
  ///    void *operator new(size_t, void *);
2151
  ///    void *operator new[](size_t, void *);
2152
  ///    void operator delete(void *, void *);
2153
  ///    void operator delete[](void *, void *);
2154
  /// These functions have special behavior under [new.delete.placement]:
2155
  ///    These functions are reserved, a C++ program may not define
2156
  ///    functions that displace the versions in the Standard C++ library.
2157
  ///    The provisions of [basic.stc.dynamic] do not apply to these
2158
  ///    reserved placement forms of operator new and operator delete.
2159
  ///
2160
  /// This function must be an allocation or deallocation function.
2161
  bool isReservedGlobalPlacementOperator() const;
2162
2163
  /// Determines whether this function is one of the replaceable
2164
  /// global allocation functions:
2165
  ///    void *operator new(size_t);
2166
  ///    void *operator new(size_t, const std::nothrow_t &) noexcept;
2167
  ///    void *operator new[](size_t);
2168
  ///    void *operator new[](size_t, const std::nothrow_t &) noexcept;
2169
  ///    void operator delete(void *) noexcept;
2170
  ///    void operator delete(void *, std::size_t) noexcept;      [C++1y]
2171
  ///    void operator delete(void *, const std::nothrow_t &) noexcept;
2172
  ///    void operator delete[](void *) noexcept;
2173
  ///    void operator delete[](void *, std::size_t) noexcept;    [C++1y]
2174
  ///    void operator delete[](void *, const std::nothrow_t &) noexcept;
2175
  /// These functions have special behavior under C++1y [expr.new]:
2176
  ///    An implementation is allowed to omit a call to a replaceable global
2177
  ///    allocation function. [...]
2178
  ///
2179
  /// If this function is an aligned allocation/deallocation function, return
2180
  /// true through IsAligned.
2181
  bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
2182
2183
  /// Determine whether this is a destroying operator delete.
2184
  bool isDestroyingOperatorDelete() const;
2185
2186
  /// Compute the language linkage.
2187
  LanguageLinkage getLanguageLinkage() const;
2188
2189
  /// Determines whether this function is a function with
2190
  /// external, C linkage.
2191
  bool isExternC() const;
2192
2193
  /// Determines whether this function's context is, or is nested within,
2194
  /// a C++ extern "C" linkage spec.
2195
  bool isInExternCContext() const;
2196
2197
  /// Determines whether this function's context is, or is nested within,
2198
  /// a C++ extern "C++" linkage spec.
2199
  bool isInExternCXXContext() const;
2200
2201
  /// Determines whether this is a global function.
2202
  bool isGlobal() const;
2203
2204
  /// Determines whether this function is known to be 'noreturn', through
2205
  /// an attribute on its declaration or its type.
2206
  bool isNoReturn() const;
2207
2208
  /// True if the function was a definition but its body was skipped.
2209
11.8M
  bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2210
8.32M
  void setHasSkippedBody(bool Skipped = true) {
2211
8.32M
    FunctionDeclBits.HasSkippedBody = Skipped;
2212
8.32M
  }
2213
2214
  /// True if this function will eventually have a body, once it's fully parsed.
2215
11.8M
  bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2216
15.8M
  void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2217
2218
  /// True if this function is considered a multiversioned function.
2219
27.8M
  bool isMultiVersion() const {
2220
27.8M
    return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2221
27.8M
  }
2222
2223
  /// Sets the multiversion state for this declaration and all of its
2224
  /// redeclarations.
2225
8.32M
  void setIsMultiVersion(bool V = true) {
2226
8.32M
    getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2227
8.32M
  }
2228
2229
  /// True if this function is a multiversioned dispatch function as a part of
2230
  /// the cpu_specific/cpu_dispatch functionality.
2231
  bool isCPUDispatchMultiVersion() const;
2232
  /// True if this function is a multiversioned processor specific function as a
2233
  /// part of the cpu_specific/cpu_dispatch functionality.
2234
  bool isCPUSpecificMultiVersion() const;
2235
2236
  /// True if this function is a multiversioned dispatch function as a part of
2237
  /// the target functionality.
2238
  bool isTargetMultiVersion() const;
2239
2240
  void setPreviousDeclaration(FunctionDecl * PrevDecl);
2241
2242
  FunctionDecl *getCanonicalDecl() override;
2243
68.7M
  const FunctionDecl *getCanonicalDecl() const {
2244
68.7M
    return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2245
68.7M
  }
2246
2247
  unsigned getBuiltinID() const;
2248
2249
  // ArrayRef interface to parameters.
2250
22.9M
  ArrayRef<ParmVarDecl *> parameters() const {
2251
22.9M
    return {ParamInfo, getNumParams()};
2252
22.9M
  }
2253
18.6M
  MutableArrayRef<ParmVarDecl *> parameters() {
2254
18.6M
    return {ParamInfo, getNumParams()};
2255
18.6M
  }
2256
2257
  // Iterator access to formal parameters.
2258
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
2259
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
2260
2261
0
  bool param_empty() const { return parameters().empty(); }
2262
965
  param_iterator param_begin() { return parameters().begin(); }
2263
0
  param_iterator param_end() { return parameters().end(); }
2264
978k
  param_const_iterator param_begin() const { return parameters().begin(); }
2265
531k
  param_const_iterator param_end() const { return parameters().end(); }
2266
199k
  size_t param_size() const { return parameters().size(); }
2267
2268
  /// Return the number of parameters this function must have based on its
2269
  /// FunctionType.  This is the length of the ParamInfo array after it has been
2270
  /// created.
2271
  unsigned getNumParams() const;
2272
2273
23.1M
  const ParmVarDecl *getParamDecl(unsigned i) const {
2274
23.1M
    assert(i < getNumParams() && "Illegal param #");
2275
23.1M
    return ParamInfo[i];
2276
23.1M
  }
2277
18.0M
  ParmVarDecl *getParamDecl(unsigned i) {
2278
18.0M
    assert(i < getNumParams() && "Illegal param #");
2279
18.0M
    return ParamInfo[i];
2280
18.0M
  }
2281
8.09M
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2282
8.09M
    setParams(getASTContext(), NewParamInfo);
2283
8.09M
  }
2284
2285
  /// Returns the minimum number of arguments needed to call this function. This
2286
  /// may be fewer than the number of function parameters, if some of the
2287
  /// parameters have default arguments (in C++).
2288
  unsigned getMinRequiredArguments() const;
2289
2290
23.6M
  QualType getReturnType() const {
2291
23.6M
    return getType()->castAs<FunctionType>()->getReturnType();
2292
23.6M
  }
2293
2294
  /// Attempt to compute an informative source range covering the
2295
  /// function return type. This may omit qualifiers and other information with
2296
  /// limited representation in the AST.
2297
  SourceRange getReturnTypeSourceRange() const;
2298
2299
  /// Get the declared return type, which may differ from the actual return
2300
  /// type if the return type is deduced.
2301
795k
  QualType getDeclaredReturnType() const {
2302
795k
    auto *TSI = getTypeSourceInfo();
2303
795k
    QualType T = TSI ? 
TSI->getType()793k
:
getType()2.21k
;
2304
795k
    return T->castAs<FunctionType>()->getReturnType();
2305
795k
  }
2306
2307
  /// Attempt to compute an informative source range covering the
2308
  /// function exception specification, if any.
2309
  SourceRange getExceptionSpecSourceRange() const;
2310
2311
  /// Determine the type of an expression that calls this function.
2312
4.26k
  QualType getCallResultType() const {
2313
4.26k
    return getType()->castAs<FunctionType>()->getCallResultType(
2314
4.26k
        getASTContext());
2315
4.26k
  }
2316
2317
  /// Returns the WarnUnusedResultAttr that is either declared on this
2318
  /// function, or its return type declaration.
2319
  const Attr *getUnusedResultAttr() const;
2320
2321
  /// Returns true if this function or its return type has the
2322
  /// warn_unused_result attribute.
2323
781k
  bool hasUnusedResultAttr() const { return getUnusedResultAttr() != nullptr; }
2324
2325
  /// Returns the storage class as written in the source. For the
2326
  /// computed linkage of symbol, see getLinkage.
2327
41.4M
  StorageClass getStorageClass() const {
2328
41.4M
    return static_cast<StorageClass>(FunctionDeclBits.SClass);
2329
41.4M
  }
2330
2331
  /// Sets the storage class as written in the source.
2332
8.32M
  void setStorageClass(StorageClass SClass) {
2333
8.32M
    FunctionDeclBits.SClass = SClass;
2334
8.32M
  }
2335
2336
  /// Determine whether the "inline" keyword was specified for this
2337
  /// function.
2338
3.36M
  bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2339
2340
  /// Set whether the "inline" keyword was specified for this function.
2341
8.33M
  void setInlineSpecified(bool I) {
2342
8.33M
    FunctionDeclBits.IsInlineSpecified = I;
2343
8.33M
    FunctionDeclBits.IsInline = I;
2344
8.33M
  }
2345
2346
  /// Flag that this function is implicitly inline.
2347
2.71M
  void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2348
2349
  /// Determine whether this function should be inlined, because it is
2350
  /// either marked "inline" or "constexpr" or is a member function of a class
2351
  /// that was defined in the class body.
2352
22.4M
  bool isInlined() const { return FunctionDeclBits.IsInline; }
2353
2354
  /// Whether this function is marked as explicit explicitly.
2355
6.15M
  bool isExplicitSpecified() const {
2356
6.15M
    return FunctionDeclBits.IsExplicitSpecified;
2357
6.15M
  }
2358
2359
  /// State that this function is marked as explicit explicitly.
2360
9.23M
  void setExplicitSpecified(bool ExpSpec = true) {
2361
9.23M
    FunctionDeclBits.IsExplicitSpecified = ExpSpec;
2362
9.23M
  }
2363
2364
  bool isInlineDefinitionExternallyVisible() const;
2365
2366
  bool isMSExternInline() const;
2367
2368
  bool doesDeclarationForceExternallyVisibleDefinition() const;
2369
2370
  /// Whether this function declaration represents an C++ overloaded
2371
  /// operator, e.g., "operator+".
2372
10.1M
  bool isOverloadedOperator() const {
2373
10.1M
    return getOverloadedOperator() != OO_None;
2374
10.1M
  }
2375
2376
  OverloadedOperatorKind getOverloadedOperator() const;
2377
2378
  const IdentifierInfo *getLiteralIdentifier() const;
2379
2380
  /// If this function is an instantiation of a member function
2381
  /// of a class template specialization, retrieves the function from
2382
  /// which it was instantiated.
2383
  ///
2384
  /// This routine will return non-NULL for (non-templated) member
2385
  /// functions of class templates and for instantiations of function
2386
  /// templates. For example, given:
2387
  ///
2388
  /// \code
2389
  /// template<typename T>
2390
  /// struct X {
2391
  ///   void f(T);
2392
  /// };
2393
  /// \endcode
2394
  ///
2395
  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2396
  /// whose parent is the class template specialization X<int>. For
2397
  /// this declaration, getInstantiatedFromFunction() will return
2398
  /// the FunctionDecl X<T>::A. When a complete definition of
2399
  /// X<int>::A is required, it will be instantiated from the
2400
  /// declaration returned by getInstantiatedFromMemberFunction().
2401
  FunctionDecl *getInstantiatedFromMemberFunction() const;
2402
2403
  /// What kind of templated function this is.
2404
  TemplatedKind getTemplatedKind() const;
2405
2406
  /// If this function is an instantiation of a member function of a
2407
  /// class template specialization, retrieves the member specialization
2408
  /// information.
2409
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
2410
2411
  /// Specify that this record is an instantiation of the
2412
  /// member function FD.
2413
  void setInstantiationOfMemberFunction(FunctionDecl *FD,
2414
1.14M
                                        TemplateSpecializationKind TSK) {
2415
1.14M
    setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2416
1.14M
  }
2417
2418
  /// Retrieves the function template that is described by this
2419
  /// function declaration.
2420
  ///
2421
  /// Every function template is represented as a FunctionTemplateDecl
2422
  /// and a FunctionDecl (or something derived from FunctionDecl). The
2423
  /// former contains template properties (such as the template
2424
  /// parameter lists) while the latter contains the actual
2425
  /// description of the template's
2426
  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2427
  /// FunctionDecl that describes the function template,
2428
  /// getDescribedFunctionTemplate() retrieves the
2429
  /// FunctionTemplateDecl from a FunctionDecl.
2430
  FunctionTemplateDecl *getDescribedFunctionTemplate() const;
2431
2432
  void setDescribedFunctionTemplate(FunctionTemplateDecl *Template);
2433
2434
  /// Determine whether this function is a function template
2435
  /// specialization.
2436
17.8M
  bool isFunctionTemplateSpecialization() const {
2437
17.8M
    return getPrimaryTemplate() != nullptr;
2438
17.8M
  }
2439
2440
  /// Retrieve the class scope template pattern that this function
2441
  ///  template specialization is instantiated from.
2442
  FunctionDecl *getClassScopeSpecializationPattern() const;
2443
2444
  /// If this function is actually a function template specialization,
2445
  /// retrieve information about this function template specialization.
2446
  /// Otherwise, returns NULL.
2447
  FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const;
2448
2449
  /// Determines whether this function is a function template
2450
  /// specialization or a member of a class template specialization that can
2451
  /// be implicitly instantiated.
2452
  bool isImplicitlyInstantiable() const;
2453
2454
  /// Determines if the given function was instantiated from a
2455
  /// function template.
2456
  bool isTemplateInstantiation() const;
2457
2458
  /// Retrieve the function declaration from which this function could
2459
  /// be instantiated, if it is an instantiation (rather than a non-template
2460
  /// or a specialization, for example).
2461
  FunctionDecl *getTemplateInstantiationPattern() const;
2462
2463
  /// Retrieve the primary template that this function template
2464
  /// specialization either specializes or was instantiated from.
2465
  ///
2466
  /// If this function declaration is not a function template specialization,
2467
  /// returns NULL.
2468
  FunctionTemplateDecl *getPrimaryTemplate() const;
2469
2470
  /// Retrieve the template arguments used to produce this function
2471
  /// template specialization from the primary template.
2472
  ///
2473
  /// If this function declaration is not a function template specialization,
2474
  /// returns NULL.
2475
  const TemplateArgumentList *getTemplateSpecializationArgs() const;
2476
2477
  /// Retrieve the template argument list as written in the sources,
2478
  /// if any.
2479
  ///
2480
  /// If this function declaration is not a function template specialization
2481
  /// or if it had no explicit template argument list, returns NULL.
2482
  /// Note that it an explicit template argument list may be written empty,
2483
  /// e.g., template<> void foo<>(char* s);
2484
  const ASTTemplateArgumentListInfo*
2485
  getTemplateSpecializationArgsAsWritten() const;
2486
2487
  /// Specify that this function declaration is actually a function
2488
  /// template specialization.
2489
  ///
2490
  /// \param Template the function template that this function template
2491
  /// specialization specializes.
2492
  ///
2493
  /// \param TemplateArgs the template arguments that produced this
2494
  /// function template specialization from the template.
2495
  ///
2496
  /// \param InsertPos If non-NULL, the position in the function template
2497
  /// specialization set where the function template specialization data will
2498
  /// be inserted.
2499
  ///
2500
  /// \param TSK the kind of template specialization this is.
2501
  ///
2502
  /// \param TemplateArgsAsWritten location info of template arguments.
2503
  ///
2504
  /// \param PointOfInstantiation point at which the function template
2505
  /// specialization was first instantiated.
2506
  void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
2507
                const TemplateArgumentList *TemplateArgs,
2508
                void *InsertPos,
2509
                TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
2510
                const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2511
272k
                SourceLocation PointOfInstantiation = SourceLocation()) {
2512
272k
    setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2513
272k
                                      InsertPos, TSK, TemplateArgsAsWritten,
2514
272k
                                      PointOfInstantiation);
2515
272k
  }
2516
2517
  /// Specifies that this function declaration is actually a
2518
  /// dependent function template specialization.
2519
  void setDependentTemplateSpecialization(ASTContext &Context,
2520
                             const UnresolvedSetImpl &Templates,
2521
                      const TemplateArgumentListInfo &TemplateArgs);
2522
2523
  DependentFunctionTemplateSpecializationInfo *
2524
  getDependentSpecializationInfo() const;
2525
2526
  /// Determine what kind of template instantiation this function
2527
  /// represents.
2528
  TemplateSpecializationKind getTemplateSpecializationKind() const;
2529
2530
  /// Determine what kind of template instantiation this function
2531
  /// represents.
2532
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
2533
                        SourceLocation PointOfInstantiation = SourceLocation());
2534
2535
  /// Retrieve the (first) point of instantiation of a function template
2536
  /// specialization or a member of a class template specialization.
2537
  ///
2538
  /// \returns the first point of instantiation, if this function was
2539
  /// instantiated from a template; otherwise, returns an invalid source
2540
  /// location.
2541
  SourceLocation getPointOfInstantiation() const;
2542
2543
  /// Determine whether this is or was instantiated from an out-of-line
2544
  /// definition of a member function.
2545
  bool isOutOfLine() const override;
2546
2547
  /// Identify a memory copying or setting function.
2548
  /// If the given function is a memory copy or setting function, returns
2549
  /// the corresponding Builtin ID. If the function is not a memory function,
2550
  /// returns 0.
2551
  unsigned getMemoryFunctionKind() const;
2552
2553
  /// Returns ODRHash of the function.  This value is calculated and
2554
  /// stored on first call, then the stored value returned on the other calls.
2555
  unsigned getODRHash();
2556
2557
  /// Returns cached ODRHash of the function.  This must have been previously
2558
  /// computed and stored.
2559
  unsigned getODRHash() const;
2560
2561
  // Implement isa/cast/dyncast/etc.
2562
389M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2563
562M
  static bool classofKind(Kind K) {
2564
562M
    return K >= firstFunction && 
K <= lastFunction329M
;
2565
562M
  }
2566
0
  static DeclContext *castToDeclContext(const FunctionDecl *D) {
2567
0
    return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2568
0
  }
2569
0
  static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
2570
0
    return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2571
0
  }
2572
};
2573
2574
/// Represents a member of a struct/union/class.
2575
class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2576
  unsigned BitField : 1;
2577
  unsigned Mutable : 1;
2578
  mutable unsigned CachedFieldIndex : 30;
2579
2580
  /// The kinds of value we can store in InitializerOrBitWidth.
2581
  ///
2582
  /// Note that this is compatible with InClassInitStyle except for
2583
  /// ISK_CapturedVLAType.
2584
  enum InitStorageKind {
2585
    /// If the pointer is null, there's nothing special.  Otherwise,
2586
    /// this is a bitfield and the pointer is the Expr* storing the
2587
    /// bit-width.
2588
    ISK_NoInit = (unsigned) ICIS_NoInit,
2589
2590
    /// The pointer is an (optional due to delayed parsing) Expr*
2591
    /// holding the copy-initializer.
2592
    ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2593
2594
    /// The pointer is an (optional due to delayed parsing) Expr*
2595
    /// holding the list-initializer.
2596
    ISK_InClassListInit = (unsigned) ICIS_ListInit,
2597
2598
    /// The pointer is a VariableArrayType* that's been captured;
2599
    /// the enclosing context is a lambda or captured statement.
2600
    ISK_CapturedVLAType,
2601
  };
2602
2603
  /// If this is a bitfield with a default member initializer, this
2604
  /// structure is used to represent the two expressions.
2605
  struct InitAndBitWidth {
2606
    Expr *Init;
2607
    Expr *BitWidth;
2608
  };
2609
2610
  /// Storage for either the bit-width, the in-class initializer, or
2611
  /// both (via InitAndBitWidth), or the captured variable length array bound.
2612
  ///
2613
  /// If the storage kind is ISK_InClassCopyInit or
2614
  /// ISK_InClassListInit, but the initializer is null, then this
2615
  /// field has an in-class initializer that has not yet been parsed
2616
  /// and attached.
2617
  // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
2618
  // overwhelmingly common case that we have none of these things.
2619
  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2620
2621
protected:
2622
  FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
2623
            SourceLocation IdLoc, IdentifierInfo *Id,
2624
            QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2625
            InClassInitStyle InitStyle)
2626
    : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2627
      BitField(false), Mutable(Mutable), CachedFieldIndex(0),
2628
2.86M
      InitStorage(nullptr, (InitStorageKind) InitStyle) {
2629
2.86M
    if (BW)
2630
37.7k
      setBitWidth(BW);
2631
2.86M
  }
2632
2633
public:
2634
  friend class ASTDeclReader;
2635
  friend class ASTDeclWriter;
2636
2637
  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2638
                           SourceLocation StartLoc, SourceLocation IdLoc,
2639
                           IdentifierInfo *Id, QualType T,
2640
                           TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2641
                           InClassInitStyle InitStyle);
2642
2643
  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2644
2645
  /// Returns the index of this field within its record,
2646
  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2647
  unsigned getFieldIndex() const;
2648
2649
  /// Determines whether this field is mutable (C++ only).
2650
6.43M
  bool isMutable() const { return Mutable; }
2651
2652
  /// Determines whether this field is a bitfield.
2653
9.78M
  bool isBitField() const { return BitField; }
2654
2655
  /// Determines whether this is an unnamed bitfield.
2656
4.52M
  bool isUnnamedBitfield() const { return isBitField() && 
!getDeclName()39.5k
; }
2657
2658
  /// Determines whether this field is a
2659
  /// representative for an anonymous struct or union. Such fields are
2660
  /// unnamed and are implicitly generated by the implementation to
2661
  /// store the data for the anonymous union or struct.
2662
  bool isAnonymousStructOrUnion() const;
2663
2664
228k
  Expr *getBitWidth() const {
2665
228k
    if (!BitField)
2666
171k
      return nullptr;
2667
56.6k
    void *Ptr = InitStorage.getPointer();
2668
56.6k
    if (getInClassInitStyle())
2669
76
      return static_cast<InitAndBitWidth*>(Ptr)->BitWidth;
2670
56.5k
    return static_cast<Expr*>(Ptr);
2671
56.5k
  }
2672
2673
  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2674
2675
  /// Set the bit-field width for this member.
2676
  // Note: used by some clients (i.e., do not remove it).
2677
37.9k
  void setBitWidth(Expr *Width) {
2678
37.9k
    assert(!hasCapturedVLAType() && !BitField &&
2679
37.9k
           "bit width or captured type already set");
2680
37.9k
    assert(Width && "no bit width specified");
2681
37.9k
    InitStorage.setPointer(
2682
37.9k
        InitStorage.getInt()
2683
37.9k
            ? new (getASTContext())
2684
9
                  InitAndBitWidth{getInClassInitializer(), Width}
2685
37.9k
            : 
static_cast<void*>(Width)37.9k
);
2686
37.9k
    BitField = true;
2687
37.9k
  }
2688
2689
  /// Remove the bit-field width from this member.
2690
  // Note: used by some clients (i.e., do not remove it).
2691
0
  void removeBitWidth() {
2692
0
    assert(isBitField() && "no bitfield width to remove");
2693
0
    InitStorage.setPointer(getInClassInitializer());
2694
0
    BitField = false;
2695
0
  }
2696
2697
  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
2698
  /// at all and instead act as a separator between contiguous runs of other
2699
  /// bit-fields.
2700
  bool isZeroLengthBitField(const ASTContext &Ctx) const;
2701
2702
  /// Get the kind of (C++11) default member initializer that this field has.
2703
6.59M
  InClassInitStyle getInClassInitStyle() const {
2704
6.59M
    InitStorageKind storageKind = InitStorage.getInt();
2705
6.59M
    return (storageKind == ISK_CapturedVLAType
2706
6.59M
              ? 
ICIS_NoInit16.6k
:
(InClassInitStyle) storageKind6.58M
);
2707
6.59M
  }
2708
2709
  /// Determine whether this member has a C++11 default member initializer.
2710
6.40M
  bool hasInClassInitializer() const {
2711
6.40M
    return getInClassInitStyle() != ICIS_NoInit;
2712
6.40M
  }
2713
2714
  /// Get the C++11 default member initializer for this member, or null if one
2715
  /// has not been set. If a valid declaration has a default member initializer,
2716
  /// but this returns null, then we have not parsed and attached it yet.
2717
23.3k
  Expr *getInClassInitializer() const {
2718
23.3k
    if (!hasInClassInitializer())
2719
8.83k
      return nullptr;
2720
14.5k
    void *Ptr = InitStorage.getPointer();
2721
14.5k
    if (BitField)
2722
99
      return static_cast<InitAndBitWidth*>(Ptr)->Init;
2723
14.4k
    return static_cast<Expr*>(Ptr);
2724
14.4k
  }
2725
2726
  /// Set the C++11 in-class initializer for this member.
2727
5.43k
  void setInClassInitializer(Expr *Init) {
2728
5.43k
    assert(hasInClassInitializer() && !getInClassInitializer());
2729
5.43k
    if (BitField)
2730
8
      static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init;
2731
5.42k
    else
2732
5.42k
      InitStorage.setPointer(Init);
2733
5.43k
  }
2734
2735
  /// Remove the C++11 in-class initializer from this member.
2736
39
  void removeInClassInitializer() {
2737
39
    assert(hasInClassInitializer() && "no initializer to remove");
2738
39
    InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit);
2739
39
  }
2740
2741
  /// Determine whether this member captures the variable length array
2742
  /// type.
2743
126k
  bool hasCapturedVLAType() const {
2744
126k
    return InitStorage.getInt() == ISK_CapturedVLAType;
2745
126k
  }
2746
2747
  /// Get the captured variable length array type.
2748
24.6k
  const VariableArrayType *getCapturedVLAType() const {
2749
24.6k
    return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
2750
24.6k
                                      InitStorage.getPointer())
2751
24.6k
                                : 
nullptr0
;
2752
24.6k
  }
2753
2754
  /// Set the captured variable length array type for this field.
2755
  void setCapturedVLAType(const VariableArrayType *VLAType);
2756
2757
  /// Returns the parent of this field declaration, which
2758
  /// is the struct in which this field is defined.
2759
2.30M
  const RecordDecl *getParent() const {
2760
2.30M
    return cast<RecordDecl>(getDeclContext());
2761
2.30M
  }
2762
2763
908k
  RecordDecl *getParent() {
2764
908k
    return cast<RecordDecl>(getDeclContext());
2765
908k
  }
2766
2767
  SourceRange getSourceRange() const override LLVM_READONLY;
2768
2769
  /// Retrieves the canonical declaration of this field.
2770
5.50M
  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2771
3.13M
  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2772
2773
  // Implement isa/cast/dyncast/etc.
2774
119M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2775
119M
  static bool classofKind(Kind K) { return K >= firstField && 
K <= lastField92.2M
; }
2776
};
2777
2778
/// An instance of this object exists for each enum constant
2779
/// that is defined.  For example, in "enum X {a,b}", each of a/b are
2780
/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
2781
/// TagType for the X EnumDecl.
2782
class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
2783
  Stmt *Init; // an integer constant expression
2784
  llvm::APSInt Val; // The value.
2785
2786
protected:
2787
  EnumConstantDecl(DeclContext *DC, SourceLocation L,
2788
                   IdentifierInfo *Id, QualType T, Expr *E,
2789
                   const llvm::APSInt &V)
2790
358k
    : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
2791
2792
public:
2793
  friend class StmtIteratorBase;
2794
2795
  static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
2796
                                  SourceLocation L, IdentifierInfo *Id,
2797
                                  QualType T, Expr *E,
2798
                                  const llvm::APSInt &V);
2799
  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2800
2801
1.58k
  const Expr *getInitExpr() const { return (const Expr*) Init; }
2802
483k
  Expr *getInitExpr() { return (Expr*) Init; }
2803
3.07M
  const llvm::APSInt &getInitVal() const { return Val; }
2804
2805
62.5k
  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
2806
288k
  void setInitVal(const llvm::APSInt &V) { Val = V; }
2807
2808
  SourceRange getSourceRange() const override LLVM_READONLY;
2809
2810
  /// Retrieves the canonical declaration of this enumerator.
2811
645k
  EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); }
2812
0
  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
2813
2814
  // Implement isa/cast/dyncast/etc.
2815
50.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2816
50.3M
  static bool classofKind(Kind K) { return K == EnumConstant; }
2817
};
2818
2819
/// Represents a field injected from an anonymous union/struct into the parent
2820
/// scope. These are always implicit.
2821
class IndirectFieldDecl : public ValueDecl,
2822
                          public Mergeable<IndirectFieldDecl> {
2823
  NamedDecl **Chaining;
2824
  unsigned ChainingSize;
2825
2826
  IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
2827
                    DeclarationName N, QualType T,
2828
                    MutableArrayRef<NamedDecl *> CH);
2829
2830
  void anchor() override;
2831
2832
public:
2833
  friend class ASTDeclReader;
2834
2835
  static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
2836
                                   SourceLocation L, IdentifierInfo *Id,
2837
                                   QualType T, llvm::MutableArrayRef<NamedDecl *> CH);
2838
2839
  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2840
2841
  using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;
2842
2843
90.4k
  ArrayRef<NamedDecl *> chain() const {
2844
90.4k
    return llvm::makeArrayRef(Chaining, ChainingSize);
2845
90.4k
  }
2846
12.4k
  chain_iterator chain_begin() const { return chain().begin(); }
2847
12.3k
  chain_iterator chain_end() const { return chain().end(); }
2848
2849
7.41k
  unsigned getChainingSize() const { return ChainingSize; }
2850
2851
34.2k
  FieldDecl *getAnonField() const {
2852
34.2k
    assert(chain().size() >= 2);
2853
34.2k
    return cast<FieldDecl>(chain().back());
2854
34.2k
  }
2855
2856
12.0k
  VarDecl *getVarDecl() const {
2857
12.0k
    assert(chain().size() >= 2);
2858
12.0k
    return dyn_cast<VarDecl>(chain().front());
2859
12.0k
  }
2860
2861
22.2k
  IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2862
0
  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2863
2864
  // Implement isa/cast/dyncast/etc.
2865
62.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2866
62.8M
  static bool classofKind(Kind K) { return K == IndirectField; }
2867
};
2868
2869
/// Represents a declaration of a type.
2870
class TypeDecl : public NamedDecl {
2871
  friend class ASTContext;
2872
2873
  /// This indicates the Type object that represents
2874
  /// this TypeDecl.  It is a cache maintained by
2875
  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
2876
  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
2877
  mutable const Type *TypeForDecl = nullptr;
2878
2879
  /// The start of the source range for this declaration.
2880
  SourceLocation LocStart;
2881
2882
  void anchor() override;
2883
2884
protected:
2885
  TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2886
           SourceLocation StartL = SourceLocation())
2887
9.13M
    : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
2888
2889
public:
2890
  // Low-level accessor. If you just want the type defined by this node,
2891
  // check out ASTContext::getTypeDeclType or one of
2892
  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
2893
  // already know the specific kind of node this is.
2894
33.7M
  const Type *getTypeForDecl() const { return TypeForDecl; }
2895
2.41M
  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
2896
2897
5.33M
  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
2898
1.02M
  void setLocStart(SourceLocation L) { LocStart = L; }
2899
1.98k
  SourceRange getSourceRange() const override LLVM_READONLY {
2900
1.98k
    if (LocStart.isValid())
2901
1.98k
      return SourceRange(LocStart, getLocation());
2902
0
    else
2903
0
      return SourceRange(getLocation());
2904
1.98k
  }
2905
2906
  // Implement isa/cast/dyncast/etc.
2907
91.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2908
91.6M
  static bool classofKind(Kind K) { return K >= firstType && 
K <= lastType55.6M
; }
2909
};
2910
2911
/// Base class for declarations which introduce a typedef-name.
2912
class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
2913
  struct alignas(8) ModedTInfo {
2914
    TypeSourceInfo *first;
2915
    QualType second;
2916
  };
2917
2918
  /// If int part is 0, we have not computed IsTransparentTag.
2919
  /// Otherwise, IsTransparentTag is (getInt() >> 1).
2920
  mutable llvm::PointerIntPair<
2921
      llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
2922
      MaybeModedTInfo;
2923
2924
  void anchor() override;
2925
2926
protected:
2927
  TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
2928
                  SourceLocation StartLoc, SourceLocation IdLoc,
2929
                  IdentifierInfo *Id, TypeSourceInfo *TInfo)
2930
      : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
2931
2.41M
        MaybeModedTInfo(TInfo, 0) {}
2932
2933
  using redeclarable_base = Redeclarable<TypedefNameDecl>;
2934
2935
310k
  TypedefNameDecl *getNextRedeclarationImpl() override {
2936
310k
    return getNextRedeclaration();
2937
310k
  }
2938
2939
12.5k
  TypedefNameDecl *getPreviousDeclImpl() override {
2940
12.5k
    return getPreviousDecl();
2941
12.5k
  }
2942
2943
632k
  TypedefNameDecl *getMostRecentDeclImpl() override {
2944
632k
    return getMostRecentDecl();
2945
632k
  }
2946
2947
public:
2948
  using redecl_range = redeclarable_base::redecl_range;
2949
  using redecl_iterator = redeclarable_base::redecl_iterator;
2950
2951
  using redeclarable_base::redecls_begin;
2952
  using redeclarable_base::redecls_end;
2953
  using redeclarable_base::redecls;
2954
  using redeclarable_base::getPreviousDecl;
2955
  using redeclarable_base::getMostRecentDecl;
2956
  using redeclarable_base::isFirstDecl;
2957
2958
52.5M
  bool isModed() const {
2959
52.5M
    return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
2960
52.5M
  }
2961
2962
2.28M
  TypeSourceInfo *getTypeSourceInfo() const {
2963
2.28M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first2.29k
2964
2.28M
                     : 
MaybeModedTInfo.getPointer().get<TypeSourceInfo *>()2.28M
;
2965
2.28M
  }
2966
2967
50.2M
  QualType getUnderlyingType() const {
2968
50.2M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second26.1k
2969
50.2M
                     : MaybeModedTInfo.getPointer()
2970
50.2M
                           .get<TypeSourceInfo *>()
2971
50.2M
                           ->getType();
2972
50.2M
  }
2973
2974
7.83k
  void setTypeSourceInfo(TypeSourceInfo *newType) {
2975
7.83k
    MaybeModedTInfo.setPointer(newType);
2976
7.83k
  }
2977
2978
2.32k
  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
2979
2.32k
    MaybeModedTInfo.setPointer(new (getASTContext(), 8)
2980
2.32k
                                   ModedTInfo({unmodedTSI, modedTy}));
2981
2.32k
  }
2982
2983
  /// Retrieves the canonical declaration of this typedef-name.
2984
10.9M
  TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); }
2985
67
  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
2986
2987
  /// Retrieves the tag declaration for which this is the typedef name for
2988
  /// linkage purposes, if any.
2989
  ///
2990
  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
2991
  /// this typedef declaration.
2992
  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
2993
2994
  /// Determines if this typedef shares a name and spelling location with its
2995
  /// underlying tag type, as is the case with the NS_ENUM macro.
2996
  bool isTransparentTag() const {
2997
    if (MaybeModedTInfo.getInt())
2998
      return MaybeModedTInfo.getInt() & 0x2;
2999
    return isTransparentTagSlow();
3000
  }
3001
3002
  // Implement isa/cast/dyncast/etc.
3003
74.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3004
74.8M
  static bool classofKind(Kind K) {
3005
74.8M
    return K >= firstTypedefName && 
K <= lastTypedefName58.5M
;
3006
74.8M
  }
3007
3008
private:
3009
  bool isTransparentTagSlow() const;
3010
};
3011
3012
/// Represents the declaration of a typedef-name via the 'typedef'
3013
/// type specifier.
3014
class TypedefDecl : public TypedefNameDecl {
3015
  TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3016
              SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
3017
2.34M
      : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3018
3019
public:
3020
  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3021
                             SourceLocation StartLoc, SourceLocation IdLoc,
3022
                             IdentifierInfo *Id, TypeSourceInfo *TInfo);
3023
  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3024
3025
  SourceRange getSourceRange() const override LLVM_READONLY;
3026
3027
  // Implement isa/cast/dyncast/etc.
3028
1.96k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3029
1.96k
  static bool classofKind(Kind K) { return K == Typedef; }
3030
};
3031
3032
/// Represents the declaration of a typedef-name via a C++11
3033
/// alias-declaration.
3034
class TypeAliasDecl : public TypedefNameDecl {
3035
  /// The template for which this is the pattern, if any.
3036
  TypeAliasTemplateDecl *Template;
3037
3038
  TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3039
                SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
3040
      : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3041
65.3k
        Template(nullptr) {}
3042
3043
public:
3044
  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3045
                               SourceLocation StartLoc, SourceLocation IdLoc,
3046
                               IdentifierInfo *Id, TypeSourceInfo *TInfo);
3047
  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3048
3049
  SourceRange getSourceRange() const override LLVM_READONLY;
3050
3051
2.62k
  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3052
52.6k
  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3053
3054
  // Implement isa/cast/dyncast/etc.
3055
1.19M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3056
1.19M
  static bool classofKind(Kind K) { return K == TypeAlias; }
3057
};
3058
3059
/// Represents the declaration of a struct/union/class/enum.
3060
class TagDecl : public TypeDecl,
3061
                public DeclContext,
3062
                public Redeclarable<TagDecl> {
3063
  // This class stores some data in DeclContext::TagDeclBits
3064
  // to save some space. Use the provided accessors to access it.
3065
public:
3066
  // This is really ugly.
3067
  using TagKind = TagTypeKind;
3068
3069
private:
3070
  SourceRange BraceRange;
3071
3072
  // A struct representing syntactic qualifier info,
3073
  // to be used for the (uncommon) case of out-of-line declarations.
3074
  using ExtInfo = QualifierInfo;
3075
3076
  /// If the (out-of-line) tag declaration name
3077
  /// is qualified, it points to the qualifier info (nns and range);
3078
  /// otherwise, if the tag declaration is anonymous and it is part of
3079
  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3080
  /// otherwise, if the tag declaration is anonymous and it is used as a
3081
  /// declaration specifier for variables, it points to the first VarDecl (used
3082
  /// for mangling);
3083
  /// otherwise, it is a null (TypedefNameDecl) pointer.
3084
  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3085
3086
1.88M
  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3087
60.1k
  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3088
314
  const ExtInfo *getExtInfo() const {
3089
314
    return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3090
314
  }
3091
3092
protected:
3093
  TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3094
          SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3095
          SourceLocation StartL);
3096
3097
  using redeclarable_base = Redeclarable<TagDecl>;
3098
3099
749k
  TagDecl *getNextRedeclarationImpl() override {
3100
749k
    return getNextRedeclaration();
3101
749k
  }
3102
3103
16.3k
  TagDecl *getPreviousDeclImpl() override {
3104
16.3k
    return getPreviousDecl();
3105
16.3k
  }
3106
3107
2.22M
  TagDecl *getMostRecentDeclImpl() override {
3108
2.22M
    return getMostRecentDecl();
3109
2.22M
  }
3110
3111
  /// Completes the definition of this tag declaration.
3112
  ///
3113
  /// This is a helper function for derived classes.
3114
  void completeDefinition();
3115
3116
  /// True if this decl is currently being defined.
3117
9.12M
  void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3118
3119
  /// Indicates whether it is possible for declarations of this kind
3120
  /// to have an out-of-date definition.
3121
  ///
3122
  /// This option is only enabled when modules are enabled.
3123
4.35M
  void setMayHaveOutOfDateDef(bool V = true) {
3124
4.35M
    TagDeclBits.MayHaveOutOfDateDef = V;
3125
4.35M
  }
3126
3127
public:
3128
  friend class ASTDeclReader;
3129
  friend class ASTDeclWriter;
3130
3131
  using redecl_range = redeclarable_base::redecl_range;
3132
  using redecl_iterator = redeclarable_base::redecl_iterator;
3133
3134
  using redeclarable_base::redecls_begin;
3135
  using redeclarable_base::redecls_end;
3136
  using redeclarable_base::redecls;
3137
  using redeclarable_base::getPreviousDecl;
3138
  using redeclarable_base::getMostRecentDecl;
3139
  using redeclarable_base::isFirstDecl;
3140
3141
1.44M
  SourceRange getBraceRange() const { return BraceRange; }
3142
2.04M
  void setBraceRange(SourceRange R) { BraceRange = R; }
3143
3144
  /// Return SourceLocation representing start of source
3145
  /// range ignoring outer template declarations.
3146
1.35M
  SourceLocation getInnerLocStart() const { return getBeginLoc(); }
3147
3148
  /// Return SourceLocation representing start of source
3149
  /// range taking into account any outer template declarations.
3150
  SourceLocation getOuterLocStart() const;
3151
  SourceRange getSourceRange() const override LLVM_READONLY;
3152
3153
  TagDecl *getCanonicalDecl() override;
3154
15.0k
  const TagDecl *getCanonicalDecl() const {
3155
15.0k
    return const_cast<TagDecl*>(this)->getCanonicalDecl();
3156
15.0k
  }
3157
3158
  /// Return true if this declaration is a completion definition of the type.
3159
  /// Provided for consistency.
3160
70.3k
  bool isThisDeclarationADefinition() const {
3161
70.3k
    return isCompleteDefinition();
3162
70.3k
  }
3163
3164
  /// Return true if this decl has its body fully specified.
3165
536M
  bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3166
3167
  /// True if this decl has its body fully specified.
3168
6.76M
  void setCompleteDefinition(bool V = true) {
3169
6.76M
    TagDeclBits.IsCompleteDefinition = V;
3170
6.76M
  }
3171
3172
  /// Return true if this complete decl is
3173
  /// required to be complete for some existing use.
3174
7.73M
  bool isCompleteDefinitionRequired() const {
3175
7.73M
    return TagDeclBits.IsCompleteDefinitionRequired;
3176
7.73M
  }
3177
3178
  /// True if this complete decl is
3179
  /// required to be complete for some existing use.
3180
5.67M
  void setCompleteDefinitionRequired(bool V = true) {
3181
5.67M
    TagDeclBits.IsCompleteDefinitionRequired = V;
3182
5.67M
  }
3183
3184
  /// Return true if this decl is currently being defined.
3185
54.9M
  bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3186
3187
  /// True if this tag declaration is "embedded" (i.e., defined or declared
3188
  /// for the very first time) in the syntax of a declarator.
3189
36.4k
  bool isEmbeddedInDeclarator() const {
3190
36.4k
    return TagDeclBits.IsEmbeddedInDeclarator;
3191
36.4k
  }
3192
3193
  /// True if this tag declaration is "embedded" (i.e., defined or declared
3194
  /// for the very first time) in the syntax of a declarator.
3195
4.58M
  void setEmbeddedInDeclarator(bool isInDeclarator) {
3196
4.58M
    TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3197
4.58M
  }
3198
3199
  /// True if this tag is free standing, e.g. "struct foo;".
3200
36.5k
  bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3201
3202
  /// True if this tag is free standing, e.g. "struct foo;".
3203
5.34M
  void setFreeStanding(bool isFreeStanding = true) {
3204
5.34M
    TagDeclBits.IsFreeStanding = isFreeStanding;
3205
5.34M
  }
3206
3207
  /// Indicates whether it is possible for declarations of this kind
3208
  /// to have an out-of-date definition.
3209
  ///
3210
  /// This option is only enabled when modules are enabled.
3211
64.8M
  bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3212
3213
  /// Whether this declaration declares a type that is
3214
  /// dependent, i.e., a type that somehow depends on template
3215
  /// parameters.
3216
14.3M
  bool isDependentType() const { return isDependentContext(); }
3217
3218
  /// Starts the definition of this tag declaration.
3219
  ///
3220
  /// This method should be invoked at the beginning of the definition
3221
  /// of this tag declaration. It will set the tag type into a state
3222
  /// where it is in the process of being defined.
3223
  void startDefinition();
3224
3225
  /// Returns the TagDecl that actually defines this
3226
  ///  struct/union/class/enum.  When determining whether or not a
3227
  ///  struct/union/class/enum has a definition, one should use this
3228
  ///  method as opposed to 'isDefinition'.  'isDefinition' indicates
3229
  ///  whether or not a specific TagDecl is defining declaration, not
3230
  ///  whether or not the struct/union/class/enum type is defined.
3231
  ///  This method returns NULL if there is no TagDecl that defines
3232
  ///  the struct/union/class/enum.
3233
  TagDecl *getDefinition() const;
3234
3235
142k
  StringRef getKindName() const {
3236
142k
    return TypeWithKeyword::getTagTypeKindName(getTagKind());
3237
142k
  }
3238
3239
30.2M
  TagKind getTagKind() const {
3240
30.2M
    return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3241
30.2M
  }
3242
3243
5.38M
  void setTagKind(TagKind TK) { TagDeclBits.TagDeclKind = TK; }
3244
3245
2.60M
  bool isStruct() const { return getTagKind() == TTK_Struct; }
3246
6.11M
  bool isInterface() const { return getTagKind() == TTK_Interface; }
3247
1.33M
  bool isClass()  const { return getTagKind() == TTK_Class; }
3248
13.7M
  bool isUnion()  const { return getTagKind() == TTK_Union; }
3249
0
  bool isEnum()   const { return getTagKind() == TTK_Enum; }
3250
3251
  /// Is this tag type named, either directly or via being defined in
3252
  /// a typedef of this type?
3253
  ///
3254
  /// C++11 [basic.link]p8:
3255
  ///   A type is said to have linkage if and only if:
3256
  ///     - it is a class or enumeration type that is named (or has a
3257
  ///       name for linkage purposes) and the name has linkage; ...
3258
  /// C++11 [dcl.typedef]p9:
3259
  ///   If the typedef declaration defines an unnamed class (or enum),
3260
  ///   the first typedef-name declared by the declaration to be that
3261
  ///   class type (or enum type) is used to denote the class type (or
3262
  ///   enum type) for linkage purposes only.
3263
  ///
3264
  /// C does not have an analogous rule, but the same concept is
3265
  /// nonetheless useful in some places.
3266
7.16M
  bool hasNameForLinkage() const {
3267
7.16M
    return (getDeclName() || 
getTypedefNameForAnonDecl()144k
);
3268
7.16M
  }
3269
3270
284k
  TypedefNameDecl *getTypedefNameForAnonDecl() const {
3271
284k
    return hasExtInfo() ? 
nullptr255
3272
284k
                        : 
TypedefNameDeclOrQualifier.get<TypedefNameDecl *>()284k
;
3273
284k
  }
3274
3275
  void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
3276
3277
  /// Retrieve the nested-name-specifier that qualifies the name of this
3278
  /// declaration, if it was present in the source.
3279
0
  NestedNameSpecifier *getQualifier() const {
3280
0
    return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3281
0
                        : nullptr;
3282
0
  }
3283
3284
  /// Retrieve the nested-name-specifier (with source-location
3285
  /// information) that qualifies the name of this declaration, if it was
3286
  /// present in the source.
3287
1.07M
  NestedNameSpecifierLoc getQualifierLoc() const {
3288
1.07M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc218
3289
1.07M
                        : 
NestedNameSpecifierLoc()1.07M
;
3290
1.07M
  }
3291
3292
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3293
3294
419k
  unsigned getNumTemplateParameterLists() const {
3295
419k
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists72
:
0419k
;
3296
419k
  }
3297
3298
24
  TemplateParameterList *getTemplateParameterList(unsigned i) const {
3299
24
    assert(i < getNumTemplateParameterLists());
3300
24
    return getExtInfo()->TemplParamLists[i];
3301
24
  }
3302
3303
  void setTemplateParameterListsInfo(ASTContext &Context,
3304
                                     ArrayRef<TemplateParameterList *> TPLists);
3305
3306
  // Implement isa/cast/dyncast/etc.
3307
87.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3308
93.0M
  static bool classofKind(Kind K) { return K >= firstTag && 
K <= lastTag53.8M
; }
3309
3310
33.2k
  static DeclContext *castToDeclContext(const TagDecl *D) {
3311
33.2k
    return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3312
33.2k
  }
3313
3314
12
  static TagDecl *castFromDeclContext(const DeclContext *DC) {
3315
12
    return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3316
12
  }
3317
};
3318
3319
/// Represents an enum.  In C++11, enums can be forward-declared
3320
/// with a fixed underlying type, and in C we allow them to be forward-declared
3321
/// with no underlying type as an extension.
3322
class EnumDecl : public TagDecl {
3323
  // This class stores some data in DeclContext::EnumDeclBits
3324
  // to save some space. Use the provided accessors to access it.
3325
3326
  /// This represent the integer type that the enum corresponds
3327
  /// to for code generation purposes.  Note that the enumerator constants may
3328
  /// have a different type than this does.
3329
  ///
3330
  /// If the underlying integer type was explicitly stated in the source
3331
  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3332
  /// was automatically deduced somehow, and this is a Type*.
3333
  ///
3334
  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3335
  /// some cases it won't.
3336
  ///
3337
  /// The underlying type of an enumeration never has any qualifiers, so
3338
  /// we can get away with just storing a raw Type*, and thus save an
3339
  /// extra pointer when TypeSourceInfo is needed.
3340
  llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3341
3342
  /// The integer type that values of this type should
3343
  /// promote to.  In C, enumerators are generally of an integer type
3344
  /// directly, but gcc-style large enumerators (and all enumerators
3345
  /// in C++) are of the enum type instead.
3346
  QualType PromotionType;
3347
3348
  /// If this enumeration is an instantiation of a member enumeration
3349
  /// of a class template specialization, this is the member specialization
3350
  /// information.
3351
  MemberSpecializationInfo *SpecializationInfo = nullptr;
3352
3353
  /// Store the ODRHash after first calculation.
3354
  /// The corresponding flag HasODRHash is in EnumDeclBits
3355
  /// and can be accessed with the provided accessors.
3356
  unsigned ODRHash;
3357
3358
  EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3359
           SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3360
           bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3361
3362
  void anchor() override;
3363
3364
  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3365
                                    TemplateSpecializationKind TSK);
3366
3367
  /// Sets the width in bits required to store all the
3368
  /// non-negative enumerators of this enum.
3369
107k
  void setNumPositiveBits(unsigned Num) {
3370
107k
    EnumDeclBits.NumPositiveBits = Num;
3371
107k
    assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3372
107k
  }
3373
3374
  /// Returns the width in bits required to store all the
3375
  /// negative enumerators of this enum. (see getNumNegativeBits)
3376
107k
  void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3377
3378
  /// True if this tag declaration is a scoped enumeration. Only
3379
  /// possible in C++11 mode.
3380
55.6k
  void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3381
3382
  /// If this tag declaration is a scoped enum,
3383
  /// then this is true if the scoped enum was declared using the class
3384
  /// tag, false if it was declared with the struct tag. No meaning is
3385
  /// associated if this tag declaration is not a scoped enum.
3386
55.6k
  void setScopedUsingClassTag(bool ScopedUCT = true) {
3387
55.6k
    EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3388
55.6k
  }
3389
3390
  /// True if this is an Objective-C, C++11, or
3391
  /// Microsoft-style enumeration with a fixed underlying type.
3392
55.6k
  void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3393
3394
  /// True if a valid hash is stored in ODRHash.
3395
420
  bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3396
55.9k
  void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3397
3398
public:
3399
  friend class ASTDeclReader;
3400
3401
479k
  EnumDecl *getCanonicalDecl() override {
3402
479k
    return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3403
479k
  }
3404
0
  const EnumDecl *getCanonicalDecl() const {
3405
0
    return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3406
0
  }
3407
3408
58.0k
  EnumDecl *getPreviousDecl() {
3409
58.0k
    return cast_or_null<EnumDecl>(
3410
58.0k
            static_cast<TagDecl *>(this)->getPreviousDecl());
3411
58.0k
  }
3412
52.7k
  const EnumDecl *getPreviousDecl() const {
3413
52.7k
    return const_cast<EnumDecl*>(this)->getPreviousDecl();
3414
52.7k
  }
3415
3416
393
  EnumDecl *getMostRecentDecl() {
3417
393
    return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3418
393
  }
3419
0
  const EnumDecl *getMostRecentDecl() const {
3420
0
    return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3421
0
  }
3422
3423
91.7k
  EnumDecl *getDefinition() const {
3424
91.7k
    return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3425
91.7k
  }
3426
3427
  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3428
                          SourceLocation StartLoc, SourceLocation IdLoc,
3429
                          IdentifierInfo *Id, EnumDecl *PrevDecl,
3430
                          bool IsScoped, bool IsScopedUsingClassTag,
3431
                          bool IsFixed);
3432
  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3433
3434
  /// When created, the EnumDecl corresponds to a
3435
  /// forward-declared enum. This method is used to mark the
3436
  /// declaration as being defined; its enumerators have already been
3437
  /// added (via DeclContext::addDecl). NewType is the new underlying
3438
  /// type of the enumeration type.
3439
  void completeDefinition(QualType NewType,
3440
                          QualType PromotionType,
3441
                          unsigned NumPositiveBits,
3442
                          unsigned NumNegativeBits);
3443
3444
  // Iterates through the enumerators of this enumeration.
3445
  using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>;
3446
  using enumerator_range =
3447
      llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>;
3448
3449
9.18k
  enumerator_range enumerators() const {
3450
9.18k
    return enumerator_range(enumerator_begin(), enumerator_end());
3451
9.18k
  }
3452
3453
38.1k
  enumerator_iterator enumerator_begin() const {
3454
38.1k
    const EnumDecl *E = getDefinition();
3455
38.1k
    if (!E)
3456
200
      E = this;
3457
38.1k
    return enumerator_iterator(E->decls_begin());
3458
38.1k
  }
3459
3460
38.1k
  enumerator_iterator enumerator_end() const {
3461
38.1k
    const EnumDecl *E = getDefinition();
3462
38.1k
    if (!E)
3463
200
      E = this;
3464
38.1k
    return enumerator_iterator(E->decls_end());
3465
38.1k
  }
3466
3467
  /// Return the integer type that enumerators should promote to.
3468
27.4M
  QualType getPromotionType() const { return PromotionType; }
3469
3470
  /// Set the promotion type.
3471
9.29k
  void setPromotionType(QualType T) { PromotionType = T; }
3472
3473
  /// Return the integer type this enum decl corresponds to.
3474
  /// This returns a null QualType for an enum forward definition with no fixed
3475
  /// underlying type.
3476
1.81M
  QualType getIntegerType() const {
3477
1.81M
    if (!IntegerType)
3478
32
      return QualType();
3479
1.81M
    if (const Type *T = IntegerType.dyn_cast<const Type*>())
3480
1.60M
      return QualType(T, 0);
3481
207k
    return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3482
207k
  }
3483
3484
  /// Set the underlying integer type.
3485
1.68k
  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3486
3487
  /// Set the underlying integer type source info.
3488
7.86k
  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3489
3490
  /// Return the type source info for the underlying integer type,
3491
  /// if no type source info exists, return 0.
3492
2.11k
  TypeSourceInfo *getIntegerTypeSourceInfo() const {
3493
2.11k
    return IntegerType.dyn_cast<TypeSourceInfo*>();
3494
2.11k
  }
3495
3496
  /// Retrieve the source range that covers the underlying type if
3497
  /// specified.
3498
  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3499
3500
  /// Returns the width in bits required to store all the
3501
  /// non-negative enumerators of this enum.
3502
82.5k
  unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
3503
3504
  /// Returns the width in bits required to store all the
3505
  /// negative enumerators of this enum.  These widths include
3506
  /// the rightmost leading 1;  that is:
3507
  ///
3508
  /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
3509
  /// ------------------------     -------     -----------------
3510
  ///                       -1     1111111                     1
3511
  ///                      -10     1110110                     5
3512
  ///                     -101     1001011                     8
3513
82.4k
  unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
3514
3515
  /// Returns true if this is a C++11 scoped enumeration.
3516
52.6M
  bool isScoped() const { return EnumDeclBits.IsScoped; }
3517
3518
  /// Returns true if this is a C++11 scoped enumeration.
3519
5.73k
  bool isScopedUsingClassTag() const {
3520
5.73k
    return EnumDeclBits.IsScopedUsingClassTag;
3521
5.73k
  }
3522
3523
  /// Returns true if this is an Objective-C, C++11, or
3524
  /// Microsoft-style enumeration with a fixed underlying type.
3525
15.8M
  bool isFixed() const { return EnumDeclBits.IsFixed; }
3526
3527
  unsigned getODRHash();
3528
3529
  /// Returns true if this can be considered a complete type.
3530
36.9M
  bool isComplete() const {
3531
36.9M
    // IntegerType is set for fixed type enums and non-fixed but implicitly
3532
36.9M
    // int-sized Microsoft enums.
3533
36.9M
    return isCompleteDefinition() || 
IntegerType200k
;
3534
36.9M
  }
3535
3536
  /// Returns true if this enum is either annotated with
3537
  /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
3538
  bool isClosed() const;
3539
3540
  /// Returns true if this enum is annotated with flag_enum and isn't annotated
3541
  /// with enum_extensibility(open).
3542
  bool isClosedFlag() const;
3543
3544
  /// Returns true if this enum is annotated with neither flag_enum nor
3545
  /// enum_extensibility(open).
3546
  bool isClosedNonFlag() const;
3547
3548
  /// Retrieve the enum definition from which this enumeration could
3549
  /// be instantiated, if it is an instantiation (rather than a non-template).
3550
  EnumDecl *getTemplateInstantiationPattern() const;
3551
3552
  /// Returns the enumeration (declared within the template)
3553
  /// from which this enumeration type was instantiated, or NULL if
3554
  /// this enumeration was not instantiated from any template.
3555
  EnumDecl *getInstantiatedFromMemberEnum() const;
3556
3557
  /// If this enumeration is a member of a specialization of a
3558
  /// templated class, determine what kind of template specialization
3559
  /// or instantiation this is.
3560
  TemplateSpecializationKind getTemplateSpecializationKind() const;
3561
3562
  /// For an enumeration member that was instantiated from a member
3563
  /// enumeration of a templated class, set the template specialiation kind.
3564
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
3565
                        SourceLocation PointOfInstantiation = SourceLocation());
3566
3567
  /// If this enumeration is an instantiation of a member enumeration of
3568
  /// a class template specialization, retrieves the member specialization
3569
  /// information.
3570
10.4k
  MemberSpecializationInfo *getMemberSpecializationInfo() const {
3571
10.4k
    return SpecializationInfo;
3572
10.4k
  }
3573
3574
  /// Specify that this enumeration is an instantiation of the
3575
  /// member enumeration ED.
3576
  void setInstantiationOfMemberEnum(EnumDecl *ED,
3577
5.37k
                                    TemplateSpecializationKind TSK) {
3578
5.37k
    setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3579
5.37k
  }
3580
3581
42.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3582
132M
  static bool classofKind(Kind K) { return K == Enum; }
3583
};
3584
3585
/// Represents a struct/union/class.  For example:
3586
///   struct X;                  // Forward declaration, no "body".
3587
///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
3588
/// This decl will be marked invalid if *any* members are invalid.
3589
class RecordDecl : public TagDecl {
3590
  // This class stores some data in DeclContext::RecordDeclBits
3591
  // to save some space. Use the provided accessors to access it.
3592
public:
3593
  friend class DeclContext;
3594
  /// Enum that represents the different ways arguments are passed to and
3595
  /// returned from function calls. This takes into account the target-specific
3596
  /// and version-specific rules along with the rules determined by the
3597
  /// language.
3598
  enum ArgPassingKind : unsigned {
3599
    /// The argument of this type can be passed directly in registers.
3600
    APK_CanPassInRegs,
3601
3602
    /// The argument of this type cannot be passed directly in registers.
3603
    /// Records containing this type as a subobject are not forced to be passed
3604
    /// indirectly. This value is used only in C++. This value is required by
3605
    /// C++ because, in uncommon situations, it is possible for a class to have
3606
    /// only trivial copy/move constructors even when one of its subobjects has
3607
    /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
3608
    /// constructor in the derived class is deleted).
3609
    APK_CannotPassInRegs,
3610
3611
    /// The argument of this type cannot be passed directly in registers.
3612
    /// Records containing this type as a subobject are forced to be passed
3613
    /// indirectly.
3614
    APK_CanNeverPassInRegs
3615
  };
3616
3617
protected:
3618
  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3619
             SourceLocation StartLoc, SourceLocation IdLoc,
3620
             IdentifierInfo *Id, RecordDecl *PrevDecl);
3621
3622
public:
3623
  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3624
                            SourceLocation StartLoc, SourceLocation IdLoc,
3625
                            IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3626
  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3627
3628
5.04M
  RecordDecl *getPreviousDecl() {
3629
5.04M
    return cast_or_null<RecordDecl>(
3630
5.04M
            static_cast<TagDecl *>(this)->getPreviousDecl());
3631
5.04M
  }
3632
2.09M
  const RecordDecl *getPreviousDecl() const {
3633
2.09M
    return const_cast<RecordDecl*>(this)->getPreviousDecl();
3634
2.09M
  }
3635
3636
319M
  RecordDecl *getMostRecentDecl() {
3637
319M
    return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3638
319M
  }
3639
0
  const RecordDecl *getMostRecentDecl() const {
3640
0
    return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3641
0
  }
3642
3643
3.77M
  bool hasFlexibleArrayMember() const {
3644
3.77M
    return RecordDeclBits.HasFlexibleArrayMember;
3645
3.77M
  }
3646
3647
4.33M
  void setHasFlexibleArrayMember(bool V) {
3648
4.33M
    RecordDeclBits.HasFlexibleArrayMember = V;
3649
4.33M
  }
3650
3651
  /// Whether this is an anonymous struct or union. To be an anonymous
3652
  /// struct or union, it must have been declared without a name and
3653
  /// there must be no objects of this type declared, e.g.,
3654
  /// @code
3655
  ///   union { int i; float f; };
3656
  /// @endcode
3657
  /// is an anonymous union but neither of the following are:
3658
  /// @code
3659
  ///  union X { int i; float f; };
3660
  ///  union { int i; float f; } obj;
3661
  /// @endcode
3662
6.89M
  bool isAnonymousStructOrUnion() const {
3663
6.89M
    return RecordDeclBits.AnonymousStructOrUnion;
3664
6.89M
  }
3665
3666
4.34M
  void setAnonymousStructOrUnion(bool Anon) {
3667
4.34M
    RecordDeclBits.AnonymousStructOrUnion = Anon;
3668
4.34M
  }
3669
3670
1.43M
  bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
3671
4.33M
  void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
3672
3673
1.43M
  bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
3674
3675
4.39M
  void setHasVolatileMember(bool val) {
3676
4.39M
    RecordDeclBits.HasVolatileMember = val;
3677
4.39M
  }
3678
3679
30.5k
  bool hasLoadedFieldsFromExternalStorage() const {
3680
30.5k
    return RecordDeclBits.LoadedFieldsFromExternalStorage;
3681
30.5k
  }
3682
3683
4.30M
  void setHasLoadedFieldsFromExternalStorage(bool val) const {
3684
4.30M
    RecordDeclBits.LoadedFieldsFromExternalStorage = val;
3685
4.30M
  }
3686
3687
  /// Functions to query basic properties of non-trivial C structs.
3688
107k
  bool isNonTrivialToPrimitiveDefaultInitialize() const {
3689
107k
    return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
3690
107k
  }
3691
3692
4.33M
  void setNonTrivialToPrimitiveDefaultInitialize(bool V) {
3693
4.33M
    RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
3694
4.33M
  }
3695
3696
106k
  bool isNonTrivialToPrimitiveCopy() const {
3697
106k
    return RecordDeclBits.NonTrivialToPrimitiveCopy;
3698
106k
  }
3699
3700
4.33M
  void setNonTrivialToPrimitiveCopy(bool V) {
3701
4.33M
    RecordDeclBits.NonTrivialToPrimitiveCopy = V;
3702
4.33M
  }
3703
3704
139k
  bool isNonTrivialToPrimitiveDestroy() const {
3705
139k
    return RecordDeclBits.NonTrivialToPrimitiveDestroy;
3706
139k
  }
3707
3708
4.33M
  void setNonTrivialToPrimitiveDestroy(bool V) {
3709
4.33M
    RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
3710
4.33M
  }
3711
3712
  /// Determine whether this class can be passed in registers. In C++ mode,
3713
  /// it must have at least one trivial, non-deleted copy or move constructor.
3714
  /// FIXME: This should be set as part of completeDefinition.
3715
24.9k
  bool canPassInRegisters() const {
3716
24.9k
    return getArgPassingRestrictions() == APK_CanPassInRegs;
3717
24.9k
  }
3718
3719
2.91M
  ArgPassingKind getArgPassingRestrictions() const {
3720
2.91M
    return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
3721
2.91M
  }
3722
3723
6.13M
  void setArgPassingRestrictions(ArgPassingKind Kind) {
3724
6.13M
    RecordDeclBits.ArgPassingRestrictions = Kind;
3725
6.13M
  }
3726
3727
67.1k
  bool isParamDestroyedInCallee() const {
3728
67.1k
    return RecordDeclBits.ParamDestroyedInCallee;
3729
67.1k
  }
3730
3731
4.44M
  void setParamDestroyedInCallee(bool V) {
3732
4.44M
    RecordDeclBits.ParamDestroyedInCallee = V;
3733
4.44M
  }
3734
3735
  /// Determines whether this declaration represents the
3736
  /// injected class name.
3737
  ///
3738
  /// The injected class name in C++ is the name of the class that
3739
  /// appears inside the class itself. For example:
3740
  ///
3741
  /// \code
3742
  /// struct C {
3743
  ///   // C is implicitly declared here as a synonym for the class name.
3744
  /// };
3745
  ///
3746
  /// C::C c; // same as "C c;"
3747
  /// \endcode
3748
  bool isInjectedClassName() const;
3749
3750
  /// Determine whether this record is a class describing a lambda
3751
  /// function object.
3752
  bool isLambda() const;
3753
3754
  /// Determine whether this record is a record for captured variables in
3755
  /// CapturedStmt construct.
3756
  bool isCapturedRecord() const;
3757
3758
  /// Mark the record as a record for captured variables in CapturedStmt
3759
  /// construct.
3760
  void setCapturedRecord();
3761
3762
  /// Returns the RecordDecl that actually defines
3763
  ///  this struct/union/class.  When determining whether or not a
3764
  ///  struct/union/class is completely defined, one should use this
3765
  ///  method as opposed to 'isCompleteDefinition'.
3766
  ///  'isCompleteDefinition' indicates whether or not a specific
3767
  ///  RecordDecl is a completed definition, not whether or not the
3768
  ///  record type is defined.  This method returns NULL if there is
3769
  ///  no RecordDecl that defines the struct/union/tag.
3770
8.42M
  RecordDecl *getDefinition() const {
3771
8.42M
    return cast_or_null<RecordDecl>(TagDecl::getDefinition());
3772
8.42M
  }
3773
3774
  // Iterator access to field members. The field iterator only visits
3775
  // the non-static data members of this class, ignoring any static
3776
  // data members, functions, constructors, destructors, etc.
3777
  using field_iterator = specific_decl_iterator<FieldDecl>;
3778
  using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
3779
3780
3.23M
  field_range fields() const { return field_range(field_begin(), field_end()); }
3781
  field_iterator field_begin() const;
3782
3783
5.81M
  field_iterator field_end() const {
3784
5.81M
    return field_iterator(decl_iterator());
3785
5.81M
  }
3786
3787
  // Whether there are any fields (non-static data members) in this record.
3788
664k
  bool field_empty() const {
3789
664k
    return field_begin() == field_end();
3790
664k
  }
3791
3792
  /// Note that the definition of this type is now complete.
3793
  virtual void completeDefinition();
3794
3795
34.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3796
61.6M
  static bool classofKind(Kind K) {
3797
61.6M
    return K >= firstRecord && 
K <= lastRecord54.2M
;
3798
61.6M
  }
3799
3800
  /// Get whether or not this is an ms_struct which can
3801
  /// be turned on with an attribute, pragma, or -mms-bitfields
3802
  /// commandline option.
3803
  bool isMsStruct(const ASTContext &C) const;
3804
3805
  /// Whether we are allowed to insert extra padding between fields.
3806
  /// These padding are added to help AddressSanitizer detect
3807
  /// intra-object-overflow bugs.
3808
  bool mayInsertExtraPadding(bool EmitRemark = false) const;
3809
3810
  /// Finds the first data member which has a name.
3811
  /// nullptr is returned if no named data member exists.
3812
  const FieldDecl *findFirstNamedDataMember() const;
3813
3814
private:
3815
  /// Deserialize just the fields.
3816
  void LoadFieldsFromExternalStorage() const;
3817
};
3818
3819
class FileScopeAsmDecl : public Decl {
3820
  StringLiteral *AsmString;
3821
  SourceLocation RParenLoc;
3822
3823
  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
3824
                   SourceLocation StartL, SourceLocation EndL)
3825
1.17k
    : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
3826
3827
  virtual void anchor();
3828
3829
public:
3830
  static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
3831
                                  StringLiteral *Str, SourceLocation AsmLoc,
3832
                                  SourceLocation RParenLoc);
3833
3834
  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3835
3836
3
  SourceLocation getAsmLoc() const { return getLocation(); }
3837
62
  SourceLocation getRParenLoc() const { return RParenLoc; }
3838
113
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3839
3
  SourceRange getSourceRange() const override LLVM_READONLY {
3840
3
    return SourceRange(getAsmLoc(), getRParenLoc());
3841
3
  }
3842
3843
3
  const StringLiteral *getAsmString() const { return AsmString; }
3844
1.06k
  StringLiteral *getAsmString() { return AsmString; }
3845
113
  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
3846
3847
725k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3848
725k
  static bool classofKind(Kind K) { return K == FileScopeAsm; }
3849
};
3850
3851
/// Pepresents a block literal declaration, which is like an
3852
/// unnamed FunctionDecl.  For example:
3853
/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
3854
class BlockDecl : public Decl, public DeclContext {
3855
  // This class stores some data in DeclContext::BlockDeclBits
3856
  // to save some space. Use the provided accessors to access it.
3857
public:
3858
  /// A class which contains all the information about a particular
3859
  /// captured value.
3860
  class Capture {
3861
    enum {
3862
      flag_isByRef = 0x1,
3863
      flag_isNested = 0x2
3864
    };
3865
3866
    /// The variable being captured.
3867
    llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
3868
3869
    /// The copy expression, expressed in terms of a DeclRef (or
3870
    /// BlockDeclRef) to the captured variable.  Only required if the
3871
    /// variable has a C++ class type.
3872
    Expr *CopyExpr;
3873
3874
  public:
3875
    Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
3876
      : VariableAndFlags(variable,
3877
                  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
3878
2.82k
        CopyExpr(copy) {}
3879
3880
    /// The variable being captured.
3881
39.2k
    VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
3882
3883
    /// Whether this is a "by ref" capture, i.e. a capture of a __block
3884
    /// variable.
3885
8.02k
    bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
3886
3887
10.9k
    bool isEscapingByref() const {
3888
10.9k
      return getVariable()->isEscapingByref();
3889
10.9k
    }
3890
3891
0
    bool isNonEscapingByref() const {
3892
0
      return getVariable()->isNonEscapingByref();
3893
0
    }
3894
3895
    /// Whether this is a nested capture, i.e. the variable captured
3896
    /// is not from outside the immediately enclosing function/block.
3897
3.43k
    bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
3898
3899
1.60k
    bool hasCopyExpr() const { return CopyExpr != nullptr; }
3900
6.19k
    Expr *getCopyExpr() const { return CopyExpr; }
3901
0
    void setCopyExpr(Expr *e) { CopyExpr = e; }
3902
  };
3903
3904
private:
3905
  /// A new[]'d array of pointers to ParmVarDecls for the formal
3906
  /// parameters of this function.  This is null if a prototype or if there are
3907
  /// no formals.
3908
  ParmVarDecl **ParamInfo = nullptr;
3909
  unsigned NumParams = 0;
3910
3911
  Stmt *Body = nullptr;
3912
  TypeSourceInfo *SignatureAsWritten = nullptr;
3913
3914
  const Capture *Captures = nullptr;
3915
  unsigned NumCaptures = 0;
3916
3917
  unsigned ManglingNumber = 0;
3918
  Decl *ManglingContextDecl = nullptr;
3919
3920
protected:
3921
  BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
3922
3923
public:
3924
  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
3925
  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3926
3927
20.8k
  SourceLocation getCaretLocation() const { return getLocation(); }
3928
3929
199
  bool isVariadic() const { return BlockDeclBits.IsVariadic; }
3930
5.34k
  void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
3931
3932
0
  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
3933
22.4k
  Stmt *getBody() const override { return (Stmt*) Body; }
3934
2.66k
  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
3935
3936
2.62k
  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
3937
967
  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
3938
3939
  // ArrayRef access to formal parameters.
3940
5.67k
  ArrayRef<ParmVarDecl *> parameters() const {
3941
5.67k
    return {ParamInfo, getNumParams()};
3942
5.67k
  }
3943
5.88k
  MutableArrayRef<ParmVarDecl *> parameters() {
3944
5.88k
    return {ParamInfo, getNumParams()};
3945
5.88k
  }
3946
3947
  // Iterator access to formal parameters.
3948
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
3949
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
3950
3951
157
  bool param_empty() const { return parameters().empty(); }
3952
55
  param_iterator param_begin() { return parameters().begin(); }
3953
23
  param_iterator param_end() { return parameters().end(); }
3954
1.16k
  param_const_iterator param_begin() const { return parameters().begin(); }
3955
1.16k
  param_const_iterator param_end() const { return parameters().end(); }
3956
16
  size_t param_size() const { return parameters().size(); }
3957
3958
11.5k
  unsigned getNumParams() const { return NumParams; }
3959
3960
10
  const ParmVarDecl *getParamDecl(unsigned i) const {
3961
10
    assert(i < getNumParams() && "Illegal param #");
3962
10
    return ParamInfo[i];
3963
10
  }
3964
16
  ParmVarDecl *getParamDecl(unsigned i) {
3965
16
    assert(i < getNumParams() && "Illegal param #");
3966
16
    return ParamInfo[i];
3967
16
  }
3968
3969
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
3970
3971
  /// True if this block (or its nested blocks) captures
3972
  /// anything of local storage from its enclosing scopes.
3973
6.87k
  bool hasCaptures() const { return NumCaptures || 
capturesCXXThis()2.63k
; }
3974
3975
  /// Returns the number of captured variables.
3976
  /// Does not include an entry for 'this'.
3977
16
  unsigned getNumCaptures() const { return NumCaptures; }
3978
3979
  using capture_const_iterator = ArrayRef<Capture>::const_iterator;
3980
3981
15.4k
  ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
3982
3983
1.23k
  capture_const_iterator capture_begin() const { return captures().begin(); }
3984
1.22k
  capture_const_iterator capture_end() const { return captures().end(); }
3985
3986
6.42k
  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
3987
5.33k
  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
3988
3989
98
  bool blockMissingReturnType() const {
3990
98
    return BlockDeclBits.BlockMissingReturnType;
3991
98
  }
3992
3993
2.88k
  void setBlockMissingReturnType(bool val = true) {
3994
2.88k
    BlockDeclBits.BlockMissingReturnType = val;
3995
2.88k
  }
3996
3997
3.39k
  bool isConversionFromLambda() const {
3998
3.39k
    return BlockDeclBits.IsConversionFromLambda;
3999
3.39k
  }
4000
4001
2.71k
  void setIsConversionFromLambda(bool val = true) {
4002
2.71k
    BlockDeclBits.IsConversionFromLambda = val;
4003
2.71k
  }
4004
4005
5.69k
  bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4006
2.72k
  void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4007
4008
  bool capturesVariable(const VarDecl *var) const;
4009
4010
  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4011
                   bool CapturesCXXThis);
4012
4013
144
   unsigned getBlockManglingNumber() const {
4014
144
     return ManglingNumber;
4015
144
   }
4016
4017
468
   Decl *getBlockManglingContextDecl() const {
4018
468
     return ManglingContextDecl;
4019
468
   }
4020
4021
203
  void setBlockMangling(unsigned Number, Decl *Ctx) {
4022
203
    ManglingNumber = Number;
4023
203
    ManglingContextDecl = Ctx;
4024
203
  }
4025
4026
  SourceRange getSourceRange() const override LLVM_READONLY;
4027
4028
  // Implement isa/cast/dyncast/etc.
4029
24.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4030
85.9M
  static bool classofKind(Kind K) { return K == Block; }
4031
36
  static DeclContext *castToDeclContext(const BlockDecl *D) {
4032
36
    return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4033
36
  }
4034
0
  static BlockDecl *castFromDeclContext(const DeclContext *DC) {
4035
0
    return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4036
0
  }
4037
};
4038
4039
/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4040
class CapturedDecl final
4041
    : public Decl,
4042
      public DeclContext,
4043
      private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4044
protected:
4045
0
  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4046
0
    return NumParams;
4047
0
  }
4048
4049
private:
4050
  /// The number of parameters to the outlined function.
4051
  unsigned NumParams;
4052
4053
  /// The position of context parameter in list of parameters.
4054
  unsigned ContextParam;
4055
4056
  /// The body of the outlined function.
4057
  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4058
4059
  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4060
4061
507k
  ImplicitParamDecl *const *getParams() const {
4062
507k
    return getTrailingObjects<ImplicitParamDecl *>();
4063
507k
  }
4064
4065
1.08M
  ImplicitParamDecl **getParams() {
4066
1.08M
    return getTrailingObjects<ImplicitParamDecl *>();
4067
1.08M
  }
4068
4069
public:
4070
  friend class ASTDeclReader;
4071
  friend class ASTDeclWriter;
4072
  friend TrailingObjects;
4073
4074
  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4075
                              unsigned NumParams);
4076
  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4077
                                          unsigned NumParams);
4078
4079
  Stmt *getBody() const override;
4080
  void setBody(Stmt *B);
4081
4082
  bool isNothrow() const;
4083
  void setNothrow(bool Nothrow = true);
4084
4085
106k
  unsigned getNumParams() const { return NumParams; }
4086
4087
390k
  ImplicitParamDecl *getParam(unsigned i) const {
4088
390k
    assert(i < NumParams);
4089
390k
    return getParams()[i];
4090
390k
  }
4091
1.08M
  void setParam(unsigned i, ImplicitParamDecl *P) {
4092
1.08M
    assert(i < NumParams);
4093
1.08M
    getParams()[i] = P;
4094
1.08M
  }
4095
4096
  // ArrayRef interface to parameters.
4097
0
  ArrayRef<ImplicitParamDecl *> parameters() const {
4098
0
    return {getParams(), getNumParams()};
4099
0
  }
4100
0
  MutableArrayRef<ImplicitParamDecl *> parameters() {
4101
0
    return {getParams(), getNumParams()};
4102
0
  }
4103
4104
  /// Retrieve the parameter containing captured variables.
4105
292k
  ImplicitParamDecl *getContextParam() const {
4106
292k
    assert(ContextParam < NumParams);
4107
292k
    return getParam(ContextParam);
4108
292k
  }
4109
310k
  void setContextParam(unsigned i, ImplicitParamDecl *P) {
4110
310k
    assert(i < NumParams);
4111
310k
    ContextParam = i;
4112
310k
    setParam(i, P);
4113
310k
  }
4114
87.0k
  unsigned getContextParamPosition() const { return ContextParam; }
4115
4116
  using param_iterator = ImplicitParamDecl *const *;
4117
  using param_range = llvm::iterator_range<param_iterator>;
4118
4119
  /// Retrieve an iterator pointing to the first parameter decl.
4120
89.0k
  param_iterator param_begin() const { return getParams(); }
4121
  /// Retrieve an iterator one past the last parameter decl.
4122
27.4k
  param_iterator param_end() const { return getParams() + NumParams; }
4123
4124
  // Implement isa/cast/dyncast/etc.
4125
277k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4126
85.6M
  static bool classofKind(Kind K) { return K == Captured; }
4127
291k
  static DeclContext *castToDeclContext(const CapturedDecl *D) {
4128
291k
    return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4129
291k
  }
4130
0
  static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
4131
0
    return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4132
0
  }
4133
};
4134
4135
/// Describes a module import declaration, which makes the contents
4136
/// of the named module visible in the current translation unit.
4137
///
4138
/// An import declaration imports the named module (or submodule). For example:
4139
/// \code
4140
///   @import std.vector;
4141
/// \endcode
4142
///
4143
/// Import declarations can also be implicitly generated from
4144
/// \#include/\#import directives.
4145
class ImportDecl final : public Decl,
4146
                         llvm::TrailingObjects<ImportDecl, SourceLocation> {
4147
  friend class ASTContext;
4148
  friend class ASTDeclReader;
4149
  friend class ASTReader;
4150
  friend TrailingObjects;
4151
4152
  /// The imported module, along with a bit that indicates whether
4153
  /// we have source-location information for each identifier in the module
4154
  /// name.
4155
  ///
4156
  /// When the bit is false, we only have a single source location for the
4157
  /// end of the import declaration.
4158
  llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
4159
4160
  /// The next import in the list of imports local to the translation
4161
  /// unit being parsed (not loaded from an AST file).
4162
  ImportDecl *NextLocalImport = nullptr;
4163
4164
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4165
             ArrayRef<SourceLocation> IdentifierLocs);
4166
4167
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4168
             SourceLocation EndLoc);
4169
4170
152
  ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4171
4172
public:
4173
  /// Create a new module import declaration.
4174
  static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4175
                            SourceLocation StartLoc, Module *Imported,
4176
                            ArrayRef<SourceLocation> IdentifierLocs);
4177
4178
  /// Create a new module import declaration for an implicitly-generated
4179
  /// import.
4180
  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4181
                                    SourceLocation StartLoc, Module *Imported,
4182
                                    SourceLocation EndLoc);
4183
4184
  /// Create a new, deserialized module import declaration.
4185
  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4186
                                        unsigned NumLocations);
4187
4188
  /// Retrieve the module that was imported by the import declaration.
4189
5.10k
  Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
4190
4191
  /// Retrieves the locations of each of the identifiers that make up
4192
  /// the complete module name in the import declaration.
4193
  ///
4194
  /// This will return an empty array if the locations of the individual
4195
  /// identifiers aren't available.
4196
  ArrayRef<SourceLocation> getIdentifierLocs() const;
4197
4198
  SourceRange getSourceRange() const override LLVM_READONLY;
4199
4200
27.2M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4201
27.2M
  static bool classofKind(Kind K) { return K == Import; }
4202
};
4203
4204
/// Represents a C++ Modules TS module export declaration.
4205
///
4206
/// For example:
4207
/// \code
4208
///   export void foo();
4209
/// \endcode
4210
class ExportDecl final : public Decl, public DeclContext {
4211
  virtual void anchor();
4212
4213
private:
4214
  friend class ASTDeclReader;
4215
4216
  /// The source location for the right brace (if valid).
4217
  SourceLocation RBraceLoc;
4218
4219
  ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4220
      : Decl(Export, DC, ExportLoc), DeclContext(Export),
4221
82
        RBraceLoc(SourceLocation()) {}
4222
4223
public:
4224
  static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4225
                            SourceLocation ExportLoc);
4226
  static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4227
4228
0
  SourceLocation getExportLoc() const { return getLocation(); }
4229
29
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4230
16
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4231
4232
0
  SourceLocation getEndLoc() const LLVM_READONLY {
4233
0
    if (RBraceLoc.isValid())
4234
0
      return RBraceLoc;
4235
0
    // No braces: get the end location of the (only) declaration in context
4236
0
    // (if present).
4237
0
    return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
4238
0
  }
4239
4240
0
  SourceRange getSourceRange() const override LLVM_READONLY {
4241
0
    return SourceRange(getLocation(), getEndLoc());
4242
0
  }
4243
4244
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4245
7.21k
  static bool classofKind(Kind K) { return K == Export; }
4246
0
  static DeclContext *castToDeclContext(const ExportDecl *D) {
4247
0
    return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4248
0
  }
4249
0
  static ExportDecl *castFromDeclContext(const DeclContext *DC) {
4250
0
    return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4251
0
  }
4252
};
4253
4254
/// Represents an empty-declaration.
4255
class EmptyDecl : public Decl {
4256
2.19k
  EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4257
4258
  virtual void anchor();
4259
4260
public:
4261
  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4262
                           SourceLocation L);
4263
  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4264
4265
67
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4266
67
  static bool classofKind(Kind K) { return K == Empty; }
4267
};
4268
4269
/// Insertion operator for diagnostics.  This allows sending NamedDecl's
4270
/// into a diagnostic with <<.
4271
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4272
159k
                                           const NamedDecl* ND) {
4273
159k
  DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4274
159k
                  DiagnosticsEngine::ak_nameddecl);
4275
159k
  return DB;
4276
159k
}
4277
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
4278
851k
                                           const NamedDecl* ND) {
4279
851k
  PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4280
851k
                  DiagnosticsEngine::ak_nameddecl);
4281
851k
  return PD;
4282
851k
}
4283
4284
template<typename decl_type>
4285
5.64M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
5.64M
  // Note: This routine is implemented here because we need both NamedDecl
4287
5.64M
  // and Redeclarable to be defined.
4288
5.64M
  assert(RedeclLink.isFirst() &&
4289
5.64M
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
5.64M
4291
5.64M
  if (PrevDecl) {
4292
1.83M
    // Point to previous. Make sure that this is actually the most recent
4293
1.83M
    // redeclaration, or we can build invalid chains. If the most recent
4294
1.83M
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
1.83M
    First = PrevDecl->getFirstDecl();
4296
1.83M
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
1.83M
    decl_type *MostRecent = First->getNextRedeclaration();
4298
1.83M
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
1.83M
4300
1.83M
    // If the declaration was previously visible, a redeclaration of it remains
4301
1.83M
    // visible even if it wouldn't be visible by itself.
4302
1.83M
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
1.83M
      MostRecent->getIdentifierNamespace() &
4304
1.83M
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
3.80M
  } else {
4306
3.80M
    // Make this first.
4307
3.80M
    First = static_cast<decl_type*>(this);
4308
3.80M
  }
4309
5.64M
4310
5.64M
  // First one will point to this one as latest.
4311
5.64M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
5.64M
4313
5.64M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
5.64M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
5.64M
}
clang::Redeclarable<clang::TypedefNameDecl>::setPreviousDecl(clang::TypedefNameDecl*)
Line
Count
Source
4285
6.79k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
6.79k
  // Note: This routine is implemented here because we need both NamedDecl
4287
6.79k
  // and Redeclarable to be defined.
4288
6.79k
  assert(RedeclLink.isFirst() &&
4289
6.79k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
6.79k
4291
6.79k
  if (PrevDecl) {
4292
6.79k
    // Point to previous. Make sure that this is actually the most recent
4293
6.79k
    // redeclaration, or we can build invalid chains. If the most recent
4294
6.79k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
6.79k
    First = PrevDecl->getFirstDecl();
4296
6.79k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
6.79k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
6.79k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
6.79k
4300
6.79k
    // If the declaration was previously visible, a redeclaration of it remains
4301
6.79k
    // visible even if it wouldn't be visible by itself.
4302
6.79k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
6.79k
      MostRecent->getIdentifierNamespace() &
4304
6.79k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
6.79k
  } else {
4306
0
    // Make this first.
4307
0
    First = static_cast<decl_type*>(this);
4308
0
  }
4309
6.79k
4310
6.79k
  // First one will point to this one as latest.
4311
6.79k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
6.79k
4313
6.79k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
6.79k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
6.79k
}
clang::Redeclarable<clang::VarDecl>::setPreviousDecl(clang::VarDecl*)
Line
Count
Source
4285
75.7k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
75.7k
  // Note: This routine is implemented here because we need both NamedDecl
4287
75.7k
  // and Redeclarable to be defined.
4288
75.7k
  assert(RedeclLink.isFirst() &&
4289
75.7k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
75.7k
4291
75.7k
  if (PrevDecl) {
4292
75.7k
    // Point to previous. Make sure that this is actually the most recent
4293
75.7k
    // redeclaration, or we can build invalid chains. If the most recent
4294
75.7k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
75.7k
    First = PrevDecl->getFirstDecl();
4296
75.7k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
75.7k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
75.7k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
75.7k
4300
75.7k
    // If the declaration was previously visible, a redeclaration of it remains
4301
75.7k
    // visible even if it wouldn't be visible by itself.
4302
75.7k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
75.7k
      MostRecent->getIdentifierNamespace() &
4304
75.7k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
75.7k
  } else {
4306
0
    // Make this first.
4307
0
    First = static_cast<decl_type*>(this);
4308
0
  }
4309
75.7k
4310
75.7k
  // First one will point to this one as latest.
4311
75.7k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
75.7k
4313
75.7k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
75.7k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
75.7k
}
clang::Redeclarable<clang::RedeclarableTemplateDecl>::setPreviousDecl(clang::RedeclarableTemplateDecl*)
Line
Count
Source
4285
345k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
345k
  // Note: This routine is implemented here because we need both NamedDecl
4287
345k
  // and Redeclarable to be defined.
4288
345k
  assert(RedeclLink.isFirst() &&
4289
345k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
345k
4291
345k
  if (PrevDecl) {
4292
88.2k
    // Point to previous. Make sure that this is actually the most recent
4293
88.2k
    // redeclaration, or we can build invalid chains. If the most recent
4294
88.2k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
88.2k
    First = PrevDecl->getFirstDecl();
4296
88.2k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
88.2k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
88.2k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
88.2k
4300
88.2k
    // If the declaration was previously visible, a redeclaration of it remains
4301
88.2k
    // visible even if it wouldn't be visible by itself.
4302
88.2k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
88.2k
      MostRecent->getIdentifierNamespace() &
4304
88.2k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
257k
  } else {
4306
257k
    // Make this first.
4307
257k
    First = static_cast<decl_type*>(this);
4308
257k
  }
4309
345k
4310
345k
  // First one will point to this one as latest.
4311
345k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
345k
4313
345k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
345k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
345k
}
clang::Redeclarable<clang::UsingShadowDecl>::setPreviousDecl(clang::UsingShadowDecl*)
Line
Count
Source
4285
160k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
160k
  // Note: This routine is implemented here because we need both NamedDecl
4287
160k
  // and Redeclarable to be defined.
4288
160k
  assert(RedeclLink.isFirst() &&
4289
160k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
160k
4291
160k
  if (PrevDecl) {
4292
3.11k
    // Point to previous. Make sure that this is actually the most recent
4293
3.11k
    // redeclaration, or we can build invalid chains. If the most recent
4294
3.11k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
3.11k
    First = PrevDecl->getFirstDecl();
4296
3.11k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
3.11k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
3.11k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
3.11k
4300
3.11k
    // If the declaration was previously visible, a redeclaration of it remains
4301
3.11k
    // visible even if it wouldn't be visible by itself.
4302
3.11k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
3.11k
      MostRecent->getIdentifierNamespace() &
4304
3.11k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
157k
  } else {
4306
157k
    // Make this first.
4307
157k
    First = static_cast<decl_type*>(this);
4308
157k
  }
4309
160k
4310
160k
  // First one will point to this one as latest.
4311
160k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
160k
4313
160k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
160k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
160k
}
clang::Redeclarable<clang::NamespaceAliasDecl>::setPreviousDecl(clang::NamespaceAliasDecl*)
Line
Count
Source
4285
12
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
12
  // Note: This routine is implemented here because we need both NamedDecl
4287
12
  // and Redeclarable to be defined.
4288
12
  assert(RedeclLink.isFirst() &&
4289
12
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
12
4291
12
  if (PrevDecl) {
4292
12
    // Point to previous. Make sure that this is actually the most recent
4293
12
    // redeclaration, or we can build invalid chains. If the most recent
4294
12
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
12
    First = PrevDecl->getFirstDecl();
4296
12
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
12
    decl_type *MostRecent = First->getNextRedeclaration();
4298
12
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
12
4300
12
    // If the declaration was previously visible, a redeclaration of it remains
4301
12
    // visible even if it wouldn't be visible by itself.
4302
12
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
12
      MostRecent->getIdentifierNamespace() &
4304
12
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
12
  } else {
4306
0
    // Make this first.
4307
0
    First = static_cast<decl_type*>(this);
4308
0
  }
4309
12
4310
12
  // First one will point to this one as latest.
4311
12
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
12
4313
12
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
12
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
12
}
clang::Redeclarable<clang::FunctionDecl>::setPreviousDecl(clang::FunctionDecl*)
Line
Count
Source
4285
540k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
540k
  // Note: This routine is implemented here because we need both NamedDecl
4287
540k
  // and Redeclarable to be defined.
4288
540k
  assert(RedeclLink.isFirst() &&
4289
540k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
540k
4291
540k
  if (PrevDecl) {
4292
540k
    // Point to previous. Make sure that this is actually the most recent
4293
540k
    // redeclaration, or we can build invalid chains. If the most recent
4294
540k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
540k
    First = PrevDecl->getFirstDecl();
4296
540k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
540k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
540k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
540k
4300
540k
    // If the declaration was previously visible, a redeclaration of it remains
4301
540k
    // visible even if it wouldn't be visible by itself.
4302
540k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
540k
      MostRecent->getIdentifierNamespace() &
4304
540k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
540k
  } else {
4306
0
    // Make this first.
4307
0
    First = static_cast<decl_type*>(this);
4308
0
  }
4309
540k
4310
540k
  // First one will point to this one as latest.
4311
540k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
540k
4313
540k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
540k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
540k
}
clang::Redeclarable<clang::TagDecl>::setPreviousDecl(clang::TagDecl*)
Line
Count
Source
4285
4.35M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
4.35M
  // Note: This routine is implemented here because we need both NamedDecl
4287
4.35M
  // and Redeclarable to be defined.
4288
4.35M
  assert(RedeclLink.isFirst() &&
4289
4.35M
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
4.35M
4291
4.35M
  if (PrevDecl) {
4292
1.04M
    // Point to previous. Make sure that this is actually the most recent
4293
1.04M
    // redeclaration, or we can build invalid chains. If the most recent
4294
1.04M
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
1.04M
    First = PrevDecl->getFirstDecl();
4296
1.04M
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
1.04M
    decl_type *MostRecent = First->getNextRedeclaration();
4298
1.04M
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
1.04M
4300
1.04M
    // If the declaration was previously visible, a redeclaration of it remains
4301
1.04M
    // visible even if it wouldn't be visible by itself.
4302
1.04M
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
1.04M
      MostRecent->getIdentifierNamespace() &
4304
1.04M
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
3.31M
  } else {
4306
3.31M
    // Make this first.
4307
3.31M
    First = static_cast<decl_type*>(this);
4308
3.31M
  }
4309
4.35M
4310
4.35M
  // First one will point to this one as latest.
4311
4.35M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
4.35M
4313
4.35M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
4.35M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
4.35M
}
clang::Redeclarable<clang::NamespaceDecl>::setPreviousDecl(clang::NamespaceDecl*)
Line
Count
Source
4285
121k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
121k
  // Note: This routine is implemented here because we need both NamedDecl
4287
121k
  // and Redeclarable to be defined.
4288
121k
  assert(RedeclLink.isFirst() &&
4289
121k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
121k
4291
121k
  if (PrevDecl) {
4292
74.7k
    // Point to previous. Make sure that this is actually the most recent
4293
74.7k
    // redeclaration, or we can build invalid chains. If the most recent
4294
74.7k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
74.7k
    First = PrevDecl->getFirstDecl();
4296
74.7k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
74.7k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
74.7k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
74.7k
4300
74.7k
    // If the declaration was previously visible, a redeclaration of it remains
4301
74.7k
    // visible even if it wouldn't be visible by itself.
4302
74.7k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
74.7k
      MostRecent->getIdentifierNamespace() &
4304
74.7k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
74.7k
  } else {
4306
46.5k
    // Make this first.
4307
46.5k
    First = static_cast<decl_type*>(this);
4308
46.5k
  }
4309
121k
4310
121k
  // First one will point to this one as latest.
4311
121k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
121k
4313
121k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
121k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
121k
}
clang::Redeclarable<clang::ObjCInterfaceDecl>::setPreviousDecl(clang::ObjCInterfaceDecl*)
Line
Count
Source
4285
30.0k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
30.0k
  // Note: This routine is implemented here because we need both NamedDecl
4287
30.0k
  // and Redeclarable to be defined.
4288
30.0k
  assert(RedeclLink.isFirst() &&
4289
30.0k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
30.0k
4291
30.0k
  if (PrevDecl) {
4292
6.74k
    // Point to previous. Make sure that this is actually the most recent
4293
6.74k
    // redeclaration, or we can build invalid chains. If the most recent
4294
6.74k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
6.74k
    First = PrevDecl->getFirstDecl();
4296
6.74k
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
6.74k
    decl_type *MostRecent = First->getNextRedeclaration();
4298
6.74k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
6.74k
4300
6.74k
    // If the declaration was previously visible, a redeclaration of it remains
4301
6.74k
    // visible even if it wouldn't be visible by itself.
4302
6.74k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
6.74k
      MostRecent->getIdentifierNamespace() &
4304
6.74k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
23.2k
  } else {
4306
23.2k
    // Make this first.
4307
23.2k
    First = static_cast<decl_type*>(this);
4308
23.2k
  }
4309
30.0k
4310
30.0k
  // First one will point to this one as latest.
4311
30.0k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
30.0k
4313
30.0k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
30.0k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
30.0k
}
clang::Redeclarable<clang::ObjCProtocolDecl>::setPreviousDecl(clang::ObjCProtocolDecl*)
Line
Count
Source
4285
3.82k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4286
3.82k
  // Note: This routine is implemented here because we need both NamedDecl
4287
3.82k
  // and Redeclarable to be defined.
4288
3.82k
  assert(RedeclLink.isFirst() &&
4289
3.82k
         "setPreviousDecl on a decl already in a redeclaration chain");
4290
3.82k
4291
3.82k
  if (PrevDecl) {
4292
386
    // Point to previous. Make sure that this is actually the most recent
4293
386
    // redeclaration, or we can build invalid chains. If the most recent
4294
386
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4295
386
    First = PrevDecl->getFirstDecl();
4296
386
    assert(First->RedeclLink.isFirst() && "Expected first");
4297
386
    decl_type *MostRecent = First->getNextRedeclaration();
4298
386
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4299
386
4300
386
    // If the declaration was previously visible, a redeclaration of it remains
4301
386
    // visible even if it wouldn't be visible by itself.
4302
386
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4303
386
      MostRecent->getIdentifierNamespace() &
4304
386
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4305
3.43k
  } else {
4306
3.43k
    // Make this first.
4307
3.43k
    First = static_cast<decl_type*>(this);
4308
3.43k
  }
4309
3.82k
4310
3.82k
  // First one will point to this one as latest.
4311
3.82k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4312
3.82k
4313
3.82k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4314
3.82k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4315
3.82k
}
4316
4317
// Inline function definitions.
4318
4319
/// Check if the given decl is complete.
4320
///
4321
/// We use this function to break a cycle between the inline definitions in
4322
/// Type.h and Decl.h.
4323
1.76M
inline bool IsEnumDeclComplete(EnumDecl *ED) {
4324
1.76M
  return ED->isComplete();
4325
1.76M
}
4326
4327
/// Check if the given decl is scoped.
4328
///
4329
/// We use this function to break a cycle between the inline definitions in
4330
/// Type.h and Decl.h.
4331
614k
inline bool IsEnumDeclScoped(EnumDecl *ED) {
4332
614k
  return ED->isScoped();
4333
614k
}
4334
4335
} // namespace clang
4336
4337
#endif // LLVM_CLANG_AST_DECL_H