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