clang API Documentation

DeclCXX.h
Go to the documentation of this file.
00001 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Defines the C++ Decl subclasses, other than those for templates
00012 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
00013 ///
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_AST_DECLCXX_H
00017 #define LLVM_CLANG_AST_DECLCXX_H
00018 
00019 #include "clang/AST/ASTUnresolvedSet.h"
00020 #include "clang/AST/Attr.h"
00021 #include "clang/AST/Decl.h"
00022 #include "clang/AST/Expr.h"
00023 #include "clang/AST/LambdaCapture.h"
00024 #include "llvm/ADT/DenseMap.h"
00025 #include "llvm/ADT/PointerIntPair.h"
00026 #include "llvm/Support/Compiler.h"
00027 
00028 namespace clang {
00029 
00030 class ClassTemplateDecl;
00031 class ClassTemplateSpecializationDecl;
00032 class CXXBasePath;
00033 class CXXBasePaths;
00034 class CXXConstructorDecl;
00035 class CXXConversionDecl;
00036 class CXXDestructorDecl;
00037 class CXXMethodDecl;
00038 class CXXRecordDecl;
00039 class CXXMemberLookupCriteria;
00040 class CXXFinalOverriderMap;
00041 class CXXIndirectPrimaryBaseSet;
00042 class FriendDecl;
00043 class LambdaExpr;
00044 class UsingDecl;
00045 
00046 /// \brief Represents any kind of function declaration, whether it is a
00047 /// concrete function or a function template.
00048 class AnyFunctionDecl {
00049   NamedDecl *Function;
00050 
00051   AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
00052 
00053 public:
00054   AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
00055   AnyFunctionDecl(FunctionTemplateDecl *FTD);
00056 
00057   /// \brief Implicily converts any function or function template into a
00058   /// named declaration.
00059   operator NamedDecl *() const { return Function; }
00060 
00061   /// \brief Retrieve the underlying function or function template.
00062   NamedDecl *get() const { return Function; }
00063 
00064   static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
00065     return AnyFunctionDecl(ND);
00066   }
00067 };
00068 
00069 } // end namespace clang
00070 
00071 namespace llvm {
00072   // Provide PointerLikeTypeTraits for non-cvr pointers.
00073   template<>
00074   class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
00075   public:
00076     static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
00077       return F.get();
00078     }
00079     static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
00080       return ::clang::AnyFunctionDecl::getFromNamedDecl(
00081                                       static_cast< ::clang::NamedDecl*>(P));
00082     }
00083 
00084     enum { NumLowBitsAvailable = 2 };
00085   };
00086 
00087 } // end namespace llvm
00088 
00089 namespace clang {
00090 
00091 /// \brief Represents an access specifier followed by colon ':'.
00092 ///
00093 /// An objects of this class represents sugar for the syntactic occurrence
00094 /// of an access specifier followed by a colon in the list of member
00095 /// specifiers of a C++ class definition.
00096 ///
00097 /// Note that they do not represent other uses of access specifiers,
00098 /// such as those occurring in a list of base specifiers.
00099 /// Also note that this class has nothing to do with so-called
00100 /// "access declarations" (C++98 11.3 [class.access.dcl]).
00101 class AccessSpecDecl : public Decl {
00102   virtual void anchor();
00103   /// \brief The location of the ':'.
00104   SourceLocation ColonLoc;
00105 
00106   AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
00107                  SourceLocation ASLoc, SourceLocation ColonLoc)
00108     : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
00109     setAccess(AS);
00110   }
00111   AccessSpecDecl(EmptyShell Empty)
00112     : Decl(AccessSpec, Empty) { }
00113 public:
00114   /// \brief The location of the access specifier.
00115   SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
00116   /// \brief Sets the location of the access specifier.
00117   void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
00118 
00119   /// \brief The location of the colon following the access specifier.
00120   SourceLocation getColonLoc() const { return ColonLoc; }
00121   /// \brief Sets the location of the colon.
00122   void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
00123 
00124   SourceRange getSourceRange() const override LLVM_READONLY {
00125     return SourceRange(getAccessSpecifierLoc(), getColonLoc());
00126   }
00127 
00128   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
00129                                 DeclContext *DC, SourceLocation ASLoc,
00130                                 SourceLocation ColonLoc) {
00131     return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
00132   }
00133   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00134 
00135   // Implement isa/cast/dyncast/etc.
00136   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00137   static bool classofKind(Kind K) { return K == AccessSpec; }
00138 };
00139 
00140 
00141 /// \brief Represents a base class of a C++ class.
00142 ///
00143 /// Each CXXBaseSpecifier represents a single, direct base class (or
00144 /// struct) of a C++ class (or struct). It specifies the type of that
00145 /// base class, whether it is a virtual or non-virtual base, and what
00146 /// level of access (public, protected, private) is used for the
00147 /// derivation. For example:
00148 ///
00149 /// \code
00150 ///   class A { };
00151 ///   class B { };
00152 ///   class C : public virtual A, protected B { };
00153 /// \endcode
00154 ///
00155 /// In this code, C will have two CXXBaseSpecifiers, one for "public
00156 /// virtual A" and the other for "protected B".
00157 class CXXBaseSpecifier {
00158   /// \brief The source code range that covers the full base
00159   /// specifier, including the "virtual" (if present) and access
00160   /// specifier (if present).
00161   SourceRange Range;
00162 
00163   /// \brief The source location of the ellipsis, if this is a pack
00164   /// expansion.
00165   SourceLocation EllipsisLoc;
00166 
00167   /// \brief Whether this is a virtual base class or not.
00168   bool Virtual : 1;
00169 
00170   /// \brief Whether this is the base of a class (true) or of a struct (false).
00171   ///
00172   /// This determines the mapping from the access specifier as written in the
00173   /// source code to the access specifier used for semantic analysis.
00174   bool BaseOfClass : 1;
00175 
00176   /// \brief Access specifier as written in the source code (may be AS_none).
00177   ///
00178   /// The actual type of data stored here is an AccessSpecifier, but we use
00179   /// "unsigned" here to work around a VC++ bug.
00180   unsigned Access : 2;
00181 
00182   /// \brief Whether the class contains a using declaration
00183   /// to inherit the named class's constructors.
00184   bool InheritConstructors : 1;
00185 
00186   /// \brief The type of the base class.
00187   ///
00188   /// This will be a class or struct (or a typedef of such). The source code
00189   /// range does not include the \c virtual or the access specifier.
00190   TypeSourceInfo *BaseTypeInfo;
00191 
00192 public:
00193   CXXBaseSpecifier() { }
00194 
00195   CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
00196                    TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
00197     : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
00198       Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
00199 
00200   /// \brief Retrieves the source range that contains the entire base specifier.
00201   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
00202   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00203   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00204 
00205   /// \brief Determines whether the base class is a virtual base class (or not).
00206   bool isVirtual() const { return Virtual; }
00207 
00208   /// \brief Determine whether this base class is a base of a class declared
00209   /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
00210   bool isBaseOfClass() const { return BaseOfClass; }
00211 
00212   /// \brief Determine whether this base specifier is a pack expansion.
00213   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
00214 
00215   /// \brief Determine whether this base class's constructors get inherited.
00216   bool getInheritConstructors() const { return InheritConstructors; }
00217 
00218   /// \brief Set that this base class's constructors should be inherited.
00219   void setInheritConstructors(bool Inherit = true) {
00220     InheritConstructors = Inherit;
00221   }
00222 
00223   /// \brief For a pack expansion, determine the location of the ellipsis.
00224   SourceLocation getEllipsisLoc() const {
00225     return EllipsisLoc;
00226   }
00227 
00228   /// \brief Returns the access specifier for this base specifier. 
00229   ///
00230   /// This is the actual base specifier as used for semantic analysis, so
00231   /// the result can never be AS_none. To retrieve the access specifier as
00232   /// written in the source code, use getAccessSpecifierAsWritten().
00233   AccessSpecifier getAccessSpecifier() const {
00234     if ((AccessSpecifier)Access == AS_none)
00235       return BaseOfClass? AS_private : AS_public;
00236     else
00237       return (AccessSpecifier)Access;
00238   }
00239 
00240   /// \brief Retrieves the access specifier as written in the source code
00241   /// (which may mean that no access specifier was explicitly written).
00242   ///
00243   /// Use getAccessSpecifier() to retrieve the access specifier for use in
00244   /// semantic analysis.
00245   AccessSpecifier getAccessSpecifierAsWritten() const {
00246     return (AccessSpecifier)Access;
00247   }
00248 
00249   /// \brief Retrieves the type of the base class.
00250   ///
00251   /// This type will always be an unqualified class type.
00252   QualType getType() const {
00253     return BaseTypeInfo->getType().getUnqualifiedType();
00254   }
00255 
00256   /// \brief Retrieves the type and source location of the base class.
00257   TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
00258 };
00259 
00260 /// \brief A lazy pointer to the definition data for a declaration.
00261 /// FIXME: This is a little CXXRecordDecl-specific that the moment.
00262 template<typename Decl, typename T> class LazyDefinitionDataPtr {
00263   llvm::PointerUnion<T *, Decl *> DataOrCanonicalDecl;
00264 
00265   LazyDefinitionDataPtr update() {
00266     if (Decl *Canon = DataOrCanonicalDecl.template dyn_cast<Decl*>()) {
00267       if (Canon->isCanonicalDecl())
00268         Canon->getMostRecentDecl();
00269       else
00270         // Declaration isn't canonical any more;
00271         // update it and perform path compression.
00272         *this = Canon->getPreviousDecl()->DefinitionData.update();
00273     }
00274     return *this;
00275   }
00276 
00277 public:
00278   LazyDefinitionDataPtr(Decl *Canon) : DataOrCanonicalDecl(Canon) {}
00279   LazyDefinitionDataPtr(T *Data) : DataOrCanonicalDecl(Data) {}
00280   T *getNotUpdated() { return DataOrCanonicalDecl.template dyn_cast<T*>(); }
00281   T *get() { return update().getNotUpdated(); }
00282 };
00283 
00284 /// \brief Represents a C++ struct/union/class.
00285 class CXXRecordDecl : public RecordDecl {
00286 
00287   friend void TagDecl::startDefinition();
00288 
00289   /// Values used in DefinitionData fields to represent special members.
00290   enum SpecialMemberFlags {
00291     SMF_DefaultConstructor = 0x1,
00292     SMF_CopyConstructor = 0x2,
00293     SMF_MoveConstructor = 0x4,
00294     SMF_CopyAssignment = 0x8,
00295     SMF_MoveAssignment = 0x10,
00296     SMF_Destructor = 0x20,
00297     SMF_All = 0x3f
00298   };
00299 
00300   struct DefinitionData {
00301     DefinitionData(CXXRecordDecl *D);
00302 
00303     /// \brief True if this class has any user-declared constructors.
00304     bool UserDeclaredConstructor : 1;
00305 
00306     /// \brief The user-declared special members which this class has.
00307     unsigned UserDeclaredSpecialMembers : 6;
00308 
00309     /// \brief True when this class is an aggregate.
00310     bool Aggregate : 1;
00311 
00312     /// \brief True when this class is a POD-type.
00313     bool PlainOldData : 1;
00314 
00315     /// true when this class is empty for traits purposes,
00316     /// i.e. has no data members other than 0-width bit-fields, has no
00317     /// virtual function/base, and doesn't inherit from a non-empty
00318     /// class. Doesn't take union-ness into account.
00319     bool Empty : 1;
00320 
00321     /// \brief True when this class is polymorphic, i.e., has at
00322     /// least one virtual member or derives from a polymorphic class.
00323     bool Polymorphic : 1;
00324 
00325     /// \brief True when this class is abstract, i.e., has at least
00326     /// one pure virtual function, (that can come from a base class).
00327     bool Abstract : 1;
00328 
00329     /// \brief True when this class has standard layout.
00330     ///
00331     /// C++11 [class]p7.  A standard-layout class is a class that:
00332     /// * has no non-static data members of type non-standard-layout class (or
00333     ///   array of such types) or reference,
00334     /// * has no virtual functions (10.3) and no virtual base classes (10.1),
00335     /// * has the same access control (Clause 11) for all non-static data
00336     ///   members
00337     /// * has no non-standard-layout base classes,
00338     /// * either has no non-static data members in the most derived class and at
00339     ///   most one base class with non-static data members, or has no base
00340     ///   classes with non-static data members, and
00341     /// * has no base classes of the same type as the first non-static data
00342     ///   member.
00343     bool IsStandardLayout : 1;
00344 
00345     /// \brief True when there are no non-empty base classes.
00346     ///
00347     /// This is a helper bit of state used to implement IsStandardLayout more
00348     /// efficiently.
00349     bool HasNoNonEmptyBases : 1;
00350 
00351     /// \brief True when there are private non-static data members.
00352     bool HasPrivateFields : 1;
00353 
00354     /// \brief True when there are protected non-static data members.
00355     bool HasProtectedFields : 1;
00356 
00357     /// \brief True when there are private non-static data members.
00358     bool HasPublicFields : 1;
00359 
00360     /// \brief True if this class (or any subobject) has mutable fields.
00361     bool HasMutableFields : 1;
00362 
00363     /// \brief True if this class (or any nested anonymous struct or union)
00364     /// has variant members.
00365     bool HasVariantMembers : 1;
00366 
00367     /// \brief True if there no non-field members declared by the user.
00368     bool HasOnlyCMembers : 1;
00369 
00370     /// \brief True if any field has an in-class initializer, including those
00371     /// within anonymous unions or structs.
00372     bool HasInClassInitializer : 1;
00373 
00374     /// \brief True if any field is of reference type, and does not have an
00375     /// in-class initializer.
00376     ///
00377     /// In this case, value-initialization of this class is illegal in C++98
00378     /// even if the class has a trivial default constructor.
00379     bool HasUninitializedReferenceMember : 1;
00380 
00381     /// \brief These flags are \c true if a defaulted corresponding special
00382     /// member can't be fully analyzed without performing overload resolution.
00383     /// @{
00384     bool NeedOverloadResolutionForMoveConstructor : 1;
00385     bool NeedOverloadResolutionForMoveAssignment : 1;
00386     bool NeedOverloadResolutionForDestructor : 1;
00387     /// @}
00388 
00389     /// \brief These flags are \c true if an implicit defaulted corresponding
00390     /// special member would be defined as deleted.
00391     /// @{
00392     bool DefaultedMoveConstructorIsDeleted : 1;
00393     bool DefaultedMoveAssignmentIsDeleted : 1;
00394     bool DefaultedDestructorIsDeleted : 1;
00395     /// @}
00396 
00397     /// \brief The trivial special members which this class has, per
00398     /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
00399     /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
00400     ///
00401     /// This excludes any user-declared but not user-provided special members
00402     /// which have been declared but not yet defined.
00403     unsigned HasTrivialSpecialMembers : 6;
00404 
00405     /// \brief The declared special members of this class which are known to be
00406     /// non-trivial.
00407     ///
00408     /// This excludes any user-declared but not user-provided special members
00409     /// which have been declared but not yet defined, and any implicit special
00410     /// members which have not yet been declared.
00411     unsigned DeclaredNonTrivialSpecialMembers : 6;
00412 
00413     /// \brief True when this class has a destructor with no semantic effect.
00414     bool HasIrrelevantDestructor : 1;
00415 
00416     /// \brief True when this class has at least one user-declared constexpr
00417     /// constructor which is neither the copy nor move constructor.
00418     bool HasConstexprNonCopyMoveConstructor : 1;
00419 
00420     /// \brief True if a defaulted default constructor for this class would
00421     /// be constexpr.
00422     bool DefaultedDefaultConstructorIsConstexpr : 1;
00423 
00424     /// \brief True if this class has a constexpr default constructor.
00425     ///
00426     /// This is true for either a user-declared constexpr default constructor
00427     /// or an implicitly declared constexpr default constructor.
00428     bool HasConstexprDefaultConstructor : 1;
00429 
00430     /// \brief True when this class contains at least one non-static data
00431     /// member or base class of non-literal or volatile type.
00432     bool HasNonLiteralTypeFieldsOrBases : 1;
00433 
00434     /// \brief True when visible conversion functions are already computed
00435     /// and are available.
00436     bool ComputedVisibleConversions : 1;
00437 
00438     /// \brief Whether we have a C++11 user-provided default constructor (not
00439     /// explicitly deleted or defaulted).
00440     bool UserProvidedDefaultConstructor : 1;
00441 
00442     /// \brief The special members which have been declared for this class,
00443     /// either by the user or implicitly.
00444     unsigned DeclaredSpecialMembers : 6;
00445 
00446     /// \brief Whether an implicit copy constructor would have a const-qualified
00447     /// parameter.
00448     bool ImplicitCopyConstructorHasConstParam : 1;
00449 
00450     /// \brief Whether an implicit copy assignment operator would have a
00451     /// const-qualified parameter.
00452     bool ImplicitCopyAssignmentHasConstParam : 1;
00453 
00454     /// \brief Whether any declared copy constructor has a const-qualified
00455     /// parameter.
00456     bool HasDeclaredCopyConstructorWithConstParam : 1;
00457 
00458     /// \brief Whether any declared copy assignment operator has either a
00459     /// const-qualified reference parameter or a non-reference parameter.
00460     bool HasDeclaredCopyAssignmentWithConstParam : 1;
00461 
00462     /// \brief Whether this class describes a C++ lambda.
00463     bool IsLambda : 1;
00464 
00465     /// \brief Whether we are currently parsing base specifiers.
00466     bool IsParsingBaseSpecifiers : 1;
00467 
00468     /// \brief The number of base class specifiers in Bases.
00469     unsigned NumBases;
00470 
00471     /// \brief The number of virtual base class specifiers in VBases.
00472     unsigned NumVBases;
00473 
00474     /// \brief Base classes of this class.
00475     ///
00476     /// FIXME: This is wasted space for a union.
00477     LazyCXXBaseSpecifiersPtr Bases;
00478 
00479     /// \brief direct and indirect virtual base classes of this class.
00480     LazyCXXBaseSpecifiersPtr VBases;
00481 
00482     /// \brief The conversion functions of this C++ class (but not its
00483     /// inherited conversion functions).
00484     ///
00485     /// Each of the entries in this overload set is a CXXConversionDecl.
00486     LazyASTUnresolvedSet Conversions;
00487 
00488     /// \brief The conversion functions of this C++ class and all those
00489     /// inherited conversion functions that are visible in this class.
00490     ///
00491     /// Each of the entries in this overload set is a CXXConversionDecl or a
00492     /// FunctionTemplateDecl.
00493     LazyASTUnresolvedSet VisibleConversions;
00494 
00495     /// \brief The declaration which defines this record.
00496     CXXRecordDecl *Definition;
00497 
00498     /// \brief The first friend declaration in this class, or null if there
00499     /// aren't any. 
00500     ///
00501     /// This is actually currently stored in reverse order.
00502     LazyDeclPtr FirstFriend;
00503 
00504     /// \brief Retrieve the set of direct base classes.
00505     CXXBaseSpecifier *getBases() const {
00506       if (!Bases.isOffset())
00507         return Bases.get(nullptr);
00508       return getBasesSlowCase();
00509     }
00510 
00511     /// \brief Retrieve the set of virtual base classes.
00512     CXXBaseSpecifier *getVBases() const {
00513       if (!VBases.isOffset())
00514         return VBases.get(nullptr);
00515       return getVBasesSlowCase();
00516     }
00517 
00518   private:
00519     CXXBaseSpecifier *getBasesSlowCase() const;
00520     CXXBaseSpecifier *getVBasesSlowCase() const;
00521   };
00522 
00523   typedef LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>
00524       DefinitionDataPtr;
00525   friend class LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>;
00526 
00527   mutable DefinitionDataPtr DefinitionData;
00528 
00529   /// \brief Describes a C++ closure type (generated by a lambda expression).
00530   struct LambdaDefinitionData : public DefinitionData {
00531     typedef LambdaCapture Capture;
00532 
00533     LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, 
00534                          bool Dependent, bool IsGeneric, 
00535                          LambdaCaptureDefault CaptureDefault) 
00536       : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), 
00537         CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), 
00538         ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
00539         MethodTyInfo(Info) {
00540       IsLambda = true;
00541 
00542       // C++11 [expr.prim.lambda]p3:
00543       //   This class type is neither an aggregate nor a literal type.
00544       Aggregate = false;
00545       PlainOldData = false;
00546       HasNonLiteralTypeFieldsOrBases = true;
00547     }
00548 
00549     /// \brief Whether this lambda is known to be dependent, even if its
00550     /// context isn't dependent.
00551     /// 
00552     /// A lambda with a non-dependent context can be dependent if it occurs
00553     /// within the default argument of a function template, because the
00554     /// lambda will have been created with the enclosing context as its
00555     /// declaration context, rather than function. This is an unfortunate
00556     /// artifact of having to parse the default arguments before. 
00557     unsigned Dependent : 1;
00558     
00559     /// \brief Whether this lambda is a generic lambda.
00560     unsigned IsGenericLambda : 1;
00561 
00562     /// \brief The Default Capture.
00563     unsigned CaptureDefault : 2;
00564 
00565     /// \brief The number of captures in this lambda is limited 2^NumCaptures.
00566     unsigned NumCaptures : 15;
00567 
00568     /// \brief The number of explicit captures in this lambda.
00569     unsigned NumExplicitCaptures : 13;
00570 
00571     /// \brief The number used to indicate this lambda expression for name 
00572     /// mangling in the Itanium C++ ABI.
00573     unsigned ManglingNumber;
00574     
00575     /// \brief The declaration that provides context for this lambda, if the
00576     /// actual DeclContext does not suffice. This is used for lambdas that
00577     /// occur within default arguments of function parameters within the class
00578     /// or within a data member initializer.
00579     Decl *ContextDecl;
00580     
00581     /// \brief The list of captures, both explicit and implicit, for this 
00582     /// lambda.
00583     Capture *Captures;
00584 
00585     /// \brief The type of the call method.
00586     TypeSourceInfo *MethodTyInfo;
00587        
00588   };
00589 
00590   struct DefinitionData &data() const {
00591     auto *DD = DefinitionData.get();
00592     assert(DD && "queried property of class with no definition");
00593     return *DD;
00594   }
00595 
00596   struct LambdaDefinitionData &getLambdaData() const {
00597     // No update required: a merged definition cannot change any lambda
00598     // properties.
00599     auto *DD = DefinitionData.getNotUpdated();
00600     assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
00601     return static_cast<LambdaDefinitionData&>(*DD);
00602   }
00603 
00604   /// \brief The template or declaration that this declaration
00605   /// describes or was instantiated from, respectively.
00606   ///
00607   /// For non-templates, this value will be null. For record
00608   /// declarations that describe a class template, this will be a
00609   /// pointer to a ClassTemplateDecl. For member
00610   /// classes of class template specializations, this will be the
00611   /// MemberSpecializationInfo referring to the member class that was
00612   /// instantiated or specialized.
00613   llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
00614     TemplateOrInstantiation;
00615 
00616   friend class DeclContext;
00617   friend class LambdaExpr;
00618 
00619   /// \brief Called from setBases and addedMember to notify the class that a
00620   /// direct or virtual base class or a member of class type has been added.
00621   void addedClassSubobject(CXXRecordDecl *Base);
00622 
00623   /// \brief Notify the class that member has been added.
00624   ///
00625   /// This routine helps maintain information about the class based on which
00626   /// members have been added. It will be invoked by DeclContext::addDecl()
00627   /// whenever a member is added to this record.
00628   void addedMember(Decl *D);
00629 
00630   void markedVirtualFunctionPure();
00631   friend void FunctionDecl::setPure(bool);
00632 
00633   friend class ASTNodeImporter;
00634 
00635   /// \brief Get the head of our list of friend declarations, possibly
00636   /// deserializing the friends from an external AST source.
00637   FriendDecl *getFirstFriend() const;
00638 
00639 protected:
00640   CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
00641                 SourceLocation StartLoc, SourceLocation IdLoc,
00642                 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
00643 
00644 public:
00645   /// \brief Iterator that traverses the base classes of a class.
00646   typedef CXXBaseSpecifier*       base_class_iterator;
00647 
00648   /// \brief Iterator that traverses the base classes of a class.
00649   typedef const CXXBaseSpecifier* base_class_const_iterator;
00650 
00651   CXXRecordDecl *getCanonicalDecl() override {
00652     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
00653   }
00654   virtual const CXXRecordDecl *getCanonicalDecl() const {
00655     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
00656   }
00657 
00658   CXXRecordDecl *getPreviousDecl() {
00659     return cast_or_null<CXXRecordDecl>(
00660             static_cast<RecordDecl *>(this)->getPreviousDecl());
00661   }
00662   const CXXRecordDecl *getPreviousDecl() const {
00663     return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
00664   }
00665 
00666   CXXRecordDecl *getMostRecentDecl() {
00667     return cast<CXXRecordDecl>(
00668             static_cast<RecordDecl *>(this)->getMostRecentDecl());
00669   }
00670 
00671   const CXXRecordDecl *getMostRecentDecl() const {
00672     return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
00673   }
00674 
00675   CXXRecordDecl *getDefinition() const {
00676     auto *DD = DefinitionData.get();
00677     return DD ? DD->Definition : nullptr;
00678   }
00679 
00680   bool hasDefinition() const { return DefinitionData.get(); }
00681 
00682   static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
00683                                SourceLocation StartLoc, SourceLocation IdLoc,
00684                                IdentifierInfo *Id,
00685                                CXXRecordDecl *PrevDecl = nullptr,
00686                                bool DelayTypeCreation = false);
00687   static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
00688                                      TypeSourceInfo *Info, SourceLocation Loc,
00689                                      bool DependentLambda, bool IsGeneric,
00690                                      LambdaCaptureDefault CaptureDefault);
00691   static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
00692 
00693   bool isDynamicClass() const {
00694     return data().Polymorphic || data().NumVBases != 0;
00695   }
00696 
00697   void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
00698 
00699   bool isParsingBaseSpecifiers() const {
00700     return data().IsParsingBaseSpecifiers;
00701   }
00702 
00703   /// \brief Sets the base classes of this struct or class.
00704   void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
00705 
00706   /// \brief Retrieves the number of base classes of this class.
00707   unsigned getNumBases() const { return data().NumBases; }
00708 
00709   typedef llvm::iterator_range<base_class_iterator> base_class_range;
00710   typedef llvm::iterator_range<base_class_const_iterator>
00711     base_class_const_range;
00712 
00713   base_class_range bases() {
00714     return base_class_range(bases_begin(), bases_end());
00715   }
00716   base_class_const_range bases() const {
00717     return base_class_const_range(bases_begin(), bases_end());
00718   }
00719 
00720   base_class_iterator bases_begin() { return data().getBases(); }
00721   base_class_const_iterator bases_begin() const { return data().getBases(); }
00722   base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
00723   base_class_const_iterator bases_end() const {
00724     return bases_begin() + data().NumBases;
00725   }
00726 
00727   /// \brief Retrieves the number of virtual base classes of this class.
00728   unsigned getNumVBases() const { return data().NumVBases; }
00729 
00730   base_class_range vbases() {
00731     return base_class_range(vbases_begin(), vbases_end());
00732   }
00733   base_class_const_range vbases() const {
00734     return base_class_const_range(vbases_begin(), vbases_end());
00735   }
00736 
00737   base_class_iterator vbases_begin() { return data().getVBases(); }
00738   base_class_const_iterator vbases_begin() const { return data().getVBases(); }
00739   base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
00740   base_class_const_iterator vbases_end() const {
00741     return vbases_begin() + data().NumVBases;
00742   }
00743 
00744   /// \brief Determine whether this class has any dependent base classes which
00745   /// are not the current instantiation.
00746   bool hasAnyDependentBases() const;
00747 
00748   /// Iterator access to method members.  The method iterator visits
00749   /// all method members of the class, including non-instance methods,
00750   /// special methods, etc.
00751   typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
00752   typedef llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>
00753     method_range;
00754 
00755   method_range methods() const {
00756     return method_range(method_begin(), method_end());
00757   }
00758 
00759   /// \brief Method begin iterator.  Iterates in the order the methods
00760   /// were declared.
00761   method_iterator method_begin() const {
00762     return method_iterator(decls_begin());
00763   }
00764   /// \brief Method past-the-end iterator.
00765   method_iterator method_end() const {
00766     return method_iterator(decls_end());
00767   }
00768 
00769   /// Iterator access to constructor members.
00770   typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
00771   typedef llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>
00772     ctor_range;
00773 
00774   ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
00775 
00776   ctor_iterator ctor_begin() const {
00777     return ctor_iterator(decls_begin());
00778   }
00779   ctor_iterator ctor_end() const {
00780     return ctor_iterator(decls_end());
00781   }
00782 
00783   /// An iterator over friend declarations.  All of these are defined
00784   /// in DeclFriend.h.
00785   class friend_iterator;
00786   typedef llvm::iterator_range<friend_iterator> friend_range;
00787 
00788   friend_range friends() const;
00789   friend_iterator friend_begin() const;
00790   friend_iterator friend_end() const;
00791   void pushFriendDecl(FriendDecl *FD);
00792 
00793   /// Determines whether this record has any friends.
00794   bool hasFriends() const {
00795     return data().FirstFriend.isValid();
00796   }
00797 
00798   /// \brief \c true if we know for sure that this class has a single,
00799   /// accessible, unambiguous move constructor that is not deleted.
00800   bool hasSimpleMoveConstructor() const {
00801     return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
00802            !data().DefaultedMoveConstructorIsDeleted;
00803   }
00804   /// \brief \c true if we know for sure that this class has a single,
00805   /// accessible, unambiguous move assignment operator that is not deleted.
00806   bool hasSimpleMoveAssignment() const {
00807     return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
00808            !data().DefaultedMoveAssignmentIsDeleted;
00809   }
00810   /// \brief \c true if we know for sure that this class has an accessible
00811   /// destructor that is not deleted.
00812   bool hasSimpleDestructor() const {
00813     return !hasUserDeclaredDestructor() &&
00814            !data().DefaultedDestructorIsDeleted;
00815   }
00816 
00817   /// \brief Determine whether this class has any default constructors.
00818   bool hasDefaultConstructor() const {
00819     return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
00820            needsImplicitDefaultConstructor();
00821   }
00822 
00823   /// \brief Determine if we need to declare a default constructor for
00824   /// this class.
00825   ///
00826   /// This value is used for lazy creation of default constructors.
00827   bool needsImplicitDefaultConstructor() const {
00828     return !data().UserDeclaredConstructor &&
00829            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
00830   }
00831 
00832   /// \brief Determine whether this class has any user-declared constructors.
00833   ///
00834   /// When true, a default constructor will not be implicitly declared.
00835   bool hasUserDeclaredConstructor() const {
00836     return data().UserDeclaredConstructor;
00837   }
00838 
00839   /// \brief Whether this class has a user-provided default constructor
00840   /// per C++11.
00841   bool hasUserProvidedDefaultConstructor() const {
00842     return data().UserProvidedDefaultConstructor;
00843   }
00844 
00845   /// \brief Determine whether this class has a user-declared copy constructor.
00846   ///
00847   /// When false, a copy constructor will be implicitly declared.
00848   bool hasUserDeclaredCopyConstructor() const {
00849     return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
00850   }
00851 
00852   /// \brief Determine whether this class needs an implicit copy
00853   /// constructor to be lazily declared.
00854   bool needsImplicitCopyConstructor() const {
00855     return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
00856   }
00857 
00858   /// \brief Determine whether we need to eagerly declare a defaulted copy
00859   /// constructor for this class.
00860   bool needsOverloadResolutionForCopyConstructor() const {
00861     return data().HasMutableFields;
00862   }
00863 
00864   /// \brief Determine whether an implicit copy constructor for this type
00865   /// would have a parameter with a const-qualified reference type.
00866   bool implicitCopyConstructorHasConstParam() const {
00867     return data().ImplicitCopyConstructorHasConstParam;
00868   }
00869 
00870   /// \brief Determine whether this class has a copy constructor with
00871   /// a parameter type which is a reference to a const-qualified type.
00872   bool hasCopyConstructorWithConstParam() const {
00873     return data().HasDeclaredCopyConstructorWithConstParam ||
00874            (needsImplicitCopyConstructor() &&
00875             implicitCopyConstructorHasConstParam());
00876   }
00877 
00878   /// \brief Whether this class has a user-declared move constructor or
00879   /// assignment operator.
00880   ///
00881   /// When false, a move constructor and assignment operator may be
00882   /// implicitly declared.
00883   bool hasUserDeclaredMoveOperation() const {
00884     return data().UserDeclaredSpecialMembers &
00885              (SMF_MoveConstructor | SMF_MoveAssignment);
00886   }
00887 
00888   /// \brief Determine whether this class has had a move constructor
00889   /// declared by the user.
00890   bool hasUserDeclaredMoveConstructor() const {
00891     return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
00892   }
00893 
00894   /// \brief Determine whether this class has a move constructor.
00895   bool hasMoveConstructor() const {
00896     return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
00897            needsImplicitMoveConstructor();
00898   }
00899 
00900   /// \brief Set that we attempted to declare an implicitly move
00901   /// constructor, but overload resolution failed so we deleted it.
00902   void setImplicitMoveConstructorIsDeleted() {
00903     assert((data().DefaultedMoveConstructorIsDeleted ||
00904             needsOverloadResolutionForMoveConstructor()) &&
00905            "move constructor should not be deleted");
00906     data().DefaultedMoveConstructorIsDeleted = true;
00907   }
00908 
00909   /// \brief Determine whether this class should get an implicit move
00910   /// constructor or if any existing special member function inhibits this.
00911   bool needsImplicitMoveConstructor() const {
00912     return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
00913            !hasUserDeclaredCopyConstructor() &&
00914            !hasUserDeclaredCopyAssignment() &&
00915            !hasUserDeclaredMoveAssignment() &&
00916            !hasUserDeclaredDestructor();
00917   }
00918 
00919   /// \brief Determine whether we need to eagerly declare a defaulted move
00920   /// constructor for this class.
00921   bool needsOverloadResolutionForMoveConstructor() const {
00922     return data().NeedOverloadResolutionForMoveConstructor;
00923   }
00924 
00925   /// \brief Determine whether this class has a user-declared copy assignment
00926   /// operator.
00927   ///
00928   /// When false, a copy assigment operator will be implicitly declared.
00929   bool hasUserDeclaredCopyAssignment() const {
00930     return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
00931   }
00932 
00933   /// \brief Determine whether this class needs an implicit copy
00934   /// assignment operator to be lazily declared.
00935   bool needsImplicitCopyAssignment() const {
00936     return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
00937   }
00938 
00939   /// \brief Determine whether we need to eagerly declare a defaulted copy
00940   /// assignment operator for this class.
00941   bool needsOverloadResolutionForCopyAssignment() const {
00942     return data().HasMutableFields;
00943   }
00944 
00945   /// \brief Determine whether an implicit copy assignment operator for this
00946   /// type would have a parameter with a const-qualified reference type.
00947   bool implicitCopyAssignmentHasConstParam() const {
00948     return data().ImplicitCopyAssignmentHasConstParam;
00949   }
00950 
00951   /// \brief Determine whether this class has a copy assignment operator with
00952   /// a parameter type which is a reference to a const-qualified type or is not
00953   /// a reference.
00954   bool hasCopyAssignmentWithConstParam() const {
00955     return data().HasDeclaredCopyAssignmentWithConstParam ||
00956            (needsImplicitCopyAssignment() &&
00957             implicitCopyAssignmentHasConstParam());
00958   }
00959 
00960   /// \brief Determine whether this class has had a move assignment
00961   /// declared by the user.
00962   bool hasUserDeclaredMoveAssignment() const {
00963     return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
00964   }
00965 
00966   /// \brief Determine whether this class has a move assignment operator.
00967   bool hasMoveAssignment() const {
00968     return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
00969            needsImplicitMoveAssignment();
00970   }
00971 
00972   /// \brief Set that we attempted to declare an implicit move assignment
00973   /// operator, but overload resolution failed so we deleted it.
00974   void setImplicitMoveAssignmentIsDeleted() {
00975     assert((data().DefaultedMoveAssignmentIsDeleted ||
00976             needsOverloadResolutionForMoveAssignment()) &&
00977            "move assignment should not be deleted");
00978     data().DefaultedMoveAssignmentIsDeleted = true;
00979   }
00980 
00981   /// \brief Determine whether this class should get an implicit move
00982   /// assignment operator or if any existing special member function inhibits
00983   /// this.
00984   bool needsImplicitMoveAssignment() const {
00985     return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
00986            !hasUserDeclaredCopyConstructor() &&
00987            !hasUserDeclaredCopyAssignment() &&
00988            !hasUserDeclaredMoveConstructor() &&
00989            !hasUserDeclaredDestructor();
00990   }
00991 
00992   /// \brief Determine whether we need to eagerly declare a move assignment
00993   /// operator for this class.
00994   bool needsOverloadResolutionForMoveAssignment() const {
00995     return data().NeedOverloadResolutionForMoveAssignment;
00996   }
00997 
00998   /// \brief Determine whether this class has a user-declared destructor.
00999   ///
01000   /// When false, a destructor will be implicitly declared.
01001   bool hasUserDeclaredDestructor() const {
01002     return data().UserDeclaredSpecialMembers & SMF_Destructor;
01003   }
01004 
01005   /// \brief Determine whether this class needs an implicit destructor to
01006   /// be lazily declared.
01007   bool needsImplicitDestructor() const {
01008     return !(data().DeclaredSpecialMembers & SMF_Destructor);
01009   }
01010 
01011   /// \brief Determine whether we need to eagerly declare a destructor for this
01012   /// class.
01013   bool needsOverloadResolutionForDestructor() const {
01014     return data().NeedOverloadResolutionForDestructor;
01015   }
01016 
01017   /// \brief Determine whether this class describes a lambda function object.
01018   bool isLambda() const {
01019     // An update record can't turn a non-lambda into a lambda.
01020     auto *DD = DefinitionData.getNotUpdated();
01021     return DD && DD->IsLambda;
01022   }
01023 
01024   /// \brief Determine whether this class describes a generic 
01025   /// lambda function object (i.e. function call operator is
01026   /// a template). 
01027   bool isGenericLambda() const; 
01028 
01029   /// \brief Retrieve the lambda call operator of the closure type
01030   /// if this is a closure type.
01031   CXXMethodDecl *getLambdaCallOperator() const; 
01032 
01033   /// \brief Retrieve the lambda static invoker, the address of which
01034   /// is returned by the conversion operator, and the body of which
01035   /// is forwarded to the lambda call operator. 
01036   CXXMethodDecl *getLambdaStaticInvoker() const; 
01037 
01038   /// \brief Retrieve the generic lambda's template parameter list.
01039   /// Returns null if the class does not represent a lambda or a generic 
01040   /// lambda.
01041   TemplateParameterList *getGenericLambdaTemplateParameterList() const;
01042 
01043   LambdaCaptureDefault getLambdaCaptureDefault() const {
01044     assert(isLambda());
01045     return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
01046   }
01047 
01048   /// \brief For a closure type, retrieve the mapping from captured
01049   /// variables and \c this to the non-static data members that store the
01050   /// values or references of the captures.
01051   ///
01052   /// \param Captures Will be populated with the mapping from captured
01053   /// variables to the corresponding fields.
01054   ///
01055   /// \param ThisCapture Will be set to the field declaration for the
01056   /// \c this capture.
01057   ///
01058   /// \note No entries will be added for init-captures, as they do not capture
01059   /// variables.
01060   void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
01061                         FieldDecl *&ThisCapture) const;
01062 
01063   typedef const LambdaCapture *capture_const_iterator;
01064   typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
01065 
01066   capture_const_range captures() const {
01067     return capture_const_range(captures_begin(), captures_end());
01068   }
01069   capture_const_iterator captures_begin() const {
01070     return isLambda() ? getLambdaData().Captures : nullptr;
01071   }
01072   capture_const_iterator captures_end() const {
01073     return isLambda() ? captures_begin() + getLambdaData().NumCaptures
01074                       : nullptr;
01075   }
01076 
01077   typedef UnresolvedSetIterator conversion_iterator;
01078   conversion_iterator conversion_begin() const {
01079     return data().Conversions.get(getASTContext()).begin();
01080   }
01081   conversion_iterator conversion_end() const {
01082     return data().Conversions.get(getASTContext()).end();
01083   }
01084 
01085   /// Removes a conversion function from this class.  The conversion
01086   /// function must currently be a member of this class.  Furthermore,
01087   /// this class must currently be in the process of being defined.
01088   void removeConversion(const NamedDecl *Old);
01089 
01090   /// \brief Get all conversion functions visible in current class,
01091   /// including conversion function templates.
01092   std::pair<conversion_iterator, conversion_iterator>
01093     getVisibleConversionFunctions();
01094 
01095   /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
01096   /// which is a class with no user-declared constructors, no private
01097   /// or protected non-static data members, no base classes, and no virtual
01098   /// functions (C++ [dcl.init.aggr]p1).
01099   bool isAggregate() const { return data().Aggregate; }
01100 
01101   /// \brief Whether this class has any in-class initializers
01102   /// for non-static data members (including those in anonymous unions or
01103   /// structs).
01104   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
01105 
01106   /// \brief Whether this class or any of its subobjects has any members of
01107   /// reference type which would make value-initialization ill-formed.
01108   ///
01109   /// Per C++03 [dcl.init]p5:
01110   ///  - if T is a non-union class type without a user-declared constructor,
01111   ///    then every non-static data member and base-class component of T is
01112   ///    value-initialized [...] A program that calls for [...]
01113   ///    value-initialization of an entity of reference type is ill-formed.
01114   bool hasUninitializedReferenceMember() const {
01115     return !isUnion() && !hasUserDeclaredConstructor() &&
01116            data().HasUninitializedReferenceMember;
01117   }
01118 
01119   /// \brief Whether this class is a POD-type (C++ [class]p4)
01120   ///
01121   /// For purposes of this function a class is POD if it is an aggregate
01122   /// that has no non-static non-POD data members, no reference data
01123   /// members, no user-defined copy assignment operator and no
01124   /// user-defined destructor.
01125   ///
01126   /// Note that this is the C++ TR1 definition of POD.
01127   bool isPOD() const { return data().PlainOldData; }
01128 
01129   /// \brief True if this class is C-like, without C++-specific features, e.g.
01130   /// it contains only public fields, no bases, tag kind is not 'class', etc.
01131   bool isCLike() const;
01132 
01133   /// \brief Determine whether this is an empty class in the sense of
01134   /// (C++11 [meta.unary.prop]).
01135   ///
01136   /// A non-union class is empty iff it has a virtual function, virtual base,
01137   /// data member (other than 0-width bit-field) or inherits from a non-empty
01138   /// class.
01139   ///
01140   /// \note This does NOT include a check for union-ness.
01141   bool isEmpty() const { return data().Empty; }
01142 
01143   /// Whether this class is polymorphic (C++ [class.virtual]),
01144   /// which means that the class contains or inherits a virtual function.
01145   bool isPolymorphic() const { return data().Polymorphic; }
01146 
01147   /// \brief Determine whether this class has a pure virtual function.
01148   ///
01149   /// The class is is abstract per (C++ [class.abstract]p2) if it declares
01150   /// a pure virtual function or inherits a pure virtual function that is
01151   /// not overridden.
01152   bool isAbstract() const { return data().Abstract; }
01153 
01154   /// \brief Determine whether this class has standard layout per 
01155   /// (C++ [class]p7)
01156   bool isStandardLayout() const { return data().IsStandardLayout; }
01157 
01158   /// \brief Determine whether this class, or any of its class subobjects,
01159   /// contains a mutable field.
01160   bool hasMutableFields() const { return data().HasMutableFields; }
01161 
01162   /// \brief Determine whether this class has any variant members.
01163   bool hasVariantMembers() const { return data().HasVariantMembers; }
01164 
01165   /// \brief Determine whether this class has a trivial default constructor
01166   /// (C++11 [class.ctor]p5).
01167   bool hasTrivialDefaultConstructor() const {
01168     return hasDefaultConstructor() &&
01169            (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
01170   }
01171 
01172   /// \brief Determine whether this class has a non-trivial default constructor
01173   /// (C++11 [class.ctor]p5).
01174   bool hasNonTrivialDefaultConstructor() const {
01175     return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
01176            (needsImplicitDefaultConstructor() &&
01177             !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
01178   }
01179 
01180   /// \brief Determine whether this class has at least one constexpr constructor
01181   /// other than the copy or move constructors.
01182   bool hasConstexprNonCopyMoveConstructor() const {
01183     return data().HasConstexprNonCopyMoveConstructor ||
01184            (needsImplicitDefaultConstructor() &&
01185             defaultedDefaultConstructorIsConstexpr());
01186   }
01187 
01188   /// \brief Determine whether a defaulted default constructor for this class
01189   /// would be constexpr.
01190   bool defaultedDefaultConstructorIsConstexpr() const {
01191     return data().DefaultedDefaultConstructorIsConstexpr &&
01192            (!isUnion() || hasInClassInitializer() || !hasVariantMembers());
01193   }
01194 
01195   /// \brief Determine whether this class has a constexpr default constructor.
01196   bool hasConstexprDefaultConstructor() const {
01197     return data().HasConstexprDefaultConstructor ||
01198            (needsImplicitDefaultConstructor() &&
01199             defaultedDefaultConstructorIsConstexpr());
01200   }
01201 
01202   /// \brief Determine whether this class has a trivial copy constructor
01203   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
01204   bool hasTrivialCopyConstructor() const {
01205     return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
01206   }
01207 
01208   /// \brief Determine whether this class has a non-trivial copy constructor
01209   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
01210   bool hasNonTrivialCopyConstructor() const {
01211     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
01212            !hasTrivialCopyConstructor();
01213   }
01214 
01215   /// \brief Determine whether this class has a trivial move constructor
01216   /// (C++11 [class.copy]p12)
01217   bool hasTrivialMoveConstructor() const {
01218     return hasMoveConstructor() &&
01219            (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
01220   }
01221 
01222   /// \brief Determine whether this class has a non-trivial move constructor
01223   /// (C++11 [class.copy]p12)
01224   bool hasNonTrivialMoveConstructor() const {
01225     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
01226            (needsImplicitMoveConstructor() &&
01227             !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
01228   }
01229 
01230   /// \brief Determine whether this class has a trivial copy assignment operator
01231   /// (C++ [class.copy]p11, C++11 [class.copy]p25)
01232   bool hasTrivialCopyAssignment() const {
01233     return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
01234   }
01235 
01236   /// \brief Determine whether this class has a non-trivial copy assignment
01237   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
01238   bool hasNonTrivialCopyAssignment() const {
01239     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
01240            !hasTrivialCopyAssignment();
01241   }
01242 
01243   /// \brief Determine whether this class has a trivial move assignment operator
01244   /// (C++11 [class.copy]p25)
01245   bool hasTrivialMoveAssignment() const {
01246     return hasMoveAssignment() &&
01247            (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
01248   }
01249 
01250   /// \brief Determine whether this class has a non-trivial move assignment
01251   /// operator (C++11 [class.copy]p25)
01252   bool hasNonTrivialMoveAssignment() const {
01253     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
01254            (needsImplicitMoveAssignment() &&
01255             !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
01256   }
01257 
01258   /// \brief Determine whether this class has a trivial destructor
01259   /// (C++ [class.dtor]p3)
01260   bool hasTrivialDestructor() const {
01261     return data().HasTrivialSpecialMembers & SMF_Destructor;
01262   }
01263 
01264   /// \brief Determine whether this class has a non-trivial destructor
01265   /// (C++ [class.dtor]p3)
01266   bool hasNonTrivialDestructor() const {
01267     return !(data().HasTrivialSpecialMembers & SMF_Destructor);
01268   }
01269 
01270   /// \brief Determine whether this class has a destructor which has no
01271   /// semantic effect.
01272   ///
01273   /// Any such destructor will be trivial, public, defaulted and not deleted,
01274   /// and will call only irrelevant destructors.
01275   bool hasIrrelevantDestructor() const {
01276     return data().HasIrrelevantDestructor;
01277   }
01278 
01279   /// \brief Determine whether this class has a non-literal or/ volatile type
01280   /// non-static data member or base class.
01281   bool hasNonLiteralTypeFieldsOrBases() const {
01282     return data().HasNonLiteralTypeFieldsOrBases;
01283   }
01284 
01285   /// \brief Determine whether this class is considered trivially copyable per
01286   /// (C++11 [class]p6).
01287   bool isTriviallyCopyable() const;
01288 
01289   /// \brief Determine whether this class is considered trivial.
01290   ///
01291   /// C++11 [class]p6:
01292   ///    "A trivial class is a class that has a trivial default constructor and
01293   ///    is trivially copiable."
01294   bool isTrivial() const {
01295     return isTriviallyCopyable() && hasTrivialDefaultConstructor();
01296   }
01297 
01298   /// \brief Determine whether this class is a literal type.
01299   ///
01300   /// C++11 [basic.types]p10:
01301   ///   A class type that has all the following properties:
01302   ///     - it has a trivial destructor
01303   ///     - every constructor call and full-expression in the
01304   ///       brace-or-equal-intializers for non-static data members (if any) is
01305   ///       a constant expression.
01306   ///     - it is an aggregate type or has at least one constexpr constructor
01307   ///       or constructor template that is not a copy or move constructor, and
01308   ///     - all of its non-static data members and base classes are of literal
01309   ///       types
01310   ///
01311   /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
01312   /// treating types with trivial default constructors as literal types.
01313   bool isLiteral() const {
01314     return hasTrivialDestructor() &&
01315            (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
01316             hasTrivialDefaultConstructor()) &&
01317            !hasNonLiteralTypeFieldsOrBases();
01318   }
01319 
01320   /// \brief If this record is an instantiation of a member class,
01321   /// retrieves the member class from which it was instantiated.
01322   ///
01323   /// This routine will return non-null for (non-templated) member
01324   /// classes of class templates. For example, given:
01325   ///
01326   /// \code
01327   /// template<typename T>
01328   /// struct X {
01329   ///   struct A { };
01330   /// };
01331   /// \endcode
01332   ///
01333   /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
01334   /// whose parent is the class template specialization X<int>. For
01335   /// this declaration, getInstantiatedFromMemberClass() will return
01336   /// the CXXRecordDecl X<T>::A. When a complete definition of
01337   /// X<int>::A is required, it will be instantiated from the
01338   /// declaration returned by getInstantiatedFromMemberClass().
01339   CXXRecordDecl *getInstantiatedFromMemberClass() const;
01340 
01341   /// \brief If this class is an instantiation of a member class of a
01342   /// class template specialization, retrieves the member specialization
01343   /// information.
01344   MemberSpecializationInfo *getMemberSpecializationInfo() const {
01345     return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
01346   }
01347 
01348   /// \brief Specify that this record is an instantiation of the
01349   /// member class \p RD.
01350   void setInstantiationOfMemberClass(CXXRecordDecl *RD,
01351                                      TemplateSpecializationKind TSK);
01352 
01353   /// \brief Retrieves the class template that is described by this
01354   /// class declaration.
01355   ///
01356   /// Every class template is represented as a ClassTemplateDecl and a
01357   /// CXXRecordDecl. The former contains template properties (such as
01358   /// the template parameter lists) while the latter contains the
01359   /// actual description of the template's
01360   /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
01361   /// CXXRecordDecl that from a ClassTemplateDecl, while
01362   /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
01363   /// a CXXRecordDecl.
01364   ClassTemplateDecl *getDescribedClassTemplate() const {
01365     return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
01366   }
01367 
01368   void setDescribedClassTemplate(ClassTemplateDecl *Template) {
01369     TemplateOrInstantiation = Template;
01370   }
01371 
01372   /// \brief Determine whether this particular class is a specialization or
01373   /// instantiation of a class template or member class of a class template,
01374   /// and how it was instantiated or specialized.
01375   TemplateSpecializationKind getTemplateSpecializationKind() const;
01376 
01377   /// \brief Set the kind of specialization or template instantiation this is.
01378   void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
01379 
01380   /// \brief Retrieve the record declaration from which this record could be
01381   /// instantiated. Returns null if this class is not a template instantiation.
01382   const CXXRecordDecl *getTemplateInstantiationPattern() const;
01383 
01384   CXXRecordDecl *getTemplateInstantiationPattern() {
01385     return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
01386                                            ->getTemplateInstantiationPattern());
01387   }
01388 
01389   /// \brief Returns the destructor decl for this class.
01390   CXXDestructorDecl *getDestructor() const;
01391 
01392   /// \brief If the class is a local class [class.local], returns
01393   /// the enclosing function declaration.
01394   const FunctionDecl *isLocalClass() const {
01395     if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
01396       return RD->isLocalClass();
01397 
01398     return dyn_cast<FunctionDecl>(getDeclContext());
01399   }
01400 
01401   FunctionDecl *isLocalClass() {
01402     return const_cast<FunctionDecl*>(
01403         const_cast<const CXXRecordDecl*>(this)->isLocalClass());
01404   }
01405 
01406   /// \brief Determine whether this dependent class is a current instantiation,
01407   /// when viewed from within the given context.
01408   bool isCurrentInstantiation(const DeclContext *CurContext) const;
01409 
01410   /// \brief Determine whether this class is derived from the class \p Base.
01411   ///
01412   /// This routine only determines whether this class is derived from \p Base,
01413   /// but does not account for factors that may make a Derived -> Base class
01414   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
01415   /// base class subobjects.
01416   ///
01417   /// \param Base the base class we are searching for.
01418   ///
01419   /// \returns true if this class is derived from Base, false otherwise.
01420   bool isDerivedFrom(const CXXRecordDecl *Base) const;
01421 
01422   /// \brief Determine whether this class is derived from the type \p Base.
01423   ///
01424   /// This routine only determines whether this class is derived from \p Base,
01425   /// but does not account for factors that may make a Derived -> Base class
01426   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
01427   /// base class subobjects.
01428   ///
01429   /// \param Base the base class we are searching for.
01430   ///
01431   /// \param Paths will contain the paths taken from the current class to the
01432   /// given \p Base class.
01433   ///
01434   /// \returns true if this class is derived from \p Base, false otherwise.
01435   ///
01436   /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
01437   /// tangling input and output in \p Paths
01438   bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
01439 
01440   /// \brief Determine whether this class is virtually derived from
01441   /// the class \p Base.
01442   ///
01443   /// This routine only determines whether this class is virtually
01444   /// derived from \p Base, but does not account for factors that may
01445   /// make a Derived -> Base class ill-formed, such as
01446   /// private/protected inheritance or multiple, ambiguous base class
01447   /// subobjects.
01448   ///
01449   /// \param Base the base class we are searching for.
01450   ///
01451   /// \returns true if this class is virtually derived from Base,
01452   /// false otherwise.
01453   bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
01454 
01455   /// \brief Determine whether this class is provably not derived from
01456   /// the type \p Base.
01457   bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
01458 
01459   /// \brief Function type used by forallBases() as a callback.
01460   ///
01461   /// \param BaseDefinition the definition of the base class
01462   ///
01463   /// \returns true if this base matched the search criteria
01464   typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
01465                                    void *UserData);
01466 
01467   /// \brief Determines if the given callback holds for all the direct
01468   /// or indirect base classes of this type.
01469   ///
01470   /// The class itself does not count as a base class.  This routine
01471   /// returns false if the class has non-computable base classes.
01472   ///
01473   /// \param BaseMatches Callback invoked for each (direct or indirect) base
01474   /// class of this type, or if \p AllowShortCircuit is true then until a call
01475   /// returns false.
01476   ///
01477   /// \param UserData Passed as the second argument of every call to
01478   /// \p BaseMatches.
01479   ///
01480   /// \param AllowShortCircuit if false, forces the callback to be called
01481   /// for every base class, even if a dependent or non-matching base was
01482   /// found.
01483   bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
01484                    bool AllowShortCircuit = true) const;
01485 
01486   /// \brief Function type used by lookupInBases() to determine whether a
01487   /// specific base class subobject matches the lookup criteria.
01488   ///
01489   /// \param Specifier the base-class specifier that describes the inheritance
01490   /// from the base class we are trying to match.
01491   ///
01492   /// \param Path the current path, from the most-derived class down to the
01493   /// base named by the \p Specifier.
01494   ///
01495   /// \param UserData a single pointer to user-specified data, provided to
01496   /// lookupInBases().
01497   ///
01498   /// \returns true if this base matched the search criteria, false otherwise.
01499   typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
01500                                    CXXBasePath &Path,
01501                                    void *UserData);
01502 
01503   /// \brief Look for entities within the base classes of this C++ class,
01504   /// transitively searching all base class subobjects.
01505   ///
01506   /// This routine uses the callback function \p BaseMatches to find base
01507   /// classes meeting some search criteria, walking all base class subobjects
01508   /// and populating the given \p Paths structure with the paths through the
01509   /// inheritance hierarchy that resulted in a match. On a successful search,
01510   /// the \p Paths structure can be queried to retrieve the matching paths and
01511   /// to determine if there were any ambiguities.
01512   ///
01513   /// \param BaseMatches callback function used to determine whether a given
01514   /// base matches the user-defined search criteria.
01515   ///
01516   /// \param UserData user data pointer that will be provided to \p BaseMatches.
01517   ///
01518   /// \param Paths used to record the paths from this class to its base class
01519   /// subobjects that match the search criteria.
01520   ///
01521   /// \returns true if there exists any path from this class to a base class
01522   /// subobject that matches the search criteria.
01523   bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
01524                      CXXBasePaths &Paths) const;
01525 
01526   /// \brief Base-class lookup callback that determines whether the given
01527   /// base class specifier refers to a specific class declaration.
01528   ///
01529   /// This callback can be used with \c lookupInBases() to determine whether
01530   /// a given derived class has is a base class subobject of a particular type.
01531   /// The user data pointer should refer to the canonical CXXRecordDecl of the
01532   /// base class that we are searching for.
01533   static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
01534                             CXXBasePath &Path, void *BaseRecord);
01535 
01536   /// \brief Base-class lookup callback that determines whether the
01537   /// given base class specifier refers to a specific class
01538   /// declaration and describes virtual derivation.
01539   ///
01540   /// This callback can be used with \c lookupInBases() to determine
01541   /// whether a given derived class has is a virtual base class
01542   /// subobject of a particular type.  The user data pointer should
01543   /// refer to the canonical CXXRecordDecl of the base class that we
01544   /// are searching for.
01545   static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
01546                                    CXXBasePath &Path, void *BaseRecord);
01547 
01548   /// \brief Base-class lookup callback that determines whether there exists
01549   /// a tag with the given name.
01550   ///
01551   /// This callback can be used with \c lookupInBases() to find tag members
01552   /// of the given name within a C++ class hierarchy. The user data pointer
01553   /// is an opaque \c DeclarationName pointer.
01554   static bool FindTagMember(const CXXBaseSpecifier *Specifier,
01555                             CXXBasePath &Path, void *Name);
01556 
01557   /// \brief Base-class lookup callback that determines whether there exists
01558   /// a member with the given name.
01559   ///
01560   /// This callback can be used with \c lookupInBases() to find members
01561   /// of the given name within a C++ class hierarchy. The user data pointer
01562   /// is an opaque \c DeclarationName pointer.
01563   static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
01564                                  CXXBasePath &Path, void *Name);
01565 
01566   /// \brief Base-class lookup callback that determines whether there exists
01567   /// a member with the given name that can be used in a nested-name-specifier.
01568   ///
01569   /// This callback can be used with \c lookupInBases() to find membes of
01570   /// the given name within a C++ class hierarchy that can occur within
01571   /// nested-name-specifiers.
01572   static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
01573                                             CXXBasePath &Path,
01574                                             void *UserData);
01575 
01576   /// \brief Retrieve the final overriders for each virtual member
01577   /// function in the class hierarchy where this class is the
01578   /// most-derived class in the class hierarchy.
01579   void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
01580 
01581   /// \brief Get the indirect primary bases for this class.
01582   void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
01583 
01584   /// Renders and displays an inheritance diagram
01585   /// for this C++ class and all of its base classes (transitively) using
01586   /// GraphViz.
01587   void viewInheritance(ASTContext& Context) const;
01588 
01589   /// \brief Calculates the access of a decl that is reached
01590   /// along a path.
01591   static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
01592                                      AccessSpecifier DeclAccess) {
01593     assert(DeclAccess != AS_none);
01594     if (DeclAccess == AS_private) return AS_none;
01595     return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
01596   }
01597 
01598   /// \brief Indicates that the declaration of a defaulted or deleted special
01599   /// member function is now complete.
01600   void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
01601 
01602   /// \brief Indicates that the definition of this class is now complete.
01603   void completeDefinition() override;
01604 
01605   /// \brief Indicates that the definition of this class is now complete,
01606   /// and provides a final overrider map to help determine
01607   ///
01608   /// \param FinalOverriders The final overrider map for this class, which can
01609   /// be provided as an optimization for abstract-class checking. If NULL,
01610   /// final overriders will be computed if they are needed to complete the
01611   /// definition.
01612   void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
01613 
01614   /// \brief Determine whether this class may end up being abstract, even though
01615   /// it is not yet known to be abstract.
01616   ///
01617   /// \returns true if this class is not known to be abstract but has any
01618   /// base classes that are abstract. In this case, \c completeDefinition()
01619   /// will need to compute final overriders to determine whether the class is
01620   /// actually abstract.
01621   bool mayBeAbstract() const;
01622 
01623   /// \brief If this is the closure type of a lambda expression, retrieve the
01624   /// number to be used for name mangling in the Itanium C++ ABI.
01625   ///
01626   /// Zero indicates that this closure type has internal linkage, so the 
01627   /// mangling number does not matter, while a non-zero value indicates which
01628   /// lambda expression this is in this particular context.
01629   unsigned getLambdaManglingNumber() const {
01630     assert(isLambda() && "Not a lambda closure type!");
01631     return getLambdaData().ManglingNumber;
01632   }
01633   
01634   /// \brief Retrieve the declaration that provides additional context for a 
01635   /// lambda, when the normal declaration context is not specific enough.
01636   ///
01637   /// Certain contexts (default arguments of in-class function parameters and 
01638   /// the initializers of data members) have separate name mangling rules for
01639   /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
01640   /// the declaration in which the lambda occurs, e.g., the function parameter 
01641   /// or the non-static data member. Otherwise, it returns NULL to imply that
01642   /// the declaration context suffices.
01643   Decl *getLambdaContextDecl() const {
01644     assert(isLambda() && "Not a lambda closure type!");
01645     return getLambdaData().ContextDecl;    
01646   }
01647   
01648   /// \brief Set the mangling number and context declaration for a lambda
01649   /// class.
01650   void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
01651     getLambdaData().ManglingNumber = ManglingNumber;
01652     getLambdaData().ContextDecl = ContextDecl;
01653   }
01654 
01655   /// \brief Returns the inheritance model used for this record.
01656   MSInheritanceAttr::Spelling getMSInheritanceModel() const;
01657   /// \brief Calculate what the inheritance model would be for this class.
01658   MSInheritanceAttr::Spelling calculateInheritanceModel() const;
01659 
01660   /// In the Microsoft C++ ABI, use zero for the field offset of a null data
01661   /// member pointer if we can guarantee that zero is not a valid field offset,
01662   /// or if the member pointer has multiple fields.  Polymorphic classes have a
01663   /// vfptr at offset zero, so we can use zero for null.  If there are multiple
01664   /// fields, we can use zero even if it is a valid field offset because
01665   /// null-ness testing will check the other fields.
01666   bool nullFieldOffsetIsZero() const {
01667     return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
01668                                                getMSInheritanceModel()) ||
01669            (hasDefinition() && isPolymorphic());
01670   }
01671 
01672   /// \brief Controls when vtordisps will be emitted if this record is used as a
01673   /// virtual base.
01674   MSVtorDispAttr::Mode getMSVtorDispMode() const;
01675 
01676   /// \brief Determine whether this lambda expression was known to be dependent
01677   /// at the time it was created, even if its context does not appear to be
01678   /// dependent.
01679   ///
01680   /// This flag is a workaround for an issue with parsing, where default
01681   /// arguments are parsed before their enclosing function declarations have
01682   /// been created. This means that any lambda expressions within those
01683   /// default arguments will have as their DeclContext the context enclosing
01684   /// the function declaration, which may be non-dependent even when the
01685   /// function declaration itself is dependent. This flag indicates when we
01686   /// know that the lambda is dependent despite that.
01687   bool isDependentLambda() const {
01688     return isLambda() && getLambdaData().Dependent;
01689   }
01690 
01691   TypeSourceInfo *getLambdaTypeInfo() const {
01692     return getLambdaData().MethodTyInfo;
01693   }
01694 
01695   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01696   static bool classofKind(Kind K) {
01697     return K >= firstCXXRecord && K <= lastCXXRecord;
01698   }
01699 
01700   friend class ASTDeclReader;
01701   friend class ASTDeclWriter;
01702   friend class ASTReader;
01703   friend class ASTWriter;
01704 };
01705 
01706 /// \brief Represents a static or instance method of a struct/union/class.
01707 ///
01708 /// In the terminology of the C++ Standard, these are the (static and
01709 /// non-static) member functions, whether virtual or not.
01710 class CXXMethodDecl : public FunctionDecl {
01711   void anchor() override;
01712 protected:
01713   CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
01714                 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
01715                 QualType T, TypeSourceInfo *TInfo,
01716                 StorageClass SC, bool isInline,
01717                 bool isConstexpr, SourceLocation EndLocation)
01718     : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
01719                    SC, isInline, isConstexpr) {
01720     if (EndLocation.isValid())
01721       setRangeEnd(EndLocation);
01722   }
01723 
01724 public:
01725   static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
01726                                SourceLocation StartLoc,
01727                                const DeclarationNameInfo &NameInfo,
01728                                QualType T, TypeSourceInfo *TInfo,
01729                                StorageClass SC,
01730                                bool isInline,
01731                                bool isConstexpr,
01732                                SourceLocation EndLocation);
01733 
01734   static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01735 
01736   bool isStatic() const;
01737   bool isInstance() const { return !isStatic(); }
01738 
01739   /// Returns true if the given operator is implicitly static in a record
01740   /// context.
01741   static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
01742     // [class.free]p1:
01743     // Any allocation function for a class T is a static member
01744     // (even if not explicitly declared static).
01745     // [class.free]p6 Any deallocation function for a class X is a static member
01746     // (even if not explicitly declared static).
01747     return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
01748            OOK == OO_Array_Delete;
01749   }
01750 
01751   bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
01752   bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
01753 
01754   bool isVirtual() const {
01755     CXXMethodDecl *CD =
01756       cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
01757 
01758     // Member function is virtual if it is marked explicitly so, or if it is
01759     // declared in __interface -- then it is automatically pure virtual.
01760     if (CD->isVirtualAsWritten() || CD->isPure())
01761       return true;
01762 
01763     return (CD->begin_overridden_methods() != CD->end_overridden_methods());
01764   }
01765 
01766   /// \brief Determine whether this is a usual deallocation function
01767   /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
01768   /// delete or delete[] operator with a particular signature.
01769   bool isUsualDeallocationFunction() const;
01770 
01771   /// \brief Determine whether this is a copy-assignment operator, regardless
01772   /// of whether it was declared implicitly or explicitly.
01773   bool isCopyAssignmentOperator() const;
01774 
01775   /// \brief Determine whether this is a move assignment operator.
01776   bool isMoveAssignmentOperator() const;
01777 
01778   CXXMethodDecl *getCanonicalDecl() override {
01779     return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
01780   }
01781   const CXXMethodDecl *getCanonicalDecl() const override {
01782     return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
01783   }
01784 
01785   CXXMethodDecl *getMostRecentDecl() {
01786     return cast<CXXMethodDecl>(
01787             static_cast<FunctionDecl *>(this)->getMostRecentDecl());
01788   }
01789   const CXXMethodDecl *getMostRecentDecl() const {
01790     return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
01791   }
01792 
01793   /// True if this method is user-declared and was not
01794   /// deleted or defaulted on its first declaration.
01795   bool isUserProvided() const {
01796     return !(isDeleted() || getCanonicalDecl()->isDefaulted());
01797   }
01798 
01799   ///
01800   void addOverriddenMethod(const CXXMethodDecl *MD);
01801 
01802   typedef const CXXMethodDecl *const* method_iterator;
01803 
01804   method_iterator begin_overridden_methods() const;
01805   method_iterator end_overridden_methods() const;
01806   unsigned size_overridden_methods() const;
01807 
01808   /// Returns the parent of this method declaration, which
01809   /// is the class in which this method is defined.
01810   const CXXRecordDecl *getParent() const {
01811     return cast<CXXRecordDecl>(FunctionDecl::getParent());
01812   }
01813 
01814   /// Returns the parent of this method declaration, which
01815   /// is the class in which this method is defined.
01816   CXXRecordDecl *getParent() {
01817     return const_cast<CXXRecordDecl *>(
01818              cast<CXXRecordDecl>(FunctionDecl::getParent()));
01819   }
01820 
01821   /// \brief Returns the type of the \c this pointer.
01822   ///
01823   /// Should only be called for instance (i.e., non-static) methods.
01824   QualType getThisType(ASTContext &C) const;
01825 
01826   unsigned getTypeQualifiers() const {
01827     return getType()->getAs<FunctionProtoType>()->getTypeQuals();
01828   }
01829 
01830   /// \brief Retrieve the ref-qualifier associated with this method.
01831   ///
01832   /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
01833   /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
01834   /// @code
01835   /// struct X {
01836   ///   void f() &;
01837   ///   void g() &&;
01838   ///   void h();
01839   /// };
01840   /// @endcode
01841   RefQualifierKind getRefQualifier() const {
01842     return getType()->getAs<FunctionProtoType>()->getRefQualifier();
01843   }
01844 
01845   bool hasInlineBody() const;
01846 
01847   /// \brief Determine whether this is a lambda closure type's static member
01848   /// function that is used for the result of the lambda's conversion to
01849   /// function pointer (for a lambda with no captures).
01850   ///
01851   /// The function itself, if used, will have a placeholder body that will be
01852   /// supplied by IR generation to either forward to the function call operator
01853   /// or clone the function call operator.
01854   bool isLambdaStaticInvoker() const;
01855 
01856   /// \brief Find the method in \p RD that corresponds to this one.
01857   ///
01858   /// Find if \p RD or one of the classes it inherits from override this method.
01859   /// If so, return it. \p RD is assumed to be a subclass of the class defining
01860   /// this method (or be the class itself), unless \p MayBeBase is set to true.
01861   CXXMethodDecl *
01862   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
01863                                 bool MayBeBase = false);
01864 
01865   const CXXMethodDecl *
01866   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
01867                                 bool MayBeBase = false) const {
01868     return const_cast<CXXMethodDecl *>(this)
01869               ->getCorrespondingMethodInClass(RD, MayBeBase);
01870   }
01871 
01872   // Implement isa/cast/dyncast/etc.
01873   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01874   static bool classofKind(Kind K) {
01875     return K >= firstCXXMethod && K <= lastCXXMethod;
01876   }
01877 };
01878 
01879 /// \brief Represents a C++ base or member initializer.
01880 ///
01881 /// This is part of a constructor initializer that
01882 /// initializes one non-static member variable or one base class. For
01883 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
01884 /// initializers:
01885 ///
01886 /// \code
01887 /// class A { };
01888 /// class B : public A {
01889 ///   float f;
01890 /// public:
01891 ///   B(A& a) : A(a), f(3.14159) { }
01892 /// };
01893 /// \endcode
01894 class CXXCtorInitializer {
01895   /// \brief Either the base class name/delegating constructor type (stored as
01896   /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
01897   /// (IndirectFieldDecl*) being initialized.
01898   llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
01899     Initializee;
01900 
01901   /// \brief The source location for the field name or, for a base initializer
01902   /// pack expansion, the location of the ellipsis.
01903   ///
01904   /// In the case of a delegating
01905   /// constructor, it will still include the type's source location as the
01906   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
01907   SourceLocation MemberOrEllipsisLocation;
01908 
01909   /// \brief The argument used to initialize the base or member, which may
01910   /// end up constructing an object (when multiple arguments are involved).
01911   Stmt *Init;
01912 
01913   /// \brief Location of the left paren of the ctor-initializer.
01914   SourceLocation LParenLoc;
01915 
01916   /// \brief Location of the right paren of the ctor-initializer.
01917   SourceLocation RParenLoc;
01918 
01919   /// \brief If the initializee is a type, whether that type makes this
01920   /// a delegating initialization.
01921   bool IsDelegating : 1;
01922 
01923   /// \brief If the initializer is a base initializer, this keeps track
01924   /// of whether the base is virtual or not.
01925   bool IsVirtual : 1;
01926 
01927   /// \brief Whether or not the initializer is explicitly written
01928   /// in the sources.
01929   bool IsWritten : 1;
01930 
01931   /// If IsWritten is true, then this number keeps track of the textual order
01932   /// of this initializer in the original sources, counting from 0; otherwise,
01933   /// it stores the number of array index variables stored after this object
01934   /// in memory.
01935   unsigned SourceOrderOrNumArrayIndices : 13;
01936 
01937   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
01938                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
01939                      SourceLocation R, VarDecl **Indices, unsigned NumIndices);
01940 
01941 public:
01942   /// \brief Creates a new base-class initializer.
01943   explicit
01944   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
01945                      SourceLocation L, Expr *Init, SourceLocation R,
01946                      SourceLocation EllipsisLoc);
01947 
01948   /// \brief Creates a new member initializer.
01949   explicit
01950   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
01951                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
01952                      SourceLocation R);
01953 
01954   /// \brief Creates a new anonymous field initializer.
01955   explicit
01956   CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
01957                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
01958                      SourceLocation R);
01959 
01960   /// \brief Creates a new delegating initializer.
01961   explicit
01962   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
01963                      SourceLocation L, Expr *Init, SourceLocation R);
01964 
01965   /// \brief Creates a new member initializer that optionally contains
01966   /// array indices used to describe an elementwise initialization.
01967   static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
01968                                     SourceLocation MemberLoc, SourceLocation L,
01969                                     Expr *Init, SourceLocation R,
01970                                     VarDecl **Indices, unsigned NumIndices);
01971 
01972   /// \brief Determine whether this initializer is initializing a base class.
01973   bool isBaseInitializer() const {
01974     return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
01975   }
01976 
01977   /// \brief Determine whether this initializer is initializing a non-static
01978   /// data member.
01979   bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
01980 
01981   bool isAnyMemberInitializer() const {
01982     return isMemberInitializer() || isIndirectMemberInitializer();
01983   }
01984 
01985   bool isIndirectMemberInitializer() const {
01986     return Initializee.is<IndirectFieldDecl*>();
01987   }
01988 
01989   /// \brief Determine whether this initializer is an implicit initializer
01990   /// generated for a field with an initializer defined on the member
01991   /// declaration.
01992   ///
01993   /// In-class member initializers (also known as "non-static data member
01994   /// initializations", NSDMIs) were introduced in C++11.
01995   bool isInClassMemberInitializer() const {
01996     return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
01997   }
01998 
01999   /// \brief Determine whether this initializer is creating a delegating
02000   /// constructor.
02001   bool isDelegatingInitializer() const {
02002     return Initializee.is<TypeSourceInfo*>() && IsDelegating;
02003   }
02004 
02005   /// \brief Determine whether this initializer is a pack expansion.
02006   bool isPackExpansion() const {
02007     return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
02008   }
02009 
02010   // \brief For a pack expansion, returns the location of the ellipsis.
02011   SourceLocation getEllipsisLoc() const {
02012     assert(isPackExpansion() && "Initializer is not a pack expansion");
02013     return MemberOrEllipsisLocation;
02014   }
02015 
02016   /// If this is a base class initializer, returns the type of the
02017   /// base class with location information. Otherwise, returns an NULL
02018   /// type location.
02019   TypeLoc getBaseClassLoc() const;
02020 
02021   /// If this is a base class initializer, returns the type of the base class.
02022   /// Otherwise, returns null.
02023   const Type *getBaseClass() const;
02024 
02025   /// Returns whether the base is virtual or not.
02026   bool isBaseVirtual() const {
02027     assert(isBaseInitializer() && "Must call this on base initializer!");
02028 
02029     return IsVirtual;
02030   }
02031 
02032   /// \brief Returns the declarator information for a base class or delegating
02033   /// initializer.
02034   TypeSourceInfo *getTypeSourceInfo() const {
02035     return Initializee.dyn_cast<TypeSourceInfo *>();
02036   }
02037 
02038   /// \brief If this is a member initializer, returns the declaration of the
02039   /// non-static data member being initialized. Otherwise, returns null.
02040   FieldDecl *getMember() const {
02041     if (isMemberInitializer())
02042       return Initializee.get<FieldDecl*>();
02043     return nullptr;
02044   }
02045   FieldDecl *getAnyMember() const {
02046     if (isMemberInitializer())
02047       return Initializee.get<FieldDecl*>();
02048     if (isIndirectMemberInitializer())
02049       return Initializee.get<IndirectFieldDecl*>()->getAnonField();
02050     return nullptr;
02051   }
02052 
02053   IndirectFieldDecl *getIndirectMember() const {
02054     if (isIndirectMemberInitializer())
02055       return Initializee.get<IndirectFieldDecl*>();
02056     return nullptr;
02057   }
02058 
02059   SourceLocation getMemberLocation() const {
02060     return MemberOrEllipsisLocation;
02061   }
02062 
02063   /// \brief Determine the source location of the initializer.
02064   SourceLocation getSourceLocation() const;
02065 
02066   /// \brief Determine the source range covering the entire initializer.
02067   SourceRange getSourceRange() const LLVM_READONLY;
02068 
02069   /// \brief Determine whether this initializer is explicitly written
02070   /// in the source code.
02071   bool isWritten() const { return IsWritten; }
02072 
02073   /// \brief Return the source position of the initializer, counting from 0.
02074   /// If the initializer was implicit, -1 is returned.
02075   int getSourceOrder() const {
02076     return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
02077   }
02078 
02079   /// \brief Set the source order of this initializer.
02080   ///
02081   /// This can only be called once for each initializer; it cannot be called
02082   /// on an initializer having a positive number of (implicit) array indices.
02083   ///
02084   /// This assumes that the initialzier was written in the source code, and
02085   /// ensures that isWritten() returns true.
02086   void setSourceOrder(int pos) {
02087     assert(!IsWritten &&
02088            "calling twice setSourceOrder() on the same initializer");
02089     assert(SourceOrderOrNumArrayIndices == 0 &&
02090            "setSourceOrder() used when there are implicit array indices");
02091     assert(pos >= 0 &&
02092            "setSourceOrder() used to make an initializer implicit");
02093     IsWritten = true;
02094     SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
02095   }
02096 
02097   SourceLocation getLParenLoc() const { return LParenLoc; }
02098   SourceLocation getRParenLoc() const { return RParenLoc; }
02099 
02100   /// \brief Determine the number of implicit array indices used while
02101   /// described an array member initialization.
02102   unsigned getNumArrayIndices() const {
02103     return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
02104   }
02105 
02106   /// \brief Retrieve a particular array index variable used to
02107   /// describe an array member initialization.
02108   VarDecl *getArrayIndex(unsigned I) {
02109     assert(I < getNumArrayIndices() && "Out of bounds member array index");
02110     return reinterpret_cast<VarDecl **>(this + 1)[I];
02111   }
02112   const VarDecl *getArrayIndex(unsigned I) const {
02113     assert(I < getNumArrayIndices() && "Out of bounds member array index");
02114     return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
02115   }
02116   void setArrayIndex(unsigned I, VarDecl *Index) {
02117     assert(I < getNumArrayIndices() && "Out of bounds member array index");
02118     reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
02119   }
02120   ArrayRef<VarDecl *> getArrayIndexes() {
02121     assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
02122     return llvm::makeArrayRef(reinterpret_cast<VarDecl **>(this + 1),
02123                               getNumArrayIndices());
02124   }
02125 
02126   /// \brief Get the initializer.
02127   Expr *getInit() const { return static_cast<Expr*>(Init); }
02128 };
02129 
02130 /// \brief Represents a C++ constructor within a class.
02131 ///
02132 /// For example:
02133 ///
02134 /// \code
02135 /// class X {
02136 /// public:
02137 ///   explicit X(int); // represented by a CXXConstructorDecl.
02138 /// };
02139 /// \endcode
02140 class CXXConstructorDecl : public CXXMethodDecl {
02141   void anchor() override;
02142   /// \brief Whether this constructor declaration has the \c explicit keyword
02143   /// specified.
02144   bool IsExplicitSpecified : 1;
02145 
02146   /// \name Support for base and member initializers.
02147   /// \{
02148   /// \brief The arguments used to initialize the base or member.
02149   CXXCtorInitializer **CtorInitializers;
02150   unsigned NumCtorInitializers;
02151   /// \}
02152 
02153   CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
02154                      const DeclarationNameInfo &NameInfo,
02155                      QualType T, TypeSourceInfo *TInfo,
02156                      bool isExplicitSpecified, bool isInline,
02157                      bool isImplicitlyDeclared, bool isConstexpr)
02158     : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
02159                     SC_None, isInline, isConstexpr, SourceLocation()),
02160       IsExplicitSpecified(isExplicitSpecified), CtorInitializers(nullptr),
02161       NumCtorInitializers(0) {
02162     setImplicit(isImplicitlyDeclared);
02163   }
02164 
02165 public:
02166   static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02167   static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
02168                                     SourceLocation StartLoc,
02169                                     const DeclarationNameInfo &NameInfo,
02170                                     QualType T, TypeSourceInfo *TInfo,
02171                                     bool isExplicit,
02172                                     bool isInline, bool isImplicitlyDeclared,
02173                                     bool isConstexpr);
02174 
02175   /// \brief Determine whether this constructor declaration has the
02176   /// \c explicit keyword specified.
02177   bool isExplicitSpecified() const { return IsExplicitSpecified; }
02178 
02179   /// \brief Determine whether this constructor was marked "explicit" or not.
02180   bool isExplicit() const {
02181     return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
02182   }
02183 
02184   /// \brief Iterates through the member/base initializer list.
02185   typedef CXXCtorInitializer **init_iterator;
02186 
02187   /// \brief Iterates through the member/base initializer list.
02188   typedef CXXCtorInitializer * const * init_const_iterator;
02189 
02190   typedef llvm::iterator_range<init_iterator> init_range;
02191   typedef llvm::iterator_range<init_const_iterator> init_const_range;
02192 
02193   init_range inits() { return init_range(init_begin(), init_end()); }
02194   init_const_range inits() const {
02195     return init_const_range(init_begin(), init_end());
02196   }
02197 
02198   /// \brief Retrieve an iterator to the first initializer.
02199   init_iterator       init_begin()       { return CtorInitializers; }
02200   /// \brief Retrieve an iterator to the first initializer.
02201   init_const_iterator init_begin() const { return CtorInitializers; }
02202 
02203   /// \brief Retrieve an iterator past the last initializer.
02204   init_iterator       init_end()       {
02205     return CtorInitializers + NumCtorInitializers;
02206   }
02207   /// \brief Retrieve an iterator past the last initializer.
02208   init_const_iterator init_end() const {
02209     return CtorInitializers + NumCtorInitializers;
02210   }
02211 
02212   typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
02213   typedef std::reverse_iterator<init_const_iterator>
02214           init_const_reverse_iterator;
02215 
02216   init_reverse_iterator init_rbegin() {
02217     return init_reverse_iterator(init_end());
02218   }
02219   init_const_reverse_iterator init_rbegin() const {
02220     return init_const_reverse_iterator(init_end());
02221   }
02222 
02223   init_reverse_iterator init_rend() {
02224     return init_reverse_iterator(init_begin());
02225   }
02226   init_const_reverse_iterator init_rend() const {
02227     return init_const_reverse_iterator(init_begin());
02228   }
02229 
02230   /// \brief Determine the number of arguments used to initialize the member
02231   /// or base.
02232   unsigned getNumCtorInitializers() const {
02233       return NumCtorInitializers;
02234   }
02235 
02236   void setNumCtorInitializers(unsigned numCtorInitializers) {
02237     NumCtorInitializers = numCtorInitializers;
02238   }
02239 
02240   void setCtorInitializers(CXXCtorInitializer ** initializers) {
02241     CtorInitializers = initializers;
02242   }
02243 
02244   /// \brief Determine whether this constructor is a delegating constructor.
02245   bool isDelegatingConstructor() const {
02246     return (getNumCtorInitializers() == 1) &&
02247       CtorInitializers[0]->isDelegatingInitializer();
02248   }
02249 
02250   /// \brief When this constructor delegates to another, retrieve the target.
02251   CXXConstructorDecl *getTargetConstructor() const;
02252 
02253   /// Whether this constructor is a default
02254   /// constructor (C++ [class.ctor]p5), which can be used to
02255   /// default-initialize a class of this type.
02256   bool isDefaultConstructor() const;
02257 
02258   /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
02259   /// which can be used to copy the class.
02260   ///
02261   /// \p TypeQuals will be set to the qualifiers on the
02262   /// argument type. For example, \p TypeQuals would be set to \c
02263   /// Qualifiers::Const for the following copy constructor:
02264   ///
02265   /// \code
02266   /// class X {
02267   /// public:
02268   ///   X(const X&);
02269   /// };
02270   /// \endcode
02271   bool isCopyConstructor(unsigned &TypeQuals) const;
02272 
02273   /// Whether this constructor is a copy
02274   /// constructor (C++ [class.copy]p2, which can be used to copy the
02275   /// class.
02276   bool isCopyConstructor() const {
02277     unsigned TypeQuals = 0;
02278     return isCopyConstructor(TypeQuals);
02279   }
02280 
02281   /// \brief Determine whether this constructor is a move constructor
02282   /// (C++0x [class.copy]p3), which can be used to move values of the class.
02283   ///
02284   /// \param TypeQuals If this constructor is a move constructor, will be set
02285   /// to the type qualifiers on the referent of the first parameter's type.
02286   bool isMoveConstructor(unsigned &TypeQuals) const;
02287 
02288   /// \brief Determine whether this constructor is a move constructor
02289   /// (C++0x [class.copy]p3), which can be used to move values of the class.
02290   bool isMoveConstructor() const {
02291     unsigned TypeQuals = 0;
02292     return isMoveConstructor(TypeQuals);
02293   }
02294 
02295   /// \brief Determine whether this is a copy or move constructor.
02296   ///
02297   /// \param TypeQuals Will be set to the type qualifiers on the reference
02298   /// parameter, if in fact this is a copy or move constructor.
02299   bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
02300 
02301   /// \brief Determine whether this a copy or move constructor.
02302   bool isCopyOrMoveConstructor() const {
02303     unsigned Quals;
02304     return isCopyOrMoveConstructor(Quals);
02305   }
02306 
02307   /// Whether this constructor is a
02308   /// converting constructor (C++ [class.conv.ctor]), which can be
02309   /// used for user-defined conversions.
02310   bool isConvertingConstructor(bool AllowExplicit) const;
02311 
02312   /// \brief Determine whether this is a member template specialization that
02313   /// would copy the object to itself. Such constructors are never used to copy
02314   /// an object.
02315   bool isSpecializationCopyingObject() const;
02316 
02317   /// \brief Get the constructor that this inheriting constructor is based on.
02318   const CXXConstructorDecl *getInheritedConstructor() const;
02319 
02320   /// \brief Set the constructor that this inheriting constructor is based on.
02321   void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
02322 
02323   const CXXConstructorDecl *getCanonicalDecl() const override {
02324     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
02325   }
02326   CXXConstructorDecl *getCanonicalDecl() override {
02327     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
02328   }
02329 
02330   // Implement isa/cast/dyncast/etc.
02331   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02332   static bool classofKind(Kind K) { return K == CXXConstructor; }
02333 
02334   friend class ASTDeclReader;
02335   friend class ASTDeclWriter;
02336 };
02337 
02338 /// \brief Represents a C++ destructor within a class.
02339 ///
02340 /// For example:
02341 ///
02342 /// \code
02343 /// class X {
02344 /// public:
02345 ///   ~X(); // represented by a CXXDestructorDecl.
02346 /// };
02347 /// \endcode
02348 class CXXDestructorDecl : public CXXMethodDecl {
02349   void anchor() override;
02350 
02351   FunctionDecl *OperatorDelete;
02352 
02353   CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
02354                     const DeclarationNameInfo &NameInfo,
02355                     QualType T, TypeSourceInfo *TInfo,
02356                     bool isInline, bool isImplicitlyDeclared)
02357     : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
02358                     SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
02359       OperatorDelete(nullptr) {
02360     setImplicit(isImplicitlyDeclared);
02361   }
02362 
02363 public:
02364   static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
02365                                    SourceLocation StartLoc,
02366                                    const DeclarationNameInfo &NameInfo,
02367                                    QualType T, TypeSourceInfo* TInfo,
02368                                    bool isInline,
02369                                    bool isImplicitlyDeclared);
02370   static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
02371 
02372   void setOperatorDelete(FunctionDecl *OD) {
02373     cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete = OD;
02374   }
02375   const FunctionDecl *getOperatorDelete() const {
02376     return cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete;
02377   }
02378 
02379   // Implement isa/cast/dyncast/etc.
02380   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02381   static bool classofKind(Kind K) { return K == CXXDestructor; }
02382 
02383   friend class ASTDeclReader;
02384   friend class ASTDeclWriter;
02385 };
02386 
02387 /// \brief Represents a C++ conversion function within a class.
02388 ///
02389 /// For example:
02390 ///
02391 /// \code
02392 /// class X {
02393 /// public:
02394 ///   operator bool();
02395 /// };
02396 /// \endcode
02397 class CXXConversionDecl : public CXXMethodDecl {
02398   void anchor() override;
02399   /// Whether this conversion function declaration is marked
02400   /// "explicit", meaning that it can only be applied when the user
02401   /// explicitly wrote a cast. This is a C++0x feature.
02402   bool IsExplicitSpecified : 1;
02403 
02404   CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
02405                     const DeclarationNameInfo &NameInfo,
02406                     QualType T, TypeSourceInfo *TInfo,
02407                     bool isInline, bool isExplicitSpecified,
02408                     bool isConstexpr, SourceLocation EndLocation)
02409     : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
02410                     SC_None, isInline, isConstexpr, EndLocation),
02411       IsExplicitSpecified(isExplicitSpecified) { }
02412 
02413 public:
02414   static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
02415                                    SourceLocation StartLoc,
02416                                    const DeclarationNameInfo &NameInfo,
02417                                    QualType T, TypeSourceInfo *TInfo,
02418                                    bool isInline, bool isExplicit,
02419                                    bool isConstexpr,
02420                                    SourceLocation EndLocation);
02421   static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02422 
02423   /// Whether this conversion function declaration is marked
02424   /// "explicit", meaning that it can only be used for direct initialization
02425   /// (including explitly written casts).  This is a C++11 feature.
02426   bool isExplicitSpecified() const { return IsExplicitSpecified; }
02427 
02428   /// \brief Whether this is an explicit conversion operator (C++11 and later).
02429   ///
02430   /// Explicit conversion operators are only considered for direct
02431   /// initialization, e.g., when the user has explicitly written a cast.
02432   bool isExplicit() const {
02433     return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
02434   }
02435 
02436   /// \brief Returns the type that this conversion function is converting to.
02437   QualType getConversionType() const {
02438     return getType()->getAs<FunctionType>()->getReturnType();
02439   }
02440 
02441   /// \brief Determine whether this conversion function is a conversion from
02442   /// a lambda closure type to a block pointer.
02443   bool isLambdaToBlockPointerConversion() const;
02444   
02445   // Implement isa/cast/dyncast/etc.
02446   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02447   static bool classofKind(Kind K) { return K == CXXConversion; }
02448 
02449   friend class ASTDeclReader;
02450   friend class ASTDeclWriter;
02451 };
02452 
02453 /// \brief Represents a linkage specification. 
02454 ///
02455 /// For example:
02456 /// \code
02457 ///   extern "C" void foo();
02458 /// \endcode
02459 class LinkageSpecDecl : public Decl, public DeclContext {
02460   virtual void anchor();
02461 public:
02462   /// \brief Represents the language in a linkage specification.
02463   ///
02464   /// The values are part of the serialization ABI for
02465   /// ASTs and cannot be changed without altering that ABI.  To help
02466   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
02467   /// from the dwarf standard.
02468   enum LanguageIDs {
02469     lang_c = /* DW_LANG_C */ 0x0002,
02470     lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
02471   };
02472 private:
02473   /// \brief The language for this linkage specification.
02474   unsigned Language : 3;
02475   /// \brief True if this linkage spec has braces.
02476   ///
02477   /// This is needed so that hasBraces() returns the correct result while the
02478   /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
02479   /// not used, so it doesn't need to be serialized.
02480   unsigned HasBraces : 1;
02481   /// \brief The source location for the extern keyword.
02482   SourceLocation ExternLoc;
02483   /// \brief The source location for the right brace (if valid).
02484   SourceLocation RBraceLoc;
02485 
02486   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
02487                   SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
02488     : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
02489       Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
02490       RBraceLoc(SourceLocation()) { }
02491 
02492 public:
02493   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
02494                                  SourceLocation ExternLoc,
02495                                  SourceLocation LangLoc, LanguageIDs Lang,
02496                                  bool HasBraces);
02497   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02498   
02499   /// \brief Return the language specified by this linkage specification.
02500   LanguageIDs getLanguage() const { return LanguageIDs(Language); }
02501   /// \brief Set the language specified by this linkage specification.
02502   void setLanguage(LanguageIDs L) { Language = L; }
02503 
02504   /// \brief Determines whether this linkage specification had braces in
02505   /// its syntactic form.
02506   bool hasBraces() const {
02507     assert(!RBraceLoc.isValid() || HasBraces);
02508     return HasBraces;
02509   }
02510 
02511   SourceLocation getExternLoc() const { return ExternLoc; }
02512   SourceLocation getRBraceLoc() const { return RBraceLoc; }
02513   void setExternLoc(SourceLocation L) { ExternLoc = L; }
02514   void setRBraceLoc(SourceLocation L) {
02515     RBraceLoc = L;
02516     HasBraces = RBraceLoc.isValid();
02517   }
02518 
02519   SourceLocation getLocEnd() const LLVM_READONLY {
02520     if (hasBraces())
02521       return getRBraceLoc();
02522     // No braces: get the end location of the (only) declaration in context
02523     // (if present).
02524     return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
02525   }
02526 
02527   SourceRange getSourceRange() const override LLVM_READONLY {
02528     return SourceRange(ExternLoc, getLocEnd());
02529   }
02530 
02531   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02532   static bool classofKind(Kind K) { return K == LinkageSpec; }
02533   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
02534     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
02535   }
02536   static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
02537     return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
02538   }
02539 };
02540 
02541 /// \brief Represents C++ using-directive.
02542 ///
02543 /// For example:
02544 /// \code
02545 ///    using namespace std;
02546 /// \endcode
02547 ///
02548 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
02549 /// artificial names for all using-directives in order to store
02550 /// them in DeclContext effectively.
02551 class UsingDirectiveDecl : public NamedDecl {
02552   void anchor() override;
02553   /// \brief The location of the \c using keyword.
02554   SourceLocation UsingLoc;
02555 
02556   /// \brief The location of the \c namespace keyword.
02557   SourceLocation NamespaceLoc;
02558 
02559   /// \brief The nested-name-specifier that precedes the namespace.
02560   NestedNameSpecifierLoc QualifierLoc;
02561 
02562   /// \brief The namespace nominated by this using-directive.
02563   NamedDecl *NominatedNamespace;
02564 
02565   /// Enclosing context containing both using-directive and nominated
02566   /// namespace.
02567   DeclContext *CommonAncestor;
02568 
02569   /// \brief Returns special DeclarationName used by using-directives.
02570   ///
02571   /// This is only used by DeclContext for storing UsingDirectiveDecls in
02572   /// its lookup structure.
02573   static DeclarationName getName() {
02574     return DeclarationName::getUsingDirectiveName();
02575   }
02576 
02577   UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
02578                      SourceLocation NamespcLoc,
02579                      NestedNameSpecifierLoc QualifierLoc,
02580                      SourceLocation IdentLoc,
02581                      NamedDecl *Nominated,
02582                      DeclContext *CommonAncestor)
02583     : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
02584       NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
02585       NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
02586 
02587 public:
02588   /// \brief Retrieve the nested-name-specifier that qualifies the
02589   /// name of the namespace, with source-location information.
02590   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
02591 
02592   /// \brief Retrieve the nested-name-specifier that qualifies the
02593   /// name of the namespace.
02594   NestedNameSpecifier *getQualifier() const {
02595     return QualifierLoc.getNestedNameSpecifier();
02596   }
02597 
02598   NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
02599   const NamedDecl *getNominatedNamespaceAsWritten() const {
02600     return NominatedNamespace;
02601   }
02602 
02603   /// \brief Returns the namespace nominated by this using-directive.
02604   NamespaceDecl *getNominatedNamespace();
02605 
02606   const NamespaceDecl *getNominatedNamespace() const {
02607     return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
02608   }
02609 
02610   /// \brief Returns the common ancestor context of this using-directive and
02611   /// its nominated namespace.
02612   DeclContext *getCommonAncestor() { return CommonAncestor; }
02613   const DeclContext *getCommonAncestor() const { return CommonAncestor; }
02614 
02615   /// \brief Return the location of the \c using keyword.
02616   SourceLocation getUsingLoc() const { return UsingLoc; }
02617 
02618   // FIXME: Could omit 'Key' in name.
02619   /// \brief Returns the location of the \c namespace keyword.
02620   SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
02621 
02622   /// \brief Returns the location of this using declaration's identifier.
02623   SourceLocation getIdentLocation() const { return getLocation(); }
02624 
02625   static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
02626                                     SourceLocation UsingLoc,
02627                                     SourceLocation NamespaceLoc,
02628                                     NestedNameSpecifierLoc QualifierLoc,
02629                                     SourceLocation IdentLoc,
02630                                     NamedDecl *Nominated,
02631                                     DeclContext *CommonAncestor);
02632   static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02633 
02634   SourceRange getSourceRange() const override LLVM_READONLY {
02635     return SourceRange(UsingLoc, getLocation());
02636   }
02637 
02638   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02639   static bool classofKind(Kind K) { return K == UsingDirective; }
02640 
02641   // Friend for getUsingDirectiveName.
02642   friend class DeclContext;
02643 
02644   friend class ASTDeclReader;
02645 };
02646 
02647 /// \brief Represents a C++ namespace alias.
02648 ///
02649 /// For example:
02650 ///
02651 /// \code
02652 /// namespace Foo = Bar;
02653 /// \endcode
02654 class NamespaceAliasDecl : public NamedDecl,
02655                            public Redeclarable<NamespaceAliasDecl> {
02656   void anchor() override;
02657 
02658   /// \brief The location of the \c namespace keyword.
02659   SourceLocation NamespaceLoc;
02660 
02661   /// \brief The location of the namespace's identifier.
02662   ///
02663   /// This is accessed by TargetNameLoc.
02664   SourceLocation IdentLoc;
02665 
02666   /// \brief The nested-name-specifier that precedes the namespace.
02667   NestedNameSpecifierLoc QualifierLoc;
02668 
02669   /// \brief The Decl that this alias points to, either a NamespaceDecl or
02670   /// a NamespaceAliasDecl.
02671   NamedDecl *Namespace;
02672 
02673   NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
02674                      SourceLocation NamespaceLoc, SourceLocation AliasLoc,
02675                      IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
02676                      SourceLocation IdentLoc, NamedDecl *Namespace)
02677       : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
02678         NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
02679         QualifierLoc(QualifierLoc), Namespace(Namespace) {}
02680 
02681   typedef Redeclarable<NamespaceAliasDecl> redeclarable_base;
02682   NamespaceAliasDecl *getNextRedeclarationImpl() override;
02683   NamespaceAliasDecl *getPreviousDeclImpl() override;
02684   NamespaceAliasDecl *getMostRecentDeclImpl() override;
02685 
02686   friend class ASTDeclReader;
02687 
02688 public:
02689   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
02690                                     SourceLocation NamespaceLoc,
02691                                     SourceLocation AliasLoc,
02692                                     IdentifierInfo *Alias,
02693                                     NestedNameSpecifierLoc QualifierLoc,
02694                                     SourceLocation IdentLoc,
02695                                     NamedDecl *Namespace);
02696 
02697   static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02698 
02699   typedef redeclarable_base::redecl_range redecl_range;
02700   typedef redeclarable_base::redecl_iterator redecl_iterator;
02701   using redeclarable_base::redecls_begin;
02702   using redeclarable_base::redecls_end;
02703   using redeclarable_base::redecls;
02704   using redeclarable_base::getPreviousDecl;
02705   using redeclarable_base::getMostRecentDecl;
02706 
02707   NamespaceAliasDecl *getCanonicalDecl() override {
02708     return getFirstDecl();
02709   }
02710   const NamespaceAliasDecl *getCanonicalDecl() const {
02711     return getFirstDecl();
02712   }
02713 
02714   /// \brief Retrieve the nested-name-specifier that qualifies the
02715   /// name of the namespace, with source-location information.
02716   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
02717 
02718   /// \brief Retrieve the nested-name-specifier that qualifies the
02719   /// name of the namespace.
02720   NestedNameSpecifier *getQualifier() const {
02721     return QualifierLoc.getNestedNameSpecifier();
02722   }
02723 
02724   /// \brief Retrieve the namespace declaration aliased by this directive.
02725   NamespaceDecl *getNamespace() {
02726     if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
02727       return AD->getNamespace();
02728 
02729     return cast<NamespaceDecl>(Namespace);
02730   }
02731 
02732   const NamespaceDecl *getNamespace() const {
02733     return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
02734   }
02735 
02736   /// Returns the location of the alias name, i.e. 'foo' in
02737   /// "namespace foo = ns::bar;".
02738   SourceLocation getAliasLoc() const { return getLocation(); }
02739 
02740   /// Returns the location of the \c namespace keyword.
02741   SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
02742 
02743   /// Returns the location of the identifier in the named namespace.
02744   SourceLocation getTargetNameLoc() const { return IdentLoc; }
02745 
02746   /// \brief Retrieve the namespace that this alias refers to, which
02747   /// may either be a NamespaceDecl or a NamespaceAliasDecl.
02748   NamedDecl *getAliasedNamespace() const { return Namespace; }
02749 
02750   SourceRange getSourceRange() const override LLVM_READONLY {
02751     return SourceRange(NamespaceLoc, IdentLoc);
02752   }
02753 
02754   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02755   static bool classofKind(Kind K) { return K == NamespaceAlias; }
02756 };
02757 
02758 /// \brief Represents a shadow declaration introduced into a scope by a
02759 /// (resolved) using declaration.
02760 ///
02761 /// For example,
02762 /// \code
02763 /// namespace A {
02764 ///   void foo();
02765 /// }
02766 /// namespace B {
02767 ///   using A::foo; // <- a UsingDecl
02768 ///                 // Also creates a UsingShadowDecl for A::foo() in B
02769 /// }
02770 /// \endcode
02771 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
02772   void anchor() override;
02773 
02774   /// The referenced declaration.
02775   NamedDecl *Underlying;
02776 
02777   /// \brief The using declaration which introduced this decl or the next using
02778   /// shadow declaration contained in the aforementioned using declaration.
02779   NamedDecl *UsingOrNextShadow;
02780   friend class UsingDecl;
02781 
02782   UsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
02783                   UsingDecl *Using, NamedDecl *Target)
02784     : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
02785       redeclarable_base(C), Underlying(Target),
02786       UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
02787     if (Target) {
02788       setDeclName(Target->getDeclName());
02789       IdentifierNamespace = Target->getIdentifierNamespace();
02790     }
02791     setImplicit();
02792   }
02793 
02794   typedef Redeclarable<UsingShadowDecl> redeclarable_base;
02795   UsingShadowDecl *getNextRedeclarationImpl() override {
02796     return getNextRedeclaration();
02797   }
02798   UsingShadowDecl *getPreviousDeclImpl() override {
02799     return getPreviousDecl();
02800   }
02801   UsingShadowDecl *getMostRecentDeclImpl() override {
02802     return getMostRecentDecl();
02803   }
02804 
02805 public:
02806   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
02807                                  SourceLocation Loc, UsingDecl *Using,
02808                                  NamedDecl *Target) {
02809     return new (C, DC) UsingShadowDecl(C, DC, Loc, Using, Target);
02810   }
02811 
02812   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02813 
02814   typedef redeclarable_base::redecl_range redecl_range;
02815   typedef redeclarable_base::redecl_iterator redecl_iterator;
02816   using redeclarable_base::redecls_begin;
02817   using redeclarable_base::redecls_end;
02818   using redeclarable_base::redecls;
02819   using redeclarable_base::getPreviousDecl;
02820   using redeclarable_base::getMostRecentDecl;
02821 
02822   UsingShadowDecl *getCanonicalDecl() override {
02823     return getFirstDecl();
02824   }
02825   const UsingShadowDecl *getCanonicalDecl() const {
02826     return getFirstDecl();
02827   }
02828 
02829   /// \brief Gets the underlying declaration which has been brought into the
02830   /// local scope.
02831   NamedDecl *getTargetDecl() const { return Underlying; }
02832 
02833   /// \brief Sets the underlying declaration which has been brought into the
02834   /// local scope.
02835   void setTargetDecl(NamedDecl* ND) {
02836     assert(ND && "Target decl is null!");
02837     Underlying = ND;
02838     IdentifierNamespace = ND->getIdentifierNamespace();
02839   }
02840 
02841   /// \brief Gets the using declaration to which this declaration is tied.
02842   UsingDecl *getUsingDecl() const;
02843 
02844   /// \brief The next using shadow declaration contained in the shadow decl
02845   /// chain of the using declaration which introduced this decl.
02846   UsingShadowDecl *getNextUsingShadowDecl() const {
02847     return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
02848   }
02849 
02850   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02851   static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
02852 
02853   friend class ASTDeclReader;
02854   friend class ASTDeclWriter;
02855 };
02856 
02857 /// \brief Represents a C++ using-declaration.
02858 ///
02859 /// For example:
02860 /// \code
02861 ///    using someNameSpace::someIdentifier;
02862 /// \endcode
02863 class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
02864   void anchor() override;
02865 
02866   /// \brief The source location of the 'using' keyword itself.
02867   SourceLocation UsingLocation;
02868 
02869   /// \brief The nested-name-specifier that precedes the name.
02870   NestedNameSpecifierLoc QualifierLoc;
02871 
02872   /// \brief Provides source/type location info for the declaration name
02873   /// embedded in the ValueDecl base class.
02874   DeclarationNameLoc DNLoc;
02875 
02876   /// \brief The first shadow declaration of the shadow decl chain associated
02877   /// with this using declaration.
02878   ///
02879   /// The bool member of the pair store whether this decl has the \c typename
02880   /// keyword.
02881   llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
02882 
02883   UsingDecl(DeclContext *DC, SourceLocation UL,
02884             NestedNameSpecifierLoc QualifierLoc,
02885             const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
02886     : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
02887       UsingLocation(UL), QualifierLoc(QualifierLoc),
02888       DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
02889   }
02890 
02891 public:
02892   /// \brief Return the source location of the 'using' keyword.
02893   SourceLocation getUsingLoc() const { return UsingLocation; }
02894 
02895   /// \brief Set the source location of the 'using' keyword.
02896   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
02897 
02898   /// \brief Retrieve the nested-name-specifier that qualifies the name,
02899   /// with source-location information.
02900   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
02901 
02902   /// \brief Retrieve the nested-name-specifier that qualifies the name.
02903   NestedNameSpecifier *getQualifier() const {
02904     return QualifierLoc.getNestedNameSpecifier();
02905   }
02906 
02907   DeclarationNameInfo getNameInfo() const {
02908     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
02909   }
02910 
02911   /// \brief Return true if it is a C++03 access declaration (no 'using').
02912   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
02913 
02914   /// \brief Return true if the using declaration has 'typename'.
02915   bool hasTypename() const { return FirstUsingShadow.getInt(); }
02916 
02917   /// \brief Sets whether the using declaration has 'typename'.
02918   void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
02919 
02920   /// \brief Iterates through the using shadow declarations associated with
02921   /// this using declaration.
02922   class shadow_iterator {
02923     /// \brief The current using shadow declaration.
02924     UsingShadowDecl *Current;
02925 
02926   public:
02927     typedef UsingShadowDecl*          value_type;
02928     typedef UsingShadowDecl*          reference;
02929     typedef UsingShadowDecl*          pointer;
02930     typedef std::forward_iterator_tag iterator_category;
02931     typedef std::ptrdiff_t            difference_type;
02932 
02933     shadow_iterator() : Current(nullptr) { }
02934     explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
02935 
02936     reference operator*() const { return Current; }
02937     pointer operator->() const { return Current; }
02938 
02939     shadow_iterator& operator++() {
02940       Current = Current->getNextUsingShadowDecl();
02941       return *this;
02942     }
02943 
02944     shadow_iterator operator++(int) {
02945       shadow_iterator tmp(*this);
02946       ++(*this);
02947       return tmp;
02948     }
02949 
02950     friend bool operator==(shadow_iterator x, shadow_iterator y) {
02951       return x.Current == y.Current;
02952     }
02953     friend bool operator!=(shadow_iterator x, shadow_iterator y) {
02954       return x.Current != y.Current;
02955     }
02956   };
02957 
02958   typedef llvm::iterator_range<shadow_iterator> shadow_range;
02959 
02960   shadow_range shadows() const {
02961     return shadow_range(shadow_begin(), shadow_end());
02962   }
02963   shadow_iterator shadow_begin() const {
02964     return shadow_iterator(FirstUsingShadow.getPointer());
02965   }
02966   shadow_iterator shadow_end() const { return shadow_iterator(); }
02967 
02968   /// \brief Return the number of shadowed declarations associated with this
02969   /// using declaration.
02970   unsigned shadow_size() const {
02971     return std::distance(shadow_begin(), shadow_end());
02972   }
02973 
02974   void addShadowDecl(UsingShadowDecl *S);
02975   void removeShadowDecl(UsingShadowDecl *S);
02976 
02977   static UsingDecl *Create(ASTContext &C, DeclContext *DC,
02978                            SourceLocation UsingL,
02979                            NestedNameSpecifierLoc QualifierLoc,
02980                            const DeclarationNameInfo &NameInfo,
02981                            bool HasTypenameKeyword);
02982 
02983   static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02984 
02985   SourceRange getSourceRange() const override LLVM_READONLY;
02986 
02987   /// Retrieves the canonical declaration of this declaration.
02988   UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
02989   const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
02990 
02991   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02992   static bool classofKind(Kind K) { return K == Using; }
02993 
02994   friend class ASTDeclReader;
02995   friend class ASTDeclWriter;
02996 };
02997 
02998 /// \brief Represents a dependent using declaration which was not marked with
02999 /// \c typename.
03000 ///
03001 /// Unlike non-dependent using declarations, these *only* bring through
03002 /// non-types; otherwise they would break two-phase lookup.
03003 ///
03004 /// \code
03005 /// template <class T> class A : public Base<T> {
03006 ///   using Base<T>::foo;
03007 /// };
03008 /// \endcode
03009 class UnresolvedUsingValueDecl : public ValueDecl,
03010                                  public Mergeable<UnresolvedUsingValueDecl> {
03011   void anchor() override;
03012 
03013   /// \brief The source location of the 'using' keyword
03014   SourceLocation UsingLocation;
03015 
03016   /// \brief The nested-name-specifier that precedes the name.
03017   NestedNameSpecifierLoc QualifierLoc;
03018 
03019   /// \brief Provides source/type location info for the declaration name
03020   /// embedded in the ValueDecl base class.
03021   DeclarationNameLoc DNLoc;
03022 
03023   UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
03024                            SourceLocation UsingLoc,
03025                            NestedNameSpecifierLoc QualifierLoc,
03026                            const DeclarationNameInfo &NameInfo)
03027     : ValueDecl(UnresolvedUsingValue, DC,
03028                 NameInfo.getLoc(), NameInfo.getName(), Ty),
03029       UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
03030       DNLoc(NameInfo.getInfo())
03031   { }
03032 
03033 public:
03034   /// \brief Returns the source location of the 'using' keyword.
03035   SourceLocation getUsingLoc() const { return UsingLocation; }
03036 
03037   /// \brief Set the source location of the 'using' keyword.
03038   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
03039 
03040   /// \brief Return true if it is a C++03 access declaration (no 'using').
03041   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
03042 
03043   /// \brief Retrieve the nested-name-specifier that qualifies the name,
03044   /// with source-location information.
03045   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
03046 
03047   /// \brief Retrieve the nested-name-specifier that qualifies the name.
03048   NestedNameSpecifier *getQualifier() const {
03049     return QualifierLoc.getNestedNameSpecifier();
03050   }
03051 
03052   DeclarationNameInfo getNameInfo() const {
03053     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
03054   }
03055 
03056   static UnresolvedUsingValueDecl *
03057     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
03058            NestedNameSpecifierLoc QualifierLoc,
03059            const DeclarationNameInfo &NameInfo);
03060 
03061   static UnresolvedUsingValueDecl *
03062   CreateDeserialized(ASTContext &C, unsigned ID);
03063 
03064   SourceRange getSourceRange() const override LLVM_READONLY;
03065 
03066   /// Retrieves the canonical declaration of this declaration.
03067   UnresolvedUsingValueDecl *getCanonicalDecl() override {
03068     return getFirstDecl();
03069   }
03070   const UnresolvedUsingValueDecl *getCanonicalDecl() const {
03071     return getFirstDecl();
03072   }
03073 
03074   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03075   static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
03076 
03077   friend class ASTDeclReader;
03078   friend class ASTDeclWriter;
03079 };
03080 
03081 /// \brief Represents a dependent using declaration which was marked with
03082 /// \c typename.
03083 ///
03084 /// \code
03085 /// template <class T> class A : public Base<T> {
03086 ///   using typename Base<T>::foo;
03087 /// };
03088 /// \endcode
03089 ///
03090 /// The type associated with an unresolved using typename decl is
03091 /// currently always a typename type.
03092 class UnresolvedUsingTypenameDecl
03093     : public TypeDecl,
03094       public Mergeable<UnresolvedUsingTypenameDecl> {
03095   void anchor() override;
03096 
03097   /// \brief The source location of the 'typename' keyword
03098   SourceLocation TypenameLocation;
03099 
03100   /// \brief The nested-name-specifier that precedes the name.
03101   NestedNameSpecifierLoc QualifierLoc;
03102 
03103   UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
03104                               SourceLocation TypenameLoc,
03105                               NestedNameSpecifierLoc QualifierLoc,
03106                               SourceLocation TargetNameLoc,
03107                               IdentifierInfo *TargetName)
03108     : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
03109                UsingLoc),
03110       TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
03111 
03112   friend class ASTDeclReader;
03113 
03114 public:
03115   /// \brief Returns the source location of the 'using' keyword.
03116   SourceLocation getUsingLoc() const { return getLocStart(); }
03117 
03118   /// \brief Returns the source location of the 'typename' keyword.
03119   SourceLocation getTypenameLoc() const { return TypenameLocation; }
03120 
03121   /// \brief Retrieve the nested-name-specifier that qualifies the name,
03122   /// with source-location information.
03123   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
03124 
03125   /// \brief Retrieve the nested-name-specifier that qualifies the name.
03126   NestedNameSpecifier *getQualifier() const {
03127     return QualifierLoc.getNestedNameSpecifier();
03128   }
03129 
03130   static UnresolvedUsingTypenameDecl *
03131     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
03132            SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
03133            SourceLocation TargetNameLoc, DeclarationName TargetName);
03134 
03135   static UnresolvedUsingTypenameDecl *
03136   CreateDeserialized(ASTContext &C, unsigned ID);
03137 
03138   /// Retrieves the canonical declaration of this declaration.
03139   UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
03140     return getFirstDecl();
03141   }
03142   const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
03143     return getFirstDecl();
03144   }
03145 
03146   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03147   static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
03148 };
03149 
03150 /// \brief Represents a C++11 static_assert declaration.
03151 class StaticAssertDecl : public Decl {
03152   virtual void anchor();
03153   llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
03154   StringLiteral *Message;
03155   SourceLocation RParenLoc;
03156 
03157   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
03158                    Expr *AssertExpr, StringLiteral *Message,
03159                    SourceLocation RParenLoc, bool Failed)
03160     : Decl(StaticAssert, DC, StaticAssertLoc),
03161       AssertExprAndFailed(AssertExpr, Failed), Message(Message),
03162       RParenLoc(RParenLoc) { }
03163 
03164 public:
03165   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
03166                                   SourceLocation StaticAssertLoc,
03167                                   Expr *AssertExpr, StringLiteral *Message,
03168                                   SourceLocation RParenLoc, bool Failed);
03169   static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03170   
03171   Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
03172   const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
03173 
03174   StringLiteral *getMessage() { return Message; }
03175   const StringLiteral *getMessage() const { return Message; }
03176 
03177   bool isFailed() const { return AssertExprAndFailed.getInt(); }
03178 
03179   SourceLocation getRParenLoc() const { return RParenLoc; }
03180 
03181   SourceRange getSourceRange() const override LLVM_READONLY {
03182     return SourceRange(getLocation(), getRParenLoc());
03183   }
03184 
03185   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03186   static bool classofKind(Kind K) { return K == StaticAssert; }
03187 
03188   friend class ASTDeclReader;
03189 };
03190 
03191 /// An instance of this class represents the declaration of a property
03192 /// member.  This is a Microsoft extension to C++, first introduced in
03193 /// Visual Studio .NET 2003 as a parallel to similar features in C#
03194 /// and Managed C++.
03195 ///
03196 /// A property must always be a non-static class member.
03197 ///
03198 /// A property member superficially resembles a non-static data
03199 /// member, except preceded by a property attribute:
03200 ///   __declspec(property(get=GetX, put=PutX)) int x;
03201 /// Either (but not both) of the 'get' and 'put' names may be omitted.
03202 ///
03203 /// A reference to a property is always an lvalue.  If the lvalue
03204 /// undergoes lvalue-to-rvalue conversion, then a getter name is
03205 /// required, and that member is called with no arguments.
03206 /// If the lvalue is assigned into, then a setter name is required,
03207 /// and that member is called with one argument, the value assigned.
03208 /// Both operations are potentially overloaded.  Compound assignments
03209 /// are permitted, as are the increment and decrement operators.
03210 ///
03211 /// The getter and putter methods are permitted to be overloaded,
03212 /// although their return and parameter types are subject to certain
03213 /// restrictions according to the type of the property.
03214 ///
03215 /// A property declared using an incomplete array type may
03216 /// additionally be subscripted, adding extra parameters to the getter
03217 /// and putter methods.
03218 class MSPropertyDecl : public DeclaratorDecl {
03219   IdentifierInfo *GetterId, *SetterId;
03220 
03221   MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
03222                  QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
03223                  IdentifierInfo *Getter, IdentifierInfo *Setter)
03224       : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
03225         GetterId(Getter), SetterId(Setter) {}
03226 
03227 public:
03228   static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
03229                                 SourceLocation L, DeclarationName N, QualType T,
03230                                 TypeSourceInfo *TInfo, SourceLocation StartL,
03231                                 IdentifierInfo *Getter, IdentifierInfo *Setter);
03232   static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03233 
03234   static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
03235 
03236   bool hasGetter() const { return GetterId != nullptr; }
03237   IdentifierInfo* getGetterId() const { return GetterId; }
03238   bool hasSetter() const { return SetterId != nullptr; }
03239   IdentifierInfo* getSetterId() const { return SetterId; }
03240 
03241   friend class ASTDeclReader;
03242 };
03243 
03244 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
03245 /// into a diagnostic with <<.
03246 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
03247                                     AccessSpecifier AS);
03248 
03249 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
03250                                     AccessSpecifier AS);
03251 
03252 } // end namespace clang
03253 
03254 #endif