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