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