clang API Documentation

Decl.h
Go to the documentation of this file.
00001 //===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the Decl subclasses.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_DECL_H
00015 #define LLVM_CLANG_AST_DECL_H
00016 
00017 #include "clang/AST/APValue.h"
00018 #include "clang/AST/DeclBase.h"
00019 #include "clang/AST/DeclarationName.h"
00020 #include "clang/AST/ExternalASTSource.h"
00021 #include "clang/AST/Redeclarable.h"
00022 #include "clang/AST/Type.h"
00023 #include "clang/Basic/Linkage.h"
00024 #include "clang/Basic/OperatorKinds.h"
00025 #include "llvm/ADT/ArrayRef.h"
00026 #include "llvm/ADT/Optional.h"
00027 #include "llvm/Support/Compiler.h"
00028 #include "llvm/Support/raw_ostream.h"
00029 
00030 namespace clang {
00031 struct ASTTemplateArgumentListInfo;
00032 class CXXTemporary;
00033 class CompoundStmt;
00034 class DependentFunctionTemplateSpecializationInfo;
00035 class Expr;
00036 class FunctionTemplateDecl;
00037 class FunctionTemplateSpecializationInfo;
00038 class LabelStmt;
00039 class MemberSpecializationInfo;
00040 class Module;
00041 class NestedNameSpecifier;
00042 class Stmt;
00043 class StringLiteral;
00044 class TemplateArgumentList;
00045 class TemplateParameterList;
00046 class TypeAliasTemplateDecl;
00047 class TypeLoc;
00048 class UnresolvedSetImpl;
00049 class VarTemplateDecl;
00050 
00051 /// \brief A container of type source information.
00052 ///
00053 /// A client can read the relevant info using TypeLoc wrappers, e.g:
00054 /// @code
00055 /// TypeLoc TL = TypeSourceInfo->getTypeLoc();
00056 /// TL.getStartLoc().print(OS, SrcMgr);
00057 /// @endcode
00058 ///
00059 class TypeSourceInfo {
00060   QualType Ty;
00061   // Contains a memory block after the class, used for type source information,
00062   // allocated by ASTContext.
00063   friend class ASTContext;
00064   TypeSourceInfo(QualType ty) : Ty(ty) { }
00065 public:
00066   /// \brief Return the type wrapped by this type source info.
00067   QualType getType() const { return Ty; }
00068 
00069   /// \brief Return the TypeLoc wrapper for the type source info.
00070   TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
00071   
00072   /// \brief Override the type stored in this TypeSourceInfo. Use with caution!
00073   void overrideType(QualType T) { Ty = T; }
00074 };
00075 
00076 /// TranslationUnitDecl - The top declaration context.
00077 class TranslationUnitDecl : public Decl, public DeclContext {
00078   virtual void anchor();
00079   ASTContext &Ctx;
00080 
00081   /// The (most recently entered) anonymous namespace for this
00082   /// translation unit, if one has been created.
00083   NamespaceDecl *AnonymousNamespace;
00084 
00085   explicit TranslationUnitDecl(ASTContext &ctx)
00086     : Decl(TranslationUnit, nullptr, SourceLocation()),
00087       DeclContext(TranslationUnit),
00088       Ctx(ctx), AnonymousNamespace(nullptr) {}
00089 public:
00090   ASTContext &getASTContext() const { return Ctx; }
00091 
00092   NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
00093   void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
00094 
00095   static TranslationUnitDecl *Create(ASTContext &C);
00096   // Implement isa/cast/dyncast/etc.
00097   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00098   static bool classofKind(Kind K) { return K == TranslationUnit; }
00099   static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
00100     return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
00101   }
00102   static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
00103     return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
00104   }
00105 };
00106 
00107 /// NamedDecl - This represents a decl with a name.  Many decls have names such
00108 /// as ObjCMethodDecl, but not \@class, etc.
00109 class NamedDecl : public Decl {
00110   virtual void anchor();
00111   /// Name - The name of this declaration, which is typically a normal
00112   /// identifier but may also be a special kind of name (C++
00113   /// constructor, Objective-C selector, etc.)
00114   DeclarationName Name;
00115 
00116 private:
00117   NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
00118 
00119 protected:
00120   NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
00121     : Decl(DK, DC, L), Name(N) { }
00122 
00123 public:
00124   /// getIdentifier - Get the identifier that names this declaration,
00125   /// if there is one. This will return NULL if this declaration has
00126   /// no name (e.g., for an unnamed class) or if the name is a special
00127   /// name (C++ constructor, Objective-C selector, etc.).
00128   IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
00129 
00130   /// getName - Get the name of identifier for this declaration as a StringRef.
00131   /// This requires that the declaration have a name and that it be a simple
00132   /// identifier.
00133   StringRef getName() const {
00134     assert(Name.isIdentifier() && "Name is not a simple identifier");
00135     return getIdentifier() ? getIdentifier()->getName() : "";
00136   }
00137 
00138   /// getNameAsString - Get a human-readable name for the declaration, even if
00139   /// it is one of the special kinds of names (C++ constructor, Objective-C
00140   /// selector, etc).  Creating this name requires expensive string
00141   /// manipulation, so it should be called only when performance doesn't matter.
00142   /// For simple declarations, getNameAsCString() should suffice.
00143   //
00144   // FIXME: This function should be renamed to indicate that it is not just an
00145   // alternate form of getName(), and clients should move as appropriate.
00146   //
00147   // FIXME: Deprecated, move clients to getName().
00148   std::string getNameAsString() const { return Name.getAsString(); }
00149 
00150   void printName(raw_ostream &os) const { os << Name; }
00151 
00152   /// getDeclName - Get the actual, stored name of the declaration,
00153   /// which may be a special name.
00154   DeclarationName getDeclName() const { return Name; }
00155 
00156   /// \brief Set the name of this declaration.
00157   void setDeclName(DeclarationName N) { Name = N; }
00158 
00159   /// printQualifiedName - Returns human-readable qualified name for
00160   /// declaration, like A::B::i, for i being member of namespace A::B.
00161   /// If declaration is not member of context which can be named (record,
00162   /// namespace), it will return same result as printName().
00163   /// Creating this name is expensive, so it should be called only when
00164   /// performance doesn't matter.
00165   void printQualifiedName(raw_ostream &OS) const;
00166   void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
00167 
00168   // FIXME: Remove string version.
00169   std::string getQualifiedNameAsString() const;
00170 
00171   /// getNameForDiagnostic - Appends a human-readable name for this
00172   /// declaration into the given stream.
00173   ///
00174   /// This is the method invoked by Sema when displaying a NamedDecl
00175   /// in a diagnostic.  It does not necessarily produce the same
00176   /// result as printName(); for example, class template
00177   /// specializations are printed with their template arguments.
00178   virtual void getNameForDiagnostic(raw_ostream &OS,
00179                                     const PrintingPolicy &Policy,
00180                                     bool Qualified) const;
00181 
00182   /// declarationReplaces - Determine whether this declaration, if
00183   /// known to be well-formed within its context, will replace the
00184   /// declaration OldD if introduced into scope. A declaration will
00185   /// replace another declaration if, for example, it is a
00186   /// redeclaration of the same variable or function, but not if it is
00187   /// a declaration of a different kind (function vs. class) or an
00188   /// overloaded function.
00189   bool declarationReplaces(NamedDecl *OldD) const;
00190 
00191   /// \brief Determine whether this declaration has linkage.
00192   bool hasLinkage() const;
00193 
00194   using Decl::isModulePrivate;
00195   using Decl::setModulePrivate;
00196 
00197   /// \brief Determine whether this declaration is hidden from name lookup.
00198   bool isHidden() const { return Hidden; }
00199 
00200   /// \brief Set whether this declaration is hidden from name lookup.
00201   void setHidden(bool Hide) { Hidden = Hide; }
00202 
00203   /// \brief Determine whether this declaration is a C++ class member.
00204   bool isCXXClassMember() const {
00205     const DeclContext *DC = getDeclContext();
00206 
00207     // C++0x [class.mem]p1:
00208     //   The enumerators of an unscoped enumeration defined in
00209     //   the class are members of the class.
00210     if (isa<EnumDecl>(DC))
00211       DC = DC->getRedeclContext();
00212 
00213     return DC->isRecord();
00214   }
00215 
00216   /// \brief Determine whether the given declaration is an instance member of
00217   /// a C++ class.
00218   bool isCXXInstanceMember() const;
00219 
00220   /// \brief Determine what kind of linkage this entity has.
00221   /// This is not the linkage as defined by the standard or the codegen notion
00222   /// of linkage. It is just an implementation detail that is used to compute
00223   /// those.
00224   Linkage getLinkageInternal() const;
00225 
00226   /// \brief Get the linkage from a semantic point of view. Entities in
00227   /// anonymous namespaces are external (in c++98).
00228   Linkage getFormalLinkage() const {
00229     return clang::getFormalLinkage(getLinkageInternal());
00230   }
00231 
00232   /// \brief True if this decl has external linkage.
00233   bool hasExternalFormalLinkage() const {
00234     return isExternalFormalLinkage(getLinkageInternal());
00235   }
00236 
00237   bool isExternallyVisible() const {
00238     return clang::isExternallyVisible(getLinkageInternal());
00239   }
00240 
00241   /// \brief Determines the visibility of this entity.
00242   Visibility getVisibility() const {
00243     return getLinkageAndVisibility().getVisibility();
00244   }
00245 
00246   /// \brief Determines the linkage and visibility of this entity.
00247   LinkageInfo getLinkageAndVisibility() const;
00248 
00249   /// Kinds of explicit visibility.
00250   enum ExplicitVisibilityKind {
00251     VisibilityForType,
00252     VisibilityForValue
00253   };
00254 
00255   /// \brief If visibility was explicitly specified for this
00256   /// declaration, return that visibility.
00257   Optional<Visibility>
00258   getExplicitVisibility(ExplicitVisibilityKind kind) const;
00259 
00260   /// \brief True if the computed linkage is valid. Used for consistency
00261   /// checking. Should always return true.
00262   bool isLinkageValid() const;
00263 
00264   /// \brief True if something has required us to compute the linkage
00265   /// of this declaration.
00266   ///
00267   /// Language features which can retroactively change linkage (like a
00268   /// typedef name for linkage purposes) may need to consider this,
00269   /// but hopefully only in transitory ways during parsing.
00270   bool hasLinkageBeenComputed() const {
00271     return hasCachedLinkage();
00272   }
00273 
00274   /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
00275   /// the underlying named decl.
00276   NamedDecl *getUnderlyingDecl() {
00277     // Fast-path the common case.
00278     if (this->getKind() != UsingShadow &&
00279         this->getKind() != ObjCCompatibleAlias)
00280       return this;
00281 
00282     return getUnderlyingDeclImpl();
00283   }
00284   const NamedDecl *getUnderlyingDecl() const {
00285     return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
00286   }
00287 
00288   NamedDecl *getMostRecentDecl() {
00289     return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
00290   }
00291   const NamedDecl *getMostRecentDecl() const {
00292     return const_cast<NamedDecl*>(this)->getMostRecentDecl();
00293   }
00294 
00295   ObjCStringFormatFamily getObjCFStringFormattingFamily() const;
00296 
00297   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00298   static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
00299 };
00300 
00301 inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
00302   ND.printName(OS);
00303   return OS;
00304 }
00305 
00306 /// LabelDecl - Represents the declaration of a label.  Labels also have a
00307 /// corresponding LabelStmt, which indicates the position that the label was
00308 /// defined at.  For normal labels, the location of the decl is the same as the
00309 /// location of the statement.  For GNU local labels (__label__), the decl
00310 /// location is where the __label__ is.
00311 class LabelDecl : public NamedDecl {
00312   void anchor() override;
00313   LabelStmt *TheStmt;
00314   StringRef MSAsmName;
00315   bool MSAsmNameResolved;
00316   /// LocStart - For normal labels, this is the same as the main declaration
00317   /// label, i.e., the location of the identifier; for GNU local labels,
00318   /// this is the location of the __label__ keyword.
00319   SourceLocation LocStart;
00320 
00321   LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
00322             LabelStmt *S, SourceLocation StartL)
00323     : NamedDecl(Label, DC, IdentL, II),
00324       TheStmt(S),
00325       MSAsmNameResolved(false),
00326       LocStart(StartL) {}
00327 
00328 public:
00329   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
00330                            SourceLocation IdentL, IdentifierInfo *II);
00331   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
00332                            SourceLocation IdentL, IdentifierInfo *II,
00333                            SourceLocation GnuLabelL);
00334   static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00335   
00336   LabelStmt *getStmt() const { return TheStmt; }
00337   void setStmt(LabelStmt *T) { TheStmt = T; }
00338 
00339   bool isGnuLocal() const { return LocStart != getLocation(); }
00340   void setLocStart(SourceLocation L) { LocStart = L; }
00341 
00342   SourceRange getSourceRange() const override LLVM_READONLY {
00343     return SourceRange(LocStart, getLocation());
00344   }
00345 
00346   bool isMSAsmLabel() const { return MSAsmName.size() != 0; }
00347   bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
00348   void setMSAsmLabel(StringRef Name);
00349   StringRef getMSAsmLabel() const { return MSAsmName; }
00350   void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
00351 
00352   // Implement isa/cast/dyncast/etc.
00353   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00354   static bool classofKind(Kind K) { return K == Label; }
00355 };
00356 
00357 /// NamespaceDecl - Represent a C++ namespace.
00358 class NamespaceDecl : public NamedDecl, public DeclContext, 
00359                       public Redeclarable<NamespaceDecl> 
00360 {
00361   /// LocStart - The starting location of the source range, pointing
00362   /// to either the namespace or the inline keyword.
00363   SourceLocation LocStart;
00364   /// RBraceLoc - The ending location of the source range.
00365   SourceLocation RBraceLoc;
00366 
00367   /// \brief A pointer to either the anonymous namespace that lives just inside
00368   /// this namespace or to the first namespace in the chain (the latter case
00369   /// only when this is not the first in the chain), along with a 
00370   /// boolean value indicating whether this is an inline namespace.
00371   llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
00372 
00373   NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
00374                 SourceLocation StartLoc, SourceLocation IdLoc,
00375                 IdentifierInfo *Id, NamespaceDecl *PrevDecl);
00376 
00377   typedef Redeclarable<NamespaceDecl> redeclarable_base;
00378   NamespaceDecl *getNextRedeclarationImpl() override;
00379   NamespaceDecl *getPreviousDeclImpl() override;
00380   NamespaceDecl *getMostRecentDeclImpl() override;
00381 
00382 public:
00383   static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
00384                                bool Inline, SourceLocation StartLoc,
00385                                SourceLocation IdLoc, IdentifierInfo *Id,
00386                                NamespaceDecl *PrevDecl);
00387 
00388   static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00389 
00390   typedef redeclarable_base::redecl_range redecl_range;
00391   typedef redeclarable_base::redecl_iterator redecl_iterator;
00392   using redeclarable_base::redecls_begin;
00393   using redeclarable_base::redecls_end;
00394   using redeclarable_base::redecls;
00395   using redeclarable_base::getPreviousDecl;
00396   using redeclarable_base::getMostRecentDecl;
00397   using redeclarable_base::isFirstDecl;
00398 
00399   /// \brief Returns true if this is an anonymous namespace declaration.
00400   ///
00401   /// For example:
00402   /// \code
00403   ///   namespace {
00404   ///     ...
00405   ///   };
00406   /// \endcode
00407   /// q.v. C++ [namespace.unnamed]
00408   bool isAnonymousNamespace() const {
00409     return !getIdentifier();
00410   }
00411 
00412   /// \brief Returns true if this is an inline namespace declaration.
00413   bool isInline() const {
00414     return AnonOrFirstNamespaceAndInline.getInt();
00415   }
00416 
00417   /// \brief Set whether this is an inline namespace declaration.
00418   void setInline(bool Inline) {
00419     AnonOrFirstNamespaceAndInline.setInt(Inline);
00420   }
00421 
00422   /// \brief Get the original (first) namespace declaration.
00423   NamespaceDecl *getOriginalNamespace() {
00424     if (isFirstDecl())
00425       return this;
00426 
00427     return AnonOrFirstNamespaceAndInline.getPointer();
00428   }
00429 
00430   /// \brief Get the original (first) namespace declaration.
00431   const NamespaceDecl *getOriginalNamespace() const {
00432     if (isFirstDecl())
00433       return this;
00434 
00435     return AnonOrFirstNamespaceAndInline.getPointer();
00436   }
00437 
00438   /// \brief Return true if this declaration is an original (first) declaration
00439   /// of the namespace. This is false for non-original (subsequent) namespace
00440   /// declarations and anonymous namespaces.
00441   bool isOriginalNamespace() const { return isFirstDecl(); }
00442 
00443   /// \brief Retrieve the anonymous namespace nested inside this namespace,
00444   /// if any.
00445   NamespaceDecl *getAnonymousNamespace() const {
00446     return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
00447   }
00448 
00449   void setAnonymousNamespace(NamespaceDecl *D) {
00450     getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
00451   }
00452 
00453   /// Retrieves the canonical declaration of this namespace.
00454   NamespaceDecl *getCanonicalDecl() override {
00455     return getOriginalNamespace();
00456   }
00457   const NamespaceDecl *getCanonicalDecl() const {
00458     return getOriginalNamespace();
00459   }
00460 
00461   SourceRange getSourceRange() const override LLVM_READONLY {
00462     return SourceRange(LocStart, RBraceLoc);
00463   }
00464 
00465   SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
00466   SourceLocation getRBraceLoc() const { return RBraceLoc; }
00467   void setLocStart(SourceLocation L) { LocStart = L; }
00468   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
00469 
00470   // Implement isa/cast/dyncast/etc.
00471   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00472   static bool classofKind(Kind K) { return K == Namespace; }
00473   static DeclContext *castToDeclContext(const NamespaceDecl *D) {
00474     return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
00475   }
00476   static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
00477     return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
00478   }
00479 
00480   friend class ASTDeclReader;
00481   friend class ASTDeclWriter;
00482 };
00483 
00484 /// ValueDecl - Represent the declaration of a variable (in which case it is
00485 /// an lvalue) a function (in which case it is a function designator) or
00486 /// an enum constant.
00487 class ValueDecl : public NamedDecl {
00488   void anchor() override;
00489   QualType DeclType;
00490 
00491 protected:
00492   ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
00493             DeclarationName N, QualType T)
00494     : NamedDecl(DK, DC, L, N), DeclType(T) {}
00495 public:
00496   QualType getType() const { return DeclType; }
00497   void setType(QualType newType) { DeclType = newType; }
00498 
00499   /// \brief Determine whether this symbol is weakly-imported,
00500   ///        or declared with the weak or weak-ref attr.
00501   bool isWeak() const;
00502 
00503   // Implement isa/cast/dyncast/etc.
00504   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00505   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
00506 };
00507 
00508 /// QualifierInfo - A struct with extended info about a syntactic
00509 /// name qualifier, to be used for the case of out-of-line declarations.
00510 struct QualifierInfo {
00511   NestedNameSpecifierLoc QualifierLoc;
00512 
00513   /// NumTemplParamLists - The number of "outer" template parameter lists.
00514   /// The count includes all of the template parameter lists that were matched
00515   /// against the template-ids occurring into the NNS and possibly (in the
00516   /// case of an explicit specialization) a final "template <>".
00517   unsigned NumTemplParamLists;
00518 
00519   /// TemplParamLists - A new-allocated array of size NumTemplParamLists,
00520   /// containing pointers to the "outer" template parameter lists.
00521   /// It includes all of the template parameter lists that were matched
00522   /// against the template-ids occurring into the NNS and possibly (in the
00523   /// case of an explicit specialization) a final "template <>".
00524   TemplateParameterList** TemplParamLists;
00525 
00526   /// Default constructor.
00527   QualifierInfo()
00528     : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(nullptr) {}
00529 
00530   /// setTemplateParameterListsInfo - Sets info about "outer" template
00531   /// parameter lists.
00532   void setTemplateParameterListsInfo(ASTContext &Context,
00533                                      unsigned NumTPLists,
00534                                      TemplateParameterList **TPLists);
00535 
00536 private:
00537   // Copy constructor and copy assignment are disabled.
00538   QualifierInfo(const QualifierInfo&) LLVM_DELETED_FUNCTION;
00539   QualifierInfo& operator=(const QualifierInfo&) LLVM_DELETED_FUNCTION;
00540 };
00541 
00542 /// \brief Represents a ValueDecl that came out of a declarator.
00543 /// Contains type source information through TypeSourceInfo.
00544 class DeclaratorDecl : public ValueDecl {
00545   // A struct representing both a TInfo and a syntactic qualifier,
00546   // to be used for the (uncommon) case of out-of-line declarations.
00547   struct ExtInfo : public QualifierInfo {
00548     TypeSourceInfo *TInfo;
00549   };
00550 
00551   llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo;
00552 
00553   /// InnerLocStart - The start of the source range for this declaration,
00554   /// ignoring outer template declarations.
00555   SourceLocation InnerLocStart;
00556 
00557   bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
00558   ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
00559   const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
00560 
00561 protected:
00562   DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
00563                  DeclarationName N, QualType T, TypeSourceInfo *TInfo,
00564                  SourceLocation StartL)
00565     : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {
00566   }
00567 
00568 public:
00569   TypeSourceInfo *getTypeSourceInfo() const {
00570     return hasExtInfo()
00571       ? getExtInfo()->TInfo
00572       : DeclInfo.get<TypeSourceInfo*>();
00573   }
00574   void setTypeSourceInfo(TypeSourceInfo *TI) {
00575     if (hasExtInfo())
00576       getExtInfo()->TInfo = TI;
00577     else
00578       DeclInfo = TI;
00579   }
00580 
00581   /// getInnerLocStart - Return SourceLocation representing start of source
00582   /// range ignoring outer template declarations.
00583   SourceLocation getInnerLocStart() const { return InnerLocStart; }
00584   void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
00585 
00586   /// getOuterLocStart - Return SourceLocation representing start of source
00587   /// range taking into account any outer template declarations.
00588   SourceLocation getOuterLocStart() const;
00589 
00590   SourceRange getSourceRange() const override LLVM_READONLY;
00591   SourceLocation getLocStart() const LLVM_READONLY {
00592     return getOuterLocStart();
00593   }
00594 
00595   /// \brief Retrieve the nested-name-specifier that qualifies the name of this
00596   /// declaration, if it was present in the source.
00597   NestedNameSpecifier *getQualifier() const {
00598     return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
00599                         : nullptr;
00600   }
00601 
00602   /// \brief Retrieve the nested-name-specifier (with source-location
00603   /// information) that qualifies the name of this declaration, if it was
00604   /// present in the source.
00605   NestedNameSpecifierLoc getQualifierLoc() const {
00606     return hasExtInfo() ? getExtInfo()->QualifierLoc
00607                         : NestedNameSpecifierLoc();
00608   }
00609 
00610   void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
00611 
00612   unsigned getNumTemplateParameterLists() const {
00613     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
00614   }
00615   TemplateParameterList *getTemplateParameterList(unsigned index) const {
00616     assert(index < getNumTemplateParameterLists());
00617     return getExtInfo()->TemplParamLists[index];
00618   }
00619   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
00620                                      TemplateParameterList **TPLists);
00621 
00622   SourceLocation getTypeSpecStartLoc() const;
00623 
00624   // Implement isa/cast/dyncast/etc.
00625   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00626   static bool classofKind(Kind K) {
00627     return K >= firstDeclarator && K <= lastDeclarator;
00628   }
00629 
00630   friend class ASTDeclReader;
00631   friend class ASTDeclWriter;
00632 };
00633 
00634 /// \brief Structure used to store a statement, the constant value to
00635 /// which it was evaluated (if any), and whether or not the statement
00636 /// is an integral constant expression (if known).
00637 struct EvaluatedStmt {
00638   EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false),
00639                     CheckingICE(false), IsICE(false) { }
00640 
00641   /// \brief Whether this statement was already evaluated.
00642   bool WasEvaluated : 1;
00643 
00644   /// \brief Whether this statement is being evaluated.
00645   bool IsEvaluating : 1;
00646 
00647   /// \brief Whether we already checked whether this statement was an
00648   /// integral constant expression.
00649   bool CheckedICE : 1;
00650 
00651   /// \brief Whether we are checking whether this statement is an
00652   /// integral constant expression.
00653   bool CheckingICE : 1;
00654 
00655   /// \brief Whether this statement is an integral constant expression,
00656   /// or in C++11, whether the statement is a constant expression. Only
00657   /// valid if CheckedICE is true.
00658   bool IsICE : 1;
00659 
00660   Stmt *Value;
00661   APValue Evaluated;
00662 };
00663 
00664 /// VarDecl - An instance of this class is created to represent a variable
00665 /// declaration or definition.
00666 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
00667 public:
00668   /// getStorageClassSpecifierString - Return the string used to
00669   /// specify the storage class \p SC.
00670   ///
00671   /// It is illegal to call this function with SC == None.
00672   static const char *getStorageClassSpecifierString(StorageClass SC);
00673 
00674   /// \brief Initialization styles.
00675   enum InitializationStyle {
00676     CInit,    ///< C-style initialization with assignment
00677     CallInit, ///< Call-style initialization (C++98)
00678     ListInit  ///< Direct list-initialization (C++11)
00679   };
00680 
00681   /// \brief Kinds of thread-local storage.
00682   enum TLSKind {
00683     TLS_None,   ///< Not a TLS variable.
00684     TLS_Static, ///< TLS with a known-constant initializer.
00685     TLS_Dynamic ///< TLS with a dynamic initializer.
00686   };
00687 
00688 protected:
00689   /// \brief Placeholder type used in Init to denote an unparsed C++ default
00690   /// argument.
00691   struct UnparsedDefaultArgument;
00692 
00693   /// \brief Placeholder type used in Init to denote an uninstantiated C++
00694   /// default argument.
00695   struct UninstantiatedDefaultArgument;
00696 
00697   typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *,
00698                               UnparsedDefaultArgument *,
00699                               UninstantiatedDefaultArgument *> InitType;
00700 
00701   /// \brief The initializer for this variable or, for a ParmVarDecl, the
00702   /// C++ default argument.
00703   mutable InitType Init;
00704 
00705 private:
00706   class VarDeclBitfields {
00707     friend class VarDecl;
00708     friend class ASTDeclReader;
00709 
00710     unsigned SClass : 3;
00711     unsigned TSCSpec : 2;
00712     unsigned InitStyle : 2;
00713 
00714     /// \brief Whether this variable is the exception variable in a C++ catch
00715     /// or an Objective-C @catch statement.
00716     unsigned ExceptionVar : 1;
00717 
00718     /// \brief Whether this local variable could be allocated in the return
00719     /// slot of its function, enabling the named return value optimization
00720     /// (NRVO).
00721     unsigned NRVOVariable : 1;
00722 
00723     /// \brief Whether this variable is the for-range-declaration in a C++0x
00724     /// for-range statement.
00725     unsigned CXXForRangeDecl : 1;
00726 
00727     /// \brief Whether this variable is an ARC pseudo-__strong
00728     /// variable;  see isARCPseudoStrong() for details.
00729     unsigned ARCPseudoStrong : 1;
00730 
00731     /// \brief Whether this variable is (C++0x) constexpr.
00732     unsigned IsConstexpr : 1;
00733 
00734     /// \brief Whether this variable is the implicit variable for a lambda
00735     /// init-capture.
00736     unsigned IsInitCapture : 1;
00737 
00738     /// \brief Whether this local extern variable's previous declaration was
00739     /// declared in the same block scope. This controls whether we should merge
00740     /// the type of this declaration with its previous declaration.
00741     unsigned PreviousDeclInSameBlockScope : 1;
00742   };
00743   enum { NumVarDeclBits = 14 };
00744 
00745   friend class ASTDeclReader;
00746   friend class StmtIteratorBase;
00747   friend class ASTNodeImporter;
00748 
00749 protected:
00750   enum { NumParameterIndexBits = 8 };
00751 
00752   class ParmVarDeclBitfields {
00753     friend class ParmVarDecl;
00754     friend class ASTDeclReader;
00755 
00756     unsigned : NumVarDeclBits;
00757 
00758     /// Whether this parameter inherits a default argument from a
00759     /// prior declaration.
00760     unsigned HasInheritedDefaultArg : 1;
00761 
00762     /// Whether this parameter undergoes K&R argument promotion.
00763     unsigned IsKNRPromoted : 1;
00764 
00765     /// Whether this parameter is an ObjC method parameter or not.
00766     unsigned IsObjCMethodParam : 1;
00767 
00768     /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
00769     /// Otherwise, the number of function parameter scopes enclosing
00770     /// the function parameter scope in which this parameter was
00771     /// declared.
00772     unsigned ScopeDepthOrObjCQuals : 7;
00773 
00774     /// The number of parameters preceding this parameter in the
00775     /// function parameter scope in which it was declared.
00776     unsigned ParameterIndex : NumParameterIndexBits;
00777   };
00778 
00779   union {
00780     unsigned AllBits;
00781     VarDeclBitfields VarDeclBits;
00782     ParmVarDeclBitfields ParmVarDeclBits;
00783   };
00784 
00785   VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
00786           SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
00787           TypeSourceInfo *TInfo, StorageClass SC);
00788 
00789   typedef Redeclarable<VarDecl> redeclarable_base;
00790   VarDecl *getNextRedeclarationImpl() override {
00791     return getNextRedeclaration();
00792   }
00793   VarDecl *getPreviousDeclImpl() override {
00794     return getPreviousDecl();
00795   }
00796   VarDecl *getMostRecentDeclImpl() override {
00797     return getMostRecentDecl();
00798   }
00799 
00800 public:
00801   typedef redeclarable_base::redecl_range redecl_range;
00802   typedef redeclarable_base::redecl_iterator redecl_iterator;
00803   using redeclarable_base::redecls_begin;
00804   using redeclarable_base::redecls_end;
00805   using redeclarable_base::redecls;
00806   using redeclarable_base::getPreviousDecl;
00807   using redeclarable_base::getMostRecentDecl;
00808   using redeclarable_base::isFirstDecl;
00809 
00810   static VarDecl *Create(ASTContext &C, DeclContext *DC,
00811                          SourceLocation StartLoc, SourceLocation IdLoc,
00812                          IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
00813                          StorageClass S);
00814 
00815   static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00816 
00817   SourceRange getSourceRange() const override LLVM_READONLY;
00818 
00819   /// \brief Returns the storage class as written in the source. For the
00820   /// computed linkage of symbol, see getLinkage.
00821   StorageClass getStorageClass() const {
00822     return (StorageClass) VarDeclBits.SClass;
00823   }
00824   void setStorageClass(StorageClass SC);
00825 
00826   void setTSCSpec(ThreadStorageClassSpecifier TSC) {
00827     VarDeclBits.TSCSpec = TSC;
00828     assert(VarDeclBits.TSCSpec == TSC && "truncation");
00829   }
00830   ThreadStorageClassSpecifier getTSCSpec() const {
00831     return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
00832   }
00833   TLSKind getTLSKind() const;
00834 
00835   /// hasLocalStorage - Returns true if a variable with function scope
00836   ///  is a non-static local variable.
00837   bool hasLocalStorage() const {
00838     if (getStorageClass() == SC_None)
00839       // Second check is for C++11 [dcl.stc]p4.
00840       return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
00841 
00842     // Global Named Register (GNU extension)
00843     if (getStorageClass() == SC_Register && !isLocalVarDecl())
00844       return false;
00845 
00846     // Return true for:  Auto, Register.
00847     // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
00848 
00849     return getStorageClass() >= SC_Auto;
00850   }
00851 
00852   /// isStaticLocal - Returns true if a variable with function scope is a
00853   /// static local variable.
00854   bool isStaticLocal() const {
00855     return (getStorageClass() == SC_Static ||
00856             // C++11 [dcl.stc]p4
00857             (getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local))
00858       && !isFileVarDecl();
00859   }
00860 
00861   /// \brief Returns true if a variable has extern or __private_extern__
00862   /// storage.
00863   bool hasExternalStorage() const {
00864     return getStorageClass() == SC_Extern ||
00865            getStorageClass() == SC_PrivateExtern;
00866   }
00867 
00868   /// \brief Returns true for all variables that do not have local storage.
00869   ///
00870   /// This includes all global variables as well as static variables declared
00871   /// within a function.
00872   bool hasGlobalStorage() const { return !hasLocalStorage(); }
00873 
00874   /// \brief Get the storage duration of this variable, per C++ [basic.stc].
00875   StorageDuration getStorageDuration() const {
00876     return hasLocalStorage() ? SD_Automatic :
00877            getTSCSpec() ? SD_Thread : SD_Static;
00878   }
00879 
00880   /// \brief Compute the language linkage.
00881   LanguageLinkage getLanguageLinkage() const;
00882 
00883   /// \brief Determines whether this variable is a variable with
00884   /// external, C linkage.
00885   bool isExternC() const;
00886 
00887   /// \brief Determines whether this variable's context is, or is nested within,
00888   /// a C++ extern "C" linkage spec.
00889   bool isInExternCContext() const;
00890 
00891   /// \brief Determines whether this variable's context is, or is nested within,
00892   /// a C++ extern "C++" linkage spec.
00893   bool isInExternCXXContext() const;
00894 
00895   /// isLocalVarDecl - Returns true for local variable declarations
00896   /// other than parameters.  Note that this includes static variables
00897   /// inside of functions. It also includes variables inside blocks.
00898   ///
00899   ///   void foo() { int x; static int y; extern int z; }
00900   ///
00901   bool isLocalVarDecl() const {
00902     if (getKind() != Decl::Var)
00903       return false;
00904     if (const DeclContext *DC = getLexicalDeclContext())
00905       return DC->getRedeclContext()->isFunctionOrMethod();
00906     return false;
00907   }
00908 
00909   /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but
00910   /// excludes variables declared in blocks.
00911   bool isFunctionOrMethodVarDecl() const {
00912     if (getKind() != Decl::Var)
00913       return false;
00914     const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
00915     return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
00916   }
00917 
00918   /// \brief Determines whether this is a static data member.
00919   ///
00920   /// This will only be true in C++, and applies to, e.g., the
00921   /// variable 'x' in:
00922   /// \code
00923   /// struct S {
00924   ///   static int x;
00925   /// };
00926   /// \endcode
00927   bool isStaticDataMember() const {
00928     // If it wasn't static, it would be a FieldDecl.
00929     return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
00930   }
00931 
00932   VarDecl *getCanonicalDecl() override;
00933   const VarDecl *getCanonicalDecl() const {
00934     return const_cast<VarDecl*>(this)->getCanonicalDecl();
00935   }
00936 
00937   enum DefinitionKind {
00938     DeclarationOnly,      ///< This declaration is only a declaration.
00939     TentativeDefinition,  ///< This declaration is a tentative definition.
00940     Definition            ///< This declaration is definitely a definition.
00941   };
00942 
00943   /// \brief Check whether this declaration is a definition. If this could be
00944   /// a tentative definition (in C), don't check whether there's an overriding
00945   /// definition.
00946   DefinitionKind isThisDeclarationADefinition(ASTContext &) const;
00947   DefinitionKind isThisDeclarationADefinition() const {
00948     return isThisDeclarationADefinition(getASTContext());
00949   }
00950 
00951   /// \brief Check whether this variable is defined in this
00952   /// translation unit.
00953   DefinitionKind hasDefinition(ASTContext &) const;
00954   DefinitionKind hasDefinition() const {
00955     return hasDefinition(getASTContext());
00956   }
00957 
00958   /// \brief Get the tentative definition that acts as the real definition in
00959   /// a TU. Returns null if there is a proper definition available.
00960   VarDecl *getActingDefinition();
00961   const VarDecl *getActingDefinition() const {
00962     return const_cast<VarDecl*>(this)->getActingDefinition();
00963   }
00964 
00965   /// \brief Get the real (not just tentative) definition for this declaration.
00966   VarDecl *getDefinition(ASTContext &);
00967   const VarDecl *getDefinition(ASTContext &C) const {
00968     return const_cast<VarDecl*>(this)->getDefinition(C);
00969   }
00970   VarDecl *getDefinition() {
00971     return getDefinition(getASTContext());
00972   }
00973   const VarDecl *getDefinition() const {
00974     return const_cast<VarDecl*>(this)->getDefinition();
00975   }
00976 
00977   /// \brief Determine whether this is or was instantiated from an out-of-line
00978   /// definition of a static data member.
00979   bool isOutOfLine() const override;
00980 
00981   /// \brief If this is a static data member, find its out-of-line definition.
00982   VarDecl *getOutOfLineDefinition();
00983 
00984   /// isFileVarDecl - Returns true for file scoped variable declaration.
00985   bool isFileVarDecl() const {
00986     Kind K = getKind();
00987     if (K == ParmVar || K == ImplicitParam)
00988       return false;
00989 
00990     if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
00991       return true;
00992 
00993     if (isStaticDataMember())
00994       return true;
00995 
00996     return false;
00997   }
00998 
00999   /// getAnyInitializer - Get the initializer for this variable, no matter which
01000   /// declaration it is attached to.
01001   const Expr *getAnyInitializer() const {
01002     const VarDecl *D;
01003     return getAnyInitializer(D);
01004   }
01005 
01006   /// getAnyInitializer - Get the initializer for this variable, no matter which
01007   /// declaration it is attached to. Also get that declaration.
01008   const Expr *getAnyInitializer(const VarDecl *&D) const;
01009 
01010   bool hasInit() const {
01011     return !Init.isNull() && (Init.is<Stmt *>() || Init.is<EvaluatedStmt *>());
01012   }
01013   const Expr *getInit() const {
01014     if (Init.isNull())
01015       return nullptr;
01016 
01017     const Stmt *S = Init.dyn_cast<Stmt *>();
01018     if (!S) {
01019       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01020         S = ES->Value;
01021     }
01022     return (const Expr*) S;
01023   }
01024   Expr *getInit() {
01025     if (Init.isNull())
01026       return nullptr;
01027 
01028     Stmt *S = Init.dyn_cast<Stmt *>();
01029     if (!S) {
01030       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01031         S = ES->Value;
01032     }
01033 
01034     return (Expr*) S;
01035   }
01036 
01037   /// \brief Retrieve the address of the initializer expression.
01038   Stmt **getInitAddress() {
01039     if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01040       return &ES->Value;
01041 
01042     // This union hack tip-toes around strict-aliasing rules.
01043     union {
01044       InitType *InitPtr;
01045       Stmt **StmtPtr;
01046     };
01047 
01048     InitPtr = &Init;
01049     return StmtPtr;
01050   }
01051 
01052   void setInit(Expr *I);
01053 
01054   /// \brief Determine whether this variable's value can be used in a
01055   /// constant expression, according to the relevant language standard.
01056   /// This only checks properties of the declaration, and does not check
01057   /// whether the initializer is in fact a constant expression.
01058   bool isUsableInConstantExpressions(ASTContext &C) const;
01059 
01060   EvaluatedStmt *ensureEvaluatedStmt() const;
01061 
01062   /// \brief Attempt to evaluate the value of the initializer attached to this
01063   /// declaration, and produce notes explaining why it cannot be evaluated or is
01064   /// not a constant expression. Returns a pointer to the value if evaluation
01065   /// succeeded, 0 otherwise.
01066   APValue *evaluateValue() const;
01067   APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
01068 
01069   /// \brief Return the already-evaluated value of this variable's
01070   /// initializer, or NULL if the value is not yet known. Returns pointer
01071   /// to untyped APValue if the value could not be evaluated.
01072   APValue *getEvaluatedValue() const {
01073     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
01074       if (Eval->WasEvaluated)
01075         return &Eval->Evaluated;
01076 
01077     return nullptr;
01078   }
01079 
01080   /// \brief Determines whether it is already known whether the
01081   /// initializer is an integral constant expression or not.
01082   bool isInitKnownICE() const {
01083     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
01084       return Eval->CheckedICE;
01085 
01086     return false;
01087   }
01088 
01089   /// \brief Determines whether the initializer is an integral constant
01090   /// expression, or in C++11, whether the initializer is a constant
01091   /// expression.
01092   ///
01093   /// \pre isInitKnownICE()
01094   bool isInitICE() const {
01095     assert(isInitKnownICE() &&
01096            "Check whether we already know that the initializer is an ICE");
01097     return Init.get<EvaluatedStmt *>()->IsICE;
01098   }
01099 
01100   /// \brief Determine whether the value of the initializer attached to this
01101   /// declaration is an integral constant expression.
01102   bool checkInitIsICE() const;
01103 
01104   void setInitStyle(InitializationStyle Style) {
01105     VarDeclBits.InitStyle = Style;
01106   }
01107 
01108   /// \brief The style of initialization for this declaration.
01109   ///
01110   /// C-style initialization is "int x = 1;". Call-style initialization is
01111   /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
01112   /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
01113   /// expression for class types. List-style initialization is C++11 syntax,
01114   /// e.g. "int x{1};". Clients can distinguish between different forms of
01115   /// initialization by checking this value. In particular, "int x = {1};" is
01116   /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
01117   /// Init expression in all three cases is an InitListExpr.
01118   InitializationStyle getInitStyle() const {
01119     return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
01120   }
01121 
01122   /// \brief Whether the initializer is a direct-initializer (list or call).
01123   bool isDirectInit() const {
01124     return getInitStyle() != CInit;
01125   }
01126 
01127   /// \brief Determine whether this variable is the exception variable in a
01128   /// C++ catch statememt or an Objective-C \@catch statement.
01129   bool isExceptionVariable() const {
01130     return VarDeclBits.ExceptionVar;
01131   }
01132   void setExceptionVariable(bool EV) { VarDeclBits.ExceptionVar = EV; }
01133 
01134   /// \brief Determine whether this local variable can be used with the named
01135   /// return value optimization (NRVO).
01136   ///
01137   /// The named return value optimization (NRVO) works by marking certain
01138   /// non-volatile local variables of class type as NRVO objects. These
01139   /// locals can be allocated within the return slot of their containing
01140   /// function, in which case there is no need to copy the object to the
01141   /// return slot when returning from the function. Within the function body,
01142   /// each return that returns the NRVO object will have this variable as its
01143   /// NRVO candidate.
01144   bool isNRVOVariable() const { return VarDeclBits.NRVOVariable; }
01145   void setNRVOVariable(bool NRVO) { VarDeclBits.NRVOVariable = NRVO; }
01146 
01147   /// \brief Determine whether this variable is the for-range-declaration in
01148   /// a C++0x for-range statement.
01149   bool isCXXForRangeDecl() const { return VarDeclBits.CXXForRangeDecl; }
01150   void setCXXForRangeDecl(bool FRD) { VarDeclBits.CXXForRangeDecl = FRD; }
01151 
01152   /// \brief Determine whether this variable is an ARC pseudo-__strong
01153   /// variable.  A pseudo-__strong variable has a __strong-qualified
01154   /// type but does not actually retain the object written into it.
01155   /// Generally such variables are also 'const' for safety.
01156   bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
01157   void setARCPseudoStrong(bool ps) { VarDeclBits.ARCPseudoStrong = ps; }
01158 
01159   /// Whether this variable is (C++11) constexpr.
01160   bool isConstexpr() const { return VarDeclBits.IsConstexpr; }
01161   void setConstexpr(bool IC) { VarDeclBits.IsConstexpr = IC; }
01162 
01163   /// Whether this variable is the implicit variable for a lambda init-capture.
01164   bool isInitCapture() const { return VarDeclBits.IsInitCapture; }
01165   void setInitCapture(bool IC) { VarDeclBits.IsInitCapture = IC; }
01166 
01167   /// Whether this local extern variable declaration's previous declaration
01168   /// was declared in the same block scope. Only correct in C++.
01169   bool isPreviousDeclInSameBlockScope() const {
01170     return VarDeclBits.PreviousDeclInSameBlockScope;
01171   }
01172   void setPreviousDeclInSameBlockScope(bool Same) {
01173     VarDeclBits.PreviousDeclInSameBlockScope = Same;
01174   }
01175 
01176   /// \brief If this variable is an instantiated static data member of a
01177   /// class template specialization, returns the templated static data member
01178   /// from which it was instantiated.
01179   VarDecl *getInstantiatedFromStaticDataMember() const;
01180 
01181   /// \brief If this variable is an instantiation of a variable template or a
01182   /// static data member of a class template, determine what kind of
01183   /// template specialization or instantiation this is.
01184   TemplateSpecializationKind getTemplateSpecializationKind() const;
01185 
01186   /// \brief If this variable is an instantiation of a variable template or a
01187   /// static data member of a class template, determine its point of
01188   /// instantiation.
01189   SourceLocation getPointOfInstantiation() const;
01190 
01191   /// \brief If this variable is an instantiation of a static data member of a
01192   /// class template specialization, retrieves the member specialization
01193   /// information.
01194   MemberSpecializationInfo *getMemberSpecializationInfo() const;
01195 
01196   /// \brief For a static data member that was instantiated from a static
01197   /// data member of a class template, set the template specialiation kind.
01198   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
01199                         SourceLocation PointOfInstantiation = SourceLocation());
01200 
01201   /// \brief Specify that this variable is an instantiation of the
01202   /// static data member VD.
01203   void setInstantiationOfStaticDataMember(VarDecl *VD,
01204                                           TemplateSpecializationKind TSK);
01205 
01206   /// \brief Retrieves the variable template that is described by this
01207   /// variable declaration.
01208   ///
01209   /// Every variable template is represented as a VarTemplateDecl and a
01210   /// VarDecl. The former contains template properties (such as
01211   /// the template parameter lists) while the latter contains the
01212   /// actual description of the template's
01213   /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
01214   /// VarDecl that from a VarTemplateDecl, while
01215   /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
01216   /// a VarDecl.
01217   VarTemplateDecl *getDescribedVarTemplate() const;
01218 
01219   void setDescribedVarTemplate(VarTemplateDecl *Template);
01220 
01221   // Implement isa/cast/dyncast/etc.
01222   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01223   static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
01224 };
01225 
01226 class ImplicitParamDecl : public VarDecl {
01227   void anchor() override;
01228 public:
01229   static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
01230                                    SourceLocation IdLoc, IdentifierInfo *Id,
01231                                    QualType T);
01232 
01233   static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01234 
01235   ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
01236                     IdentifierInfo *Id, QualType Type)
01237     : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
01238               /*tinfo*/ nullptr, SC_None) {
01239     setImplicit();
01240   }
01241 
01242   // Implement isa/cast/dyncast/etc.
01243   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01244   static bool classofKind(Kind K) { return K == ImplicitParam; }
01245 };
01246 
01247 /// ParmVarDecl - Represents a parameter to a function.
01248 class ParmVarDecl : public VarDecl {
01249 public:
01250   enum { MaxFunctionScopeDepth = 255 };
01251   enum { MaxFunctionScopeIndex = 255 };
01252 
01253 protected:
01254   ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
01255               SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
01256               TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
01257       : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
01258     assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
01259     assert(ParmVarDeclBits.IsKNRPromoted == false);
01260     assert(ParmVarDeclBits.IsObjCMethodParam == false);
01261     setDefaultArg(DefArg);
01262   }
01263 
01264 public:
01265   static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
01266                              SourceLocation StartLoc,
01267                              SourceLocation IdLoc, IdentifierInfo *Id,
01268                              QualType T, TypeSourceInfo *TInfo,
01269                              StorageClass S, Expr *DefArg);
01270 
01271   static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01272 
01273   SourceRange getSourceRange() const override LLVM_READONLY;
01274 
01275   void setObjCMethodScopeInfo(unsigned parameterIndex) {
01276     ParmVarDeclBits.IsObjCMethodParam = true;
01277     setParameterIndex(parameterIndex);
01278   }
01279 
01280   void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
01281     assert(!ParmVarDeclBits.IsObjCMethodParam);
01282 
01283     ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
01284     assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
01285            && "truncation!");
01286 
01287     setParameterIndex(parameterIndex);
01288   }
01289 
01290   bool isObjCMethodParameter() const {
01291     return ParmVarDeclBits.IsObjCMethodParam;
01292   }
01293 
01294   unsigned getFunctionScopeDepth() const {
01295     if (ParmVarDeclBits.IsObjCMethodParam) return 0;
01296     return ParmVarDeclBits.ScopeDepthOrObjCQuals;
01297   }
01298 
01299   /// Returns the index of this parameter in its prototype or method scope.
01300   unsigned getFunctionScopeIndex() const {
01301     return getParameterIndex();
01302   }
01303 
01304   ObjCDeclQualifier getObjCDeclQualifier() const {
01305     if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
01306     return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
01307   }
01308   void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
01309     assert(ParmVarDeclBits.IsObjCMethodParam);
01310     ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
01311   }
01312 
01313   /// True if the value passed to this parameter must undergo
01314   /// K&R-style default argument promotion:
01315   ///
01316   /// C99 6.5.2.2.
01317   ///   If the expression that denotes the called function has a type
01318   ///   that does not include a prototype, the integer promotions are
01319   ///   performed on each argument, and arguments that have type float
01320   ///   are promoted to double.
01321   bool isKNRPromoted() const {
01322     return ParmVarDeclBits.IsKNRPromoted;
01323   }
01324   void setKNRPromoted(bool promoted) {
01325     ParmVarDeclBits.IsKNRPromoted = promoted;
01326   }
01327 
01328   Expr *getDefaultArg();
01329   const Expr *getDefaultArg() const {
01330     return const_cast<ParmVarDecl *>(this)->getDefaultArg();
01331   }
01332 
01333   void setDefaultArg(Expr *defarg) {
01334     Init = reinterpret_cast<Stmt *>(defarg);
01335   }
01336 
01337   /// \brief Retrieve the source range that covers the entire default
01338   /// argument.
01339   SourceRange getDefaultArgRange() const;
01340   void setUninstantiatedDefaultArg(Expr *arg) {
01341     Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg);
01342   }
01343   Expr *getUninstantiatedDefaultArg() {
01344     return (Expr *)Init.get<UninstantiatedDefaultArgument *>();
01345   }
01346   const Expr *getUninstantiatedDefaultArg() const {
01347     return (const Expr *)Init.get<UninstantiatedDefaultArgument *>();
01348   }
01349 
01350   /// hasDefaultArg - Determines whether this parameter has a default argument,
01351   /// either parsed or not.
01352   bool hasDefaultArg() const {
01353     return getInit() || hasUnparsedDefaultArg() ||
01354       hasUninstantiatedDefaultArg();
01355   }
01356 
01357   /// hasUnparsedDefaultArg - Determines whether this parameter has a
01358   /// default argument that has not yet been parsed. This will occur
01359   /// during the processing of a C++ class whose member functions have
01360   /// default arguments, e.g.,
01361   /// @code
01362   ///   class X {
01363   ///   public:
01364   ///     void f(int x = 17); // x has an unparsed default argument now
01365   ///   }; // x has a regular default argument now
01366   /// @endcode
01367   bool hasUnparsedDefaultArg() const {
01368     return Init.is<UnparsedDefaultArgument*>();
01369   }
01370 
01371   bool hasUninstantiatedDefaultArg() const {
01372     return Init.is<UninstantiatedDefaultArgument*>();
01373   }
01374 
01375   /// setUnparsedDefaultArg - Specify that this parameter has an
01376   /// unparsed default argument. The argument will be replaced with a
01377   /// real default argument via setDefaultArg when the class
01378   /// definition enclosing the function declaration that owns this
01379   /// default argument is completed.
01380   void setUnparsedDefaultArg() { Init = (UnparsedDefaultArgument *)nullptr; }
01381 
01382   bool hasInheritedDefaultArg() const {
01383     return ParmVarDeclBits.HasInheritedDefaultArg;
01384   }
01385 
01386   void setHasInheritedDefaultArg(bool I = true) {
01387     ParmVarDeclBits.HasInheritedDefaultArg = I;
01388   }
01389 
01390   QualType getOriginalType() const;
01391 
01392   /// \brief Determine whether this parameter is actually a function
01393   /// parameter pack.
01394   bool isParameterPack() const;
01395 
01396   /// setOwningFunction - Sets the function declaration that owns this
01397   /// ParmVarDecl. Since ParmVarDecls are often created before the
01398   /// FunctionDecls that own them, this routine is required to update
01399   /// the DeclContext appropriately.
01400   void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
01401 
01402   // Implement isa/cast/dyncast/etc.
01403   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01404   static bool classofKind(Kind K) { return K == ParmVar; }
01405 
01406 private:
01407   enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
01408 
01409   void setParameterIndex(unsigned parameterIndex) {
01410     if (parameterIndex >= ParameterIndexSentinel) {
01411       setParameterIndexLarge(parameterIndex);
01412       return;
01413     }
01414 
01415     ParmVarDeclBits.ParameterIndex = parameterIndex;
01416     assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
01417   }
01418   unsigned getParameterIndex() const {
01419     unsigned d = ParmVarDeclBits.ParameterIndex;
01420     return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
01421   }
01422 
01423   void setParameterIndexLarge(unsigned parameterIndex);
01424   unsigned getParameterIndexLarge() const;
01425 };
01426 
01427 /// FunctionDecl - An instance of this class is created to represent a
01428 /// function declaration or definition.
01429 ///
01430 /// Since a given function can be declared several times in a program,
01431 /// there may be several FunctionDecls that correspond to that
01432 /// function. Only one of those FunctionDecls will be found when
01433 /// traversing the list of declarations in the context of the
01434 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
01435 /// contains all of the information known about the function. Other,
01436 /// previous declarations of the function are available via the
01437 /// getPreviousDecl() chain.
01438 class FunctionDecl : public DeclaratorDecl, public DeclContext,
01439                      public Redeclarable<FunctionDecl> {
01440 public:
01441   /// \brief The kind of templated function a FunctionDecl can be.
01442   enum TemplatedKind {
01443     TK_NonTemplate,
01444     TK_FunctionTemplate,
01445     TK_MemberSpecialization,
01446     TK_FunctionTemplateSpecialization,
01447     TK_DependentFunctionTemplateSpecialization
01448   };
01449 
01450 private:
01451   /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
01452   /// parameters of this function.  This is null if a prototype or if there are
01453   /// no formals.
01454   ParmVarDecl **ParamInfo;
01455 
01456   /// DeclsInPrototypeScope - Array of pointers to NamedDecls for
01457   /// decls defined in the function prototype that are not parameters. E.g.
01458   /// 'enum Y' in 'void f(enum Y {AA} x) {}'.
01459   ArrayRef<NamedDecl *> DeclsInPrototypeScope;
01460 
01461   LazyDeclStmtPtr Body;
01462 
01463   // FIXME: This can be packed into the bitfields in Decl.
01464   // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
01465   unsigned SClass : 2;
01466   bool IsInline : 1;
01467   bool IsInlineSpecified : 1;
01468   bool IsVirtualAsWritten : 1;
01469   bool IsPure : 1;
01470   bool HasInheritedPrototype : 1;
01471   bool HasWrittenPrototype : 1;
01472   bool IsDeleted : 1;
01473   bool IsTrivial : 1; // sunk from CXXMethodDecl
01474   bool IsDefaulted : 1; // sunk from CXXMethoDecl
01475   bool IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl
01476   bool HasImplicitReturnZero : 1;
01477   bool IsLateTemplateParsed : 1;
01478   bool IsConstexpr : 1;
01479 
01480   /// \brief Indicates if the function was a definition but its body was
01481   /// skipped.
01482   unsigned HasSkippedBody : 1;
01483 
01484   /// \brief End part of this FunctionDecl's source range.
01485   ///
01486   /// We could compute the full range in getSourceRange(). However, when we're
01487   /// dealing with a function definition deserialized from a PCH/AST file,
01488   /// we can only compute the full range once the function body has been
01489   /// de-serialized, so it's far better to have the (sometimes-redundant)
01490   /// EndRangeLoc.
01491   SourceLocation EndRangeLoc;
01492 
01493   /// \brief The template or declaration that this declaration
01494   /// describes or was instantiated from, respectively.
01495   ///
01496   /// For non-templates, this value will be NULL. For function
01497   /// declarations that describe a function template, this will be a
01498   /// pointer to a FunctionTemplateDecl. For member functions
01499   /// of class template specializations, this will be a MemberSpecializationInfo
01500   /// pointer containing information about the specialization.
01501   /// For function template specializations, this will be a
01502   /// FunctionTemplateSpecializationInfo, which contains information about
01503   /// the template being specialized and the template arguments involved in
01504   /// that specialization.
01505   llvm::PointerUnion4<FunctionTemplateDecl *,
01506                       MemberSpecializationInfo *,
01507                       FunctionTemplateSpecializationInfo *,
01508                       DependentFunctionTemplateSpecializationInfo *>
01509     TemplateOrSpecialization;
01510 
01511   /// DNLoc - Provides source/type location info for the
01512   /// declaration name embedded in the DeclaratorDecl base class.
01513   DeclarationNameLoc DNLoc;
01514 
01515   /// \brief Specify that this function declaration is actually a function
01516   /// template specialization.
01517   ///
01518   /// \param C the ASTContext.
01519   ///
01520   /// \param Template the function template that this function template
01521   /// specialization specializes.
01522   ///
01523   /// \param TemplateArgs the template arguments that produced this
01524   /// function template specialization from the template.
01525   ///
01526   /// \param InsertPos If non-NULL, the position in the function template
01527   /// specialization set where the function template specialization data will
01528   /// be inserted.
01529   ///
01530   /// \param TSK the kind of template specialization this is.
01531   ///
01532   /// \param TemplateArgsAsWritten location info of template arguments.
01533   ///
01534   /// \param PointOfInstantiation point at which the function template
01535   /// specialization was first instantiated.
01536   void setFunctionTemplateSpecialization(ASTContext &C,
01537                                          FunctionTemplateDecl *Template,
01538                                        const TemplateArgumentList *TemplateArgs,
01539                                          void *InsertPos,
01540                                          TemplateSpecializationKind TSK,
01541                           const TemplateArgumentListInfo *TemplateArgsAsWritten,
01542                                          SourceLocation PointOfInstantiation);
01543 
01544   /// \brief Specify that this record is an instantiation of the
01545   /// member function FD.
01546   void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
01547                                         TemplateSpecializationKind TSK);
01548 
01549   void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
01550 
01551 protected:
01552   FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
01553                const DeclarationNameInfo &NameInfo,
01554                QualType T, TypeSourceInfo *TInfo,
01555                StorageClass S, bool isInlineSpecified,
01556                bool isConstexprSpecified)
01557     : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
01558                      StartLoc),
01559       DeclContext(DK),
01560       redeclarable_base(C),
01561       ParamInfo(nullptr), Body(),
01562       SClass(S),
01563       IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified),
01564       IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
01565       HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
01566       IsDefaulted(false), IsExplicitlyDefaulted(false),
01567       HasImplicitReturnZero(false), IsLateTemplateParsed(false),
01568       IsConstexpr(isConstexprSpecified), HasSkippedBody(false),
01569       EndRangeLoc(NameInfo.getEndLoc()),
01570       TemplateOrSpecialization(),
01571       DNLoc(NameInfo.getInfo()) {}
01572 
01573   typedef Redeclarable<FunctionDecl> redeclarable_base;
01574   FunctionDecl *getNextRedeclarationImpl() override {
01575     return getNextRedeclaration();
01576   }
01577   FunctionDecl *getPreviousDeclImpl() override {
01578     return getPreviousDecl();
01579   }
01580   FunctionDecl *getMostRecentDeclImpl() override {
01581     return getMostRecentDecl();
01582   }
01583 
01584 public:
01585   typedef redeclarable_base::redecl_range redecl_range;
01586   typedef redeclarable_base::redecl_iterator redecl_iterator;
01587   using redeclarable_base::redecls_begin;
01588   using redeclarable_base::redecls_end;
01589   using redeclarable_base::redecls;
01590   using redeclarable_base::getPreviousDecl;
01591   using redeclarable_base::getMostRecentDecl;
01592   using redeclarable_base::isFirstDecl;
01593 
01594   static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
01595                               SourceLocation StartLoc, SourceLocation NLoc,
01596                               DeclarationName N, QualType T,
01597                               TypeSourceInfo *TInfo,
01598                               StorageClass SC,
01599                               bool isInlineSpecified = false,
01600                               bool hasWrittenPrototype = true,
01601                               bool isConstexprSpecified = false) {
01602     DeclarationNameInfo NameInfo(N, NLoc);
01603     return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
01604                                 SC,
01605                                 isInlineSpecified, hasWrittenPrototype,
01606                                 isConstexprSpecified);
01607   }
01608 
01609   static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
01610                               SourceLocation StartLoc,
01611                               const DeclarationNameInfo &NameInfo,
01612                               QualType T, TypeSourceInfo *TInfo,
01613                               StorageClass SC,
01614                               bool isInlineSpecified,
01615                               bool hasWrittenPrototype,
01616                               bool isConstexprSpecified = false);
01617 
01618   static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01619                        
01620   DeclarationNameInfo getNameInfo() const {
01621     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
01622   }
01623 
01624   void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
01625                             bool Qualified) const override;
01626 
01627   void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
01628 
01629   SourceRange getSourceRange() const override LLVM_READONLY;
01630 
01631   /// \brief Returns true if the function has a body (definition). The
01632   /// function body might be in any of the (re-)declarations of this
01633   /// function. The variant that accepts a FunctionDecl pointer will
01634   /// set that function declaration to the actual declaration
01635   /// containing the body (if there is one).
01636   bool hasBody(const FunctionDecl *&Definition) const;
01637 
01638   bool hasBody() const override {
01639     const FunctionDecl* Definition;
01640     return hasBody(Definition);
01641   }
01642 
01643   /// hasTrivialBody - Returns whether the function has a trivial body that does
01644   /// not require any specific codegen.
01645   bool hasTrivialBody() const;
01646 
01647   /// isDefined - Returns true if the function is defined at all, including
01648   /// a deleted definition. Except for the behavior when the function is
01649   /// deleted, behaves like hasBody.
01650   bool isDefined(const FunctionDecl *&Definition) const;
01651 
01652   virtual bool isDefined() const {
01653     const FunctionDecl* Definition;
01654     return isDefined(Definition);
01655   }
01656 
01657   /// getBody - Retrieve the body (definition) of the function. The
01658   /// function body might be in any of the (re-)declarations of this
01659   /// function. The variant that accepts a FunctionDecl pointer will
01660   /// set that function declaration to the actual declaration
01661   /// containing the body (if there is one).
01662   /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
01663   /// unnecessary AST de-serialization of the body.
01664   Stmt *getBody(const FunctionDecl *&Definition) const;
01665 
01666   Stmt *getBody() const override {
01667     const FunctionDecl* Definition;
01668     return getBody(Definition);
01669   }
01670 
01671   /// isThisDeclarationADefinition - Returns whether this specific
01672   /// declaration of the function is also a definition. This does not
01673   /// determine whether the function has been defined (e.g., in a
01674   /// previous definition); for that information, use isDefined. Note
01675   /// that this returns false for a defaulted function unless that function
01676   /// has been implicitly defined (possibly as deleted).
01677   bool isThisDeclarationADefinition() const {
01678     return IsDeleted || Body || IsLateTemplateParsed;
01679   }
01680 
01681   /// doesThisDeclarationHaveABody - Returns whether this specific
01682   /// declaration of the function has a body - that is, if it is a non-
01683   /// deleted definition.
01684   bool doesThisDeclarationHaveABody() const {
01685     return Body || IsLateTemplateParsed;
01686   }
01687 
01688   void setBody(Stmt *B);
01689   void setLazyBody(uint64_t Offset) { Body = Offset; }
01690 
01691   /// Whether this function is variadic.
01692   bool isVariadic() const;
01693 
01694   /// Whether this function is marked as virtual explicitly.
01695   bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
01696   void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
01697 
01698   /// Whether this virtual function is pure, i.e. makes the containing class
01699   /// abstract.
01700   bool isPure() const { return IsPure; }
01701   void setPure(bool P = true);
01702 
01703   /// Whether this templated function will be late parsed.
01704   bool isLateTemplateParsed() const { return IsLateTemplateParsed; }
01705   void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; }
01706 
01707   /// Whether this function is "trivial" in some specialized C++ senses.
01708   /// Can only be true for default constructors, copy constructors,
01709   /// copy assignment operators, and destructors.  Not meaningful until
01710   /// the class has been fully built by Sema.
01711   bool isTrivial() const { return IsTrivial; }
01712   void setTrivial(bool IT) { IsTrivial = IT; }
01713 
01714   /// Whether this function is defaulted per C++0x. Only valid for
01715   /// special member functions.
01716   bool isDefaulted() const { return IsDefaulted; }
01717   void setDefaulted(bool D = true) { IsDefaulted = D; }
01718 
01719   /// Whether this function is explicitly defaulted per C++0x. Only valid
01720   /// for special member functions.
01721   bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; }
01722   void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; }
01723 
01724   /// Whether falling off this function implicitly returns null/zero.
01725   /// If a more specific implicit return value is required, front-ends
01726   /// should synthesize the appropriate return statements.
01727   bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
01728   void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
01729 
01730   /// \brief Whether this function has a prototype, either because one
01731   /// was explicitly written or because it was "inherited" by merging
01732   /// a declaration without a prototype with a declaration that has a
01733   /// prototype.
01734   bool hasPrototype() const {
01735     return HasWrittenPrototype || HasInheritedPrototype;
01736   }
01737 
01738   bool hasWrittenPrototype() const { return HasWrittenPrototype; }
01739 
01740   /// \brief Whether this function inherited its prototype from a
01741   /// previous declaration.
01742   bool hasInheritedPrototype() const { return HasInheritedPrototype; }
01743   void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
01744 
01745   /// Whether this is a (C++11) constexpr function or constexpr constructor.
01746   bool isConstexpr() const { return IsConstexpr; }
01747   void setConstexpr(bool IC) { IsConstexpr = IC; }
01748 
01749   /// \brief Whether this function has been deleted.
01750   ///
01751   /// A function that is "deleted" (via the C++0x "= delete" syntax)
01752   /// acts like a normal function, except that it cannot actually be
01753   /// called or have its address taken. Deleted functions are
01754   /// typically used in C++ overload resolution to attract arguments
01755   /// whose type or lvalue/rvalue-ness would permit the use of a
01756   /// different overload that would behave incorrectly. For example,
01757   /// one might use deleted functions to ban implicit conversion from
01758   /// a floating-point number to an Integer type:
01759   ///
01760   /// @code
01761   /// struct Integer {
01762   ///   Integer(long); // construct from a long
01763   ///   Integer(double) = delete; // no construction from float or double
01764   ///   Integer(long double) = delete; // no construction from long double
01765   /// };
01766   /// @endcode
01767   // If a function is deleted, its first declaration must be.
01768   bool isDeleted() const { return getCanonicalDecl()->IsDeleted; }
01769   bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; }
01770   void setDeletedAsWritten(bool D = true) { IsDeleted = D; }
01771 
01772   /// \brief Determines whether this function is "main", which is the
01773   /// entry point into an executable program.
01774   bool isMain() const;
01775 
01776   /// \brief Determines whether this function is a MSVCRT user defined entry
01777   /// point.
01778   bool isMSVCRTEntryPoint() const;
01779 
01780   /// \brief Determines whether this operator new or delete is one
01781   /// of the reserved global placement operators:
01782   ///    void *operator new(size_t, void *);
01783   ///    void *operator new[](size_t, void *);
01784   ///    void operator delete(void *, void *);
01785   ///    void operator delete[](void *, void *);
01786   /// These functions have special behavior under [new.delete.placement]:
01787   ///    These functions are reserved, a C++ program may not define
01788   ///    functions that displace the versions in the Standard C++ library.
01789   ///    The provisions of [basic.stc.dynamic] do not apply to these
01790   ///    reserved placement forms of operator new and operator delete.
01791   ///
01792   /// This function must be an allocation or deallocation function.
01793   bool isReservedGlobalPlacementOperator() const;
01794 
01795   /// \brief Determines whether this function is one of the replaceable
01796   /// global allocation functions:
01797   ///    void *operator new(size_t);
01798   ///    void *operator new(size_t, const std::nothrow_t &) noexcept;
01799   ///    void *operator new[](size_t);
01800   ///    void *operator new[](size_t, const std::nothrow_t &) noexcept;
01801   ///    void operator delete(void *) noexcept;
01802   ///    void operator delete(void *, std::size_t) noexcept;      [C++1y]
01803   ///    void operator delete(void *, const std::nothrow_t &) noexcept;
01804   ///    void operator delete[](void *) noexcept;
01805   ///    void operator delete[](void *, std::size_t) noexcept;    [C++1y]
01806   ///    void operator delete[](void *, const std::nothrow_t &) noexcept;
01807   /// These functions have special behavior under C++1y [expr.new]:
01808   ///    An implementation is allowed to omit a call to a replaceable global
01809   ///    allocation function. [...]
01810   bool isReplaceableGlobalAllocationFunction() const;
01811 
01812   /// \brief Determine whether this function is a sized global deallocation
01813   /// function in C++1y. If so, find and return the corresponding unsized
01814   /// deallocation function.
01815   FunctionDecl *getCorrespondingUnsizedGlobalDeallocationFunction() const;
01816 
01817   /// Compute the language linkage.
01818   LanguageLinkage getLanguageLinkage() const;
01819 
01820   /// \brief Determines whether this function is a function with
01821   /// external, C linkage.
01822   bool isExternC() const;
01823 
01824   /// \brief Determines whether this function's context is, or is nested within,
01825   /// a C++ extern "C" linkage spec.
01826   bool isInExternCContext() const;
01827 
01828   /// \brief Determines whether this function's context is, or is nested within,
01829   /// a C++ extern "C++" linkage spec.
01830   bool isInExternCXXContext() const;
01831 
01832   /// \brief Determines whether this is a global function.
01833   bool isGlobal() const;
01834 
01835   /// \brief Determines whether this function is known to be 'noreturn', through
01836   /// an attribute on its declaration or its type.
01837   bool isNoReturn() const;
01838 
01839   /// \brief True if the function was a definition but its body was skipped.
01840   bool hasSkippedBody() const { return HasSkippedBody; }
01841   void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
01842 
01843   void setPreviousDeclaration(FunctionDecl * PrevDecl);
01844 
01845   virtual const FunctionDecl *getCanonicalDecl() const;
01846   FunctionDecl *getCanonicalDecl() override;
01847 
01848   unsigned getBuiltinID() const;
01849 
01850   // Iterator access to formal parameters.
01851   unsigned param_size() const { return getNumParams(); }
01852   typedef ParmVarDecl **param_iterator;
01853   typedef ParmVarDecl * const *param_const_iterator;
01854   typedef llvm::iterator_range<param_iterator> param_range;
01855   typedef llvm::iterator_range<param_const_iterator> param_const_range;
01856 
01857   param_iterator param_begin() { return param_iterator(ParamInfo); }
01858   param_iterator param_end() {
01859     return param_iterator(ParamInfo + param_size());
01860   }
01861   param_range params() { return param_range(param_begin(), param_end()); }
01862 
01863   param_const_iterator param_begin() const {
01864     return param_const_iterator(ParamInfo);
01865   }
01866   param_const_iterator param_end() const {
01867     return param_const_iterator(ParamInfo + param_size());
01868   }
01869   param_const_range params() const {
01870     return param_const_range(param_begin(), param_end());
01871   }
01872 
01873   /// getNumParams - Return the number of parameters this function must have
01874   /// based on its FunctionType.  This is the length of the ParamInfo array
01875   /// after it has been created.
01876   unsigned getNumParams() const;
01877 
01878   const ParmVarDecl *getParamDecl(unsigned i) const {
01879     assert(i < getNumParams() && "Illegal param #");
01880     return ParamInfo[i];
01881   }
01882   ParmVarDecl *getParamDecl(unsigned i) {
01883     assert(i < getNumParams() && "Illegal param #");
01884     return ParamInfo[i];
01885   }
01886   void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
01887     setParams(getASTContext(), NewParamInfo);
01888   }
01889 
01890   // ArrayRef iterface to parameters.
01891   // FIXME: Should one day replace iterator interface.
01892   ArrayRef<ParmVarDecl*> parameters() const {
01893     return llvm::makeArrayRef(ParamInfo, getNumParams());
01894   }
01895 
01896   ArrayRef<NamedDecl *> getDeclsInPrototypeScope() const {
01897     return DeclsInPrototypeScope;
01898   }
01899   void setDeclsInPrototypeScope(ArrayRef<NamedDecl *> NewDecls);
01900 
01901   /// getMinRequiredArguments - Returns the minimum number of arguments
01902   /// needed to call this function. This may be fewer than the number of
01903   /// function parameters, if some of the parameters have default
01904   /// arguments (in C++).
01905   unsigned getMinRequiredArguments() const;
01906 
01907   QualType getReturnType() const {
01908     return getType()->getAs<FunctionType>()->getReturnType();
01909   }
01910 
01911   /// \brief Attempt to compute an informative source range covering the
01912   /// function return type. This may omit qualifiers and other information with
01913   /// limited representation in the AST.
01914   SourceRange getReturnTypeSourceRange() const;
01915 
01916   /// \brief Determine the type of an expression that calls this function.
01917   QualType getCallResultType() const {
01918     return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
01919   }
01920 
01921   /// \brief Returns the storage class as written in the source. For the
01922   /// computed linkage of symbol, see getLinkage.
01923   StorageClass getStorageClass() const { return StorageClass(SClass); }
01924 
01925   /// \brief Determine whether the "inline" keyword was specified for this
01926   /// function.
01927   bool isInlineSpecified() const { return IsInlineSpecified; }
01928 
01929   /// Set whether the "inline" keyword was specified for this function.
01930   void setInlineSpecified(bool I) {
01931     IsInlineSpecified = I;
01932     IsInline = I;
01933   }
01934 
01935   /// Flag that this function is implicitly inline.
01936   void setImplicitlyInline() {
01937     IsInline = true;
01938   }
01939 
01940   /// \brief Determine whether this function should be inlined, because it is
01941   /// either marked "inline" or "constexpr" or is a member function of a class
01942   /// that was defined in the class body.
01943   bool isInlined() const { return IsInline; }
01944 
01945   bool isInlineDefinitionExternallyVisible() const;
01946 
01947   bool isMSExternInline() const;
01948 
01949   bool doesDeclarationForceExternallyVisibleDefinition() const;
01950 
01951   /// isOverloadedOperator - Whether this function declaration
01952   /// represents an C++ overloaded operator, e.g., "operator+".
01953   bool isOverloadedOperator() const {
01954     return getOverloadedOperator() != OO_None;
01955   }
01956 
01957   OverloadedOperatorKind getOverloadedOperator() const;
01958 
01959   const IdentifierInfo *getLiteralIdentifier() const;
01960 
01961   /// \brief If this function is an instantiation of a member function
01962   /// of a class template specialization, retrieves the function from
01963   /// which it was instantiated.
01964   ///
01965   /// This routine will return non-NULL for (non-templated) member
01966   /// functions of class templates and for instantiations of function
01967   /// templates. For example, given:
01968   ///
01969   /// \code
01970   /// template<typename T>
01971   /// struct X {
01972   ///   void f(T);
01973   /// };
01974   /// \endcode
01975   ///
01976   /// The declaration for X<int>::f is a (non-templated) FunctionDecl
01977   /// whose parent is the class template specialization X<int>. For
01978   /// this declaration, getInstantiatedFromFunction() will return
01979   /// the FunctionDecl X<T>::A. When a complete definition of
01980   /// X<int>::A is required, it will be instantiated from the
01981   /// declaration returned by getInstantiatedFromMemberFunction().
01982   FunctionDecl *getInstantiatedFromMemberFunction() const;
01983 
01984   /// \brief What kind of templated function this is.
01985   TemplatedKind getTemplatedKind() const;
01986 
01987   /// \brief If this function is an instantiation of a member function of a
01988   /// class template specialization, retrieves the member specialization
01989   /// information.
01990   MemberSpecializationInfo *getMemberSpecializationInfo() const {
01991     return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
01992   }
01993 
01994   /// \brief Specify that this record is an instantiation of the
01995   /// member function FD.
01996   void setInstantiationOfMemberFunction(FunctionDecl *FD,
01997                                         TemplateSpecializationKind TSK) {
01998     setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
01999   }
02000 
02001   /// \brief Retrieves the function template that is described by this
02002   /// function declaration.
02003   ///
02004   /// Every function template is represented as a FunctionTemplateDecl
02005   /// and a FunctionDecl (or something derived from FunctionDecl). The
02006   /// former contains template properties (such as the template
02007   /// parameter lists) while the latter contains the actual
02008   /// description of the template's
02009   /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
02010   /// FunctionDecl that describes the function template,
02011   /// getDescribedFunctionTemplate() retrieves the
02012   /// FunctionTemplateDecl from a FunctionDecl.
02013   FunctionTemplateDecl *getDescribedFunctionTemplate() const {
02014     return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>();
02015   }
02016 
02017   void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) {
02018     TemplateOrSpecialization = Template;
02019   }
02020 
02021   /// \brief Determine whether this function is a function template
02022   /// specialization.
02023   bool isFunctionTemplateSpecialization() const {
02024     return getPrimaryTemplate() != nullptr;
02025   }
02026 
02027   /// \brief Retrieve the class scope template pattern that this function
02028   ///  template specialization is instantiated from.
02029   FunctionDecl *getClassScopeSpecializationPattern() const;
02030 
02031   /// \brief If this function is actually a function template specialization,
02032   /// retrieve information about this function template specialization.
02033   /// Otherwise, returns NULL.
02034   FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const {
02035     return TemplateOrSpecialization.
02036              dyn_cast<FunctionTemplateSpecializationInfo*>();
02037   }
02038 
02039   /// \brief Determines whether this function is a function template
02040   /// specialization or a member of a class template specialization that can
02041   /// be implicitly instantiated.
02042   bool isImplicitlyInstantiable() const;
02043 
02044   /// \brief Determines if the given function was instantiated from a
02045   /// function template.
02046   bool isTemplateInstantiation() const;
02047 
02048   /// \brief Retrieve the function declaration from which this function could
02049   /// be instantiated, if it is an instantiation (rather than a non-template
02050   /// or a specialization, for example).
02051   FunctionDecl *getTemplateInstantiationPattern() const;
02052 
02053   /// \brief Retrieve the primary template that this function template
02054   /// specialization either specializes or was instantiated from.
02055   ///
02056   /// If this function declaration is not a function template specialization,
02057   /// returns NULL.
02058   FunctionTemplateDecl *getPrimaryTemplate() const;
02059 
02060   /// \brief Retrieve the template arguments used to produce this function
02061   /// template specialization from the primary template.
02062   ///
02063   /// If this function declaration is not a function template specialization,
02064   /// returns NULL.
02065   const TemplateArgumentList *getTemplateSpecializationArgs() const;
02066 
02067   /// \brief Retrieve the template argument list as written in the sources,
02068   /// if any.
02069   ///
02070   /// If this function declaration is not a function template specialization
02071   /// or if it had no explicit template argument list, returns NULL.
02072   /// Note that it an explicit template argument list may be written empty,
02073   /// e.g., template<> void foo<>(char* s);
02074   const ASTTemplateArgumentListInfo*
02075   getTemplateSpecializationArgsAsWritten() const;
02076 
02077   /// \brief Specify that this function declaration is actually a function
02078   /// template specialization.
02079   ///
02080   /// \param Template the function template that this function template
02081   /// specialization specializes.
02082   ///
02083   /// \param TemplateArgs the template arguments that produced this
02084   /// function template specialization from the template.
02085   ///
02086   /// \param InsertPos If non-NULL, the position in the function template
02087   /// specialization set where the function template specialization data will
02088   /// be inserted.
02089   ///
02090   /// \param TSK the kind of template specialization this is.
02091   ///
02092   /// \param TemplateArgsAsWritten location info of template arguments.
02093   ///
02094   /// \param PointOfInstantiation point at which the function template
02095   /// specialization was first instantiated.
02096   void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
02097                 const TemplateArgumentList *TemplateArgs,
02098                 void *InsertPos,
02099                 TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
02100                 const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
02101                 SourceLocation PointOfInstantiation = SourceLocation()) {
02102     setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
02103                                       InsertPos, TSK, TemplateArgsAsWritten,
02104                                       PointOfInstantiation);
02105   }
02106 
02107   /// \brief Specifies that this function declaration is actually a
02108   /// dependent function template specialization.
02109   void setDependentTemplateSpecialization(ASTContext &Context,
02110                              const UnresolvedSetImpl &Templates,
02111                       const TemplateArgumentListInfo &TemplateArgs);
02112 
02113   DependentFunctionTemplateSpecializationInfo *
02114   getDependentSpecializationInfo() const {
02115     return TemplateOrSpecialization.
02116              dyn_cast<DependentFunctionTemplateSpecializationInfo*>();
02117   }
02118 
02119   /// \brief Determine what kind of template instantiation this function
02120   /// represents.
02121   TemplateSpecializationKind getTemplateSpecializationKind() const;
02122 
02123   /// \brief Determine what kind of template instantiation this function
02124   /// represents.
02125   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
02126                         SourceLocation PointOfInstantiation = SourceLocation());
02127 
02128   /// \brief Retrieve the (first) point of instantiation of a function template
02129   /// specialization or a member of a class template specialization.
02130   ///
02131   /// \returns the first point of instantiation, if this function was
02132   /// instantiated from a template; otherwise, returns an invalid source
02133   /// location.
02134   SourceLocation getPointOfInstantiation() const;
02135 
02136   /// \brief Determine whether this is or was instantiated from an out-of-line
02137   /// definition of a member function.
02138   bool isOutOfLine() const override;
02139 
02140   /// \brief Identify a memory copying or setting function.
02141   /// If the given function is a memory copy or setting function, returns
02142   /// the corresponding Builtin ID. If the function is not a memory function,
02143   /// returns 0.
02144   unsigned getMemoryFunctionKind() const;
02145 
02146   // Implement isa/cast/dyncast/etc.
02147   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02148   static bool classofKind(Kind K) {
02149     return K >= firstFunction && K <= lastFunction;
02150   }
02151   static DeclContext *castToDeclContext(const FunctionDecl *D) {
02152     return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
02153   }
02154   static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
02155     return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
02156   }
02157 
02158   friend class ASTDeclReader;
02159   friend class ASTDeclWriter;
02160 };
02161 
02162 
02163 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
02164 /// represent a member of a struct/union/class.
02165 class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
02166   // FIXME: This can be packed into the bitfields in Decl.
02167   bool Mutable : 1;
02168   mutable unsigned CachedFieldIndex : 31;
02169 
02170   /// The kinds of value we can store in InitializerOrBitWidth.
02171   ///
02172   /// Note that this is compatible with InClassInitStyle except for
02173   /// ISK_CapturedVLAType.
02174   enum InitStorageKind {
02175     /// If the pointer is null, there's nothing special.  Otherwise,
02176     /// this is a bitfield and the pointer is the Expr* storing the
02177     /// bit-width.
02178     ISK_BitWidthOrNothing = (unsigned) ICIS_NoInit,
02179 
02180     /// The pointer is an (optional due to delayed parsing) Expr*
02181     /// holding the copy-initializer.
02182     ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
02183 
02184     /// The pointer is an (optional due to delayed parsing) Expr*
02185     /// holding the list-initializer.
02186     ISK_InClassListInit = (unsigned) ICIS_ListInit,
02187 
02188     /// The pointer is a VariableArrayType* that's been captured;
02189     /// the enclosing context is a lambda or captured statement.
02190     ISK_CapturedVLAType,
02191   };
02192 
02193   /// \brief Storage for either the bit-width, the in-class
02194   /// initializer, or the captured variable length array bound.
02195   ///
02196   /// We can safely combine these because in-class initializers are
02197   /// not permitted for bit-fields, and both are exclusive with VLA
02198   /// captures.
02199   ///
02200   /// If the storage kind is ISK_InClassCopyInit or
02201   /// ISK_InClassListInit, but the initializer is null, then this
02202   /// field has an in-class initializer which has not yet been parsed
02203   /// and attached.
02204   llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
02205 protected:
02206   FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
02207             SourceLocation IdLoc, IdentifierInfo *Id,
02208             QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
02209             InClassInitStyle InitStyle)
02210     : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
02211       Mutable(Mutable), CachedFieldIndex(0),
02212       InitStorage(BW, (InitStorageKind) InitStyle) {
02213     assert((!BW || InitStyle == ICIS_NoInit) && "got initializer for bitfield");
02214   }
02215 
02216 public:
02217   static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
02218                            SourceLocation StartLoc, SourceLocation IdLoc,
02219                            IdentifierInfo *Id, QualType T,
02220                            TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
02221                            InClassInitStyle InitStyle);
02222 
02223   static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02224   
02225   /// getFieldIndex - Returns the index of this field within its record,
02226   /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
02227   unsigned getFieldIndex() const;
02228 
02229   /// isMutable - Determines whether this field is mutable (C++ only).
02230   bool isMutable() const { return Mutable; }
02231 
02232   /// \brief Determines whether this field is a bitfield.
02233   bool isBitField() const {
02234     return InitStorage.getInt() == ISK_BitWidthOrNothing &&
02235            InitStorage.getPointer() != nullptr;
02236   }
02237 
02238   /// @brief Determines whether this is an unnamed bitfield.
02239   bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
02240 
02241   /// isAnonymousStructOrUnion - Determines whether this field is a
02242   /// representative for an anonymous struct or union. Such fields are
02243   /// unnamed and are implicitly generated by the implementation to
02244   /// store the data for the anonymous union or struct.
02245   bool isAnonymousStructOrUnion() const;
02246 
02247   Expr *getBitWidth() const {
02248     return isBitField()
02249                ? static_cast<Expr *>(InitStorage.getPointer())
02250                : nullptr;
02251   }
02252   unsigned getBitWidthValue(const ASTContext &Ctx) const;
02253 
02254   /// setBitWidth - Set the bit-field width for this member.
02255   // Note: used by some clients (i.e., do not remove it).
02256   void setBitWidth(Expr *Width) {
02257     assert(InitStorage.getInt() == ISK_BitWidthOrNothing &&
02258            InitStorage.getPointer() == nullptr &&
02259            "bit width, initializer or captured type already set");
02260     InitStorage.setPointerAndInt(Width, ISK_BitWidthOrNothing);
02261   }
02262 
02263   /// removeBitWidth - Remove the bit-field width from this member.
02264   // Note: used by some clients (i.e., do not remove it).
02265   void removeBitWidth() {
02266     assert(isBitField() && "no bitfield width to remove");
02267     InitStorage.setPointerAndInt(nullptr, ISK_BitWidthOrNothing);
02268   }
02269 
02270   /// getInClassInitStyle - Get the kind of (C++11) in-class initializer which
02271   /// this field has.
02272   InClassInitStyle getInClassInitStyle() const {
02273     InitStorageKind storageKind = InitStorage.getInt();
02274     return (storageKind == ISK_CapturedVLAType
02275               ? ICIS_NoInit : (InClassInitStyle) storageKind);
02276   }
02277 
02278   /// hasInClassInitializer - Determine whether this member has a C++11 in-class
02279   /// initializer.
02280   bool hasInClassInitializer() const {
02281     return getInClassInitStyle() != ICIS_NoInit;
02282   }
02283 
02284   /// getInClassInitializer - Get the C++11 in-class initializer for this
02285   /// member, or null if one has not been set. If a valid declaration has an
02286   /// in-class initializer, but this returns null, then we have not parsed and
02287   /// attached it yet.
02288   Expr *getInClassInitializer() const {
02289     return hasInClassInitializer()
02290                ? static_cast<Expr *>(InitStorage.getPointer())
02291                : nullptr;
02292   }
02293 
02294   /// setInClassInitializer - Set the C++11 in-class initializer for this
02295   /// member.
02296   void setInClassInitializer(Expr *Init) {
02297     assert(hasInClassInitializer() &&
02298            InitStorage.getPointer() == nullptr &&
02299            "bit width, initializer or captured type already set");
02300     InitStorage.setPointer(Init);
02301   }
02302 
02303   /// removeInClassInitializer - Remove the C++11 in-class initializer from this
02304   /// member.
02305   void removeInClassInitializer() {
02306     assert(hasInClassInitializer() && "no initializer to remove");
02307     InitStorage.setPointerAndInt(nullptr, ISK_BitWidthOrNothing);
02308   }
02309 
02310   /// \brief Determine whether this member captures the variable length array
02311   /// type.
02312   bool hasCapturedVLAType() const {
02313     return InitStorage.getInt() == ISK_CapturedVLAType;
02314   }
02315 
02316   /// \brief Get the captured variable length array type.
02317   const VariableArrayType *getCapturedVLAType() const {
02318     return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
02319                                       InitStorage.getPointer())
02320                                 : nullptr;
02321   }
02322   /// \brief Set the captured variable length array type for this field.
02323   void setCapturedVLAType(const VariableArrayType *VLAType);
02324 
02325   /// getParent - Returns the parent of this field declaration, which
02326   /// is the struct in which this method is defined.
02327   const RecordDecl *getParent() const {
02328     return cast<RecordDecl>(getDeclContext());
02329   }
02330 
02331   RecordDecl *getParent() {
02332     return cast<RecordDecl>(getDeclContext());
02333   }
02334 
02335   SourceRange getSourceRange() const override LLVM_READONLY;
02336 
02337   /// Retrieves the canonical declaration of this field.
02338   FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
02339   const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
02340 
02341   // Implement isa/cast/dyncast/etc.
02342   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02343   static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
02344 
02345   friend class ASTDeclReader;
02346   friend class ASTDeclWriter;
02347 };
02348 
02349 /// EnumConstantDecl - An instance of this object exists for each enum constant
02350 /// that is defined.  For example, in "enum X {a,b}", each of a/b are
02351 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
02352 /// TagType for the X EnumDecl.
02353 class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
02354   Stmt *Init; // an integer constant expression
02355   llvm::APSInt Val; // The value.
02356 protected:
02357   EnumConstantDecl(DeclContext *DC, SourceLocation L,
02358                    IdentifierInfo *Id, QualType T, Expr *E,
02359                    const llvm::APSInt &V)
02360     : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
02361 
02362 public:
02363 
02364   static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
02365                                   SourceLocation L, IdentifierInfo *Id,
02366                                   QualType T, Expr *E,
02367                                   const llvm::APSInt &V);
02368   static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02369   
02370   const Expr *getInitExpr() const { return (const Expr*) Init; }
02371   Expr *getInitExpr() { return (Expr*) Init; }
02372   const llvm::APSInt &getInitVal() const { return Val; }
02373 
02374   void setInitExpr(Expr *E) { Init = (Stmt*) E; }
02375   void setInitVal(const llvm::APSInt &V) { Val = V; }
02376 
02377   SourceRange getSourceRange() const override LLVM_READONLY;
02378 
02379   /// Retrieves the canonical declaration of this enumerator.
02380   EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); }
02381   const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
02382 
02383   // Implement isa/cast/dyncast/etc.
02384   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02385   static bool classofKind(Kind K) { return K == EnumConstant; }
02386 
02387   friend class StmtIteratorBase;
02388 };
02389 
02390 /// IndirectFieldDecl - An instance of this class is created to represent a
02391 /// field injected from an anonymous union/struct into the parent scope.
02392 /// IndirectFieldDecl are always implicit.
02393 class IndirectFieldDecl : public ValueDecl {
02394   void anchor() override;
02395   NamedDecl **Chaining;
02396   unsigned ChainingSize;
02397 
02398   IndirectFieldDecl(DeclContext *DC, SourceLocation L,
02399                     DeclarationName N, QualType T,
02400                     NamedDecl **CH, unsigned CHS)
02401     : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH), ChainingSize(CHS) {}
02402 
02403 public:
02404   static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
02405                                    SourceLocation L, IdentifierInfo *Id,
02406                                    QualType T, NamedDecl **CH, unsigned CHS);
02407 
02408   static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02409   
02410   typedef NamedDecl * const *chain_iterator;
02411   typedef llvm::iterator_range<chain_iterator> chain_range;
02412 
02413   chain_range chain() const { return chain_range(chain_begin(), chain_end()); }
02414   chain_iterator chain_begin() const { return chain_iterator(Chaining); }
02415   chain_iterator chain_end() const {
02416     return chain_iterator(Chaining + ChainingSize);
02417   }
02418 
02419   unsigned getChainingSize() const { return ChainingSize; }
02420 
02421   FieldDecl *getAnonField() const {
02422     assert(ChainingSize >= 2);
02423     return cast<FieldDecl>(Chaining[ChainingSize - 1]);
02424   }
02425 
02426   VarDecl *getVarDecl() const {
02427     assert(ChainingSize >= 2);
02428     return dyn_cast<VarDecl>(*chain_begin());
02429   }
02430 
02431   // Implement isa/cast/dyncast/etc.
02432   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02433   static bool classofKind(Kind K) { return K == IndirectField; }
02434   friend class ASTDeclReader;
02435 };
02436 
02437 /// TypeDecl - Represents a declaration of a type.
02438 ///
02439 class TypeDecl : public NamedDecl {
02440   void anchor() override;
02441   /// TypeForDecl - This indicates the Type object that represents
02442   /// this TypeDecl.  It is a cache maintained by
02443   /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
02444   /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
02445   mutable const Type *TypeForDecl;
02446   /// LocStart - The start of the source range for this declaration.
02447   SourceLocation LocStart;
02448   friend class ASTContext;
02449 
02450 protected:
02451   TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
02452            SourceLocation StartL = SourceLocation())
02453     : NamedDecl(DK, DC, L, Id), TypeForDecl(nullptr), LocStart(StartL) {}
02454 
02455 public:
02456   // Low-level accessor. If you just want the type defined by this node,
02457   // check out ASTContext::getTypeDeclType or one of
02458   // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
02459   // already know the specific kind of node this is.
02460   const Type *getTypeForDecl() const { return TypeForDecl; }
02461   void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
02462 
02463   SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
02464   void setLocStart(SourceLocation L) { LocStart = L; }
02465   SourceRange getSourceRange() const override LLVM_READONLY {
02466     if (LocStart.isValid())
02467       return SourceRange(LocStart, getLocation());
02468     else
02469       return SourceRange(getLocation());
02470   }
02471 
02472   // Implement isa/cast/dyncast/etc.
02473   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02474   static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
02475 };
02476 
02477 
02478 /// Base class for declarations which introduce a typedef-name.
02479 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
02480   void anchor() override;
02481   typedef std::pair<TypeSourceInfo*, QualType> ModedTInfo;
02482   llvm::PointerUnion<TypeSourceInfo*, ModedTInfo*> MaybeModedTInfo;
02483 
02484 protected:
02485   TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
02486                   SourceLocation StartLoc, SourceLocation IdLoc,
02487                   IdentifierInfo *Id, TypeSourceInfo *TInfo)
02488       : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
02489         MaybeModedTInfo(TInfo) {}
02490 
02491   typedef Redeclarable<TypedefNameDecl> redeclarable_base;
02492   TypedefNameDecl *getNextRedeclarationImpl() override {
02493     return getNextRedeclaration();
02494   }
02495   TypedefNameDecl *getPreviousDeclImpl() override {
02496     return getPreviousDecl();
02497   }
02498   TypedefNameDecl *getMostRecentDeclImpl() override {
02499     return getMostRecentDecl();
02500   }
02501 
02502 public:
02503   typedef redeclarable_base::redecl_range redecl_range;
02504   typedef redeclarable_base::redecl_iterator redecl_iterator;
02505   using redeclarable_base::redecls_begin;
02506   using redeclarable_base::redecls_end;
02507   using redeclarable_base::redecls;
02508   using redeclarable_base::getPreviousDecl;
02509   using redeclarable_base::getMostRecentDecl;
02510   using redeclarable_base::isFirstDecl;
02511 
02512   bool isModed() const { return MaybeModedTInfo.is<ModedTInfo*>(); }
02513 
02514   TypeSourceInfo *getTypeSourceInfo() const {
02515     return isModed()
02516       ? MaybeModedTInfo.get<ModedTInfo*>()->first
02517       : MaybeModedTInfo.get<TypeSourceInfo*>();
02518   }
02519   QualType getUnderlyingType() const {
02520     return isModed()
02521       ? MaybeModedTInfo.get<ModedTInfo*>()->second
02522       : MaybeModedTInfo.get<TypeSourceInfo*>()->getType();
02523   }
02524   void setTypeSourceInfo(TypeSourceInfo *newType) {
02525     MaybeModedTInfo = newType;
02526   }
02527   void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
02528     MaybeModedTInfo = new (getASTContext()) ModedTInfo(unmodedTSI, modedTy);
02529   }
02530 
02531   /// Retrieves the canonical declaration of this typedef-name.
02532   TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); }
02533   const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
02534 
02535   // Implement isa/cast/dyncast/etc.
02536   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02537   static bool classofKind(Kind K) {
02538     return K >= firstTypedefName && K <= lastTypedefName;
02539   }
02540 };
02541 
02542 /// TypedefDecl - Represents the declaration of a typedef-name via the 'typedef'
02543 /// type specifier.
02544 class TypedefDecl : public TypedefNameDecl {
02545   TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
02546               SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
02547       : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
02548 
02549 public:
02550   static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
02551                              SourceLocation StartLoc, SourceLocation IdLoc,
02552                              IdentifierInfo *Id, TypeSourceInfo *TInfo);
02553   static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02554 
02555   SourceRange getSourceRange() const override LLVM_READONLY;
02556 
02557   // Implement isa/cast/dyncast/etc.
02558   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02559   static bool classofKind(Kind K) { return K == Typedef; }
02560 };
02561 
02562 /// TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x
02563 /// alias-declaration.
02564 class TypeAliasDecl : public TypedefNameDecl {
02565   /// The template for which this is the pattern, if any.
02566   TypeAliasTemplateDecl *Template;
02567 
02568   TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
02569                 SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
02570       : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
02571         Template(nullptr) {}
02572 
02573 public:
02574   static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
02575                                SourceLocation StartLoc, SourceLocation IdLoc,
02576                                IdentifierInfo *Id, TypeSourceInfo *TInfo);
02577   static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02578 
02579   SourceRange getSourceRange() const override LLVM_READONLY;
02580 
02581   TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
02582   void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
02583 
02584   // Implement isa/cast/dyncast/etc.
02585   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02586   static bool classofKind(Kind K) { return K == TypeAlias; }
02587 };
02588 
02589 /// TagDecl - Represents the declaration of a struct/union/class/enum.
02590 class TagDecl
02591   : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
02592 public:
02593   // This is really ugly.
02594   typedef TagTypeKind TagKind;
02595 
02596 private:
02597   // FIXME: This can be packed into the bitfields in Decl.
02598   /// TagDeclKind - The TagKind enum.
02599   unsigned TagDeclKind : 3;
02600 
02601   /// IsCompleteDefinition - True if this is a definition ("struct foo
02602   /// {};"), false if it is a declaration ("struct foo;").  It is not
02603   /// a definition until the definition has been fully processed.
02604   bool IsCompleteDefinition : 1;
02605 
02606 protected:
02607   /// IsBeingDefined - True if this is currently being defined.
02608   bool IsBeingDefined : 1;
02609 
02610 private:
02611   /// IsEmbeddedInDeclarator - True if this tag declaration is
02612   /// "embedded" (i.e., defined or declared for the very first time)
02613   /// in the syntax of a declarator.
02614   bool IsEmbeddedInDeclarator : 1;
02615 
02616   /// \brief True if this tag is free standing, e.g. "struct foo;".
02617   bool IsFreeStanding : 1;
02618 
02619 protected:
02620   // These are used by (and only defined for) EnumDecl.
02621   unsigned NumPositiveBits : 8;
02622   unsigned NumNegativeBits : 8;
02623 
02624   /// IsScoped - True if this tag declaration is a scoped enumeration. Only
02625   /// possible in C++11 mode.
02626   bool IsScoped : 1;
02627   /// IsScopedUsingClassTag - If this tag declaration is a scoped enum,
02628   /// then this is true if the scoped enum was declared using the class
02629   /// tag, false if it was declared with the struct tag. No meaning is
02630   /// associated if this tag declaration is not a scoped enum.
02631   bool IsScopedUsingClassTag : 1;
02632 
02633   /// IsFixed - True if this is an enumeration with fixed underlying type. Only
02634   /// possible in C++11, Microsoft extensions, or Objective C mode.
02635   bool IsFixed : 1;
02636 
02637   /// \brief Indicates whether it is possible for declarations of this kind
02638   /// to have an out-of-date definition.
02639   ///
02640   /// This option is only enabled when modules are enabled.
02641   bool MayHaveOutOfDateDef : 1;
02642 
02643   /// Has the full definition of this type been required by a use somewhere in
02644   /// the TU.
02645   bool IsCompleteDefinitionRequired : 1;
02646 private:
02647   SourceLocation RBraceLoc;
02648 
02649   // A struct representing syntactic qualifier info,
02650   // to be used for the (uncommon) case of out-of-line declarations.
02651   typedef QualifierInfo ExtInfo;
02652 
02653   /// \brief If the (out-of-line) tag declaration name
02654   /// is qualified, it points to the qualifier info (nns and range);
02655   /// otherwise, if the tag declaration is anonymous and it is part of
02656   /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
02657   /// otherwise, if the tag declaration is anonymous and it is used as a
02658   /// declaration specifier for variables, it points to the first VarDecl (used
02659   /// for mangling);
02660   /// otherwise, it is a null (TypedefNameDecl) pointer.
02661   llvm::PointerUnion<NamedDecl *, ExtInfo *> NamedDeclOrQualifier;
02662 
02663   bool hasExtInfo() const { return NamedDeclOrQualifier.is<ExtInfo *>(); }
02664   ExtInfo *getExtInfo() { return NamedDeclOrQualifier.get<ExtInfo *>(); }
02665   const ExtInfo *getExtInfo() const {
02666     return NamedDeclOrQualifier.get<ExtInfo *>();
02667   }
02668 
02669 protected:
02670   TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
02671           SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
02672           SourceLocation StartL)
02673       : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
02674         TagDeclKind(TK), IsCompleteDefinition(false), IsBeingDefined(false),
02675         IsEmbeddedInDeclarator(false), IsFreeStanding(false),
02676         IsCompleteDefinitionRequired(false),
02677         NamedDeclOrQualifier((NamedDecl *)nullptr) {
02678     assert((DK != Enum || TK == TTK_Enum) &&
02679            "EnumDecl not matched with TTK_Enum");
02680     setPreviousDecl(PrevDecl);
02681   }
02682 
02683   typedef Redeclarable<TagDecl> redeclarable_base;
02684   TagDecl *getNextRedeclarationImpl() override {
02685     return getNextRedeclaration();
02686   }
02687   TagDecl *getPreviousDeclImpl() override {
02688     return getPreviousDecl();
02689   }
02690   TagDecl *getMostRecentDeclImpl() override {
02691     return getMostRecentDecl();
02692   }
02693 
02694   /// @brief Completes the definition of this tag declaration.
02695   ///
02696   /// This is a helper function for derived classes.
02697   void completeDefinition();
02698 
02699 public:
02700   typedef redeclarable_base::redecl_range redecl_range;
02701   typedef redeclarable_base::redecl_iterator redecl_iterator;
02702   using redeclarable_base::redecls_begin;
02703   using redeclarable_base::redecls_end;
02704   using redeclarable_base::redecls;
02705   using redeclarable_base::getPreviousDecl;
02706   using redeclarable_base::getMostRecentDecl;
02707   using redeclarable_base::isFirstDecl;
02708 
02709   SourceLocation getRBraceLoc() const { return RBraceLoc; }
02710   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
02711 
02712   /// getInnerLocStart - Return SourceLocation representing start of source
02713   /// range ignoring outer template declarations.
02714   SourceLocation getInnerLocStart() const { return getLocStart(); }
02715 
02716   /// getOuterLocStart - Return SourceLocation representing start of source
02717   /// range taking into account any outer template declarations.
02718   SourceLocation getOuterLocStart() const;
02719   SourceRange getSourceRange() const override LLVM_READONLY;
02720 
02721   TagDecl *getCanonicalDecl() override;
02722   const TagDecl *getCanonicalDecl() const {
02723     return const_cast<TagDecl*>(this)->getCanonicalDecl();
02724   }
02725 
02726   /// isThisDeclarationADefinition() - Return true if this declaration
02727   /// is a completion definition of the type.  Provided for consistency.
02728   bool isThisDeclarationADefinition() const {
02729     return isCompleteDefinition();
02730   }
02731 
02732   /// isCompleteDefinition - Return true if this decl has its body
02733   /// fully specified.
02734   bool isCompleteDefinition() const {
02735     return IsCompleteDefinition;
02736   }
02737 
02738   /// \brief Return true if this complete decl is
02739   /// required to be complete for some existing use.
02740   bool isCompleteDefinitionRequired() const {
02741     return IsCompleteDefinitionRequired;
02742   }
02743 
02744   /// isBeingDefined - Return true if this decl is currently being defined.
02745   bool isBeingDefined() const {
02746     return IsBeingDefined;
02747   }
02748 
02749   bool isEmbeddedInDeclarator() const {
02750     return IsEmbeddedInDeclarator;
02751   }
02752   void setEmbeddedInDeclarator(bool isInDeclarator) {
02753     IsEmbeddedInDeclarator = isInDeclarator;
02754   }
02755 
02756   bool isFreeStanding() const { return IsFreeStanding; }
02757   void setFreeStanding(bool isFreeStanding = true) {
02758     IsFreeStanding = isFreeStanding;
02759   }
02760 
02761   /// \brief Whether this declaration declares a type that is
02762   /// dependent, i.e., a type that somehow depends on template
02763   /// parameters.
02764   bool isDependentType() const { return isDependentContext(); }
02765 
02766   /// @brief Starts the definition of this tag declaration.
02767   ///
02768   /// This method should be invoked at the beginning of the definition
02769   /// of this tag declaration. It will set the tag type into a state
02770   /// where it is in the process of being defined.
02771   void startDefinition();
02772 
02773   /// getDefinition - Returns the TagDecl that actually defines this
02774   ///  struct/union/class/enum.  When determining whether or not a
02775   ///  struct/union/class/enum has a definition, one should use this
02776   ///  method as opposed to 'isDefinition'.  'isDefinition' indicates
02777   ///  whether or not a specific TagDecl is defining declaration, not
02778   ///  whether or not the struct/union/class/enum type is defined.
02779   ///  This method returns NULL if there is no TagDecl that defines
02780   ///  the struct/union/class/enum.
02781   TagDecl *getDefinition() const;
02782 
02783   void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
02784 
02785   void setCompleteDefinitionRequired(bool V = true) {
02786     IsCompleteDefinitionRequired = V;
02787   }
02788 
02789   StringRef getKindName() const {
02790     return TypeWithKeyword::getTagTypeKindName(getTagKind());
02791   }
02792 
02793   TagKind getTagKind() const {
02794     return TagKind(TagDeclKind);
02795   }
02796 
02797   void setTagKind(TagKind TK) { TagDeclKind = TK; }
02798 
02799   bool isStruct() const { return getTagKind() == TTK_Struct; }
02800   bool isInterface() const { return getTagKind() == TTK_Interface; }
02801   bool isClass()  const { return getTagKind() == TTK_Class; }
02802   bool isUnion()  const { return getTagKind() == TTK_Union; }
02803   bool isEnum()   const { return getTagKind() == TTK_Enum; }
02804 
02805   /// Is this tag type named, either directly or via being defined in
02806   /// a typedef of this type?
02807   ///
02808   /// C++11 [basic.link]p8:
02809   ///   A type is said to have linkage if and only if:
02810   ///     - it is a class or enumeration type that is named (or has a
02811   ///       name for linkage purposes) and the name has linkage; ...
02812   /// C++11 [dcl.typedef]p9:
02813   ///   If the typedef declaration defines an unnamed class (or enum),
02814   ///   the first typedef-name declared by the declaration to be that
02815   ///   class type (or enum type) is used to denote the class type (or
02816   ///   enum type) for linkage purposes only.
02817   ///
02818   /// C does not have an analogous rule, but the same concept is
02819   /// nonetheless useful in some places.
02820   bool hasNameForLinkage() const {
02821     return (getDeclName() || getTypedefNameForAnonDecl());
02822   }
02823 
02824   bool hasDeclaratorForAnonDecl() const {
02825     return dyn_cast_or_null<DeclaratorDecl>(
02826         NamedDeclOrQualifier.get<NamedDecl *>());
02827   }
02828   DeclaratorDecl *getDeclaratorForAnonDecl() const {
02829     return hasExtInfo() ? nullptr : dyn_cast_or_null<DeclaratorDecl>(
02830                                   NamedDeclOrQualifier.get<NamedDecl *>());
02831   }
02832 
02833   TypedefNameDecl *getTypedefNameForAnonDecl() const {
02834     return hasExtInfo() ? nullptr : dyn_cast_or_null<TypedefNameDecl>(
02835                                   NamedDeclOrQualifier.get<NamedDecl *>());
02836   }
02837 
02838   void setDeclaratorForAnonDecl(DeclaratorDecl *DD) { NamedDeclOrQualifier = DD; }
02839 
02840   void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
02841 
02842   /// \brief Retrieve the nested-name-specifier that qualifies the name of this
02843   /// declaration, if it was present in the source.
02844   NestedNameSpecifier *getQualifier() const {
02845     return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
02846                         : nullptr;
02847   }
02848 
02849   /// \brief Retrieve the nested-name-specifier (with source-location
02850   /// information) that qualifies the name of this declaration, if it was
02851   /// present in the source.
02852   NestedNameSpecifierLoc getQualifierLoc() const {
02853     return hasExtInfo() ? getExtInfo()->QualifierLoc
02854                         : NestedNameSpecifierLoc();
02855   }
02856 
02857   void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
02858 
02859   unsigned getNumTemplateParameterLists() const {
02860     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
02861   }
02862   TemplateParameterList *getTemplateParameterList(unsigned i) const {
02863     assert(i < getNumTemplateParameterLists());
02864     return getExtInfo()->TemplParamLists[i];
02865   }
02866   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
02867                                      TemplateParameterList **TPLists);
02868 
02869   // Implement isa/cast/dyncast/etc.
02870   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02871   static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
02872 
02873   static DeclContext *castToDeclContext(const TagDecl *D) {
02874     return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
02875   }
02876   static TagDecl *castFromDeclContext(const DeclContext *DC) {
02877     return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
02878   }
02879 
02880   friend class ASTDeclReader;
02881   friend class ASTDeclWriter;
02882 };
02883 
02884 /// EnumDecl - Represents an enum.  In C++11, enums can be forward-declared
02885 /// with a fixed underlying type, and in C we allow them to be forward-declared
02886 /// with no underlying type as an extension.
02887 class EnumDecl : public TagDecl {
02888   void anchor() override;
02889   /// IntegerType - This represent the integer type that the enum corresponds
02890   /// to for code generation purposes.  Note that the enumerator constants may
02891   /// have a different type than this does.
02892   ///
02893   /// If the underlying integer type was explicitly stated in the source
02894   /// code, this is a TypeSourceInfo* for that type. Otherwise this type
02895   /// was automatically deduced somehow, and this is a Type*.
02896   ///
02897   /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
02898   /// some cases it won't.
02899   ///
02900   /// The underlying type of an enumeration never has any qualifiers, so
02901   /// we can get away with just storing a raw Type*, and thus save an
02902   /// extra pointer when TypeSourceInfo is needed.
02903 
02904   llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType;
02905 
02906   /// PromotionType - The integer type that values of this type should
02907   /// promote to.  In C, enumerators are generally of an integer type
02908   /// directly, but gcc-style large enumerators (and all enumerators
02909   /// in C++) are of the enum type instead.
02910   QualType PromotionType;
02911 
02912   /// \brief If this enumeration is an instantiation of a member enumeration
02913   /// of a class template specialization, this is the member specialization
02914   /// information.
02915   MemberSpecializationInfo *SpecializationInfo;
02916 
02917   EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
02918            SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
02919            bool Scoped, bool ScopedUsingClassTag, bool Fixed)
02920       : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc),
02921         SpecializationInfo(nullptr) {
02922     assert(Scoped || !ScopedUsingClassTag);
02923     IntegerType = (const Type *)nullptr;
02924     NumNegativeBits = 0;
02925     NumPositiveBits = 0;
02926     IsScoped = Scoped;
02927     IsScopedUsingClassTag = ScopedUsingClassTag;
02928     IsFixed = Fixed;
02929   }
02930 
02931   void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
02932                                     TemplateSpecializationKind TSK);
02933 public:
02934   EnumDecl *getCanonicalDecl() override {
02935     return cast<EnumDecl>(TagDecl::getCanonicalDecl());
02936   }
02937   const EnumDecl *getCanonicalDecl() const {
02938     return const_cast<EnumDecl*>(this)->getCanonicalDecl();
02939   }
02940 
02941   EnumDecl *getPreviousDecl() {
02942     return cast_or_null<EnumDecl>(
02943             static_cast<TagDecl *>(this)->getPreviousDecl());
02944   }
02945   const EnumDecl *getPreviousDecl() const {
02946     return const_cast<EnumDecl*>(this)->getPreviousDecl();
02947   }
02948 
02949   EnumDecl *getMostRecentDecl() {
02950     return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
02951   }
02952   const EnumDecl *getMostRecentDecl() const {
02953     return const_cast<EnumDecl*>(this)->getMostRecentDecl();
02954   }
02955 
02956   EnumDecl *getDefinition() const {
02957     return cast_or_null<EnumDecl>(TagDecl::getDefinition());
02958   }
02959 
02960   static EnumDecl *Create(ASTContext &C, DeclContext *DC,
02961                           SourceLocation StartLoc, SourceLocation IdLoc,
02962                           IdentifierInfo *Id, EnumDecl *PrevDecl,
02963                           bool IsScoped, bool IsScopedUsingClassTag,
02964                           bool IsFixed);
02965   static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02966 
02967   /// completeDefinition - When created, the EnumDecl corresponds to a
02968   /// forward-declared enum. This method is used to mark the
02969   /// declaration as being defined; it's enumerators have already been
02970   /// added (via DeclContext::addDecl). NewType is the new underlying
02971   /// type of the enumeration type.
02972   void completeDefinition(QualType NewType,
02973                           QualType PromotionType,
02974                           unsigned NumPositiveBits,
02975                           unsigned NumNegativeBits);
02976 
02977   // enumerator_iterator - Iterates through the enumerators of this
02978   // enumeration.
02979   typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
02980   typedef llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>
02981     enumerator_range;
02982 
02983   enumerator_range enumerators() const {
02984     return enumerator_range(enumerator_begin(), enumerator_end());
02985   }
02986 
02987   enumerator_iterator enumerator_begin() const {
02988     const EnumDecl *E = getDefinition();
02989     if (!E)
02990       E = this;
02991     return enumerator_iterator(E->decls_begin());
02992   }
02993 
02994   enumerator_iterator enumerator_end() const {
02995     const EnumDecl *E = getDefinition();
02996     if (!E)
02997       E = this;
02998     return enumerator_iterator(E->decls_end());
02999   }
03000 
03001   /// getPromotionType - Return the integer type that enumerators
03002   /// should promote to.
03003   QualType getPromotionType() const { return PromotionType; }
03004 
03005   /// \brief Set the promotion type.
03006   void setPromotionType(QualType T) { PromotionType = T; }
03007 
03008   /// getIntegerType - Return the integer type this enum decl corresponds to.
03009   /// This returns a null QualType for an enum forward definition with no fixed
03010   /// underlying type.
03011   QualType getIntegerType() const {
03012     if (!IntegerType)
03013       return QualType();
03014     if (const Type *T = IntegerType.dyn_cast<const Type*>())
03015       return QualType(T, 0);
03016     return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
03017   }
03018 
03019   /// \brief Set the underlying integer type.
03020   void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
03021 
03022   /// \brief Set the underlying integer type source info.
03023   void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
03024 
03025   /// \brief Return the type source info for the underlying integer type,
03026   /// if no type source info exists, return 0.
03027   TypeSourceInfo *getIntegerTypeSourceInfo() const {
03028     return IntegerType.dyn_cast<TypeSourceInfo*>();
03029   }
03030 
03031   /// \brief Retrieve the source range that covers the underlying type if
03032   /// specified.
03033   SourceRange getIntegerTypeRange() const LLVM_READONLY;
03034 
03035   /// \brief Returns the width in bits required to store all the
03036   /// non-negative enumerators of this enum.
03037   unsigned getNumPositiveBits() const {
03038     return NumPositiveBits;
03039   }
03040   void setNumPositiveBits(unsigned Num) {
03041     NumPositiveBits = Num;
03042     assert(NumPositiveBits == Num && "can't store this bitcount");
03043   }
03044 
03045   /// \brief Returns the width in bits required to store all the
03046   /// negative enumerators of this enum.  These widths include
03047   /// the rightmost leading 1;  that is:
03048   ///
03049   /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
03050   /// ------------------------     -------     -----------------
03051   ///                       -1     1111111                     1
03052   ///                      -10     1110110                     5
03053   ///                     -101     1001011                     8
03054   unsigned getNumNegativeBits() const {
03055     return NumNegativeBits;
03056   }
03057   void setNumNegativeBits(unsigned Num) {
03058     NumNegativeBits = Num;
03059   }
03060 
03061   /// \brief Returns true if this is a C++11 scoped enumeration.
03062   bool isScoped() const {
03063     return IsScoped;
03064   }
03065 
03066   /// \brief Returns true if this is a C++11 scoped enumeration.
03067   bool isScopedUsingClassTag() const {
03068     return IsScopedUsingClassTag;
03069   }
03070 
03071   /// \brief Returns true if this is an Objective-C, C++11, or
03072   /// Microsoft-style enumeration with a fixed underlying type.
03073   bool isFixed() const {
03074     return IsFixed;
03075   }
03076 
03077   /// \brief Returns true if this can be considered a complete type.
03078   bool isComplete() const {
03079     return isCompleteDefinition() || isFixed();
03080   }
03081 
03082   /// \brief Returns the enumeration (declared within the template)
03083   /// from which this enumeration type was instantiated, or NULL if
03084   /// this enumeration was not instantiated from any template.
03085   EnumDecl *getInstantiatedFromMemberEnum() const;
03086 
03087   /// \brief If this enumeration is a member of a specialization of a
03088   /// templated class, determine what kind of template specialization
03089   /// or instantiation this is.
03090   TemplateSpecializationKind getTemplateSpecializationKind() const;
03091 
03092   /// \brief For an enumeration member that was instantiated from a member
03093   /// enumeration of a templated class, set the template specialiation kind.
03094   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
03095                         SourceLocation PointOfInstantiation = SourceLocation());
03096 
03097   /// \brief If this enumeration is an instantiation of a member enumeration of
03098   /// a class template specialization, retrieves the member specialization
03099   /// information.
03100   MemberSpecializationInfo *getMemberSpecializationInfo() const {
03101     return SpecializationInfo;
03102   }
03103 
03104   /// \brief Specify that this enumeration is an instantiation of the
03105   /// member enumeration ED.
03106   void setInstantiationOfMemberEnum(EnumDecl *ED,
03107                                     TemplateSpecializationKind TSK) {
03108     setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
03109   }
03110 
03111   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03112   static bool classofKind(Kind K) { return K == Enum; }
03113 
03114   friend class ASTDeclReader;
03115 };
03116 
03117 
03118 /// RecordDecl - Represents a struct/union/class.  For example:
03119 ///   struct X;                  // Forward declaration, no "body".
03120 ///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
03121 /// This decl will be marked invalid if *any* members are invalid.
03122 ///
03123 class RecordDecl : public TagDecl {
03124   // FIXME: This can be packed into the bitfields in Decl.
03125   /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
03126   /// array member (e.g. int X[]) or if this union contains a struct that does.
03127   /// If so, this cannot be contained in arrays or other structs as a member.
03128   bool HasFlexibleArrayMember : 1;
03129 
03130   /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct
03131   /// or union.
03132   bool AnonymousStructOrUnion : 1;
03133 
03134   /// HasObjectMember - This is true if this struct has at least one member
03135   /// containing an Objective-C object pointer type.
03136   bool HasObjectMember : 1;
03137   
03138   /// HasVolatileMember - This is true if struct has at least one member of
03139   /// 'volatile' type.
03140   bool HasVolatileMember : 1;
03141 
03142   /// \brief Whether the field declarations of this record have been loaded
03143   /// from external storage. To avoid unnecessary deserialization of
03144   /// methods/nested types we allow deserialization of just the fields
03145   /// when needed.
03146   mutable bool LoadedFieldsFromExternalStorage : 1;
03147   friend class DeclContext;
03148 
03149 protected:
03150   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
03151              SourceLocation StartLoc, SourceLocation IdLoc,
03152              IdentifierInfo *Id, RecordDecl *PrevDecl);
03153 
03154 public:
03155   static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
03156                             SourceLocation StartLoc, SourceLocation IdLoc,
03157                             IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
03158   static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
03159 
03160   RecordDecl *getPreviousDecl() {
03161     return cast_or_null<RecordDecl>(
03162             static_cast<TagDecl *>(this)->getPreviousDecl());
03163   }
03164   const RecordDecl *getPreviousDecl() const {
03165     return const_cast<RecordDecl*>(this)->getPreviousDecl();
03166   }
03167 
03168   RecordDecl *getMostRecentDecl() {
03169     return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
03170   }
03171   const RecordDecl *getMostRecentDecl() const {
03172     return const_cast<RecordDecl*>(this)->getMostRecentDecl();
03173   }
03174 
03175   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
03176   void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
03177 
03178   /// isAnonymousStructOrUnion - Whether this is an anonymous struct
03179   /// or union. To be an anonymous struct or union, it must have been
03180   /// declared without a name and there must be no objects of this
03181   /// type declared, e.g.,
03182   /// @code
03183   ///   union { int i; float f; };
03184   /// @endcode
03185   /// is an anonymous union but neither of the following are:
03186   /// @code
03187   ///  union X { int i; float f; };
03188   ///  union { int i; float f; } obj;
03189   /// @endcode
03190   bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
03191   void setAnonymousStructOrUnion(bool Anon) {
03192     AnonymousStructOrUnion = Anon;
03193   }
03194 
03195   bool hasObjectMember() const { return HasObjectMember; }
03196   void setHasObjectMember (bool val) { HasObjectMember = val; }
03197 
03198   bool hasVolatileMember() const { return HasVolatileMember; }
03199   void setHasVolatileMember (bool val) { HasVolatileMember = val; }
03200   
03201   /// \brief Determines whether this declaration represents the
03202   /// injected class name.
03203   ///
03204   /// The injected class name in C++ is the name of the class that
03205   /// appears inside the class itself. For example:
03206   ///
03207   /// \code
03208   /// struct C {
03209   ///   // C is implicitly declared here as a synonym for the class name.
03210   /// };
03211   ///
03212   /// C::C c; // same as "C c;"
03213   /// \endcode
03214   bool isInjectedClassName() const;
03215 
03216   /// \brief Determine whether this record is a class describing a lambda
03217   /// function object.
03218   bool isLambda() const;
03219 
03220   /// \brief Determine whether this record is a record for captured variables in
03221   /// CapturedStmt construct.
03222   bool isCapturedRecord() const;
03223   /// \brief Mark the record as a record for captured variables in CapturedStmt
03224   /// construct.
03225   void setCapturedRecord();
03226 
03227   /// getDefinition - Returns the RecordDecl that actually defines
03228   ///  this struct/union/class.  When determining whether or not a
03229   ///  struct/union/class is completely defined, one should use this
03230   ///  method as opposed to 'isCompleteDefinition'.
03231   ///  'isCompleteDefinition' indicates whether or not a specific
03232   ///  RecordDecl is a completed definition, not whether or not the
03233   ///  record type is defined.  This method returns NULL if there is
03234   ///  no RecordDecl that defines the struct/union/tag.
03235   RecordDecl *getDefinition() const {
03236     return cast_or_null<RecordDecl>(TagDecl::getDefinition());
03237   }
03238 
03239   // Iterator access to field members. The field iterator only visits
03240   // the non-static data members of this class, ignoring any static
03241   // data members, functions, constructors, destructors, etc.
03242   typedef specific_decl_iterator<FieldDecl> field_iterator;
03243   typedef llvm::iterator_range<specific_decl_iterator<FieldDecl>> field_range;
03244 
03245   field_range fields() const { return field_range(field_begin(), field_end()); }
03246   field_iterator field_begin() const;
03247 
03248   field_iterator field_end() const {
03249     return field_iterator(decl_iterator());
03250   }
03251 
03252   // field_empty - Whether there are any fields (non-static data
03253   // members) in this record.
03254   bool field_empty() const {
03255     return field_begin() == field_end();
03256   }
03257 
03258   /// completeDefinition - Notes that the definition of this type is
03259   /// now complete.
03260   virtual void completeDefinition();
03261 
03262   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03263   static bool classofKind(Kind K) {
03264     return K >= firstRecord && K <= lastRecord;
03265   }
03266 
03267   /// isMsStrust - Get whether or not this is an ms_struct which can
03268   /// be turned on with an attribute, pragma, or -mms-bitfields
03269   /// commandline option.
03270   bool isMsStruct(const ASTContext &C) const;
03271 
03272   /// \brief Whether we are allowed to insert extra padding between fields.
03273   /// These padding are added to help AddressSanitizer detect
03274   /// intra-object-overflow bugs.
03275   bool mayInsertExtraPadding(bool EmitRemark = false) const;
03276 
03277 private:
03278   /// \brief Deserialize just the fields.
03279   void LoadFieldsFromExternalStorage() const;
03280 };
03281 
03282 class FileScopeAsmDecl : public Decl {
03283   virtual void anchor();
03284   StringLiteral *AsmString;
03285   SourceLocation RParenLoc;
03286   FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
03287                    SourceLocation StartL, SourceLocation EndL)
03288     : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
03289 public:
03290   static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
03291                                   StringLiteral *Str, SourceLocation AsmLoc,
03292                                   SourceLocation RParenLoc);
03293 
03294   static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03295   
03296   SourceLocation getAsmLoc() const { return getLocation(); }
03297   SourceLocation getRParenLoc() const { return RParenLoc; }
03298   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
03299   SourceRange getSourceRange() const override LLVM_READONLY {
03300     return SourceRange(getAsmLoc(), getRParenLoc());
03301   }
03302 
03303   const StringLiteral *getAsmString() const { return AsmString; }
03304   StringLiteral *getAsmString() { return AsmString; }
03305   void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
03306 
03307   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03308   static bool classofKind(Kind K) { return K == FileScopeAsm; }
03309 };
03310 
03311 /// BlockDecl - This represents a block literal declaration, which is like an
03312 /// unnamed FunctionDecl.  For example:
03313 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
03314 ///
03315 class BlockDecl : public Decl, public DeclContext {
03316 public:
03317   /// A class which contains all the information about a particular
03318   /// captured value.
03319   class Capture {
03320     enum {
03321       flag_isByRef = 0x1,
03322       flag_isNested = 0x2
03323     };
03324 
03325     /// The variable being captured.
03326     llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
03327 
03328     /// The copy expression, expressed in terms of a DeclRef (or
03329     /// BlockDeclRef) to the captured variable.  Only required if the
03330     /// variable has a C++ class type.
03331     Expr *CopyExpr;
03332 
03333   public:
03334     Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
03335       : VariableAndFlags(variable,
03336                   (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
03337         CopyExpr(copy) {}
03338 
03339     /// The variable being captured.
03340     VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
03341 
03342     /// Whether this is a "by ref" capture, i.e. a capture of a __block
03343     /// variable.
03344     bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
03345 
03346     /// Whether this is a nested capture, i.e. the variable captured
03347     /// is not from outside the immediately enclosing function/block.
03348     bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
03349 
03350     bool hasCopyExpr() const { return CopyExpr != nullptr; }
03351     Expr *getCopyExpr() const { return CopyExpr; }
03352     void setCopyExpr(Expr *e) { CopyExpr = e; }
03353   };
03354 
03355 private:
03356   // FIXME: This can be packed into the bitfields in Decl.
03357   bool IsVariadic : 1;
03358   bool CapturesCXXThis : 1;
03359   bool BlockMissingReturnType : 1;
03360   bool IsConversionFromLambda : 1;
03361   /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
03362   /// parameters of this function.  This is null if a prototype or if there are
03363   /// no formals.
03364   ParmVarDecl **ParamInfo;
03365   unsigned NumParams;
03366 
03367   Stmt *Body;
03368   TypeSourceInfo *SignatureAsWritten;
03369 
03370   Capture *Captures;
03371   unsigned NumCaptures;
03372 
03373   unsigned ManglingNumber;
03374   Decl *ManglingContextDecl;
03375 
03376 protected:
03377   BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
03378     : Decl(Block, DC, CaretLoc), DeclContext(Block),
03379       IsVariadic(false), CapturesCXXThis(false),
03380       BlockMissingReturnType(true), IsConversionFromLambda(false),
03381       ParamInfo(nullptr), NumParams(0), Body(nullptr),
03382       SignatureAsWritten(nullptr), Captures(nullptr), NumCaptures(0),
03383       ManglingNumber(0), ManglingContextDecl(nullptr) {}
03384 
03385 public:
03386   static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 
03387   static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03388   
03389   SourceLocation getCaretLocation() const { return getLocation(); }
03390 
03391   bool isVariadic() const { return IsVariadic; }
03392   void setIsVariadic(bool value) { IsVariadic = value; }
03393 
03394   CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
03395   Stmt *getBody() const override { return (Stmt*) Body; }
03396   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
03397 
03398   void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
03399   TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
03400 
03401   // Iterator access to formal parameters.
03402   unsigned param_size() const { return getNumParams(); }
03403   typedef ParmVarDecl **param_iterator;
03404   typedef ParmVarDecl * const *param_const_iterator;
03405   typedef llvm::iterator_range<param_iterator> param_range;
03406   typedef llvm::iterator_range<param_const_iterator> param_const_range;
03407 
03408   // ArrayRef access to formal parameters.
03409   // FIXME: Should eventual replace iterator access.
03410   ArrayRef<ParmVarDecl*> parameters() const {
03411     return llvm::makeArrayRef(ParamInfo, param_size());
03412   }
03413 
03414   bool param_empty() const { return NumParams == 0; }
03415   param_range params() { return param_range(param_begin(), param_end()); }
03416   param_iterator param_begin() { return param_iterator(ParamInfo); }
03417   param_iterator param_end() {
03418     return param_iterator(ParamInfo + param_size());
03419   }
03420 
03421   param_const_range params() const {
03422     return param_const_range(param_begin(), param_end());
03423   }
03424   param_const_iterator param_begin() const {
03425     return param_const_iterator(ParamInfo);
03426   }
03427   param_const_iterator param_end() const {
03428     return param_const_iterator(ParamInfo + param_size());
03429   }
03430 
03431   unsigned getNumParams() const { return NumParams; }
03432   const ParmVarDecl *getParamDecl(unsigned i) const {
03433     assert(i < getNumParams() && "Illegal param #");
03434     return ParamInfo[i];
03435   }
03436   ParmVarDecl *getParamDecl(unsigned i) {
03437     assert(i < getNumParams() && "Illegal param #");
03438     return ParamInfo[i];
03439   }
03440   void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
03441 
03442   /// hasCaptures - True if this block (or its nested blocks) captures
03443   /// anything of local storage from its enclosing scopes.
03444   bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; }
03445 
03446   /// getNumCaptures - Returns the number of captured variables.
03447   /// Does not include an entry for 'this'.
03448   unsigned getNumCaptures() const { return NumCaptures; }
03449 
03450   typedef const Capture *capture_iterator;
03451   typedef const Capture *capture_const_iterator;
03452   typedef llvm::iterator_range<capture_iterator> capture_range;
03453   typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
03454 
03455   capture_range captures() {
03456     return capture_range(capture_begin(), capture_end());
03457   }
03458   capture_const_range captures() const {
03459     return capture_const_range(capture_begin(), capture_end());
03460   }
03461 
03462   capture_iterator capture_begin() { return Captures; }
03463   capture_iterator capture_end() { return Captures + NumCaptures; }
03464   capture_const_iterator capture_begin() const { return Captures; }
03465   capture_const_iterator capture_end() const { return Captures + NumCaptures; }
03466 
03467   bool capturesCXXThis() const { return CapturesCXXThis; }
03468   bool blockMissingReturnType() const { return BlockMissingReturnType; }
03469   void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; }
03470 
03471   bool isConversionFromLambda() const { return IsConversionFromLambda; }
03472   void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
03473 
03474   bool capturesVariable(const VarDecl *var) const;
03475 
03476   void setCaptures(ASTContext &Context,
03477                    const Capture *begin,
03478                    const Capture *end,
03479                    bool capturesCXXThis);
03480 
03481    unsigned getBlockManglingNumber() const {
03482      return ManglingNumber;
03483    }
03484    Decl *getBlockManglingContextDecl() const {
03485      return ManglingContextDecl;    
03486    }
03487 
03488   void setBlockMangling(unsigned Number, Decl *Ctx) {
03489     ManglingNumber = Number;
03490     ManglingContextDecl = Ctx;
03491   }
03492 
03493   SourceRange getSourceRange() const override LLVM_READONLY;
03494 
03495   // Implement isa/cast/dyncast/etc.
03496   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03497   static bool classofKind(Kind K) { return K == Block; }
03498   static DeclContext *castToDeclContext(const BlockDecl *D) {
03499     return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
03500   }
03501   static BlockDecl *castFromDeclContext(const DeclContext *DC) {
03502     return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
03503   }
03504 };
03505 
03506 /// \brief This represents the body of a CapturedStmt, and serves as its
03507 /// DeclContext.
03508 class CapturedDecl : public Decl, public DeclContext {
03509 private:
03510   /// \brief The number of parameters to the outlined function.
03511   unsigned NumParams;
03512   /// \brief The position of context parameter in list of parameters.
03513   unsigned ContextParam;
03514   /// \brief The body of the outlined function.
03515   llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
03516 
03517   explicit CapturedDecl(DeclContext *DC, unsigned NumParams)
03518     : Decl(Captured, DC, SourceLocation()), DeclContext(Captured),
03519       NumParams(NumParams), ContextParam(0), BodyAndNothrow(nullptr, false) { }
03520 
03521   ImplicitParamDecl **getParams() const {
03522     return reinterpret_cast<ImplicitParamDecl **>(
03523              const_cast<CapturedDecl *>(this) + 1);
03524   }
03525 
03526 public:
03527   static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
03528                               unsigned NumParams);
03529   static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
03530                                           unsigned NumParams);
03531 
03532   Stmt *getBody() const override { return BodyAndNothrow.getPointer(); }
03533   void setBody(Stmt *B) { BodyAndNothrow.setPointer(B); }
03534 
03535   bool isNothrow() const { return BodyAndNothrow.getInt(); }
03536   void setNothrow(bool Nothrow = true) { BodyAndNothrow.setInt(Nothrow); }
03537 
03538   unsigned getNumParams() const { return NumParams; }
03539 
03540   ImplicitParamDecl *getParam(unsigned i) const {
03541     assert(i < NumParams);
03542     return getParams()[i];
03543   }
03544   void setParam(unsigned i, ImplicitParamDecl *P) {
03545     assert(i < NumParams);
03546     getParams()[i] = P;
03547   }
03548 
03549   /// \brief Retrieve the parameter containing captured variables.
03550   ImplicitParamDecl *getContextParam() const {
03551     assert(ContextParam < NumParams);
03552     return getParam(ContextParam);
03553   }
03554   void setContextParam(unsigned i, ImplicitParamDecl *P) {
03555     assert(i < NumParams);
03556     ContextParam = i;
03557     setParam(i, P);
03558   }
03559   unsigned getContextParamPosition() const { return ContextParam; }
03560 
03561   typedef ImplicitParamDecl **param_iterator;
03562   typedef llvm::iterator_range<param_iterator> param_range;
03563 
03564   /// \brief Retrieve an iterator pointing to the first parameter decl.
03565   param_iterator param_begin() const { return getParams(); }
03566   /// \brief Retrieve an iterator one past the last parameter decl.
03567   param_iterator param_end() const { return getParams() + NumParams; }
03568 
03569   /// \brief Retrieve an iterator range for the parameter declarations.
03570   param_range params() const { return param_range(param_begin(), param_end()); }
03571 
03572   // Implement isa/cast/dyncast/etc.
03573   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03574   static bool classofKind(Kind K) { return K == Captured; }
03575   static DeclContext *castToDeclContext(const CapturedDecl *D) {
03576     return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
03577   }
03578   static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
03579     return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
03580   }
03581 
03582   friend class ASTDeclReader;
03583   friend class ASTDeclWriter;
03584 };
03585 
03586 /// \brief Describes a module import declaration, which makes the contents
03587 /// of the named module visible in the current translation unit.
03588 ///
03589 /// An import declaration imports the named module (or submodule). For example:
03590 /// \code
03591 ///   @import std.vector;
03592 /// \endcode
03593 ///
03594 /// Import declarations can also be implicitly generated from
03595 /// \#include/\#import directives.
03596 class ImportDecl : public Decl {
03597   /// \brief The imported module, along with a bit that indicates whether
03598   /// we have source-location information for each identifier in the module
03599   /// name. 
03600   ///
03601   /// When the bit is false, we only have a single source location for the
03602   /// end of the import declaration.
03603   llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
03604   
03605   /// \brief The next import in the list of imports local to the translation
03606   /// unit being parsed (not loaded from an AST file).
03607   ImportDecl *NextLocalImport;
03608   
03609   friend class ASTReader;
03610   friend class ASTDeclReader;
03611   friend class ASTContext;
03612   
03613   ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
03614              ArrayRef<SourceLocation> IdentifierLocs);
03615 
03616   ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
03617              SourceLocation EndLoc);
03618 
03619   ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { }
03620   
03621 public:
03622   /// \brief Create a new module import declaration.
03623   static ImportDecl *Create(ASTContext &C, DeclContext *DC, 
03624                             SourceLocation StartLoc, Module *Imported,
03625                             ArrayRef<SourceLocation> IdentifierLocs);
03626   
03627   /// \brief Create a new module import declaration for an implicitly-generated
03628   /// import.
03629   static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, 
03630                                     SourceLocation StartLoc, Module *Imported, 
03631                                     SourceLocation EndLoc);
03632   
03633   /// \brief Create a new, deserialized module import declaration.
03634   static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, 
03635                                         unsigned NumLocations);
03636   
03637   /// \brief Retrieve the module that was imported by the import declaration.
03638   Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
03639   
03640   /// \brief Retrieves the locations of each of the identifiers that make up
03641   /// the complete module name in the import declaration.
03642   ///
03643   /// This will return an empty array if the locations of the individual
03644   /// identifiers aren't available.
03645   ArrayRef<SourceLocation> getIdentifierLocs() const;
03646 
03647   SourceRange getSourceRange() const override LLVM_READONLY;
03648 
03649   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03650   static bool classofKind(Kind K) { return K == Import; }
03651 };
03652 
03653 /// \brief Represents an empty-declaration.
03654 class EmptyDecl : public Decl {
03655   virtual void anchor();
03656   EmptyDecl(DeclContext *DC, SourceLocation L)
03657     : Decl(Empty, DC, L) { }
03658 
03659 public:
03660   static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
03661                            SourceLocation L);
03662   static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03663 
03664   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03665   static bool classofKind(Kind K) { return K == Empty; }
03666 };
03667 
03668 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
03669 /// into a diagnostic with <<.
03670 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
03671                                            const NamedDecl* ND) {
03672   DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
03673                   DiagnosticsEngine::ak_nameddecl);
03674   return DB;
03675 }
03676 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
03677                                            const NamedDecl* ND) {
03678   PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
03679                   DiagnosticsEngine::ak_nameddecl);
03680   return PD;
03681 }
03682 
03683 template<typename decl_type>
03684 void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
03685   // Note: This routine is implemented here because we need both NamedDecl
03686   // and Redeclarable to be defined.
03687   assert(RedeclLink.NextIsLatest() &&
03688          "setPreviousDecl on a decl already in a redeclaration chain");
03689 
03690   decl_type *First;
03691 
03692   if (PrevDecl) {
03693     // Point to previous. Make sure that this is actually the most recent
03694     // redeclaration, or we can build invalid chains. If the most recent
03695     // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
03696     First = PrevDecl->getFirstDecl();
03697     assert(First->RedeclLink.NextIsLatest() && "Expected first");
03698     decl_type *MostRecent = First->getNextRedeclaration();
03699     RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
03700 
03701     // If the declaration was previously visible, a redeclaration of it remains
03702     // visible even if it wouldn't be visible by itself.
03703     static_cast<decl_type*>(this)->IdentifierNamespace |=
03704       MostRecent->getIdentifierNamespace() &
03705       (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
03706   } else {
03707     // Make this first.
03708     First = static_cast<decl_type*>(this);
03709   }
03710 
03711   // First one will point to this one as latest.
03712   First->RedeclLink.setLatest(static_cast<decl_type*>(this));
03713 
03714   assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
03715          cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
03716 }
03717 
03718 // Inline function definitions.
03719 
03720 /// \brief Check if the given decl is complete.
03721 ///
03722 /// We use this function to break a cycle between the inline definitions in
03723 /// Type.h and Decl.h.
03724 inline bool IsEnumDeclComplete(EnumDecl *ED) {
03725   return ED->isComplete();
03726 }
03727 
03728 /// \brief Check if the given decl is scoped.
03729 ///
03730 /// We use this function to break a cycle between the inline definitions in
03731 /// Type.h and Decl.h.
03732 inline bool IsEnumDeclScoped(EnumDecl *ED) {
03733   return ED->isScoped();
03734 }
03735 
03736 }  // end namespace clang
03737 
03738 #endif