clang  14.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,
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,
1075  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  // Implement isa/cast/dyncast/etc.
1595  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1596  static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1597 };
1598 
1599 class ImplicitParamDecl : public VarDecl {
1600  void anchor() override;
1601 
1602 public:
1603  /// Defines the kind of the implicit parameter: is this an implicit parameter
1604  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1605  /// context or something else.
1606  enum ImplicitParamKind : unsigned {
1607  /// Parameter for Objective-C 'self' argument
1609 
1610  /// Parameter for Objective-C '_cmd' argument
1612 
1613  /// Parameter for C++ 'this' argument
1615 
1616  /// Parameter for C++ virtual table pointers
1618 
1619  /// Parameter for captured context
1621 
1622  /// Other implicit parameter
1624  };
1625 
1626  /// Create implicit parameter.
1629  QualType T, ImplicitParamKind ParamKind);
1631  ImplicitParamKind ParamKind);
1632 
1633  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1634 
1637  ImplicitParamKind ParamKind)
1638  : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1639  /*TInfo=*/nullptr, SC_None) {
1640  NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1641  setImplicit();
1642  }
1643 
1645  : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1646  SourceLocation(), /*Id=*/nullptr, Type,
1647  /*TInfo=*/nullptr, SC_None) {
1648  NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1649  setImplicit();
1650  }
1651 
1652  /// Returns the implicit parameter kind.
1654  return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1655  }
1656 
1657  // Implement isa/cast/dyncast/etc.
1658  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1659  static bool classofKind(Kind K) { return K == ImplicitParam; }
1660 };
1661 
1662 /// Represents a parameter to a function.
1663 class ParmVarDecl : public VarDecl {
1664 public:
1665  enum { MaxFunctionScopeDepth = 255 };
1666  enum { MaxFunctionScopeIndex = 255 };
1667 
1668 protected:
1671  TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1672  : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1673  assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1674  assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1675  assert(ParmVarDeclBits.IsKNRPromoted == false);
1676  assert(ParmVarDeclBits.IsObjCMethodParam == false);
1677  setDefaultArg(DefArg);
1678  }
1679 
1680 public:
1681  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1682  SourceLocation StartLoc,
1684  QualType T, TypeSourceInfo *TInfo,
1685  StorageClass S, Expr *DefArg);
1686 
1687  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1688 
1689  SourceRange getSourceRange() const override LLVM_READONLY;
1690 
1691  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1692  ParmVarDeclBits.IsObjCMethodParam = true;
1693  setParameterIndex(parameterIndex);
1694  }
1695 
1696  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1697  assert(!ParmVarDeclBits.IsObjCMethodParam);
1698 
1699  ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1700  assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1701  && "truncation!");
1702 
1703  setParameterIndex(parameterIndex);
1704  }
1705 
1706  bool isObjCMethodParameter() const {
1707  return ParmVarDeclBits.IsObjCMethodParam;
1708  }
1709 
1710  /// Determines whether this parameter is destroyed in the callee function.
1711  bool isDestroyedInCallee() const;
1712 
1713  unsigned getFunctionScopeDepth() const {
1714  if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1715  return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1716  }
1717 
1718  static constexpr unsigned getMaxFunctionScopeDepth() {
1719  return (1u << NumScopeDepthOrObjCQualsBits) - 1;
1720  }
1721 
1722  /// Returns the index of this parameter in its prototype or method scope.
1723  unsigned getFunctionScopeIndex() const {
1724  return getParameterIndex();
1725  }
1726 
1728  if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1729  return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1730  }
1732  assert(ParmVarDeclBits.IsObjCMethodParam);
1733  ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1734  }
1735 
1736  /// True if the value passed to this parameter must undergo
1737  /// K&R-style default argument promotion:
1738  ///
1739  /// C99 6.5.2.2.
1740  /// If the expression that denotes the called function has a type
1741  /// that does not include a prototype, the integer promotions are
1742  /// performed on each argument, and arguments that have type float
1743  /// are promoted to double.
1744  bool isKNRPromoted() const {
1745  return ParmVarDeclBits.IsKNRPromoted;
1746  }
1747  void setKNRPromoted(bool promoted) {
1748  ParmVarDeclBits.IsKNRPromoted = promoted;
1749  }
1750 
1751  Expr *getDefaultArg();
1752  const Expr *getDefaultArg() const {
1753  return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1754  }
1755 
1756  void setDefaultArg(Expr *defarg);
1757 
1758  /// Retrieve the source range that covers the entire default
1759  /// argument.
1764  return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1765  }
1766 
1767  /// Determines whether this parameter has a default argument,
1768  /// either parsed or not.
1769  bool hasDefaultArg() const;
1770 
1771  /// Determines whether this parameter has a default argument that has not
1772  /// yet been parsed. This will occur during the processing of a C++ class
1773  /// whose member functions have default arguments, e.g.,
1774  /// @code
1775  /// class X {
1776  /// public:
1777  /// void f(int x = 17); // x has an unparsed default argument now
1778  /// }; // x has a regular default argument now
1779  /// @endcode
1780  bool hasUnparsedDefaultArg() const {
1781  return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1782  }
1783 
1785  return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1786  }
1787 
1788  /// Specify that this parameter has an unparsed default argument.
1789  /// The argument will be replaced with a real default argument via
1790  /// setDefaultArg when the class definition enclosing the function
1791  /// declaration that owns this default argument is completed.
1793  ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1794  }
1795 
1796  bool hasInheritedDefaultArg() const {
1797  return ParmVarDeclBits.HasInheritedDefaultArg;
1798  }
1799 
1800  void setHasInheritedDefaultArg(bool I = true) {
1801  ParmVarDeclBits.HasInheritedDefaultArg = I;
1802  }
1803 
1804  QualType getOriginalType() const;
1805 
1806  /// Sets the function declaration that owns this
1807  /// ParmVarDecl. Since ParmVarDecls are often created before the
1808  /// FunctionDecls that own them, this routine is required to update
1809  /// the DeclContext appropriately.
1811 
1812  // Implement isa/cast/dyncast/etc.
1813  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1814  static bool classofKind(Kind K) { return K == ParmVar; }
1815 
1816 private:
1817  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1818 
1819  void setParameterIndex(unsigned parameterIndex) {
1820  if (parameterIndex >= ParameterIndexSentinel) {
1821  setParameterIndexLarge(parameterIndex);
1822  return;
1823  }
1824 
1825  ParmVarDeclBits.ParameterIndex = parameterIndex;
1826  assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1827  }
1828  unsigned getParameterIndex() const {
1829  unsigned d = ParmVarDeclBits.ParameterIndex;
1830  return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
1831  }
1832 
1833  void setParameterIndexLarge(unsigned parameterIndex);
1834  unsigned getParameterIndexLarge() const;
1835 };
1836 
1837 enum class MultiVersionKind {
1838  None,
1839  Target,
1840  CPUSpecific,
1841  CPUDispatch,
1842  TargetClones
1843 };
1844 
1845 /// Represents a function declaration or definition.
1846 ///
1847 /// Since a given function can be declared several times in a program,
1848 /// there may be several FunctionDecls that correspond to that
1849 /// function. Only one of those FunctionDecls will be found when
1850 /// traversing the list of declarations in the context of the
1851 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
1852 /// contains all of the information known about the function. Other,
1853 /// previous declarations of the function are available via the
1854 /// getPreviousDecl() chain.
1856  public DeclContext,
1857  public Redeclarable<FunctionDecl> {
1858  // This class stores some data in DeclContext::FunctionDeclBits
1859  // to save some space. Use the provided accessors to access it.
1860 public:
1861  /// The kind of templated function a FunctionDecl can be.
1863  // Not templated.
1865  // The pattern in a function template declaration.
1867  // A non-template function that is an instantiation or explicit
1868  // specialization of a member of a templated class.
1870  // An instantiation or explicit specialization of a function template.
1871  // Note: this might have been instantiated from a templated class if it
1872  // is a class-scope explicit specialization.
1874  // A function template specialization that hasn't yet been resolved to a
1875  // particular specialized function template.
1877  };
1878 
1879  /// Stashed information about a defaulted function definition whose body has
1880  /// not yet been lazily generated.
1882  : llvm::TrailingObjects<DefaultedFunctionInfo, DeclAccessPair> {
1883  friend TrailingObjects;
1884  unsigned NumLookups;
1885 
1886  public:
1887  static DefaultedFunctionInfo *Create(ASTContext &Context,
1888  ArrayRef<DeclAccessPair> Lookups);
1889  /// Get the unqualified lookup results that should be used in this
1890  /// defaulted function definition.
1892  return {getTrailingObjects<DeclAccessPair>(), NumLookups};
1893  }
1894  };
1895 
1896 private:
1897  /// A new[]'d array of pointers to VarDecls for the formal
1898  /// parameters of this function. This is null if a prototype or if there are
1899  /// no formals.
1900  ParmVarDecl **ParamInfo = nullptr;
1901 
1902  /// The active member of this union is determined by
1903  /// FunctionDeclBits.HasDefaultedFunctionInfo.
1904  union {
1905  /// The body of the function.
1907  /// Information about a future defaulted function definition.
1909  };
1910 
1911  unsigned ODRHash;
1912 
1913  /// End part of this FunctionDecl's source range.
1914  ///
1915  /// We could compute the full range in getSourceRange(). However, when we're
1916  /// dealing with a function definition deserialized from a PCH/AST file,
1917  /// we can only compute the full range once the function body has been
1918  /// de-serialized, so it's far better to have the (sometimes-redundant)
1919  /// EndRangeLoc.
1920  SourceLocation EndRangeLoc;
1921 
1922  /// The template or declaration that this declaration
1923  /// describes or was instantiated from, respectively.
1924  ///
1925  /// For non-templates, this value will be NULL. For function
1926  /// declarations that describe a function template, this will be a
1927  /// pointer to a FunctionTemplateDecl. For member functions
1928  /// of class template specializations, this will be a MemberSpecializationInfo
1929  /// pointer containing information about the specialization.
1930  /// For function template specializations, this will be a
1931  /// FunctionTemplateSpecializationInfo, which contains information about
1932  /// the template being specialized and the template arguments involved in
1933  /// that specialization.
1934  llvm::PointerUnion<FunctionTemplateDecl *,
1938  TemplateOrSpecialization;
1939 
1940  /// Provides source/type location info for the declaration name embedded in
1941  /// the DeclaratorDecl base class.
1942  DeclarationNameLoc DNLoc;
1943 
1944  /// Specify that this function declaration is actually a function
1945  /// template specialization.
1946  ///
1947  /// \param C the ASTContext.
1948  ///
1949  /// \param Template the function template that this function template
1950  /// specialization specializes.
1951  ///
1952  /// \param TemplateArgs the template arguments that produced this
1953  /// function template specialization from the template.
1954  ///
1955  /// \param InsertPos If non-NULL, the position in the function template
1956  /// specialization set where the function template specialization data will
1957  /// be inserted.
1958  ///
1959  /// \param TSK the kind of template specialization this is.
1960  ///
1961  /// \param TemplateArgsAsWritten location info of template arguments.
1962  ///
1963  /// \param PointOfInstantiation point at which the function template
1964  /// specialization was first instantiated.
1965  void setFunctionTemplateSpecialization(ASTContext &C,
1966  FunctionTemplateDecl *Template,
1967  const TemplateArgumentList *TemplateArgs,
1968  void *InsertPos,
1970  const TemplateArgumentListInfo *TemplateArgsAsWritten,
1971  SourceLocation PointOfInstantiation);
1972 
1973  /// Specify that this record is an instantiation of the
1974  /// member function FD.
1975  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1977 
1978  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1979 
1980  // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
1981  // need to access this bit but we want to avoid making ASTDeclWriter
1982  // a friend of FunctionDeclBitfields just for this.
1983  bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
1984 
1985  /// Whether an ODRHash has been stored.
1986  bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
1987 
1988  /// State that an ODRHash has been stored.
1989  void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
1990 
1991 protected:
1992  FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1993  const DeclarationNameInfo &NameInfo, QualType T,
1994  TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
1995  bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
1996  Expr *TrailingRequiresClause = nullptr);
1997 
1999 
2001  return getNextRedeclaration();
2002  }
2003 
2005  return getPreviousDecl();
2006  }
2007 
2009  return getMostRecentDecl();
2010  }
2011 
2012 public:
2013  friend class ASTDeclReader;
2014  friend class ASTDeclWriter;
2015 
2017  using redecl_iterator = redeclarable_base::redecl_iterator;
2018 
2025 
2026  static FunctionDecl *
2029  TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
2030  bool isInlineSpecified = false, bool hasWrittenPrototype = true,
2032  Expr *TrailingRequiresClause = nullptr) {
2033  DeclarationNameInfo NameInfo(N, NLoc);
2034  return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
2036  hasWrittenPrototype, ConstexprKind,
2037  TrailingRequiresClause);
2038  }
2039 
2040  static FunctionDecl *
2041  Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2042  const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2044  bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
2045  Expr *TrailingRequiresClause);
2046 
2047  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2048 
2050  return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2051  }
2052 
2053  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2054  bool Qualified) const override;
2055 
2056  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
2057 
2058  /// Returns the location of the ellipsis of a variadic function.
2060  const auto *FPT = getType()->getAs<FunctionProtoType>();
2061  if (FPT && FPT->isVariadic())
2062  return FPT->getEllipsisLoc();
2063  return SourceLocation();
2064  }
2065 
2066  SourceRange getSourceRange() const override LLVM_READONLY;
2067 
2068  // Function definitions.
2069  //
2070  // A function declaration may be:
2071  // - a non defining declaration,
2072  // - a definition. A function may be defined because:
2073  // - it has a body, or will have it in the case of late parsing.
2074  // - it has an uninstantiated body. The body does not exist because the
2075  // function is not used yet, but the declaration is considered a
2076  // definition and does not allow other definition of this function.
2077  // - it does not have a user specified body, but it does not allow
2078  // redefinition, because it is deleted/defaulted or is defined through
2079  // some other mechanism (alias, ifunc).
2080 
2081  /// Returns true if the function has a body.
2082  ///
2083  /// The function body might be in any of the (re-)declarations of this
2084  /// function. The variant that accepts a FunctionDecl pointer will set that
2085  /// function declaration to the actual declaration containing the body (if
2086  /// there is one).
2087  bool hasBody(const FunctionDecl *&Definition) const;
2088 
2089  bool hasBody() const override {
2090  const FunctionDecl* Definition;
2091  return hasBody(Definition);
2092  }
2093 
2094  /// Returns whether the function has a trivial body that does not require any
2095  /// specific codegen.
2096  bool hasTrivialBody() const;
2097 
2098  /// Returns true if the function has a definition that does not need to be
2099  /// instantiated.
2100  ///
2101  /// The variant that accepts a FunctionDecl pointer will set that function
2102  /// declaration to the declaration that is a definition (if there is one).
2103  ///
2104  /// \param CheckForPendingFriendDefinition If \c true, also check for friend
2105  /// declarations that were instantiataed from function definitions.
2106  /// Such a declaration behaves as if it is a definition for the
2107  /// purpose of redefinition checking, but isn't actually a "real"
2108  /// definition until its body is instantiated.
2109  bool isDefined(const FunctionDecl *&Definition,
2110  bool CheckForPendingFriendDefinition = false) const;
2111 
2112  bool isDefined() const {
2113  const FunctionDecl* Definition;
2114  return isDefined(Definition);
2115  }
2116 
2117  /// Get the definition for this declaration.
2119  const FunctionDecl *Definition;
2120  if (isDefined(Definition))
2121  return const_cast<FunctionDecl *>(Definition);
2122  return nullptr;
2123  }
2124  const FunctionDecl *getDefinition() const {
2125  return const_cast<FunctionDecl *>(this)->getDefinition();
2126  }
2127 
2128  /// Retrieve the body (definition) of the function. The function body might be
2129  /// in any of the (re-)declarations of this function. The variant that accepts
2130  /// a FunctionDecl pointer will set that function declaration to the actual
2131  /// declaration containing the body (if there is one).
2132  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
2133  /// unnecessary AST de-serialization of the body.
2134  Stmt *getBody(const FunctionDecl *&Definition) const;
2135 
2136  Stmt *getBody() const override {
2137  const FunctionDecl* Definition;
2138  return getBody(Definition);
2139  }
2140 
2141  /// Returns whether this specific declaration of the function is also a
2142  /// definition that does not contain uninstantiated body.
2143  ///
2144  /// This does not determine whether the function has been defined (e.g., in a
2145  /// previous definition); for that information, use isDefined.
2146  ///
2147  /// Note: the function declaration does not become a definition until the
2148  /// parser reaches the definition, if called before, this function will return
2149  /// `false`.
2151  return isDeletedAsWritten() || isDefaulted() ||
2154  }
2155 
2156  /// Determine whether this specific declaration of the function is a friend
2157  /// declaration that was instantiated from a function definition. Such
2158  /// declarations behave like definitions in some contexts.
2160 
2161  /// Returns whether this specific declaration of the function has a body.
2163  return (!FunctionDeclBits.HasDefaultedFunctionInfo && Body) ||
2165  }
2166 
2167  void setBody(Stmt *B);
2168  void setLazyBody(uint64_t Offset) {
2169  FunctionDeclBits.HasDefaultedFunctionInfo = false;
2171  }
2172 
2173  void setDefaultedFunctionInfo(DefaultedFunctionInfo *Info);
2174  DefaultedFunctionInfo *getDefaultedFunctionInfo() const;
2175 
2176  /// Whether this function is variadic.
2177  bool isVariadic() const;
2178 
2179  /// Whether this function is marked as virtual explicitly.
2180  bool isVirtualAsWritten() const {
2181  return FunctionDeclBits.IsVirtualAsWritten;
2182  }
2183 
2184  /// State that this function is marked as virtual explicitly.
2185  void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2186 
2187  /// Whether this virtual function is pure, i.e. makes the containing class
2188  /// abstract.
2189  bool isPure() const { return FunctionDeclBits.IsPure; }
2190  void setPure(bool P = true);
2191 
2192  /// Whether this templated function will be late parsed.
2193  bool isLateTemplateParsed() const {
2194  return FunctionDeclBits.IsLateTemplateParsed;
2195  }
2196 
2197  /// State that this templated function will be late parsed.
2198  void setLateTemplateParsed(bool ILT = true) {
2199  FunctionDeclBits.IsLateTemplateParsed = ILT;
2200  }
2201 
2202  /// Whether this function is "trivial" in some specialized C++ senses.
2203  /// Can only be true for default constructors, copy constructors,
2204  /// copy assignment operators, and destructors. Not meaningful until
2205  /// the class has been fully built by Sema.
2206  bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2207  void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2208 
2209  bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2210  void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2211 
2212  /// Whether this function is defaulted. Valid for e.g.
2213  /// special member functions, defaulted comparisions (not methods!).
2214  bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2215  void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2216 
2217  /// Whether this function is explicitly defaulted.
2218  bool isExplicitlyDefaulted() const {
2219  return FunctionDeclBits.IsExplicitlyDefaulted;
2220  }
2221 
2222  /// State that this function is explicitly defaulted.
2223  void setExplicitlyDefaulted(bool ED = true) {
2224  FunctionDeclBits.IsExplicitlyDefaulted = ED;
2225  }
2226 
2227  /// True if this method is user-declared and was not
2228  /// deleted or defaulted on its first declaration.
2229  bool isUserProvided() const {
2230  auto *DeclAsWritten = this;
2232  DeclAsWritten = Pattern;
2233  return !(DeclAsWritten->isDeleted() ||
2234  DeclAsWritten->getCanonicalDecl()->isDefaulted());
2235  }
2236 
2237  /// Whether falling off this function implicitly returns null/zero.
2238  /// If a more specific implicit return value is required, front-ends
2239  /// should synthesize the appropriate return statements.
2240  bool hasImplicitReturnZero() const {
2241  return FunctionDeclBits.HasImplicitReturnZero;
2242  }
2243 
2244  /// State that falling off this function implicitly returns null/zero.
2245  /// If a more specific implicit return value is required, front-ends
2246  /// should synthesize the appropriate return statements.
2247  void setHasImplicitReturnZero(bool IRZ) {
2248  FunctionDeclBits.HasImplicitReturnZero = IRZ;
2249  }
2250 
2251  /// Whether this function has a prototype, either because one
2252  /// was explicitly written or because it was "inherited" by merging
2253  /// a declaration without a prototype with a declaration that has a
2254  /// prototype.
2255  bool hasPrototype() const {
2257  }
2258 
2259  /// Whether this function has a written prototype.
2260  bool hasWrittenPrototype() const {
2261  return FunctionDeclBits.HasWrittenPrototype;
2262  }
2263 
2264  /// State that this function has a written prototype.
2265  void setHasWrittenPrototype(bool P = true) {
2266  FunctionDeclBits.HasWrittenPrototype = P;
2267  }
2268 
2269  /// Whether this function inherited its prototype from a
2270  /// previous declaration.
2271  bool hasInheritedPrototype() const {
2272  return FunctionDeclBits.HasInheritedPrototype;
2273  }
2274 
2275  /// State that this function inherited its prototype from a
2276  /// previous declaration.
2277  void setHasInheritedPrototype(bool P = true) {
2278  FunctionDeclBits.HasInheritedPrototype = P;
2279  }
2280 
2281  /// Whether this is a (C++11) constexpr function or constexpr constructor.
2282  bool isConstexpr() const {
2284  }
2286  FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK);
2287  }
2289  return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
2290  }
2291  bool isConstexprSpecified() const {
2293  }
2294  bool isConsteval() const {
2296  }
2297 
2298  /// Whether the instantiation of this function is pending.
2299  /// This bit is set when the decision to instantiate this function is made
2300  /// and unset if and when the function body is created. That leaves out
2301  /// cases where instantiation did not happen because the template definition
2302  /// was not seen in this TU. This bit remains set in those cases, under the
2303  /// assumption that the instantiation will happen in some other TU.
2304  bool instantiationIsPending() const {
2305  return FunctionDeclBits.InstantiationIsPending;
2306  }
2307 
2308  /// State that the instantiation of this function is pending.
2309  /// (see instantiationIsPending)
2311  FunctionDeclBits.InstantiationIsPending = IC;
2312  }
2313 
2314  /// Indicates the function uses __try.
2315  bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2316  void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2317 
2318  /// Whether this function has been deleted.
2319  ///
2320  /// A function that is "deleted" (via the C++0x "= delete" syntax)
2321  /// acts like a normal function, except that it cannot actually be
2322  /// called or have its address taken. Deleted functions are
2323  /// typically used in C++ overload resolution to attract arguments
2324  /// whose type or lvalue/rvalue-ness would permit the use of a
2325  /// different overload that would behave incorrectly. For example,
2326  /// one might use deleted functions to ban implicit conversion from
2327  /// a floating-point number to an Integer type:
2328  ///
2329  /// @code
2330  /// struct Integer {
2331  /// Integer(long); // construct from a long
2332  /// Integer(double) = delete; // no construction from float or double
2333  /// Integer(long double) = delete; // no construction from long double
2334  /// };
2335  /// @endcode
2336  // If a function is deleted, its first declaration must be.
2337  bool isDeleted() const {
2338  return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2339  }
2340 
2341  bool isDeletedAsWritten() const {
2342  return FunctionDeclBits.IsDeleted && !isDefaulted();
2343  }
2344 
2345  void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
2346 
2347  /// Determines whether this function is "main", which is the
2348  /// entry point into an executable program.
2349  bool isMain() const;
2350 
2351  /// Determines whether this function is a MSVCRT user defined entry
2352  /// point.
2353  bool isMSVCRTEntryPoint() const;
2354 
2355  /// Determines whether this operator new or delete is one
2356  /// of the reserved global placement operators:
2357  /// void *operator new(size_t, void *);
2358  /// void *operator new[](size_t, void *);
2359  /// void operator delete(void *, void *);
2360  /// void operator delete[](void *, void *);
2361  /// These functions have special behavior under [new.delete.placement]:
2362  /// These functions are reserved, a C++ program may not define
2363  /// functions that displace the versions in the Standard C++ library.
2364  /// The provisions of [basic.stc.dynamic] do not apply to these
2365  /// reserved placement forms of operator new and operator delete.
2366  ///
2367  /// This function must be an allocation or deallocation function.
2368  bool isReservedGlobalPlacementOperator() const;
2369 
2370  /// Determines whether this function is one of the replaceable
2371  /// global allocation functions:
2372  /// void *operator new(size_t);
2373  /// void *operator new(size_t, const std::nothrow_t &) noexcept;
2374  /// void *operator new[](size_t);
2375  /// void *operator new[](size_t, const std::nothrow_t &) noexcept;
2376  /// void operator delete(void *) noexcept;
2377  /// void operator delete(void *, std::size_t) noexcept; [C++1y]
2378  /// void operator delete(void *, const std::nothrow_t &) noexcept;
2379  /// void operator delete[](void *) noexcept;
2380  /// void operator delete[](void *, std::size_t) noexcept; [C++1y]
2381  /// void operator delete[](void *, const std::nothrow_t &) noexcept;
2382  /// These functions have special behavior under C++1y [expr.new]:
2383  /// An implementation is allowed to omit a call to a replaceable global
2384  /// allocation function. [...]
2385  ///
2386  /// If this function is an aligned allocation/deallocation function, return
2387  /// the parameter number of the requested alignment through AlignmentParam.
2388  ///
2389  /// If this function is an allocation/deallocation function that takes
2390  /// the `std::nothrow_t` tag, return true through IsNothrow,
2392  Optional<unsigned> *AlignmentParam = nullptr,
2393  bool *IsNothrow = nullptr) const;
2394 
2395  /// Determine if this function provides an inline implementation of a builtin.
2396  bool isInlineBuiltinDeclaration() const;
2397 
2398  /// Determine whether this is a destroying operator delete.
2399  bool isDestroyingOperatorDelete() const;
2400 
2401  /// Compute the language linkage.
2403 
2404  /// Determines whether this function is a function with
2405  /// external, C linkage.
2406  bool isExternC() const;
2407 
2408  /// Determines whether this function's context is, or is nested within,
2409  /// a C++ extern "C" linkage spec.
2410  bool isInExternCContext() const;
2411 
2412  /// Determines whether this function's context is, or is nested within,
2413  /// a C++ extern "C++" linkage spec.
2414  bool isInExternCXXContext() const;
2415 
2416  /// Determines whether this is a global function.
2417  bool isGlobal() const;
2418 
2419  /// Determines whether this function is known to be 'noreturn', through
2420  /// an attribute on its declaration or its type.
2421  bool isNoReturn() const;
2422 
2423  /// True if the function was a definition but its body was skipped.
2424  bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2425  void setHasSkippedBody(bool Skipped = true) {
2426  FunctionDeclBits.HasSkippedBody = Skipped;
2427  }
2428 
2429  /// True if this function will eventually have a body, once it's fully parsed.
2430  bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2431  void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2432 
2433  /// True if this function is considered a multiversioned function.
2434  bool isMultiVersion() const {
2435  return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2436  }
2437 
2438  /// Sets the multiversion state for this declaration and all of its
2439  /// redeclarations.
2440  void setIsMultiVersion(bool V = true) {
2441  getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2442  }
2443 
2444  /// Gets the kind of multiversioning attribute this declaration has. Note that
2445  /// this can return a value even if the function is not multiversion, such as
2446  /// the case of 'target'.
2448 
2449 
2450  /// True if this function is a multiversioned dispatch function as a part of
2451  /// the cpu_specific/cpu_dispatch functionality.
2452  bool isCPUDispatchMultiVersion() const;
2453  /// True if this function is a multiversioned processor specific function as a
2454  /// part of the cpu_specific/cpu_dispatch functionality.
2455  bool isCPUSpecificMultiVersion() const;
2456 
2457  /// True if this function is a multiversioned dispatch function as a part of
2458  /// the target functionality.
2459  bool isTargetMultiVersion() const;
2460 
2461  /// True if this function is a multiversioned dispatch function as a part of
2462  /// the target-clones functionality.
2463  bool isTargetClonesMultiVersion() const;
2464 
2465  /// \brief Get the associated-constraints of this function declaration.
2466  /// Currently, this will either be a vector of size 1 containing the
2467  /// trailing-requires-clause or an empty vector.
2468  ///
2469  /// Use this instead of getTrailingRequiresClause for concepts APIs that
2470  /// accept an ArrayRef of constraint expressions.
2472  if (auto *TRC = getTrailingRequiresClause())
2473  AC.push_back(TRC);
2474  }
2475 
2476  void setPreviousDeclaration(FunctionDecl * PrevDecl);
2477 
2478  FunctionDecl *getCanonicalDecl() override;
2480  return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2481  }
2482 
2483  unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2484 
2485  // ArrayRef interface to parameters.
2487  return {ParamInfo, getNumParams()};
2488  }
2490  return {ParamInfo, getNumParams()};
2491  }
2492 
2493  // Iterator access to formal parameters.
2496 
2497  bool param_empty() const { return parameters().empty(); }
2498  param_iterator param_begin() { return parameters().begin(); }
2499  param_iterator param_end() { return parameters().end(); }
2500  param_const_iterator param_begin() const { return parameters().begin(); }
2501  param_const_iterator param_end() const { return parameters().end(); }
2502  size_t param_size() const { return parameters().size(); }
2503 
2504  /// Return the number of parameters this function must have based on its
2505  /// FunctionType. This is the length of the ParamInfo array after it has been
2506  /// created.
2507  unsigned getNumParams() const;
2508 
2509  const ParmVarDecl *getParamDecl(unsigned i) const {
2510  assert(i < getNumParams() && "Illegal param #");
2511  return ParamInfo[i];
2512  }
2513  ParmVarDecl *getParamDecl(unsigned i) {
2514  assert(i < getNumParams() && "Illegal param #");
2515  return ParamInfo[i];
2516  }
2517  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2518  setParams(getASTContext(), NewParamInfo);
2519  }
2520 
2521  /// Returns the minimum number of arguments needed to call this function. This
2522  /// may be fewer than the number of function parameters, if some of the
2523  /// parameters have default arguments (in C++).
2524  unsigned getMinRequiredArguments() const;
2525 
2526  /// Determine whether this function has a single parameter, or multiple
2527  /// parameters where all but the first have default arguments.
2528  ///
2529  /// This notion is used in the definition of copy/move constructors and
2530  /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2531  /// parameter packs are not treated specially here.
2532  bool hasOneParamOrDefaultArgs() const;
2533 
2534  /// Find the source location information for how the type of this function
2535  /// was written. May be absent (for example if the function was declared via
2536  /// a typedef) and may contain a different type from that of the function
2537  /// (for example if the function type was adjusted by an attribute).
2539 
2541  return getType()->castAs<FunctionType>()->getReturnType();
2542  }
2543 
2544  /// Attempt to compute an informative source range covering the
2545  /// function return type. This may omit qualifiers and other information with
2546  /// limited representation in the AST.
2548 
2549  /// Attempt to compute an informative source range covering the
2550  /// function parameters, including the ellipsis of a variadic function.
2551  /// The source range excludes the parentheses, and is invalid if there are
2552  /// no parameters and no ellipsis.
2554 
2555  /// Get the declared return type, which may differ from the actual return
2556  /// type if the return type is deduced.
2558  auto *TSI = getTypeSourceInfo();
2559  QualType T = TSI ? TSI->getType() : getType();
2560  return T->castAs<FunctionType>()->getReturnType();
2561  }
2562 
2563  /// Gets the ExceptionSpecificationType as declared.
2565  auto *TSI = getTypeSourceInfo();
2566  QualType T = TSI ? TSI->getType() : getType();
2567  const auto *FPT = T->getAs<FunctionProtoType>();
2568  return FPT ? FPT->getExceptionSpecType() : EST_None;
2569  }
2570 
2571  /// Attempt to compute an informative source range covering the
2572  /// function exception specification, if any.
2574 
2575  /// Determine the type of an expression that calls this function.
2578  getASTContext());
2579  }
2580 
2581  /// Returns the storage class as written in the source. For the
2582  /// computed linkage of symbol, see getLinkage.
2584  return static_cast<StorageClass>(FunctionDeclBits.SClass);
2585  }
2586 
2587  /// Sets the storage class as written in the source.
2589  FunctionDeclBits.SClass = SClass;
2590  }
2591 
2592  /// Determine whether the "inline" keyword was specified for this
2593  /// function.
2594  bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2595 
2596  /// Set whether the "inline" keyword was specified for this function.
2597  void setInlineSpecified(bool I) {
2598  FunctionDeclBits.IsInlineSpecified = I;
2599  FunctionDeclBits.IsInline = I;
2600  }
2601 
2602  /// Determine whether the function was declared in source context
2603  /// that requires constrained FP intrinsics
2604  bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
2605 
2606  /// Set whether the function was declared in source context
2607  /// that requires constrained FP intrinsics
2608  void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
2609 
2610  /// Flag that this function is implicitly inline.
2611  void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2612 
2613  /// Determine whether this function should be inlined, because it is
2614  /// either marked "inline" or "constexpr" or is a member function of a class
2615  /// that was defined in the class body.
2616  bool isInlined() const { return FunctionDeclBits.IsInline; }
2617 
2619 
2620  bool isMSExternInline() const;
2621 
2623 
2624  bool isStatic() const { return getStorageClass() == SC_Static; }
2625 
2626  /// Whether this function declaration represents an C++ overloaded
2627  /// operator, e.g., "operator+".
2628  bool isOverloadedOperator() const {
2629  return getOverloadedOperator() != OO_None;
2630  }
2631 
2633 
2634  const IdentifierInfo *getLiteralIdentifier() const;
2635 
2636  /// If this function is an instantiation of a member function
2637  /// of a class template specialization, retrieves the function from
2638  /// which it was instantiated.
2639  ///
2640  /// This routine will return non-NULL for (non-templated) member
2641  /// functions of class templates and for instantiations of function
2642  /// templates. For example, given:
2643  ///
2644  /// \code
2645  /// template<typename T>
2646  /// struct X {
2647  /// void f(T);
2648  /// };
2649  /// \endcode
2650  ///
2651  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2652  /// whose parent is the class template specialization X<int>. For
2653  /// this declaration, getInstantiatedFromFunction() will return
2654  /// the FunctionDecl X<T>::A. When a complete definition of
2655  /// X<int>::A is required, it will be instantiated from the
2656  /// declaration returned by getInstantiatedFromMemberFunction().
2658 
2659  /// What kind of templated function this is.
2661 
2662  /// If this function is an instantiation of a member function of a
2663  /// class template specialization, retrieves the member specialization
2664  /// information.
2666 
2667  /// Specify that this record is an instantiation of the
2668  /// member function FD.
2671  setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2672  }
2673 
2674  /// Retrieves the function template that is described by this
2675  /// function declaration.
2676  ///
2677  /// Every function template is represented as a FunctionTemplateDecl
2678  /// and a FunctionDecl (or something derived from FunctionDecl). The
2679  /// former contains template properties (such as the template
2680  /// parameter lists) while the latter contains the actual
2681  /// description of the template's
2682  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2683  /// FunctionDecl that describes the function template,
2684  /// getDescribedFunctionTemplate() retrieves the
2685  /// FunctionTemplateDecl from a FunctionDecl.
2687 
2689 
2690  /// Determine whether this function is a function template
2691  /// specialization.
2693  return getPrimaryTemplate() != nullptr;
2694  }
2695 
2696  /// If this function is actually a function template specialization,
2697  /// retrieve information about this function template specialization.
2698  /// Otherwise, returns NULL.
2700 
2701  /// Determines whether this function is a function template
2702  /// specialization or a member of a class template specialization that can
2703  /// be implicitly instantiated.
2704  bool isImplicitlyInstantiable() const;
2705 
2706  /// Determines if the given function was instantiated from a
2707  /// function template.
2708  bool isTemplateInstantiation() const;
2709 
2710  /// Retrieve the function declaration from which this function could
2711  /// be instantiated, if it is an instantiation (rather than a non-template
2712  /// or a specialization, for example).
2713  ///
2714  /// If \p ForDefinition is \c false, explicit specializations will be treated
2715  /// as if they were implicit instantiations. This will then find the pattern
2716  /// corresponding to non-definition portions of the declaration, such as
2717  /// default arguments and the exception specification.
2718  FunctionDecl *
2720 
2721  /// Retrieve the primary template that this function template
2722  /// specialization either specializes or was instantiated from.
2723  ///
2724  /// If this function declaration is not a function template specialization,
2725  /// returns NULL.
2727 
2728  /// Retrieve the template arguments used to produce this function
2729  /// template specialization from the primary template.
2730  ///
2731  /// If this function declaration is not a function template specialization,
2732  /// returns NULL.
2734 
2735  /// Retrieve the template argument list as written in the sources,
2736  /// if any.
2737  ///
2738  /// If this function declaration is not a function template specialization
2739  /// or if it had no explicit template argument list, returns NULL.
2740  /// Note that it an explicit template argument list may be written empty,
2741  /// e.g., template<> void foo<>(char* s);
2744 
2745  /// Specify that this function declaration is actually a function
2746  /// template specialization.
2747  ///
2748  /// \param Template the function template that this function template
2749  /// specialization specializes.
2750  ///
2751  /// \param TemplateArgs the template arguments that produced this
2752  /// function template specialization from the template.
2753  ///
2754  /// \param InsertPos If non-NULL, the position in the function template
2755  /// specialization set where the function template specialization data will
2756  /// be inserted.
2757  ///
2758  /// \param TSK the kind of template specialization this is.
2759  ///
2760  /// \param TemplateArgsAsWritten location info of template arguments.
2761  ///
2762  /// \param PointOfInstantiation point at which the function template
2763  /// specialization was first instantiated.
2765  const TemplateArgumentList *TemplateArgs,
2766  void *InsertPos,
2768  const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2769  SourceLocation PointOfInstantiation = SourceLocation()) {
2770  setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2771  InsertPos, TSK, TemplateArgsAsWritten,
2772  PointOfInstantiation);
2773  }
2774 
2775  /// Specifies that this function declaration is actually a
2776  /// dependent function template specialization.
2778  const UnresolvedSetImpl &Templates,
2779  const TemplateArgumentListInfo &TemplateArgs);
2780 
2783 
2784  /// Determine what kind of template instantiation this function
2785  /// represents.
2787 
2788  /// Determine the kind of template specialization this function represents
2789  /// for the purpose of template instantiation.
2792 
2793  /// Determine what kind of template instantiation this function
2794  /// represents.
2796  SourceLocation PointOfInstantiation = SourceLocation());
2797 
2798  /// Retrieve the (first) point of instantiation of a function template
2799  /// specialization or a member of a class template specialization.
2800  ///
2801  /// \returns the first point of instantiation, if this function was
2802  /// instantiated from a template; otherwise, returns an invalid source
2803  /// location.
2805 
2806  /// Determine whether this is or was instantiated from an out-of-line
2807  /// definition of a member function.
2808  bool isOutOfLine() const override;
2809 
2810  /// Identify a memory copying or setting function.
2811  /// If the given function is a memory copy or setting function, returns
2812  /// the corresponding Builtin ID. If the function is not a memory function,
2813  /// returns 0.
2814  unsigned getMemoryFunctionKind() const;
2815 
2816  /// Returns ODRHash of the function. This value is calculated and
2817  /// stored on first call, then the stored value returned on the other calls.
2818  unsigned getODRHash();
2819 
2820  /// Returns cached ODRHash of the function. This must have been previously
2821  /// computed and stored.
2822  unsigned getODRHash() const;
2823 
2824  // Implement isa/cast/dyncast/etc.
2825  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2826  static bool classofKind(Kind K) {
2827  return K >= firstFunction && K <= lastFunction;
2828  }
2830  return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2831  }
2833  return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2834  }
2835 };
2836 
2837 /// Represents a member of a struct/union/class.
2838 class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2839  unsigned BitField : 1;
2840  unsigned Mutable : 1;
2841  mutable unsigned CachedFieldIndex : 30;
2842 
2843  /// The kinds of value we can store in InitializerOrBitWidth.
2844  ///
2845  /// Note that this is compatible with InClassInitStyle except for
2846  /// ISK_CapturedVLAType.
2847  enum InitStorageKind {
2848  /// If the pointer is null, there's nothing special. Otherwise,
2849  /// this is a bitfield and the pointer is the Expr* storing the
2850  /// bit-width.
2851  ISK_NoInit = (unsigned) ICIS_NoInit,
2852 
2853  /// The pointer is an (optional due to delayed parsing) Expr*
2854  /// holding the copy-initializer.
2855  ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2856 
2857  /// The pointer is an (optional due to delayed parsing) Expr*
2858  /// holding the list-initializer.
2859  ISK_InClassListInit = (unsigned) ICIS_ListInit,
2860 
2861  /// The pointer is a VariableArrayType* that's been captured;
2862  /// the enclosing context is a lambda or captured statement.
2863  ISK_CapturedVLAType,
2864  };
2865 
2866  /// If this is a bitfield with a default member initializer, this
2867  /// structure is used to represent the two expressions.
2868  struct InitAndBitWidth {
2869  Expr *Init;
2870  Expr *BitWidth;
2871  };
2872 
2873  /// Storage for either the bit-width, the in-class initializer, or
2874  /// both (via InitAndBitWidth), or the captured variable length array bound.
2875  ///
2876  /// If the storage kind is ISK_InClassCopyInit or
2877  /// ISK_InClassListInit, but the initializer is null, then this
2878  /// field has an in-class initializer that has not yet been parsed
2879  /// and attached.
2880  // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
2881  // overwhelmingly common case that we have none of these things.
2882  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2883 
2884 protected:
2887  QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2888  InClassInitStyle InitStyle)
2889  : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2890  BitField(false), Mutable(Mutable), CachedFieldIndex(0),
2891  InitStorage(nullptr, (InitStorageKind) InitStyle) {
2892  if (BW)
2893  setBitWidth(BW);
2894  }
2895 
2896 public:
2897  friend class ASTDeclReader;
2898  friend class ASTDeclWriter;
2899 
2900  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2901  SourceLocation StartLoc, SourceLocation IdLoc,
2903  TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2904  InClassInitStyle InitStyle);
2905 
2906  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2907 
2908  /// Returns the index of this field within its record,
2909  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2910  unsigned getFieldIndex() const;
2911 
2912  /// Determines whether this field is mutable (C++ only).
2913  bool isMutable() const { return Mutable; }
2914 
2915  /// Determines whether this field is a bitfield.
2916  bool isBitField() const { return BitField; }
2917 
2918  /// Determines whether this is an unnamed bitfield.
2919  bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
2920 
2921  /// Determines whether this field is a
2922  /// representative for an anonymous struct or union. Such fields are
2923  /// unnamed and are implicitly generated by the implementation to
2924  /// store the data for the anonymous union or struct.
2925  bool isAnonymousStructOrUnion() const;
2926 
2927  Expr *getBitWidth() const {
2928  if (!BitField)
2929  return nullptr;
2930  void *Ptr = InitStorage.getPointer();
2931  if (getInClassInitStyle())
2932  return static_cast<InitAndBitWidth*>(Ptr)->BitWidth;
2933  return static_cast<Expr*>(Ptr);
2934  }
2935 
2936  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2937 
2938  /// Set the bit-field width for this member.
2939  // Note: used by some clients (i.e., do not remove it).
2940  void setBitWidth(Expr *Width) {
2941  assert(!hasCapturedVLAType() && !BitField &&
2942  "bit width or captured type already set");
2943  assert(Width && "no bit width specified");
2944  InitStorage.setPointer(
2945  InitStorage.getInt()
2946  ? new (getASTContext())
2947  InitAndBitWidth{getInClassInitializer(), Width}
2948  : static_cast<void*>(Width));
2949  BitField = true;
2950  }
2951 
2952  /// Remove the bit-field width from this member.
2953  // Note: used by some clients (i.e., do not remove it).
2955  assert(isBitField() && "no bitfield width to remove");
2956  InitStorage.setPointer(getInClassInitializer());
2957  BitField = false;
2958  }
2959 
2960  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
2961  /// at all and instead act as a separator between contiguous runs of other
2962  /// bit-fields.
2963  bool isZeroLengthBitField(const ASTContext &Ctx) const;
2964 
2965  /// Determine if this field is a subobject of zero size, that is, either a
2966  /// zero-length bit-field or a field of empty class type with the
2967  /// [[no_unique_address]] attribute.
2968  bool isZeroSize(const ASTContext &Ctx) const;
2969 
2970  /// Get the kind of (C++11) default member initializer that this field has.
2972  InitStorageKind storageKind = InitStorage.getInt();
2973  return (storageKind == ISK_CapturedVLAType
2974  ? ICIS_NoInit : (InClassInitStyle) storageKind);
2975  }
2976 
2977  /// Determine whether this member has a C++11 default member initializer.
2978  bool hasInClassInitializer() const {
2979  return getInClassInitStyle() != ICIS_NoInit;
2980  }
2981 
2982  /// Get the C++11 default member initializer for this member, or null if one
2983  /// has not been set. If a valid declaration has a default member initializer,
2984  /// but this returns null, then we have not parsed and attached it yet.
2986  if (!hasInClassInitializer())
2987  return nullptr;
2988  void *Ptr = InitStorage.getPointer();
2989  if (BitField)
2990  return static_cast<InitAndBitWidth*>(Ptr)->Init;
2991  return static_cast<Expr*>(Ptr);
2992  }
2993 
2994  /// Set the C++11 in-class initializer for this member.
2997  if (BitField)
2998  static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init;
2999  else
3000  InitStorage.setPointer(Init);
3001  }
3002 
3003  /// Remove the C++11 in-class initializer from this member.
3005  assert(hasInClassInitializer() && "no initializer to remove");
3006  InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit);
3007  }
3008 
3009  /// Determine whether this member captures the variable length array
3010  /// type.
3011  bool hasCapturedVLAType() const {
3012  return InitStorage.getInt() == ISK_CapturedVLAType;
3013  }
3014 
3015  /// Get the captured variable length array type.
3017  return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
3018  InitStorage.getPointer())
3019  : nullptr;
3020  }
3021 
3022  /// Set the captured variable length array type for this field.
3023  void setCapturedVLAType(const VariableArrayType *VLAType);
3024 
3025  /// Returns the parent of this field declaration, which
3026  /// is the struct in which this field is defined.
3027  ///
3028  /// Returns null if this is not a normal class/struct field declaration, e.g.
3029  /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3030  const RecordDecl *getParent() const {
3031  return dyn_cast<RecordDecl>(getDeclContext());
3032  }
3033 
3035  return dyn_cast<RecordDecl>(getDeclContext());
3036  }
3037 
3038  SourceRange getSourceRange() const override LLVM_READONLY;
3039 
3040  /// Retrieves the canonical declaration of this field.
3041  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3042  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3043 
3044  // Implement isa/cast/dyncast/etc.
3045  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3046  static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3047 };
3048 
3049 /// An instance of this object exists for each enum constant
3050 /// that is defined. For example, in "enum X {a,b}", each of a/b are
3051 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3052 /// TagType for the X EnumDecl.
3053 class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
3054  Stmt *Init; // an integer constant expression
3055  llvm::APSInt Val; // The value.
3056 
3057 protected:
3059  IdentifierInfo *Id, QualType T, Expr *E,
3060  const llvm::APSInt &V)
3061  : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
3062 
3063 public:
3064  friend class StmtIteratorBase;
3065 
3068  QualType T, Expr *E,
3069  const llvm::APSInt &V);
3070  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3071 
3072  const Expr *getInitExpr() const { return (const Expr*) Init; }
3073  Expr *getInitExpr() { return (Expr*) Init; }
3074  const llvm::APSInt &getInitVal() const { return Val; }
3075 
3076  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3077  void setInitVal(const llvm::APSInt &V) { Val = V; }
3078 
3079  SourceRange getSourceRange() const override LLVM_READONLY;
3080 
3081  /// Retrieves the canonical declaration of this enumerator.
3083  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
3084 
3085  // Implement isa/cast/dyncast/etc.
3086  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3087  static bool classofKind(Kind K) { return K == EnumConstant; }
3088 };
3089 
3090 /// Represents a field injected from an anonymous union/struct into the parent
3091 /// scope. These are always implicit.
3093  public Mergeable<IndirectFieldDecl> {
3094  NamedDecl **Chaining;
3095  unsigned ChainingSize;
3096 
3100 
3101  void anchor() override;
3102 
3103 public:
3104  friend class ASTDeclReader;
3105 
3109 
3110  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3111 
3113 
3115  return llvm::makeArrayRef(Chaining, ChainingSize);
3116  }
3117  chain_iterator chain_begin() const { return chain().begin(); }
3118  chain_iterator chain_end() const { return chain().end(); }
3119 
3120  unsigned getChainingSize() const { return ChainingSize; }
3121 
3123  assert(chain().size() >= 2);
3124  return cast<FieldDecl>(chain().back());
3125  }
3126 
3127  VarDecl *getVarDecl() const {
3128  assert(chain().size() >= 2);
3129  return dyn_cast<VarDecl>(chain().front());
3130  }
3131 
3133  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3134 
3135  // Implement isa/cast/dyncast/etc.
3136  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3137  static bool classofKind(Kind K) { return K == IndirectField; }
3138 };
3139 
3140 /// Represents a declaration of a type.
3141 class TypeDecl : public NamedDecl {
3142  friend class ASTContext;
3143 
3144  /// This indicates the Type object that represents
3145  /// this TypeDecl. It is a cache maintained by
3146  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3147  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3148  mutable const Type *TypeForDecl = nullptr;
3149 
3150  /// The start of the source range for this declaration.
3151  SourceLocation LocStart;
3152 
3153  void anchor() override;
3154 
3155 protected:
3157  SourceLocation StartL = SourceLocation())
3158  : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3159 
3160 public:
3161  // Low-level accessor. If you just want the type defined by this node,
3162  // check out ASTContext::getTypeDeclType or one of
3163  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
3164  // already know the specific kind of node this is.
3165  const Type *getTypeForDecl() const { return TypeForDecl; }
3166  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
3167 
3168  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3169  void setLocStart(SourceLocation L) { LocStart = L; }
3170  SourceRange getSourceRange() const override LLVM_READONLY {
3171  if (LocStart.isValid())
3172  return SourceRange(LocStart, getLocation());
3173  else
3174  return SourceRange(getLocation());
3175  }
3176 
3177  // Implement isa/cast/dyncast/etc.
3178  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3179  static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3180 };
3181 
3182 /// Base class for declarations which introduce a typedef-name.
3183 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3184  struct alignas(8) ModedTInfo {
3185  TypeSourceInfo *first;
3186  QualType second;
3187  };
3188 
3189  /// If int part is 0, we have not computed IsTransparentTag.
3190  /// Otherwise, IsTransparentTag is (getInt() >> 1).
3191  mutable llvm::PointerIntPair<
3192  llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3193  MaybeModedTInfo;
3194 
3195  void anchor() override;
3196 
3197 protected:
3199  SourceLocation StartLoc, SourceLocation IdLoc,
3200  IdentifierInfo *Id, TypeSourceInfo *TInfo)
3201  : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3202  MaybeModedTInfo(TInfo, 0) {}
3203 
3205 
3207  return getNextRedeclaration();
3208  }
3209 
3211  return getPreviousDecl();
3212  }
3213 
3215  return getMostRecentDecl();
3216  }
3217 
3218 public:
3220  using redecl_iterator = redeclarable_base::redecl_iterator;
3221 
3228 
3229  bool isModed() const {
3230  return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
3231  }
3232 
3234  return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first
3235  : MaybeModedTInfo.getPointer().get<TypeSourceInfo *>();
3236  }
3237 
3239  return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second
3240  : MaybeModedTInfo.getPointer()
3241  .get<TypeSourceInfo *>()
3242  ->getType();
3243  }
3244 
3246  MaybeModedTInfo.setPointer(newType);
3247  }
3248 
3249  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
3250  MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3251  ModedTInfo({unmodedTSI, modedTy}));
3252  }
3253 
3254  /// Retrieves the canonical declaration of this typedef-name.
3256  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3257 
3258  /// Retrieves the tag declaration for which this is the typedef name for
3259  /// linkage purposes, if any.
3260  ///
3261  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3262  /// this typedef declaration.
3263  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3264 
3265  /// Determines if this typedef shares a name and spelling location with its
3266  /// underlying tag type, as is the case with the NS_ENUM macro.
3267  bool isTransparentTag() const {
3268  if (MaybeModedTInfo.getInt())
3269  return MaybeModedTInfo.getInt() & 0x2;
3270  return isTransparentTagSlow();
3271  }
3272 
3273  // Implement isa/cast/dyncast/etc.
3274  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3275  static bool classofKind(Kind K) {
3276  return K >= firstTypedefName && K <= lastTypedefName;
3277  }
3278 
3279 private:
3280  bool isTransparentTagSlow() const;
3281 };
3282 
3283 /// Represents the declaration of a typedef-name via the 'typedef'
3284 /// type specifier.
3288  : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3289 
3290 public:
3291  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3292  SourceLocation StartLoc, SourceLocation IdLoc,
3293  IdentifierInfo *Id, TypeSourceInfo *TInfo);
3294  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3295 
3296  SourceRange getSourceRange() const override LLVM_READONLY;
3297 
3298  // Implement isa/cast/dyncast/etc.
3299  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3300  static bool classofKind(Kind K) { return K == Typedef; }
3301 };
3302 
3303 /// Represents the declaration of a typedef-name via a C++11
3304 /// alias-declaration.
3306  /// The template for which this is the pattern, if any.
3307  TypeAliasTemplateDecl *Template;
3308 
3311  : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3312  Template(nullptr) {}
3313 
3314 public:
3315  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3316  SourceLocation StartLoc, SourceLocation IdLoc,
3317  IdentifierInfo *Id, TypeSourceInfo *TInfo);
3318  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3319 
3320  SourceRange getSourceRange() const override LLVM_READONLY;
3321 
3322  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3323  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3324 
3325  // Implement isa/cast/dyncast/etc.
3326  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3327  static bool classofKind(Kind K) { return K == TypeAlias; }
3328 };
3329 
3330 /// Represents the declaration of a struct/union/class/enum.
3331 class TagDecl : public TypeDecl,
3332  public DeclContext,
3333  public Redeclarable<TagDecl> {
3334  // This class stores some data in DeclContext::TagDeclBits
3335  // to save some space. Use the provided accessors to access it.
3336 public:
3337  // This is really ugly.
3339 
3340 private:
3341  SourceRange BraceRange;
3342 
3343  // A struct representing syntactic qualifier info,
3344  // to be used for the (uncommon) case of out-of-line declarations.
3345  using ExtInfo = QualifierInfo;
3346 
3347  /// If the (out-of-line) tag declaration name
3348  /// is qualified, it points to the qualifier info (nns and range);
3349  /// otherwise, if the tag declaration is anonymous and it is part of
3350  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3351  /// otherwise, if the tag declaration is anonymous and it is used as a
3352  /// declaration specifier for variables, it points to the first VarDecl (used
3353  /// for mangling);
3354  /// otherwise, it is a null (TypedefNameDecl) pointer.
3355  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3356 
3357  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3358  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3359  const ExtInfo *getExtInfo() const {
3360  return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3361  }
3362 
3363 protected:
3364  TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3365  SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3366  SourceLocation StartL);
3367 
3369 
3371  return getNextRedeclaration();
3372  }
3373 
3375  return getPreviousDecl();
3376  }
3377 
3379  return getMostRecentDecl();
3380  }
3381 
3382  /// Completes the definition of this tag declaration.
3383  ///
3384  /// This is a helper function for derived classes.
3385  void completeDefinition();
3386 
3387  /// True if this decl is currently being defined.
3388  void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3389 
3390  /// Indicates whether it is possible for declarations of this kind
3391  /// to have an out-of-date definition.
3392  ///
3393  /// This option is only enabled when modules are enabled.
3394  void setMayHaveOutOfDateDef(bool V = true) {
3395  TagDeclBits.MayHaveOutOfDateDef = V;
3396  }
3397 
3398 public:
3399  friend class ASTDeclReader;
3400  friend class ASTDeclWriter;
3401 
3403  using redecl_iterator = redeclarable_base::redecl_iterator;
3404 
3411 
3412  SourceRange getBraceRange() const { return BraceRange; }
3413  void setBraceRange(SourceRange R) { BraceRange = R; }
3414 
3415  /// Return SourceLocation representing start of source
3416  /// range ignoring outer template declarations.
3418 
3419  /// Return SourceLocation representing start of source
3420  /// range taking into account any outer template declarations.
3422  SourceRange getSourceRange() const override LLVM_READONLY;
3423 
3424  TagDecl *getCanonicalDecl() override;
3425  const TagDecl *getCanonicalDecl() const {
3426  return const_cast<TagDecl*>(this)->getCanonicalDecl();
3427  }
3428 
3429  /// Return true if this declaration is a completion definition of the type.
3430  /// Provided for consistency.
3432  return isCompleteDefinition();
3433  }
3434 
3435  /// Return true if this decl has its body fully specified.
3436  bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3437 
3438  /// True if this decl has its body fully specified.
3439  void setCompleteDefinition(bool V = true) {
3440  TagDeclBits.IsCompleteDefinition = V;
3441  }
3442 
3443  /// Return true if this complete decl is
3444  /// required to be complete for some existing use.
3446  return TagDeclBits.IsCompleteDefinitionRequired;
3447  }
3448 
3449  /// True if this complete decl is
3450  /// required to be complete for some existing use.
3451  void setCompleteDefinitionRequired(bool V = true) {
3452  TagDeclBits.IsCompleteDefinitionRequired = V;
3453  }
3454 
3455  /// Return true if this decl is currently being defined.
3456  bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3457 
3458  /// True if this tag declaration is "embedded" (i.e., defined or declared
3459  /// for the very first time) in the syntax of a declarator.
3460  bool isEmbeddedInDeclarator() const {
3461  return TagDeclBits.IsEmbeddedInDeclarator;
3462  }
3463 
3464  /// True if this tag declaration is "embedded" (i.e., defined or declared
3465  /// for the very first time) in the syntax of a declarator.
3466  void setEmbeddedInDeclarator(bool isInDeclarator) {
3467  TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3468  }
3469 
3470  /// True if this tag is free standing, e.g. "struct foo;".
3471  bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3472 
3473  /// True if this tag is free standing, e.g. "struct foo;".
3474  void setFreeStanding(bool isFreeStanding = true) {
3475  TagDeclBits.IsFreeStanding = isFreeStanding;
3476  }
3477 
3478  /// Indicates whether it is possible for declarations of this kind
3479  /// to have an out-of-date definition.
3480  ///
3481  /// This option is only enabled when modules are enabled.
3482  bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3483 
3484  /// Whether this declaration declares a type that is
3485  /// dependent, i.e., a type that somehow depends on template
3486  /// parameters.
3487  bool isDependentType() const { return isDependentContext(); }
3488 
3489  /// Starts the definition of this tag declaration.
3490  ///
3491  /// This method should be invoked at the beginning of the definition
3492  /// of this tag declaration. It will set the tag type into a state
3493  /// where it is in the process of being defined.
3494  void startDefinition();
3495 
3496  /// Returns the TagDecl that actually defines this
3497  /// struct/union/class/enum. When determining whether or not a
3498  /// struct/union/class/enum has a definition, one should use this
3499  /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3500  /// whether or not a specific TagDecl is defining declaration, not
3501  /// whether or not the struct/union/class/enum type is defined.
3502  /// This method returns NULL if there is no TagDecl that defines
3503  /// the struct/union/class/enum.
3504  TagDecl *getDefinition() const;
3505 
3506  StringRef getKindName() const {
3508  }
3509 
3511  return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3512  }
3513 
3514  void setTagKind(TagKind TK) { TagDeclBits.TagDeclKind = TK; }
3515 
3516  bool isStruct() const { return getTagKind() == TTK_Struct; }
3517  bool isInterface() const { return getTagKind() == TTK_Interface; }
3518  bool isClass() const { return getTagKind() == TTK_Class; }
3519  bool isUnion() const { return getTagKind() == TTK_Union; }
3520  bool isEnum() const { return getTagKind() == TTK_Enum; }
3521 
3522  /// Is this tag type named, either directly or via being defined in
3523  /// a typedef of this type?
3524  ///
3525  /// C++11 [basic.link]p8:
3526  /// A type is said to have linkage if and only if:
3527  /// - it is a class or enumeration type that is named (or has a
3528  /// name for linkage purposes) and the name has linkage; ...
3529  /// C++11 [dcl.typedef]p9:
3530  /// If the typedef declaration defines an unnamed class (or enum),
3531  /// the first typedef-name declared by the declaration to be that
3532  /// class type (or enum type) is used to denote the class type (or
3533  /// enum type) for linkage purposes only.
3534  ///
3535  /// C does not have an analogous rule, but the same concept is
3536  /// nonetheless useful in some places.
3537  bool hasNameForLinkage() const {
3538  return (getDeclName() || getTypedefNameForAnonDecl());
3539  }
3540 
3542  return hasExtInfo() ? nullptr
3543  : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
3544  }
3545 
3547 
3548  /// Retrieve the nested-name-specifier that qualifies the name of this
3549  /// declaration, if it was present in the source.
3551  return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3552  : nullptr;
3553  }
3554 
3555  /// Retrieve the nested-name-specifier (with source-location
3556  /// information) that qualifies the name of this declaration, if it was
3557  /// present in the source.
3559  return hasExtInfo() ? getExtInfo()->QualifierLoc
3561  }
3562 
3563  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3564 
3565  unsigned getNumTemplateParameterLists() const {
3566  return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
3567  }
3568 
3570  assert(i < getNumTemplateParameterLists());
3571  return getExtInfo()->TemplParamLists[i];
3572  }
3573 
3576 
3577  // Implement isa/cast/dyncast/etc.
3578  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3579  static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
3580 
3582  return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3583  }
3584 
3586  return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3587  }
3588 };
3589 
3590 /// Represents an enum. In C++11, enums can be forward-declared
3591 /// with a fixed underlying type, and in C we allow them to be forward-declared
3592 /// with no underlying type as an extension.
3593 class EnumDecl : public TagDecl {
3594  // This class stores some data in DeclContext::EnumDeclBits
3595  // to save some space. Use the provided accessors to access it.
3596 
3597  /// This represent the integer type that the enum corresponds
3598  /// to for code generation purposes. Note that the enumerator constants may
3599  /// have a different type than this does.
3600  ///
3601  /// If the underlying integer type was explicitly stated in the source
3602  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3603  /// was automatically deduced somehow, and this is a Type*.
3604  ///
3605  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3606  /// some cases it won't.
3607  ///
3608  /// The underlying type of an enumeration never has any qualifiers, so
3609  /// we can get away with just storing a raw Type*, and thus save an
3610  /// extra pointer when TypeSourceInfo is needed.
3611  llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3612 
3613  /// The integer type that values of this type should
3614  /// promote to. In C, enumerators are generally of an integer type
3615  /// directly, but gcc-style large enumerators (and all enumerators
3616  /// in C++) are of the enum type instead.
3617  QualType PromotionType;
3618 
3619  /// If this enumeration is an instantiation of a member enumeration
3620  /// of a class template specialization, this is the member specialization
3621  /// information.
3622  MemberSpecializationInfo *SpecializationInfo = nullptr;
3623 
3624  /// Store the ODRHash after first calculation.
3625  /// The corresponding flag HasODRHash is in EnumDeclBits
3626  /// and can be accessed with the provided accessors.
3627  unsigned ODRHash;
3628 
3629  EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3630  SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3631  bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3632 
3633  void anchor() override;
3634 
3635  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3637 
3638  /// Sets the width in bits required to store all the
3639  /// non-negative enumerators of this enum.
3640  void setNumPositiveBits(unsigned Num) {
3641  EnumDeclBits.NumPositiveBits = Num;
3642  assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3643  }
3644 
3645  /// Returns the width in bits required to store all the
3646  /// negative enumerators of this enum. (see getNumNegativeBits)
3647  void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3648 
3649 public:
3650  /// True if this tag declaration is a scoped enumeration. Only
3651  /// possible in C++11 mode.
3652  void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3653 
3654  /// If this tag declaration is a scoped enum,
3655  /// then this is true if the scoped enum was declared using the class
3656  /// tag, false if it was declared with the struct tag. No meaning is
3657  /// associated if this tag declaration is not a scoped enum.
3658  void setScopedUsingClassTag(bool ScopedUCT = true) {
3659  EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3660  }
3661 
3662  /// True if this is an Objective-C, C++11, or
3663  /// Microsoft-style enumeration with a fixed underlying type.
3664  void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3665 
3666 private:
3667  /// True if a valid hash is stored in ODRHash.
3668  bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3669  void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3670 
3671 public:
3672  friend class ASTDeclReader;
3673 
3675  return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3676  }
3677  const EnumDecl *getCanonicalDecl() const {
3678  return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3679  }
3680 
3682  return cast_or_null<EnumDecl>(
3683  static_cast<TagDecl *>(this)->getPreviousDecl());
3684  }
3685  const EnumDecl *getPreviousDecl() const {
3686  return const_cast<EnumDecl*>(this)->getPreviousDecl();
3687  }
3688 
3690  return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3691  }
3692  const EnumDecl *getMostRecentDecl() const {
3693  return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3694  }
3695 
3697  return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3698  }
3699 
3700  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3701  SourceLocation StartLoc, SourceLocation IdLoc,
3702  IdentifierInfo *Id, EnumDecl *PrevDecl,
3703  bool IsScoped, bool IsScopedUsingClassTag,
3704  bool IsFixed);
3705  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3706 
3707  /// Overrides to provide correct range when there's an enum-base specifier
3708  /// with forward declarations.
3709  SourceRange getSourceRange() const override LLVM_READONLY;
3710 
3711  /// When created, the EnumDecl corresponds to a
3712  /// forward-declared enum. This method is used to mark the
3713  /// declaration as being defined; its enumerators have already been
3714  /// added (via DeclContext::addDecl). NewType is the new underlying
3715  /// type of the enumeration type.
3716  void completeDefinition(QualType NewType,
3717  QualType PromotionType,
3718  unsigned NumPositiveBits,
3719  unsigned NumNegativeBits);
3720 
3721  // Iterates through the enumerators of this enumeration.
3723  using enumerator_range =
3725 
3728  }
3729 
3731  const EnumDecl *E = getDefinition();
3732  if (!E)
3733  E = this;
3734  return enumerator_iterator(E->decls_begin());
3735  }
3736 
3738  const EnumDecl *E = getDefinition();
3739  if (!E)
3740  E = this;
3741  return enumerator_iterator(E->decls_end());
3742  }
3743 
3744  /// Return the integer type that enumerators should promote to.
3745  QualType getPromotionType() const { return PromotionType; }
3746 
3747  /// Set the promotion type.
3748  void setPromotionType(QualType T) { PromotionType = T; }
3749 
3750  /// Return the integer type this enum decl corresponds to.
3751  /// This returns a null QualType for an enum forward definition with no fixed
3752  /// underlying type.
3754  if (!IntegerType)
3755  return QualType();
3756  if (const Type *T = IntegerType.dyn_cast<const Type*>())
3757  return QualType(T, 0);
3758  return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3759  }
3760 
3761  /// Set the underlying integer type.
3762  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3763 
3764  /// Set the underlying integer type source info.
3765  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3766 
3767  /// Return the type source info for the underlying integer type,
3768  /// if no type source info exists, return 0.
3770  return IntegerType.dyn_cast<TypeSourceInfo*>();
3771  }
3772 
3773  /// Retrieve the source range that covers the underlying type if
3774  /// specified.
3775  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3776 
3777  /// Returns the width in bits required to store all the
3778  /// non-negative enumerators of this enum.
3779  unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
3780 
3781  /// Returns the width in bits required to store all the
3782  /// negative enumerators of this enum. These widths include
3783  /// the rightmost leading 1; that is:
3784  ///
3785  /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
3786  /// ------------------------ ------- -----------------
3787  /// -1 1111111 1
3788  /// -10 1110110 5
3789  /// -101 1001011 8
3790  unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
3791 
3792  /// Returns true if this is a C++11 scoped enumeration.
3793  bool isScoped() const { return EnumDeclBits.IsScoped; }
3794 
3795  /// Returns true if this is a C++11 scoped enumeration.
3796  bool isScopedUsingClassTag() const {
3797  return EnumDeclBits.IsScopedUsingClassTag;
3798  }
3799 
3800  /// Returns true if this is an Objective-C, C++11, or
3801  /// Microsoft-style enumeration with a fixed underlying type.
3802  bool isFixed() const { return EnumDeclBits.IsFixed; }
3803 
3804  unsigned getODRHash();
3805 
3806  /// Returns true if this can be considered a complete type.
3807  bool isComplete() const {
3808  // IntegerType is set for fixed type enums and non-fixed but implicitly
3809  // int-sized Microsoft enums.
3810  return isCompleteDefinition() || IntegerType;
3811  }
3812 
3813  /// Returns true if this enum is either annotated with
3814  /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
3815  bool isClosed() const;
3816 
3817  /// Returns true if this enum is annotated with flag_enum and isn't annotated
3818  /// with enum_extensibility(open).
3819  bool isClosedFlag() const;
3820 
3821  /// Returns true if this enum is annotated with neither flag_enum nor
3822  /// enum_extensibility(open).
3823  bool isClosedNonFlag() const;
3824 
3825  /// Retrieve the enum definition from which this enumeration could
3826  /// be instantiated, if it is an instantiation (rather than a non-template).
3828 
3829  /// Returns the enumeration (declared within the template)
3830  /// from which this enumeration type was instantiated, or NULL if
3831  /// this enumeration was not instantiated from any template.
3833 
3834  /// If this enumeration is a member of a specialization of a
3835  /// templated class, determine what kind of template specialization
3836  /// or instantiation this is.
3838 
3839  /// For an enumeration member that was instantiated from a member
3840  /// enumeration of a templated class, set the template specialiation kind.
3842  SourceLocation PointOfInstantiation = SourceLocation());
3843 
3844  /// If this enumeration is an instantiation of a member enumeration of
3845  /// a class template specialization, retrieves the member specialization
3846  /// information.
3848  return SpecializationInfo;
3849  }
3850 
3851  /// Specify that this enumeration is an instantiation of the
3852  /// member enumeration ED.
3855  setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3856  }
3857 
3858  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3859  static bool classofKind(Kind K) { return K == Enum; }
3860 };
3861 
3862 /// Represents a struct/union/class. For example:
3863 /// struct X; // Forward declaration, no "body".
3864 /// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
3865 /// This decl will be marked invalid if *any* members are invalid.
3866 class RecordDecl : public TagDecl {
3867  // This class stores some data in DeclContext::RecordDeclBits
3868  // to save some space. Use the provided accessors to access it.
3869 public:
3870  friend class DeclContext;
3871  /// Enum that represents the different ways arguments are passed to and
3872  /// returned from function calls. This takes into account the target-specific
3873  /// and version-specific rules along with the rules determined by the
3874  /// language.
3875  enum ArgPassingKind : unsigned {
3876  /// The argument of this type can be passed directly in registers.
3878 
3879  /// The argument of this type cannot be passed directly in registers.
3880  /// Records containing this type as a subobject are not forced to be passed
3881  /// indirectly. This value is used only in C++. This value is required by
3882  /// C++ because, in uncommon situations, it is possible for a class to have
3883  /// only trivial copy/move constructors even when one of its subobjects has
3884  /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
3885  /// constructor in the derived class is deleted).
3887 
3888  /// The argument of this type cannot be passed directly in registers.
3889  /// Records containing this type as a subobject are forced to be passed
3890  /// indirectly.
3892  };
3893 
3894 protected:
3895  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3896  SourceLocation StartLoc, SourceLocation IdLoc,
3897  IdentifierInfo *Id, RecordDecl *PrevDecl);
3898 
3899 public:
3900  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3901  SourceLocation StartLoc, SourceLocation IdLoc,
3902  IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3903  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3904 
3906  return cast_or_null<RecordDecl>(
3907  static_cast<TagDecl *>(this)->getPreviousDecl());
3908  }
3909  const RecordDecl *getPreviousDecl() const {
3910  return const_cast<RecordDecl*>(this)->getPreviousDecl();
3911  }
3912 
3914  return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3915  }
3917  return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3918  }
3919 
3920  bool hasFlexibleArrayMember() const {
3921  return RecordDeclBits.HasFlexibleArrayMember;
3922  }
3923 
3925  RecordDeclBits.HasFlexibleArrayMember = V;
3926  }
3927 
3928  /// Whether this is an anonymous struct or union. To be an anonymous
3929  /// struct or union, it must have been declared without a name and
3930  /// there must be no objects of this type declared, e.g.,
3931  /// @code
3932  /// union { int i; float f; };
3933  /// @endcode
3934  /// is an anonymous union but neither of the following are:
3935  /// @code
3936  /// union X { int i; float f; };
3937  /// union { int i; float f; } obj;
3938  /// @endcode
3940  return RecordDeclBits.AnonymousStructOrUnion;
3941  }
3942 
3943  void setAnonymousStructOrUnion(bool Anon) {
3944  RecordDeclBits.AnonymousStructOrUnion = Anon;
3945  }
3946 
3947  bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
3948  void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
3949 
3950  bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
3951 
3952  void setHasVolatileMember(bool val) {
3953  RecordDeclBits.HasVolatileMember = val;
3954  }
3955 
3957  return RecordDeclBits.LoadedFieldsFromExternalStorage;
3958  }
3959 
3961  RecordDeclBits.LoadedFieldsFromExternalStorage = val;
3962  }
3963 
3964  /// Functions to query basic properties of non-trivial C structs.
3966  return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
3967  }
3968 
3970  RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
3971  }
3972 
3974  return RecordDeclBits.NonTrivialToPrimitiveCopy;
3975  }
3976 
3978  RecordDeclBits.NonTrivialToPrimitiveCopy = V;
3979  }
3980 
3982  return RecordDeclBits.NonTrivialToPrimitiveDestroy;
3983  }
3984 
3986  RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
3987  }
3988 
3990  return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
3991  }
3992 
3994  RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
3995  }
3996 
3998  return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
3999  }
4000 
4002  RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4003  }
4004 
4006  return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4007  }
4008 
4010  RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4011  }
4012 
4013  /// Determine whether this class can be passed in registers. In C++ mode,
4014  /// it must have at least one trivial, non-deleted copy or move constructor.
4015  /// FIXME: This should be set as part of completeDefinition.
4016  bool canPassInRegisters() const {
4018  }
4019 
4021  return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
4022  }
4023 
4025  RecordDeclBits.ArgPassingRestrictions = Kind;
4026  }
4027 
4029  return RecordDeclBits.ParamDestroyedInCallee;
4030  }
4031 
4033  RecordDeclBits.ParamDestroyedInCallee = V;
4034  }
4035 
4036  /// Determines whether this declaration represents the
4037  /// injected class name.
4038  ///
4039  /// The injected class name in C++ is the name of the class that
4040  /// appears inside the class itself. For example:
4041  ///
4042  /// \code
4043  /// struct C {
4044  /// // C is implicitly declared here as a synonym for the class name.
4045  /// };
4046  ///
4047  /// C::C c; // same as "C c;"
4048  /// \endcode
4049  bool isInjectedClassName() const;
4050 
4051  /// Determine whether this record is a class describing a lambda
4052  /// function object.
4053  bool isLambda() const;
4054 
4055  /// Determine whether this record is a record for captured variables in
4056  /// CapturedStmt construct.
4057  bool isCapturedRecord() const;
4058 
4059  /// Mark the record as a record for captured variables in CapturedStmt
4060  /// construct.
4061  void setCapturedRecord();
4062 
4063  /// Returns the RecordDecl that actually defines
4064  /// this struct/union/class. When determining whether or not a
4065  /// struct/union/class is completely defined, one should use this
4066  /// method as opposed to 'isCompleteDefinition'.
4067  /// 'isCompleteDefinition' indicates whether or not a specific
4068  /// RecordDecl is a completed definition, not whether or not the
4069  /// record type is defined. This method returns NULL if there is
4070  /// no RecordDecl that defines the struct/union/tag.
4072  return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4073  }
4074 
4075  /// Returns whether this record is a union, or contains (at any nesting level)
4076  /// a union member. This is used by CMSE to warn about possible information
4077  /// leaks.
4078  bool isOrContainsUnion() const;
4079 
4080  // Iterator access to field members. The field iterator only visits
4081  // the non-static data members of this class, ignoring any static
4082  // data members, functions, constructors, destructors, etc.
4084  using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4085 
4087  field_iterator field_begin() const;
4088 
4090  return field_iterator(decl_iterator());
4091  }
4092 
4093  // Whether there are any fields (non-static data members) in this record.
4094  bool field_empty() const {
4095  return field_begin() == field_end();
4096  }
4097 
4098  /// Note that the definition of this type is now complete.
4099  virtual void completeDefinition();
4100 
4101  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4102  static bool classofKind(Kind K) {
4103  return K >= firstRecord && K <= lastRecord;
4104  }
4105 
4106  /// Get whether or not this is an ms_struct which can
4107  /// be turned on with an attribute, pragma, or -mms-bitfields
4108  /// commandline option.
4109  bool isMsStruct(const ASTContext &C) const;
4110 
4111  /// Whether we are allowed to insert extra padding between fields.
4112  /// These padding are added to help AddressSanitizer detect
4113  /// intra-object-overflow bugs.
4114  bool mayInsertExtraPadding(bool EmitRemark = false) const;
4115 
4116  /// Finds the first data member which has a name.
4117  /// nullptr is returned if no named data member exists.
4118  const FieldDecl *findFirstNamedDataMember() const;
4119 
4120 private:
4121  /// Deserialize just the fields.
4122  void LoadFieldsFromExternalStorage() const;
4123 };
4124 
4125 class FileScopeAsmDecl : public Decl {
4126  StringLiteral *AsmString;
4127  SourceLocation RParenLoc;
4128 
4129  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
4130  SourceLocation StartL, SourceLocation EndL)
4131  : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4132 
4133  virtual void anchor();
4134 
4135 public:
4137  StringLiteral *Str, SourceLocation AsmLoc,
4138  SourceLocation RParenLoc);
4139 
4140  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4141 
4142  SourceLocation getAsmLoc() const { return getLocation(); }
4143  SourceLocation getRParenLoc() const { return RParenLoc; }
4144  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4145  SourceRange getSourceRange() const override LLVM_READONLY {
4146  return SourceRange(getAsmLoc(), getRParenLoc());
4147  }
4148 
4149  const StringLiteral *getAsmString() const { return AsmString; }
4150  StringLiteral *getAsmString() { return AsmString; }
4151  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
4152 
4153  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4154  static bool classofKind(Kind K) { return K == FileScopeAsm; }
4155 };
4156 
4157 /// Represents a block literal declaration, which is like an
4158 /// unnamed FunctionDecl. For example:
4159 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4160 class BlockDecl : public Decl, public DeclContext {
4161  // This class stores some data in DeclContext::BlockDeclBits
4162  // to save some space. Use the provided accessors to access it.
4163 public:
4164  /// A class which contains all the information about a particular
4165  /// captured value.
4166  class Capture {
4167  enum {
4168  flag_isByRef = 0x1,
4169  flag_isNested = 0x2
4170  };
4171 
4172  /// The variable being captured.
4173  llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4174 
4175  /// The copy expression, expressed in terms of a DeclRef (or
4176  /// BlockDeclRef) to the captured variable. Only required if the
4177  /// variable has a C++ class type.
4178  Expr *CopyExpr;
4179 
4180  public:
4181  Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4182  : VariableAndFlags(variable,
4183  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4184  CopyExpr(copy) {}
4185 
4186  /// The variable being captured.
4187  VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4188 
4189  /// Whether this is a "by ref" capture, i.e. a capture of a __block
4190  /// variable.
4191  bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4192 
4193  bool isEscapingByref() const {
4194  return getVariable()->isEscapingByref();
4195  }
4196 
4197  bool isNonEscapingByref() const {
4198  return getVariable()->isNonEscapingByref();
4199  }
4200 
4201  /// Whether this is a nested capture, i.e. the variable captured
4202  /// is not from outside the immediately enclosing function/block.
4203  bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4204 
4205  bool hasCopyExpr() const { return CopyExpr != nullptr; }
4206  Expr *getCopyExpr() const { return CopyExpr; }
4207  void setCopyExpr(Expr *e) { CopyExpr = e; }
4208  };
4209 
4210 private:
4211  /// A new[]'d array of pointers to ParmVarDecls for the formal
4212  /// parameters of this function. This is null if a prototype or if there are
4213  /// no formals.
4214  ParmVarDecl **ParamInfo = nullptr;
4215  unsigned NumParams = 0;
4216 
4217  Stmt *Body = nullptr;
4218  TypeSourceInfo *SignatureAsWritten = nullptr;
4219 
4220  const Capture *Captures = nullptr;
4221  unsigned NumCaptures = 0;
4222 
4223  unsigned ManglingNumber = 0;
4224  Decl *ManglingContextDecl = nullptr;
4225 
4226 protected:
4227  BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4228 
4229 public:
4231  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4232 
4234 
4235  bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4236  void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4237 
4238  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4239  Stmt *getBody() const override { return (Stmt*) Body; }
4240  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4241 
4242  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4243  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4244 
4245  // ArrayRef access to formal parameters.
4247  return {ParamInfo, getNumParams()};
4248  }
4250  return {ParamInfo, getNumParams()};
4251  }
4252 
4253  // Iterator access to formal parameters.
4256 
4257  bool param_empty() const { return parameters().empty(); }
4258  param_iterator param_begin() { return parameters().begin(); }
4259  param_iterator param_end() { return parameters().end(); }
4260  param_const_iterator param_begin() const { return parameters().begin(); }
4261  param_const_iterator param_end() const { return parameters().end(); }
4262  size_t param_size() const { return parameters().size(); }
4263 
4264  unsigned getNumParams() const { return NumParams; }
4265 
4266  const ParmVarDecl *getParamDecl(unsigned i) const {
4267  assert(i < getNumParams() && "Illegal param #");
4268  return ParamInfo[i];
4269  }
4270  ParmVarDecl *getParamDecl(unsigned i) {
4271  assert(i < getNumParams() && "Illegal param #");
4272  return ParamInfo[i];
4273  }
4274 
4275  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4276 
4277  /// True if this block (or its nested blocks) captures
4278  /// anything of local storage from its enclosing scopes.
4279  bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4280 
4281  /// Returns the number of captured variables.
4282  /// Does not include an entry for 'this'.
4283  unsigned getNumCaptures() const { return NumCaptures; }
4284 
4286 
4287  ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4288 
4289  capture_const_iterator capture_begin() const { return captures().begin(); }
4290  capture_const_iterator capture_end() const { return captures().end(); }
4291 
4292  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4293  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4294 
4295  bool blockMissingReturnType() const {
4296  return BlockDeclBits.BlockMissingReturnType;
4297  }
4298 
4299  void setBlockMissingReturnType(bool val = true) {
4300  BlockDeclBits.BlockMissingReturnType = val;
4301  }
4302 
4303  bool isConversionFromLambda() const {
4304  return BlockDeclBits.IsConversionFromLambda;
4305  }
4306 
4307  void setIsConversionFromLambda(bool val = true) {
4308  BlockDeclBits.IsConversionFromLambda = val;
4309  }
4310 
4311  bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4312  void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4313 
4314  bool canAvoidCopyToHeap() const {
4315  return BlockDeclBits.CanAvoidCopyToHeap;
4316  }
4317  void setCanAvoidCopyToHeap(bool B = true) {
4318  BlockDeclBits.CanAvoidCopyToHeap = B;
4319  }
4320 
4321  bool capturesVariable(const VarDecl *var) const;
4322 
4323  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4324  bool CapturesCXXThis);
4325 
4326  unsigned getBlockManglingNumber() const { return ManglingNumber; }
4327 
4328  Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4329 
4330  void setBlockMangling(unsigned Number, Decl *Ctx) {
4331  ManglingNumber = Number;
4332  ManglingContextDecl = Ctx;
4333  }
4334 
4335  SourceRange getSourceRange() const override LLVM_READONLY;
4336 
4337  // Implement isa/cast/dyncast/etc.
4338  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4339  static bool classofKind(Kind K) { return K == Block; }
4341  return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4342  }
4344  return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4345  }
4346 };
4347 
4348 /// Represents the body of a CapturedStmt, and serves as its DeclContext.
4349 class CapturedDecl final
4350  : public Decl,
4351  public DeclContext,
4352  private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4353 protected:
4354  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4355  return NumParams;
4356  }
4357 
4358 private:
4359  /// The number of parameters to the outlined function.
4360  unsigned NumParams;
4361 
4362  /// The position of context parameter in list of parameters.
4363  unsigned ContextParam;
4364 
4365  /// The body of the outlined function.
4366  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4367 
4368  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4369 
4370  ImplicitParamDecl *const *getParams() const {
4371  return getTrailingObjects<ImplicitParamDecl *>();
4372  }
4373 
4374  ImplicitParamDecl **getParams() {
4375  return getTrailingObjects<ImplicitParamDecl *>();
4376  }
4377 
4378 public:
4379  friend class ASTDeclReader;
4380  friend class ASTDeclWriter;
4382 
4383  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4384  unsigned NumParams);
4385  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4386  unsigned NumParams);
4387 
4388  Stmt *getBody() const override;
4389  void setBody(Stmt *B);
4390 
4391  bool isNothrow() const;
4392  void setNothrow(bool Nothrow = true);
4393 
4394  unsigned getNumParams() const { return NumParams; }
4395 
4396  ImplicitParamDecl *getParam(unsigned i) const {
4397  assert(i < NumParams);
4398  return getParams()[i];
4399  }
4400  void setParam(unsigned i, ImplicitParamDecl *P) {
4401  assert(i < NumParams);
4402  getParams()[i] = P;
4403  }
4404 
4405  // ArrayRef interface to parameters.
4407  return {getParams(), getNumParams()};
4408  }
4410  return {getParams(), getNumParams()};
4411  }
4412 
4413  /// Retrieve the parameter containing captured variables.
4415  assert(ContextParam < NumParams);
4416  return getParam(ContextParam);
4417  }
4418  void setContextParam(unsigned i, ImplicitParamDecl *P) {
4419  assert(i < NumParams);
4420  ContextParam = i;
4421  setParam(i, P);
4422  }
4423  unsigned getContextParamPosition() const { return ContextParam; }
4424 
4426  using param_range = llvm::iterator_range<param_iterator>;
4427 
4428  /// Retrieve an iterator pointing to the first parameter decl.
4429  param_iterator param_begin() const { return getParams(); }
4430  /// Retrieve an iterator one past the last parameter decl.
4431  param_iterator param_end() const { return getParams() + NumParams; }
4432 
4433  // Implement isa/cast/dyncast/etc.
4434  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4435  static bool classofKind(Kind K) { return K == Captured; }
4437  return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4438  }
4440  return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4441  }
4442 };
4443 
4444 /// Describes a module import declaration, which makes the contents
4445 /// of the named module visible in the current translation unit.
4446 ///
4447 /// An import declaration imports the named module (or submodule). For example:
4448 /// \code
4449 /// @import std.vector;
4450 /// \endcode
4451 ///
4452 /// Import declarations can also be implicitly generated from
4453 /// \#include/\#import directives.
4454 class ImportDecl final : public Decl,
4455  llvm::TrailingObjects<ImportDecl, SourceLocation> {
4456  friend class ASTContext;
4457  friend class ASTDeclReader;
4458  friend class ASTReader;
4459  friend TrailingObjects;
4460 
4461  /// The imported module.
4462  Module *ImportedModule = nullptr;
4463 
4464  /// The next import in the list of imports local to the translation
4465  /// unit being parsed (not loaded from an AST file).
4466  ///
4467  /// Includes a bit that indicates whether we have source-location information
4468  /// for each identifier in the module name.
4469  ///
4470  /// When the bit is false, we only have a single source location for the
4471  /// end of the import declaration.
4472  llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
4473 
4474  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4475  ArrayRef<SourceLocation> IdentifierLocs);
4476 
4477  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4478  SourceLocation EndLoc);
4479 
4480  ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4481 
4482  bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
4483 
4484  void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
4485 
4486  /// The next import in the list of imports local to the translation
4487  /// unit being parsed (not loaded from an AST file).
4488  ImportDecl *getNextLocalImport() const {
4489  return NextLocalImportAndComplete.getPointer();
4490  }
4491 
4492  void setNextLocalImport(ImportDecl *Import) {
4493  NextLocalImportAndComplete.setPointer(Import);
4494  }
4495 
4496 public:
4497  /// Create a new module import declaration.
4498  static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4499  SourceLocation StartLoc, Module *Imported,
4500  ArrayRef<SourceLocation> IdentifierLocs);
4501 
4502  /// Create a new module import declaration for an implicitly-generated
4503  /// import.
4504  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4505  SourceLocation StartLoc, Module *Imported,
4506  SourceLocation EndLoc);
4507 
4508  /// Create a new, deserialized module import declaration.
4509  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4510  unsigned NumLocations);
4511 
4512  /// Retrieve the module that was imported by the import declaration.
4513  Module *getImportedModule() const { return ImportedModule; }
4514 
4515  /// Retrieves the locations of each of the identifiers that make up
4516  /// the complete module name in the import declaration.
4517  ///
4518  /// This will return an empty array if the locations of the individual
4519  /// identifiers aren't available.
4521 
4522  SourceRange getSourceRange() const override LLVM_READONLY;
4523 
4524  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4525  static bool classofKind(Kind K) { return K == Import; }
4526 };
4527 
4528 /// Represents a C++ Modules TS module export declaration.
4529 ///
4530 /// For example:
4531 /// \code
4532 /// export void foo();
4533 /// \endcode
4534 class ExportDecl final : public Decl, public DeclContext {
4535  virtual void anchor();
4536 
4537 private:
4538  friend class ASTDeclReader;
4539 
4540  /// The source location for the right brace (if valid).
4541  SourceLocation RBraceLoc;
4542 
4543  ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4544  : Decl(Export, DC, ExportLoc), DeclContext(Export),
4545  RBraceLoc(SourceLocation()) {}
4546 
4547 public:
4548  static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4549  SourceLocation ExportLoc);
4550  static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4551 
4553  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4554  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4555 
4556  bool hasBraces() const { return RBraceLoc.isValid(); }
4557 
4558  SourceLocation getEndLoc() const LLVM_READONLY {
4559  if (hasBraces())
4560  return RBraceLoc;
4561  // No braces: get the end location of the (only) declaration in context
4562  // (if present).
4563  return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
4564  }
4565 
4566  SourceRange getSourceRange() const override LLVM_READONLY {
4567  return SourceRange(getLocation(), getEndLoc());
4568  }
4569 
4570  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4571  static bool classofKind(Kind K) { return K == Export; }
4573  return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4574  }
4576  return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4577  }
4578 };
4579 
4580 /// Represents an empty-declaration.
4581 class EmptyDecl : public Decl {
4582  EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4583 
4584  virtual void anchor();
4585 
4586 public:
4587  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4588  SourceLocation L);
4589  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4590 
4591  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4592  static bool classofKind(Kind K) { return K == Empty; }
4593 };
4594 
4595 /// Insertion operator for diagnostics. This allows sending NamedDecl's
4596 /// into a diagnostic with <<.
4598  const NamedDecl *ND) {
4599  PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
4601  return PD;
4602 }
4603 
4604 template<typename decl_type>
4605 void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4606  // Note: This routine is implemented here because we need both NamedDecl
4607  // and Redeclarable to be defined.
4608  assert(RedeclLink.isFirst() &&
4609  "setPreviousDecl on a decl already in a redeclaration chain");
4610 
4611  if (PrevDecl) {
4612  // Point to previous. Make sure that this is actually the most recent
4613  // redeclaration, or we can build invalid chains. If the most recent
4614  // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4615  First = PrevDecl->getFirstDecl();
4616  assert(First->RedeclLink.isFirst() && "Expected first");
4617  decl_type *MostRecent = First->getNextRedeclaration();
4618  RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4619 
4620  // If the declaration was previously visible, a redeclaration of it remains
4621  // visible even if it wouldn't be visible by itself.
4622  static_cast<decl_type*>(this)->IdentifierNamespace |=
4623  MostRecent->getIdentifierNamespace() &
4625  } else {
4626  // Make this first.
4627  First = static_cast<decl_type*>(this);
4628  }
4629 
4630  // First one will point to this one as latest.
4631  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4632 
4633  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4634  cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4635 }
4636 
4637 // Inline function definitions.
4638 
4639 /// Check if the given decl is complete.
4640 ///
4641 /// We use this function to break a cycle between the inline definitions in
4642 /// Type.h and Decl.h.
4643 inline bool IsEnumDeclComplete(EnumDecl *ED) {
4644  return ED->isComplete();
4645 }
4646 
4647 /// Check if the given decl is scoped.
4648 ///
4649 /// We use this function to break a cycle between the inline definitions in
4650 /// Type.h and Decl.h.
4651 inline bool IsEnumDeclScoped(EnumDecl *ED) {
4652  return ED->isScoped();
4653 }
4654 
4655 /// OpenMP variants are mangled early based on their OpenMP context selector.
4656 /// The new name looks likes this:
4657 /// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
4658 static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
4659  return "$ompvariant";
4660 }
4661 
4662 } // namespace clang
4663 
4664 #endif // LLVM_CLANG_AST_DECL_H
clang::FunctionDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4048
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:3170
clang::FieldDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4280
clang::FunctionDecl::getParamDecl
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:2513
clang::EnumDecl::setIntegerTypeSourceInfo
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition: Decl.h:3765
clang::LabelStmt
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:1804
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:3537
clang::TagDecl::getKindName
StringRef getKindName() const
Definition: Decl.h:3506
clang::RecordDecl::hasFlexibleArrayMember
bool hasFlexibleArrayMember() const
Definition: Decl.h:3920
clang::ExportDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4566
clang::FunctionDecl::getMultiVersionKind
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition: Decl.cpp:3283
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:2136
clang::EmptyDecl
Represents an empty-declaration.
Definition: Decl.h:4581
clang::FieldDecl::getBitWidthValue
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:4217
clang::LabelDecl::Create
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:4867
clang::FunctionDecl::castFromDeclContext
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:2832
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:2162
clang::FunctionDecl::getDefinition
const FunctionDecl * getDefinition() const
Definition: Decl.h:2124
clang::FunctionDecl::param_empty
bool param_empty() const
Definition: Decl.h:2497
clang::ImportDecl::classof
static bool classof(const Decl *D)
Definition: Decl.h:4524
clang::NamespaceDecl::Create
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl)
Definition: DeclCXX.cpp:2858
clang::FunctionDecl::getDefaultedFunctionInfo
DefaultedFunctionInfo * getDefaultedFunctionInfo() const
Definition: Decl.cpp:2967
clang::TypeDecl::classofKind
static bool classofKind(Kind K)
Definition: Decl.h:3179
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::VarDecl::isKnownToBeDefined
bool isKnownToBeDefined() const
Definition: Decl.cpp:2686
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2214
clang::NamedDecl::classof
static bool classof(const Decl *D)
Definition: Decl.h:480
clang::BlockDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4246
clang::RecordDecl::APK_CanPassInRegs
@ APK_CanPassInRegs
The argument of this type can be passed directly in registers.
Definition: Decl.h:3877
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2111
clang::RecordDecl::field_begin
field_iterator field_begin() const
Definition: Decl.cpp:4637
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:1792
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::RecordDecl::setHasNonTrivialToPrimitiveCopyCUnion
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition: Decl.h:4009
clang::FunctionDecl::setRangeEnd
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2056
clang::FunctionDecl::hasWrittenPrototype
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2260
clang::VarDecl::getStorageDuration
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition: Decl.h:1144
clang::RecordDecl::hasVolatileMember
bool hasVolatileMember() const
Definition: Decl.h:3950
Visibility.h
clang::ExportDecl::getRBraceLoc
SourceLocation getRBraceLoc() const
Definition: Decl.h:4553
clang::VarDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2089
clang::BlockDecl::isVariadic
bool isVariadic() const
Definition: Decl.h:4235
clang::IndirectFieldDecl::chain_begin
chain_iterator chain_begin() const
Definition: Decl.h:3117
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3401
clang::ExternCContextDecl
Declaration context for names declared as extern "C" in C++.
Definition: Decl.h:220
clang::EnumDecl::enumerator_end
enumerator_iterator enumerator_end() const
Definition: Decl.h:3737
clang::VarDecl::isFileVarDecl
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1257
clang::VarDecl::getTemplateInstantiationPattern
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition: Decl.cpp:2581
clang::RecordDecl::setArgPassingRestrictions
void setArgPassingRestrictions(ArgPassingKind Kind)
Definition: Decl.h:4024
clang::Decl::setDeclContext
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:327
clang::EnumDecl::getPreviousDecl
EnumDecl * getPreviousDecl()
Definition: Decl.h:3681
Specifiers.h
ASTContextAllocate.h
clang::FunctionProtoType::getExceptionSpecType
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4121
clang::Decl::hasCachedLinkage
bool hasCachedLinkage() const
Definition: DeclBase.h:406
clang::VarDecl::getTLSKind
TLSKind getTLSKind() const
Definition: Decl.cpp:2067
clang::EnumConstantDecl::getInitExpr
Expr * getInitExpr()
Definition: Decl.h:3073
clang::RecordDecl::setHasFlexibleArrayMember
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:3924
clang::VarDecl::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
Definition: Decl.cpp:2730
clang::DeclContext::specific_decl_iterator
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2129
clang::MultiVersionKind::CPUDispatch
@ CPUDispatch
clang::EnumConstantDecl::Create
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:4968
clang::RecordDecl::hasNonTrivialToPrimitiveCopyCUnion
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition: Decl.h:4005
clang::NamespaceDecl::getRBraceLoc
SourceLocation getRBraceLoc() const
Definition: Decl.h:656
clang::NamedDecl::isCXXInstanceMember
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1860
clang::DependentFunctionTemplateSpecializationInfo
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:684