clang  15.0.0git
Decl.h
Go to the documentation of this file.
1 //===- Decl.h - Classes for representing declarations -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the Decl subclasses.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_DECL_H
14 #define LLVM_CLANG_AST_DECL_H
15 
16 #include "clang/AST/APValue.h"
19 #include "clang/AST/DeclBase.h"
23 #include "clang/AST/Redeclarable.h"
24 #include "clang/AST/Type.h"
26 #include "clang/Basic/Diagnostic.h"
28 #include "clang/Basic/LLVM.h"
29 #include "clang/Basic/Linkage.h"
34 #include "clang/Basic/Specifiers.h"
35 #include "clang/Basic/Visibility.h"
36 #include "llvm/ADT/APSInt.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/Optional.h"
39 #include "llvm/ADT/PointerIntPair.h"
40 #include "llvm/ADT/PointerUnion.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/iterator_range.h"
43 #include "llvm/Support/Casting.h"
44 #include "llvm/Support/Compiler.h"
45 #include "llvm/Support/TrailingObjects.h"
46 #include <cassert>
47 #include <cstddef>
48 #include <cstdint>
49 #include <string>
50 #include <utility>
51 
52 namespace clang {
53 
54 class ASTContext;
55 struct ASTTemplateArgumentListInfo;
56 class CompoundStmt;
57 class DependentFunctionTemplateSpecializationInfo;
58 class EnumDecl;
59 class Expr;
60 class FunctionTemplateDecl;
61 class FunctionTemplateSpecializationInfo;
62 class FunctionTypeLoc;
63 class LabelStmt;
64 class MemberSpecializationInfo;
65 class Module;
66 class NamespaceDecl;
67 class ParmVarDecl;
68 class RecordDecl;
69 class Stmt;
70 class StringLiteral;
71 class TagDecl;
72 class TemplateArgumentList;
73 class TemplateArgumentListInfo;
74 class TemplateParameterList;
75 class TypeAliasTemplateDecl;
76 class UnresolvedSetImpl;
77 class VarTemplateDecl;
78 
79 /// The top declaration context.
80 class TranslationUnitDecl : public Decl,
81  public DeclContext,
82  public Redeclarable<TranslationUnitDecl> {
84 
85  TranslationUnitDecl *getNextRedeclarationImpl() override {
86  return getNextRedeclaration();
87  }
88 
89  TranslationUnitDecl *getPreviousDeclImpl() override {
90  return getPreviousDecl();
91  }
92 
93  TranslationUnitDecl *getMostRecentDeclImpl() override {
94  return getMostRecentDecl();
95  }
96 
97  ASTContext &Ctx;
98 
99  /// The (most recently entered) anonymous namespace for this
100  /// translation unit, if one has been created.
101  NamespaceDecl *AnonymousNamespace = nullptr;
102 
103  explicit TranslationUnitDecl(ASTContext &ctx);
104 
105  virtual void anchor();
106 
107 public:
109  using redecl_iterator = redeclarable_base::redecl_iterator;
110 
117 
118  ASTContext &getASTContext() const { return Ctx; }
119 
120  NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
121  void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
122 
124 
125  // Implement isa/cast/dyncast/etc.
126  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
127  static bool classofKind(Kind K) { return K == TranslationUnit; }
129  return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
130  }
132  return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
133  }
134 };
135 
136 /// Represents a `#pragma comment` line. Always a child of
137 /// TranslationUnitDecl.
138 class PragmaCommentDecl final
139  : public Decl,
140  private llvm::TrailingObjects<PragmaCommentDecl, char> {
141  friend class ASTDeclReader;
142  friend class ASTDeclWriter;
143  friend TrailingObjects;
144 
145  PragmaMSCommentKind CommentKind;
146 
148  PragmaMSCommentKind CommentKind)
149  : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
150 
151  virtual void anchor();
152 
153 public:
155  SourceLocation CommentLoc,
156  PragmaMSCommentKind CommentKind,
157  StringRef Arg);
159  unsigned ArgSize);
160 
161  PragmaMSCommentKind getCommentKind() const { return CommentKind; }
162 
163  StringRef getArg() const { return getTrailingObjects<char>(); }
164 
165  // Implement isa/cast/dyncast/etc.
166  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
167  static bool classofKind(Kind K) { return K == PragmaComment; }
168 };
169 
170 /// Represents a `#pragma detect_mismatch` line. Always a child of
171 /// TranslationUnitDecl.
173  : public Decl,
174  private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
175  friend class ASTDeclReader;
176  friend class ASTDeclWriter;
177  friend TrailingObjects;
178 
179  size_t ValueStart;
180 
182  size_t ValueStart)
183  : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
184 
185  virtual void anchor();
186 
187 public:
190  SourceLocation Loc, StringRef Name,
191  StringRef Value);
192  static PragmaDetectMismatchDecl *
193  CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
194 
195  StringRef getName() const { return getTrailingObjects<char>(); }
196  StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
197 
198  // Implement isa/cast/dyncast/etc.
199  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
200  static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
201 };
202 
203 /// Declaration context for names declared as extern "C" in C++. This
204 /// is neither the semantic nor lexical context for such declarations, but is
205 /// used to check for conflicts with other extern "C" declarations. Example:
206 ///
207 /// \code
208 /// namespace N { extern "C" void f(); } // #1
209 /// void N::f() {} // #2
210 /// namespace M { extern "C" void f(); } // #3
211 /// \endcode
212 ///
213 /// The semantic context of #1 is namespace N and its lexical context is the
214 /// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
215 /// context is the TU. However, both declarations are also visible in the
216 /// extern "C" context.
217 ///
218 /// The declaration at #3 finds it is a redeclaration of \c N::f through
219 /// lookup in the extern "C" context.
220 class ExternCContextDecl : public Decl, public DeclContext {
222  : Decl(ExternCContext, TU, SourceLocation()),
223  DeclContext(ExternCContext) {}
224 
225  virtual void anchor();
226 
227 public:
228  static ExternCContextDecl *Create(const ASTContext &C,
229  TranslationUnitDecl *TU);
230 
231  // Implement isa/cast/dyncast/etc.
232  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
233  static bool classofKind(Kind K) { return K == ExternCContext; }
235  return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
236  }
238  return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
239  }
240 };
241 
242 /// This represents a decl that may have a name. Many decls have names such
243 /// as ObjCMethodDecl, but not \@class, etc.
244 ///
245 /// Note that not every NamedDecl is actually named (e.g., a struct might
246 /// be anonymous), and not every name is an identifier.
247 class NamedDecl : public Decl {
248  /// The name of this declaration, which is typically a normal
249  /// identifier but may also be a special kind of name (C++
250  /// constructor, Objective-C selector, etc.)
251  DeclarationName Name;
252 
253  virtual void anchor();
254 
255 private:
256  NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
257 
258 protected:
260  : Decl(DK, DC, L), Name(N) {}
261 
262 public:
263  /// Get the identifier that names this declaration, if there is one.
264  ///
265  /// This will return NULL if this declaration has no name (e.g., for
266  /// an unnamed class) or if the name is a special name (C++ constructor,
267  /// Objective-C selector, etc.).
268  IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
269 
270  /// Get the name of identifier for this declaration as a StringRef.
271  ///
272  /// This requires that the declaration have a name and that it be a simple
273  /// identifier.
274  StringRef getName() const {
275  assert(Name.isIdentifier() && "Name is not a simple identifier");
276  return getIdentifier() ? getIdentifier()->getName() : "";
277  }
278 
279  /// Get a human-readable name for the declaration, even if it is one of the
280  /// special kinds of names (C++ constructor, Objective-C selector, etc).
281  ///
282  /// Creating this name requires expensive string manipulation, so it should
283  /// be called only when performance doesn't matter. For simple declarations,
284  /// getNameAsCString() should suffice.
285  //
286  // FIXME: This function should be renamed to indicate that it is not just an
287  // alternate form of getName(), and clients should move as appropriate.
288  //
289  // FIXME: Deprecated, move clients to getName().
290  std::string getNameAsString() const { return Name.getAsString(); }
291 
292  /// Pretty-print the unqualified name of this declaration. Can be overloaded
293  /// by derived classes to provide a more user-friendly name when appropriate.
294  virtual void printName(raw_ostream &os) const;
295 
296  /// Get the actual, stored name of the declaration, which may be a special
297  /// name.
298  ///
299  /// Note that generally in diagnostics, the non-null \p NamedDecl* itself
300  /// should be sent into the diagnostic instead of using the result of
301  /// \p getDeclName().
302  ///
303  /// A \p DeclarationName in a diagnostic will just be streamed to the output,
304  /// which will directly result in a call to \p DeclarationName::print.
305  ///
306  /// A \p NamedDecl* in a diagnostic will also ultimately result in a call to
307  /// \p DeclarationName::print, but with two customisation points along the
308  /// way (\p getNameForDiagnostic and \p printName). These are used to print
309  /// the template arguments if any, and to provide a user-friendly name for
310  /// some entities (such as unnamed variables and anonymous records).
311  DeclarationName getDeclName() const { return Name; }
312 
313  /// Set the name of this declaration.
314  void setDeclName(DeclarationName N) { Name = N; }
315 
316  /// Returns a human-readable qualified name for this declaration, like
317  /// A::B::i, for i being member of namespace A::B.
318  ///
319  /// If the declaration is not a member of context which can be named (record,
320  /// namespace), it will return the same result as printName().
321  ///
322  /// Creating this name is expensive, so it should be called only when
323  /// performance doesn't matter.
324  void printQualifiedName(raw_ostream &OS) const;
325  void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
326 
327  /// Print only the nested name specifier part of a fully-qualified name,
328  /// including the '::' at the end. E.g.
329  /// when `printQualifiedName(D)` prints "A::B::i",
330  /// this function prints "A::B::".
331  void printNestedNameSpecifier(raw_ostream &OS) const;
332  void printNestedNameSpecifier(raw_ostream &OS,
333  const PrintingPolicy &Policy) const;
334 
335  // FIXME: Remove string version.
337 
338  /// Appends a human-readable name for this declaration into the given stream.
339  ///
340  /// This is the method invoked by Sema when displaying a NamedDecl
341  /// in a diagnostic. It does not necessarily produce the same
342  /// result as printName(); for example, class template
343  /// specializations are printed with their template arguments.
344  virtual void getNameForDiagnostic(raw_ostream &OS,
345  const PrintingPolicy &Policy,
346  bool Qualified) const;
347 
348  /// Determine whether this declaration, if known to be well-formed within
349  /// its context, will replace the declaration OldD if introduced into scope.
350  ///
351  /// A declaration will replace another declaration if, for example, it is
352  /// a redeclaration of the same variable or function, but not if it is a
353  /// declaration of a different kind (function vs. class) or an overloaded
354  /// function.
355  ///
356  /// \param IsKnownNewer \c true if this declaration is known to be newer
357  /// than \p OldD (for instance, if this declaration is newly-created).
358  bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
359 
360  /// Determine whether this declaration has linkage.
361  bool hasLinkage() const;
362 
363  using Decl::isModulePrivate;
365 
366  /// Determine whether this declaration is a C++ class member.
367  bool isCXXClassMember() const {
368  const DeclContext *DC = getDeclContext();
369 
370  // C++0x [class.mem]p1:
371  // The enumerators of an unscoped enumeration defined in
372  // the class are members of the class.
373  if (isa<EnumDecl>(DC))
374  DC = DC->getRedeclContext();
375 
376  return DC->isRecord();
377  }
378 
379  /// Determine whether the given declaration is an instance member of
380  /// a C++ class.
381  bool isCXXInstanceMember() const;
382 
383  /// Determine if the declaration obeys the reserved identifier rules of the
384  /// given language.
385  ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
386 
387  /// Determine what kind of linkage this entity has.
388  ///
389  /// This is not the linkage as defined by the standard or the codegen notion
390  /// of linkage. It is just an implementation detail that is used to compute
391  /// those.
392  Linkage getLinkageInternal() const;
393 
394  /// Get the linkage from a semantic point of view. Entities in
395  /// anonymous namespaces are external (in c++98).
398  }
399 
400  /// True if this decl has external linkage.
403  }
404 
405  bool isExternallyVisible() const {
407  }
408 
409  /// Determine whether this declaration can be redeclared in a
410  /// different translation unit.
411  bool isExternallyDeclarable() const {
413  }
414 
415  /// Determines the visibility of this entity.
418  }
419 
420  /// Determines the linkage and visibility of this entity.
422 
423  /// Kinds of explicit visibility.
425  /// Do an LV computation for, ultimately, a type.
426  /// Visibility may be restricted by type visibility settings and
427  /// the visibility of template arguments.
429 
430  /// Do an LV computation for, ultimately, a non-type declaration.
431  /// Visibility may be restricted by value visibility settings and
432  /// the visibility of template arguments.
434  };
435 
436  /// If visibility was explicitly specified for this
437  /// declaration, return that visibility.
440 
441  /// True if the computed linkage is valid. Used for consistency
442  /// checking. Should always return true.
443  bool isLinkageValid() const;
444 
445  /// True if something has required us to compute the linkage
446  /// of this declaration.
447  ///
448  /// Language features which can retroactively change linkage (like a
449  /// typedef name for linkage purposes) may need to consider this,
450  /// but hopefully only in transitory ways during parsing.
451  bool hasLinkageBeenComputed() const {
452  return hasCachedLinkage();
453  }
454 
455  /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
456  /// the underlying named decl.
458  // Fast-path the common case.
459  if (this->getKind() != UsingShadow &&
460  this->getKind() != ConstructorUsingShadow &&
461  this->getKind() != ObjCCompatibleAlias &&
462  this->getKind() != NamespaceAlias)
463  return this;
464 
465  return getUnderlyingDeclImpl();
466  }
467  const NamedDecl *getUnderlyingDecl() const {
468  return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
469  }
470 
472  return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
473  }
474  const NamedDecl *getMostRecentDecl() const {
475  return const_cast<NamedDecl*>(this)->getMostRecentDecl();
476  }
477 
479 
480  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
481  static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
482 };
483 
484 inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
485  ND.printName(OS);
486  return OS;
487 }
488 
489 /// Represents the declaration of a label. Labels also have a
490 /// corresponding LabelStmt, which indicates the position that the label was
491 /// defined at. For normal labels, the location of the decl is the same as the
492 /// location of the statement. For GNU local labels (__label__), the decl
493 /// location is where the __label__ is.
494 class LabelDecl : public NamedDecl {
495  LabelStmt *TheStmt;
496  StringRef MSAsmName;
497  bool MSAsmNameResolved = false;
498 
499  /// For normal labels, this is the same as the main declaration
500  /// label, i.e., the location of the identifier; for GNU local labels,
501  /// this is the location of the __label__ keyword.
502  SourceLocation LocStart;
503 
505  LabelStmt *S, SourceLocation StartL)
506  : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
507 
508  void anchor() override;
509 
510 public:
511  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
512  SourceLocation IdentL, IdentifierInfo *II);
513  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
514  SourceLocation IdentL, IdentifierInfo *II,
515  SourceLocation GnuLabelL);
516  static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
517 
518  LabelStmt *getStmt() const { return TheStmt; }
519  void setStmt(LabelStmt *T) { TheStmt = T; }
520 
521  bool isGnuLocal() const { return LocStart != getLocation(); }
522  void setLocStart(SourceLocation L) { LocStart = L; }
523 
524  SourceRange getSourceRange() const override LLVM_READONLY {
525  return SourceRange(LocStart, getLocation());
526  }
527 
528  bool isMSAsmLabel() const { return !MSAsmName.empty(); }
529  bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
530  void setMSAsmLabel(StringRef Name);
531  StringRef getMSAsmLabel() const { return MSAsmName; }
532  void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
533 
534  // Implement isa/cast/dyncast/etc.
535  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
536  static bool classofKind(Kind K) { return K == Label; }
537 };
538 
539 /// Represent a C++ namespace.
540 class NamespaceDecl : public NamedDecl, public DeclContext,
541  public Redeclarable<NamespaceDecl>
542 {
543  /// The starting location of the source range, pointing
544  /// to either the namespace or the inline keyword.
545  SourceLocation LocStart;
546 
547  /// The ending location of the source range.
548  SourceLocation RBraceLoc;
549 
550  /// A pointer to either the anonymous namespace that lives just inside
551  /// this namespace or to the first namespace in the chain (the latter case
552  /// only when this is not the first in the chain), along with a
553  /// boolean value indicating whether this is an inline namespace.
554  llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
555 
556  NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
557  SourceLocation StartLoc, SourceLocation IdLoc,
558  IdentifierInfo *Id, NamespaceDecl *PrevDecl);
559 
561 
562  NamespaceDecl *getNextRedeclarationImpl() override;
563  NamespaceDecl *getPreviousDeclImpl() override;
564  NamespaceDecl *getMostRecentDeclImpl() override;
565 
566 public:
567  friend class ASTDeclReader;
568  friend class ASTDeclWriter;
569 
571  bool Inline, SourceLocation StartLoc,
573  NamespaceDecl *PrevDecl);
574 
575  static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
576 
578  using redecl_iterator = redeclarable_base::redecl_iterator;
579 
586 
587  /// Returns true if this is an anonymous namespace declaration.
588  ///
589  /// For example:
590  /// \code
591  /// namespace {
592  /// ...
593  /// };
594  /// \endcode
595  /// q.v. C++ [namespace.unnamed]
596  bool isAnonymousNamespace() const {
597  return !getIdentifier();
598  }
599 
600  /// Returns true if this is an inline namespace declaration.
601  bool isInline() const {
602  return AnonOrFirstNamespaceAndInline.getInt();
603  }
604 
605  /// Set whether this is an inline namespace declaration.
606  void setInline(bool Inline) {
607  AnonOrFirstNamespaceAndInline.setInt(Inline);
608  }
609 
610  /// Returns true if the inline qualifier for \c Name is redundant.
612  if (!isInline())
613  return false;
614  auto X = lookup(Name);
615  // We should not perform a lookup within a transparent context, so find a
616  // non-transparent parent context.
617  auto Y = getParent()->getNonTransparentContext()->lookup(Name);
618  return std::distance(X.begin(), X.end()) ==
619  std::distance(Y.begin(), Y.end());
620  }
621 
622  /// Get the original (first) namespace declaration.
624 
625  /// Get the original (first) namespace declaration.
626  const NamespaceDecl *getOriginalNamespace() const;
627 
628  /// Return true if this declaration is an original (first) declaration
629  /// of the namespace. This is false for non-original (subsequent) namespace
630  /// declarations and anonymous namespaces.
631  bool isOriginalNamespace() const;
632 
633  /// Retrieve the anonymous namespace nested inside this namespace,
634  /// if any.
636  return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
637  }
638 
640  getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
641  }
642 
643  /// Retrieves the canonical declaration of this namespace.
645  return getOriginalNamespace();
646  }
648  return getOriginalNamespace();
649  }
650 
651  SourceRange getSourceRange() const override LLVM_READONLY {
652  return SourceRange(LocStart, RBraceLoc);
653  }
654 
655  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
656  SourceLocation getRBraceLoc() const { return RBraceLoc; }
657  void setLocStart(SourceLocation L) { LocStart = L; }
658  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
659 
660  // Implement isa/cast/dyncast/etc.
661  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
662  static bool classofKind(Kind K) { return K == Namespace; }
664  return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
665  }
667  return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
668  }
669 };
670 
671 /// Represent the declaration of a variable (in which case it is
672 /// an lvalue) a function (in which case it is a function designator) or
673 /// an enum constant.
674 class ValueDecl : public NamedDecl {
675  QualType DeclType;
676 
677  void anchor() override;
678 
679 protected:
682  : NamedDecl(DK, DC, L, N), DeclType(T) {}
683 
684 public:
685  QualType getType() const { return DeclType; }
686  void setType(QualType newType) { DeclType = newType; }
687 
688  /// Determine whether this symbol is weakly-imported,
689  /// or declared with the weak or weak-ref attr.
690  bool isWeak() const;
691 
692  // Implement isa/cast/dyncast/etc.
693  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
694  static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
695 };
696 
697 /// A struct with extended info about a syntactic
698 /// name qualifier, to be used for the case of out-of-line declarations.
701 
702  /// The number of "outer" template parameter lists.
703  /// The count includes all of the template parameter lists that were matched
704  /// against the template-ids occurring into the NNS and possibly (in the
705  /// case of an explicit specialization) a final "template <>".
706  unsigned NumTemplParamLists = 0;
707 
708  /// A new-allocated array of size NumTemplParamLists,
709  /// containing pointers to the "outer" template parameter lists.
710  /// It includes all of the template parameter lists that were matched
711  /// against the template-ids occurring into the NNS and possibly (in the
712  /// case of an explicit specialization) a final "template <>".
714 
715  QualifierInfo() = default;
716  QualifierInfo(const QualifierInfo &) = delete;
717  QualifierInfo& operator=(const QualifierInfo &) = delete;
718 
719  /// Sets info about "outer" template parameter lists.
722 };
723 
724 /// Represents a ValueDecl that came out of a declarator.
725 /// Contains type source information through TypeSourceInfo.
726 class DeclaratorDecl : public ValueDecl {
727  // A struct representing a TInfo, a trailing requires-clause and a syntactic
728  // qualifier, to be used for the (uncommon) case of out-of-line declarations
729  // and constrained function decls.
730  struct ExtInfo : public QualifierInfo {
731  TypeSourceInfo *TInfo;
732  Expr *TrailingRequiresClause = nullptr;
733  };
734 
735  llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
736 
737  /// The start of the source range for this declaration,
738  /// ignoring outer template declarations.
739  SourceLocation InnerLocStart;
740 
741  bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
742  ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
743  const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
744 
745 protected:
748  SourceLocation StartL)
749  : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
750 
751 public:
752  friend class ASTDeclReader;
753  friend class ASTDeclWriter;
754 
756  return hasExtInfo()
757  ? getExtInfo()->TInfo
758  : DeclInfo.get<TypeSourceInfo*>();
759  }
760 
762  if (hasExtInfo())
763  getExtInfo()->TInfo = TI;
764  else
765  DeclInfo = TI;
766  }
767 
768  /// Return start of source range ignoring outer template declarations.
769  SourceLocation getInnerLocStart() const { return InnerLocStart; }
770  void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
771 
772  /// Return start of source range taking into account any outer template
773  /// declarations.
775 
776  SourceRange getSourceRange() const override LLVM_READONLY;
777 
778  SourceLocation getBeginLoc() const LLVM_READONLY {
779  return getOuterLocStart();
780  }
781 
782  /// Retrieve the nested-name-specifier that qualifies the name of this
783  /// declaration, if it was present in the source.
785  return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
786  : nullptr;
787  }
788 
789  /// Retrieve the nested-name-specifier (with source-location
790  /// information) that qualifies the name of this declaration, if it was
791  /// present in the source.
793  return hasExtInfo() ? getExtInfo()->QualifierLoc
795  }
796 
797  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
798 
799  /// \brief Get the constraint-expression introduced by the trailing
800  /// requires-clause in the function/member declaration, or null if no
801  /// requires-clause was provided.
803  return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
804  : nullptr;
805  }
806 
808  return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
809  : nullptr;
810  }
811 
812  void setTrailingRequiresClause(Expr *TrailingRequiresClause);
813 
814  unsigned getNumTemplateParameterLists() const {
815  return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
816  }
817 
819  assert(index < getNumTemplateParameterLists());
820  return getExtInfo()->TemplParamLists[index];
821  }
822 
825 
828 
829  // Implement isa/cast/dyncast/etc.
830  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
831  static bool classofKind(Kind K) {
832  return K >= firstDeclarator && K <= lastDeclarator;
833  }
834 };
835 
836 /// Structure used to store a statement, the constant value to
837 /// which it was evaluated (if any), and whether or not the statement
838 /// is an integral constant expression (if known).
840  /// Whether this statement was already evaluated.
841  bool WasEvaluated : 1;
842 
843  /// Whether this statement is being evaluated.
844  bool IsEvaluating : 1;
845 
846  /// Whether this variable is known to have constant initialization. This is
847  /// currently only computed in C++, for static / thread storage duration
848  /// variables that might have constant initialization and for variables that
849  /// are usable in constant expressions.
851 
852  /// Whether this variable is known to have constant destruction. That is,
853  /// whether running the destructor on the initial value is a side-effect
854  /// (and doesn't inspect any state that might have changed during program
855  /// execution). This is currently only computed if the destructor is
856  /// non-trivial.
858 
859  /// In C++98, whether the initializer is an ICE. This affects whether the
860  /// variable is usable in constant expressions.
861  bool HasICEInit : 1;
863 
866 
871 };
872 
873 /// Represents a variable declaration or definition.
874 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
875 public:
876  /// Initialization styles.
878  /// C-style initialization with assignment
880 
881  /// Call-style initialization (C++98)
883 
884  /// Direct list-initialization (C++11)
886  };
887 
888  /// Kinds of thread-local storage.
889  enum TLSKind {
890  /// Not a TLS variable.
892 
893  /// TLS with a known-constant initializer.
895 
896  /// TLS with a dynamic initializer.
898  };
899 
900  /// Return the string used to specify the storage class \p SC.
901  ///
902  /// It is illegal to call this function with SC == None.
903  static const char *getStorageClassSpecifierString(StorageClass SC);
904 
905 protected:
906  // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
907  // have allocated the auxiliary struct of information there.
908  //
909  // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
910  // this as *many* VarDecls are ParmVarDecls that don't have default
911  // arguments. We could save some space by moving this pointer union to be
912  // allocated in trailing space when necessary.
913  using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
914 
915  /// The initializer for this variable or, for a ParmVarDecl, the
916  /// C++ default argument.
917  mutable InitType Init;
918 
919 private:
920  friend class ASTDeclReader;
921  friend class ASTNodeImporter;
922  friend class StmtIteratorBase;
923 
924  class VarDeclBitfields {
925  friend class ASTDeclReader;
926  friend class VarDecl;
927 
928  unsigned SClass : 3;
929  unsigned TSCSpec : 2;
930  unsigned InitStyle : 2;
931 
932  /// Whether this variable is an ARC pseudo-__strong variable; see
933  /// isARCPseudoStrong() for details.
934  unsigned ARCPseudoStrong : 1;
935  };
936  enum { NumVarDeclBits = 8 };
937 
938 protected:
939  enum { NumParameterIndexBits = 8 };
940 
946  };
947 
949 
951  friend class ASTDeclReader;
952  friend class ParmVarDecl;
953 
954  unsigned : NumVarDeclBits;
955 
956  /// Whether this parameter inherits a default argument from a
957  /// prior declaration.
958  unsigned HasInheritedDefaultArg : 1;
959 
960  /// Describes the kind of default argument for this parameter. By default
961  /// this is none. If this is normal, then the default argument is stored in
962  /// the \c VarDecl initializer expression unless we were unable to parse
963  /// (even an invalid) expression for the default argument.
964  unsigned DefaultArgKind : 2;
965 
966  /// Whether this parameter undergoes K&R argument promotion.
967  unsigned IsKNRPromoted : 1;
968 
969  /// Whether this parameter is an ObjC method parameter or not.
970  unsigned IsObjCMethodParam : 1;
971 
972  /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
973  /// Otherwise, the number of function parameter scopes enclosing
974  /// the function parameter scope in which this parameter was
975  /// declared.
976  unsigned ScopeDepthOrObjCQuals : NumScopeDepthOrObjCQualsBits;
977 
978  /// The number of parameters preceding this parameter in the
979  /// function parameter scope in which it was declared.
980  unsigned ParameterIndex : NumParameterIndexBits;
981  };
982 
984  friend class ASTDeclReader;
985  friend class ImplicitParamDecl;
986  friend class VarDecl;
987 
988  unsigned : NumVarDeclBits;
989 
990  // FIXME: We need something similar to CXXRecordDecl::DefinitionData.
991  /// Whether this variable is a definition which was demoted due to
992  /// module merge.
993  unsigned IsThisDeclarationADemotedDefinition : 1;
994 
995  /// Whether this variable is the exception variable in a C++ catch
996  /// or an Objective-C @catch statement.
997  unsigned ExceptionVar : 1;
998 
999  /// Whether this local variable could be allocated in the return
1000  /// slot of its function, enabling the named return value optimization
1001  /// (NRVO).
1002  unsigned NRVOVariable : 1;
1003 
1004  /// Whether this variable is the for-range-declaration in a C++0x
1005  /// for-range statement.
1006  unsigned CXXForRangeDecl : 1;
1007 
1008  /// Whether this variable is the for-in loop declaration in Objective-C.
1009  unsigned ObjCForDecl : 1;
1010 
1011  /// Whether this variable is (C++1z) inline.
1012  unsigned IsInline : 1;
1013 
1014  /// Whether this variable has (C++1z) inline explicitly specified.
1015  unsigned IsInlineSpecified : 1;
1016 
1017  /// Whether this variable is (C++0x) constexpr.
1018  unsigned IsConstexpr : 1;
1019 
1020  /// Whether this variable is the implicit variable for a lambda
1021  /// init-capture.
1022  unsigned IsInitCapture : 1;
1023 
1024  /// Whether this local extern variable's previous declaration was
1025  /// declared in the same block scope. This controls whether we should merge
1026  /// the type of this declaration with its previous declaration.
1027  unsigned PreviousDeclInSameBlockScope : 1;
1028 
1029  /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
1030  /// something else.
1031  unsigned ImplicitParamKind : 3;
1032 
1033  unsigned EscapingByref : 1;
1034  };
1035 
1036  union {
1037  unsigned AllBits;
1038  VarDeclBitfields VarDeclBits;
1041  };
1042 
1043  VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1044  SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1045  TypeSourceInfo *TInfo, StorageClass SC);
1046 
1048 
1050  return getNextRedeclaration();
1051  }
1052 
1054  return getPreviousDecl();
1055  }
1056 
1058  return getMostRecentDecl();
1059  }
1060 
1061 public:
1063  using redecl_iterator = redeclarable_base::redecl_iterator;
1064 
1071 
1072  static VarDecl *Create(ASTContext &C, DeclContext *DC,
1073  SourceLocation StartLoc, SourceLocation IdLoc,
1074  const IdentifierInfo *Id, QualType T,
1075  TypeSourceInfo *TInfo, StorageClass S);
1076 
1077  static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1078 
1079  SourceRange getSourceRange() const override LLVM_READONLY;
1080 
1081  /// Returns the storage class as written in the source. For the
1082  /// computed linkage of symbol, see getLinkage.
1084  return (StorageClass) VarDeclBits.SClass;
1085  }
1086  void setStorageClass(StorageClass SC);
1087 
1089  VarDeclBits.TSCSpec = TSC;
1090  assert(VarDeclBits.TSCSpec == TSC && "truncation");
1091  }
1093  return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1094  }
1095  TLSKind getTLSKind() const;
1096 
1097  /// Returns true if a variable with function scope is a non-static local
1098  /// variable.
1099  bool hasLocalStorage() const {
1100  if (getStorageClass() == SC_None) {
1101  // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1102  // used to describe variables allocated in global memory and which are
1103  // accessed inside a kernel(s) as read-only variables. As such, variables
1104  // in constant address space cannot have local storage.
1105  if (getType().getAddressSpace() == LangAS::opencl_constant)
1106  return false;
1107  // Second check is for C++11 [dcl.stc]p4.
1108  return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
1109  }
1110 
1111  // Global Named Register (GNU extension)
1113  return false;
1114 
1115  // Return true for: Auto, Register.
1116  // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1117 
1118  return getStorageClass() >= SC_Auto;
1119  }
1120 
1121  /// Returns true if a variable with function scope is a static local
1122  /// variable.
1123  bool isStaticLocal() const {
1124  return (getStorageClass() == SC_Static ||
1125  // C++11 [dcl.stc]p4
1127  && !isFileVarDecl();
1128  }
1129 
1130  /// Returns true if a variable has extern or __private_extern__
1131  /// storage.
1132  bool hasExternalStorage() const {
1133  return getStorageClass() == SC_Extern ||
1135  }
1136 
1137  /// Returns true for all variables that do not have local storage.
1138  ///
1139  /// This includes all global variables as well as static variables declared
1140  /// within a function.
1141  bool hasGlobalStorage() const { return !hasLocalStorage(); }
1142 
1143  /// Get the storage duration of this variable, per C++ [basic.stc].
1145  return hasLocalStorage() ? SD_Automatic :
1147  }
1148 
1149  /// Compute the language linkage.
1151 
1152  /// Determines whether this variable is a variable with external, C linkage.
1153  bool isExternC() const;
1154 
1155  /// Determines whether this variable's context is, or is nested within,
1156  /// a C++ extern "C" linkage spec.
1157  bool isInExternCContext() const;
1158 
1159  /// Determines whether this variable's context is, or is nested within,
1160  /// a C++ extern "C++" linkage spec.
1161  bool isInExternCXXContext() const;
1162 
1163  /// Returns true for local variable declarations other than parameters.
1164  /// Note that this includes static variables inside of functions. It also
1165  /// includes variables inside blocks.
1166  ///
1167  /// void foo() { int x; static int y; extern int z; }
1168  bool isLocalVarDecl() const {
1169  if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1170  return false;
1171  if (const DeclContext *DC = getLexicalDeclContext())
1172  return DC->getRedeclContext()->isFunctionOrMethod();
1173  return false;
1174  }
1175 
1176  /// Similar to isLocalVarDecl but also includes parameters.
1177  bool isLocalVarDeclOrParm() const {
1178  return isLocalVarDecl() || getKind() == Decl::ParmVar;
1179  }
1180 
1181  /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1183  if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1184  return false;
1186  return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
1187  }
1188 
1189  /// Determines whether this is a static data member.
1190  ///
1191  /// This will only be true in C++, and applies to, e.g., the
1192  /// variable 'x' in:
1193  /// \code
1194  /// struct S {
1195  /// static int x;
1196  /// };
1197  /// \endcode
1198  bool isStaticDataMember() const {
1199  // If it wasn't static, it would be a FieldDecl.
1200  return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
1201  }
1202 
1203  VarDecl *getCanonicalDecl() override;
1204  const VarDecl *getCanonicalDecl() const {
1205  return const_cast<VarDecl*>(this)->getCanonicalDecl();
1206  }
1207 
1209  /// This declaration is only a declaration.
1211 
1212  /// This declaration is a tentative definition.
1214 
1215  /// This declaration is definitely a definition.
1217  };
1218 
1219  /// Check whether this declaration is a definition. If this could be
1220  /// a tentative definition (in C), don't check whether there's an overriding
1221  /// definition.
1225  }
1226 
1227  /// Check whether this variable is defined in this translation unit.
1230  return hasDefinition(getASTContext());
1231  }
1232 
1233  /// Get the tentative definition that acts as the real definition in a TU.
1234  /// Returns null if there is a proper definition available.
1236  const VarDecl *getActingDefinition() const {
1237  return const_cast<VarDecl*>(this)->getActingDefinition();
1238  }
1239 
1240  /// Get the real (not just tentative) definition for this declaration.
1242  const VarDecl *getDefinition(ASTContext &C) const {
1243  return const_cast<VarDecl*>(this)->getDefinition(C);
1244  }
1246  return getDefinition(getASTContext());
1247  }
1248  const VarDecl *getDefinition() const {
1249  return const_cast<VarDecl*>(this)->getDefinition();
1250  }
1251 
1252  /// Determine whether this is or was instantiated from an out-of-line
1253  /// definition of a static data member.
1254  bool isOutOfLine() const override;
1255 
1256  /// Returns true for file scoped variable declaration.
1257  bool isFileVarDecl() const {
1258  Kind K = getKind();
1259  if (K == ParmVar || K == ImplicitParam)
1260  return false;
1261 
1262  if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1263  return true;
1264 
1265  if (isStaticDataMember())
1266  return true;
1267 
1268  return false;
1269  }
1270 
1271  /// Get the initializer for this variable, no matter which
1272  /// declaration it is attached to.
1273  const Expr *getAnyInitializer() const {
1274  const VarDecl *D;
1275  return getAnyInitializer(D);
1276  }
1277 
1278  /// Get the initializer for this variable, no matter which
1279  /// declaration it is attached to. Also get that declaration.
1280  const Expr *getAnyInitializer(const VarDecl *&D) const;
1281 
1282  bool hasInit() const;
1283  const Expr *getInit() const {
1284  return const_cast<VarDecl *>(this)->getInit();
1285  }
1286  Expr *getInit();
1287 
1288  /// Retrieve the address of the initializer expression.
1289  Stmt **getInitAddress();
1290 
1291  void setInit(Expr *I);
1292 
1293  /// Get the initializing declaration of this variable, if any. This is
1294  /// usually the definition, except that for a static data member it can be
1295  /// the in-class declaration.
1298  return const_cast<VarDecl *>(this)->getInitializingDeclaration();
1299  }
1300 
1301  /// Determine whether this variable's value might be usable in a
1302  /// constant expression, according to the relevant language standard.
1303  /// This only checks properties of the declaration, and does not check
1304  /// whether the initializer is in fact a constant expression.
1305  ///
1306  /// This corresponds to C++20 [expr.const]p3's notion of a
1307  /// "potentially-constant" variable.
1308  bool mightBeUsableInConstantExpressions(const ASTContext &C) const;
1309 
1310  /// Determine whether this variable's value can be used in a
1311  /// constant expression, according to the relevant language standard,
1312  /// including checking whether it was initialized by a constant expression.
1313  bool isUsableInConstantExpressions(const ASTContext &C) const;
1314 
1317 
1318  /// Attempt to evaluate the value of the initializer attached to this
1319  /// declaration, and produce notes explaining why it cannot be evaluated.
1320  /// Returns a pointer to the value if evaluation succeeded, 0 otherwise.
1321  APValue *evaluateValue() const;
1322 
1323 private:
1324  APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
1325  bool IsConstantInitialization) const;
1326 
1327 public:
1328  /// Return the already-evaluated value of this variable's
1329  /// initializer, or NULL if the value is not yet known. Returns pointer
1330  /// to untyped APValue if the value could not be evaluated.
1331  APValue *getEvaluatedValue() const;
1332 
1333  /// Evaluate the destruction of this variable to determine if it constitutes
1334  /// constant destruction.
1335  ///
1336  /// \pre hasConstantInitialization()
1337  /// \return \c true if this variable has constant destruction, \c false if
1338  /// not.
1340 
1341  /// Determine whether this variable has constant initialization.
1342  ///
1343  /// This is only set in two cases: when the language semantics require
1344  /// constant initialization (globals in C and some globals in C++), and when
1345  /// the variable is usable in constant expressions (constexpr, const int, and
1346  /// reference variables in C++).
1347  bool hasConstantInitialization() const;
1348 
1349  /// Determine whether the initializer of this variable is an integer constant
1350  /// expression. For use in C++98, where this affects whether the variable is
1351  /// usable in constant expressions.
1352  bool hasICEInitializer(const ASTContext &Context) const;
1353 
1354  /// Evaluate the initializer of this variable to determine whether it's a
1355  /// constant initializer. Should only be called once, after completing the
1356  /// definition of the variable.
1359 
1361  VarDeclBits.InitStyle = Style;
1362  }
1363 
1364  /// The style of initialization for this declaration.
1365  ///
1366  /// C-style initialization is "int x = 1;". Call-style initialization is
1367  /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1368  /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1369  /// expression for class types. List-style initialization is C++11 syntax,
1370  /// e.g. "int x{1};". Clients can distinguish between different forms of
1371  /// initialization by checking this value. In particular, "int x = {1};" is
1372  /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1373  /// Init expression in all three cases is an InitListExpr.
1375  return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1376  }
1377 
1378  /// Whether the initializer is a direct-initializer (list or call).
1379  bool isDirectInit() const {
1380  return getInitStyle() != CInit;
1381  }
1382 
1383  /// If this definition should pretend to be a declaration.
1385  return isa<ParmVarDecl>(this) ? false :
1386  NonParmVarDeclBits.IsThisDeclarationADemotedDefinition;
1387  }
1388 
1389  /// This is a definition which should be demoted to a declaration.
1390  ///
1391  /// In some cases (mostly module merging) we can end up with two visible
1392  /// definitions one of which needs to be demoted to a declaration to keep
1393  /// the AST invariants.
1395  assert(isThisDeclarationADefinition() && "Not a definition!");
1396  assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1397  NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1398  }
1399 
1400  /// Determine whether this variable is the exception variable in a
1401  /// C++ catch statememt or an Objective-C \@catch statement.
1402  bool isExceptionVariable() const {
1403  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar;
1404  }
1405  void setExceptionVariable(bool EV) {
1406  assert(!isa<ParmVarDecl>(this));
1407  NonParmVarDeclBits.ExceptionVar = EV;
1408  }
1409 
1410  /// Determine whether this local variable can be used with the named
1411  /// return value optimization (NRVO).
1412  ///
1413  /// The named return value optimization (NRVO) works by marking certain
1414  /// non-volatile local variables of class type as NRVO objects. These
1415  /// locals can be allocated within the return slot of their containing
1416  /// function, in which case there is no need to copy the object to the
1417  /// return slot when returning from the function. Within the function body,
1418  /// each return that returns the NRVO object will have this variable as its
1419  /// NRVO candidate.
1420  bool isNRVOVariable() const {
1421  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;
1422  }
1423  void setNRVOVariable(bool NRVO) {
1424  assert(!isa<ParmVarDecl>(this));
1425  NonParmVarDeclBits.NRVOVariable = NRVO;
1426  }
1427 
1428  /// Determine whether this variable is the for-range-declaration in
1429  /// a C++0x for-range statement.
1430  bool isCXXForRangeDecl() const {
1431  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl;
1432  }
1433  void setCXXForRangeDecl(bool FRD) {
1434  assert(!isa<ParmVarDecl>(this));
1435  NonParmVarDeclBits.CXXForRangeDecl = FRD;
1436  }
1437 
1438  /// Determine whether this variable is a for-loop declaration for a
1439  /// for-in statement in Objective-C.
1440  bool isObjCForDecl() const {
1441  return NonParmVarDeclBits.ObjCForDecl;
1442  }
1443 
1444  void setObjCForDecl(bool FRD) {
1445  NonParmVarDeclBits.ObjCForDecl = FRD;
1446  }
1447 
1448  /// Determine whether this variable is an ARC pseudo-__strong variable. A
1449  /// pseudo-__strong variable has a __strong-qualified type but does not
1450  /// actually retain the object written into it. Generally such variables are
1451  /// also 'const' for safety. There are 3 cases where this will be set, 1) if
1452  /// the variable is annotated with the objc_externally_retained attribute, 2)
1453  /// if its 'self' in a non-init method, or 3) if its the variable in an for-in
1454  /// loop.
1455  bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
1456  void setARCPseudoStrong(bool PS) { VarDeclBits.ARCPseudoStrong = PS; }
1457 
1458  /// Whether this variable is (C++1z) inline.
1459  bool isInline() const {
1460  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline;
1461  }
1462  bool isInlineSpecified() const {
1463  return isa<ParmVarDecl>(this) ? false
1464  : NonParmVarDeclBits.IsInlineSpecified;
1465  }
1467  assert(!isa<ParmVarDecl>(this));
1468  NonParmVarDeclBits.IsInline = true;
1469  NonParmVarDeclBits.IsInlineSpecified = true;
1470  }
1472  assert(!isa<ParmVarDecl>(this));
1473  NonParmVarDeclBits.IsInline = true;
1474  }
1475 
1476  /// Whether this variable is (C++11) constexpr.
1477  bool isConstexpr() const {
1478  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr;
1479  }
1480  void setConstexpr(bool IC) {
1481  assert(!isa<ParmVarDecl>(this));
1482  NonParmVarDeclBits.IsConstexpr = IC;
1483  }
1484 
1485  /// Whether this variable is the implicit variable for a lambda init-capture.
1486  bool isInitCapture() const {
1487  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
1488  }
1489  void setInitCapture(bool IC) {
1490  assert(!isa<ParmVarDecl>(this));
1491  NonParmVarDeclBits.IsInitCapture = IC;
1492  }
1493 
1494  /// Determine whether this variable is actually a function parameter pack or
1495  /// init-capture pack.
1496  bool isParameterPack() const;
1497 
1498  /// Whether this local extern variable declaration's previous declaration
1499  /// was declared in the same block scope. Only correct in C++.
1501  return isa<ParmVarDecl>(this)
1502  ? false
1503  : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1504  }
1506  assert(!isa<ParmVarDecl>(this));
1507  NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1508  }
1509 
1510  /// Indicates the capture is a __block variable that is captured by a block
1511  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
1512  /// returns false).
1513  bool isEscapingByref() const;
1514 
1515  /// Indicates the capture is a __block variable that is never captured by an
1516  /// escaping block.
1517  bool isNonEscapingByref() const;
1518 
1520  NonParmVarDeclBits.EscapingByref = true;
1521  }
1522 
1523  /// Determines if this variable's alignment is dependent.
1524  bool hasDependentAlignment() const;
1525 
1526  /// Retrieve the variable declaration from which this variable could
1527  /// be instantiated, if it is an instantiation (rather than a non-template).
1529 
1530  /// If this variable is an instantiated static data member of a
1531  /// class template specialization, returns the templated static data member
1532  /// from which it was instantiated.
1534 
1535  /// If this variable is an instantiation of a variable template or a
1536  /// static data member of a class template, determine what kind of
1537  /// template specialization or instantiation this is.
1539 
1540  /// Get the template specialization kind of this variable for the purposes of
1541  /// template instantiation. This differs from getTemplateSpecializationKind()
1542  /// for an instantiation of a class-scope explicit specialization.
1545 
1546  /// If this variable is an instantiation of a variable template or a
1547  /// static data member of a class template, determine its point of
1548  /// instantiation.
1550 
1551  /// If this variable is an instantiation of a static data member of a
1552  /// class template specialization, retrieves the member specialization
1553  /// information.
1555 
1556  /// For a static data member that was instantiated from a static
1557  /// data member of a class template, set the template specialiation kind.
1559  SourceLocation PointOfInstantiation = SourceLocation());
1560 
1561  /// Specify that this variable is an instantiation of the
1562  /// static data member VD.
1565 
1566  /// Retrieves the variable template that is described by this
1567  /// variable declaration.
1568  ///
1569  /// Every variable template is represented as a VarTemplateDecl and a
1570  /// VarDecl. The former contains template properties (such as
1571  /// the template parameter lists) while the latter contains the
1572  /// actual description of the template's
1573  /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1574  /// VarDecl that from a VarTemplateDecl, while
1575  /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1576  /// a VarDecl.
1578 
1579  void setDescribedVarTemplate(VarTemplateDecl *Template);
1580 
1581  // Is this variable known to have a definition somewhere in the complete
1582  // program? This may be true even if the declaration has internal linkage and
1583  // has no definition within this source file.
1584  bool isKnownToBeDefined() const;
1585 
1586  /// Is destruction of this variable entirely suppressed? If so, the variable
1587  /// need not have a usable destructor at all.
1588  bool isNoDestroy(const ASTContext &) const;
1589 
1590  /// Would the destruction of this variable have any effect, and if so, what
1591  /// kind?
1593 
1594  /// Whether this variable has a flexible array member initialized with one
1595  /// or more elements. This can only be called for declarations where
1596  /// hasInit() is true.
1597  ///
1598  /// (The standard doesn't allow initializing flexible array members; this is
1599  /// a gcc/msvc extension.)
1600  bool hasFlexibleArrayInit(const ASTContext &Ctx) const;
1601 
1602  /// If hasFlexibleArrayInit is true, compute the number of additional bytes
1603  /// necessary to store those elements. Otherwise, returns zero.
1604  ///
1605  /// This can only be called for declarations where hasInit() is true.
1607 
1608  // Implement isa/cast/dyncast/etc.
1609  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1610  static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1611 };
1612 
1613 class ImplicitParamDecl : public VarDecl {
1614  void anchor() override;
1615 
1616 public:
1617  /// Defines the kind of the implicit parameter: is this an implicit parameter
1618  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1619  /// context or something else.
1620  enum ImplicitParamKind : unsigned {
1621  /// Parameter for Objective-C 'self' argument
1623 
1624  /// Parameter for Objective-C '_cmd' argument
1626 
1627  /// Parameter for C++ 'this' argument
1629 
1630  /// Parameter for C++ virtual table pointers
1632 
1633  /// Parameter for captured context
1635 
1636  /// Parameter for Thread private variable
1638 
1639  /// Other implicit parameter
1641  };
1642 
1643  /// Create implicit parameter.
1646  QualType T, ImplicitParamKind ParamKind);
1648  ImplicitParamKind ParamKind);
1649 
1650  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1651 
1654  ImplicitParamKind ParamKind)
1655  : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1656  /*TInfo=*/nullptr, SC_None) {
1657  NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1658  setImplicit();
1659  }
1660 
1662  : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1663  SourceLocation(), /*Id=*/nullptr, Type,
1664  /*TInfo=*/nullptr, SC_None) {
1665  NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1666  setImplicit();
1667  }
1668 
1669  /// Returns the implicit parameter kind.
1671  return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1672  }
1673 
1674  // Implement isa/cast/dyncast/etc.
1675  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1676  static bool classofKind(Kind K) { return K == ImplicitParam; }
1677 };
1678 
1679 /// Represents a parameter to a function.
1680 class ParmVarDecl : public VarDecl {
1681 public:
1682  enum { MaxFunctionScopeDepth = 255 };
1683  enum { MaxFunctionScopeIndex = 255 };
1684 
1685 protected:
1688  TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1689  : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1690  assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1691  assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1692  assert(ParmVarDeclBits.IsKNRPromoted == false);
1693  assert(ParmVarDeclBits.IsObjCMethodParam == false);
1694  setDefaultArg(DefArg);
1695  }
1696 
1697 public:
1698  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1699  SourceLocation StartLoc,
1701  QualType T, TypeSourceInfo *TInfo,
1702  StorageClass S, Expr *DefArg);
1703 
1704  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1705 
1706  SourceRange getSourceRange() const override LLVM_READONLY;
1707 
1708  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1709  ParmVarDeclBits.IsObjCMethodParam = true;
1710  setParameterIndex(parameterIndex);
1711  }
1712 
1713  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1714  assert(!ParmVarDeclBits.IsObjCMethodParam);
1715 
1716  ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1717  assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1718  && "truncation!");
1719 
1720  setParameterIndex(parameterIndex);
1721  }
1722 
1723  bool isObjCMethodParameter() const {
1724  return ParmVarDeclBits.IsObjCMethodParam;
1725  }
1726 
1727  /// Determines whether this parameter is destroyed in the callee function.
1728  bool isDestroyedInCallee() const;
1729 
1730  unsigned getFunctionScopeDepth() const {
1731  if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1732  return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1733  }
1734 
1735  static constexpr unsigned getMaxFunctionScopeDepth() {
1736  return (1u << NumScopeDepthOrObjCQualsBits) - 1;
1737  }
1738 
1739  /// Returns the index of this parameter in its prototype or method scope.
1740  unsigned getFunctionScopeIndex() const {
1741  return getParameterIndex();
1742  }
1743 
1745  if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1746  return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1747  }
1749  assert(ParmVarDeclBits.IsObjCMethodParam);
1750  ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1751  }
1752 
1753  /// True if the value passed to this parameter must undergo
1754  /// K&R-style default argument promotion:
1755  ///
1756  /// C99 6.5.2.2.
1757  /// If the expression that denotes the called function has a type
1758  /// that does not include a prototype, the integer promotions are
1759  /// performed on each argument, and arguments that have type float
1760  /// are promoted to double.
1761  bool isKNRPromoted() const {
1762  return ParmVarDeclBits.IsKNRPromoted;
1763  }
1764  void setKNRPromoted(bool promoted) {
1765  ParmVarDeclBits.IsKNRPromoted = promoted;
1766  }
1767 
1768  Expr *getDefaultArg();
1769  const Expr *getDefaultArg() const {
1770  return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1771  }
1772 
1773  void setDefaultArg(Expr *defarg);
1774 
1775  /// Retrieve the source range that covers the entire default
1776  /// argument.
1781  return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1782  }
1783 
1784  /// Determines whether this parameter has a default argument,
1785  /// either parsed or not.
1786  bool hasDefaultArg() const;
1787 
1788  /// Determines whether this parameter has a default argument that has not
1789  /// yet been parsed. This will occur during the processing of a C++ class
1790  /// whose member functions have default arguments, e.g.,
1791  /// @code
1792  /// class X {
1793  /// public:
1794  /// void f(int x = 17); // x has an unparsed default argument now
1795  /// }; // x has a regular default argument now
1796  /// @endcode
1797  bool hasUnparsedDefaultArg() const {
1798  return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1799  }
1800 
1802  return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1803  }
1804 
1805  /// Specify that this parameter has an unparsed default argument.
1806  /// The argument will be replaced with a real default argument via
1807  /// setDefaultArg when the class definition enclosing the function
1808  /// declaration that owns this default argument is completed.
1810  ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1811  }
1812 
1813  bool hasInheritedDefaultArg() const {
1814  return ParmVarDeclBits.HasInheritedDefaultArg;
1815  }
1816 
1817  void setHasInheritedDefaultArg(bool I = true) {
1818  ParmVarDeclBits.HasInheritedDefaultArg = I;
1819  }
1820 
1821  QualType getOriginalType() const;
1822 
1823  /// Sets the function declaration that owns this
1824  /// ParmVarDecl. Since ParmVarDecls are often created before the
1825  /// FunctionDecls that own them, this routine is required to update
1826  /// the DeclContext appropriately.
1828 
1829  // Implement isa/cast/dyncast/etc.
1830  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1831  static bool classofKind(Kind K) { return K == ParmVar; }
1832 
1833 private:
1834  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1835 
1836  void setParameterIndex(unsigned parameterIndex) {
1837  if (parameterIndex >= ParameterIndexSentinel) {
1838  setParameterIndexLarge(parameterIndex);
1839  return;
1840  }
1841 
1842  ParmVarDeclBits.ParameterIndex = parameterIndex;
1843  assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1844  }
1845  unsigned getParameterIndex() const {
1846  unsigned d = ParmVarDeclBits.ParameterIndex;
1847  return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
1848  }
1849 
1850  void setParameterIndexLarge(unsigned parameterIndex);
1851  unsigned getParameterIndexLarge() const;
1852 };
1853 
1854 enum class MultiVersionKind {
1855  None,
1856  Target,
1857  CPUSpecific,
1858  CPUDispatch,
1859  TargetClones
1860 };
1861 
1862 /// Represents a function declaration or definition.
1863 ///
1864 /// Since a given function can be declared several times in a program,
1865 /// there may be several FunctionDecls that correspond to that
1866 /// function. Only one of those FunctionDecls will be found when
1867 /// traversing the list of declarations in the context of the
1868 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
1869 /// contains all of the information known about the function. Other,
1870 /// previous declarations of the function are available via the
1871 /// getPreviousDecl() chain.
1873  public DeclContext,
1874  public Redeclarable<FunctionDecl> {
1875  // This class stores some data in DeclContext::FunctionDeclBits
1876  // to save some space. Use the provided accessors to access it.
1877 public:
1878  /// The kind of templated function a FunctionDecl can be.
1880  // Not templated.
1882  // The pattern in a function template declaration.
1884  // A non-template function that is an instantiation or explicit
1885  // specialization of a member of a templated class.
1887  // An instantiation or explicit specialization of a function template.
1888  // Note: this might have been instantiated from a templated class if it
1889  // is a class-scope explicit specialization.
1891  // A function template specialization that hasn't yet been resolved to a
1892  // particular specialized function template.
1894  };
1895 
1896  /// Stashed information about a defaulted function definition whose body has
1897  /// not yet been lazily generated.
1899  : llvm::TrailingObjects<DefaultedFunctionInfo, DeclAccessPair> {
1900  friend TrailingObjects;
1901  unsigned NumLookups;
1902 
1903  public:
1904  static DefaultedFunctionInfo *Create(ASTContext &Context,
1905  ArrayRef<DeclAccessPair> Lookups);
1906  /// Get the unqualified lookup results that should be used in this
1907  /// defaulted function definition.
1909  return {getTrailingObjects<DeclAccessPair>(), NumLookups};
1910  }
1911  };
1912 
1913 private:
1914  /// A new[]'d array of pointers to VarDecls for the formal
1915  /// parameters of this function. This is null if a prototype or if there are
1916  /// no formals.
1917  ParmVarDecl **ParamInfo = nullptr;
1918 
1919  /// The active member of this union is determined by
1920  /// FunctionDeclBits.HasDefaultedFunctionInfo.
1921  union {
1922  /// The body of the function.
1924  /// Information about a future defaulted function definition.
1926  };
1927 
1928  unsigned ODRHash;
1929 
1930  /// End part of this FunctionDecl's source range.
1931  ///
1932  /// We could compute the full range in getSourceRange(). However, when we're
1933  /// dealing with a function definition deserialized from a PCH/AST file,
1934  /// we can only compute the full range once the function body has been
1935  /// de-serialized, so it's far better to have the (sometimes-redundant)
1936  /// EndRangeLoc.
1937  SourceLocation EndRangeLoc;
1938 
1939  /// The template or declaration that this declaration
1940  /// describes or was instantiated from, respectively.
1941  ///
1942  /// For non-templates, this value will be NULL. For function
1943  /// declarations that describe a function template, this will be a
1944  /// pointer to a FunctionTemplateDecl. For member functions
1945  /// of class template specializations, this will be a MemberSpecializationInfo
1946  /// pointer containing information about the specialization.
1947  /// For function template specializations, this will be a
1948  /// FunctionTemplateSpecializationInfo, which contains information about
1949  /// the template being specialized and the template arguments involved in
1950  /// that specialization.
1951  llvm::PointerUnion<FunctionTemplateDecl *,
1955  TemplateOrSpecialization;
1956 
1957  /// Provides source/type location info for the declaration name embedded in
1958  /// the DeclaratorDecl base class.
1959  DeclarationNameLoc DNLoc;
1960 
1961  /// Specify that this function declaration is actually a function
1962  /// template specialization.
1963  ///
1964  /// \param C the ASTContext.
1965  ///
1966  /// \param Template the function template that this function template
1967  /// specialization specializes.
1968  ///
1969  /// \param TemplateArgs the template arguments that produced this
1970  /// function template specialization from the template.
1971  ///
1972  /// \param InsertPos If non-NULL, the position in the function template
1973  /// specialization set where the function template specialization data will
1974  /// be inserted.
1975  ///
1976  /// \param TSK the kind of template specialization this is.
1977  ///
1978  /// \param TemplateArgsAsWritten location info of template arguments.
1979  ///
1980  /// \param PointOfInstantiation point at which the function template
1981  /// specialization was first instantiated.
1982  void setFunctionTemplateSpecialization(ASTContext &C,
1983  FunctionTemplateDecl *Template,
1984  const TemplateArgumentList *TemplateArgs,
1985  void *InsertPos,
1987  const TemplateArgumentListInfo *TemplateArgsAsWritten,
1988  SourceLocation PointOfInstantiation);
1989 
1990  /// Specify that this record is an instantiation of the
1991  /// member function FD.
1992  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1994 
1995  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1996 
1997  // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
1998  // need to access this bit but we want to avoid making ASTDeclWriter
1999  // a friend of FunctionDeclBitfields just for this.
2000  bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
2001 
2002  /// Whether an ODRHash has been stored.
2003  bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
2004 
2005  /// State that an ODRHash has been stored.
2006  void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
2007 
2008 protected:
2009  FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2010  const DeclarationNameInfo &NameInfo, QualType T,
2011  TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
2012  bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
2013  Expr *TrailingRequiresClause = nullptr);
2014 
2016 
2018  return getNextRedeclaration();
2019  }
2020 
2022  return getPreviousDecl();
2023  }
2024 
2026  return getMostRecentDecl();
2027  }
2028 
2029 public:
2030  friend class ASTDeclReader;
2031  friend class ASTDeclWriter;
2032 
2034  using redecl_iterator = redeclarable_base::redecl_iterator;
2035 
2042 
2043  static FunctionDecl *
2046  TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
2047  bool isInlineSpecified = false, bool hasWrittenPrototype = true,
2049  Expr *TrailingRequiresClause = nullptr) {
2050  DeclarationNameInfo NameInfo(N, NLoc);
2051  return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
2053  hasWrittenPrototype, ConstexprKind,
2054  TrailingRequiresClause);
2055  }
2056 
2057  static FunctionDecl *
2058  Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2059  const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2061  bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
2062  Expr *TrailingRequiresClause);
2063 
2064  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2065 
2067  return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2068  }
2069 
2070  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2071  bool Qualified) const override;
2072 
2073  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
2074 
2075  /// Returns the location of the ellipsis of a variadic function.
2077  const auto *FPT = getType()->getAs<FunctionProtoType>();
2078  if (FPT && FPT->isVariadic())
2079  return FPT->getEllipsisLoc();
2080  return SourceLocation();
2081  }
2082 
2083  SourceRange getSourceRange() const override LLVM_READONLY;
2084 
2085  // Function definitions.
2086  //
2087  // A function declaration may be:
2088  // - a non defining declaration,
2089  // - a definition. A function may be defined because:
2090  // - it has a body, or will have it in the case of late parsing.
2091  // - it has an uninstantiated body. The body does not exist because the
2092  // function is not used yet, but the declaration is considered a
2093  // definition and does not allow other definition of this function.
2094  // - it does not have a user specified body, but it does not allow
2095  // redefinition, because it is deleted/defaulted or is defined through
2096  // some other mechanism (alias, ifunc).
2097 
2098  /// Returns true if the function has a body.
2099  ///
2100  /// The function body might be in any of the (re-)declarations of this
2101  /// function. The variant that accepts a FunctionDecl pointer will set that
2102  /// function declaration to the actual declaration containing the body (if
2103  /// there is one).
2104  bool hasBody(const FunctionDecl *&Definition) const;
2105 
2106  bool hasBody() const override {
2107  const FunctionDecl* Definition;
2108  return hasBody(Definition);
2109  }
2110 
2111  /// Returns whether the function has a trivial body that does not require any
2112  /// specific codegen.
2113  bool hasTrivialBody() const;
2114 
2115  /// Returns true if the function has a definition that does not need to be
2116  /// instantiated.
2117  ///
2118  /// The variant that accepts a FunctionDecl pointer will set that function
2119  /// declaration to the declaration that is a definition (if there is one).
2120  ///
2121  /// \param CheckForPendingFriendDefinition If \c true, also check for friend
2122  /// declarations that were instantiataed from function definitions.
2123  /// Such a declaration behaves as if it is a definition for the
2124  /// purpose of redefinition checking, but isn't actually a "real"
2125  /// definition until its body is instantiated.
2126  bool isDefined(const FunctionDecl *&Definition,
2127  bool CheckForPendingFriendDefinition = false) const;
2128 
2129  bool isDefined() const {
2130  const FunctionDecl* Definition;
2131  return isDefined(Definition);
2132  }
2133 
2134  /// Get the definition for this declaration.
2136  const FunctionDecl *Definition;
2137  if (isDefined(Definition))
2138  return const_cast<FunctionDecl *>(Definition);
2139  return nullptr;
2140  }
2141  const FunctionDecl *getDefinition() const {
2142  return const_cast<FunctionDecl *>(this)->getDefinition();
2143  }
2144 
2145  /// Retrieve the body (definition) of the function. The function body might be
2146  /// in any of the (re-)declarations of this function. The variant that accepts
2147  /// a FunctionDecl pointer will set that function declaration to the actual
2148  /// declaration containing the body (if there is one).
2149  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
2150  /// unnecessary AST de-serialization of the body.
2151  Stmt *getBody(const FunctionDecl *&Definition) const;
2152 
2153  Stmt *getBody() const override {
2154  const FunctionDecl* Definition;
2155  return getBody(Definition);
2156  }
2157 
2158  /// Returns whether this specific declaration of the function is also a
2159  /// definition that does not contain uninstantiated body.
2160  ///
2161  /// This does not determine whether the function has been defined (e.g., in a
2162  /// previous definition); for that information, use isDefined.
2163  ///
2164  /// Note: the function declaration does not become a definition until the
2165  /// parser reaches the definition, if called before, this function will return
2166  /// `false`.
2168  return isDeletedAsWritten() || isDefaulted() ||
2171  }
2172 
2173  /// Determine whether this specific declaration of the function is a friend
2174  /// declaration that was instantiated from a function definition. Such
2175  /// declarations behave like definitions in some contexts.
2177 
2178  /// Returns whether this specific declaration of the function has a body.
2180  return (!FunctionDeclBits.HasDefaultedFunctionInfo && Body) ||
2182  }
2183 
2184  void setBody(Stmt *B);
2186  FunctionDeclBits.HasDefaultedFunctionInfo = false;
2188  }
2189 
2190  void setDefaultedFunctionInfo(DefaultedFunctionInfo *Info);
2191  DefaultedFunctionInfo *getDefaultedFunctionInfo() const;
2192 
2193  /// Whether this function is variadic.
2194  bool isVariadic() const;
2195 
2196  /// Whether this function is marked as virtual explicitly.
2197  bool isVirtualAsWritten() const {
2198  return FunctionDeclBits.IsVirtualAsWritten;
2199  }
2200 
2201  /// State that this function is marked as virtual explicitly.
2202  void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2203 
2204  /// Whether this virtual function is pure, i.e. makes the containing class
2205  /// abstract.
2206  bool isPure() const { return FunctionDeclBits.IsPure; }
2207  void setPure(bool P = true);
2208 
2209  /// Whether this templated function will be late parsed.
2210  bool isLateTemplateParsed() const {
2211  return FunctionDeclBits.IsLateTemplateParsed;
2212  }
2213 
2214  /// State that this templated function will be late parsed.
2215  void setLateTemplateParsed(bool ILT = true) {
2216  FunctionDeclBits.IsLateTemplateParsed = ILT;
2217  }
2218 
2219  /// Whether this function is "trivial" in some specialized C++ senses.
2220  /// Can only be true for default constructors, copy constructors,
2221  /// copy assignment operators, and destructors. Not meaningful until
2222  /// the class has been fully built by Sema.
2223  bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2224  void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2225 
2226  bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2227  void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2228 
2229  /// Whether this function is defaulted. Valid for e.g.
2230  /// special member functions, defaulted comparisions (not methods!).
2231  bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2232  void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2233 
2234  /// Whether this function is explicitly defaulted.
2235  bool isExplicitlyDefaulted() const {
2236  return FunctionDeclBits.IsExplicitlyDefaulted;
2237  }
2238 
2239  /// State that this function is explicitly defaulted.
2240  void setExplicitlyDefaulted(bool ED = true) {
2241  FunctionDeclBits.IsExplicitlyDefaulted = ED;
2242  }
2243 
2244  /// True if this method is user-declared and was not
2245  /// deleted or defaulted on its first declaration.
2246  bool isUserProvided() const {
2247  auto *DeclAsWritten = this;
2249  DeclAsWritten = Pattern;
2250  return !(DeclAsWritten->isDeleted() ||
2251  DeclAsWritten->getCanonicalDecl()->isDefaulted());
2252  }
2253 
2255  return FunctionDeclBits.IsIneligibleOrNotSelected;
2256  }
2258  FunctionDeclBits.IsIneligibleOrNotSelected = II;
2259  }
2260 
2261  /// Whether falling off this function implicitly returns null/zero.
2262  /// If a more specific implicit return value is required, front-ends
2263  /// should synthesize the appropriate return statements.
2264  bool hasImplicitReturnZero() const {
2265  return FunctionDeclBits.HasImplicitReturnZero;
2266  }
2267 
2268  /// State that falling off this function implicitly returns null/zero.
2269  /// If a more specific implicit return value is required, front-ends
2270  /// should synthesize the appropriate return statements.
2271  void setHasImplicitReturnZero(bool IRZ) {
2272  FunctionDeclBits.HasImplicitReturnZero = IRZ;
2273  }
2274 
2275  /// Whether this function has a prototype, either because one
2276  /// was explicitly written or because it was "inherited" by merging
2277  /// a declaration without a prototype with a declaration that has a
2278  /// prototype.
2279  bool hasPrototype() const {
2281  }
2282 
2283  /// Whether this function has a written prototype.
2284  bool hasWrittenPrototype() const {
2285  return FunctionDeclBits.HasWrittenPrototype;
2286  }
2287 
2288  /// State that this function has a written prototype.
2289  void setHasWrittenPrototype(bool P = true) {
2290  FunctionDeclBits.HasWrittenPrototype = P;
2291  }
2292 
2293  /// Whether this function inherited its prototype from a
2294  /// previous declaration.
2295  bool hasInheritedPrototype() const {
2296  return FunctionDeclBits.HasInheritedPrototype;
2297  }
2298 
2299  /// State that this function inherited its prototype from a
2300  /// previous declaration.
2301  void setHasInheritedPrototype(bool P = true) {
2302  FunctionDeclBits.HasInheritedPrototype = P;
2303  }
2304 
2305  /// Whether this is a (C++11) constexpr function or constexpr constructor.
2306  bool isConstexpr() const {
2308  }
2310  FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK);
2311  }
2313  return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
2314  }
2315  bool isConstexprSpecified() const {
2317  }
2318  bool isConsteval() const {
2320  }
2321 
2322  /// Whether the instantiation of this function is pending.
2323  /// This bit is set when the decision to instantiate this function is made
2324  /// and unset if and when the function body is created. That leaves out
2325  /// cases where instantiation did not happen because the template definition
2326  /// was not seen in this TU. This bit remains set in those cases, under the
2327  /// assumption that the instantiation will happen in some other TU.
2328  bool instantiationIsPending() const {
2329  return FunctionDeclBits.InstantiationIsPending;
2330  }
2331 
2332  /// State that the instantiation of this function is pending.
2333  /// (see instantiationIsPending)
2335  FunctionDeclBits.InstantiationIsPending = IC;
2336  }
2337 
2338  /// Indicates the function uses __try.
2339  bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2340  void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2341 
2342  /// Whether this function has been deleted.
2343  ///
2344  /// A function that is "deleted" (via the C++0x "= delete" syntax)
2345  /// acts like a normal function, except that it cannot actually be
2346  /// called or have its address taken. Deleted functions are
2347  /// typically used in C++ overload resolution to attract arguments
2348  /// whose type or lvalue/rvalue-ness would permit the use of a
2349  /// different overload that would behave incorrectly. For example,
2350  /// one might use deleted functions to ban implicit conversion from
2351  /// a floating-point number to an Integer type:
2352  ///
2353  /// @code
2354  /// struct Integer {
2355  /// Integer(long); // construct from a long
2356  /// Integer(double) = delete; // no construction from float or double
2357  /// Integer(long double) = delete; // no construction from long double
2358  /// };
2359  /// @endcode
2360  // If a function is deleted, its first declaration must be.
2361  bool isDeleted() const {
2362  return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2363  }
2364 
2365  bool isDeletedAsWritten() const {
2366  return FunctionDeclBits.IsDeleted && !isDefaulted();
2367  }
2368 
2369  void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
2370 
2371  /// Determines whether this function is "main", which is the
2372  /// entry point into an executable program.
2373  bool isMain() const;
2374 
2375  /// Determines whether this function is a MSVCRT user defined entry
2376  /// point.
2377  bool isMSVCRTEntryPoint() const;
2378 
2379  /// Determines whether this operator new or delete is one
2380  /// of the reserved global placement operators:
2381  /// void *operator new(size_t, void *);
2382  /// void *operator new[](size_t, void *);
2383  /// void operator delete(void *, void *);
2384  /// void operator delete[](void *, void *);
2385  /// These functions have special behavior under [new.delete.placement]:
2386  /// These functions are reserved, a C++ program may not define
2387  /// functions that displace the versions in the Standard C++ library.
2388  /// The provisions of [basic.stc.dynamic] do not apply to these
2389  /// reserved placement forms of operator new and operator delete.
2390  ///
2391  /// This function must be an allocation or deallocation function.
2392  bool isReservedGlobalPlacementOperator() const;
2393 
2394  /// Determines whether this function is one of the replaceable
2395  /// global allocation functions:
2396  /// void *operator new(size_t);
2397  /// void *operator new(size_t, const std::nothrow_t &) noexcept;
2398  /// void *operator new[](size_t);
2399  /// void *operator new[](size_t, const std::nothrow_t &) noexcept;
2400  /// void operator delete(void *) noexcept;
2401  /// void operator delete(void *, std::size_t) noexcept; [C++1y]
2402  /// void operator delete(void *, const std::nothrow_t &) noexcept;
2403  /// void operator delete[](void *) noexcept;
2404  /// void operator delete[](void *, std::size_t) noexcept; [C++1y]
2405  /// void operator delete[](void *, const std::nothrow_t &) noexcept;
2406  /// These functions have special behavior under C++1y [expr.new]:
2407  /// An implementation is allowed to omit a call to a replaceable global
2408  /// allocation function. [...]
2409  ///
2410  /// If this function is an aligned allocation/deallocation function, return
2411  /// the parameter number of the requested alignment through AlignmentParam.
2412  ///
2413  /// If this function is an allocation/deallocation function that takes
2414  /// the `std::nothrow_t` tag, return true through IsNothrow,
2416  Optional<unsigned> *AlignmentParam = nullptr,
2417  bool *IsNothrow = nullptr) const;
2418 
2419  /// Determine if this function provides an inline implementation of a builtin.
2420  bool isInlineBuiltinDeclaration() const;
2421 
2422  /// Determine whether this is a destroying operator delete.
2423  bool isDestroyingOperatorDelete() const;
2424 
2425  /// Compute the language linkage.
2427 
2428  /// Determines whether this function is a function with
2429  /// external, C linkage.
2430  bool isExternC() const;
2431 
2432  /// Determines whether this function's context is, or is nested within,
2433  /// a C++ extern "C" linkage spec.
2434  bool isInExternCContext() const;
2435 
2436  /// Determines whether this function's context is, or is nested within,
2437  /// a C++ extern "C++" linkage spec.
2438  bool isInExternCXXContext() const;
2439 
2440  /// Determines whether this is a global function.
2441  bool isGlobal() const;
2442 
2443  /// Determines whether this function is known to be 'noreturn', through
2444  /// an attribute on its declaration or its type.
2445  bool isNoReturn() const;
2446 
2447  /// True if the function was a definition but its body was skipped.
2448  bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2449  void setHasSkippedBody(bool Skipped = true) {
2450  FunctionDeclBits.HasSkippedBody = Skipped;
2451  }
2452 
2453  /// True if this function will eventually have a body, once it's fully parsed.
2454  bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2455  void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2456 
2457  /// True if this function is considered a multiversioned function.
2458  bool isMultiVersion() const {
2459  return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2460  }
2461 
2462  /// Sets the multiversion state for this declaration and all of its
2463  /// redeclarations.
2464  void setIsMultiVersion(bool V = true) {
2465  getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2466  }
2467 
2468  /// Gets the kind of multiversioning attribute this declaration has. Note that
2469  /// this can return a value even if the function is not multiversion, such as
2470  /// the case of 'target'.
2472 
2473 
2474  /// True if this function is a multiversioned dispatch function as a part of
2475  /// the cpu_specific/cpu_dispatch functionality.
2476  bool isCPUDispatchMultiVersion() const;
2477  /// True if this function is a multiversioned processor specific function as a
2478  /// part of the cpu_specific/cpu_dispatch functionality.
2479  bool isCPUSpecificMultiVersion() const;
2480 
2481  /// True if this function is a multiversioned dispatch function as a part of
2482  /// the target functionality.
2483  bool isTargetMultiVersion() const;
2484 
2485  /// True if this function is a multiversioned dispatch function as a part of
2486  /// the target-clones functionality.
2487  bool isTargetClonesMultiVersion() const;
2488 
2489  /// \brief Get the associated-constraints of this function declaration.
2490  /// Currently, this will either be a vector of size 1 containing the
2491  /// trailing-requires-clause or an empty vector.
2492  ///
2493  /// Use this instead of getTrailingRequiresClause for concepts APIs that
2494  /// accept an ArrayRef of constraint expressions.
2496  if (auto *TRC = getTrailingRequiresClause())
2497  AC.push_back(TRC);
2498  }
2499 
2500  void setPreviousDeclaration(FunctionDecl * PrevDecl);
2501 
2502  FunctionDecl *getCanonicalDecl() override;
2504  return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2505  }
2506 
2507  unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2508 
2509  // ArrayRef interface to parameters.
2511  return {ParamInfo, getNumParams()};
2512  }
2514  return {ParamInfo, getNumParams()};
2515  }
2516 
2517  // Iterator access to formal parameters.
2520 
2521  bool param_empty() const { return parameters().empty(); }
2522  param_iterator param_begin() { return parameters().begin(); }
2523  param_iterator param_end() { return parameters().end(); }
2524  param_const_iterator param_begin() const { return parameters().begin(); }
2525  param_const_iterator param_end() const { return parameters().end(); }
2526  size_t param_size() const { return parameters().size(); }
2527 
2528  /// Return the number of parameters this function must have based on its
2529  /// FunctionType. This is the length of the ParamInfo array after it has been
2530  /// created.
2531  unsigned getNumParams() const;
2532 
2533  const ParmVarDecl *getParamDecl(unsigned i) const {
2534  assert(i < getNumParams() && "Illegal param #");
2535  return ParamInfo[i];
2536  }
2537  ParmVarDecl *getParamDecl(unsigned i) {
2538  assert(i < getNumParams() && "Illegal param #");
2539  return ParamInfo[i];
2540  }
2541  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2542  setParams(getASTContext(), NewParamInfo);
2543  }
2544 
2545  /// Returns the minimum number of arguments needed to call this function. This
2546  /// may be fewer than the number of function parameters, if some of the
2547  /// parameters have default arguments (in C++).
2548  unsigned getMinRequiredArguments() const;
2549 
2550  /// Determine whether this function has a single parameter, or multiple
2551  /// parameters where all but the first have default arguments.
2552  ///
2553  /// This notion is used in the definition of copy/move constructors and
2554  /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2555  /// parameter packs are not treated specially here.
2556  bool hasOneParamOrDefaultArgs() const;
2557 
2558  /// Find the source location information for how the type of this function
2559  /// was written. May be absent (for example if the function was declared via
2560  /// a typedef) and may contain a different type from that of the function
2561  /// (for example if the function type was adjusted by an attribute).
2563 
2565  return getType()->castAs<FunctionType>()->getReturnType();
2566  }
2567 
2568  /// Attempt to compute an informative source range covering the
2569  /// function return type. This may omit qualifiers and other information with
2570  /// limited representation in the AST.
2572 
2573  /// Attempt to compute an informative source range covering the
2574  /// function parameters, including the ellipsis of a variadic function.
2575  /// The source range excludes the parentheses, and is invalid if there are
2576  /// no parameters and no ellipsis.
2578 
2579  /// Get the declared return type, which may differ from the actual return
2580  /// type if the return type is deduced.
2582  auto *TSI = getTypeSourceInfo();
2583  QualType T = TSI ? TSI->getType() : getType();
2584  return T->castAs<FunctionType>()->getReturnType();
2585  }
2586 
2587  /// Gets the ExceptionSpecificationType as declared.
2589  auto *TSI = getTypeSourceInfo();
2590  QualType T = TSI ? TSI->getType() : getType();
2591  const auto *FPT = T->getAs<FunctionProtoType>();
2592  return FPT ? FPT->getExceptionSpecType() : EST_None;
2593  }
2594 
2595  /// Attempt to compute an informative source range covering the
2596  /// function exception specification, if any.
2598 
2599  /// Determine the type of an expression that calls this function.
2602  getASTContext());
2603  }
2604 
2605  /// Returns the storage class as written in the source. For the
2606  /// computed linkage of symbol, see getLinkage.
2608  return static_cast<StorageClass>(FunctionDeclBits.SClass);
2609  }
2610 
2611  /// Sets the storage class as written in the source.
2613  FunctionDeclBits.SClass = SClass;
2614  }
2615 
2616  /// Determine whether the "inline" keyword was specified for this
2617  /// function.
2618  bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2619 
2620  /// Set whether the "inline" keyword was specified for this function.
2621  void setInlineSpecified(bool I) {
2622  FunctionDeclBits.IsInlineSpecified = I;
2623  FunctionDeclBits.IsInline = I;
2624  }
2625 
2626  /// Determine whether the function was declared in source context
2627  /// that requires constrained FP intrinsics
2628  bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
2629 
2630  /// Set whether the function was declared in source context
2631  /// that requires constrained FP intrinsics
2632  void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
2633 
2634  /// Flag that this function is implicitly inline.
2635  void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2636 
2637  /// Determine whether this function should be inlined, because it is
2638  /// either marked "inline" or "constexpr" or is a member function of a class
2639  /// that was defined in the class body.
2640  bool isInlined() const { return FunctionDeclBits.IsInline; }
2641 
2643 
2644  bool isMSExternInline() const;
2645 
2647 
2648  bool isStatic() const { return getStorageClass() == SC_Static; }
2649 
2650  /// Whether this function declaration represents an C++ overloaded
2651  /// operator, e.g., "operator+".
2652  bool isOverloadedOperator() const {
2653  return getOverloadedOperator() != OO_None;
2654  }
2655 
2657 
2658  const IdentifierInfo *getLiteralIdentifier() const;
2659 
2660  /// If this function is an instantiation of a member function
2661  /// of a class template specialization, retrieves the function from
2662  /// which it was instantiated.
2663  ///
2664  /// This routine will return non-NULL for (non-templated) member
2665  /// functions of class templates and for instantiations of function
2666  /// templates. For example, given:
2667  ///
2668  /// \code
2669  /// template<typename T>
2670  /// struct X {
2671  /// void f(T);
2672  /// };
2673  /// \endcode
2674  ///
2675  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2676  /// whose parent is the class template specialization X<int>. For
2677  /// this declaration, getInstantiatedFromFunction() will return
2678  /// the FunctionDecl X<T>::A. When a complete definition of
2679  /// X<int>::A is required, it will be instantiated from the
2680  /// declaration returned by getInstantiatedFromMemberFunction().
2682 
2683  /// What kind of templated function this is.
2685 
2686  /// If this function is an instantiation of a member function of a
2687  /// class template specialization, retrieves the member specialization
2688  /// information.
2690 
2691  /// Specify that this record is an instantiation of the
2692  /// member function FD.
2695  setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2696  }
2697 
2698  /// Retrieves the function template that is described by this
2699  /// function declaration.
2700  ///
2701  /// Every function template is represented as a FunctionTemplateDecl
2702  /// and a FunctionDecl (or something derived from FunctionDecl). The
2703  /// former contains template properties (such as the template
2704  /// parameter lists) while the latter contains the actual
2705  /// description of the template's
2706  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2707  /// FunctionDecl that describes the function template,
2708  /// getDescribedFunctionTemplate() retrieves the
2709  /// FunctionTemplateDecl from a FunctionDecl.
2711 
2713 
2714  /// Determine whether this function is a function template
2715  /// specialization.
2717  return getPrimaryTemplate() != nullptr;
2718  }
2719 
2720  /// If this function is actually a function template specialization,
2721  /// retrieve information about this function template specialization.
2722  /// Otherwise, returns NULL.
2724 
2725  /// Determines whether this function is a function template
2726  /// specialization or a member of a class template specialization that can
2727  /// be implicitly instantiated.
2728  bool isImplicitlyInstantiable() const;
2729 
2730  /// Determines if the given function was instantiated from a
2731  /// function template.
2732  bool isTemplateInstantiation() const;
2733 
2734  /// Retrieve the function declaration from which this function could
2735  /// be instantiated, if it is an instantiation (rather than a non-template
2736  /// or a specialization, for example).
2737  ///
2738  /// If \p ForDefinition is \c false, explicit specializations will be treated
2739  /// as if they were implicit instantiations. This will then find the pattern
2740  /// corresponding to non-definition portions of the declaration, such as
2741  /// default arguments and the exception specification.
2742  FunctionDecl *
2744 
2745  /// Retrieve the primary template that this function template
2746  /// specialization either specializes or was instantiated from.
2747  ///
2748  /// If this function declaration is not a function template specialization,
2749  /// returns NULL.
2751 
2752  /// Retrieve the template arguments used to produce this function
2753  /// template specialization from the primary template.
2754  ///
2755  /// If this function declaration is not a function template specialization,
2756  /// returns NULL.
2758 
2759  /// Retrieve the template argument list as written in the sources,
2760  /// if any.
2761  ///
2762  /// If this function declaration is not a function template specialization
2763  /// or if it had no explicit template argument list, returns NULL.
2764  /// Note that it an explicit template argument list may be written empty,
2765  /// e.g., template<> void foo<>(char* s);
2768 
2769  /// Specify that this function declaration is actually a function
2770  /// template specialization.
2771  ///
2772  /// \param Template the function template that this function template
2773  /// specialization specializes.
2774  ///
2775  /// \param TemplateArgs the template arguments that produced this
2776  /// function template specialization from the template.
2777  ///
2778  /// \param InsertPos If non-NULL, the position in the function template
2779  /// specialization set where the function template specialization data will
2780  /// be inserted.
2781  ///
2782  /// \param TSK the kind of template specialization this is.
2783  ///
2784  /// \param TemplateArgsAsWritten location info of template arguments.
2785  ///
2786  /// \param PointOfInstantiation point at which the function template
2787  /// specialization was first instantiated.
2789  const TemplateArgumentList *TemplateArgs,
2790  void *InsertPos,
2792  const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2793  SourceLocation PointOfInstantiation = SourceLocation()) {
2794  setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2795  InsertPos, TSK, TemplateArgsAsWritten,
2796  PointOfInstantiation);
2797  }
2798 
2799  /// Specifies that this function declaration is actually a
2800  /// dependent function template specialization.
2802  const UnresolvedSetImpl &Templates,
2803  const TemplateArgumentListInfo &TemplateArgs);
2804 
2807 
2808  /// Determine what kind of template instantiation this function
2809  /// represents.
2811 
2812  /// Determine the kind of template specialization this function represents
2813  /// for the purpose of template instantiation.
2816 
2817  /// Determine what kind of template instantiation this function
2818  /// represents.
2820  SourceLocation PointOfInstantiation = SourceLocation());
2821 
2822  /// Retrieve the (first) point of instantiation of a function template
2823  /// specialization or a member of a class template specialization.
2824  ///
2825  /// \returns the first point of instantiation, if this function was
2826  /// instantiated from a template; otherwise, returns an invalid source
2827  /// location.
2829 
2830  /// Determine whether this is or was instantiated from an out-of-line
2831  /// definition of a member function.
2832  bool isOutOfLine() const override;
2833 
2834  /// Identify a memory copying or setting function.
2835  /// If the given function is a memory copy or setting function, returns
2836  /// the corresponding Builtin ID. If the function is not a memory function,
2837  /// returns 0.
2838  unsigned getMemoryFunctionKind() const;
2839 
2840  /// Returns ODRHash of the function. This value is calculated and
2841  /// stored on first call, then the stored value returned on the other calls.
2842  unsigned getODRHash();
2843 
2844  /// Returns cached ODRHash of the function. This must have been previously
2845  /// computed and stored.
2846  unsigned getODRHash() const;
2847 
2848  // Implement isa/cast/dyncast/etc.
2849  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2850  static bool classofKind(Kind K) {
2851  return K >= firstFunction && K <= lastFunction;
2852  }
2854  return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2855  }
2857  return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2858  }
2859 };
2860 
2861 /// Represents a member of a struct/union/class.
2862 class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2863  unsigned BitField : 1;
2864  unsigned Mutable : 1;
2865  mutable unsigned CachedFieldIndex : 30;
2866 
2867  /// The kinds of value we can store in InitializerOrBitWidth.
2868  ///
2869  /// Note that this is compatible with InClassInitStyle except for
2870  /// ISK_CapturedVLAType.
2871  enum InitStorageKind {
2872  /// If the pointer is null, there's nothing special. Otherwise,
2873  /// this is a bitfield and the pointer is the Expr* storing the
2874  /// bit-width.
2875  ISK_NoInit = (unsigned) ICIS_NoInit,
2876 
2877  /// The pointer is an (optional due to delayed parsing) Expr*
2878  /// holding the copy-initializer.
2879  ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2880 
2881  /// The pointer is an (optional due to delayed parsing) Expr*
2882  /// holding the list-initializer.
2883  ISK_InClassListInit = (unsigned) ICIS_ListInit,
2884 
2885  /// The pointer is a VariableArrayType* that's been captured;
2886  /// the enclosing context is a lambda or captured statement.
2887  ISK_CapturedVLAType,
2888  };
2889 
2890  /// If this is a bitfield with a default member initializer, this
2891  /// structure is used to represent the two expressions.
2892  struct InitAndBitWidth {
2893  Expr *Init;
2894  Expr *BitWidth;
2895  };
2896 
2897  /// Storage for either the bit-width, the in-class initializer, or
2898  /// both (via InitAndBitWidth), or the captured variable length array bound.
2899  ///
2900  /// If the storage kind is ISK_InClassCopyInit or
2901  /// ISK_InClassListInit, but the initializer is null, then this
2902  /// field has an in-class initializer that has not yet been parsed
2903  /// and attached.
2904  // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
2905  // overwhelmingly common case that we have none of these things.
2906  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2907 
2908 protected:
2911  QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2912  InClassInitStyle InitStyle)
2913  : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2914  BitField(false), Mutable(Mutable), CachedFieldIndex(0),
2915  InitStorage(nullptr, (InitStorageKind) InitStyle) {
2916  if (BW)
2917  setBitWidth(BW);
2918  }
2919 
2920 public:
2921  friend class ASTDeclReader;
2922  friend class ASTDeclWriter;
2923 
2924  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2925  SourceLocation StartLoc, SourceLocation IdLoc,
2927  TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2928  InClassInitStyle InitStyle);
2929 
2930  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2931 
2932  /// Returns the index of this field within its record,
2933  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2934  unsigned getFieldIndex() const;
2935 
2936  /// Determines whether this field is mutable (C++ only).
2937  bool isMutable() const { return Mutable; }
2938 
2939  /// Determines whether this field is a bitfield.
2940  bool isBitField() const { return BitField; }
2941 
2942  /// Determines whether this is an unnamed bitfield.
2943  bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
2944 
2945  /// Determines whether this field is a
2946  /// representative for an anonymous struct or union. Such fields are
2947  /// unnamed and are implicitly generated by the implementation to
2948  /// store the data for the anonymous union or struct.
2949  bool isAnonymousStructOrUnion() const;
2950 
2951  Expr *getBitWidth() const {
2952  if (!BitField)
2953  return nullptr;
2954  void *Ptr = InitStorage.getPointer();
2955  if (getInClassInitStyle())
2956  return static_cast<InitAndBitWidth*>(Ptr)->BitWidth;
2957  return static_cast<Expr*>(Ptr);
2958  }
2959 
2960  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2961 
2962  /// Set the bit-field width for this member.
2963  // Note: used by some clients (i.e., do not remove it).
2964  void setBitWidth(Expr *Width) {
2965  assert(!hasCapturedVLAType() && !BitField &&
2966  "bit width or captured type already set");
2967  assert(Width && "no bit width specified");
2968  InitStorage.setPointer(
2969  InitStorage.getInt()
2970  ? new (getASTContext())
2971  InitAndBitWidth{getInClassInitializer(), Width}
2972  : static_cast<void*>(Width));
2973  BitField = true;
2974  }
2975 
2976  /// Remove the bit-field width from this member.
2977  // Note: used by some clients (i.e., do not remove it).
2979  assert(isBitField() && "no bitfield width to remove");
2980  InitStorage.setPointer(getInClassInitializer());
2981  BitField = false;
2982  }
2983 
2984  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
2985  /// at all and instead act as a separator between contiguous runs of other
2986  /// bit-fields.
2987  bool isZeroLengthBitField(const ASTContext &Ctx) const;
2988 
2989  /// Determine if this field is a subobject of zero size, that is, either a
2990  /// zero-length bit-field or a field of empty class type with the
2991  /// [[no_unique_address]] attribute.
2992  bool isZeroSize(const ASTContext &Ctx) const;
2993 
2994  /// Get the kind of (C++11) default member initializer that this field has.
2996  InitStorageKind storageKind = InitStorage.getInt();
2997  return (storageKind == ISK_CapturedVLAType
2998  ? ICIS_NoInit : (InClassInitStyle) storageKind);
2999  }
3000 
3001  /// Determine whether this member has a C++11 default member initializer.
3002  bool hasInClassInitializer() const {
3003  return getInClassInitStyle() != ICIS_NoInit;
3004  }
3005 
3006  /// Get the C++11 default member initializer for this member, or null if one
3007  /// has not been set. If a valid declaration has a default member initializer,
3008  /// but this returns null, then we have not parsed and attached it yet.
3010  if (!hasInClassInitializer())
3011  return nullptr;
3012  void *Ptr = InitStorage.getPointer();
3013  if (BitField)
3014  return static_cast<InitAndBitWidth*>(Ptr)->Init;
3015  return static_cast<Expr*>(Ptr);
3016  }
3017 
3018  /// Set the C++11 in-class initializer for this member.
3021  if (BitField)
3022  static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init;
3023  else
3024  InitStorage.setPointer(Init);
3025  }
3026 
3027  /// Remove the C++11 in-class initializer from this member.
3029  assert(hasInClassInitializer() && "no initializer to remove");
3030  InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit);
3031  }
3032 
3033  /// Determine whether this member captures the variable length array
3034  /// type.
3035  bool hasCapturedVLAType() const {
3036  return InitStorage.getInt() == ISK_CapturedVLAType;
3037  }
3038 
3039  /// Get the captured variable length array type.
3041  return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
3042  InitStorage.getPointer())
3043  : nullptr;
3044  }
3045 
3046  /// Set the captured variable length array type for this field.
3047  void setCapturedVLAType(const VariableArrayType *VLAType);
3048 
3049  /// Returns the parent of this field declaration, which
3050  /// is the struct in which this field is defined.
3051  ///
3052  /// Returns null if this is not a normal class/struct field declaration, e.g.
3053  /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3054  const RecordDecl *getParent() const {
3055  return dyn_cast<RecordDecl>(getDeclContext());
3056  }
3057 
3059  return dyn_cast<RecordDecl>(getDeclContext());
3060  }
3061 
3062  SourceRange getSourceRange() const override LLVM_READONLY;
3063 
3064  /// Retrieves the canonical declaration of this field.
3065  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3066  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3067 
3068  // Implement isa/cast/dyncast/etc.
3069  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3070  static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3071 };
3072 
3073 /// An instance of this object exists for each enum constant
3074 /// that is defined. For example, in "enum X {a,b}", each of a/b are
3075 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3076 /// TagType for the X EnumDecl.
3077 class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
3078  Stmt *Init; // an integer constant expression
3079  llvm::APSInt Val; // The value.
3080 
3081 protected:
3083  IdentifierInfo *Id, QualType T, Expr *E,
3084  const llvm::APSInt &V)
3085  : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
3086 
3087 public:
3088  friend class StmtIteratorBase;
3089 
3092  QualType T, Expr *E,
3093  const llvm::APSInt &V);
3094  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3095 
3096  const Expr *getInitExpr() const { return (const Expr*) Init; }
3097  Expr *getInitExpr() { return (Expr*) Init; }
3098  const llvm::APSInt &getInitVal() const { return Val; }
3099 
3100  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3101  void setInitVal(const llvm::APSInt &V) { Val = V; }
3102 
3103  SourceRange getSourceRange() const override LLVM_READONLY;
3104 
3105  /// Retrieves the canonical declaration of this enumerator.
3107  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
3108 
3109  // Implement isa/cast/dyncast/etc.
3110  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3111  static bool classofKind(Kind K) { return K == EnumConstant; }
3112 };
3113 
3114 /// Represents a field injected from an anonymous union/struct into the parent
3115 /// scope. These are always implicit.
3117  public Mergeable<IndirectFieldDecl> {
3118  NamedDecl **Chaining;
3119  unsigned ChainingSize;
3120 
3124 
3125  void anchor() override;
3126 
3127 public:
3128  friend class ASTDeclReader;
3129 
3133 
3134  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3135 
3137 
3139  return llvm::makeArrayRef(Chaining, ChainingSize);
3140  }
3141  chain_iterator chain_begin() const { return chain().begin(); }
3142  chain_iterator chain_end() const { return chain().end(); }
3143 
3144  unsigned getChainingSize() const { return ChainingSize; }
3145 
3147  assert(chain().size() >= 2);
3148  return cast<FieldDecl>(chain().back());
3149  }
3150 
3151  VarDecl *getVarDecl() const {
3152  assert(chain().size() >= 2);
3153  return dyn_cast<VarDecl>(chain().front());
3154  }
3155 
3157  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3158 
3159  // Implement isa/cast/dyncast/etc.
3160  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3161  static bool classofKind(Kind K) { return K == IndirectField; }
3162 };
3163 
3164 /// Represents a declaration of a type.
3165 class TypeDecl : public NamedDecl {
3166  friend class ASTContext;
3167 
3168  /// This indicates the Type object that represents
3169  /// this TypeDecl. It is a cache maintained by
3170  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3171  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3172  mutable const Type *TypeForDecl = nullptr;
3173 
3174  /// The start of the source range for this declaration.
3175  SourceLocation LocStart;
3176 
3177  void anchor() override;
3178 
3179 protected:
3181  SourceLocation StartL = SourceLocation())
3182  : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3183 
3184 public:
3185  // Low-level accessor. If you just want the type defined by this node,
3186  // check out ASTContext::getTypeDeclType or one of
3187  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
3188  // already know the specific kind of node this is.
3189  const Type *getTypeForDecl() const { return TypeForDecl; }
3190  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
3191 
3192  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3193  void setLocStart(SourceLocation L) { LocStart = L; }
3194  SourceRange getSourceRange() const override LLVM_READONLY {
3195  if (LocStart.isValid())
3196  return SourceRange(LocStart, getLocation());
3197  else
3198  return SourceRange(getLocation());
3199  }
3200 
3201  // Implement isa/cast/dyncast/etc.
3202  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3203  static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3204 };
3205 
3206 /// Base class for declarations which introduce a typedef-name.
3207 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3208  struct alignas(8) ModedTInfo {
3209  TypeSourceInfo *first;
3210  QualType second;
3211  };
3212 
3213  /// If int part is 0, we have not computed IsTransparentTag.
3214  /// Otherwise, IsTransparentTag is (getInt() >> 1).
3215  mutable llvm::PointerIntPair<
3216  llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3217  MaybeModedTInfo;
3218 
3219  void anchor() override;
3220 
3221 protected:
3223  SourceLocation StartLoc, SourceLocation IdLoc,
3224  IdentifierInfo *Id, TypeSourceInfo *TInfo)
3225  : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3226  MaybeModedTInfo(TInfo, 0) {}
3227 
3229 
3231  return getNextRedeclaration();
3232  }
3233 
3235  return getPreviousDecl();
3236  }
3237 
3239  return getMostRecentDecl();
3240  }
3241 
3242 public:
3244  using redecl_iterator = redeclarable_base::redecl_iterator;
3245 
3252 
3253  bool isModed() const {
3254  return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
3255  }
3256 
3258  return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first
3259  : MaybeModedTInfo.getPointer().get<TypeSourceInfo *>();
3260  }
3261 
3263  return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second
3264  : MaybeModedTInfo.getPointer()
3265  .get<TypeSourceInfo *>()
3266  ->getType();
3267  }
3268 
3270  MaybeModedTInfo.setPointer(newType);
3271  }
3272 
3273  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
3274  MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3275  ModedTInfo({unmodedTSI, modedTy}));
3276  }
3277 
3278  /// Retrieves the canonical declaration of this typedef-name.
3280  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3281 
3282  /// Retrieves the tag declaration for which this is the typedef name for
3283  /// linkage purposes, if any.
3284  ///
3285  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3286  /// this typedef declaration.
3287  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3288 
3289  /// Determines if this typedef shares a name and spelling location with its
3290  /// underlying tag type, as is the case with the NS_ENUM macro.
3291  bool isTransparentTag() const {
3292  if (MaybeModedTInfo.getInt())
3293  return MaybeModedTInfo.getInt() & 0x2;
3294  return isTransparentTagSlow();
3295  }
3296 
3297  // Implement isa/cast/dyncast/etc.
3298  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3299  static bool classofKind(Kind K) {
3300  return K >= firstTypedefName && K <= lastTypedefName;
3301  }
3302 
3303 private:
3304  bool isTransparentTagSlow() const;
3305 };
3306 
3307 /// Represents the declaration of a typedef-name via the 'typedef'
3308 /// type specifier.
3312  : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3313 
3314 public:
3315  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3316  SourceLocation StartLoc, SourceLocation IdLoc,
3317  IdentifierInfo *Id, TypeSourceInfo *TInfo);
3318  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3319 
3320  SourceRange getSourceRange() const override LLVM_READONLY;
3321 
3322  // Implement isa/cast/dyncast/etc.
3323  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3324  static bool classofKind(Kind K) { return K == Typedef; }
3325 };
3326 
3327 /// Represents the declaration of a typedef-name via a C++11
3328 /// alias-declaration.
3330  /// The template for which this is the pattern, if any.
3331  TypeAliasTemplateDecl *Template;
3332 
3335  : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3336  Template(nullptr) {}
3337 
3338 public:
3339  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3340  SourceLocation StartLoc, SourceLocation IdLoc,
3341  IdentifierInfo *Id, TypeSourceInfo *TInfo);
3342  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3343 
3344  SourceRange getSourceRange() const override LLVM_READONLY;
3345 
3346  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3347  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3348 
3349  // Implement isa/cast/dyncast/etc.
3350  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3351  static bool classofKind(Kind K) { return K == TypeAlias; }
3352 };
3353 
3354 /// Represents the declaration of a struct/union/class/enum.
3355 class TagDecl : public TypeDecl,
3356  public DeclContext,
3357  public Redeclarable<TagDecl> {
3358  // This class stores some data in DeclContext::TagDeclBits
3359  // to save some space. Use the provided accessors to access it.
3360 public:
3361  // This is really ugly.
3363 
3364 private:
3365  SourceRange BraceRange;
3366 
3367  // A struct representing syntactic qualifier info,
3368  // to be used for the (uncommon) case of out-of-line declarations.
3369  using ExtInfo = QualifierInfo;
3370 
3371  /// If the (out-of-line) tag declaration name
3372  /// is qualified, it points to the qualifier info (nns and range);
3373  /// otherwise, if the tag declaration is anonymous and it is part of
3374  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3375  /// otherwise, if the tag declaration is anonymous and it is used as a
3376  /// declaration specifier for variables, it points to the first VarDecl (used
3377  /// for mangling);
3378  /// otherwise, it is a null (TypedefNameDecl) pointer.
3379  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3380 
3381  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3382  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3383  const ExtInfo *getExtInfo() const {
3384  return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3385  }
3386 
3387 protected:
3388  TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3389  SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3390  SourceLocation StartL);
3391 
3393 
3395  return getNextRedeclaration();
3396  }
3397 
3399  return getPreviousDecl();
3400  }
3401 
3403  return getMostRecentDecl();
3404  }
3405 
3406  /// Completes the definition of this tag declaration.
3407  ///
3408  /// This is a helper function for derived classes.
3409  void completeDefinition();
3410 
3411  /// True if this decl is currently being defined.
3412  void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3413 
3414  /// Indicates whether it is possible for declarations of this kind
3415  /// to have an out-of-date definition.
3416  ///
3417  /// This option is only enabled when modules are enabled.
3418  void setMayHaveOutOfDateDef(bool V = true) {
3419  TagDeclBits.MayHaveOutOfDateDef = V;
3420  }
3421 
3422 public:
3423  friend class ASTDeclReader;
3424  friend class ASTDeclWriter;
3425 
3427  using redecl_iterator = redeclarable_base::redecl_iterator;
3428 
3435 
3436  SourceRange getBraceRange() const { return BraceRange; }
3437  void setBraceRange(SourceRange R) { BraceRange = R; }
3438 
3439  /// Return SourceLocation representing start of source
3440  /// range ignoring outer template declarations.
3442 
3443  /// Return SourceLocation representing start of source
3444  /// range taking into account any outer template declarations.
3446  SourceRange getSourceRange() const override LLVM_READONLY;
3447 
3448  TagDecl *getCanonicalDecl() override;
3449  const TagDecl *getCanonicalDecl() const {
3450  return const_cast<TagDecl*>(this)->getCanonicalDecl();
3451  }
3452 
3453  /// Return true if this declaration is a completion definition of the type.
3454  /// Provided for consistency.
3456  return isCompleteDefinition();
3457  }
3458 
3459  /// Return true if this decl has its body fully specified.
3460  bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3461 
3462  /// True if this decl has its body fully specified.
3463  void setCompleteDefinition(bool V = true) {
3464  TagDeclBits.IsCompleteDefinition = V;
3465  }
3466 
3467  /// Return true if this complete decl is
3468  /// required to be complete for some existing use.
3470  return TagDeclBits.IsCompleteDefinitionRequired;
3471  }
3472 
3473  /// True if this complete decl is
3474  /// required to be complete for some existing use.
3475  void setCompleteDefinitionRequired(bool V = true) {
3476  TagDeclBits.IsCompleteDefinitionRequired = V;
3477  }
3478 
3479  /// Return true if this decl is currently being defined.
3480  bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3481 
3482  /// True if this tag declaration is "embedded" (i.e., defined or declared
3483  /// for the very first time) in the syntax of a declarator.
3484  bool isEmbeddedInDeclarator() const {
3485  return TagDeclBits.IsEmbeddedInDeclarator;
3486  }
3487 
3488  /// True if this tag declaration is "embedded" (i.e., defined or declared
3489  /// for the very first time) in the syntax of a declarator.
3490  void setEmbeddedInDeclarator(bool isInDeclarator) {
3491  TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3492  }
3493 
3494  /// True if this tag is free standing, e.g. "struct foo;".
3495  bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3496 
3497  /// True if this tag is free standing, e.g. "struct foo;".
3498  void setFreeStanding(bool isFreeStanding = true) {
3499  TagDeclBits.IsFreeStanding = isFreeStanding;
3500  }
3501 
3502  /// Indicates whether it is possible for declarations of this kind
3503  /// to have an out-of-date definition.
3504  ///
3505  /// This option is only enabled when modules are enabled.
3506  bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3507 
3508  /// Whether this declaration declares a type that is
3509  /// dependent, i.e., a type that somehow depends on template
3510  /// parameters.
3511  bool isDependentType() const { return isDependentContext(); }
3512 
3513  /// Whether this declaration was a definition in some module but was forced
3514  /// to be a declaration.
3515  ///
3516  /// Useful for clients checking if a module has a definition of a specific
3517  /// symbol and not interested in the final AST with deduplicated definitions.
3519  return TagDeclBits.IsThisDeclarationADemotedDefinition;
3520  }
3521 
3522  /// Mark a definition as a declaration and maintain information it _was_
3523  /// a definition.
3525  assert(isCompleteDefinition() &&
3526  "Should demote definitions only, not forward declarations");
3527  setCompleteDefinition(false);
3528  TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3529  }
3530 
3531  /// Starts the definition of this tag declaration.
3532  ///
3533  /// This method should be invoked at the beginning of the definition
3534  /// of this tag declaration. It will set the tag type into a state
3535  /// where it is in the process of being defined.
3536  void startDefinition();
3537 
3538  /// Returns the TagDecl that actually defines this
3539  /// struct/union/class/enum. When determining whether or not a
3540  /// struct/union/class/enum has a definition, one should use this
3541  /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3542  /// whether or not a specific TagDecl is defining declaration, not
3543  /// whether or not the struct/union/class/enum type is defined.
3544  /// This method returns NULL if there is no TagDecl that defines
3545  /// the struct/union/class/enum.
3546  TagDecl *getDefinition() const;
3547 
3548  StringRef getKindName() const {
3550  }
3551 
3553  return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3554  }
3555 
3556  void setTagKind(TagKind TK) { TagDeclBits.TagDeclKind = TK; }
3557 
3558  bool isStruct() const { return getTagKind() == TTK_Struct; }
3559  bool isInterface() const { return getTagKind() == TTK_Interface; }
3560  bool isClass() const { return getTagKind() == TTK_Class; }
3561  bool isUnion() const { return getTagKind() == TTK_Union; }
3562  bool isEnum() const { return getTagKind() == TTK_Enum; }
3563 
3564  /// Is this tag type named, either directly or via being defined in
3565  /// a typedef of this type?
3566  ///
3567  /// C++11 [basic.link]p8:
3568  /// A type is said to have linkage if and only if:
3569  /// - it is a class or enumeration type that is named (or has a
3570  /// name for linkage purposes) and the name has linkage; ...
3571  /// C++11 [dcl.typedef]p9:
3572  /// If the typedef declaration defines an unnamed class (or enum),
3573  /// the first typedef-name declared by the declaration to be that
3574  /// class type (or enum type) is used to denote the class type (or
3575  /// enum type) for linkage purposes only.
3576  ///
3577  /// C does not have an analogous rule, but the same concept is
3578  /// nonetheless useful in some places.
3579  bool hasNameForLinkage() const {
3580  return (getDeclName() || getTypedefNameForAnonDecl());
3581  }
3582 
3584  return hasExtInfo() ? nullptr
3585  : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
3586  }
3587 
3589 
3590  /// Retrieve the nested-name-specifier that qualifies the name of this
3591  /// declaration, if it was present in the source.
3593  return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3594  : nullptr;
3595  }
3596 
3597  /// Retrieve the nested-name-specifier (with source-location
3598  /// information) that qualifies the name of this declaration, if it was
3599  /// present in the source.
3601  return hasExtInfo() ? getExtInfo()->QualifierLoc
3603  }
3604 
3605  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3606 
3607  unsigned getNumTemplateParameterLists() const {
3608  return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
3609  }
3610 
3612  assert(i < getNumTemplateParameterLists());
3613  return getExtInfo()->TemplParamLists[i];
3614  }
3615 
3618 
3619  // Implement isa/cast/dyncast/etc.
3620  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3621  static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
3622 
3624  return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3625  }
3626 
3628  return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3629  }
3630 };
3631 
3632 /// Represents an enum. In C++11, enums can be forward-declared
3633 /// with a fixed underlying type, and in C we allow them to be forward-declared
3634 /// with no underlying type as an extension.
3635 class EnumDecl : public TagDecl {
3636  // This class stores some data in DeclContext::EnumDeclBits
3637  // to save some space. Use the provided accessors to access it.
3638 
3639  /// This represent the integer type that the enum corresponds
3640  /// to for code generation purposes. Note that the enumerator constants may
3641  /// have a different type than this does.
3642  ///
3643  /// If the underlying integer type was explicitly stated in the source
3644  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3645  /// was automatically deduced somehow, and this is a Type*.
3646  ///
3647  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3648  /// some cases it won't.
3649  ///
3650  /// The underlying type of an enumeration never has any qualifiers, so
3651  /// we can get away with just storing a raw Type*, and thus save an
3652  /// extra pointer when TypeSourceInfo is needed.
3653  llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3654 
3655  /// The integer type that values of this type should
3656  /// promote to. In C, enumerators are generally of an integer type
3657  /// directly, but gcc-style large enumerators (and all enumerators
3658  /// in C++) are of the enum type instead.
3659  QualType PromotionType;
3660 
3661  /// If this enumeration is an instantiation of a member enumeration
3662  /// of a class template specialization, this is the member specialization
3663  /// information.
3664  MemberSpecializationInfo *SpecializationInfo = nullptr;
3665 
3666  /// Store the ODRHash after first calculation.
3667  /// The corresponding flag HasODRHash is in EnumDeclBits
3668  /// and can be accessed with the provided accessors.
3669  unsigned ODRHash;
3670 
3671  EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3672  SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3673  bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3674 
3675  void anchor() override;
3676 
3677  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3679 
3680  /// Sets the width in bits required to store all the
3681  /// non-negative enumerators of this enum.
3682  void setNumPositiveBits(unsigned Num) {
3683  EnumDeclBits.NumPositiveBits = Num;
3684  assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3685  }
3686 
3687  /// Returns the width in bits required to store all the
3688  /// negative enumerators of this enum. (see getNumNegativeBits)
3689  void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3690 
3691 public:
3692  /// True if this tag declaration is a scoped enumeration. Only
3693  /// possible in C++11 mode.
3694  void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3695 
3696  /// If this tag declaration is a scoped enum,
3697  /// then this is true if the scoped enum was declared using the class
3698  /// tag, false if it was declared with the struct tag. No meaning is
3699  /// associated if this tag declaration is not a scoped enum.
3700  void setScopedUsingClassTag(bool ScopedUCT = true) {
3701  EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3702  }
3703 
3704  /// True if this is an Objective-C, C++11, or
3705  /// Microsoft-style enumeration with a fixed underlying type.
3706  void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3707 
3708 private:
3709  /// True if a valid hash is stored in ODRHash.
3710  bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3711  void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3712 
3713 public:
3714  friend class ASTDeclReader;
3715 
3717  return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3718  }
3719  const EnumDecl *getCanonicalDecl() const {
3720  return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3721  }
3722 
3724  return cast_or_null<EnumDecl>(
3725  static_cast<TagDecl *>(this)->getPreviousDecl());
3726  }
3727  const EnumDecl *getPreviousDecl() const {
3728  return const_cast<EnumDecl*>(this)->getPreviousDecl();
3729  }
3730 
3732  return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3733  }
3734  const EnumDecl *getMostRecentDecl() const {
3735  return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3736  }
3737 
3739  return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3740  }
3741 
3742  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3743  SourceLocation StartLoc, SourceLocation IdLoc,
3744  IdentifierInfo *Id, EnumDecl *PrevDecl,
3745  bool IsScoped, bool IsScopedUsingClassTag,
3746  bool IsFixed);
3747  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3748 
3749  /// Overrides to provide correct range when there's an enum-base specifier
3750  /// with forward declarations.
3751  SourceRange getSourceRange() const override LLVM_READONLY;
3752 
3753  /// When created, the EnumDecl corresponds to a
3754  /// forward-declared enum. This method is used to mark the
3755  /// declaration as being defined; its enumerators have already been
3756  /// added (via DeclContext::addDecl). NewType is the new underlying
3757  /// type of the enumeration type.
3758  void completeDefinition(QualType NewType,
3759  QualType PromotionType,
3760  unsigned NumPositiveBits,
3761  unsigned NumNegativeBits);
3762 
3763  // Iterates through the enumerators of this enumeration.
3765  using enumerator_range =
3767 
3770  }
3771 
3773  const EnumDecl *E = getDefinition();
3774  if (!E)
3775  E = this;
3776  return enumerator_iterator(E->decls_begin());
3777  }
3778 
3780  const EnumDecl *E = getDefinition();
3781  if (!E)
3782  E = this;
3783  return enumerator_iterator(E->decls_end());
3784  }
3785 
3786  /// Return the integer type that enumerators should promote to.
3787  QualType getPromotionType() const { return PromotionType; }
3788 
3789  /// Set the promotion type.
3790  void setPromotionType(QualType T) { PromotionType = T; }
3791 
3792  /// Return the integer type this enum decl corresponds to.
3793  /// This returns a null QualType for an enum forward definition with no fixed
3794  /// underlying type.
3796  if (!IntegerType)
3797  return QualType();
3798  if (const Type *T = IntegerType.dyn_cast<const Type*>())
3799  return QualType(T, 0);
3800  return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3801  }
3802 
3803  /// Set the underlying integer type.
3804  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3805 
3806  /// Set the underlying integer type source info.
3807  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3808 
3809  /// Return the type source info for the underlying integer type,
3810  /// if no type source info exists, return 0.
3812  return IntegerType.dyn_cast<TypeSourceInfo*>();
3813  }
3814 
3815  /// Retrieve the source range that covers the underlying type if
3816  /// specified.
3817  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3818 
3819  /// Returns the width in bits required to store all the
3820  /// non-negative enumerators of this enum.
3821  unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
3822 
3823  /// Returns the width in bits required to store all the
3824  /// negative enumerators of this enum. These widths include
3825  /// the rightmost leading 1; that is:
3826  ///
3827  /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
3828  /// ------------------------ ------- -----------------
3829  /// -1 1111111 1
3830  /// -10 1110110 5
3831  /// -101 1001011 8
3832  unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
3833 
3834  /// Returns true if this is a C++11 scoped enumeration.
3835  bool isScoped() const { return EnumDeclBits.IsScoped; }
3836 
3837  /// Returns true if this is a C++11 scoped enumeration.
3838  bool isScopedUsingClassTag() const {
3839  return EnumDeclBits.IsScopedUsingClassTag;
3840  }
3841 
3842  /// Returns true if this is an Objective-C, C++11, or
3843  /// Microsoft-style enumeration with a fixed underlying type.
3844  bool isFixed() const { return EnumDeclBits.IsFixed; }
3845 
3846  unsigned getODRHash();
3847 
3848  /// Returns true if this can be considered a complete type.
3849  bool isComplete() const {
3850  // IntegerType is set for fixed type enums and non-fixed but implicitly
3851  // int-sized Microsoft enums.
3852  return isCompleteDefinition() || IntegerType;
3853  }
3854 
3855  /// Returns true if this enum is either annotated with
3856  /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
3857  bool isClosed() const;
3858 
3859  /// Returns true if this enum is annotated with flag_enum and isn't annotated
3860  /// with enum_extensibility(open).
3861  bool isClosedFlag() const;
3862 
3863  /// Returns true if this enum is annotated with neither flag_enum nor
3864  /// enum_extensibility(open).
3865  bool isClosedNonFlag() const;
3866 
3867  /// Retrieve the enum definition from which this enumeration could
3868  /// be instantiated, if it is an instantiation (rather than a non-template).
3870 
3871  /// Returns the enumeration (declared within the template)
3872  /// from which this enumeration type was instantiated, or NULL if
3873  /// this enumeration was not instantiated from any template.
3875 
3876  /// If this enumeration is a member of a specialization of a
3877  /// templated class, determine what kind of template specialization
3878  /// or instantiation this is.
3880 
3881  /// For an enumeration member that was instantiated from a member
3882  /// enumeration of a templated class, set the template specialiation kind.
3884  SourceLocation PointOfInstantiation = SourceLocation());
3885 
3886  /// If this enumeration is an instantiation of a member enumeration of
3887  /// a class template specialization, retrieves the member specialization
3888  /// information.
3890  return SpecializationInfo;
3891  }
3892 
3893  /// Specify that this enumeration is an instantiation of the
3894  /// member enumeration ED.
3897  setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3898  }
3899 
3900  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3901  static bool classofKind(Kind K) { return K == Enum; }
3902 };
3903 
3904 /// Represents a struct/union/class. For example:
3905 /// struct X; // Forward declaration, no "body".
3906 /// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
3907 /// This decl will be marked invalid if *any* members are invalid.
3908 class RecordDecl : public TagDecl {
3909  // This class stores some data in DeclContext::RecordDeclBits
3910  // to save some space. Use the provided accessors to access it.
3911 public:
3912  friend class DeclContext;
3913  /// Enum that represents the different ways arguments are passed to and
3914  /// returned from function calls. This takes into account the target-specific
3915  /// and version-specific rules along with the rules determined by the
3916  /// language.
3917  enum ArgPassingKind : unsigned {
3918  /// The argument of this type can be passed directly in registers.
3920 
3921  /// The argument of this type cannot be passed directly in registers.
3922  /// Records containing this type as a subobject are not forced to be passed
3923  /// indirectly. This value is used only in C++. This value is required by
3924  /// C++ because, in uncommon situations, it is possible for a class to have
3925  /// only trivial copy/move constructors even when one of its subobjects has
3926  /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
3927  /// constructor in the derived class is deleted).
3929 
3930  /// The argument of this type cannot be passed directly in registers.
3931  /// Records containing this type as a subobject are forced to be passed
3932  /// indirectly.
3934  };
3935 
3936 protected:
3937  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3938  SourceLocation StartLoc, SourceLocation IdLoc,
3939  IdentifierInfo *Id, RecordDecl *PrevDecl);
3940 
3941 public:
3942  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3943  SourceLocation StartLoc, SourceLocation IdLoc,
3944  IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3945  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3946 
3948  return cast_or_null<RecordDecl>(
3949  static_cast<TagDecl *>(this)->getPreviousDecl());
3950  }
3951  const RecordDecl *getPreviousDecl() const {
3952  return const_cast<RecordDecl*>(this)->getPreviousDecl();
3953  }
3954 
3956  return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3957  }
3959  return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3960  }
3961 
3962  bool hasFlexibleArrayMember() const {
3963  return RecordDeclBits.HasFlexibleArrayMember;
3964  }
3965 
3967  RecordDeclBits.HasFlexibleArrayMember = V;
3968  }
3969 
3970  /// Whether this is an anonymous struct or union. To be an anonymous
3971  /// struct or union, it must have been declared without a name and
3972  /// there must be no objects of this type declared, e.g.,
3973  /// @code
3974  /// union { int i; float f; };
3975  /// @endcode
3976  /// is an anonymous union but neither of the following are:
3977  /// @code
3978  /// union X { int i; float f; };
3979  /// union { int i; float f; } obj;
3980  /// @endcode
3982  return RecordDeclBits.AnonymousStructOrUnion;
3983  }
3984 
3985  void setAnonymousStructOrUnion(bool Anon) {
3986  RecordDeclBits.AnonymousStructOrUnion = Anon;
3987  }
3988 
3989  bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
3990  void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
3991 
3992  bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
3993 
3994  void setHasVolatileMember(bool val) {
3995  RecordDeclBits.HasVolatileMember = val;
3996  }
3997 
3999  return RecordDeclBits.LoadedFieldsFromExternalStorage;
4000  }
4001 
4003  RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4004  }
4005 
4006  /// Functions to query basic properties of non-trivial C structs.
4008  return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4009  }
4010 
4012  RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4013  }
4014 
4016  return RecordDeclBits.NonTrivialToPrimitiveCopy;
4017  }
4018 
4020  RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4021  }
4022 
4024  return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4025  }
4026 
4028  RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4029  }
4030 
4032  return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4033  }
4034 
4036  RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4037  }
4038 
4040  return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4041  }
4042 
4044  RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4045  }
4046 
4048  return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4049  }
4050 
4052  RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4053  }
4054 
4055  /// Determine whether this class can be passed in registers. In C++ mode,
4056  /// it must have at least one trivial, non-deleted copy or move constructor.
4057  /// FIXME: This should be set as part of completeDefinition.
4058  bool canPassInRegisters() const {
4060  }
4061 
4063  return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
4064  }
4065 
4067  RecordDeclBits.ArgPassingRestrictions = Kind;
4068  }
4069 
4071  return RecordDeclBits.ParamDestroyedInCallee;
4072  }
4073 
4075  RecordDeclBits.ParamDestroyedInCallee = V;
4076  }
4077 
4078  bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4079 
4080  void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4081 
4082  void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4083 
4084  /// Determines whether this declaration represents the
4085  /// injected class name.
4086  ///
4087  /// The injected class name in C++ is the name of the class that
4088  /// appears inside the class itself. For example:
4089  ///
4090  /// \code
4091  /// struct C {
4092  /// // C is implicitly declared here as a synonym for the class name.
4093  /// };
4094  ///
4095  /// C::C c; // same as "C c;"
4096  /// \endcode
4097  bool isInjectedClassName() const;
4098 
4099  /// Determine whether this record is a class describing a lambda
4100  /// function object.
4101  bool isLambda() const;
4102 
4103  /// Determine whether this record is a record for captured variables in
4104  /// CapturedStmt construct.
4105  bool isCapturedRecord() const;
4106 
4107  /// Mark the record as a record for captured variables in CapturedStmt
4108  /// construct.
4109  void setCapturedRecord();
4110 
4111  /// Returns the RecordDecl that actually defines
4112  /// this struct/union/class. When determining whether or not a
4113  /// struct/union/class is completely defined, one should use this
4114  /// method as opposed to 'isCompleteDefinition'.
4115  /// 'isCompleteDefinition' indicates whether or not a specific
4116  /// RecordDecl is a completed definition, not whether or not the
4117  /// record type is defined. This method returns NULL if there is
4118  /// no RecordDecl that defines the struct/union/tag.
4120  return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4121  }
4122 
4123  /// Returns whether this record is a union, or contains (at any nesting level)
4124  /// a union member. This is used by CMSE to warn about possible information
4125  /// leaks.
4126  bool isOrContainsUnion() const;
4127 
4128  // Iterator access to field members. The field iterator only visits
4129  // the non-static data members of this class, ignoring any static
4130  // data members, functions, constructors, destructors, etc.
4132  using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4133 
4135  field_iterator field_begin() const;
4136 
4138  return field_iterator(decl_iterator());
4139  }
4140 
4141  // Whether there are any fields (non-static data members) in this record.
4142  bool field_empty() const {
4143  return field_begin() == field_end();
4144  }
4145 
4146  /// Note that the definition of this type is now complete.
4147  virtual void completeDefinition();
4148 
4149  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4150  static bool classofKind(Kind K) {
4151  return K >= firstRecord && K <= lastRecord;
4152  }
4153 
4154  /// Get whether or not this is an ms_struct which can
4155  /// be turned on with an attribute, pragma, or -mms-bitfields
4156  /// commandline option.
4157  bool isMsStruct(const ASTContext &C) const;
4158 
4159  /// Whether we are allowed to insert extra padding between fields.
4160  /// These padding are added to help AddressSanitizer detect
4161  /// intra-object-overflow bugs.
4162  bool mayInsertExtraPadding(bool EmitRemark = false) const;
4163 
4164  /// Finds the first data member which has a name.
4165  /// nullptr is returned if no named data member exists.
4166  const FieldDecl *findFirstNamedDataMember() const;
4167 
4168 private:
4169  /// Deserialize just the fields.
4170  void LoadFieldsFromExternalStorage() const;
4171 };
4172 
4173 class FileScopeAsmDecl : public Decl {
4174  StringLiteral *AsmString;
4175  SourceLocation RParenLoc;
4176 
4177  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
4178  SourceLocation StartL, SourceLocation EndL)
4179  : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4180 
4181  virtual void anchor();
4182 
4183 public:
4185  StringLiteral *Str, SourceLocation AsmLoc,
4186  SourceLocation RParenLoc);
4187 
4188  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4189 
4190  SourceLocation getAsmLoc() const { return getLocation(); }
4191  SourceLocation getRParenLoc() const { return RParenLoc; }
4192  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4193  SourceRange getSourceRange() const override LLVM_READONLY {
4194  return SourceRange(getAsmLoc(), getRParenLoc());
4195  }
4196 
4197  const StringLiteral *getAsmString() const { return AsmString; }
4198  StringLiteral *getAsmString() { return AsmString; }
4199  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
4200 
4201  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4202  static bool classofKind(Kind K) { return K == FileScopeAsm; }
4203 };
4204 
4205 /// Represents a block literal declaration, which is like an
4206 /// unnamed FunctionDecl. For example:
4207 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4208 class BlockDecl : public Decl, public DeclContext {
4209  // This class stores some data in DeclContext::BlockDeclBits
4210  // to save some space. Use the provided accessors to access it.
4211 public:
4212  /// A class which contains all the information about a particular
4213  /// captured value.
4214  class Capture {
4215  enum {
4216  flag_isByRef = 0x1,
4217  flag_isNested = 0x2
4218  };
4219 
4220  /// The variable being captured.
4221  llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4222 
4223  /// The copy expression, expressed in terms of a DeclRef (or
4224  /// BlockDeclRef) to the captured variable. Only required if the
4225  /// variable has a C++ class type.
4226  Expr *CopyExpr;
4227 
4228  public:
4229  Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4230  : VariableAndFlags(variable,
4231  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4232  CopyExpr(copy) {}
4233 
4234  /// The variable being captured.
4235  VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4236 
4237  /// Whether this is a "by ref" capture, i.e. a capture of a __block
4238  /// variable.
4239  bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4240 
4241  bool isEscapingByref() const {
4242  return getVariable()->isEscapingByref();
4243  }
4244 
4245  bool isNonEscapingByref() const {
4246  return getVariable()->isNonEscapingByref();
4247  }
4248 
4249  /// Whether this is a nested capture, i.e. the variable captured
4250  /// is not from outside the immediately enclosing function/block.
4251  bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4252 
4253  bool hasCopyExpr() const { return CopyExpr != nullptr; }
4254  Expr *getCopyExpr() const { return CopyExpr; }
4255  void setCopyExpr(Expr *e) { CopyExpr = e; }
4256  };
4257 
4258 private:
4259  /// A new[]'d array of pointers to ParmVarDecls for the formal
4260  /// parameters of this function. This is null if a prototype or if there are
4261  /// no formals.
4262  ParmVarDecl **ParamInfo = nullptr;
4263  unsigned NumParams = 0;
4264 
4265  Stmt *Body = nullptr;
4266  TypeSourceInfo *SignatureAsWritten = nullptr;
4267 
4268  const Capture *Captures = nullptr;
4269  unsigned NumCaptures = 0;
4270 
4271  unsigned ManglingNumber = 0;
4272  Decl *ManglingContextDecl = nullptr;
4273 
4274 protected:
4275  BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4276 
4277 public:
4279  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4280 
4282 
4283  bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4284  void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4285 
4286  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4287  Stmt *getBody() const override { return (Stmt*) Body; }
4288  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4289 
4290  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4291  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4292 
4293  // ArrayRef access to formal parameters.
4295  return {ParamInfo, getNumParams()};
4296  }
4298  return {ParamInfo, getNumParams()};
4299  }
4300 
4301  // Iterator access to formal parameters.
4304 
4305  bool param_empty() const { return parameters().empty(); }
4306  param_iterator param_begin() { return parameters().begin(); }
4307  param_iterator param_end() { return parameters().end(); }
4308  param_const_iterator param_begin() const { return parameters().begin(); }
4309  param_const_iterator param_end() const { return parameters().end(); }
4310  size_t param_size() const { return parameters().size(); }
4311 
4312  unsigned getNumParams() const { return NumParams; }
4313 
4314  const ParmVarDecl *getParamDecl(unsigned i) const {
4315  assert(i < getNumParams() && "Illegal param #");
4316  return ParamInfo[i];
4317  }
4318  ParmVarDecl *getParamDecl(unsigned i) {
4319  assert(i < getNumParams() && "Illegal param #");
4320  return ParamInfo[i];
4321  }
4322 
4323  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4324 
4325  /// True if this block (or its nested blocks) captures
4326  /// anything of local storage from its enclosing scopes.
4327  bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4328 
4329  /// Returns the number of captured variables.
4330  /// Does not include an entry for 'this'.
4331  unsigned getNumCaptures() const { return NumCaptures; }
4332 
4334 
4335  ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4336 
4337  capture_const_iterator capture_begin() const { return captures().begin(); }
4338  capture_const_iterator capture_end() const { return captures().end(); }
4339 
4340  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4341  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4342 
4343  bool blockMissingReturnType() const {
4344  return BlockDeclBits.BlockMissingReturnType;
4345  }
4346 
4347  void setBlockMissingReturnType(bool val = true) {
4348  BlockDeclBits.BlockMissingReturnType = val;
4349  }
4350 
4351  bool isConversionFromLambda() const {
4352  return BlockDeclBits.IsConversionFromLambda;
4353  }
4354 
4355  void setIsConversionFromLambda(bool val = true) {
4356  BlockDeclBits.IsConversionFromLambda = val;
4357  }
4358 
4359  bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4360  void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4361 
4362  bool canAvoidCopyToHeap() const {
4363  return BlockDeclBits.CanAvoidCopyToHeap;
4364  }
4365  void setCanAvoidCopyToHeap(bool B = true) {
4366  BlockDeclBits.CanAvoidCopyToHeap = B;
4367  }
4368 
4369  bool capturesVariable(const VarDecl *var) const;
4370 
4371  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4372  bool CapturesCXXThis);
4373 
4374  unsigned getBlockManglingNumber() const { return ManglingNumber; }
4375 
4376  Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4377 
4378  void setBlockMangling(unsigned Number, Decl *Ctx) {
4379  ManglingNumber = Number;
4380  ManglingContextDecl = Ctx;
4381  }
4382 
4383  SourceRange getSourceRange() const override LLVM_READONLY;
4384 
4385  // Implement isa/cast/dyncast/etc.
4386  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4387  static bool classofKind(Kind K) { return K == Block; }
4389  return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4390  }
4392  return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4393  }
4394 };
4395 
4396 /// Represents the body of a CapturedStmt, and serves as its DeclContext.
4397 class CapturedDecl final
4398  : public Decl,
4399  public DeclContext,
4400  private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4401 protected:
4402  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4403  return NumParams;
4404  }
4405 
4406 private:
4407  /// The number of parameters to the outlined function.
4408  unsigned NumParams;
4409 
4410  /// The position of context parameter in list of parameters.
4411  unsigned ContextParam;
4412 
4413  /// The body of the outlined function.
4414  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4415 
4416  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4417 
4418  ImplicitParamDecl *const *getParams() const {
4419  return getTrailingObjects<ImplicitParamDecl *>();
4420  }
4421 
4422  ImplicitParamDecl **getParams() {
4423  return getTrailingObjects<ImplicitParamDecl *>();
4424  }
4425 
4426 public:
4427  friend class ASTDeclReader;
4428  friend class ASTDeclWriter;
4430 
4431  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4432  unsigned NumParams);
4433  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4434  unsigned NumParams);
4435 
4436  Stmt *getBody() const override;
4437  void setBody(Stmt *B);
4438 
4439  bool isNothrow() const;
4440  void setNothrow(bool Nothrow = true);
4441 
4442  unsigned getNumParams() const { return NumParams; }
4443 
4444  ImplicitParamDecl *getParam(unsigned i) const {
4445  assert(i < NumParams);
4446  return getParams()[i];
4447  }
4448  void setParam(unsigned i, ImplicitParamDecl *P) {
4449  assert(i < NumParams);
4450  getParams()[i] = P;
4451  }
4452 
4453  // ArrayRef interface to parameters.
4455  return {getParams(), getNumParams()};
4456  }
4458  return {getParams(), getNumParams()};
4459  }
4460 
4461  /// Retrieve the parameter containing captured variables.
4463  assert(ContextParam < NumParams);
4464  return getParam(ContextParam);
4465  }
4466  void setContextParam(unsigned i, ImplicitParamDecl *P) {
4467  assert(i < NumParams);
4468  ContextParam = i;
4469  setParam(i, P);
4470  }
4471  unsigned getContextParamPosition() const { return ContextParam; }
4472 
4474  using param_range = llvm::iterator_range<param_iterator>;
4475 
4476  /// Retrieve an iterator pointing to the first parameter decl.
4477  param_iterator param_begin() const { return getParams(); }
4478  /// Retrieve an iterator one past the last parameter decl.
4479  param_iterator param_end() const { return getParams() + NumParams; }
4480 
4481  // Implement isa/cast/dyncast/etc.
4482  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4483  static bool classofKind(Kind K) { return K == Captured; }
4485  return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4486  }
4488  return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4489  }
4490 };
4491 
4492 /// Describes a module import declaration, which makes the contents
4493 /// of the named module visible in the current translation unit.
4494 ///
4495 /// An import declaration imports the named module (or submodule). For example:
4496 /// \code
4497 /// @import std.vector;
4498 /// \endcode
4499 ///
4500 /// A C++20 module import declaration imports the named module or partition.
4501 /// Periods are permitted in C++20 module names, but have no semantic meaning.
4502 /// For example:
4503 /// \code
4504 /// import NamedModule;
4505 /// import :SomePartition; // Must be a partition of the current module.
4506 /// import Names.Like.this; // Allowed.
4507 /// import :and.Also.Partition.names;
4508 /// \endcode
4509 ///
4510 /// Import declarations can also be implicitly generated from
4511 /// \#include/\#import directives.
4512 class ImportDecl final : public Decl,
4513  llvm::TrailingObjects<ImportDecl, SourceLocation> {
4514  friend class ASTContext;
4515  friend class ASTDeclReader;
4516  friend class ASTReader;
4517  friend TrailingObjects;
4518 
4519  /// The imported module.
4520  Module *ImportedModule = nullptr;
4521 
4522  /// The next import in the list of imports local to the translation
4523  /// unit being parsed (not loaded from an AST file).
4524  ///
4525  /// Includes a bit that indicates whether we have source-location information
4526  /// for each identifier in the module name.
4527  ///
4528  /// When the bit is false, we only have a single source location for the
4529  /// end of the import declaration.
4530  llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
4531 
4532  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4533  ArrayRef<SourceLocation> IdentifierLocs);
4534 
4535  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4536  SourceLocation EndLoc);
4537 
4538  ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4539 
4540  bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
4541 
4542  void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
4543 
4544  /// The next import in the list of imports local to the translation
4545  /// unit being parsed (not loaded from an AST file).
4546  ImportDecl *getNextLocalImport() const {
4547  return NextLocalImportAndComplete.getPointer();
4548  }
4549 
4550  void setNextLocalImport(ImportDecl *Import) {
4551  NextLocalImportAndComplete.setPointer(Import);
4552  }
4553 
4554 public:
4555  /// Create a new module import declaration.
4556  static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4557  SourceLocation StartLoc, Module *Imported,
4558  ArrayRef<SourceLocation> IdentifierLocs);
4559 
4560  /// Create a new module import declaration for an implicitly-generated
4561  /// import.
4562  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4563  SourceLocation StartLoc, Module *Imported,
4564  SourceLocation EndLoc);
4565 
4566  /// Create a new, deserialized module import declaration.
4567  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4568  unsigned NumLocations);
4569 
4570  /// Retrieve the module that was imported by the import declaration.
4571  Module *getImportedModule() const { return ImportedModule; }
4572 
4573  /// Retrieves the locations of each of the identifiers that make up
4574  /// the complete module name in the import declaration.
4575  ///
4576  /// This will return an empty array if the locations of the individual
4577  /// identifiers aren't available.
4579 
4580  SourceRange getSourceRange() const override LLVM_READONLY;
4581 
4582  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4583  static bool classofKind(Kind K) { return K == Import; }
4584 };
4585 
4586 /// Represents a C++ Modules TS module export declaration.
4587 ///
4588 /// For example:
4589 /// \code
4590 /// export void foo();
4591 /// \endcode
4592 class ExportDecl final : public Decl, public DeclContext {
4593  virtual void anchor();
4594 
4595 private:
4596  friend class ASTDeclReader;
4597 
4598  /// The source location for the right brace (if valid).
4599  SourceLocation RBraceLoc;
4600 
4601  ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4602  : Decl(Export, DC, ExportLoc), DeclContext(Export),
4603  RBraceLoc(SourceLocation()) {}
4604 
4605 public:
4606  static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4607  SourceLocation ExportLoc);
4608  static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4609 
4611  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4612  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4613 
4614  bool hasBraces() const { return RBraceLoc.isValid(); }
4615 
4616  SourceLocation getEndLoc() const LLVM_READONLY {
4617  if (hasBraces())
4618  return RBraceLoc;
4619  // No braces: get the end location of the (only) declaration in context
4620  // (if present).
4621  return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
4622  }
4623 
4624  SourceRange getSourceRange() const override LLVM_READONLY {
4625  return SourceRange(getLocation(), getEndLoc());
4626  }
4627 
4628  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4629  static bool classofKind(Kind K) { return K == Export; }
4631  return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4632  }
4634  return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4635  }
4636 };
4637 
4638 /// Represents an empty-declaration.
4639 class EmptyDecl : public Decl {
4640  EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4641 
4642  virtual void anchor();
4643 
4644 public:
4645  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4646  SourceLocation L);
4647  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4648 
4649  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4650  static bool classofKind(Kind K) { return K == Empty; }
4651 };
4652 
4653 /// Insertion operator for diagnostics. This allows sending NamedDecl's
4654 /// into a diagnostic with <<.
4656  const NamedDecl *ND) {
4657  PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
4659  return PD;
4660 }
4661 
4662 template<typename decl_type>
4663 void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4664  // Note: This routine is implemented here because we need both NamedDecl
4665  // and Redeclarable to be defined.
4666  assert(RedeclLink.isFirst() &&
4667  "setPreviousDecl on a decl already in a redeclaration chain");
4668 
4669  if (PrevDecl) {
4670  // Point to previous. Make sure that this is actually the most recent
4671  // redeclaration, or we can build invalid chains. If the most recent
4672  // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4673  First = PrevDecl->getFirstDecl();
4674  assert(First->RedeclLink.isFirst() && "Expected first");
4675  decl_type *MostRecent = First->getNextRedeclaration();
4676  RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4677 
4678  // If the declaration was previously visible, a redeclaration of it remains
4679  // visible even if it wouldn't be visible by itself.
4680  static_cast<decl_type*>(this)->IdentifierNamespace |=
4681  MostRecent->getIdentifierNamespace() &
4683  } else {
4684  // Make this first.
4685  First = static_cast<decl_type*>(this);
4686  }
4687 
4688  // First one will point to this one as latest.
4689  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4690 
4691  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4692  cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4693 }
4694 
4695 // Inline function definitions.
4696 
4697 /// Check if the given decl is complete.
4698 ///
4699 /// We use this function to break a cycle between the inline definitions in
4700 /// Type.h and Decl.h.
4701 inline bool IsEnumDeclComplete(EnumDecl *ED) {
4702  return ED->isComplete();
4703 }
4704 
4705 /// Check if the given decl is scoped.
4706 ///
4707 /// We use this function to break a cycle between the inline definitions in
4708 /// Type.h and Decl.h.
4709 inline bool IsEnumDeclScoped(EnumDecl *ED) {
4710  return ED->isScoped();
4711 }
4712 
4713 /// OpenMP variants are mangled early based on their OpenMP context selector.
4714 /// The new name looks likes this:
4715 /// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
4716 static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
4717  return "$ompvariant";
4718 }
4719 
4720 } // namespace clang
4721 
4722 #endif // LLVM_CLANG_AST_DECL_H
clang::FunctionDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4091
clang::DeclaratorDecl::getInnerLocStart
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:769
clang::TypeDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:3194
clang::FieldDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4323
clang::FunctionDecl::getParamDecl
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:2537
clang::EnumDecl::setIntegerTypeSourceInfo
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition: Decl.h:3807
clang::LabelStmt
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:1803
clang::TagDecl::hasNameForLinkage
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition: Decl.h:3579
clang::TagDecl::getKindName
StringRef getKindName() const
Definition: Decl.h:3548
clang::RecordDecl::hasFlexibleArrayMember
bool hasFlexibleArrayMember() const
Definition: Decl.h:3962
clang::ExportDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4624
clang::FunctionDecl::getMultiVersionKind
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition: Decl.cpp:3326
clang::VarDecl::TentativeDefinition
@ TentativeDefinition
This declaration is a tentative definition.
Definition: Decl.h:1213
clang::FunctionDecl::getBody
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.h:2153
clang::EmptyDecl
Represents an empty-declaration.
Definition: Decl.h:4639
clang::FieldDecl::getBitWidthValue
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:4260
clang::LabelDecl::Create
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:4918
clang::FunctionDecl::castFromDeclContext
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:2856
clang::VarDecl::DAK_Unparsed
@ DAK_Unparsed
Definition: Decl.h:943
clang::FunctionDecl::doesThisDeclarationHaveABody
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2179
clang::FunctionDecl::getDefinition
const FunctionDecl * getDefinition() const
Definition: Decl.h:2141
clang::FunctionDecl::param_empty
bool param_empty() const
Definition: Decl.h:2521
clang::ImportDecl::classof
static bool classof(const Decl *D)
Definition: Decl.h:4582
clang::NamespaceDecl::Create
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl)
Definition: DeclCXX.cpp:2878
clang::FunctionDecl::getDefaultedFunctionInfo
DefaultedFunctionInfo * getDefaultedFunctionInfo() const
Definition: Decl.cpp:3010
clang::TypeDecl::classofKind
static bool classofKind(Kind K)
Definition: Decl.h:3203
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::VarDecl::isKnownToBeDefined
bool isKnownToBeDefined() const
Definition: Decl.cpp:2691
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2231
clang::NamedDecl::classof
static bool classof(const Decl *D)
Definition: Decl.h:480
clang::BlockDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4294
clang::RecordDecl::APK_CanPassInRegs
@ APK_CanPassInRegs
The argument of this type can be passed directly in registers.
Definition: Decl.h:3919
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2139
clang::RecordDecl::field_begin
field_iterator field_begin() const
Definition: Decl.cpp:4682
clang::Decl::IDNS_Type
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition: DeclBase.h:127
clang::ParmVarDecl::setUnparsedDefaultArg
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1809
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::RecordDecl::setHasNonTrivialToPrimitiveCopyCUnion
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition: Decl.h:4051
clang::FunctionDecl::setRangeEnd
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2073
clang::FunctionDecl::hasWrittenPrototype
bool hasWr