Home | History | Annotate | Download | only in AST
      1 //===-- DeclCXX.h - Classes for representing C++ 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 C++ Decl subclasses, other than those for
     11 //  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_AST_DECLCXX_H
     16 #define LLVM_CLANG_AST_DECLCXX_H
     17 
     18 #include "clang/AST/ASTUnresolvedSet.h"
     19 #include "clang/AST/Decl.h"
     20 #include "clang/AST/Expr.h"
     21 #include "clang/AST/ExprCXX.h"
     22 #include "clang/AST/TypeLoc.h"
     23 #include "llvm/ADT/DenseMap.h"
     24 #include "llvm/ADT/PointerIntPair.h"
     25 #include "llvm/ADT/SmallPtrSet.h"
     26 #include "llvm/Support/Compiler.h"
     27 
     28 namespace clang {
     29 
     30 class ClassTemplateDecl;
     31 class ClassTemplateSpecializationDecl;
     32 class CXXBasePath;
     33 class CXXBasePaths;
     34 class CXXConstructorDecl;
     35 class CXXConversionDecl;
     36 class CXXDestructorDecl;
     37 class CXXMethodDecl;
     38 class CXXRecordDecl;
     39 class CXXMemberLookupCriteria;
     40 class CXXFinalOverriderMap;
     41 class CXXIndirectPrimaryBaseSet;
     42 class FriendDecl;
     43 class LambdaExpr;
     44 class UsingDecl;
     45 
     46 /// \brief Represents any kind of function declaration, whether it is a
     47 /// concrete function or a function template.
     48 class AnyFunctionDecl {
     49   NamedDecl *Function;
     50 
     51   AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
     52 
     53 public:
     54   AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
     55   AnyFunctionDecl(FunctionTemplateDecl *FTD);
     56 
     57   /// \brief Implicily converts any function or function template into a
     58   /// named declaration.
     59   operator NamedDecl *() const { return Function; }
     60 
     61   /// \brief Retrieve the underlying function or function template.
     62   NamedDecl *get() const { return Function; }
     63 
     64   static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
     65     return AnyFunctionDecl(ND);
     66   }
     67 };
     68 
     69 } // end namespace clang
     70 
     71 namespace llvm {
     72   /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
     73   /// AnyFunctionDecl to any function or function template declaration.
     74   template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
     75     typedef ::clang::NamedDecl* SimpleType;
     76     static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
     77       return Val;
     78     }
     79   };
     80   template<> struct simplify_type< ::clang::AnyFunctionDecl>
     81   : public simplify_type<const ::clang::AnyFunctionDecl> {};
     82 
     83   // Provide PointerLikeTypeTraits for non-cvr pointers.
     84   template<>
     85   class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
     86   public:
     87     static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
     88       return F.get();
     89     }
     90     static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
     91       return ::clang::AnyFunctionDecl::getFromNamedDecl(
     92                                       static_cast< ::clang::NamedDecl*>(P));
     93     }
     94 
     95     enum { NumLowBitsAvailable = 2 };
     96   };
     97 
     98 } // end namespace llvm
     99 
    100 namespace clang {
    101 
    102 /// @brief Represents an access specifier followed by colon ':'.
    103 ///
    104 /// An objects of this class represents sugar for the syntactic occurrence
    105 /// of an access specifier followed by a colon in the list of member
    106 /// specifiers of a C++ class definition.
    107 ///
    108 /// Note that they do not represent other uses of access specifiers,
    109 /// such as those occurring in a list of base specifiers.
    110 /// Also note that this class has nothing to do with so-called
    111 /// "access declarations" (C++98 11.3 [class.access.dcl]).
    112 class AccessSpecDecl : public Decl {
    113   virtual void anchor();
    114   /// \brief The location of the ':'.
    115   SourceLocation ColonLoc;
    116 
    117   AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
    118                  SourceLocation ASLoc, SourceLocation ColonLoc)
    119     : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
    120     setAccess(AS);
    121   }
    122   AccessSpecDecl(EmptyShell Empty)
    123     : Decl(AccessSpec, Empty) { }
    124 public:
    125   /// \brief The location of the access specifier.
    126   SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
    127   /// \brief Sets the location of the access specifier.
    128   void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
    129 
    130   /// \brief The location of the colon following the access specifier.
    131   SourceLocation getColonLoc() const { return ColonLoc; }
    132   /// \brief Sets the location of the colon.
    133   void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
    134 
    135   SourceRange getSourceRange() const LLVM_READONLY {
    136     return SourceRange(getAccessSpecifierLoc(), getColonLoc());
    137   }
    138 
    139   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
    140                                 DeclContext *DC, SourceLocation ASLoc,
    141                                 SourceLocation ColonLoc) {
    142     return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
    143   }
    144   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
    145 
    146   // Implement isa/cast/dyncast/etc.
    147   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
    148   static bool classofKind(Kind K) { return K == AccessSpec; }
    149 };
    150 
    151 
    152 /// \brief Represents a base class of a C++ class.
    153 ///
    154 /// Each CXXBaseSpecifier represents a single, direct base class (or
    155 /// struct) of a C++ class (or struct). It specifies the type of that
    156 /// base class, whether it is a virtual or non-virtual base, and what
    157 /// level of access (public, protected, private) is used for the
    158 /// derivation. For example:
    159 ///
    160 /// @code
    161 ///   class A { };
    162 ///   class B { };
    163 ///   class C : public virtual A, protected B { };
    164 /// @endcode
    165 ///
    166 /// In this code, C will have two CXXBaseSpecifiers, one for "public
    167 /// virtual A" and the other for "protected B".
    168 class CXXBaseSpecifier {
    169   /// Range - The source code range that covers the full base
    170   /// specifier, including the "virtual" (if present) and access
    171   /// specifier (if present).
    172   SourceRange Range;
    173 
    174   /// \brief The source location of the ellipsis, if this is a pack
    175   /// expansion.
    176   SourceLocation EllipsisLoc;
    177 
    178   /// \brief Whether this is a virtual base class or not.
    179   bool Virtual : 1;
    180 
    181   /// BaseOfClass - Whether this is the base of a class (true) or of a
    182   /// struct (false). This determines the mapping from the access
    183   /// specifier as written in the source code to the access specifier
    184   /// used for semantic analysis.
    185   bool BaseOfClass : 1;
    186 
    187   /// Access - Access specifier as written in the source code (which
    188   /// may be AS_none). The actual type of data stored here is an
    189   /// AccessSpecifier, but we use "unsigned" here to work around a
    190   /// VC++ bug.
    191   unsigned Access : 2;
    192 
    193   /// InheritConstructors - Whether the class contains a using declaration
    194   /// to inherit the named class's constructors.
    195   bool InheritConstructors : 1;
    196 
    197   /// BaseTypeInfo - The type of the base class. This will be a class or struct
    198   /// (or a typedef of such). The source code range does not include the
    199   /// "virtual" or access specifier.
    200   TypeSourceInfo *BaseTypeInfo;
    201 
    202 public:
    203   CXXBaseSpecifier() { }
    204 
    205   CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
    206                    TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
    207     : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
    208       Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
    209 
    210   /// getSourceRange - Retrieves the source range that contains the
    211   /// entire base specifier.
    212   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
    213   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
    214   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
    215 
    216   /// isVirtual - Determines whether the base class is a virtual base
    217   /// class (or not).
    218   bool isVirtual() const { return Virtual; }
    219 
    220   /// \brief Determine whether this base class is a base of a class declared
    221   /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
    222   bool isBaseOfClass() const { return BaseOfClass; }
    223 
    224   /// \brief Determine whether this base specifier is a pack expansion.
    225   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
    226 
    227   /// \brief Determine whether this base class's constructors get inherited.
    228   bool getInheritConstructors() const { return InheritConstructors; }
    229 
    230   /// \brief Set that this base class's constructors should be inherited.
    231   void setInheritConstructors(bool Inherit = true) {
    232     InheritConstructors = Inherit;
    233   }
    234 
    235   /// \brief For a pack expansion, determine the location of the ellipsis.
    236   SourceLocation getEllipsisLoc() const {
    237     return EllipsisLoc;
    238   }
    239 
    240   /// getAccessSpecifier - Returns the access specifier for this base
    241   /// specifier. This is the actual base specifier as used for
    242   /// semantic analysis, so the result can never be AS_none. To
    243   /// retrieve the access specifier as written in the source code, use
    244   /// getAccessSpecifierAsWritten().
    245   AccessSpecifier getAccessSpecifier() const {
    246     if ((AccessSpecifier)Access == AS_none)
    247       return BaseOfClass? AS_private : AS_public;
    248     else
    249       return (AccessSpecifier)Access;
    250   }
    251 
    252   /// getAccessSpecifierAsWritten - Retrieves the access specifier as
    253   /// written in the source code (which may mean that no access
    254   /// specifier was explicitly written). Use getAccessSpecifier() to
    255   /// retrieve the access specifier for use in semantic analysis.
    256   AccessSpecifier getAccessSpecifierAsWritten() const {
    257     return (AccessSpecifier)Access;
    258   }
    259 
    260   /// getType - Retrieves the type of the base class. This type will
    261   /// always be an unqualified class type.
    262   QualType getType() const { return BaseTypeInfo->getType(); }
    263 
    264   /// getTypeLoc - Retrieves the type and source location of the base class.
    265   TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
    266 };
    267 
    268 /// CXXRecordDecl - Represents a C++ struct/union/class.
    269 /// FIXME: This class will disappear once we've properly taught RecordDecl
    270 /// to deal with C++-specific things.
    271 class CXXRecordDecl : public RecordDecl {
    272 
    273   friend void TagDecl::startDefinition();
    274 
    275   /// Values used in DefinitionData fields to represent special members.
    276   enum SpecialMemberFlags {
    277     SMF_DefaultConstructor = 0x1,
    278     SMF_CopyConstructor = 0x2,
    279     SMF_MoveConstructor = 0x4,
    280     SMF_CopyAssignment = 0x8,
    281     SMF_MoveAssignment = 0x10,
    282     SMF_Destructor = 0x20,
    283     SMF_All = 0x3f
    284   };
    285 
    286   struct DefinitionData {
    287     DefinitionData(CXXRecordDecl *D);
    288 
    289     /// \brief True if this class has any user-declared constructors.
    290     bool UserDeclaredConstructor : 1;
    291 
    292     /// The user-declared special members which this class has.
    293     unsigned UserDeclaredSpecialMembers : 6;
    294 
    295     /// Aggregate - True when this class is an aggregate.
    296     bool Aggregate : 1;
    297 
    298     /// PlainOldData - True when this class is a POD-type.
    299     bool PlainOldData : 1;
    300 
    301     /// Empty - true when this class is empty for traits purposes,
    302     /// i.e. has no data members other than 0-width bit-fields, has no
    303     /// virtual function/base, and doesn't inherit from a non-empty
    304     /// class. Doesn't take union-ness into account.
    305     bool Empty : 1;
    306 
    307     /// Polymorphic - True when this class is polymorphic, i.e. has at
    308     /// least one virtual member or derives from a polymorphic class.
    309     bool Polymorphic : 1;
    310 
    311     /// Abstract - True when this class is abstract, i.e. has at least
    312     /// one pure virtual function, (that can come from a base class).
    313     bool Abstract : 1;
    314 
    315     /// IsStandardLayout - True when this class has standard layout.
    316     ///
    317     /// C++0x [class]p7.  A standard-layout class is a class that:
    318     /// * has no non-static data members of type non-standard-layout class (or
    319     ///   array of such types) or reference,
    320     /// * has no virtual functions (10.3) and no virtual base classes (10.1),
    321     /// * has the same access control (Clause 11) for all non-static data
    322     ///   members
    323     /// * has no non-standard-layout base classes,
    324     /// * either has no non-static data members in the most derived class and at
    325     ///   most one base class with non-static data members, or has no base
    326     ///   classes with non-static data members, and
    327     /// * has no base classes of the same type as the first non-static data
    328     ///   member.
    329     bool IsStandardLayout : 1;
    330 
    331     /// HasNoNonEmptyBases - True when there are no non-empty base classes.
    332     ///
    333     /// This is a helper bit of state used to implement IsStandardLayout more
    334     /// efficiently.
    335     bool HasNoNonEmptyBases : 1;
    336 
    337     /// HasPrivateFields - True when there are private non-static data members.
    338     bool HasPrivateFields : 1;
    339 
    340     /// HasProtectedFields - True when there are protected non-static data
    341     /// members.
    342     bool HasProtectedFields : 1;
    343 
    344     /// HasPublicFields - True when there are private non-static data members.
    345     bool HasPublicFields : 1;
    346 
    347     /// \brief True if this class (or any subobject) has mutable fields.
    348     bool HasMutableFields : 1;
    349 
    350     /// \brief True if there no non-field members declared by the user.
    351     bool HasOnlyCMembers : 1;
    352 
    353     /// \brief True if any field has an in-class initializer.
    354     bool HasInClassInitializer : 1;
    355 
    356     /// \brief True if any field is of reference type, and does not have an
    357     /// in-class initializer. In this case, value-initialization of this class
    358     /// is illegal in C++98 even if the class has a trivial default constructor.
    359     bool HasUninitializedReferenceMember : 1;
    360 
    361     /// \brief These flags are \c true if a defaulted corresponding special
    362     /// member can't be fully analyzed without performing overload resolution.
    363     /// @{
    364     bool NeedOverloadResolutionForMoveConstructor : 1;
    365     bool NeedOverloadResolutionForMoveAssignment : 1;
    366     bool NeedOverloadResolutionForDestructor : 1;
    367     /// @}
    368 
    369     /// \brief These flags are \c true if an implicit defaulted corresponding
    370     /// special member would be defined as deleted.
    371     /// @{
    372     bool DefaultedMoveConstructorIsDeleted : 1;
    373     bool DefaultedMoveAssignmentIsDeleted : 1;
    374     bool DefaultedDestructorIsDeleted : 1;
    375     /// @}
    376 
    377     /// \brief The trivial special members which this class has, per
    378     /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
    379     /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
    380     ///
    381     /// This excludes any user-declared but not user-provided special members
    382     /// which have been declared but not yet defined.
    383     unsigned HasTrivialSpecialMembers : 6;
    384 
    385     /// \brief The declared special members of this class which are known to be
    386     /// non-trivial.
    387     ///
    388     /// This excludes any user-declared but not user-provided special members
    389     /// which have been declared but not yet defined, and any implicit special
    390     /// members which have not yet been declared.
    391     unsigned DeclaredNonTrivialSpecialMembers : 6;
    392 
    393     /// HasIrrelevantDestructor - True when this class has a destructor with no
    394     /// semantic effect.
    395     bool HasIrrelevantDestructor : 1;
    396 
    397     /// HasConstexprNonCopyMoveConstructor - True when this class has at least
    398     /// one user-declared constexpr constructor which is neither the copy nor
    399     /// move constructor.
    400     bool HasConstexprNonCopyMoveConstructor : 1;
    401 
    402     /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default
    403     /// constructor for this class would be constexpr.
    404     bool DefaultedDefaultConstructorIsConstexpr : 1;
    405 
    406     /// HasConstexprDefaultConstructor - True if this class has a constexpr
    407     /// default constructor (either user-declared or implicitly declared).
    408     bool HasConstexprDefaultConstructor : 1;
    409 
    410     /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
    411     /// one non-static data member or base class of non-literal or volatile
    412     /// type.
    413     bool HasNonLiteralTypeFieldsOrBases : 1;
    414 
    415     /// ComputedVisibleConversions - True when visible conversion functions are
    416     /// already computed and are available.
    417     bool ComputedVisibleConversions : 1;
    418 
    419     /// \brief Whether we have a C++11 user-provided default constructor (not
    420     /// explicitly deleted or defaulted).
    421     bool UserProvidedDefaultConstructor : 1;
    422 
    423     /// \brief The special members which have been declared for this class,
    424     /// either by the user or implicitly.
    425     unsigned DeclaredSpecialMembers : 6;
    426 
    427     /// \brief Whether an implicit copy constructor would have a const-qualified
    428     /// parameter.
    429     bool ImplicitCopyConstructorHasConstParam : 1;
    430 
    431     /// \brief Whether an implicit copy assignment operator would have a
    432     /// const-qualified parameter.
    433     bool ImplicitCopyAssignmentHasConstParam : 1;
    434 
    435     /// \brief Whether any declared copy constructor has a const-qualified
    436     /// parameter.
    437     bool HasDeclaredCopyConstructorWithConstParam : 1;
    438 
    439     /// \brief Whether any declared copy assignment operator has either a
    440     /// const-qualified reference parameter or a non-reference parameter.
    441     bool HasDeclaredCopyAssignmentWithConstParam : 1;
    442 
    443     /// \brief Whether an implicit move constructor was attempted to be declared
    444     /// but would have been deleted.
    445     bool FailedImplicitMoveConstructor : 1;
    446 
    447     /// \brief Whether an implicit move assignment operator was attempted to be
    448     /// declared but would have been deleted.
    449     bool FailedImplicitMoveAssignment : 1;
    450 
    451     /// \brief Whether this class describes a C++ lambda.
    452     bool IsLambda : 1;
    453 
    454     /// NumBases - The number of base class specifiers in Bases.
    455     unsigned NumBases;
    456 
    457     /// NumVBases - The number of virtual base class specifiers in VBases.
    458     unsigned NumVBases;
    459 
    460     /// Bases - Base classes of this class.
    461     /// FIXME: This is wasted space for a union.
    462     LazyCXXBaseSpecifiersPtr Bases;
    463 
    464     /// VBases - direct and indirect virtual base classes of this class.
    465     LazyCXXBaseSpecifiersPtr VBases;
    466 
    467     /// Conversions - Overload set containing the conversion functions
    468     /// of this C++ class (but not its inherited conversion
    469     /// functions). Each of the entries in this overload set is a
    470     /// CXXConversionDecl.
    471     ASTUnresolvedSet Conversions;
    472 
    473     /// VisibleConversions - Overload set containing the conversion
    474     /// functions of this C++ class and all those inherited conversion
    475     /// functions that are visible in this class. Each of the entries
    476     /// in this overload set is a CXXConversionDecl or a
    477     /// FunctionTemplateDecl.
    478     ASTUnresolvedSet VisibleConversions;
    479 
    480     /// Definition - The declaration which defines this record.
    481     CXXRecordDecl *Definition;
    482 
    483     /// FirstFriend - The first friend declaration in this class, or
    484     /// null if there aren't any.  This is actually currently stored
    485     /// in reverse order.
    486     FriendDecl *FirstFriend;
    487 
    488     /// \brief Retrieve the set of direct base classes.
    489     CXXBaseSpecifier *getBases() const {
    490       if (!Bases.isOffset())
    491         return Bases.get(0);
    492       return getBasesSlowCase();
    493     }
    494 
    495     /// \brief Retrieve the set of virtual base classes.
    496     CXXBaseSpecifier *getVBases() const {
    497       if (!VBases.isOffset())
    498         return VBases.get(0);
    499       return getVBasesSlowCase();
    500     }
    501 
    502   private:
    503     CXXBaseSpecifier *getBasesSlowCase() const;
    504     CXXBaseSpecifier *getVBasesSlowCase() const;
    505   } *DefinitionData;
    506 
    507   /// \brief Describes a C++ closure type (generated by a lambda expression).
    508   struct LambdaDefinitionData : public DefinitionData {
    509     typedef LambdaExpr::Capture Capture;
    510 
    511     LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent)
    512       : DefinitionData(D), Dependent(Dependent), NumCaptures(0),
    513         NumExplicitCaptures(0), ManglingNumber(0), ContextDecl(0), Captures(0),
    514         MethodTyInfo(Info)
    515     {
    516       IsLambda = true;
    517     }
    518 
    519     /// \brief Whether this lambda is known to be dependent, even if its
    520     /// context isn't dependent.
    521     ///
    522     /// A lambda with a non-dependent context can be dependent if it occurs
    523     /// within the default argument of a function template, because the
    524     /// lambda will have been created with the enclosing context as its
    525     /// declaration context, rather than function. This is an unfortunate
    526     /// artifact of having to parse the default arguments before
    527     unsigned Dependent : 1;
    528 
    529     /// \brief The number of captures in this lambda.
    530     unsigned NumCaptures : 16;
    531 
    532     /// \brief The number of explicit captures in this lambda.
    533     unsigned NumExplicitCaptures : 15;
    534 
    535     /// \brief The number used to indicate this lambda expression for name
    536     /// mangling in the Itanium C++ ABI.
    537     unsigned ManglingNumber;
    538 
    539     /// \brief The declaration that provides context for this lambda, if the
    540     /// actual DeclContext does not suffice. This is used for lambdas that
    541     /// occur within default arguments of function parameters within the class
    542     /// or within a data member initializer.
    543     Decl *ContextDecl;
    544 
    545     /// \brief The list of captures, both explicit and implicit, for this
    546     /// lambda.
    547     Capture *Captures;
    548 
    549     /// \brief The type of the call method.
    550     TypeSourceInfo *MethodTyInfo;
    551   };
    552 
    553   struct DefinitionData &data() {
    554     assert(DefinitionData && "queried property of class with no definition");
    555     return *DefinitionData;
    556   }
    557 
    558   const struct DefinitionData &data() const {
    559     assert(DefinitionData && "queried property of class with no definition");
    560     return *DefinitionData;
    561   }
    562 
    563   struct LambdaDefinitionData &getLambdaData() const {
    564     assert(DefinitionData && "queried property of lambda with no definition");
    565     assert(DefinitionData->IsLambda &&
    566            "queried lambda property of non-lambda class");
    567     return static_cast<LambdaDefinitionData &>(*DefinitionData);
    568   }
    569 
    570   /// \brief The template or declaration that this declaration
    571   /// describes or was instantiated from, respectively.
    572   ///
    573   /// For non-templates, this value will be NULL. For record
    574   /// declarations that describe a class template, this will be a
    575   /// pointer to a ClassTemplateDecl. For member
    576   /// classes of class template specializations, this will be the
    577   /// MemberSpecializationInfo referring to the member class that was
    578   /// instantiated or specialized.
    579   llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
    580     TemplateOrInstantiation;
    581 
    582   friend class DeclContext;
    583   friend class LambdaExpr;
    584 
    585   /// \brief Called from setBases and addedMember to notify the class that a
    586   /// direct or virtual base class or a member of class type has been added.
    587   void addedClassSubobject(CXXRecordDecl *Base);
    588 
    589   /// \brief Notify the class that member has been added.
    590   ///
    591   /// This routine helps maintain information about the class based on which
    592   /// members have been added. It will be invoked by DeclContext::addDecl()
    593   /// whenever a member is added to this record.
    594   void addedMember(Decl *D);
    595 
    596   void markedVirtualFunctionPure();
    597   friend void FunctionDecl::setPure(bool);
    598 
    599   friend class ASTNodeImporter;
    600 
    601 protected:
    602   CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
    603                 SourceLocation StartLoc, SourceLocation IdLoc,
    604                 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
    605 
    606 public:
    607   /// base_class_iterator - Iterator that traverses the base classes
    608   /// of a class.
    609   typedef CXXBaseSpecifier*       base_class_iterator;
    610 
    611   /// base_class_const_iterator - Iterator that traverses the base
    612   /// classes of a class.
    613   typedef const CXXBaseSpecifier* base_class_const_iterator;
    614 
    615   /// reverse_base_class_iterator = Iterator that traverses the base classes
    616   /// of a class in reverse order.
    617   typedef std::reverse_iterator<base_class_iterator>
    618     reverse_base_class_iterator;
    619 
    620   /// reverse_base_class_iterator = Iterator that traverses the base classes
    621   /// of a class in reverse order.
    622   typedef std::reverse_iterator<base_class_const_iterator>
    623     reverse_base_class_const_iterator;
    624 
    625   virtual CXXRecordDecl *getCanonicalDecl() {
    626     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
    627   }
    628   virtual const CXXRecordDecl *getCanonicalDecl() const {
    629     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
    630   }
    631 
    632   const CXXRecordDecl *getPreviousDecl() const {
    633     return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
    634   }
    635   CXXRecordDecl *getPreviousDecl() {
    636     return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
    637   }
    638 
    639   const CXXRecordDecl *getMostRecentDecl() const {
    640     return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
    641   }
    642   CXXRecordDecl *getMostRecentDecl() {
    643     return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
    644   }
    645 
    646   CXXRecordDecl *getDefinition() const {
    647     if (!DefinitionData) return 0;
    648     return data().Definition;
    649   }
    650 
    651   bool hasDefinition() const { return DefinitionData != 0; }
    652 
    653   static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
    654                                SourceLocation StartLoc, SourceLocation IdLoc,
    655                                IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
    656                                bool DelayTypeCreation = false);
    657   static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
    658                                      TypeSourceInfo *Info, SourceLocation Loc,
    659                                      bool DependentLambda);
    660   static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
    661 
    662   bool isDynamicClass() const {
    663     return data().Polymorphic || data().NumVBases != 0;
    664   }
    665 
    666   /// setBases - Sets the base classes of this struct or class.
    667   void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
    668 
    669   /// getNumBases - Retrieves the number of base classes of this
    670   /// class.
    671   unsigned getNumBases() const { return data().NumBases; }
    672 
    673   base_class_iterator bases_begin() { return data().getBases(); }
    674   base_class_const_iterator bases_begin() const { return data().getBases(); }
    675   base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
    676   base_class_const_iterator bases_end() const {
    677     return bases_begin() + data().NumBases;
    678   }
    679   reverse_base_class_iterator       bases_rbegin() {
    680     return reverse_base_class_iterator(bases_end());
    681   }
    682   reverse_base_class_const_iterator bases_rbegin() const {
    683     return reverse_base_class_const_iterator(bases_end());
    684   }
    685   reverse_base_class_iterator bases_rend() {
    686     return reverse_base_class_iterator(bases_begin());
    687   }
    688   reverse_base_class_const_iterator bases_rend() const {
    689     return reverse_base_class_const_iterator(bases_begin());
    690   }
    691 
    692   /// getNumVBases - Retrieves the number of virtual base classes of this
    693   /// class.
    694   unsigned getNumVBases() const { return data().NumVBases; }
    695 
    696   base_class_iterator vbases_begin() { return data().getVBases(); }
    697   base_class_const_iterator vbases_begin() const { return data().getVBases(); }
    698   base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
    699   base_class_const_iterator vbases_end() const {
    700     return vbases_begin() + data().NumVBases;
    701   }
    702   reverse_base_class_iterator vbases_rbegin() {
    703     return reverse_base_class_iterator(vbases_end());
    704   }
    705   reverse_base_class_const_iterator vbases_rbegin() const {
    706     return reverse_base_class_const_iterator(vbases_end());
    707   }
    708   reverse_base_class_iterator vbases_rend() {
    709     return reverse_base_class_iterator(vbases_begin());
    710   }
    711   reverse_base_class_const_iterator vbases_rend() const {
    712     return reverse_base_class_const_iterator(vbases_begin());
    713  }
    714 
    715   /// \brief Determine whether this class has any dependent base classes which
    716   /// are not the current instantiation.
    717   bool hasAnyDependentBases() const;
    718 
    719   /// Iterator access to method members.  The method iterator visits
    720   /// all method members of the class, including non-instance methods,
    721   /// special methods, etc.
    722   typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
    723 
    724   /// method_begin - Method begin iterator.  Iterates in the order the methods
    725   /// were declared.
    726   method_iterator method_begin() const {
    727     return method_iterator(decls_begin());
    728   }
    729   /// method_end - Method end iterator.
    730   method_iterator method_end() const {
    731     return method_iterator(decls_end());
    732   }
    733 
    734   /// Iterator access to constructor members.
    735   typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
    736 
    737   ctor_iterator ctor_begin() const {
    738     return ctor_iterator(decls_begin());
    739   }
    740   ctor_iterator ctor_end() const {
    741     return ctor_iterator(decls_end());
    742   }
    743 
    744   /// An iterator over friend declarations.  All of these are defined
    745   /// in DeclFriend.h.
    746   class friend_iterator;
    747   friend_iterator friend_begin() const;
    748   friend_iterator friend_end() const;
    749   void pushFriendDecl(FriendDecl *FD);
    750 
    751   /// Determines whether this record has any friends.
    752   bool hasFriends() const {
    753     return data().FirstFriend != 0;
    754   }
    755 
    756   /// \brief \c true if we know for sure that this class has a single,
    757   /// accessible, unambiguous move constructor that is not deleted.
    758   bool hasSimpleMoveConstructor() const {
    759     return !hasUserDeclaredMoveConstructor() && hasMoveConstructor();
    760   }
    761   /// \brief \c true if we know for sure that this class has a single,
    762   /// accessible, unambiguous move assignment operator that is not deleted.
    763   bool hasSimpleMoveAssignment() const {
    764     return !hasUserDeclaredMoveAssignment() && hasMoveAssignment();
    765   }
    766   /// \brief \c true if we know for sure that this class has an accessible
    767   /// destructor that is not deleted.
    768   bool hasSimpleDestructor() const {
    769     return !hasUserDeclaredDestructor() &&
    770            !data().DefaultedDestructorIsDeleted;
    771   }
    772 
    773   /// \brief Determine whether this class has any default constructors.
    774   bool hasDefaultConstructor() const {
    775     return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
    776            needsImplicitDefaultConstructor();
    777   }
    778 
    779   /// \brief Determine if we need to declare a default constructor for
    780   /// this class.
    781   ///
    782   /// This value is used for lazy creation of default constructors.
    783   bool needsImplicitDefaultConstructor() const {
    784     return !data().UserDeclaredConstructor &&
    785            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
    786   }
    787 
    788   /// hasUserDeclaredConstructor - Whether this class has any
    789   /// user-declared constructors. When true, a default constructor
    790   /// will not be implicitly declared.
    791   bool hasUserDeclaredConstructor() const {
    792     return data().UserDeclaredConstructor;
    793   }
    794 
    795   /// hasUserProvidedDefaultconstructor - Whether this class has a
    796   /// user-provided default constructor per C++0x.
    797   bool hasUserProvidedDefaultConstructor() const {
    798     return data().UserProvidedDefaultConstructor;
    799   }
    800 
    801   /// hasUserDeclaredCopyConstructor - Whether this class has a
    802   /// user-declared copy constructor. When false, a copy constructor
    803   /// will be implicitly declared.
    804   bool hasUserDeclaredCopyConstructor() const {
    805     return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
    806   }
    807 
    808   /// \brief Determine whether this class needs an implicit copy
    809   /// constructor to be lazily declared.
    810   bool needsImplicitCopyConstructor() const {
    811     return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
    812   }
    813 
    814   /// \brief Determine whether we need to eagerly declare a defaulted copy
    815   /// constructor for this class.
    816   bool needsOverloadResolutionForCopyConstructor() const {
    817     return data().HasMutableFields;
    818   }
    819 
    820   /// \brief Determine whether an implicit copy constructor for this type
    821   /// would have a parameter with a const-qualified reference type.
    822   bool implicitCopyConstructorHasConstParam() const {
    823     return data().ImplicitCopyConstructorHasConstParam;
    824   }
    825 
    826   /// \brief Determine whether this class has a copy constructor with
    827   /// a parameter type which is a reference to a const-qualified type.
    828   bool hasCopyConstructorWithConstParam() const {
    829     return data().HasDeclaredCopyConstructorWithConstParam ||
    830            (needsImplicitCopyConstructor() &&
    831             implicitCopyConstructorHasConstParam());
    832   }
    833 
    834   /// hasUserDeclaredMoveOperation - Whether this class has a user-
    835   /// declared move constructor or assignment operator. When false, a
    836   /// move constructor and assignment operator may be implicitly declared.
    837   bool hasUserDeclaredMoveOperation() const {
    838     return data().UserDeclaredSpecialMembers &
    839              (SMF_MoveConstructor | SMF_MoveAssignment);
    840   }
    841 
    842   /// \brief Determine whether this class has had a move constructor
    843   /// declared by the user.
    844   bool hasUserDeclaredMoveConstructor() const {
    845     return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
    846   }
    847 
    848   /// \brief Determine whether this class has a move constructor.
    849   bool hasMoveConstructor() const {
    850     return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
    851            needsImplicitMoveConstructor();
    852   }
    853 
    854   /// \brief Determine whether implicit move constructor generation for this
    855   /// class has failed before.
    856   bool hasFailedImplicitMoveConstructor() const {
    857     return data().FailedImplicitMoveConstructor;
    858   }
    859 
    860   /// \brief Set whether implicit move constructor generation for this class
    861   /// has failed before.
    862   void setFailedImplicitMoveConstructor(bool Failed = true) {
    863     data().FailedImplicitMoveConstructor = Failed;
    864   }
    865 
    866   /// \brief Determine whether this class should get an implicit move
    867   /// constructor or if any existing special member function inhibits this.
    868   bool needsImplicitMoveConstructor() const {
    869     return !hasFailedImplicitMoveConstructor() &&
    870            !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
    871            !hasUserDeclaredCopyConstructor() &&
    872            !hasUserDeclaredCopyAssignment() &&
    873            !hasUserDeclaredMoveAssignment() &&
    874            !hasUserDeclaredDestructor() &&
    875            !data().DefaultedMoveConstructorIsDeleted;
    876   }
    877 
    878   /// \brief Determine whether we need to eagerly declare a defaulted move
    879   /// constructor for this class.
    880   bool needsOverloadResolutionForMoveConstructor() const {
    881     return data().NeedOverloadResolutionForMoveConstructor;
    882   }
    883 
    884   /// hasUserDeclaredCopyAssignment - Whether this class has a
    885   /// user-declared copy assignment operator. When false, a copy
    886   /// assigment operator will be implicitly declared.
    887   bool hasUserDeclaredCopyAssignment() const {
    888     return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
    889   }
    890 
    891   /// \brief Determine whether this class needs an implicit copy
    892   /// assignment operator to be lazily declared.
    893   bool needsImplicitCopyAssignment() const {
    894     return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
    895   }
    896 
    897   /// \brief Determine whether we need to eagerly declare a defaulted copy
    898   /// assignment operator for this class.
    899   bool needsOverloadResolutionForCopyAssignment() const {
    900     return data().HasMutableFields;
    901   }
    902 
    903   /// \brief Determine whether an implicit copy assignment operator for this
    904   /// type would have a parameter with a const-qualified reference type.
    905   bool implicitCopyAssignmentHasConstParam() const {
    906     return data().ImplicitCopyAssignmentHasConstParam;
    907   }
    908 
    909   /// \brief Determine whether this class has a copy assignment operator with
    910   /// a parameter type which is a reference to a const-qualified type or is not
    911   /// a reference..
    912   bool hasCopyAssignmentWithConstParam() const {
    913     return data().HasDeclaredCopyAssignmentWithConstParam ||
    914            (needsImplicitCopyAssignment() &&
    915             implicitCopyAssignmentHasConstParam());
    916   }
    917 
    918   /// \brief Determine whether this class has had a move assignment
    919   /// declared by the user.
    920   bool hasUserDeclaredMoveAssignment() const {
    921     return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
    922   }
    923 
    924   /// \brief Determine whether this class has a move assignment operator.
    925   bool hasMoveAssignment() const {
    926     return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
    927            needsImplicitMoveAssignment();
    928   }
    929 
    930   /// \brief Determine whether implicit move assignment generation for this
    931   /// class has failed before.
    932   bool hasFailedImplicitMoveAssignment() const {
    933     return data().FailedImplicitMoveAssignment;
    934   }
    935 
    936   /// \brief Set whether implicit move assignment generation for this class
    937   /// has failed before.
    938   void setFailedImplicitMoveAssignment(bool Failed = true) {
    939     data().FailedImplicitMoveAssignment = Failed;
    940   }
    941 
    942   /// \brief Determine whether this class should get an implicit move
    943   /// assignment operator or if any existing special member function inhibits
    944   /// this.
    945   bool needsImplicitMoveAssignment() const {
    946     return !hasFailedImplicitMoveAssignment() &&
    947            !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
    948            !hasUserDeclaredCopyConstructor() &&
    949            !hasUserDeclaredCopyAssignment() &&
    950            !hasUserDeclaredMoveConstructor() &&
    951            !hasUserDeclaredDestructor() &&
    952            !data().DefaultedMoveAssignmentIsDeleted;
    953   }
    954 
    955   /// \brief Determine whether we need to eagerly declare a move assignment
    956   /// operator for this class.
    957   bool needsOverloadResolutionForMoveAssignment() const {
    958     return data().NeedOverloadResolutionForMoveAssignment;
    959   }
    960 
    961   /// hasUserDeclaredDestructor - Whether this class has a
    962   /// user-declared destructor. When false, a destructor will be
    963   /// implicitly declared.
    964   bool hasUserDeclaredDestructor() const {
    965     return data().UserDeclaredSpecialMembers & SMF_Destructor;
    966   }
    967 
    968   /// \brief Determine whether this class needs an implicit destructor to
    969   /// be lazily declared.
    970   bool needsImplicitDestructor() const {
    971     return !(data().DeclaredSpecialMembers & SMF_Destructor);
    972   }
    973 
    974   /// \brief Determine whether we need to eagerly declare a destructor for this
    975   /// class.
    976   bool needsOverloadResolutionForDestructor() const {
    977     return data().NeedOverloadResolutionForDestructor;
    978   }
    979 
    980   /// \brief Determine whether this class describes a lambda function object.
    981   bool isLambda() const { return hasDefinition() && data().IsLambda; }
    982 
    983   /// \brief For a closure type, retrieve the mapping from captured
    984   /// variables and this to the non-static data members that store the
    985   /// values or references of the captures.
    986   ///
    987   /// \param Captures Will be populated with the mapping from captured
    988   /// variables to the corresponding fields.
    989   ///
    990   /// \param ThisCapture Will be set to the field declaration for the
    991   /// 'this' capture.
    992   void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
    993                         FieldDecl *&ThisCapture) const;
    994 
    995   typedef const LambdaExpr::Capture* capture_const_iterator;
    996   capture_const_iterator captures_begin() const {
    997     return isLambda() ? getLambdaData().Captures : NULL;
    998   }
    999   capture_const_iterator captures_end() const {
   1000     return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
   1001   }
   1002 
   1003   typedef UnresolvedSetIterator conversion_iterator;
   1004   conversion_iterator conversion_begin() const {
   1005     return data().Conversions.begin();
   1006   }
   1007   conversion_iterator conversion_end() const {
   1008     return data().Conversions.end();
   1009   }
   1010 
   1011   /// Removes a conversion function from this class.  The conversion
   1012   /// function must currently be a member of this class.  Furthermore,
   1013   /// this class must currently be in the process of being defined.
   1014   void removeConversion(const NamedDecl *Old);
   1015 
   1016   /// getVisibleConversionFunctions - get all conversion functions visible
   1017   /// in current class; including conversion function templates.
   1018   std::pair<conversion_iterator, conversion_iterator>
   1019     getVisibleConversionFunctions();
   1020 
   1021   /// isAggregate - Whether this class is an aggregate (C++
   1022   /// [dcl.init.aggr]), which is a class with no user-declared
   1023   /// constructors, no private or protected non-static data members,
   1024   /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
   1025   bool isAggregate() const { return data().Aggregate; }
   1026 
   1027   /// hasInClassInitializer - Whether this class has any in-class initializers
   1028   /// for non-static data members.
   1029   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
   1030 
   1031   /// \brief Whether this class or any of its subobjects has any members of
   1032   /// reference type which would make value-initialization ill-formed, per
   1033   /// C++03 [dcl.init]p5:
   1034   ///  -- if T is a non-union class type without a user-declared constructor,
   1035   ///     then every non-static data member and base-class component of T is
   1036   ///     value-initialized
   1037   /// [...]
   1038   /// A program that calls for [...] value-initialization of an entity of
   1039   /// reference type is ill-formed.
   1040   bool hasUninitializedReferenceMember() const {
   1041     return !isUnion() && !hasUserDeclaredConstructor() &&
   1042            data().HasUninitializedReferenceMember;
   1043   }
   1044 
   1045   /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
   1046   /// that is an aggregate that has no non-static non-POD data members, no
   1047   /// reference data members, no user-defined copy assignment operator and no
   1048   /// user-defined destructor.
   1049   ///
   1050   /// Note that this is the C++ TR1 definition of POD.
   1051   bool isPOD() const { return data().PlainOldData; }
   1052 
   1053   /// \brief True if this class is C-like, without C++-specific features, e.g.
   1054   /// it contains only public fields, no bases, tag kind is not 'class', etc.
   1055   bool isCLike() const;
   1056 
   1057   /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
   1058   /// means it has a virtual function, virtual base, data member (other than
   1059   /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
   1060   /// a check for union-ness.
   1061   bool isEmpty() const { return data().Empty; }
   1062 
   1063   /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
   1064   /// which means that the class contains or inherits a virtual function.
   1065   bool isPolymorphic() const { return data().Polymorphic; }
   1066 
   1067   /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
   1068   /// which means that the class contains or inherits a pure virtual function.
   1069   bool isAbstract() const { return data().Abstract; }
   1070 
   1071   /// isStandardLayout - Whether this class has standard layout
   1072   /// (C++ [class]p7)
   1073   bool isStandardLayout() const { return data().IsStandardLayout; }
   1074 
   1075   /// \brief Whether this class, or any of its class subobjects, contains a
   1076   /// mutable field.
   1077   bool hasMutableFields() const { return data().HasMutableFields; }
   1078 
   1079   /// \brief Determine whether this class has a trivial default constructor
   1080   /// (C++11 [class.ctor]p5).
   1081   bool hasTrivialDefaultConstructor() const {
   1082     return hasDefaultConstructor() &&
   1083            (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
   1084   }
   1085 
   1086   /// \brief Determine whether this class has a non-trivial default constructor
   1087   /// (C++11 [class.ctor]p5).
   1088   bool hasNonTrivialDefaultConstructor() const {
   1089     return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
   1090            (needsImplicitDefaultConstructor() &&
   1091             !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
   1092   }
   1093 
   1094   /// \brief Determine whether this class has at least one constexpr constructor
   1095   /// other than the copy or move constructors.
   1096   bool hasConstexprNonCopyMoveConstructor() const {
   1097     return data().HasConstexprNonCopyMoveConstructor ||
   1098            (needsImplicitDefaultConstructor() &&
   1099             defaultedDefaultConstructorIsConstexpr());
   1100   }
   1101 
   1102   /// \brief Determine whether a defaulted default constructor for this class
   1103   /// would be constexpr.
   1104   bool defaultedDefaultConstructorIsConstexpr() const {
   1105     return data().DefaultedDefaultConstructorIsConstexpr &&
   1106            (!isUnion() || hasInClassInitializer());
   1107   }
   1108 
   1109   /// \brief Determine whether this class has a constexpr default constructor.
   1110   bool hasConstexprDefaultConstructor() const {
   1111     return data().HasConstexprDefaultConstructor ||
   1112            (needsImplicitDefaultConstructor() &&
   1113             defaultedDefaultConstructorIsConstexpr());
   1114   }
   1115 
   1116   /// \brief Determine whether this class has a trivial copy constructor
   1117   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   1118   bool hasTrivialCopyConstructor() const {
   1119     return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
   1120   }
   1121 
   1122   /// \brief Determine whether this class has a non-trivial copy constructor
   1123   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   1124   bool hasNonTrivialCopyConstructor() const {
   1125     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
   1126            !hasTrivialCopyConstructor();
   1127   }
   1128 
   1129   /// \brief Determine whether this class has a trivial move constructor
   1130   /// (C++11 [class.copy]p12)
   1131   bool hasTrivialMoveConstructor() const {
   1132     return hasMoveConstructor() &&
   1133            (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
   1134   }
   1135 
   1136   /// \brief Determine whether this class has a non-trivial move constructor
   1137   /// (C++11 [class.copy]p12)
   1138   bool hasNonTrivialMoveConstructor() const {
   1139     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
   1140            (needsImplicitMoveConstructor() &&
   1141             !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
   1142   }
   1143 
   1144   /// \brief Determine whether this class has a trivial copy assignment operator
   1145   /// (C++ [class.copy]p11, C++11 [class.copy]p25)
   1146   bool hasTrivialCopyAssignment() const {
   1147     return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
   1148   }
   1149 
   1150   /// \brief Determine whether this class has a non-trivial copy assignment
   1151   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
   1152   bool hasNonTrivialCopyAssignment() const {
   1153     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
   1154            !hasTrivialCopyAssignment();
   1155   }
   1156 
   1157   /// \brief Determine whether this class has a trivial move assignment operator
   1158   /// (C++11 [class.copy]p25)
   1159   bool hasTrivialMoveAssignment() const {
   1160     return hasMoveAssignment() &&
   1161            (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
   1162   }
   1163 
   1164   /// \brief Determine whether this class has a non-trivial move assignment
   1165   /// operator (C++11 [class.copy]p25)
   1166   bool hasNonTrivialMoveAssignment() const {
   1167     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
   1168            (needsImplicitMoveAssignment() &&
   1169             !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
   1170   }
   1171 
   1172   /// \brief Determine whether this class has a trivial destructor
   1173   /// (C++ [class.dtor]p3)
   1174   bool hasTrivialDestructor() const {
   1175     return data().HasTrivialSpecialMembers & SMF_Destructor;
   1176   }
   1177 
   1178   /// \brief Determine whether this class has a non-trivial destructor
   1179   /// (C++ [class.dtor]p3)
   1180   bool hasNonTrivialDestructor() const {
   1181     return !(data().HasTrivialSpecialMembers & SMF_Destructor);
   1182   }
   1183 
   1184   // hasIrrelevantDestructor - Whether this class has a destructor which has no
   1185   // semantic effect. Any such destructor will be trivial, public, defaulted
   1186   // and not deleted, and will call only irrelevant destructors.
   1187   bool hasIrrelevantDestructor() const {
   1188     return data().HasIrrelevantDestructor;
   1189   }
   1190 
   1191   // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or
   1192   // volatile type non-static data member or base class.
   1193   bool hasNonLiteralTypeFieldsOrBases() const {
   1194     return data().HasNonLiteralTypeFieldsOrBases;
   1195   }
   1196 
   1197   // isTriviallyCopyable - Whether this class is considered trivially copyable
   1198   // (C++0x [class]p6).
   1199   bool isTriviallyCopyable() const;
   1200 
   1201   // isTrivial - Whether this class is considered trivial
   1202   //
   1203   // C++0x [class]p6
   1204   //    A trivial class is a class that has a trivial default constructor and
   1205   //    is trivially copiable.
   1206   bool isTrivial() const {
   1207     return isTriviallyCopyable() && hasTrivialDefaultConstructor();
   1208   }
   1209 
   1210   // isLiteral - Whether this class is a literal type.
   1211   //
   1212   // C++11 [basic.types]p10
   1213   //   A class type that has all the following properties:
   1214   //     -- it has a trivial destructor
   1215   //     -- every constructor call and full-expression in the
   1216   //        brace-or-equal-intializers for non-static data members (if any) is
   1217   //        a constant expression.
   1218   //     -- it is an aggregate type or has at least one constexpr constructor or
   1219   //        constructor template that is not a copy or move constructor, and
   1220   //     -- all of its non-static data members and base classes are of literal
   1221   //        types
   1222   //
   1223   // We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
   1224   // treating types with trivial default constructors as literal types.
   1225   bool isLiteral() const {
   1226     return hasTrivialDestructor() &&
   1227            (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
   1228             hasTrivialDefaultConstructor()) &&
   1229            !hasNonLiteralTypeFieldsOrBases();
   1230   }
   1231 
   1232   /// \brief If this record is an instantiation of a member class,
   1233   /// retrieves the member class from which it was instantiated.
   1234   ///
   1235   /// This routine will return non-NULL for (non-templated) member
   1236   /// classes of class templates. For example, given:
   1237   ///
   1238   /// @code
   1239   /// template<typename T>
   1240   /// struct X {
   1241   ///   struct A { };
   1242   /// };
   1243   /// @endcode
   1244   ///
   1245   /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
   1246   /// whose parent is the class template specialization X<int>. For
   1247   /// this declaration, getInstantiatedFromMemberClass() will return
   1248   /// the CXXRecordDecl X<T>::A. When a complete definition of
   1249   /// X<int>::A is required, it will be instantiated from the
   1250   /// declaration returned by getInstantiatedFromMemberClass().
   1251   CXXRecordDecl *getInstantiatedFromMemberClass() const;
   1252 
   1253   /// \brief If this class is an instantiation of a member class of a
   1254   /// class template specialization, retrieves the member specialization
   1255   /// information.
   1256   MemberSpecializationInfo *getMemberSpecializationInfo() const {
   1257     return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
   1258   }
   1259 
   1260   /// \brief Specify that this record is an instantiation of the
   1261   /// member class RD.
   1262   void setInstantiationOfMemberClass(CXXRecordDecl *RD,
   1263                                      TemplateSpecializationKind TSK);
   1264 
   1265   /// \brief Retrieves the class template that is described by this
   1266   /// class declaration.
   1267   ///
   1268   /// Every class template is represented as a ClassTemplateDecl and a
   1269   /// CXXRecordDecl. The former contains template properties (such as
   1270   /// the template parameter lists) while the latter contains the
   1271   /// actual description of the template's
   1272   /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
   1273   /// CXXRecordDecl that from a ClassTemplateDecl, while
   1274   /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
   1275   /// a CXXRecordDecl.
   1276   ClassTemplateDecl *getDescribedClassTemplate() const {
   1277     return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
   1278   }
   1279 
   1280   void setDescribedClassTemplate(ClassTemplateDecl *Template) {
   1281     TemplateOrInstantiation = Template;
   1282   }
   1283 
   1284   /// \brief Determine whether this particular class is a specialization or
   1285   /// instantiation of a class template or member class of a class template,
   1286   /// and how it was instantiated or specialized.
   1287   TemplateSpecializationKind getTemplateSpecializationKind() const;
   1288 
   1289   /// \brief Set the kind of specialization or template instantiation this is.
   1290   void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
   1291 
   1292   /// getDestructor - Returns the destructor decl for this class.
   1293   CXXDestructorDecl *getDestructor() const;
   1294 
   1295   /// isLocalClass - If the class is a local class [class.local], returns
   1296   /// the enclosing function declaration.
   1297   const FunctionDecl *isLocalClass() const {
   1298     if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
   1299       return RD->isLocalClass();
   1300 
   1301     return dyn_cast<FunctionDecl>(getDeclContext());
   1302   }
   1303 
   1304   /// \brief Determine whether this dependent class is a current instantiation,
   1305   /// when viewed from within the given context.
   1306   bool isCurrentInstantiation(const DeclContext *CurContext) const;
   1307 
   1308   /// \brief Determine whether this class is derived from the class \p Base.
   1309   ///
   1310   /// This routine only determines whether this class is derived from \p Base,
   1311   /// but does not account for factors that may make a Derived -> Base class
   1312   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
   1313   /// base class subobjects.
   1314   ///
   1315   /// \param Base the base class we are searching for.
   1316   ///
   1317   /// \returns true if this class is derived from Base, false otherwise.
   1318   bool isDerivedFrom(const CXXRecordDecl *Base) const;
   1319 
   1320   /// \brief Determine whether this class is derived from the type \p Base.
   1321   ///
   1322   /// This routine only determines whether this class is derived from \p Base,
   1323   /// but does not account for factors that may make a Derived -> Base class
   1324   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
   1325   /// base class subobjects.
   1326   ///
   1327   /// \param Base the base class we are searching for.
   1328   ///
   1329   /// \param Paths will contain the paths taken from the current class to the
   1330   /// given \p Base class.
   1331   ///
   1332   /// \returns true if this class is derived from Base, false otherwise.
   1333   ///
   1334   /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
   1335   /// tangling input and output in \p Paths
   1336   bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
   1337 
   1338   /// \brief Determine whether this class is virtually derived from
   1339   /// the class \p Base.
   1340   ///
   1341   /// This routine only determines whether this class is virtually
   1342   /// derived from \p Base, but does not account for factors that may
   1343   /// make a Derived -> Base class ill-formed, such as
   1344   /// private/protected inheritance or multiple, ambiguous base class
   1345   /// subobjects.
   1346   ///
   1347   /// \param Base the base class we are searching for.
   1348   ///
   1349   /// \returns true if this class is virtually derived from Base,
   1350   /// false otherwise.
   1351   bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
   1352 
   1353   /// \brief Determine whether this class is provably not derived from
   1354   /// the type \p Base.
   1355   bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
   1356 
   1357   /// \brief Function type used by forallBases() as a callback.
   1358   ///
   1359   /// \param BaseDefinition the definition of the base class
   1360   ///
   1361   /// \returns true if this base matched the search criteria
   1362   typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
   1363                                    void *UserData);
   1364 
   1365   /// \brief Determines if the given callback holds for all the direct
   1366   /// or indirect base classes of this type.
   1367   ///
   1368   /// The class itself does not count as a base class.  This routine
   1369   /// returns false if the class has non-computable base classes.
   1370   ///
   1371   /// \param AllowShortCircuit if false, forces the callback to be called
   1372   /// for every base class, even if a dependent or non-matching base was
   1373   /// found.
   1374   bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
   1375                    bool AllowShortCircuit = true) const;
   1376 
   1377   /// \brief Function type used by lookupInBases() to determine whether a
   1378   /// specific base class subobject matches the lookup criteria.
   1379   ///
   1380   /// \param Specifier the base-class specifier that describes the inheritance
   1381   /// from the base class we are trying to match.
   1382   ///
   1383   /// \param Path the current path, from the most-derived class down to the
   1384   /// base named by the \p Specifier.
   1385   ///
   1386   /// \param UserData a single pointer to user-specified data, provided to
   1387   /// lookupInBases().
   1388   ///
   1389   /// \returns true if this base matched the search criteria, false otherwise.
   1390   typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
   1391                                    CXXBasePath &Path,
   1392                                    void *UserData);
   1393 
   1394   /// \brief Look for entities within the base classes of this C++ class,
   1395   /// transitively searching all base class subobjects.
   1396   ///
   1397   /// This routine uses the callback function \p BaseMatches to find base
   1398   /// classes meeting some search criteria, walking all base class subobjects
   1399   /// and populating the given \p Paths structure with the paths through the
   1400   /// inheritance hierarchy that resulted in a match. On a successful search,
   1401   /// the \p Paths structure can be queried to retrieve the matching paths and
   1402   /// to determine if there were any ambiguities.
   1403   ///
   1404   /// \param BaseMatches callback function used to determine whether a given
   1405   /// base matches the user-defined search criteria.
   1406   ///
   1407   /// \param UserData user data pointer that will be provided to \p BaseMatches.
   1408   ///
   1409   /// \param Paths used to record the paths from this class to its base class
   1410   /// subobjects that match the search criteria.
   1411   ///
   1412   /// \returns true if there exists any path from this class to a base class
   1413   /// subobject that matches the search criteria.
   1414   bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
   1415                      CXXBasePaths &Paths) const;
   1416 
   1417   /// \brief Base-class lookup callback that determines whether the given
   1418   /// base class specifier refers to a specific class declaration.
   1419   ///
   1420   /// This callback can be used with \c lookupInBases() to determine whether
   1421   /// a given derived class has is a base class subobject of a particular type.
   1422   /// The user data pointer should refer to the canonical CXXRecordDecl of the
   1423   /// base class that we are searching for.
   1424   static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
   1425                             CXXBasePath &Path, void *BaseRecord);
   1426 
   1427   /// \brief Base-class lookup callback that determines whether the
   1428   /// given base class specifier refers to a specific class
   1429   /// declaration and describes virtual derivation.
   1430   ///
   1431   /// This callback can be used with \c lookupInBases() to determine
   1432   /// whether a given derived class has is a virtual base class
   1433   /// subobject of a particular type.  The user data pointer should
   1434   /// refer to the canonical CXXRecordDecl of the base class that we
   1435   /// are searching for.
   1436   static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
   1437                                    CXXBasePath &Path, void *BaseRecord);
   1438 
   1439   /// \brief Base-class lookup callback that determines whether there exists
   1440   /// a tag with the given name.
   1441   ///
   1442   /// This callback can be used with \c lookupInBases() to find tag members
   1443   /// of the given name within a C++ class hierarchy. The user data pointer
   1444   /// is an opaque \c DeclarationName pointer.
   1445   static bool FindTagMember(const CXXBaseSpecifier *Specifier,
   1446                             CXXBasePath &Path, void *Name);
   1447 
   1448   /// \brief Base-class lookup callback that determines whether there exists
   1449   /// a member with the given name.
   1450   ///
   1451   /// This callback can be used with \c lookupInBases() to find members
   1452   /// of the given name within a C++ class hierarchy. The user data pointer
   1453   /// is an opaque \c DeclarationName pointer.
   1454   static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
   1455                                  CXXBasePath &Path, void *Name);
   1456 
   1457   /// \brief Base-class lookup callback that determines whether there exists
   1458   /// a member with the given name that can be used in a nested-name-specifier.
   1459   ///
   1460   /// This callback can be used with \c lookupInBases() to find membes of
   1461   /// the given name within a C++ class hierarchy that can occur within
   1462   /// nested-name-specifiers.
   1463   static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
   1464                                             CXXBasePath &Path,
   1465                                             void *UserData);
   1466 
   1467   /// \brief Retrieve the final overriders for each virtual member
   1468   /// function in the class hierarchy where this class is the
   1469   /// most-derived class in the class hierarchy.
   1470   void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
   1471 
   1472   /// \brief Get the indirect primary bases for this class.
   1473   void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
   1474 
   1475   /// viewInheritance - Renders and displays an inheritance diagram
   1476   /// for this C++ class and all of its base classes (transitively) using
   1477   /// GraphViz.
   1478   void viewInheritance(ASTContext& Context) const;
   1479 
   1480   /// MergeAccess - Calculates the access of a decl that is reached
   1481   /// along a path.
   1482   static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
   1483                                      AccessSpecifier DeclAccess) {
   1484     assert(DeclAccess != AS_none);
   1485     if (DeclAccess == AS_private) return AS_none;
   1486     return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
   1487   }
   1488 
   1489   /// \brief Indicates that the declaration of a defaulted or deleted special
   1490   /// member function is now complete.
   1491   void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
   1492 
   1493   /// \brief Indicates that the definition of this class is now complete.
   1494   virtual void completeDefinition();
   1495 
   1496   /// \brief Indicates that the definition of this class is now complete,
   1497   /// and provides a final overrider map to help determine
   1498   ///
   1499   /// \param FinalOverriders The final overrider map for this class, which can
   1500   /// be provided as an optimization for abstract-class checking. If NULL,
   1501   /// final overriders will be computed if they are needed to complete the
   1502   /// definition.
   1503   void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
   1504 
   1505   /// \brief Determine whether this class may end up being abstract, even though
   1506   /// it is not yet known to be abstract.
   1507   ///
   1508   /// \returns true if this class is not known to be abstract but has any
   1509   /// base classes that are abstract. In this case, \c completeDefinition()
   1510   /// will need to compute final overriders to determine whether the class is
   1511   /// actually abstract.
   1512   bool mayBeAbstract() const;
   1513 
   1514   /// \brief If this is the closure type of a lambda expression, retrieve the
   1515   /// number to be used for name mangling in the Itanium C++ ABI.
   1516   ///
   1517   /// Zero indicates that this closure type has internal linkage, so the
   1518   /// mangling number does not matter, while a non-zero value indicates which
   1519   /// lambda expression this is in this particular context.
   1520   unsigned getLambdaManglingNumber() const {
   1521     assert(isLambda() && "Not a lambda closure type!");
   1522     return getLambdaData().ManglingNumber;
   1523   }
   1524 
   1525   /// \brief Retrieve the declaration that provides additional context for a
   1526   /// lambda, when the normal declaration context is not specific enough.
   1527   ///
   1528   /// Certain contexts (default arguments of in-class function parameters and
   1529   /// the initializers of data members) have separate name mangling rules for
   1530   /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
   1531   /// the declaration in which the lambda occurs, e.g., the function parameter
   1532   /// or the non-static data member. Otherwise, it returns NULL to imply that
   1533   /// the declaration context suffices.
   1534   Decl *getLambdaContextDecl() const {
   1535     assert(isLambda() && "Not a lambda closure type!");
   1536     return getLambdaData().ContextDecl;
   1537   }
   1538 
   1539   /// \brief Set the mangling number and context declaration for a lambda
   1540   /// class.
   1541   void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
   1542     getLambdaData().ManglingNumber = ManglingNumber;
   1543     getLambdaData().ContextDecl = ContextDecl;
   1544   }
   1545 
   1546   /// \brief Determine whether this lambda expression was known to be dependent
   1547   /// at the time it was created, even if its context does not appear to be
   1548   /// dependent.
   1549   ///
   1550   /// This flag is a workaround for an issue with parsing, where default
   1551   /// arguments are parsed before their enclosing function declarations have
   1552   /// been created. This means that any lambda expressions within those
   1553   /// default arguments will have as their DeclContext the context enclosing
   1554   /// the function declaration, which may be non-dependent even when the
   1555   /// function declaration itself is dependent. This flag indicates when we
   1556   /// know that the lambda is dependent despite that.
   1557   bool isDependentLambda() const {
   1558     return isLambda() && getLambdaData().Dependent;
   1559   }
   1560 
   1561   TypeSourceInfo *getLambdaTypeInfo() const {
   1562     return getLambdaData().MethodTyInfo;
   1563   }
   1564 
   1565   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   1566   static bool classofKind(Kind K) {
   1567     return K >= firstCXXRecord && K <= lastCXXRecord;
   1568   }
   1569 
   1570   friend class ASTDeclReader;
   1571   friend class ASTDeclWriter;
   1572   friend class ASTReader;
   1573   friend class ASTWriter;
   1574 };
   1575 
   1576 /// CXXMethodDecl - Represents a static or instance method of a
   1577 /// struct/union/class.
   1578 class CXXMethodDecl : public FunctionDecl {
   1579   virtual void anchor();
   1580 protected:
   1581   CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
   1582                 const DeclarationNameInfo &NameInfo,
   1583                 QualType T, TypeSourceInfo *TInfo,
   1584                 bool isStatic, StorageClass SCAsWritten, bool isInline,
   1585                 bool isConstexpr, SourceLocation EndLocation)
   1586     : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
   1587                    (isStatic ? SC_Static : SC_None),
   1588                    SCAsWritten, isInline, isConstexpr) {
   1589     if (EndLocation.isValid())
   1590       setRangeEnd(EndLocation);
   1591   }
   1592 
   1593 public:
   1594   static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
   1595                                SourceLocation StartLoc,
   1596                                const DeclarationNameInfo &NameInfo,
   1597                                QualType T, TypeSourceInfo *TInfo,
   1598                                bool isStatic,
   1599                                StorageClass SCAsWritten,
   1600                                bool isInline,
   1601                                bool isConstexpr,
   1602                                SourceLocation EndLocation);
   1603 
   1604   static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   1605 
   1606   bool isStatic() const { return getStorageClass() == SC_Static; }
   1607   bool isInstance() const { return !isStatic(); }
   1608 
   1609   bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
   1610   bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
   1611 
   1612   bool isVirtual() const {
   1613     CXXMethodDecl *CD =
   1614       cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
   1615 
   1616     // Methods declared in interfaces are automatically (pure) virtual.
   1617     if (CD->isVirtualAsWritten() ||
   1618           (CD->getParent()->isInterface() && CD->isUserProvided()))
   1619       return true;
   1620 
   1621     return (CD->begin_overridden_methods() != CD->end_overridden_methods());
   1622   }
   1623 
   1624   /// \brief Determine whether this is a usual deallocation function
   1625   /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
   1626   /// delete or delete[] operator with a particular signature.
   1627   bool isUsualDeallocationFunction() const;
   1628 
   1629   /// \brief Determine whether this is a copy-assignment operator, regardless
   1630   /// of whether it was declared implicitly or explicitly.
   1631   bool isCopyAssignmentOperator() const;
   1632 
   1633   /// \brief Determine whether this is a move assignment operator.
   1634   bool isMoveAssignmentOperator() const;
   1635 
   1636   const CXXMethodDecl *getCanonicalDecl() const {
   1637     return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
   1638   }
   1639   CXXMethodDecl *getCanonicalDecl() {
   1640     return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
   1641   }
   1642 
   1643   /// isUserProvided - True if this method is user-declared and was not
   1644   /// deleted or defaulted on its first declaration.
   1645   bool isUserProvided() const {
   1646     return !(isDeleted() || getCanonicalDecl()->isDefaulted());
   1647   }
   1648 
   1649   ///
   1650   void addOverriddenMethod(const CXXMethodDecl *MD);
   1651 
   1652   typedef const CXXMethodDecl *const* method_iterator;
   1653 
   1654   method_iterator begin_overridden_methods() const;
   1655   method_iterator end_overridden_methods() const;
   1656   unsigned size_overridden_methods() const;
   1657 
   1658   /// getParent - Returns the parent of this method declaration, which
   1659   /// is the class in which this method is defined.
   1660   const CXXRecordDecl *getParent() const {
   1661     return cast<CXXRecordDecl>(FunctionDecl::getParent());
   1662   }
   1663 
   1664   /// getParent - Returns the parent of this method declaration, which
   1665   /// is the class in which this method is defined.
   1666   CXXRecordDecl *getParent() {
   1667     return const_cast<CXXRecordDecl *>(
   1668              cast<CXXRecordDecl>(FunctionDecl::getParent()));
   1669   }
   1670 
   1671   /// getThisType - Returns the type of 'this' pointer.
   1672   /// Should only be called for instance methods.
   1673   QualType getThisType(ASTContext &C) const;
   1674 
   1675   unsigned getTypeQualifiers() const {
   1676     return getType()->getAs<FunctionProtoType>()->getTypeQuals();
   1677   }
   1678 
   1679   /// \brief Retrieve the ref-qualifier associated with this method.
   1680   ///
   1681   /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
   1682   /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
   1683   /// @code
   1684   /// struct X {
   1685   ///   void f() &;
   1686   ///   void g() &&;
   1687   ///   void h();
   1688   /// };
   1689   /// @endcode
   1690   RefQualifierKind getRefQualifier() const {
   1691     return getType()->getAs<FunctionProtoType>()->getRefQualifier();
   1692   }
   1693 
   1694   bool hasInlineBody() const;
   1695 
   1696   /// \brief Determine whether this is a lambda closure type's static member
   1697   /// function that is used for the result of the lambda's conversion to
   1698   /// function pointer (for a lambda with no captures).
   1699   ///
   1700   /// The function itself, if used, will have a placeholder body that will be
   1701   /// supplied by IR generation to either forward to the function call operator
   1702   /// or clone the function call operator.
   1703   bool isLambdaStaticInvoker() const;
   1704 
   1705   /// \brief Find the method in RD that corresponds to this one.
   1706   ///
   1707   /// Find if RD or one of the classes it inherits from override this method.
   1708   /// If so, return it. RD is assumed to be a subclass of the class defining
   1709   /// this method (or be the class itself), unless MayBeBase is set to true.
   1710   CXXMethodDecl *
   1711   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
   1712                                 bool MayBeBase = false);
   1713 
   1714   const CXXMethodDecl *
   1715   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
   1716                                 bool MayBeBase = false) const {
   1717     return const_cast<CXXMethodDecl *>(this)
   1718               ->getCorrespondingMethodInClass(RD, MayBeBase);
   1719   }
   1720 
   1721   // Implement isa/cast/dyncast/etc.
   1722   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   1723   static bool classofKind(Kind K) {
   1724     return K >= firstCXXMethod && K <= lastCXXMethod;
   1725   }
   1726 };
   1727 
   1728 /// CXXCtorInitializer - Represents a C++ base or member
   1729 /// initializer, which is part of a constructor initializer that
   1730 /// initializes one non-static member variable or one base class. For
   1731 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
   1732 /// initializers:
   1733 ///
   1734 /// @code
   1735 /// class A { };
   1736 /// class B : public A {
   1737 ///   float f;
   1738 /// public:
   1739 ///   B(A& a) : A(a), f(3.14159) { }
   1740 /// };
   1741 /// @endcode
   1742 class CXXCtorInitializer {
   1743   /// \brief Either the base class name/delegating constructor type (stored as
   1744   /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
   1745   /// (IndirectFieldDecl*) being initialized.
   1746   llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
   1747     Initializee;
   1748 
   1749   /// \brief The source location for the field name or, for a base initializer
   1750   /// pack expansion, the location of the ellipsis. In the case of a delegating
   1751   /// constructor, it will still include the type's source location as the
   1752   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
   1753   SourceLocation MemberOrEllipsisLocation;
   1754 
   1755   /// \brief The argument used to initialize the base or member, which may
   1756   /// end up constructing an object (when multiple arguments are involved).
   1757   /// If 0, this is a field initializer, and the in-class member initializer
   1758   /// will be used.
   1759   Stmt *Init;
   1760 
   1761   /// LParenLoc - Location of the left paren of the ctor-initializer.
   1762   SourceLocation LParenLoc;
   1763 
   1764   /// RParenLoc - Location of the right paren of the ctor-initializer.
   1765   SourceLocation RParenLoc;
   1766 
   1767   /// \brief If the initializee is a type, whether that type makes this
   1768   /// a delegating initialization.
   1769   bool IsDelegating : 1;
   1770 
   1771   /// IsVirtual - If the initializer is a base initializer, this keeps track
   1772   /// of whether the base is virtual or not.
   1773   bool IsVirtual : 1;
   1774 
   1775   /// IsWritten - Whether or not the initializer is explicitly written
   1776   /// in the sources.
   1777   bool IsWritten : 1;
   1778 
   1779   /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
   1780   /// number keeps track of the textual order of this initializer in the
   1781   /// original sources, counting from 0; otherwise, if IsWritten is false,
   1782   /// it stores the number of array index variables stored after this
   1783   /// object in memory.
   1784   unsigned SourceOrderOrNumArrayIndices : 13;
   1785 
   1786   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
   1787                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
   1788                      SourceLocation R, VarDecl **Indices, unsigned NumIndices);
   1789 
   1790 public:
   1791   /// CXXCtorInitializer - Creates a new base-class initializer.
   1792   explicit
   1793   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
   1794                      SourceLocation L, Expr *Init, SourceLocation R,
   1795                      SourceLocation EllipsisLoc);
   1796 
   1797   /// CXXCtorInitializer - Creates a new member initializer.
   1798   explicit
   1799   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
   1800                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
   1801                      SourceLocation R);
   1802 
   1803   /// CXXCtorInitializer - Creates a new anonymous field initializer.
   1804   explicit
   1805   CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
   1806                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
   1807                      SourceLocation R);
   1808 
   1809   /// CXXCtorInitializer - Creates a new delegating Initializer.
   1810   explicit
   1811   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
   1812                      SourceLocation L, Expr *Init, SourceLocation R);
   1813 
   1814   /// \brief Creates a new member initializer that optionally contains
   1815   /// array indices used to describe an elementwise initialization.
   1816   static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
   1817                                     SourceLocation MemberLoc, SourceLocation L,
   1818                                     Expr *Init, SourceLocation R,
   1819                                     VarDecl **Indices, unsigned NumIndices);
   1820 
   1821   /// isBaseInitializer - Returns true when this initializer is
   1822   /// initializing a base class.
   1823   bool isBaseInitializer() const {
   1824     return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
   1825   }
   1826 
   1827   /// isMemberInitializer - Returns true when this initializer is
   1828   /// initializing a non-static data member.
   1829   bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
   1830 
   1831   bool isAnyMemberInitializer() const {
   1832     return isMemberInitializer() || isIndirectMemberInitializer();
   1833   }
   1834 
   1835   bool isIndirectMemberInitializer() const {
   1836     return Initializee.is<IndirectFieldDecl*>();
   1837   }
   1838 
   1839   /// isInClassMemberInitializer - Returns true when this initializer is an
   1840   /// implicit ctor initializer generated for a field with an initializer
   1841   /// defined on the member declaration.
   1842   bool isInClassMemberInitializer() const {
   1843     return !Init;
   1844   }
   1845 
   1846   /// isDelegatingInitializer - Returns true when this initializer is creating
   1847   /// a delegating constructor.
   1848   bool isDelegatingInitializer() const {
   1849     return Initializee.is<TypeSourceInfo*>() && IsDelegating;
   1850   }
   1851 
   1852   /// \brief Determine whether this initializer is a pack expansion.
   1853   bool isPackExpansion() const {
   1854     return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
   1855   }
   1856 
   1857   // \brief For a pack expansion, returns the location of the ellipsis.
   1858   SourceLocation getEllipsisLoc() const {
   1859     assert(isPackExpansion() && "Initializer is not a pack expansion");
   1860     return MemberOrEllipsisLocation;
   1861   }
   1862 
   1863   /// If this is a base class initializer, returns the type of the
   1864   /// base class with location information. Otherwise, returns an NULL
   1865   /// type location.
   1866   TypeLoc getBaseClassLoc() const;
   1867 
   1868   /// If this is a base class initializer, returns the type of the base class.
   1869   /// Otherwise, returns NULL.
   1870   const Type *getBaseClass() const;
   1871 
   1872   /// Returns whether the base is virtual or not.
   1873   bool isBaseVirtual() const {
   1874     assert(isBaseInitializer() && "Must call this on base initializer!");
   1875 
   1876     return IsVirtual;
   1877   }
   1878 
   1879   /// \brief Returns the declarator information for a base class or delegating
   1880   /// initializer.
   1881   TypeSourceInfo *getTypeSourceInfo() const {
   1882     return Initializee.dyn_cast<TypeSourceInfo *>();
   1883   }
   1884 
   1885   /// getMember - If this is a member initializer, returns the
   1886   /// declaration of the non-static data member being
   1887   /// initialized. Otherwise, returns NULL.
   1888   FieldDecl *getMember() const {
   1889     if (isMemberInitializer())
   1890       return Initializee.get<FieldDecl*>();
   1891     return 0;
   1892   }
   1893   FieldDecl *getAnyMember() const {
   1894     if (isMemberInitializer())
   1895       return Initializee.get<FieldDecl*>();
   1896     if (isIndirectMemberInitializer())
   1897       return Initializee.get<IndirectFieldDecl*>()->getAnonField();
   1898     return 0;
   1899   }
   1900 
   1901   IndirectFieldDecl *getIndirectMember() const {
   1902     if (isIndirectMemberInitializer())
   1903       return Initializee.get<IndirectFieldDecl*>();
   1904     return 0;
   1905   }
   1906 
   1907   SourceLocation getMemberLocation() const {
   1908     return MemberOrEllipsisLocation;
   1909   }
   1910 
   1911   /// \brief Determine the source location of the initializer.
   1912   SourceLocation getSourceLocation() const;
   1913 
   1914   /// \brief Determine the source range covering the entire initializer.
   1915   SourceRange getSourceRange() const LLVM_READONLY;
   1916 
   1917   /// isWritten - Returns true if this initializer is explicitly written
   1918   /// in the source code.
   1919   bool isWritten() const { return IsWritten; }
   1920 
   1921   /// \brief Return the source position of the initializer, counting from 0.
   1922   /// If the initializer was implicit, -1 is returned.
   1923   int getSourceOrder() const {
   1924     return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
   1925   }
   1926 
   1927   /// \brief Set the source order of this initializer. This method can only
   1928   /// be called once for each initializer; it cannot be called on an
   1929   /// initializer having a positive number of (implicit) array indices.
   1930   void setSourceOrder(int pos) {
   1931     assert(!IsWritten &&
   1932            "calling twice setSourceOrder() on the same initializer");
   1933     assert(SourceOrderOrNumArrayIndices == 0 &&
   1934            "setSourceOrder() used when there are implicit array indices");
   1935     assert(pos >= 0 &&
   1936            "setSourceOrder() used to make an initializer implicit");
   1937     IsWritten = true;
   1938     SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
   1939   }
   1940 
   1941   SourceLocation getLParenLoc() const { return LParenLoc; }
   1942   SourceLocation getRParenLoc() const { return RParenLoc; }
   1943 
   1944   /// \brief Determine the number of implicit array indices used while
   1945   /// described an array member initialization.
   1946   unsigned getNumArrayIndices() const {
   1947     return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
   1948   }
   1949 
   1950   /// \brief Retrieve a particular array index variable used to
   1951   /// describe an array member initialization.
   1952   VarDecl *getArrayIndex(unsigned I) {
   1953     assert(I < getNumArrayIndices() && "Out of bounds member array index");
   1954     return reinterpret_cast<VarDecl **>(this + 1)[I];
   1955   }
   1956   const VarDecl *getArrayIndex(unsigned I) const {
   1957     assert(I < getNumArrayIndices() && "Out of bounds member array index");
   1958     return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
   1959   }
   1960   void setArrayIndex(unsigned I, VarDecl *Index) {
   1961     assert(I < getNumArrayIndices() && "Out of bounds member array index");
   1962     reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
   1963   }
   1964   ArrayRef<VarDecl *> getArrayIndexes() {
   1965     assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
   1966     return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
   1967                                getNumArrayIndices());
   1968   }
   1969 
   1970   /// \brief Get the initializer. This is 0 if this is an in-class initializer
   1971   /// for a non-static data member which has not yet been parsed.
   1972   Expr *getInit() const {
   1973     if (!Init)
   1974       return getAnyMember()->getInClassInitializer();
   1975 
   1976     return static_cast<Expr*>(Init);
   1977   }
   1978 };
   1979 
   1980 /// CXXConstructorDecl - Represents a C++ constructor within a
   1981 /// class. For example:
   1982 ///
   1983 /// @code
   1984 /// class X {
   1985 /// public:
   1986 ///   explicit X(int); // represented by a CXXConstructorDecl.
   1987 /// };
   1988 /// @endcode
   1989 class CXXConstructorDecl : public CXXMethodDecl {
   1990   virtual void anchor();
   1991   /// IsExplicitSpecified - Whether this constructor declaration has the
   1992   /// 'explicit' keyword specified.
   1993   bool IsExplicitSpecified : 1;
   1994 
   1995   /// ImplicitlyDefined - Whether this constructor was implicitly
   1996   /// defined by the compiler. When false, the constructor was defined
   1997   /// by the user. In C++03, this flag will have the same value as
   1998   /// Implicit. In C++0x, however, a constructor that is
   1999   /// explicitly defaulted (i.e., defined with " = default") will have
   2000   /// @c !Implicit && ImplicitlyDefined.
   2001   bool ImplicitlyDefined : 1;
   2002 
   2003   /// Support for base and member initializers.
   2004   /// CtorInitializers - The arguments used to initialize the base
   2005   /// or member.
   2006   CXXCtorInitializer **CtorInitializers;
   2007   unsigned NumCtorInitializers;
   2008 
   2009   CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
   2010                      const DeclarationNameInfo &NameInfo,
   2011                      QualType T, TypeSourceInfo *TInfo,
   2012                      bool isExplicitSpecified, bool isInline,
   2013                      bool isImplicitlyDeclared, bool isConstexpr)
   2014     : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
   2015                     SC_None, isInline, isConstexpr, SourceLocation()),
   2016       IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
   2017       CtorInitializers(0), NumCtorInitializers(0) {
   2018     setImplicit(isImplicitlyDeclared);
   2019   }
   2020 
   2021 public:
   2022   static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2023   static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
   2024                                     SourceLocation StartLoc,
   2025                                     const DeclarationNameInfo &NameInfo,
   2026                                     QualType T, TypeSourceInfo *TInfo,
   2027                                     bool isExplicit,
   2028                                     bool isInline, bool isImplicitlyDeclared,
   2029                                     bool isConstexpr);
   2030 
   2031   /// isExplicitSpecified - Whether this constructor declaration has the
   2032   /// 'explicit' keyword specified.
   2033   bool isExplicitSpecified() const { return IsExplicitSpecified; }
   2034 
   2035   /// isExplicit - Whether this constructor was marked "explicit" or not.
   2036   bool isExplicit() const {
   2037     return cast<CXXConstructorDecl>(getFirstDeclaration())
   2038       ->isExplicitSpecified();
   2039   }
   2040 
   2041   /// isImplicitlyDefined - Whether this constructor was implicitly
   2042   /// defined. If false, then this constructor was defined by the
   2043   /// user. This operation can only be invoked if the constructor has
   2044   /// already been defined.
   2045   bool isImplicitlyDefined() const {
   2046     assert(isThisDeclarationADefinition() &&
   2047            "Can only get the implicit-definition flag once the "
   2048            "constructor has been defined");
   2049     return ImplicitlyDefined;
   2050   }
   2051 
   2052   /// setImplicitlyDefined - Set whether this constructor was
   2053   /// implicitly defined or not.
   2054   void setImplicitlyDefined(bool ID) {
   2055     assert(isThisDeclarationADefinition() &&
   2056            "Can only set the implicit-definition flag once the constructor "
   2057            "has been defined");
   2058     ImplicitlyDefined = ID;
   2059   }
   2060 
   2061   /// init_iterator - Iterates through the member/base initializer list.
   2062   typedef CXXCtorInitializer **init_iterator;
   2063 
   2064   /// init_const_iterator - Iterates through the memberbase initializer list.
   2065   typedef CXXCtorInitializer * const * init_const_iterator;
   2066 
   2067   /// init_begin() - Retrieve an iterator to the first initializer.
   2068   init_iterator       init_begin()       { return CtorInitializers; }
   2069   /// begin() - Retrieve an iterator to the first initializer.
   2070   init_const_iterator init_begin() const { return CtorInitializers; }
   2071 
   2072   /// init_end() - Retrieve an iterator past the last initializer.
   2073   init_iterator       init_end()       {
   2074     return CtorInitializers + NumCtorInitializers;
   2075   }
   2076   /// end() - Retrieve an iterator past the last initializer.
   2077   init_const_iterator init_end() const {
   2078     return CtorInitializers + NumCtorInitializers;
   2079   }
   2080 
   2081   typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
   2082   typedef std::reverse_iterator<init_const_iterator>
   2083           init_const_reverse_iterator;
   2084 
   2085   init_reverse_iterator init_rbegin() {
   2086     return init_reverse_iterator(init_end());
   2087   }
   2088   init_const_reverse_iterator init_rbegin() const {
   2089     return init_const_reverse_iterator(init_end());
   2090   }
   2091 
   2092   init_reverse_iterator init_rend() {
   2093     return init_reverse_iterator(init_begin());
   2094   }
   2095   init_const_reverse_iterator init_rend() const {
   2096     return init_const_reverse_iterator(init_begin());
   2097   }
   2098 
   2099   /// getNumArgs - Determine the number of arguments used to
   2100   /// initialize the member or base.
   2101   unsigned getNumCtorInitializers() const {
   2102       return NumCtorInitializers;
   2103   }
   2104 
   2105   void setNumCtorInitializers(unsigned numCtorInitializers) {
   2106     NumCtorInitializers = numCtorInitializers;
   2107   }
   2108 
   2109   void setCtorInitializers(CXXCtorInitializer ** initializers) {
   2110     CtorInitializers = initializers;
   2111   }
   2112 
   2113   /// isDelegatingConstructor - Whether this constructor is a
   2114   /// delegating constructor
   2115   bool isDelegatingConstructor() const {
   2116     return (getNumCtorInitializers() == 1) &&
   2117       CtorInitializers[0]->isDelegatingInitializer();
   2118   }
   2119 
   2120   /// getTargetConstructor - When this constructor delegates to
   2121   /// another, retrieve the target
   2122   CXXConstructorDecl *getTargetConstructor() const;
   2123 
   2124   /// isDefaultConstructor - Whether this constructor is a default
   2125   /// constructor (C++ [class.ctor]p5), which can be used to
   2126   /// default-initialize a class of this type.
   2127   bool isDefaultConstructor() const;
   2128 
   2129   /// isCopyConstructor - Whether this constructor is a copy
   2130   /// constructor (C++ [class.copy]p2, which can be used to copy the
   2131   /// class. @p TypeQuals will be set to the qualifiers on the
   2132   /// argument type. For example, @p TypeQuals would be set to @c
   2133   /// Qualifiers::Const for the following copy constructor:
   2134   ///
   2135   /// @code
   2136   /// class X {
   2137   /// public:
   2138   ///   X(const X&);
   2139   /// };
   2140   /// @endcode
   2141   bool isCopyConstructor(unsigned &TypeQuals) const;
   2142 
   2143   /// isCopyConstructor - Whether this constructor is a copy
   2144   /// constructor (C++ [class.copy]p2, which can be used to copy the
   2145   /// class.
   2146   bool isCopyConstructor() const {
   2147     unsigned TypeQuals = 0;
   2148     return isCopyConstructor(TypeQuals);
   2149   }
   2150 
   2151   /// \brief Determine whether this constructor is a move constructor
   2152   /// (C++0x [class.copy]p3), which can be used to move values of the class.
   2153   ///
   2154   /// \param TypeQuals If this constructor is a move constructor, will be set
   2155   /// to the type qualifiers on the referent of the first parameter's type.
   2156   bool isMoveConstructor(unsigned &TypeQuals) const;
   2157 
   2158   /// \brief Determine whether this constructor is a move constructor
   2159   /// (C++0x [class.copy]p3), which can be used to move values of the class.
   2160   bool isMoveConstructor() const {
   2161     unsigned TypeQuals = 0;
   2162     return isMoveConstructor(TypeQuals);
   2163   }
   2164 
   2165   /// \brief Determine whether this is a copy or move constructor.
   2166   ///
   2167   /// \param TypeQuals Will be set to the type qualifiers on the reference
   2168   /// parameter, if in fact this is a copy or move constructor.
   2169   bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
   2170 
   2171   /// \brief Determine whether this a copy or move constructor.
   2172   bool isCopyOrMoveConstructor() const {
   2173     unsigned Quals;
   2174     return isCopyOrMoveConstructor(Quals);
   2175   }
   2176 
   2177   /// isConvertingConstructor - Whether this constructor is a
   2178   /// converting constructor (C++ [class.conv.ctor]), which can be
   2179   /// used for user-defined conversions.
   2180   bool isConvertingConstructor(bool AllowExplicit) const;
   2181 
   2182   /// \brief Determine whether this is a member template specialization that
   2183   /// would copy the object to itself. Such constructors are never used to copy
   2184   /// an object.
   2185   bool isSpecializationCopyingObject() const;
   2186 
   2187   /// \brief Get the constructor that this inheriting constructor is based on.
   2188   const CXXConstructorDecl *getInheritedConstructor() const;
   2189 
   2190   /// \brief Set the constructor that this inheriting constructor is based on.
   2191   void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
   2192 
   2193   const CXXConstructorDecl *getCanonicalDecl() const {
   2194     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
   2195   }
   2196   CXXConstructorDecl *getCanonicalDecl() {
   2197     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
   2198   }
   2199 
   2200   // Implement isa/cast/dyncast/etc.
   2201   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2202   static bool classofKind(Kind K) { return K == CXXConstructor; }
   2203 
   2204   friend class ASTDeclReader;
   2205   friend class ASTDeclWriter;
   2206 };
   2207 
   2208 /// CXXDestructorDecl - Represents a C++ destructor within a
   2209 /// class. For example:
   2210 ///
   2211 /// @code
   2212 /// class X {
   2213 /// public:
   2214 ///   ~X(); // represented by a CXXDestructorDecl.
   2215 /// };
   2216 /// @endcode
   2217 class CXXDestructorDecl : public CXXMethodDecl {
   2218   virtual void anchor();
   2219   /// ImplicitlyDefined - Whether this destructor was implicitly
   2220   /// defined by the compiler. When false, the destructor was defined
   2221   /// by the user. In C++03, this flag will have the same value as
   2222   /// Implicit. In C++0x, however, a destructor that is
   2223   /// explicitly defaulted (i.e., defined with " = default") will have
   2224   /// @c !Implicit && ImplicitlyDefined.
   2225   bool ImplicitlyDefined : 1;
   2226 
   2227   FunctionDecl *OperatorDelete;
   2228 
   2229   CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
   2230                     const DeclarationNameInfo &NameInfo,
   2231                     QualType T, TypeSourceInfo *TInfo,
   2232                     bool isInline, bool isImplicitlyDeclared)
   2233     : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
   2234                     SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
   2235       ImplicitlyDefined(false), OperatorDelete(0) {
   2236     setImplicit(isImplicitlyDeclared);
   2237   }
   2238 
   2239 public:
   2240   static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
   2241                                    SourceLocation StartLoc,
   2242                                    const DeclarationNameInfo &NameInfo,
   2243                                    QualType T, TypeSourceInfo* TInfo,
   2244                                    bool isInline,
   2245                                    bool isImplicitlyDeclared);
   2246   static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
   2247 
   2248   /// isImplicitlyDefined - Whether this destructor was implicitly
   2249   /// defined. If false, then this destructor was defined by the
   2250   /// user. This operation can only be invoked if the destructor has
   2251   /// already been defined.
   2252   bool isImplicitlyDefined() const {
   2253     assert(isThisDeclarationADefinition() &&
   2254            "Can only get the implicit-definition flag once the destructor has "
   2255            "been defined");
   2256     return ImplicitlyDefined;
   2257   }
   2258 
   2259   /// setImplicitlyDefined - Set whether this destructor was
   2260   /// implicitly defined or not.
   2261   void setImplicitlyDefined(bool ID) {
   2262     assert(isThisDeclarationADefinition() &&
   2263            "Can only set the implicit-definition flag once the destructor has "
   2264            "been defined");
   2265     ImplicitlyDefined = ID;
   2266   }
   2267 
   2268   void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
   2269   const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   2270 
   2271   // Implement isa/cast/dyncast/etc.
   2272   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2273   static bool classofKind(Kind K) { return K == CXXDestructor; }
   2274 
   2275   friend class ASTDeclReader;
   2276   friend class ASTDeclWriter;
   2277 };
   2278 
   2279 /// CXXConversionDecl - Represents a C++ conversion function within a
   2280 /// class. For example:
   2281 ///
   2282 /// @code
   2283 /// class X {
   2284 /// public:
   2285 ///   operator bool();
   2286 /// };
   2287 /// @endcode
   2288 class CXXConversionDecl : public CXXMethodDecl {
   2289   virtual void anchor();
   2290   /// IsExplicitSpecified - Whether this conversion function declaration is
   2291   /// marked "explicit", meaning that it can only be applied when the user
   2292   /// explicitly wrote a cast. This is a C++0x feature.
   2293   bool IsExplicitSpecified : 1;
   2294 
   2295   CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
   2296                     const DeclarationNameInfo &NameInfo,
   2297                     QualType T, TypeSourceInfo *TInfo,
   2298                     bool isInline, bool isExplicitSpecified,
   2299                     bool isConstexpr, SourceLocation EndLocation)
   2300     : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
   2301                     SC_None, isInline, isConstexpr, EndLocation),
   2302       IsExplicitSpecified(isExplicitSpecified) { }
   2303 
   2304 public:
   2305   static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
   2306                                    SourceLocation StartLoc,
   2307                                    const DeclarationNameInfo &NameInfo,
   2308                                    QualType T, TypeSourceInfo *TInfo,
   2309                                    bool isInline, bool isExplicit,
   2310                                    bool isConstexpr,
   2311                                    SourceLocation EndLocation);
   2312   static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2313 
   2314   /// IsExplicitSpecified - Whether this conversion function declaration is
   2315   /// marked "explicit", meaning that it can only be applied when the user
   2316   /// explicitly wrote a cast. This is a C++0x feature.
   2317   bool isExplicitSpecified() const { return IsExplicitSpecified; }
   2318 
   2319   /// isExplicit - Whether this is an explicit conversion operator
   2320   /// (C++0x only). Explicit conversion operators are only considered
   2321   /// when the user has explicitly written a cast.
   2322   bool isExplicit() const {
   2323     return cast<CXXConversionDecl>(getFirstDeclaration())
   2324       ->isExplicitSpecified();
   2325   }
   2326 
   2327   /// getConversionType - Returns the type that this conversion
   2328   /// function is converting to.
   2329   QualType getConversionType() const {
   2330     return getType()->getAs<FunctionType>()->getResultType();
   2331   }
   2332 
   2333   /// \brief Determine whether this conversion function is a conversion from
   2334   /// a lambda closure type to a block pointer.
   2335   bool isLambdaToBlockPointerConversion() const;
   2336 
   2337   // Implement isa/cast/dyncast/etc.
   2338   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2339   static bool classofKind(Kind K) { return K == CXXConversion; }
   2340 
   2341   friend class ASTDeclReader;
   2342   friend class ASTDeclWriter;
   2343 };
   2344 
   2345 /// LinkageSpecDecl - This represents a linkage specification.  For example:
   2346 ///   extern "C" void foo();
   2347 ///
   2348 class LinkageSpecDecl : public Decl, public DeclContext {
   2349   virtual void anchor();
   2350 public:
   2351   /// LanguageIDs - Used to represent the language in a linkage
   2352   /// specification.  The values are part of the serialization abi for
   2353   /// ASTs and cannot be changed without altering that abi.  To help
   2354   /// ensure a stable abi for this, we choose the DW_LANG_ encodings
   2355   /// from the dwarf standard.
   2356   enum LanguageIDs {
   2357     lang_c = /* DW_LANG_C */ 0x0002,
   2358     lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
   2359   };
   2360 private:
   2361   /// Language - The language for this linkage specification.
   2362   LanguageIDs Language;
   2363   /// ExternLoc - The source location for the extern keyword.
   2364   SourceLocation ExternLoc;
   2365   /// RBraceLoc - The source location for the right brace (if valid).
   2366   SourceLocation RBraceLoc;
   2367 
   2368   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
   2369                   SourceLocation LangLoc, LanguageIDs lang,
   2370                   SourceLocation RBLoc)
   2371     : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
   2372       Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
   2373 
   2374 public:
   2375   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
   2376                                  SourceLocation ExternLoc,
   2377                                  SourceLocation LangLoc, LanguageIDs Lang,
   2378                                  SourceLocation RBraceLoc = SourceLocation());
   2379   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2380 
   2381   /// \brief Return the language specified by this linkage specification.
   2382   LanguageIDs getLanguage() const { return Language; }
   2383   /// \brief Set the language specified by this linkage specification.
   2384   void setLanguage(LanguageIDs L) { Language = L; }
   2385 
   2386   /// \brief Determines whether this linkage specification had braces in
   2387   /// its syntactic form.
   2388   bool hasBraces() const { return RBraceLoc.isValid(); }
   2389 
   2390   SourceLocation getExternLoc() const { return ExternLoc; }
   2391   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   2392   void setExternLoc(SourceLocation L) { ExternLoc = L; }
   2393   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
   2394 
   2395   SourceLocation getLocEnd() const LLVM_READONLY {
   2396     if (hasBraces())
   2397       return getRBraceLoc();
   2398     // No braces: get the end location of the (only) declaration in context
   2399     // (if present).
   2400     return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
   2401   }
   2402 
   2403   SourceRange getSourceRange() const LLVM_READONLY {
   2404     return SourceRange(ExternLoc, getLocEnd());
   2405   }
   2406 
   2407   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2408   static bool classofKind(Kind K) { return K == LinkageSpec; }
   2409   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
   2410     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
   2411   }
   2412   static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
   2413     return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
   2414   }
   2415 };
   2416 
   2417 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
   2418 ///
   2419 ///    using namespace std;
   2420 ///
   2421 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
   2422 // artificial names for all using-directives in order to store
   2423 // them in DeclContext effectively.
   2424 class UsingDirectiveDecl : public NamedDecl {
   2425   virtual void anchor();
   2426   /// \brief The location of the "using" keyword.
   2427   SourceLocation UsingLoc;
   2428 
   2429   /// SourceLocation - Location of 'namespace' token.
   2430   SourceLocation NamespaceLoc;
   2431 
   2432   /// \brief The nested-name-specifier that precedes the namespace.
   2433   NestedNameSpecifierLoc QualifierLoc;
   2434 
   2435   /// NominatedNamespace - Namespace nominated by using-directive.
   2436   NamedDecl *NominatedNamespace;
   2437 
   2438   /// Enclosing context containing both using-directive and nominated
   2439   /// namespace.
   2440   DeclContext *CommonAncestor;
   2441 
   2442   /// getUsingDirectiveName - Returns special DeclarationName used by
   2443   /// using-directives. This is only used by DeclContext for storing
   2444   /// UsingDirectiveDecls in its lookup structure.
   2445   static DeclarationName getName() {
   2446     return DeclarationName::getUsingDirectiveName();
   2447   }
   2448 
   2449   UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
   2450                      SourceLocation NamespcLoc,
   2451                      NestedNameSpecifierLoc QualifierLoc,
   2452                      SourceLocation IdentLoc,
   2453                      NamedDecl *Nominated,
   2454                      DeclContext *CommonAncestor)
   2455     : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
   2456       NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
   2457       NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
   2458 
   2459 public:
   2460   /// \brief Retrieve the nested-name-specifier that qualifies the
   2461   /// name of the namespace, with source-location information.
   2462   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2463 
   2464   /// \brief Retrieve the nested-name-specifier that qualifies the
   2465   /// name of the namespace.
   2466   NestedNameSpecifier *getQualifier() const {
   2467     return QualifierLoc.getNestedNameSpecifier();
   2468   }
   2469 
   2470   NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
   2471   const NamedDecl *getNominatedNamespaceAsWritten() const {
   2472     return NominatedNamespace;
   2473   }
   2474 
   2475   /// getNominatedNamespace - Returns namespace nominated by using-directive.
   2476   NamespaceDecl *getNominatedNamespace();
   2477 
   2478   const NamespaceDecl *getNominatedNamespace() const {
   2479     return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
   2480   }
   2481 
   2482   /// \brief Returns the common ancestor context of this using-directive and
   2483   /// its nominated namespace.
   2484   DeclContext *getCommonAncestor() { return CommonAncestor; }
   2485   const DeclContext *getCommonAncestor() const { return CommonAncestor; }
   2486 
   2487   /// \brief Return the location of the "using" keyword.
   2488   SourceLocation getUsingLoc() const { return UsingLoc; }
   2489 
   2490   // FIXME: Could omit 'Key' in name.
   2491   /// getNamespaceKeyLocation - Returns location of namespace keyword.
   2492   SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
   2493 
   2494   /// getIdentLocation - Returns location of identifier.
   2495   SourceLocation getIdentLocation() const { return getLocation(); }
   2496 
   2497   static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
   2498                                     SourceLocation UsingLoc,
   2499                                     SourceLocation NamespaceLoc,
   2500                                     NestedNameSpecifierLoc QualifierLoc,
   2501                                     SourceLocation IdentLoc,
   2502                                     NamedDecl *Nominated,
   2503                                     DeclContext *CommonAncestor);
   2504   static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2505 
   2506   SourceRange getSourceRange() const LLVM_READONLY {
   2507     return SourceRange(UsingLoc, getLocation());
   2508   }
   2509 
   2510   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2511   static bool classofKind(Kind K) { return K == UsingDirective; }
   2512 
   2513   // Friend for getUsingDirectiveName.
   2514   friend class DeclContext;
   2515 
   2516   friend class ASTDeclReader;
   2517 };
   2518 
   2519 /// \brief Represents a C++ namespace alias.
   2520 ///
   2521 /// For example:
   2522 ///
   2523 /// @code
   2524 /// namespace Foo = Bar;
   2525 /// @endcode
   2526 class NamespaceAliasDecl : public NamedDecl {
   2527   virtual void anchor();
   2528 
   2529   /// \brief The location of the "namespace" keyword.
   2530   SourceLocation NamespaceLoc;
   2531 
   2532   /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
   2533   SourceLocation IdentLoc;
   2534 
   2535   /// \brief The nested-name-specifier that precedes the namespace.
   2536   NestedNameSpecifierLoc QualifierLoc;
   2537 
   2538   /// Namespace - The Decl that this alias points to. Can either be a
   2539   /// NamespaceDecl or a NamespaceAliasDecl.
   2540   NamedDecl *Namespace;
   2541 
   2542   NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
   2543                      SourceLocation AliasLoc, IdentifierInfo *Alias,
   2544                      NestedNameSpecifierLoc QualifierLoc,
   2545                      SourceLocation IdentLoc, NamedDecl *Namespace)
   2546     : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
   2547       NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
   2548       QualifierLoc(QualifierLoc), Namespace(Namespace) { }
   2549 
   2550   friend class ASTDeclReader;
   2551 
   2552 public:
   2553   /// \brief Retrieve the nested-name-specifier that qualifies the
   2554   /// name of the namespace, with source-location information.
   2555   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2556 
   2557   /// \brief Retrieve the nested-name-specifier that qualifies the
   2558   /// name of the namespace.
   2559   NestedNameSpecifier *getQualifier() const {
   2560     return QualifierLoc.getNestedNameSpecifier();
   2561   }
   2562 
   2563   /// \brief Retrieve the namespace declaration aliased by this directive.
   2564   NamespaceDecl *getNamespace() {
   2565     if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
   2566       return AD->getNamespace();
   2567 
   2568     return cast<NamespaceDecl>(Namespace);
   2569   }
   2570 
   2571   const NamespaceDecl *getNamespace() const {
   2572     return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
   2573   }
   2574 
   2575   /// Returns the location of the alias name, i.e. 'foo' in
   2576   /// "namespace foo = ns::bar;".
   2577   SourceLocation getAliasLoc() const { return getLocation(); }
   2578 
   2579   /// Returns the location of the 'namespace' keyword.
   2580   SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
   2581 
   2582   /// Returns the location of the identifier in the named namespace.
   2583   SourceLocation getTargetNameLoc() const { return IdentLoc; }
   2584 
   2585   /// \brief Retrieve the namespace that this alias refers to, which
   2586   /// may either be a NamespaceDecl or a NamespaceAliasDecl.
   2587   NamedDecl *getAliasedNamespace() const { return Namespace; }
   2588 
   2589   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
   2590                                     SourceLocation NamespaceLoc,
   2591                                     SourceLocation AliasLoc,
   2592                                     IdentifierInfo *Alias,
   2593                                     NestedNameSpecifierLoc QualifierLoc,
   2594                                     SourceLocation IdentLoc,
   2595                                     NamedDecl *Namespace);
   2596 
   2597   static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2598 
   2599   virtual SourceRange getSourceRange() const LLVM_READONLY {
   2600     return SourceRange(NamespaceLoc, IdentLoc);
   2601   }
   2602 
   2603   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2604   static bool classofKind(Kind K) { return K == NamespaceAlias; }
   2605 };
   2606 
   2607 /// \brief Represents a shadow declaration introduced into a scope by a
   2608 /// (resolved) using declaration.
   2609 ///
   2610 /// For example,
   2611 /// @code
   2612 /// namespace A {
   2613 ///   void foo();
   2614 /// }
   2615 /// namespace B {
   2616 ///   using A::foo; // <- a UsingDecl
   2617 ///                 // Also creates a UsingShadowDecl for A::foo() in B
   2618 /// }
   2619 /// @endcode
   2620 class UsingShadowDecl : public NamedDecl {
   2621   virtual void anchor();
   2622 
   2623   /// The referenced declaration.
   2624   NamedDecl *Underlying;
   2625 
   2626   /// \brief The using declaration which introduced this decl or the next using
   2627   /// shadow declaration contained in the aforementioned using declaration.
   2628   NamedDecl *UsingOrNextShadow;
   2629   friend class UsingDecl;
   2630 
   2631   UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
   2632                   NamedDecl *Target)
   2633     : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
   2634       Underlying(Target),
   2635       UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
   2636     if (Target) {
   2637       setDeclName(Target->getDeclName());
   2638       IdentifierNamespace = Target->getIdentifierNamespace();
   2639     }
   2640     setImplicit();
   2641   }
   2642 
   2643 public:
   2644   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
   2645                                  SourceLocation Loc, UsingDecl *Using,
   2646                                  NamedDecl *Target) {
   2647     return new (C) UsingShadowDecl(DC, Loc, Using, Target);
   2648   }
   2649 
   2650   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2651 
   2652   /// \brief Gets the underlying declaration which has been brought into the
   2653   /// local scope.
   2654   NamedDecl *getTargetDecl() const { return Underlying; }
   2655 
   2656   /// \brief Sets the underlying declaration which has been brought into the
   2657   /// local scope.
   2658   void setTargetDecl(NamedDecl* ND) {
   2659     assert(ND && "Target decl is null!");
   2660     Underlying = ND;
   2661     IdentifierNamespace = ND->getIdentifierNamespace();
   2662   }
   2663 
   2664   /// \brief Gets the using declaration to which this declaration is tied.
   2665   UsingDecl *getUsingDecl() const;
   2666 
   2667   /// \brief The next using shadow declaration contained in the shadow decl
   2668   /// chain of the using declaration which introduced this decl.
   2669   UsingShadowDecl *getNextUsingShadowDecl() const {
   2670     return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
   2671   }
   2672 
   2673   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2674   static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
   2675 
   2676   friend class ASTDeclReader;
   2677   friend class ASTDeclWriter;
   2678 };
   2679 
   2680 /// \brief Represents a C++ using-declaration.
   2681 ///
   2682 /// For example:
   2683 /// @code
   2684 ///    using someNameSpace::someIdentifier;
   2685 /// @endcode
   2686 class UsingDecl : public NamedDecl {
   2687   virtual void anchor();
   2688 
   2689   /// \brief The source location of the "using" location itself.
   2690   SourceLocation UsingLocation;
   2691 
   2692   /// \brief The nested-name-specifier that precedes the name.
   2693   NestedNameSpecifierLoc QualifierLoc;
   2694 
   2695   /// DNLoc - Provides source/type location info for the
   2696   /// declaration name embedded in the ValueDecl base class.
   2697   DeclarationNameLoc DNLoc;
   2698 
   2699   /// \brief The first shadow declaration of the shadow decl chain associated
   2700   /// with this using declaration.
   2701   ///
   2702   /// The bool member of the pair store whether this decl has the \c typename
   2703   /// keyword.
   2704   llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
   2705 
   2706   UsingDecl(DeclContext *DC, SourceLocation UL,
   2707             NestedNameSpecifierLoc QualifierLoc,
   2708             const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
   2709     : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
   2710       UsingLocation(UL), QualifierLoc(QualifierLoc),
   2711       DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) {
   2712   }
   2713 
   2714 public:
   2715   /// \brief Returns the source location of the "using" keyword.
   2716   SourceLocation getUsingLocation() const { return UsingLocation; }
   2717 
   2718   /// \brief Set the source location of the 'using' keyword.
   2719   void setUsingLocation(SourceLocation L) { UsingLocation = L; }
   2720 
   2721   /// \brief Retrieve the nested-name-specifier that qualifies the name,
   2722   /// with source-location information.
   2723   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2724 
   2725   /// \brief Retrieve the nested-name-specifier that qualifies the name.
   2726   NestedNameSpecifier *getQualifier() const {
   2727     return QualifierLoc.getNestedNameSpecifier();
   2728   }
   2729 
   2730   DeclarationNameInfo getNameInfo() const {
   2731     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
   2732   }
   2733 
   2734   /// \brief Return true if the using declaration has 'typename'.
   2735   bool isTypeName() const { return FirstUsingShadow.getInt(); }
   2736 
   2737   /// \brief Sets whether the using declaration has 'typename'.
   2738   void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); }
   2739 
   2740   /// \brief Iterates through the using shadow declarations assosiated with
   2741   /// this using declaration.
   2742   class shadow_iterator {
   2743     /// \brief The current using shadow declaration.
   2744     UsingShadowDecl *Current;
   2745 
   2746   public:
   2747     typedef UsingShadowDecl*          value_type;
   2748     typedef UsingShadowDecl*          reference;
   2749     typedef UsingShadowDecl*          pointer;
   2750     typedef std::forward_iterator_tag iterator_category;
   2751     typedef std::ptrdiff_t            difference_type;
   2752 
   2753     shadow_iterator() : Current(0) { }
   2754     explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
   2755 
   2756     reference operator*() const { return Current; }
   2757     pointer operator->() const { return Current; }
   2758 
   2759     shadow_iterator& operator++() {
   2760       Current = Current->getNextUsingShadowDecl();
   2761       return *this;
   2762     }
   2763 
   2764     shadow_iterator operator++(int) {
   2765       shadow_iterator tmp(*this);
   2766       ++(*this);
   2767       return tmp;
   2768     }
   2769 
   2770     friend bool operator==(shadow_iterator x, shadow_iterator y) {
   2771       return x.Current == y.Current;
   2772     }
   2773     friend bool operator!=(shadow_iterator x, shadow_iterator y) {
   2774       return x.Current != y.Current;
   2775     }
   2776   };
   2777 
   2778   shadow_iterator shadow_begin() const {
   2779     return shadow_iterator(FirstUsingShadow.getPointer());
   2780   }
   2781   shadow_iterator shadow_end() const { return shadow_iterator(); }
   2782 
   2783   /// \brief Return the number of shadowed declarations associated with this
   2784   /// using declaration.
   2785   unsigned shadow_size() const {
   2786     return std::distance(shadow_begin(), shadow_end());
   2787   }
   2788 
   2789   void addShadowDecl(UsingShadowDecl *S);
   2790   void removeShadowDecl(UsingShadowDecl *S);
   2791 
   2792   static UsingDecl *Create(ASTContext &C, DeclContext *DC,
   2793                            SourceLocation UsingL,
   2794                            NestedNameSpecifierLoc QualifierLoc,
   2795                            const DeclarationNameInfo &NameInfo,
   2796                            bool IsTypeNameArg);
   2797 
   2798   static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2799 
   2800   SourceRange getSourceRange() const LLVM_READONLY {
   2801     return SourceRange(UsingLocation, getNameInfo().getEndLoc());
   2802   }
   2803 
   2804   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2805   static bool classofKind(Kind K) { return K == Using; }
   2806 
   2807   friend class ASTDeclReader;
   2808   friend class ASTDeclWriter;
   2809 };
   2810 
   2811 /// \brief Represents a dependent using declaration which was not marked with
   2812 /// \c typename.
   2813 ///
   2814 /// Unlike non-dependent using declarations, these *only* bring through
   2815 /// non-types; otherwise they would break two-phase lookup.
   2816 ///
   2817 /// @code
   2818 /// template \<class T> class A : public Base<T> {
   2819 ///   using Base<T>::foo;
   2820 /// };
   2821 /// @endcode
   2822 class UnresolvedUsingValueDecl : public ValueDecl {
   2823   virtual void anchor();
   2824 
   2825   /// \brief The source location of the 'using' keyword
   2826   SourceLocation UsingLocation;
   2827 
   2828   /// \brief The nested-name-specifier that precedes the name.
   2829   NestedNameSpecifierLoc QualifierLoc;
   2830 
   2831   /// DNLoc - Provides source/type location info for the
   2832   /// declaration name embedded in the ValueDecl base class.
   2833   DeclarationNameLoc DNLoc;
   2834 
   2835   UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
   2836                            SourceLocation UsingLoc,
   2837                            NestedNameSpecifierLoc QualifierLoc,
   2838                            const DeclarationNameInfo &NameInfo)
   2839     : ValueDecl(UnresolvedUsingValue, DC,
   2840                 NameInfo.getLoc(), NameInfo.getName(), Ty),
   2841       UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
   2842       DNLoc(NameInfo.getInfo())
   2843   { }
   2844 
   2845 public:
   2846   /// \brief Returns the source location of the 'using' keyword.
   2847   SourceLocation getUsingLoc() const { return UsingLocation; }
   2848 
   2849   /// \brief Set the source location of the 'using' keyword.
   2850   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
   2851 
   2852   /// \brief Retrieve the nested-name-specifier that qualifies the name,
   2853   /// with source-location information.
   2854   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2855 
   2856   /// \brief Retrieve the nested-name-specifier that qualifies the name.
   2857   NestedNameSpecifier *getQualifier() const {
   2858     return QualifierLoc.getNestedNameSpecifier();
   2859   }
   2860 
   2861   DeclarationNameInfo getNameInfo() const {
   2862     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
   2863   }
   2864 
   2865   static UnresolvedUsingValueDecl *
   2866     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
   2867            NestedNameSpecifierLoc QualifierLoc,
   2868            const DeclarationNameInfo &NameInfo);
   2869 
   2870   static UnresolvedUsingValueDecl *
   2871   CreateDeserialized(ASTContext &C, unsigned ID);
   2872 
   2873   SourceRange getSourceRange() const LLVM_READONLY {
   2874     return SourceRange(UsingLocation, getNameInfo().getEndLoc());
   2875   }
   2876 
   2877   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2878   static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
   2879 
   2880   friend class ASTDeclReader;
   2881   friend class ASTDeclWriter;
   2882 };
   2883 
   2884 /// @brief Represents a dependent using declaration which was marked with
   2885 /// \c typename.
   2886 ///
   2887 /// @code
   2888 /// template \<class T> class A : public Base<T> {
   2889 ///   using typename Base<T>::foo;
   2890 /// };
   2891 /// @endcode
   2892 ///
   2893 /// The type associated with an unresolved using typename decl is
   2894 /// currently always a typename type.
   2895 class UnresolvedUsingTypenameDecl : public TypeDecl {
   2896   virtual void anchor();
   2897 
   2898   /// \brief The source location of the 'using' keyword
   2899   SourceLocation UsingLocation;
   2900 
   2901   /// \brief The source location of the 'typename' keyword
   2902   SourceLocation TypenameLocation;
   2903 
   2904   /// \brief The nested-name-specifier that precedes the name.
   2905   NestedNameSpecifierLoc QualifierLoc;
   2906 
   2907   UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
   2908                               SourceLocation TypenameLoc,
   2909                               NestedNameSpecifierLoc QualifierLoc,
   2910                               SourceLocation TargetNameLoc,
   2911                               IdentifierInfo *TargetName)
   2912     : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
   2913                UsingLoc),
   2914       TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
   2915 
   2916   friend class ASTDeclReader;
   2917 
   2918 public:
   2919   /// \brief Returns the source location of the 'using' keyword.
   2920   SourceLocation getUsingLoc() const { return getLocStart(); }
   2921 
   2922   /// \brief Returns the source location of the 'typename' keyword.
   2923   SourceLocation getTypenameLoc() const { return TypenameLocation; }
   2924 
   2925   /// \brief Retrieve the nested-name-specifier that qualifies the name,
   2926   /// with source-location information.
   2927   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2928 
   2929   /// \brief Retrieve the nested-name-specifier that qualifies the name.
   2930   NestedNameSpecifier *getQualifier() const {
   2931     return QualifierLoc.getNestedNameSpecifier();
   2932   }
   2933 
   2934   static UnresolvedUsingTypenameDecl *
   2935     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
   2936            SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
   2937            SourceLocation TargetNameLoc, DeclarationName TargetName);
   2938 
   2939   static UnresolvedUsingTypenameDecl *
   2940   CreateDeserialized(ASTContext &C, unsigned ID);
   2941 
   2942   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2943   static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
   2944 };
   2945 
   2946 /// \brief Represents a C++11 static_assert declaration.
   2947 class StaticAssertDecl : public Decl {
   2948   virtual void anchor();
   2949   llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
   2950   StringLiteral *Message;
   2951   SourceLocation RParenLoc;
   2952 
   2953   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
   2954                    Expr *AssertExpr, StringLiteral *Message,
   2955                    SourceLocation RParenLoc, bool Failed)
   2956     : Decl(StaticAssert, DC, StaticAssertLoc),
   2957       AssertExprAndFailed(AssertExpr, Failed), Message(Message),
   2958       RParenLoc(RParenLoc) { }
   2959 
   2960 public:
   2961   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
   2962                                   SourceLocation StaticAssertLoc,
   2963                                   Expr *AssertExpr, StringLiteral *Message,
   2964                                   SourceLocation RParenLoc, bool Failed);
   2965   static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   2966 
   2967   Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
   2968   const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
   2969 
   2970   StringLiteral *getMessage() { return Message; }
   2971   const StringLiteral *getMessage() const { return Message; }
   2972 
   2973   bool isFailed() const { return AssertExprAndFailed.getInt(); }
   2974 
   2975   SourceLocation getRParenLoc() const { return RParenLoc; }
   2976 
   2977   SourceRange getSourceRange() const LLVM_READONLY {
   2978     return SourceRange(getLocation(), getRParenLoc());
   2979   }
   2980 
   2981   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   2982   static bool classofKind(Kind K) { return K == StaticAssert; }
   2983 
   2984   friend class ASTDeclReader;
   2985 };
   2986 
   2987 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
   2988 /// into a diagnostic with <<.
   2989 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
   2990                                     AccessSpecifier AS);
   2991 
   2992 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
   2993                                     AccessSpecifier AS);
   2994 
   2995 } // end namespace clang
   2996 
   2997 #endif
   2998