1193326Sed//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9263508Sdim/// 10263508Sdim/// \file 11263508Sdim/// \brief Defines the C++ Decl subclasses, other than those for templates 12263508Sdim/// (found in DeclTemplate.h) and friends (in DeclFriend.h). 13263508Sdim/// 14193326Sed//===----------------------------------------------------------------------===// 15193326Sed 16193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H 17193326Sed#define LLVM_CLANG_AST_DECLCXX_H 18193326Sed 19249423Sdim#include "clang/AST/ASTUnresolvedSet.h" 20249423Sdim#include "clang/AST/Decl.h" 21198092Srdivacky#include "clang/AST/Expr.h" 22234353Sdim#include "clang/AST/ExprCXX.h" 23212904Sdim#include "clang/AST/TypeLoc.h" 24234353Sdim#include "llvm/ADT/DenseMap.h" 25234353Sdim#include "llvm/ADT/PointerIntPair.h" 26198092Srdivacky#include "llvm/ADT/SmallPtrSet.h" 27234353Sdim#include "llvm/Support/Compiler.h" 28193326Sed 29193326Sednamespace clang { 30193326Sed 31193326Sedclass ClassTemplateDecl; 32198092Srdivackyclass ClassTemplateSpecializationDecl; 33198092Srdivackyclass CXXBasePath; 34198092Srdivackyclass CXXBasePaths; 35193326Sedclass CXXConstructorDecl; 36198092Srdivackyclass CXXConversionDecl; 37193326Sedclass CXXDestructorDecl; 38193326Sedclass CXXMethodDecl; 39198092Srdivackyclass CXXRecordDecl; 40198092Srdivackyclass CXXMemberLookupCriteria; 41206084Srdivackyclass CXXFinalOverriderMap; 42218893Sdimclass CXXIndirectPrimaryBaseSet; 43205219Srdivackyclass FriendDecl; 44234353Sdimclass LambdaExpr; 45239462Sdimclass UsingDecl; 46234353Sdim 47198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a 48195099Sed/// concrete function or a function template. 49195099Sedclass AnyFunctionDecl { 50195099Sed NamedDecl *Function; 51198092Srdivacky 52195341Sed AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 53198092Srdivacky 54195099Sedpublic: 55195099Sed AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 56195099Sed AnyFunctionDecl(FunctionTemplateDecl *FTD); 57198092Srdivacky 58198092Srdivacky /// \brief Implicily converts any function or function template into a 59195099Sed /// named declaration. 60195099Sed operator NamedDecl *() const { return Function; } 61198092Srdivacky 62195099Sed /// \brief Retrieve the underlying function or function template. 63195099Sed NamedDecl *get() const { return Function; } 64198092Srdivacky 65198092Srdivacky static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 66195341Sed return AnyFunctionDecl(ND); 67195341Sed } 68195099Sed}; 69198092Srdivacky 70195099Sed} // end namespace clang 71195099Sed 72195099Sednamespace llvm { 73195341Sed // Provide PointerLikeTypeTraits for non-cvr pointers. 74195341Sed template<> 75195341Sed class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 76195341Sed public: 77195341Sed static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 78198092Srdivacky return F.get(); 79195341Sed } 80195341Sed static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 81195341Sed return ::clang::AnyFunctionDecl::getFromNamedDecl( 82195341Sed static_cast< ::clang::NamedDecl*>(P)); 83195341Sed } 84198092Srdivacky 85195341Sed enum { NumLowBitsAvailable = 2 }; 86195341Sed }; 87198092Srdivacky 88195099Sed} // end namespace llvm 89195099Sed 90195099Sednamespace clang { 91198092Srdivacky 92263508Sdim/// \brief Represents an access specifier followed by colon ':'. 93210299Sed/// 94210299Sed/// An objects of this class represents sugar for the syntactic occurrence 95210299Sed/// of an access specifier followed by a colon in the list of member 96210299Sed/// specifiers of a C++ class definition. 97210299Sed/// 98210299Sed/// Note that they do not represent other uses of access specifiers, 99210299Sed/// such as those occurring in a list of base specifiers. 100210299Sed/// Also note that this class has nothing to do with so-called 101210299Sed/// "access declarations" (C++98 11.3 [class.access.dcl]). 102210299Sedclass AccessSpecDecl : public Decl { 103234353Sdim virtual void anchor(); 104239462Sdim /// \brief The location of the ':'. 105210299Sed SourceLocation ColonLoc; 106210299Sed 107210299Sed AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, 108210299Sed SourceLocation ASLoc, SourceLocation ColonLoc) 109210299Sed : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { 110210299Sed setAccess(AS); 111210299Sed } 112218893Sdim AccessSpecDecl(EmptyShell Empty) 113218893Sdim : Decl(AccessSpec, Empty) { } 114210299Sedpublic: 115239462Sdim /// \brief The location of the access specifier. 116210299Sed SourceLocation getAccessSpecifierLoc() const { return getLocation(); } 117239462Sdim /// \brief Sets the location of the access specifier. 118210299Sed void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } 119210299Sed 120239462Sdim /// \brief The location of the colon following the access specifier. 121210299Sed SourceLocation getColonLoc() const { return ColonLoc; } 122239462Sdim /// \brief Sets the location of the colon. 123210299Sed void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } 124210299Sed 125234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 126210299Sed return SourceRange(getAccessSpecifierLoc(), getColonLoc()); 127210299Sed } 128210299Sed 129210299Sed static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, 130210299Sed DeclContext *DC, SourceLocation ASLoc, 131210299Sed SourceLocation ColonLoc) { 132210299Sed return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); 133210299Sed } 134234353Sdim static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 135210299Sed 136210299Sed // Implement isa/cast/dyncast/etc. 137210299Sed static bool classof(const Decl *D) { return classofKind(D->getKind()); } 138210299Sed static bool classofKind(Kind K) { return K == AccessSpec; } 139210299Sed}; 140210299Sed 141210299Sed 142239462Sdim/// \brief Represents a base class of a C++ class. 143193326Sed/// 144193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 145193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 146193326Sed/// base class, whether it is a virtual or non-virtual base, and what 147193326Sed/// level of access (public, protected, private) is used for the 148193326Sed/// derivation. For example: 149193326Sed/// 150263508Sdim/// \code 151193326Sed/// class A { }; 152193326Sed/// class B { }; 153193326Sed/// class C : public virtual A, protected B { }; 154263508Sdim/// \endcode 155193326Sed/// 156193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 157193326Sed/// virtual A" and the other for "protected B". 158193326Sedclass CXXBaseSpecifier { 159263508Sdim /// \brief The source code range that covers the full base 160193326Sed /// specifier, including the "virtual" (if present) and access 161193326Sed /// specifier (if present). 162193326Sed SourceRange Range; 163193326Sed 164218893Sdim /// \brief The source location of the ellipsis, if this is a pack 165218893Sdim /// expansion. 166218893Sdim SourceLocation EllipsisLoc; 167234353Sdim 168239462Sdim /// \brief Whether this is a virtual base class or not. 169193326Sed bool Virtual : 1; 170193326Sed 171263508Sdim /// \brief Whether this is the base of a class (true) or of a struct (false). 172263508Sdim /// 173263508Sdim /// This determines the mapping from the access specifier as written in the 174263508Sdim /// source code to the access specifier used for semantic analysis. 175198092Srdivacky bool BaseOfClass : 1; 176193326Sed 177263508Sdim /// \brief Access specifier as written in the source code (may be AS_none). 178263508Sdim /// 179263508Sdim /// The actual type of data stored here is an AccessSpecifier, but we use 180263508Sdim /// "unsigned" here to work around a VC++ bug. 181193326Sed unsigned Access : 2; 182193326Sed 183263508Sdim /// \brief Whether the class contains a using declaration 184218893Sdim /// to inherit the named class's constructors. 185218893Sdim bool InheritConstructors : 1; 186218893Sdim 187263508Sdim /// \brief The type of the base class. 188263508Sdim /// 189263508Sdim /// This will be a class or struct (or a typedef of such). The source code 190263508Sdim /// range does not include the \c virtual or the access specifier. 191212904Sdim TypeSourceInfo *BaseTypeInfo; 192198092Srdivacky 193193326Sedpublic: 194193326Sed CXXBaseSpecifier() { } 195193326Sed 196212904Sdim CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, 197218893Sdim TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) 198234353Sdim : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), 199218893Sdim Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { } 200193326Sed 201263508Sdim /// \brief Retrieves the source range that contains the entire base specifier. 202234353Sdim SourceRange getSourceRange() const LLVM_READONLY { return Range; } 203234353Sdim SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 204234353Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 205198092Srdivacky 206263508Sdim /// \brief Determines whether the base class is a virtual base class (or not). 207193326Sed bool isVirtual() const { return Virtual; } 208193326Sed 209212904Sdim /// \brief Determine whether this base class is a base of a class declared 210203955Srdivacky /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 211203955Srdivacky bool isBaseOfClass() const { return BaseOfClass; } 212234353Sdim 213218893Sdim /// \brief Determine whether this base specifier is a pack expansion. 214218893Sdim bool isPackExpansion() const { return EllipsisLoc.isValid(); } 215218893Sdim 216218893Sdim /// \brief Determine whether this base class's constructors get inherited. 217218893Sdim bool getInheritConstructors() const { return InheritConstructors; } 218218893Sdim 219218893Sdim /// \brief Set that this base class's constructors should be inherited. 220218893Sdim void setInheritConstructors(bool Inherit = true) { 221218893Sdim InheritConstructors = Inherit; 222218893Sdim } 223218893Sdim 224218893Sdim /// \brief For a pack expansion, determine the location of the ellipsis. 225218893Sdim SourceLocation getEllipsisLoc() const { 226218893Sdim return EllipsisLoc; 227218893Sdim } 228218893Sdim 229263508Sdim /// \brief Returns the access specifier for this base specifier. 230263508Sdim /// 231263508Sdim /// This is the actual base specifier as used for semantic analysis, so 232263508Sdim /// the result can never be AS_none. To retrieve the access specifier as 233263508Sdim /// written in the source code, use getAccessSpecifierAsWritten(). 234198092Srdivacky AccessSpecifier getAccessSpecifier() const { 235193326Sed if ((AccessSpecifier)Access == AS_none) 236193326Sed return BaseOfClass? AS_private : AS_public; 237193326Sed else 238198092Srdivacky return (AccessSpecifier)Access; 239193326Sed } 240193326Sed 241263508Sdim /// \brief Retrieves the access specifier as written in the source code 242263508Sdim /// (which may mean that no access specifier was explicitly written). 243263508Sdim /// 244263508Sdim /// Use getAccessSpecifier() to retrieve the access specifier for use in 245263508Sdim /// semantic analysis. 246193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 247193326Sed return (AccessSpecifier)Access; 248193326Sed } 249193326Sed 250263508Sdim /// \brief Retrieves the type of the base class. 251263508Sdim /// 252263508Sdim /// This type will always be an unqualified class type. 253263508Sdim QualType getType() const { 254263508Sdim return BaseTypeInfo->getType().getUnqualifiedType(); 255263508Sdim } 256212904Sdim 257263508Sdim /// \brief Retrieves the type and source location of the base class. 258212904Sdim TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } 259193326Sed}; 260193326Sed 261251662Sdim/// The inheritance model to use for member pointers of a given CXXRecordDecl. 262251662Sdimenum MSInheritanceModel { 263251662Sdim MSIM_Single, 264251662Sdim MSIM_SinglePolymorphic, 265251662Sdim MSIM_Multiple, 266251662Sdim MSIM_MultiplePolymorphic, 267251662Sdim MSIM_Virtual, 268251662Sdim MSIM_Unspecified 269251662Sdim}; 270251662Sdim 271263508Sdim/// \brief Represents a C++ struct/union/class. 272263508Sdim/// 273193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 274193326Sed/// to deal with C++-specific things. 275193326Sedclass CXXRecordDecl : public RecordDecl { 276193326Sed 277203955Srdivacky friend void TagDecl::startDefinition(); 278193326Sed 279249423Sdim /// Values used in DefinitionData fields to represent special members. 280249423Sdim enum SpecialMemberFlags { 281249423Sdim SMF_DefaultConstructor = 0x1, 282249423Sdim SMF_CopyConstructor = 0x2, 283249423Sdim SMF_MoveConstructor = 0x4, 284249423Sdim SMF_CopyAssignment = 0x8, 285249423Sdim SMF_MoveAssignment = 0x10, 286249423Sdim SMF_Destructor = 0x20, 287249423Sdim SMF_All = 0x3f 288249423Sdim }; 289249423Sdim 290203955Srdivacky struct DefinitionData { 291203955Srdivacky DefinitionData(CXXRecordDecl *D); 292193326Sed 293249423Sdim /// \brief True if this class has any user-declared constructors. 294203955Srdivacky bool UserDeclaredConstructor : 1; 295193326Sed 296263508Sdim /// \brief The user-declared special members which this class has. 297249423Sdim unsigned UserDeclaredSpecialMembers : 6; 298193326Sed 299263508Sdim /// \brief True when this class is an aggregate. 300203955Srdivacky bool Aggregate : 1; 301193326Sed 302263508Sdim /// \brief True when this class is a POD-type. 303203955Srdivacky bool PlainOldData : 1; 304198092Srdivacky 305263508Sdim /// true when this class is empty for traits purposes, 306203955Srdivacky /// i.e. has no data members other than 0-width bit-fields, has no 307203955Srdivacky /// virtual function/base, and doesn't inherit from a non-empty 308203955Srdivacky /// class. Doesn't take union-ness into account. 309203955Srdivacky bool Empty : 1; 310198092Srdivacky 311263508Sdim /// \brief True when this class is polymorphic, i.e., has at 312203955Srdivacky /// least one virtual member or derives from a polymorphic class. 313203955Srdivacky bool Polymorphic : 1; 314198092Srdivacky 315263508Sdim /// \brief True when this class is abstract, i.e., has at least 316203955Srdivacky /// one pure virtual function, (that can come from a base class). 317203955Srdivacky bool Abstract : 1; 318198092Srdivacky 319263508Sdim /// \brief True when this class has standard layout. 320221345Sdim /// 321263508Sdim /// C++11 [class]p7. A standard-layout class is a class that: 322221345Sdim /// * has no non-static data members of type non-standard-layout class (or 323221345Sdim /// array of such types) or reference, 324221345Sdim /// * has no virtual functions (10.3) and no virtual base classes (10.1), 325234353Sdim /// * has the same access control (Clause 11) for all non-static data 326234353Sdim /// members 327221345Sdim /// * has no non-standard-layout base classes, 328221345Sdim /// * either has no non-static data members in the most derived class and at 329221345Sdim /// most one base class with non-static data members, or has no base 330221345Sdim /// classes with non-static data members, and 331221345Sdim /// * has no base classes of the same type as the first non-static data 332221345Sdim /// member. 333221345Sdim bool IsStandardLayout : 1; 334221345Sdim 335263508Sdim /// \brief True when there are no non-empty base classes. 336221345Sdim /// 337221345Sdim /// This is a helper bit of state used to implement IsStandardLayout more 338221345Sdim /// efficiently. 339221345Sdim bool HasNoNonEmptyBases : 1; 340221345Sdim 341263508Sdim /// \brief True when there are private non-static data members. 342221345Sdim bool HasPrivateFields : 1; 343221345Sdim 344263508Sdim /// \brief True when there are protected non-static data members. 345221345Sdim bool HasProtectedFields : 1; 346221345Sdim 347263508Sdim /// \brief True when there are private non-static data members. 348221345Sdim bool HasPublicFields : 1; 349221345Sdim 350223017Sdim /// \brief True if this class (or any subobject) has mutable fields. 351223017Sdim bool HasMutableFields : 1; 352234353Sdim 353234353Sdim /// \brief True if there no non-field members declared by the user. 354234353Sdim bool HasOnlyCMembers : 1; 355234353Sdim 356239462Sdim /// \brief True if any field has an in-class initializer. 357239462Sdim bool HasInClassInitializer : 1; 358239462Sdim 359249423Sdim /// \brief True if any field is of reference type, and does not have an 360263508Sdim /// in-class initializer. 361263508Sdim /// 362263508Sdim /// In this case, value-initialization of this class is illegal in C++98 363263508Sdim /// even if the class has a trivial default constructor. 364249423Sdim bool HasUninitializedReferenceMember : 1; 365249423Sdim 366249423Sdim /// \brief These flags are \c true if a defaulted corresponding special 367249423Sdim /// member can't be fully analyzed without performing overload resolution. 368249423Sdim /// @{ 369249423Sdim bool NeedOverloadResolutionForMoveConstructor : 1; 370249423Sdim bool NeedOverloadResolutionForMoveAssignment : 1; 371249423Sdim bool NeedOverloadResolutionForDestructor : 1; 372249423Sdim /// @} 373249423Sdim 374249423Sdim /// \brief These flags are \c true if an implicit defaulted corresponding 375249423Sdim /// special member would be defined as deleted. 376249423Sdim /// @{ 377249423Sdim bool DefaultedMoveConstructorIsDeleted : 1; 378249423Sdim bool DefaultedMoveAssignmentIsDeleted : 1; 379249423Sdim bool DefaultedDestructorIsDeleted : 1; 380249423Sdim /// @} 381249423Sdim 382249423Sdim /// \brief The trivial special members which this class has, per 383249423Sdim /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25, 384249423Sdim /// C++11 [class.dtor]p5, or would have if the member were not suppressed. 385203955Srdivacky /// 386249423Sdim /// This excludes any user-declared but not user-provided special members 387249423Sdim /// which have been declared but not yet defined. 388249423Sdim unsigned HasTrivialSpecialMembers : 6; 389198092Srdivacky 390249423Sdim /// \brief The declared special members of this class which are known to be 391249423Sdim /// non-trivial. 392249423Sdim /// 393249423Sdim /// This excludes any user-declared but not user-provided special members 394249423Sdim /// which have been declared but not yet defined, and any implicit special 395249423Sdim /// members which have not yet been declared. 396249423Sdim unsigned DeclaredNonTrivialSpecialMembers : 6; 397249423Sdim 398263508Sdim /// \brief True when this class has a destructor with no semantic effect. 399249423Sdim bool HasIrrelevantDestructor : 1; 400249423Sdim 401263508Sdim /// \brief True when this class has at least one user-declared constexpr 402263508Sdim /// constructor which is neither the copy nor move constructor. 403226633Sdim bool HasConstexprNonCopyMoveConstructor : 1; 404221345Sdim 405263508Sdim /// \brief True if a defaulted default constructor for this class would 406263508Sdim /// be constexpr. 407234353Sdim bool DefaultedDefaultConstructorIsConstexpr : 1; 408234353Sdim 409263508Sdim /// \brief True if this class has a constexpr default constructor. 410263508Sdim /// 411263508Sdim /// This is true for either a user-declared constexpr default constructor 412263508Sdim /// or an implicitly declared constexpr default constructor.. 413234353Sdim bool HasConstexprDefaultConstructor : 1; 414234353Sdim 415263508Sdim /// \brief True when this class contains at least one non-static data 416263508Sdim /// member or base class of non-literal or volatile type. 417221345Sdim bool HasNonLiteralTypeFieldsOrBases : 1; 418221345Sdim 419263508Sdim /// \brief True when visible conversion functions are already computed 420263508Sdim /// and are available. 421203955Srdivacky bool ComputedVisibleConversions : 1; 422210299Sed 423249423Sdim /// \brief Whether we have a C++11 user-provided default constructor (not 424223017Sdim /// explicitly deleted or defaulted). 425223017Sdim bool UserProvidedDefaultConstructor : 1; 426223017Sdim 427249423Sdim /// \brief The special members which have been declared for this class, 428249423Sdim /// either by the user or implicitly. 429249423Sdim unsigned DeclaredSpecialMembers : 6; 430210299Sed 431249423Sdim /// \brief Whether an implicit copy constructor would have a const-qualified 432249423Sdim /// parameter. 433249423Sdim bool ImplicitCopyConstructorHasConstParam : 1; 434223017Sdim 435249423Sdim /// \brief Whether an implicit copy assignment operator would have a 436249423Sdim /// const-qualified parameter. 437249423Sdim bool ImplicitCopyAssignmentHasConstParam : 1; 438234353Sdim 439249423Sdim /// \brief Whether any declared copy constructor has a const-qualified 440249423Sdim /// parameter. 441249423Sdim bool HasDeclaredCopyConstructorWithConstParam : 1; 442223017Sdim 443249423Sdim /// \brief Whether any declared copy assignment operator has either a 444249423Sdim /// const-qualified reference parameter or a non-reference parameter. 445249423Sdim bool HasDeclaredCopyAssignmentWithConstParam : 1; 446234353Sdim 447234353Sdim /// \brief Whether this class describes a C++ lambda. 448234353Sdim bool IsLambda : 1; 449234353Sdim 450263508Sdim /// \brief The number of base class specifiers in Bases. 451218893Sdim unsigned NumBases; 452234353Sdim 453263508Sdim /// \brief The number of virtual base class specifiers in VBases. 454218893Sdim unsigned NumVBases; 455218893Sdim 456263508Sdim /// \brief Base classes of this class. 457263508Sdim /// 458203955Srdivacky /// FIXME: This is wasted space for a union. 459218893Sdim LazyCXXBaseSpecifiersPtr Bases; 460193326Sed 461263508Sdim /// \brief direct and indirect virtual base classes of this class. 462218893Sdim LazyCXXBaseSpecifiersPtr VBases; 463198092Srdivacky 464263508Sdim /// \brief The conversion functions of this C++ class (but not its 465263508Sdim /// inherited conversion functions). 466263508Sdim /// 467263508Sdim /// Each of the entries in this overload set is a CXXConversionDecl. 468263508Sdim LazyASTUnresolvedSet Conversions; 469193326Sed 470263508Sdim /// \brief The conversion functions of this C++ class and all those 471263508Sdim /// inherited conversion functions that are visible in this class. 472263508Sdim /// 473263508Sdim /// Each of the entries in this overload set is a CXXConversionDecl or a 474203955Srdivacky /// FunctionTemplateDecl. 475263508Sdim LazyASTUnresolvedSet VisibleConversions; 476203955Srdivacky 477263508Sdim /// \brief The declaration which defines this record. 478203955Srdivacky CXXRecordDecl *Definition; 479203955Srdivacky 480263508Sdim /// \brief The first friend declaration in this class, or null if there 481263508Sdim /// aren't any. 482263508Sdim /// 483263508Sdim /// This is actually currently stored in reverse order. 484263508Sdim LazyDeclPtr FirstFriend; 485205219Srdivacky 486234353Sdim /// \brief Retrieve the set of direct base classes. 487218893Sdim CXXBaseSpecifier *getBases() const { 488239462Sdim if (!Bases.isOffset()) 489239462Sdim return Bases.get(0); 490239462Sdim return getBasesSlowCase(); 491218893Sdim } 492218893Sdim 493234353Sdim /// \brief Retrieve the set of virtual base classes. 494218893Sdim CXXBaseSpecifier *getVBases() const { 495239462Sdim if (!VBases.isOffset()) 496239462Sdim return VBases.get(0); 497239462Sdim return getVBasesSlowCase(); 498218893Sdim } 499239462Sdim 500239462Sdim private: 501239462Sdim CXXBaseSpecifier *getBasesSlowCase() const; 502239462Sdim CXXBaseSpecifier *getVBasesSlowCase() const; 503203955Srdivacky } *DefinitionData; 504203955Srdivacky 505234353Sdim /// \brief Describes a C++ closure type (generated by a lambda expression). 506234353Sdim struct LambdaDefinitionData : public DefinitionData { 507234353Sdim typedef LambdaExpr::Capture Capture; 508234353Sdim 509263508Sdim LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, 510263508Sdim bool Dependent, bool IsGeneric, 511263508Sdim LambdaCaptureDefault CaptureDefault) 512263508Sdim : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), 513263508Sdim CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), 514263508Sdim ManglingNumber(0), ContextDecl(0), Captures(0), MethodTyInfo(Info) 515234353Sdim { 516234353Sdim IsLambda = true; 517234353Sdim } 518234353Sdim 519234353Sdim /// \brief Whether this lambda is known to be dependent, even if its 520234353Sdim /// context isn't dependent. 521234353Sdim /// 522234353Sdim /// A lambda with a non-dependent context can be dependent if it occurs 523234353Sdim /// within the default argument of a function template, because the 524234353Sdim /// lambda will have been created with the enclosing context as its 525234353Sdim /// declaration context, rather than function. This is an unfortunate 526263508Sdim /// artifact of having to parse the default arguments before. 527234353Sdim unsigned Dependent : 1; 528234353Sdim 529263508Sdim /// \brief Whether this lambda is a generic lambda. 530263508Sdim unsigned IsGenericLambda : 1; 531234353Sdim 532263508Sdim /// \brief The Default Capture. 533263508Sdim unsigned CaptureDefault : 2; 534263508Sdim 535263508Sdim /// \brief The number of captures in this lambda is limited 2^NumCaptures. 536263508Sdim unsigned NumCaptures : 15; 537263508Sdim 538234353Sdim /// \brief The number of explicit captures in this lambda. 539263508Sdim unsigned NumExplicitCaptures : 13; 540234353Sdim 541234353Sdim /// \brief The number used to indicate this lambda expression for name 542234353Sdim /// mangling in the Itanium C++ ABI. 543234353Sdim unsigned ManglingNumber; 544234353Sdim 545234353Sdim /// \brief The declaration that provides context for this lambda, if the 546234353Sdim /// actual DeclContext does not suffice. This is used for lambdas that 547234353Sdim /// occur within default arguments of function parameters within the class 548234353Sdim /// or within a data member initializer. 549234353Sdim Decl *ContextDecl; 550234353Sdim 551234353Sdim /// \brief The list of captures, both explicit and implicit, for this 552234353Sdim /// lambda. 553243830Sdim Capture *Captures; 554243830Sdim 555243830Sdim /// \brief The type of the call method. 556243830Sdim TypeSourceInfo *MethodTyInfo; 557263508Sdim 558234353Sdim }; 559234353Sdim 560203955Srdivacky struct DefinitionData &data() { 561203955Srdivacky assert(DefinitionData && "queried property of class with no definition"); 562203955Srdivacky return *DefinitionData; 563203955Srdivacky } 564203955Srdivacky 565203955Srdivacky const struct DefinitionData &data() const { 566203955Srdivacky assert(DefinitionData && "queried property of class with no definition"); 567203955Srdivacky return *DefinitionData; 568203955Srdivacky } 569234353Sdim 570234353Sdim struct LambdaDefinitionData &getLambdaData() const { 571234353Sdim assert(DefinitionData && "queried property of lambda with no definition"); 572234353Sdim assert(DefinitionData->IsLambda && 573234353Sdim "queried lambda property of non-lambda class"); 574234353Sdim return static_cast<LambdaDefinitionData &>(*DefinitionData); 575234353Sdim } 576198092Srdivacky 577193326Sed /// \brief The template or declaration that this declaration 578193326Sed /// describes or was instantiated from, respectively. 579198092Srdivacky /// 580263508Sdim /// For non-templates, this value will be null. For record 581193326Sed /// declarations that describe a class template, this will be a 582193326Sed /// pointer to a ClassTemplateDecl. For member 583193326Sed /// classes of class template specializations, this will be the 584234353Sdim /// MemberSpecializationInfo referring to the member class that was 585198092Srdivacky /// instantiated or specialized. 586198092Srdivacky llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 587193326Sed TemplateOrInstantiation; 588206084Srdivacky 589218893Sdim friend class DeclContext; 590234353Sdim friend class LambdaExpr; 591234353Sdim 592249423Sdim /// \brief Called from setBases and addedMember to notify the class that a 593249423Sdim /// direct or virtual base class or a member of class type has been added. 594249423Sdim void addedClassSubobject(CXXRecordDecl *Base); 595249423Sdim 596218893Sdim /// \brief Notify the class that member has been added. 597218893Sdim /// 598234353Sdim /// This routine helps maintain information about the class based on which 599218893Sdim /// members have been added. It will be invoked by DeclContext::addDecl() 600218893Sdim /// whenever a member is added to this record. 601218893Sdim void addedMember(Decl *D); 602218893Sdim 603218893Sdim void markedVirtualFunctionPure(); 604218893Sdim friend void FunctionDecl::setPure(bool); 605234353Sdim 606234353Sdim friend class ASTNodeImporter; 607234353Sdim 608263508Sdim /// \brief Get the head of our list of friend declarations, possibly 609263508Sdim /// deserializing the friends from an external AST source. 610263508Sdim FriendDecl *getFirstFriend() const; 611263508Sdim 612193326Sedprotected: 613193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 614221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 615221345Sdim IdentifierInfo *Id, CXXRecordDecl *PrevDecl); 616193326Sed 617193326Sedpublic: 618263508Sdim /// \brief Iterator that traverses the base classes of a class. 619193326Sed typedef CXXBaseSpecifier* base_class_iterator; 620193326Sed 621263508Sdim /// \brief Iterator that traverses the base classes of a class. 622193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 623193326Sed 624263508Sdim /// \brief Iterator that traverses the base classes of a class in reverse 625263508Sdim /// order. 626198092Srdivacky typedef std::reverse_iterator<base_class_iterator> 627198092Srdivacky reverse_base_class_iterator; 628198092Srdivacky 629263508Sdim /// \brief Iterator that traverses the base classes of a class in reverse 630263508Sdim /// order. 631198092Srdivacky typedef std::reverse_iterator<base_class_const_iterator> 632198092Srdivacky reverse_base_class_const_iterator; 633198092Srdivacky 634198092Srdivacky virtual CXXRecordDecl *getCanonicalDecl() { 635198092Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 636198092Srdivacky } 637199482Srdivacky virtual const CXXRecordDecl *getCanonicalDecl() const { 638199482Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 639199482Srdivacky } 640234353Sdim 641263508Sdim CXXRecordDecl *getPreviousDecl() { 642263508Sdim return cast_or_null<CXXRecordDecl>( 643263508Sdim static_cast<RecordDecl *>(this)->getPreviousDecl()); 644263508Sdim } 645234353Sdim const CXXRecordDecl *getPreviousDecl() const { 646263508Sdim return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); 647210299Sed } 648263508Sdim 649263508Sdim CXXRecordDecl *getMostRecentDecl() { 650263508Sdim return cast<CXXRecordDecl>( 651263508Sdim static_cast<RecordDecl *>(this)->getMostRecentDecl()); 652210299Sed } 653198092Srdivacky 654234353Sdim const CXXRecordDecl *getMostRecentDecl() const { 655263508Sdim return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); 656234353Sdim } 657234353Sdim 658203955Srdivacky CXXRecordDecl *getDefinition() const { 659203955Srdivacky if (!DefinitionData) return 0; 660203955Srdivacky return data().Definition; 661203955Srdivacky } 662203955Srdivacky 663203955Srdivacky bool hasDefinition() const { return DefinitionData != 0; } 664203955Srdivacky 665218893Sdim static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 666221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 667221345Sdim IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0, 668193326Sed bool DelayTypeCreation = false); 669234353Sdim static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, 670243830Sdim TypeSourceInfo *Info, SourceLocation Loc, 671263508Sdim bool DependentLambda, bool IsGeneric, 672263508Sdim LambdaCaptureDefault CaptureDefault); 673234353Sdim static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); 674198092Srdivacky 675198092Srdivacky bool isDynamicClass() const { 676203955Srdivacky return data().Polymorphic || data().NumVBases != 0; 677198092Srdivacky } 678198092Srdivacky 679263508Sdim /// \brief Sets the base classes of this struct or class. 680203955Srdivacky void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 681193326Sed 682263508Sdim /// \brief Retrieves the number of base classes of this class. 683203955Srdivacky unsigned getNumBases() const { return data().NumBases; } 684193326Sed 685218893Sdim base_class_iterator bases_begin() { return data().getBases(); } 686218893Sdim base_class_const_iterator bases_begin() const { return data().getBases(); } 687203955Srdivacky base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 688203955Srdivacky base_class_const_iterator bases_end() const { 689203955Srdivacky return bases_begin() + data().NumBases; 690203955Srdivacky } 691198092Srdivacky reverse_base_class_iterator bases_rbegin() { 692198092Srdivacky return reverse_base_class_iterator(bases_end()); 693198092Srdivacky } 694198092Srdivacky reverse_base_class_const_iterator bases_rbegin() const { 695198092Srdivacky return reverse_base_class_const_iterator(bases_end()); 696198092Srdivacky } 697198092Srdivacky reverse_base_class_iterator bases_rend() { 698198092Srdivacky return reverse_base_class_iterator(bases_begin()); 699198092Srdivacky } 700198092Srdivacky reverse_base_class_const_iterator bases_rend() const { 701198092Srdivacky return reverse_base_class_const_iterator(bases_begin()); 702198092Srdivacky } 703193326Sed 704263508Sdim /// \brief Retrieves the number of virtual base classes of this class. 705203955Srdivacky unsigned getNumVBases() const { return data().NumVBases; } 706198092Srdivacky 707218893Sdim base_class_iterator vbases_begin() { return data().getVBases(); } 708218893Sdim base_class_const_iterator vbases_begin() const { return data().getVBases(); } 709203955Srdivacky base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 710203955Srdivacky base_class_const_iterator vbases_end() const { 711203955Srdivacky return vbases_begin() + data().NumVBases; 712203955Srdivacky } 713198092Srdivacky reverse_base_class_iterator vbases_rbegin() { 714198092Srdivacky return reverse_base_class_iterator(vbases_end()); 715198092Srdivacky } 716198092Srdivacky reverse_base_class_const_iterator vbases_rbegin() const { 717198092Srdivacky return reverse_base_class_const_iterator(vbases_end()); 718198092Srdivacky } 719198092Srdivacky reverse_base_class_iterator vbases_rend() { 720198092Srdivacky return reverse_base_class_iterator(vbases_begin()); 721198092Srdivacky } 722198092Srdivacky reverse_base_class_const_iterator vbases_rend() const { 723198092Srdivacky return reverse_base_class_const_iterator(vbases_begin()); 724198092Srdivacky } 725198092Srdivacky 726249423Sdim /// \brief Determine whether this class has any dependent base classes which 727249423Sdim /// are not the current instantiation. 728202379Srdivacky bool hasAnyDependentBases() const; 729202379Srdivacky 730198092Srdivacky /// Iterator access to method members. The method iterator visits 731198092Srdivacky /// all method members of the class, including non-instance methods, 732198092Srdivacky /// special methods, etc. 733198092Srdivacky typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 734198092Srdivacky 735263508Sdim /// \brief Method begin iterator. Iterates in the order the methods 736198092Srdivacky /// were declared. 737198092Srdivacky method_iterator method_begin() const { 738198092Srdivacky return method_iterator(decls_begin()); 739198092Srdivacky } 740263508Sdim /// \brief Method past-the-end iterator. 741198092Srdivacky method_iterator method_end() const { 742198092Srdivacky return method_iterator(decls_end()); 743198092Srdivacky } 744198092Srdivacky 745198092Srdivacky /// Iterator access to constructor members. 746198092Srdivacky typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 747198092Srdivacky 748198092Srdivacky ctor_iterator ctor_begin() const { 749198092Srdivacky return ctor_iterator(decls_begin()); 750198092Srdivacky } 751198092Srdivacky ctor_iterator ctor_end() const { 752198092Srdivacky return ctor_iterator(decls_end()); 753198092Srdivacky } 754198092Srdivacky 755205219Srdivacky /// An iterator over friend declarations. All of these are defined 756205219Srdivacky /// in DeclFriend.h. 757205219Srdivacky class friend_iterator; 758205219Srdivacky friend_iterator friend_begin() const; 759205219Srdivacky friend_iterator friend_end() const; 760205219Srdivacky void pushFriendDecl(FriendDecl *FD); 761205219Srdivacky 762207619Srdivacky /// Determines whether this record has any friends. 763207619Srdivacky bool hasFriends() const { 764263508Sdim return data().FirstFriend.isValid(); 765207619Srdivacky } 766207619Srdivacky 767249423Sdim /// \brief \c true if we know for sure that this class has a single, 768249423Sdim /// accessible, unambiguous move constructor that is not deleted. 769249423Sdim bool hasSimpleMoveConstructor() const { 770263508Sdim return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && 771263508Sdim !data().DefaultedMoveConstructorIsDeleted; 772249423Sdim } 773249423Sdim /// \brief \c true if we know for sure that this class has a single, 774249423Sdim /// accessible, unambiguous move assignment operator that is not deleted. 775249423Sdim bool hasSimpleMoveAssignment() const { 776263508Sdim return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && 777263508Sdim !data().DefaultedMoveAssignmentIsDeleted; 778249423Sdim } 779249423Sdim /// \brief \c true if we know for sure that this class has an accessible 780249423Sdim /// destructor that is not deleted. 781249423Sdim bool hasSimpleDestructor() const { 782249423Sdim return !hasUserDeclaredDestructor() && 783249423Sdim !data().DefaultedDestructorIsDeleted; 784249423Sdim } 785249423Sdim 786249423Sdim /// \brief Determine whether this class has any default constructors. 787249423Sdim bool hasDefaultConstructor() const { 788249423Sdim return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || 789249423Sdim needsImplicitDefaultConstructor(); 790249423Sdim } 791249423Sdim 792223017Sdim /// \brief Determine if we need to declare a default constructor for 793223017Sdim /// this class. 794210299Sed /// 795210299Sed /// This value is used for lazy creation of default constructors. 796223017Sdim bool needsImplicitDefaultConstructor() const { 797234353Sdim return !data().UserDeclaredConstructor && 798249423Sdim !(data().DeclaredSpecialMembers & SMF_DefaultConstructor); 799223017Sdim } 800223017Sdim 801263508Sdim /// \brief Determine whether this class has any user-declared constructors. 802263508Sdim /// 803263508Sdim /// When true, a default constructor will not be implicitly declared. 804198092Srdivacky bool hasUserDeclaredConstructor() const { 805203955Srdivacky return data().UserDeclaredConstructor; 806198092Srdivacky } 807193326Sed 808263508Sdim /// \brief Whether this class has a user-provided default constructor 809263508Sdim /// per C++11. 810223017Sdim bool hasUserProvidedDefaultConstructor() const { 811223017Sdim return data().UserProvidedDefaultConstructor; 812223017Sdim } 813223017Sdim 814263508Sdim /// \brief Determine whether this class has a user-declared copy constructor. 815263508Sdim /// 816263508Sdim /// When false, a copy constructor will be implicitly declared. 817193326Sed bool hasUserDeclaredCopyConstructor() const { 818249423Sdim return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; 819193326Sed } 820193326Sed 821249423Sdim /// \brief Determine whether this class needs an implicit copy 822249423Sdim /// constructor to be lazily declared. 823249423Sdim bool needsImplicitCopyConstructor() const { 824249423Sdim return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); 825210299Sed } 826223017Sdim 827249423Sdim /// \brief Determine whether we need to eagerly declare a defaulted copy 828249423Sdim /// constructor for this class. 829249423Sdim bool needsOverloadResolutionForCopyConstructor() const { 830249423Sdim return data().HasMutableFields; 831249423Sdim } 832249423Sdim 833249423Sdim /// \brief Determine whether an implicit copy constructor for this type 834249423Sdim /// would have a parameter with a const-qualified reference type. 835249423Sdim bool implicitCopyConstructorHasConstParam() const { 836249423Sdim return data().ImplicitCopyConstructorHasConstParam; 837249423Sdim } 838249423Sdim 839249423Sdim /// \brief Determine whether this class has a copy constructor with 840249423Sdim /// a parameter type which is a reference to a const-qualified type. 841249423Sdim bool hasCopyConstructorWithConstParam() const { 842249423Sdim return data().HasDeclaredCopyConstructorWithConstParam || 843249423Sdim (needsImplicitCopyConstructor() && 844249423Sdim implicitCopyConstructorHasConstParam()); 845249423Sdim } 846249423Sdim 847263508Sdim /// \brief Whether this class has a user-declared move constructor or 848263508Sdim /// assignment operator. 849263508Sdim /// 850263508Sdim /// When false, a move constructor and assignment operator may be 851263508Sdim /// implicitly declared. 852223017Sdim bool hasUserDeclaredMoveOperation() const { 853249423Sdim return data().UserDeclaredSpecialMembers & 854249423Sdim (SMF_MoveConstructor | SMF_MoveAssignment); 855223017Sdim } 856223017Sdim 857223017Sdim /// \brief Determine whether this class has had a move constructor 858223017Sdim /// declared by the user. 859223017Sdim bool hasUserDeclaredMoveConstructor() const { 860249423Sdim return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; 861223017Sdim } 862223017Sdim 863249423Sdim /// \brief Determine whether this class has a move constructor. 864249423Sdim bool hasMoveConstructor() const { 865249423Sdim return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || 866249423Sdim needsImplicitMoveConstructor(); 867223017Sdim } 868223017Sdim 869263508Sdim /// \brief Set that we attempted to declare an implicitly move 870263508Sdim /// constructor, but overload resolution failed so we deleted it. 871263508Sdim void setImplicitMoveConstructorIsDeleted() { 872263508Sdim assert((data().DefaultedMoveConstructorIsDeleted || 873263508Sdim needsOverloadResolutionForMoveConstructor()) && 874263508Sdim "move constructor should not be deleted"); 875263508Sdim data().DefaultedMoveConstructorIsDeleted = true; 876226633Sdim } 877226633Sdim 878226633Sdim /// \brief Determine whether this class should get an implicit move 879226633Sdim /// constructor or if any existing special member function inhibits this. 880226633Sdim bool needsImplicitMoveConstructor() const { 881263508Sdim return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && 882226633Sdim !hasUserDeclaredCopyConstructor() && 883226633Sdim !hasUserDeclaredCopyAssignment() && 884226633Sdim !hasUserDeclaredMoveAssignment() && 885263508Sdim !hasUserDeclaredDestructor(); 886226633Sdim } 887226633Sdim 888249423Sdim /// \brief Determine whether we need to eagerly declare a defaulted move 889249423Sdim /// constructor for this class. 890249423Sdim bool needsOverloadResolutionForMoveConstructor() const { 891249423Sdim return data().NeedOverloadResolutionForMoveConstructor; 892249423Sdim } 893249423Sdim 894263508Sdim /// \brief Determine whether this class has a user-declared copy assignment 895263508Sdim /// operator. 896263508Sdim /// 897263508Sdim /// When false, a copy assigment operator will be implicitly declared. 898193326Sed bool hasUserDeclaredCopyAssignment() const { 899249423Sdim return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; 900193326Sed } 901193326Sed 902249423Sdim /// \brief Determine whether this class needs an implicit copy 903249423Sdim /// assignment operator to be lazily declared. 904249423Sdim bool needsImplicitCopyAssignment() const { 905249423Sdim return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); 906210299Sed } 907223017Sdim 908249423Sdim /// \brief Determine whether we need to eagerly declare a defaulted copy 909249423Sdim /// assignment operator for this class. 910249423Sdim bool needsOverloadResolutionForCopyAssignment() const { 911249423Sdim return data().HasMutableFields; 912249423Sdim } 913249423Sdim 914249423Sdim /// \brief Determine whether an implicit copy assignment operator for this 915249423Sdim /// type would have a parameter with a const-qualified reference type. 916249423Sdim bool implicitCopyAssignmentHasConstParam() const { 917249423Sdim return data().ImplicitCopyAssignmentHasConstParam; 918249423Sdim } 919249423Sdim 920249423Sdim /// \brief Determine whether this class has a copy assignment operator with 921249423Sdim /// a parameter type which is a reference to a const-qualified type or is not 922263508Sdim /// a reference. 923249423Sdim bool hasCopyAssignmentWithConstParam() const { 924249423Sdim return data().HasDeclaredCopyAssignmentWithConstParam || 925249423Sdim (needsImplicitCopyAssignment() && 926249423Sdim implicitCopyAssignmentHasConstParam()); 927249423Sdim } 928249423Sdim 929223017Sdim /// \brief Determine whether this class has had a move assignment 930223017Sdim /// declared by the user. 931223017Sdim bool hasUserDeclaredMoveAssignment() const { 932249423Sdim return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; 933223017Sdim } 934223017Sdim 935249423Sdim /// \brief Determine whether this class has a move assignment operator. 936249423Sdim bool hasMoveAssignment() const { 937249423Sdim return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || 938249423Sdim needsImplicitMoveAssignment(); 939223017Sdim } 940223017Sdim 941263508Sdim /// \brief Set that we attempted to declare an implicit move assignment 942263508Sdim /// operator, but overload resolution failed so we deleted it. 943263508Sdim void setImplicitMoveAssignmentIsDeleted() { 944263508Sdim assert((data().DefaultedMoveAssignmentIsDeleted || 945263508Sdim needsOverloadResolutionForMoveAssignment()) && 946263508Sdim "move assignment should not be deleted"); 947263508Sdim data().DefaultedMoveAssignmentIsDeleted = true; 948226633Sdim } 949226633Sdim 950226633Sdim /// \brief Determine whether this class should get an implicit move 951226633Sdim /// assignment operator or if any existing special member function inhibits 952226633Sdim /// this. 953226633Sdim bool needsImplicitMoveAssignment() const { 954263508Sdim return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && 955226633Sdim !hasUserDeclaredCopyConstructor() && 956226633Sdim !hasUserDeclaredCopyAssignment() && 957226633Sdim !hasUserDeclaredMoveConstructor() && 958263508Sdim !hasUserDeclaredDestructor(); 959226633Sdim } 960226633Sdim 961249423Sdim /// \brief Determine whether we need to eagerly declare a move assignment 962249423Sdim /// operator for this class. 963249423Sdim bool needsOverloadResolutionForMoveAssignment() const { 964249423Sdim return data().NeedOverloadResolutionForMoveAssignment; 965249423Sdim } 966249423Sdim 967263508Sdim /// \brief Determine whether this class has a user-declared destructor. 968263508Sdim /// 969263508Sdim /// When false, a destructor will be implicitly declared. 970203955Srdivacky bool hasUserDeclaredDestructor() const { 971249423Sdim return data().UserDeclaredSpecialMembers & SMF_Destructor; 972203955Srdivacky } 973193326Sed 974249423Sdim /// \brief Determine whether this class needs an implicit destructor to 975249423Sdim /// be lazily declared. 976249423Sdim bool needsImplicitDestructor() const { 977249423Sdim return !(data().DeclaredSpecialMembers & SMF_Destructor); 978249423Sdim } 979218893Sdim 980249423Sdim /// \brief Determine whether we need to eagerly declare a destructor for this 981249423Sdim /// class. 982249423Sdim bool needsOverloadResolutionForDestructor() const { 983249423Sdim return data().NeedOverloadResolutionForDestructor; 984249423Sdim } 985249423Sdim 986234353Sdim /// \brief Determine whether this class describes a lambda function object. 987234353Sdim bool isLambda() const { return hasDefinition() && data().IsLambda; } 988249423Sdim 989263508Sdim /// \brief Determine whether this class describes a generic 990263508Sdim /// lambda function object (i.e. function call operator is 991263508Sdim /// a template). 992263508Sdim bool isGenericLambda() const; 993263508Sdim 994263508Sdim /// \brief Retrieve the lambda call operator of the closure type 995263508Sdim /// if this is a closure type. 996263508Sdim CXXMethodDecl *getLambdaCallOperator() const; 997263508Sdim 998263508Sdim /// \brief Retrieve the lambda static invoker, the address of which 999263508Sdim /// is returned by the conversion operator, and the body of which 1000263508Sdim /// is forwarded to the lambda call operator. 1001263508Sdim CXXMethodDecl *getLambdaStaticInvoker() const; 1002263508Sdim 1003263508Sdim /// \brief Retrieve the generic lambda's template parameter list. 1004263508Sdim /// Returns null if the class does not represent a lambda or a generic 1005263508Sdim /// lambda. 1006263508Sdim TemplateParameterList *getGenericLambdaTemplateParameterList() const; 1007263508Sdim 1008263508Sdim LambdaCaptureDefault getLambdaCaptureDefault() const { 1009263508Sdim assert(isLambda()); 1010263508Sdim return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); 1011263508Sdim } 1012263508Sdim 1013234353Sdim /// \brief For a closure type, retrieve the mapping from captured 1014263508Sdim /// variables and \c this to the non-static data members that store the 1015234353Sdim /// values or references of the captures. 1016234353Sdim /// 1017234353Sdim /// \param Captures Will be populated with the mapping from captured 1018234353Sdim /// variables to the corresponding fields. 1019234353Sdim /// 1020234353Sdim /// \param ThisCapture Will be set to the field declaration for the 1021263508Sdim /// \c this capture. 1022263508Sdim /// 1023263508Sdim /// \note No entries will be added for init-captures, as they do not capture 1024263508Sdim /// variables. 1025234353Sdim void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, 1026234353Sdim FieldDecl *&ThisCapture) const; 1027234353Sdim 1028234353Sdim typedef const LambdaExpr::Capture* capture_const_iterator; 1029234353Sdim capture_const_iterator captures_begin() const { 1030234353Sdim return isLambda() ? getLambdaData().Captures : NULL; 1031234353Sdim } 1032234353Sdim capture_const_iterator captures_end() const { 1033234353Sdim return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL; 1034234353Sdim } 1035234353Sdim 1036249423Sdim typedef UnresolvedSetIterator conversion_iterator; 1037203955Srdivacky conversion_iterator conversion_begin() const { 1038263508Sdim return data().Conversions.get(getASTContext()).begin(); 1039203955Srdivacky } 1040203955Srdivacky conversion_iterator conversion_end() const { 1041263508Sdim return data().Conversions.get(getASTContext()).end(); 1042203955Srdivacky } 1043199990Srdivacky 1044206084Srdivacky /// Removes a conversion function from this class. The conversion 1045206084Srdivacky /// function must currently be a member of this class. Furthermore, 1046206084Srdivacky /// this class must currently be in the process of being defined. 1047206084Srdivacky void removeConversion(const NamedDecl *Old); 1048206084Srdivacky 1049263508Sdim /// \brief Get all conversion functions visible in current class, 1050263508Sdim /// including conversion function templates. 1051249423Sdim std::pair<conversion_iterator, conversion_iterator> 1052249423Sdim getVisibleConversionFunctions(); 1053199990Srdivacky 1054263508Sdim /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), 1055263508Sdim /// which is a class with no user-declared constructors, no private 1056263508Sdim /// or protected non-static data members, no base classes, and no virtual 1057263508Sdim /// functions (C++ [dcl.init.aggr]p1). 1058203955Srdivacky bool isAggregate() const { return data().Aggregate; } 1059193326Sed 1060263508Sdim /// \brief Whether this class has any in-class initializers 1061239462Sdim /// for non-static data members. 1062239462Sdim bool hasInClassInitializer() const { return data().HasInClassInitializer; } 1063239462Sdim 1064249423Sdim /// \brief Whether this class or any of its subobjects has any members of 1065263508Sdim /// reference type which would make value-initialization ill-formed. 1066263508Sdim /// 1067263508Sdim /// Per C++03 [dcl.init]p5: 1068263508Sdim /// - if T is a non-union class type without a user-declared constructor, 1069263508Sdim /// then every non-static data member and base-class component of T is 1070263508Sdim /// value-initialized [...] A program that calls for [...] 1071263508Sdim /// value-initialization of an entity of reference type is ill-formed. 1072249423Sdim bool hasUninitializedReferenceMember() const { 1073249423Sdim return !isUnion() && !hasUserDeclaredConstructor() && 1074249423Sdim data().HasUninitializedReferenceMember; 1075249423Sdim } 1076249423Sdim 1077263508Sdim /// \brief Whether this class is a POD-type (C++ [class]p4) 1078263508Sdim /// 1079263508Sdim /// For purposes of this function a class is POD if it is an aggregate 1080263508Sdim /// that has no non-static non-POD data members, no reference data 1081263508Sdim /// members, no user-defined copy assignment operator and no 1082193326Sed /// user-defined destructor. 1083249423Sdim /// 1084249423Sdim /// Note that this is the C++ TR1 definition of POD. 1085203955Srdivacky bool isPOD() const { return data().PlainOldData; } 1086193326Sed 1087234353Sdim /// \brief True if this class is C-like, without C++-specific features, e.g. 1088234353Sdim /// it contains only public fields, no bases, tag kind is not 'class', etc. 1089234353Sdim bool isCLike() const; 1090234353Sdim 1091263508Sdim /// \brief Determine whether this is an empty class in the sense of 1092263508Sdim /// (C++11 [meta.unary.prop]). 1093263508Sdim /// 1094263508Sdim /// A non-union class is empty iff it has a virtual function, virtual base, 1095263508Sdim /// data member (other than 0-width bit-field) or inherits from a non-empty 1096263508Sdim /// class. 1097263508Sdim /// 1098263508Sdim /// \note This does NOT include a check for union-ness. 1099203955Srdivacky bool isEmpty() const { return data().Empty; } 1100198092Srdivacky 1101263508Sdim /// Whether this class is polymorphic (C++ [class.virtual]), 1102193326Sed /// which means that the class contains or inherits a virtual function. 1103203955Srdivacky bool isPolymorphic() const { return data().Polymorphic; } 1104193326Sed 1105263508Sdim /// \brief Determine whether this class has a pure virtual function. 1106263508Sdim /// 1107263508Sdim /// The class is is abstract per (C++ [class.abstract]p2) if it declares 1108263508Sdim /// a pure virtual function or inherits a pure virtual function that is 1109263508Sdim /// not overridden. 1110203955Srdivacky bool isAbstract() const { return data().Abstract; } 1111198092Srdivacky 1112263508Sdim /// \brief Determine whether this class has standard layout per 1113221345Sdim /// (C++ [class]p7) 1114221345Sdim bool isStandardLayout() const { return data().IsStandardLayout; } 1115221345Sdim 1116263508Sdim /// \brief Determine whether this class, or any of its class subobjects, 1117263508Sdim /// contains a mutable field. 1118223017Sdim bool hasMutableFields() const { return data().HasMutableFields; } 1119234353Sdim 1120249423Sdim /// \brief Determine whether this class has a trivial default constructor 1121249423Sdim /// (C++11 [class.ctor]p5). 1122223017Sdim bool hasTrivialDefaultConstructor() const { 1123249423Sdim return hasDefaultConstructor() && 1124249423Sdim (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); 1125223017Sdim } 1126198092Srdivacky 1127249423Sdim /// \brief Determine whether this class has a non-trivial default constructor 1128249423Sdim /// (C++11 [class.ctor]p5). 1129249423Sdim bool hasNonTrivialDefaultConstructor() const { 1130249423Sdim return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || 1131249423Sdim (needsImplicitDefaultConstructor() && 1132249423Sdim !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); 1133249423Sdim } 1134249423Sdim 1135249423Sdim /// \brief Determine whether this class has at least one constexpr constructor 1136249423Sdim /// other than the copy or move constructors. 1137226633Sdim bool hasConstexprNonCopyMoveConstructor() const { 1138234353Sdim return data().HasConstexprNonCopyMoveConstructor || 1139249423Sdim (needsImplicitDefaultConstructor() && 1140234353Sdim defaultedDefaultConstructorIsConstexpr()); 1141221345Sdim } 1142221345Sdim 1143249423Sdim /// \brief Determine whether a defaulted default constructor for this class 1144249423Sdim /// would be constexpr. 1145234353Sdim bool defaultedDefaultConstructorIsConstexpr() const { 1146239462Sdim return data().DefaultedDefaultConstructorIsConstexpr && 1147239462Sdim (!isUnion() || hasInClassInitializer()); 1148234353Sdim } 1149234353Sdim 1150249423Sdim /// \brief Determine whether this class has a constexpr default constructor. 1151234353Sdim bool hasConstexprDefaultConstructor() const { 1152234353Sdim return data().HasConstexprDefaultConstructor || 1153249423Sdim (needsImplicitDefaultConstructor() && 1154239462Sdim defaultedDefaultConstructorIsConstexpr()); 1155234353Sdim } 1156234353Sdim 1157249423Sdim /// \brief Determine whether this class has a trivial copy constructor 1158249423Sdim /// (C++ [class.copy]p6, C++11 [class.copy]p12) 1159203955Srdivacky bool hasTrivialCopyConstructor() const { 1160249423Sdim return data().HasTrivialSpecialMembers & SMF_CopyConstructor; 1161203955Srdivacky } 1162198092Srdivacky 1163249423Sdim /// \brief Determine whether this class has a non-trivial copy constructor 1164249423Sdim /// (C++ [class.copy]p6, C++11 [class.copy]p12) 1165249423Sdim bool hasNonTrivialCopyConstructor() const { 1166249423Sdim return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || 1167249423Sdim !hasTrivialCopyConstructor(); 1168249423Sdim } 1169249423Sdim 1170249423Sdim /// \brief Determine whether this class has a trivial move constructor 1171249423Sdim /// (C++11 [class.copy]p12) 1172221345Sdim bool hasTrivialMoveConstructor() const { 1173249423Sdim return hasMoveConstructor() && 1174249423Sdim (data().HasTrivialSpecialMembers & SMF_MoveConstructor); 1175221345Sdim } 1176221345Sdim 1177249423Sdim /// \brief Determine whether this class has a non-trivial move constructor 1178249423Sdim /// (C++11 [class.copy]p12) 1179249423Sdim bool hasNonTrivialMoveConstructor() const { 1180249423Sdim return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || 1181249423Sdim (needsImplicitMoveConstructor() && 1182249423Sdim !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); 1183249423Sdim } 1184249423Sdim 1185249423Sdim /// \brief Determine whether this class has a trivial copy assignment operator 1186249423Sdim /// (C++ [class.copy]p11, C++11 [class.copy]p25) 1187203955Srdivacky bool hasTrivialCopyAssignment() const { 1188249423Sdim return data().HasTrivialSpecialMembers & SMF_CopyAssignment; 1189203955Srdivacky } 1190198092Srdivacky 1191249423Sdim /// \brief Determine whether this class has a non-trivial copy assignment 1192249423Sdim /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) 1193249423Sdim bool hasNonTrivialCopyAssignment() const { 1194249423Sdim return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || 1195249423Sdim !hasTrivialCopyAssignment(); 1196249423Sdim } 1197249423Sdim 1198249423Sdim /// \brief Determine whether this class has a trivial move assignment operator 1199249423Sdim /// (C++11 [class.copy]p25) 1200221345Sdim bool hasTrivialMoveAssignment() const { 1201249423Sdim return hasMoveAssignment() && 1202249423Sdim (data().HasTrivialSpecialMembers & SMF_MoveAssignment); 1203221345Sdim } 1204221345Sdim 1205249423Sdim /// \brief Determine whether this class has a non-trivial move assignment 1206249423Sdim /// operator (C++11 [class.copy]p25) 1207249423Sdim bool hasNonTrivialMoveAssignment() const { 1208249423Sdim return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || 1209249423Sdim (needsImplicitMoveAssignment() && 1210249423Sdim !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); 1211249423Sdim } 1212198092Srdivacky 1213249423Sdim /// \brief Determine whether this class has a trivial destructor 1214249423Sdim /// (C++ [class.dtor]p3) 1215249423Sdim bool hasTrivialDestructor() const { 1216249423Sdim return data().HasTrivialSpecialMembers & SMF_Destructor; 1217249423Sdim } 1218249423Sdim 1219249423Sdim /// \brief Determine whether this class has a non-trivial destructor 1220249423Sdim /// (C++ [class.dtor]p3) 1221249423Sdim bool hasNonTrivialDestructor() const { 1222249423Sdim return !(data().HasTrivialSpecialMembers & SMF_Destructor); 1223249423Sdim } 1224249423Sdim 1225263508Sdim /// \brief Determine whether this class has a destructor which has no 1226263508Sdim /// semantic effect. 1227263508Sdim /// 1228263508Sdim /// Any such destructor will be trivial, public, defaulted and not deleted, 1229263508Sdim /// and will call only irrelevant destructors. 1230234353Sdim bool hasIrrelevantDestructor() const { 1231234353Sdim return data().HasIrrelevantDestructor; 1232234353Sdim } 1233234353Sdim 1234263508Sdim /// \brief Determine whether this class has a non-literal or/ volatile type 1235263508Sdim /// non-static data member or base class. 1236221345Sdim bool hasNonLiteralTypeFieldsOrBases() const { 1237221345Sdim return data().HasNonLiteralTypeFieldsOrBases; 1238221345Sdim } 1239221345Sdim 1240263508Sdim /// \brief Determine whether this class is considered trivially copyable per 1241263508Sdim /// (C++11 [class]p6). 1242221345Sdim bool isTriviallyCopyable() const; 1243221345Sdim 1244263508Sdim /// \brief Determine whether this class is considered trivial. 1245263508Sdim /// 1246263508Sdim /// C++11 [class]p6: 1247263508Sdim /// "A trivial class is a class that has a trivial default constructor and 1248263508Sdim /// is trivially copiable." 1249223017Sdim bool isTrivial() const { 1250223017Sdim return isTriviallyCopyable() && hasTrivialDefaultConstructor(); 1251223017Sdim } 1252223017Sdim 1253263508Sdim /// \brief Determine whether this class is a literal type. 1254263508Sdim /// 1255263508Sdim /// C++11 [basic.types]p10: 1256263508Sdim /// A class type that has all the following properties: 1257263508Sdim /// - it has a trivial destructor 1258263508Sdim /// - every constructor call and full-expression in the 1259263508Sdim /// brace-or-equal-intializers for non-static data members (if any) is 1260263508Sdim /// a constant expression. 1261263508Sdim /// - it is an aggregate type or has at least one constexpr constructor 1262263508Sdim /// or constructor template that is not a copy or move constructor, and 1263263508Sdim /// - all of its non-static data members and base classes are of literal 1264263508Sdim /// types 1265263508Sdim /// 1266263508Sdim /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by 1267263508Sdim /// treating types with trivial default constructors as literal types. 1268226633Sdim bool isLiteral() const { 1269226633Sdim return hasTrivialDestructor() && 1270234353Sdim (isAggregate() || hasConstexprNonCopyMoveConstructor() || 1271234353Sdim hasTrivialDefaultConstructor()) && 1272226633Sdim !hasNonLiteralTypeFieldsOrBases(); 1273226633Sdim } 1274226633Sdim 1275193326Sed /// \brief If this record is an instantiation of a member class, 1276193326Sed /// retrieves the member class from which it was instantiated. 1277193326Sed /// 1278263508Sdim /// This routine will return non-null for (non-templated) member 1279193326Sed /// classes of class templates. For example, given: 1280193326Sed /// 1281263508Sdim /// \code 1282193326Sed /// template<typename T> 1283193326Sed /// struct X { 1284193326Sed /// struct A { }; 1285193326Sed /// }; 1286263508Sdim /// \endcode 1287193326Sed /// 1288193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 1289193326Sed /// whose parent is the class template specialization X<int>. For 1290193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 1291193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 1292193326Sed /// X<int>::A is required, it will be instantiated from the 1293193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 1294198092Srdivacky CXXRecordDecl *getInstantiatedFromMemberClass() const; 1295234353Sdim 1296198092Srdivacky /// \brief If this class is an instantiation of a member class of a 1297198092Srdivacky /// class template specialization, retrieves the member specialization 1298198092Srdivacky /// information. 1299249423Sdim MemberSpecializationInfo *getMemberSpecializationInfo() const { 1300249423Sdim return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); 1301249423Sdim } 1302234353Sdim 1303193326Sed /// \brief Specify that this record is an instantiation of the 1304263508Sdim /// member class \p RD. 1305198092Srdivacky void setInstantiationOfMemberClass(CXXRecordDecl *RD, 1306198092Srdivacky TemplateSpecializationKind TSK); 1307193326Sed 1308193326Sed /// \brief Retrieves the class template that is described by this 1309193326Sed /// class declaration. 1310193326Sed /// 1311193326Sed /// Every class template is represented as a ClassTemplateDecl and a 1312193326Sed /// CXXRecordDecl. The former contains template properties (such as 1313193326Sed /// the template parameter lists) while the latter contains the 1314193326Sed /// actual description of the template's 1315193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 1316193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 1317193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 1318193326Sed /// a CXXRecordDecl. 1319193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 1320193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 1321193326Sed } 1322193326Sed 1323193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 1324193326Sed TemplateOrInstantiation = Template; 1325193326Sed } 1326193326Sed 1327198092Srdivacky /// \brief Determine whether this particular class is a specialization or 1328198092Srdivacky /// instantiation of a class template or member class of a class template, 1329198092Srdivacky /// and how it was instantiated or specialized. 1330200583Srdivacky TemplateSpecializationKind getTemplateSpecializationKind() const; 1331234353Sdim 1332198092Srdivacky /// \brief Set the kind of specialization or template instantiation this is. 1333198092Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 1334198092Srdivacky 1335263508Sdim /// \brief Returns the destructor decl for this class. 1336210299Sed CXXDestructorDecl *getDestructor() const; 1337198092Srdivacky 1338263508Sdim /// \brief If the class is a local class [class.local], returns 1339195099Sed /// the enclosing function declaration. 1340195099Sed const FunctionDecl *isLocalClass() const { 1341195099Sed if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 1342195099Sed return RD->isLocalClass(); 1343198092Srdivacky 1344195099Sed return dyn_cast<FunctionDecl>(getDeclContext()); 1345195099Sed } 1346198092Srdivacky 1347263508Sdim FunctionDecl *isLocalClass() { 1348263508Sdim return const_cast<FunctionDecl*>( 1349263508Sdim const_cast<const CXXRecordDecl*>(this)->isLocalClass()); 1350263508Sdim } 1351263508Sdim 1352249423Sdim /// \brief Determine whether this dependent class is a current instantiation, 1353249423Sdim /// when viewed from within the given context. 1354249423Sdim bool isCurrentInstantiation(const DeclContext *CurContext) const; 1355249423Sdim 1356198092Srdivacky /// \brief Determine whether this class is derived from the class \p Base. 1357198092Srdivacky /// 1358198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 1359198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 1360198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1361198092Srdivacky /// base class subobjects. 1362198092Srdivacky /// 1363198092Srdivacky /// \param Base the base class we are searching for. 1364198092Srdivacky /// 1365198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 1366218893Sdim bool isDerivedFrom(const CXXRecordDecl *Base) const; 1367234353Sdim 1368198092Srdivacky /// \brief Determine whether this class is derived from the type \p Base. 1369198092Srdivacky /// 1370198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 1371198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 1372198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1373198092Srdivacky /// base class subobjects. 1374198092Srdivacky /// 1375198092Srdivacky /// \param Base the base class we are searching for. 1376198092Srdivacky /// 1377198092Srdivacky /// \param Paths will contain the paths taken from the current class to the 1378198092Srdivacky /// given \p Base class. 1379198092Srdivacky /// 1380263508Sdim /// \returns true if this class is derived from \p Base, false otherwise. 1381198092Srdivacky /// 1382234353Sdim /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 1383234353Sdim /// tangling input and output in \p Paths 1384218893Sdim bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; 1385200583Srdivacky 1386204643Srdivacky /// \brief Determine whether this class is virtually derived from 1387204643Srdivacky /// the class \p Base. 1388204643Srdivacky /// 1389204643Srdivacky /// This routine only determines whether this class is virtually 1390204643Srdivacky /// derived from \p Base, but does not account for factors that may 1391204643Srdivacky /// make a Derived -> Base class ill-formed, such as 1392204643Srdivacky /// private/protected inheritance or multiple, ambiguous base class 1393204643Srdivacky /// subobjects. 1394204643Srdivacky /// 1395204643Srdivacky /// \param Base the base class we are searching for. 1396204643Srdivacky /// 1397204643Srdivacky /// \returns true if this class is virtually derived from Base, 1398204643Srdivacky /// false otherwise. 1399239462Sdim bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; 1400204643Srdivacky 1401200583Srdivacky /// \brief Determine whether this class is provably not derived from 1402200583Srdivacky /// the type \p Base. 1403200583Srdivacky bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 1404200583Srdivacky 1405200583Srdivacky /// \brief Function type used by forallBases() as a callback. 1406200583Srdivacky /// 1407243830Sdim /// \param BaseDefinition the definition of the base class 1408200583Srdivacky /// 1409200583Srdivacky /// \returns true if this base matched the search criteria 1410200583Srdivacky typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 1411200583Srdivacky void *UserData); 1412200583Srdivacky 1413200583Srdivacky /// \brief Determines if the given callback holds for all the direct 1414200583Srdivacky /// or indirect base classes of this type. 1415200583Srdivacky /// 1416200583Srdivacky /// The class itself does not count as a base class. This routine 1417200583Srdivacky /// returns false if the class has non-computable base classes. 1418234353Sdim /// 1419263508Sdim /// \param BaseMatches Callback invoked for each (direct or indirect) base 1420263508Sdim /// class of this type, or if \p AllowShortCircuit is true then until a call 1421263508Sdim /// returns false. 1422263508Sdim /// 1423263508Sdim /// \param UserData Passed as the second argument of every call to 1424263508Sdim /// \p BaseMatches. 1425263508Sdim /// 1426200583Srdivacky /// \param AllowShortCircuit if false, forces the callback to be called 1427200583Srdivacky /// for every base class, even if a dependent or non-matching base was 1428200583Srdivacky /// found. 1429200583Srdivacky bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 1430200583Srdivacky bool AllowShortCircuit = true) const; 1431234353Sdim 1432234353Sdim /// \brief Function type used by lookupInBases() to determine whether a 1433198092Srdivacky /// specific base class subobject matches the lookup criteria. 1434198092Srdivacky /// 1435234353Sdim /// \param Specifier the base-class specifier that describes the inheritance 1436198092Srdivacky /// from the base class we are trying to match. 1437198092Srdivacky /// 1438234353Sdim /// \param Path the current path, from the most-derived class down to the 1439198092Srdivacky /// base named by the \p Specifier. 1440198092Srdivacky /// 1441198092Srdivacky /// \param UserData a single pointer to user-specified data, provided to 1442198092Srdivacky /// lookupInBases(). 1443198092Srdivacky /// 1444198092Srdivacky /// \returns true if this base matched the search criteria, false otherwise. 1445199482Srdivacky typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 1446198092Srdivacky CXXBasePath &Path, 1447198092Srdivacky void *UserData); 1448234353Sdim 1449198092Srdivacky /// \brief Look for entities within the base classes of this C++ class, 1450198092Srdivacky /// transitively searching all base class subobjects. 1451198092Srdivacky /// 1452234353Sdim /// This routine uses the callback function \p BaseMatches to find base 1453198092Srdivacky /// classes meeting some search criteria, walking all base class subobjects 1454234353Sdim /// and populating the given \p Paths structure with the paths through the 1455198092Srdivacky /// inheritance hierarchy that resulted in a match. On a successful search, 1456198092Srdivacky /// the \p Paths structure can be queried to retrieve the matching paths and 1457198092Srdivacky /// to determine if there were any ambiguities. 1458198092Srdivacky /// 1459198092Srdivacky /// \param BaseMatches callback function used to determine whether a given 1460198092Srdivacky /// base matches the user-defined search criteria. 1461198092Srdivacky /// 1462198092Srdivacky /// \param UserData user data pointer that will be provided to \p BaseMatches. 1463198092Srdivacky /// 1464198092Srdivacky /// \param Paths used to record the paths from this class to its base class 1465198092Srdivacky /// subobjects that match the search criteria. 1466198092Srdivacky /// 1467198092Srdivacky /// \returns true if there exists any path from this class to a base class 1468198092Srdivacky /// subobject that matches the search criteria. 1469198092Srdivacky bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 1470199482Srdivacky CXXBasePaths &Paths) const; 1471234353Sdim 1472198092Srdivacky /// \brief Base-class lookup callback that determines whether the given 1473198092Srdivacky /// base class specifier refers to a specific class declaration. 1474198092Srdivacky /// 1475198092Srdivacky /// This callback can be used with \c lookupInBases() to determine whether 1476198092Srdivacky /// a given derived class has is a base class subobject of a particular type. 1477198092Srdivacky /// The user data pointer should refer to the canonical CXXRecordDecl of the 1478198092Srdivacky /// base class that we are searching for. 1479199482Srdivacky static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 1480199482Srdivacky CXXBasePath &Path, void *BaseRecord); 1481204643Srdivacky 1482204643Srdivacky /// \brief Base-class lookup callback that determines whether the 1483204643Srdivacky /// given base class specifier refers to a specific class 1484204643Srdivacky /// declaration and describes virtual derivation. 1485204643Srdivacky /// 1486204643Srdivacky /// This callback can be used with \c lookupInBases() to determine 1487204643Srdivacky /// whether a given derived class has is a virtual base class 1488204643Srdivacky /// subobject of a particular type. The user data pointer should 1489204643Srdivacky /// refer to the canonical CXXRecordDecl of the base class that we 1490204643Srdivacky /// are searching for. 1491204643Srdivacky static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 1492204643Srdivacky CXXBasePath &Path, void *BaseRecord); 1493234353Sdim 1494198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 1495198092Srdivacky /// a tag with the given name. 1496198092Srdivacky /// 1497198092Srdivacky /// This callback can be used with \c lookupInBases() to find tag members 1498198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 1499198092Srdivacky /// is an opaque \c DeclarationName pointer. 1500199482Srdivacky static bool FindTagMember(const CXXBaseSpecifier *Specifier, 1501199482Srdivacky CXXBasePath &Path, void *Name); 1502198092Srdivacky 1503198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 1504198092Srdivacky /// a member with the given name. 1505198092Srdivacky /// 1506198092Srdivacky /// This callback can be used with \c lookupInBases() to find members 1507198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 1508198092Srdivacky /// is an opaque \c DeclarationName pointer. 1509199482Srdivacky static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 1510199482Srdivacky CXXBasePath &Path, void *Name); 1511234353Sdim 1512198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 1513198092Srdivacky /// a member with the given name that can be used in a nested-name-specifier. 1514198092Srdivacky /// 1515198092Srdivacky /// This callback can be used with \c lookupInBases() to find membes of 1516198092Srdivacky /// the given name within a C++ class hierarchy that can occur within 1517198092Srdivacky /// nested-name-specifiers. 1518199482Srdivacky static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 1519198092Srdivacky CXXBasePath &Path, 1520198092Srdivacky void *UserData); 1521206084Srdivacky 1522206084Srdivacky /// \brief Retrieve the final overriders for each virtual member 1523206084Srdivacky /// function in the class hierarchy where this class is the 1524206084Srdivacky /// most-derived class in the class hierarchy. 1525206084Srdivacky void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 1526206084Srdivacky 1527218893Sdim /// \brief Get the indirect primary bases for this class. 1528218893Sdim void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; 1529218893Sdim 1530263508Sdim /// Renders and displays an inheritance diagram 1531193326Sed /// for this C++ class and all of its base classes (transitively) using 1532193326Sed /// GraphViz. 1533193326Sed void viewInheritance(ASTContext& Context) const; 1534193326Sed 1535263508Sdim /// \brief Calculates the access of a decl that is reached 1536202879Srdivacky /// along a path. 1537202879Srdivacky static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 1538202879Srdivacky AccessSpecifier DeclAccess) { 1539202879Srdivacky assert(DeclAccess != AS_none); 1540202879Srdivacky if (DeclAccess == AS_private) return AS_none; 1541202879Srdivacky return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 1542202879Srdivacky } 1543202879Srdivacky 1544249423Sdim /// \brief Indicates that the declaration of a defaulted or deleted special 1545249423Sdim /// member function is now complete. 1546249423Sdim void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); 1547249423Sdim 1548218893Sdim /// \brief Indicates that the definition of this class is now complete. 1549218893Sdim virtual void completeDefinition(); 1550218893Sdim 1551234353Sdim /// \brief Indicates that the definition of this class is now complete, 1552218893Sdim /// and provides a final overrider map to help determine 1553234353Sdim /// 1554218893Sdim /// \param FinalOverriders The final overrider map for this class, which can 1555218893Sdim /// be provided as an optimization for abstract-class checking. If NULL, 1556218893Sdim /// final overriders will be computed if they are needed to complete the 1557218893Sdim /// definition. 1558218893Sdim void completeDefinition(CXXFinalOverriderMap *FinalOverriders); 1559234353Sdim 1560218893Sdim /// \brief Determine whether this class may end up being abstract, even though 1561218893Sdim /// it is not yet known to be abstract. 1562218893Sdim /// 1563218893Sdim /// \returns true if this class is not known to be abstract but has any 1564218893Sdim /// base classes that are abstract. In this case, \c completeDefinition() 1565218893Sdim /// will need to compute final overriders to determine whether the class is 1566218893Sdim /// actually abstract. 1567218893Sdim bool mayBeAbstract() const; 1568234353Sdim 1569234353Sdim /// \brief If this is the closure type of a lambda expression, retrieve the 1570234353Sdim /// number to be used for name mangling in the Itanium C++ ABI. 1571234353Sdim /// 1572234353Sdim /// Zero indicates that this closure type has internal linkage, so the 1573234353Sdim /// mangling number does not matter, while a non-zero value indicates which 1574234353Sdim /// lambda expression this is in this particular context. 1575234353Sdim unsigned getLambdaManglingNumber() const { 1576234353Sdim assert(isLambda() && "Not a lambda closure type!"); 1577234353Sdim return getLambdaData().ManglingNumber; 1578234353Sdim } 1579218893Sdim 1580234353Sdim /// \brief Retrieve the declaration that provides additional context for a 1581234353Sdim /// lambda, when the normal declaration context is not specific enough. 1582234353Sdim /// 1583234353Sdim /// Certain contexts (default arguments of in-class function parameters and 1584234353Sdim /// the initializers of data members) have separate name mangling rules for 1585234353Sdim /// lambdas within the Itanium C++ ABI. For these cases, this routine provides 1586234353Sdim /// the declaration in which the lambda occurs, e.g., the function parameter 1587234353Sdim /// or the non-static data member. Otherwise, it returns NULL to imply that 1588234353Sdim /// the declaration context suffices. 1589234353Sdim Decl *getLambdaContextDecl() const { 1590234353Sdim assert(isLambda() && "Not a lambda closure type!"); 1591234353Sdim return getLambdaData().ContextDecl; 1592234353Sdim } 1593234353Sdim 1594234353Sdim /// \brief Set the mangling number and context declaration for a lambda 1595234353Sdim /// class. 1596234353Sdim void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) { 1597234353Sdim getLambdaData().ManglingNumber = ManglingNumber; 1598234353Sdim getLambdaData().ContextDecl = ContextDecl; 1599234353Sdim } 1600234353Sdim 1601249423Sdim /// \brief Returns the inheritance model used for this record. 1602249423Sdim MSInheritanceModel getMSInheritanceModel() const; 1603249423Sdim 1604234353Sdim /// \brief Determine whether this lambda expression was known to be dependent 1605234353Sdim /// at the time it was created, even if its context does not appear to be 1606234353Sdim /// dependent. 1607234353Sdim /// 1608234353Sdim /// This flag is a workaround for an issue with parsing, where default 1609234353Sdim /// arguments are parsed before their enclosing function declarations have 1610234353Sdim /// been created. This means that any lambda expressions within those 1611234353Sdim /// default arguments will have as their DeclContext the context enclosing 1612234353Sdim /// the function declaration, which may be non-dependent even when the 1613234353Sdim /// function declaration itself is dependent. This flag indicates when we 1614234353Sdim /// know that the lambda is dependent despite that. 1615234353Sdim bool isDependentLambda() const { 1616234353Sdim return isLambda() && getLambdaData().Dependent; 1617234353Sdim } 1618243830Sdim 1619243830Sdim TypeSourceInfo *getLambdaTypeInfo() const { 1620243830Sdim return getLambdaData().MethodTyInfo; 1621243830Sdim } 1622243830Sdim 1623203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1624203955Srdivacky static bool classofKind(Kind K) { 1625210299Sed return K >= firstCXXRecord && K <= lastCXXRecord; 1626193326Sed } 1627210299Sed 1628212904Sdim friend class ASTDeclReader; 1629212904Sdim friend class ASTDeclWriter; 1630218893Sdim friend class ASTReader; 1631218893Sdim friend class ASTWriter; 1632193326Sed}; 1633193326Sed 1634263508Sdim/// \brief Represents a static or instance method of a struct/union/class. 1635263508Sdim/// 1636263508Sdim/// In the terminology of the C++ Standard, these are the (static and 1637263508Sdim/// non-static) member functions, whether virtual or not. 1638193326Sedclass CXXMethodDecl : public FunctionDecl { 1639234353Sdim virtual void anchor(); 1640193326Sedprotected: 1641221345Sdim CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc, 1642212904Sdim const DeclarationNameInfo &NameInfo, 1643212904Sdim QualType T, TypeSourceInfo *TInfo, 1644249423Sdim StorageClass SC, bool isInline, 1645226633Sdim bool isConstexpr, SourceLocation EndLocation) 1646221345Sdim : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo, 1647249423Sdim SC, isInline, isConstexpr) { 1648234353Sdim if (EndLocation.isValid()) 1649234353Sdim setRangeEnd(EndLocation); 1650234353Sdim } 1651193326Sed 1652193326Sedpublic: 1653193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1654221345Sdim SourceLocation StartLoc, 1655212904Sdim const DeclarationNameInfo &NameInfo, 1656212904Sdim QualType T, TypeSourceInfo *TInfo, 1657249423Sdim StorageClass SC, 1658221345Sdim bool isInline, 1659226633Sdim bool isConstexpr, 1660221345Sdim SourceLocation EndLocation); 1661198092Srdivacky 1662234353Sdim static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1663249423Sdim 1664249423Sdim bool isStatic() const; 1665193326Sed bool isInstance() const { return !isStatic(); } 1666193326Sed 1667263508Sdim /// Returns true if the given operator is implicitly static in a record 1668263508Sdim /// context. 1669263508Sdim static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { 1670263508Sdim // [class.free]p1: 1671263508Sdim // Any allocation function for a class T is a static member 1672263508Sdim // (even if not explicitly declared static). 1673263508Sdim // [class.free]p6 Any deallocation function for a class X is a static member 1674263508Sdim // (even if not explicitly declared static). 1675263508Sdim return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || 1676263508Sdim OOK == OO_Array_Delete; 1677263508Sdim } 1678263508Sdim 1679243830Sdim bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } 1680243830Sdim bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } 1681239462Sdim 1682198092Srdivacky bool isVirtual() const { 1683234353Sdim CXXMethodDecl *CD = 1684198092Srdivacky cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 1685198092Srdivacky 1686243830Sdim // Methods declared in interfaces are automatically (pure) virtual. 1687243830Sdim if (CD->isVirtualAsWritten() || 1688243830Sdim (CD->getParent()->isInterface() && CD->isUserProvided())) 1689198092Srdivacky return true; 1690234353Sdim 1691198092Srdivacky return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 1692193326Sed } 1693206084Srdivacky 1694198092Srdivacky /// \brief Determine whether this is a usual deallocation function 1695198092Srdivacky /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 1696198092Srdivacky /// delete or delete[] operator with a particular signature. 1697198092Srdivacky bool isUsualDeallocationFunction() const; 1698234353Sdim 1699207619Srdivacky /// \brief Determine whether this is a copy-assignment operator, regardless 1700207619Srdivacky /// of whether it was declared implicitly or explicitly. 1701207619Srdivacky bool isCopyAssignmentOperator() const; 1702223017Sdim 1703223017Sdim /// \brief Determine whether this is a move assignment operator. 1704223017Sdim bool isMoveAssignmentOperator() const; 1705234353Sdim 1706198092Srdivacky CXXMethodDecl *getCanonicalDecl() { 1707198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1708198092Srdivacky } 1709263508Sdim const CXXMethodDecl *getCanonicalDecl() const { 1710263508Sdim return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); 1711263508Sdim } 1712223017Sdim 1713263508Sdim CXXMethodDecl *getMostRecentDecl() { 1714263508Sdim return cast<CXXMethodDecl>( 1715263508Sdim static_cast<FunctionDecl *>(this)->getMostRecentDecl()); 1716263508Sdim } 1717263508Sdim const CXXMethodDecl *getMostRecentDecl() const { 1718263508Sdim return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); 1719263508Sdim } 1720263508Sdim 1721263508Sdim /// True if this method is user-declared and was not 1722239462Sdim /// deleted or defaulted on its first declaration. 1723223017Sdim bool isUserProvided() const { 1724223017Sdim return !(isDeleted() || getCanonicalDecl()->isDefaulted()); 1725223017Sdim } 1726234353Sdim 1727198092Srdivacky /// 1728198092Srdivacky void addOverriddenMethod(const CXXMethodDecl *MD); 1729193326Sed 1730234353Sdim typedef const CXXMethodDecl *const* method_iterator; 1731198092Srdivacky 1732193326Sed method_iterator begin_overridden_methods() const; 1733193326Sed method_iterator end_overridden_methods() const; 1734210299Sed unsigned size_overridden_methods() const; 1735198092Srdivacky 1736263508Sdim /// Returns the parent of this method declaration, which 1737193326Sed /// is the class in which this method is defined. 1738198092Srdivacky const CXXRecordDecl *getParent() const { 1739198092Srdivacky return cast<CXXRecordDecl>(FunctionDecl::getParent()); 1740193326Sed } 1741198092Srdivacky 1742263508Sdim /// Returns the parent of this method declaration, which 1743193326Sed /// is the class in which this method is defined. 1744198092Srdivacky CXXRecordDecl *getParent() { 1745193326Sed return const_cast<CXXRecordDecl *>( 1746193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 1747193326Sed } 1748193326Sed 1749263508Sdim /// \brief Returns the type of the \c this pointer. 1750263508Sdim /// 1751263508Sdim /// Should only be called for instance (i.e., non-static) methods. 1752193326Sed QualType getThisType(ASTContext &C) const; 1753193326Sed 1754193326Sed unsigned getTypeQualifiers() const { 1755198092Srdivacky return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 1756193326Sed } 1757193326Sed 1758218893Sdim /// \brief Retrieve the ref-qualifier associated with this method. 1759218893Sdim /// 1760218893Sdim /// In the following example, \c f() has an lvalue ref-qualifier, \c g() 1761218893Sdim /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. 1762239462Sdim /// @code 1763218893Sdim /// struct X { 1764218893Sdim /// void f() &; 1765218893Sdim /// void g() &&; 1766218893Sdim /// void h(); 1767218893Sdim /// }; 1768239462Sdim /// @endcode 1769218893Sdim RefQualifierKind getRefQualifier() const { 1770218893Sdim return getType()->getAs<FunctionProtoType>()->getRefQualifier(); 1771218893Sdim } 1772234353Sdim 1773200583Srdivacky bool hasInlineBody() const; 1774200583Srdivacky 1775234353Sdim /// \brief Determine whether this is a lambda closure type's static member 1776234353Sdim /// function that is used for the result of the lambda's conversion to 1777234353Sdim /// function pointer (for a lambda with no captures). 1778234353Sdim /// 1779234353Sdim /// The function itself, if used, will have a placeholder body that will be 1780234353Sdim /// supplied by IR generation to either forward to the function call operator 1781234353Sdim /// or clone the function call operator. 1782234353Sdim bool isLambdaStaticInvoker() const; 1783239462Sdim 1784263508Sdim /// \brief Find the method in \p RD that corresponds to this one. 1785239462Sdim /// 1786263508Sdim /// Find if \p RD or one of the classes it inherits from override this method. 1787263508Sdim /// If so, return it. \p RD is assumed to be a subclass of the class defining 1788263508Sdim /// this method (or be the class itself), unless \p MayBeBase is set to true. 1789239462Sdim CXXMethodDecl * 1790239462Sdim getCorrespondingMethodInClass(const CXXRecordDecl *RD, 1791239462Sdim bool MayBeBase = false); 1792239462Sdim 1793239462Sdim const CXXMethodDecl * 1794239462Sdim getCorrespondingMethodInClass(const CXXRecordDecl *RD, 1795239462Sdim bool MayBeBase = false) const { 1796239462Sdim return const_cast<CXXMethodDecl *>(this) 1797239462Sdim ->getCorrespondingMethodInClass(RD, MayBeBase); 1798239462Sdim } 1799239462Sdim 1800193326Sed // Implement isa/cast/dyncast/etc. 1801203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1802203955Srdivacky static bool classofKind(Kind K) { 1803210299Sed return K >= firstCXXMethod && K <= lastCXXMethod; 1804193326Sed } 1805193326Sed}; 1806193326Sed 1807263508Sdim/// \brief Represents a C++ base or member initializer. 1808263508Sdim/// 1809263508Sdim/// This is part of a constructor initializer that 1810193326Sed/// initializes one non-static member variable or one base class. For 1811193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 1812193326Sed/// initializers: 1813193326Sed/// 1814263508Sdim/// \code 1815193326Sed/// class A { }; 1816193326Sed/// class B : public A { 1817193326Sed/// float f; 1818193326Sed/// public: 1819193326Sed/// B(A& a) : A(a), f(3.14159) { } 1820193326Sed/// }; 1821263508Sdim/// \endcode 1822218893Sdimclass CXXCtorInitializer { 1823234353Sdim /// \brief Either the base class name/delegating constructor type (stored as 1824234353Sdim /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field 1825234353Sdim /// (IndirectFieldDecl*) being initialized. 1826234353Sdim llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> 1827218893Sdim Initializee; 1828234353Sdim 1829218893Sdim /// \brief The source location for the field name or, for a base initializer 1830263508Sdim /// pack expansion, the location of the ellipsis. 1831263508Sdim /// 1832263508Sdim /// In the case of a delegating 1833221345Sdim /// constructor, it will still include the type's source location as the 1834221345Sdim /// Initializee points to the CXXConstructorDecl (to allow loop detection). 1835218893Sdim SourceLocation MemberOrEllipsisLocation; 1836234353Sdim 1837203955Srdivacky /// \brief The argument used to initialize the base or member, which may 1838203955Srdivacky /// end up constructing an object (when multiple arguments are involved). 1839203955Srdivacky Stmt *Init; 1840234353Sdim 1841263508Sdim /// \brief Location of the left paren of the ctor-initializer. 1842200583Srdivacky SourceLocation LParenLoc; 1843193326Sed 1844263508Sdim /// \brief Location of the right paren of the ctor-initializer. 1845198092Srdivacky SourceLocation RParenLoc; 1846198092Srdivacky 1847234353Sdim /// \brief If the initializee is a type, whether that type makes this 1848234353Sdim /// a delegating initialization. 1849234353Sdim bool IsDelegating : 1; 1850234353Sdim 1851263508Sdim /// \brief If the initializer is a base initializer, this keeps track 1852208600Srdivacky /// of whether the base is virtual or not. 1853208600Srdivacky bool IsVirtual : 1; 1854208600Srdivacky 1855263508Sdim /// \brief Whether or not the initializer is explicitly written 1856208600Srdivacky /// in the sources. 1857208600Srdivacky bool IsWritten : 1; 1858218893Sdim 1859263508Sdim /// If IsWritten is true, then this number keeps track of the textual order 1860263508Sdim /// of this initializer in the original sources, counting from 0; otherwise, 1861263508Sdim /// it stores the number of array index variables stored after this object 1862263508Sdim /// in memory. 1863234353Sdim unsigned SourceOrderOrNumArrayIndices : 13; 1864208600Srdivacky 1865218893Sdim CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1866218893Sdim SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1867218893Sdim SourceLocation R, VarDecl **Indices, unsigned NumIndices); 1868234353Sdim 1869193326Sedpublic: 1870263508Sdim /// \brief Creates a new base-class initializer. 1871198092Srdivacky explicit 1872218893Sdim CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, 1873218893Sdim SourceLocation L, Expr *Init, SourceLocation R, 1874218893Sdim SourceLocation EllipsisLoc); 1875193326Sed 1876263508Sdim /// \brief Creates a new member initializer. 1877198092Srdivacky explicit 1878218893Sdim CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1879218893Sdim SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1880218893Sdim SourceLocation R); 1881193326Sed 1882263508Sdim /// \brief Creates a new anonymous field initializer. 1883218893Sdim explicit 1884218893Sdim CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, 1885218893Sdim SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1886218893Sdim SourceLocation R); 1887218893Sdim 1888263508Sdim /// \brief Creates a new delegating initializer. 1889221345Sdim explicit 1890234353Sdim CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, 1891234353Sdim SourceLocation L, Expr *Init, SourceLocation R); 1892221345Sdim 1893234353Sdim /// \brief Creates a new member initializer that optionally contains 1894208600Srdivacky /// array indices used to describe an elementwise initialization. 1895218893Sdim static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member, 1896218893Sdim SourceLocation MemberLoc, SourceLocation L, 1897218893Sdim Expr *Init, SourceLocation R, 1898218893Sdim VarDecl **Indices, unsigned NumIndices); 1899234353Sdim 1900263508Sdim /// \brief Determine whether this initializer is initializing a base class. 1901234353Sdim bool isBaseInitializer() const { 1902234353Sdim return Initializee.is<TypeSourceInfo*>() && !IsDelegating; 1903234353Sdim } 1904193326Sed 1905263508Sdim /// \brief Determine whether this initializer is initializing a non-static 1906263508Sdim /// data member. 1907218893Sdim bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } 1908193326Sed 1909234353Sdim bool isAnyMemberInitializer() const { 1910218893Sdim return isMemberInitializer() || isIndirectMemberInitializer(); 1911218893Sdim } 1912218893Sdim 1913218893Sdim bool isIndirectMemberInitializer() const { 1914218893Sdim return Initializee.is<IndirectFieldDecl*>(); 1915218893Sdim } 1916218893Sdim 1917263508Sdim /// \brief Determine whether this initializer is an implicit initializer 1918263508Sdim /// generated for a field with an initializer defined on the member 1919263508Sdim /// declaration. 1920263508Sdim /// 1921263508Sdim /// In-class member initializers (also known as "non-static data member 1922263508Sdim /// initializations", NSDMIs) were introduced in C++11. 1923223017Sdim bool isInClassMemberInitializer() const { 1924251662Sdim return isa<CXXDefaultInitExpr>(Init); 1925223017Sdim } 1926223017Sdim 1927263508Sdim /// \brief Determine whether this initializer is creating a delegating 1928263508Sdim /// constructor. 1929221345Sdim bool isDelegatingInitializer() const { 1930234353Sdim return Initializee.is<TypeSourceInfo*>() && IsDelegating; 1931221345Sdim } 1932221345Sdim 1933218893Sdim /// \brief Determine whether this initializer is a pack expansion. 1934234353Sdim bool isPackExpansion() const { 1935234353Sdim return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); 1936218893Sdim } 1937234353Sdim 1938218893Sdim // \brief For a pack expansion, returns the location of the ellipsis. 1939218893Sdim SourceLocation getEllipsisLoc() const { 1940218893Sdim assert(isPackExpansion() && "Initializer is not a pack expansion"); 1941218893Sdim return MemberOrEllipsisLocation; 1942218893Sdim } 1943234353Sdim 1944234353Sdim /// If this is a base class initializer, returns the type of the 1945200583Srdivacky /// base class with location information. Otherwise, returns an NULL 1946200583Srdivacky /// type location. 1947200583Srdivacky TypeLoc getBaseClassLoc() const; 1948193326Sed 1949200583Srdivacky /// If this is a base class initializer, returns the type of the base class. 1950263508Sdim /// Otherwise, returns null. 1951200583Srdivacky const Type *getBaseClass() const; 1952207619Srdivacky 1953207619Srdivacky /// Returns whether the base is virtual or not. 1954207619Srdivacky bool isBaseVirtual() const { 1955207619Srdivacky assert(isBaseInitializer() && "Must call this on base initializer!"); 1956234353Sdim 1957207619Srdivacky return IsVirtual; 1958207619Srdivacky } 1959207619Srdivacky 1960234353Sdim /// \brief Returns the declarator information for a base class or delegating 1961234353Sdim /// initializer. 1962234353Sdim TypeSourceInfo *getTypeSourceInfo() const { 1963218893Sdim return Initializee.dyn_cast<TypeSourceInfo *>(); 1964193326Sed } 1965234353Sdim 1966263508Sdim /// \brief If this is a member initializer, returns the declaration of the 1967263508Sdim /// non-static data member being initialized. Otherwise, returns null. 1968212904Sdim FieldDecl *getMember() const { 1969193326Sed if (isMemberInitializer()) 1970218893Sdim return Initializee.get<FieldDecl*>(); 1971234353Sdim return 0; 1972193326Sed } 1973218893Sdim FieldDecl *getAnyMember() const { 1974218893Sdim if (isMemberInitializer()) 1975218893Sdim return Initializee.get<FieldDecl*>(); 1976234353Sdim if (isIndirectMemberInitializer()) 1977218893Sdim return Initializee.get<IndirectFieldDecl*>()->getAnonField(); 1978234353Sdim return 0; 1979218893Sdim } 1980193326Sed 1981218893Sdim IndirectFieldDecl *getIndirectMember() const { 1982218893Sdim if (isIndirectMemberInitializer()) 1983218893Sdim return Initializee.get<IndirectFieldDecl*>(); 1984234353Sdim return 0; 1985198092Srdivacky } 1986198092Srdivacky 1987234353Sdim SourceLocation getMemberLocation() const { 1988234353Sdim return MemberOrEllipsisLocation; 1989221345Sdim } 1990221345Sdim 1991200583Srdivacky /// \brief Determine the source location of the initializer. 1992200583Srdivacky SourceLocation getSourceLocation() const; 1993234353Sdim 1994200583Srdivacky /// \brief Determine the source range covering the entire initializer. 1995234353Sdim SourceRange getSourceRange() const LLVM_READONLY; 1996208600Srdivacky 1997263508Sdim /// \brief Determine whether this initializer is explicitly written 1998208600Srdivacky /// in the source code. 1999208600Srdivacky bool isWritten() const { return IsWritten; } 2000208600Srdivacky 2001208600Srdivacky /// \brief Return the source position of the initializer, counting from 0. 2002208600Srdivacky /// If the initializer was implicit, -1 is returned. 2003208600Srdivacky int getSourceOrder() const { 2004208600Srdivacky return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1; 2005208600Srdivacky } 2006208600Srdivacky 2007263508Sdim /// \brief Set the source order of this initializer. 2008263508Sdim /// 2009263508Sdim /// This can only be called once for each initializer; it cannot be called 2010263508Sdim /// on an initializer having a positive number of (implicit) array indices. 2011263508Sdim /// 2012263508Sdim /// This assumes that the initialzier was written in the source code, and 2013263508Sdim /// ensures that isWritten() returns true. 2014208600Srdivacky void setSourceOrder(int pos) { 2015208600Srdivacky assert(!IsWritten && 2016208600Srdivacky "calling twice setSourceOrder() on the same initializer"); 2017208600Srdivacky assert(SourceOrderOrNumArrayIndices == 0 && 2018208600Srdivacky "setSourceOrder() used when there are implicit array indices"); 2019208600Srdivacky assert(pos >= 0 && 2020208600Srdivacky "setSourceOrder() used to make an initializer implicit"); 2021208600Srdivacky IsWritten = true; 2022208600Srdivacky SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos); 2023208600Srdivacky } 2024198092Srdivacky 2025200583Srdivacky SourceLocation getLParenLoc() const { return LParenLoc; } 2026198092Srdivacky SourceLocation getRParenLoc() const { return RParenLoc; } 2027193326Sed 2028208600Srdivacky /// \brief Determine the number of implicit array indices used while 2029208600Srdivacky /// described an array member initialization. 2030208600Srdivacky unsigned getNumArrayIndices() const { 2031208600Srdivacky return IsWritten ? 0 : SourceOrderOrNumArrayIndices; 2032208600Srdivacky } 2033208600Srdivacky 2034234353Sdim /// \brief Retrieve a particular array index variable used to 2035208600Srdivacky /// describe an array member initialization. 2036208600Srdivacky VarDecl *getArrayIndex(unsigned I) { 2037208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 2038208600Srdivacky return reinterpret_cast<VarDecl **>(this + 1)[I]; 2039208600Srdivacky } 2040208600Srdivacky const VarDecl *getArrayIndex(unsigned I) const { 2041208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 2042208600Srdivacky return reinterpret_cast<const VarDecl * const *>(this + 1)[I]; 2043208600Srdivacky } 2044208600Srdivacky void setArrayIndex(unsigned I, VarDecl *Index) { 2045208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 2046208600Srdivacky reinterpret_cast<VarDecl **>(this + 1)[I] = Index; 2047208600Srdivacky } 2048234353Sdim ArrayRef<VarDecl *> getArrayIndexes() { 2049234353Sdim assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init"); 2050234353Sdim return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1), 2051234353Sdim getNumArrayIndices()); 2052234353Sdim } 2053234353Sdim 2054251662Sdim /// \brief Get the initializer. 2055251662Sdim Expr *getInit() const { return static_cast<Expr*>(Init); } 2056193326Sed}; 2057193326Sed 2058263508Sdim/// \brief Represents a C++ constructor within a class. 2059198092Srdivacky/// 2060263508Sdim/// For example: 2061263508Sdim/// 2062263508Sdim/// \code 2063193326Sed/// class X { 2064193326Sed/// public: 2065193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 2066193326Sed/// }; 2067263508Sdim/// \endcode 2068193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 2069234353Sdim virtual void anchor(); 2070263508Sdim /// \brief Whether this constructor declaration has the \c explicit keyword 2071263508Sdim /// specified. 2072203955Srdivacky bool IsExplicitSpecified : 1; 2073193326Sed 2074263508Sdim /// \name Support for base and member initializers. 2075263508Sdim /// \{ 2076263508Sdim /// \brief The arguments used to initialize the base or member. 2077218893Sdim CXXCtorInitializer **CtorInitializers; 2078218893Sdim unsigned NumCtorInitializers; 2079263508Sdim /// \} 2080198092Srdivacky 2081221345Sdim CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 2082221345Sdim const DeclarationNameInfo &NameInfo, 2083212904Sdim QualType T, TypeSourceInfo *TInfo, 2084234353Sdim bool isExplicitSpecified, bool isInline, 2085226633Sdim bool isImplicitlyDeclared, bool isConstexpr) 2086249423Sdim : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, 2087226633Sdim SC_None, isInline, isConstexpr, SourceLocation()), 2088263508Sdim IsExplicitSpecified(isExplicitSpecified), CtorInitializers(0), 2089263508Sdim NumCtorInitializers(0) { 2090193326Sed setImplicit(isImplicitlyDeclared); 2091193326Sed } 2092198092Srdivacky 2093193326Sedpublic: 2094234353Sdim static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2095193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 2096221345Sdim SourceLocation StartLoc, 2097212904Sdim const DeclarationNameInfo &NameInfo, 2098200583Srdivacky QualType T, TypeSourceInfo *TInfo, 2099198092Srdivacky bool isExplicit, 2100226633Sdim bool isInline, bool isImplicitlyDeclared, 2101226633Sdim bool isConstexpr); 2102193326Sed 2103263508Sdim /// \brief Determine whether this constructor declaration has the 2104263508Sdim /// \c explicit keyword specified. 2105203955Srdivacky bool isExplicitSpecified() const { return IsExplicitSpecified; } 2106234353Sdim 2107263508Sdim /// \brief Determine whether this constructor was marked "explicit" or not. 2108203955Srdivacky bool isExplicit() const { 2109263508Sdim return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified(); 2110203955Srdivacky } 2111193326Sed 2112263508Sdim /// \brief Iterates through the member/base initializer list. 2113218893Sdim typedef CXXCtorInitializer **init_iterator; 2114198092Srdivacky 2115263508Sdim /// \brief Iterates through the member/base initializer list. 2116218893Sdim typedef CXXCtorInitializer * const * init_const_iterator; 2117198092Srdivacky 2118263508Sdim /// \brief Retrieve an iterator to the first initializer. 2119218893Sdim init_iterator init_begin() { return CtorInitializers; } 2120263508Sdim /// \brief Retrieve an iterator to the first initializer. 2121218893Sdim init_const_iterator init_begin() const { return CtorInitializers; } 2122198092Srdivacky 2123263508Sdim /// \brief Retrieve an iterator past the last initializer. 2124198092Srdivacky init_iterator init_end() { 2125218893Sdim return CtorInitializers + NumCtorInitializers; 2126195341Sed } 2127263508Sdim /// \brief Retrieve an iterator past the last initializer. 2128198092Srdivacky init_const_iterator init_end() const { 2129218893Sdim return CtorInitializers + NumCtorInitializers; 2130195341Sed } 2131198092Srdivacky 2132218893Sdim typedef std::reverse_iterator<init_iterator> init_reverse_iterator; 2133234353Sdim typedef std::reverse_iterator<init_const_iterator> 2134234353Sdim init_const_reverse_iterator; 2135218893Sdim 2136218893Sdim init_reverse_iterator init_rbegin() { 2137218893Sdim return init_reverse_iterator(init_end()); 2138218893Sdim } 2139218893Sdim init_const_reverse_iterator init_rbegin() const { 2140218893Sdim return init_const_reverse_iterator(init_end()); 2141218893Sdim } 2142218893Sdim 2143218893Sdim init_reverse_iterator init_rend() { 2144218893Sdim return init_reverse_iterator(init_begin()); 2145218893Sdim } 2146218893Sdim init_const_reverse_iterator init_rend() const { 2147218893Sdim return init_const_reverse_iterator(init_begin()); 2148218893Sdim } 2149218893Sdim 2150263508Sdim /// \brief Determine the number of arguments used to initialize the member 2151263508Sdim /// or base. 2152218893Sdim unsigned getNumCtorInitializers() const { 2153218893Sdim return NumCtorInitializers; 2154195341Sed } 2155198092Srdivacky 2156218893Sdim void setNumCtorInitializers(unsigned numCtorInitializers) { 2157218893Sdim NumCtorInitializers = numCtorInitializers; 2158198092Srdivacky } 2159198092Srdivacky 2160218893Sdim void setCtorInitializers(CXXCtorInitializer ** initializers) { 2161218893Sdim CtorInitializers = initializers; 2162198092Srdivacky } 2163221345Sdim 2164263508Sdim /// \brief Determine whether this constructor is a delegating constructor. 2165221345Sdim bool isDelegatingConstructor() const { 2166221345Sdim return (getNumCtorInitializers() == 1) && 2167221345Sdim CtorInitializers[0]->isDelegatingInitializer(); 2168221345Sdim } 2169221345Sdim 2170263508Sdim /// \brief When this constructor delegates to another, retrieve the target. 2171234353Sdim CXXConstructorDecl *getTargetConstructor() const; 2172221345Sdim 2173263508Sdim /// Whether this constructor is a default 2174193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 2175193326Sed /// default-initialize a class of this type. 2176193326Sed bool isDefaultConstructor() const; 2177193326Sed 2178263508Sdim /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2, 2179263508Sdim /// which can be used to copy the class. 2180263508Sdim /// 2181263508Sdim /// \p TypeQuals will be set to the qualifiers on the 2182263508Sdim /// argument type. For example, \p TypeQuals would be set to \c 2183249423Sdim /// Qualifiers::Const for the following copy constructor: 2184193326Sed /// 2185263508Sdim /// \code 2186193326Sed /// class X { 2187193326Sed /// public: 2188193326Sed /// X(const X&); 2189193326Sed /// }; 2190263508Sdim /// \endcode 2191201361Srdivacky bool isCopyConstructor(unsigned &TypeQuals) const; 2192193326Sed 2193263508Sdim /// Whether this constructor is a copy 2194193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 2195193326Sed /// class. 2196201361Srdivacky bool isCopyConstructor() const { 2197193326Sed unsigned TypeQuals = 0; 2198201361Srdivacky return isCopyConstructor(TypeQuals); 2199193326Sed } 2200193326Sed 2201218893Sdim /// \brief Determine whether this constructor is a move constructor 2202218893Sdim /// (C++0x [class.copy]p3), which can be used to move values of the class. 2203218893Sdim /// 2204218893Sdim /// \param TypeQuals If this constructor is a move constructor, will be set 2205218893Sdim /// to the type qualifiers on the referent of the first parameter's type. 2206218893Sdim bool isMoveConstructor(unsigned &TypeQuals) const; 2207218893Sdim 2208218893Sdim /// \brief Determine whether this constructor is a move constructor 2209218893Sdim /// (C++0x [class.copy]p3), which can be used to move values of the class. 2210221345Sdim bool isMoveConstructor() const { 2211221345Sdim unsigned TypeQuals = 0; 2212221345Sdim return isMoveConstructor(TypeQuals); 2213221345Sdim } 2214221345Sdim 2215218893Sdim /// \brief Determine whether this is a copy or move constructor. 2216218893Sdim /// 2217218893Sdim /// \param TypeQuals Will be set to the type qualifiers on the reference 2218218893Sdim /// parameter, if in fact this is a copy or move constructor. 2219218893Sdim bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; 2220218893Sdim 2221218893Sdim /// \brief Determine whether this a copy or move constructor. 2222218893Sdim bool isCopyOrMoveConstructor() const { 2223218893Sdim unsigned Quals; 2224218893Sdim return isCopyOrMoveConstructor(Quals); 2225218893Sdim } 2226218893Sdim 2227263508Sdim /// Whether this constructor is a 2228193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 2229193326Sed /// used for user-defined conversions. 2230198092Srdivacky bool isConvertingConstructor(bool AllowExplicit) const; 2231193326Sed 2232199482Srdivacky /// \brief Determine whether this is a member template specialization that 2233218893Sdim /// would copy the object to itself. Such constructors are never used to copy 2234199482Srdivacky /// an object. 2235218893Sdim bool isSpecializationCopyingObject() const; 2236218893Sdim 2237218893Sdim /// \brief Get the constructor that this inheriting constructor is based on. 2238218893Sdim const CXXConstructorDecl *getInheritedConstructor() const; 2239218893Sdim 2240218893Sdim /// \brief Set the constructor that this inheriting constructor is based on. 2241218893Sdim void setInheritedConstructor(const CXXConstructorDecl *BaseCtor); 2242223017Sdim 2243223017Sdim const CXXConstructorDecl *getCanonicalDecl() const { 2244223017Sdim return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 2245223017Sdim } 2246223017Sdim CXXConstructorDecl *getCanonicalDecl() { 2247223017Sdim return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 2248223017Sdim } 2249234353Sdim 2250193326Sed // Implement isa/cast/dyncast/etc. 2251203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2252203955Srdivacky static bool classofKind(Kind K) { return K == CXXConstructor; } 2253234353Sdim 2254212904Sdim friend class ASTDeclReader; 2255212904Sdim friend class ASTDeclWriter; 2256193326Sed}; 2257193326Sed 2258263508Sdim/// \brief Represents a C++ destructor within a class. 2259198092Srdivacky/// 2260263508Sdim/// For example: 2261263508Sdim/// 2262263508Sdim/// \code 2263193326Sed/// class X { 2264193326Sed/// public: 2265193326Sed/// ~X(); // represented by a CXXDestructorDecl. 2266193326Sed/// }; 2267263508Sdim/// \endcode 2268193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 2269234353Sdim virtual void anchor(); 2270193326Sed 2271199482Srdivacky FunctionDecl *OperatorDelete; 2272234353Sdim 2273221345Sdim CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 2274221345Sdim const DeclarationNameInfo &NameInfo, 2275218893Sdim QualType T, TypeSourceInfo *TInfo, 2276218893Sdim bool isInline, bool isImplicitlyDeclared) 2277249423Sdim : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, 2278226633Sdim SC_None, isInline, /*isConstexpr=*/false, SourceLocation()), 2279263508Sdim OperatorDelete(0) { 2280193326Sed setImplicit(isImplicitlyDeclared); 2281193326Sed } 2282193326Sed 2283193326Sedpublic: 2284193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 2285221345Sdim SourceLocation StartLoc, 2286212904Sdim const DeclarationNameInfo &NameInfo, 2287218893Sdim QualType T, TypeSourceInfo* TInfo, 2288218893Sdim bool isInline, 2289193326Sed bool isImplicitlyDeclared); 2290234353Sdim static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); 2291193326Sed 2292199482Srdivacky void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 2293199482Srdivacky const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 2294198092Srdivacky 2295193326Sed // Implement isa/cast/dyncast/etc. 2296203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2297203955Srdivacky static bool classofKind(Kind K) { return K == CXXDestructor; } 2298234353Sdim 2299212904Sdim friend class ASTDeclReader; 2300212904Sdim friend class ASTDeclWriter; 2301193326Sed}; 2302193326Sed 2303263508Sdim/// \brief Represents a C++ conversion function within a class. 2304198092Srdivacky/// 2305263508Sdim/// For example: 2306263508Sdim/// 2307263508Sdim/// \code 2308193326Sed/// class X { 2309193326Sed/// public: 2310193326Sed/// operator bool(); 2311193326Sed/// }; 2312263508Sdim/// \endcode 2313193326Sedclass CXXConversionDecl : public CXXMethodDecl { 2314234353Sdim virtual void anchor(); 2315263508Sdim /// Whether this conversion function declaration is marked 2316263508Sdim /// "explicit", meaning that it can only be applied when the user 2317193326Sed /// explicitly wrote a cast. This is a C++0x feature. 2318203955Srdivacky bool IsExplicitSpecified : 1; 2319193326Sed 2320221345Sdim CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 2321221345Sdim const DeclarationNameInfo &NameInfo, 2322212904Sdim QualType T, TypeSourceInfo *TInfo, 2323221345Sdim bool isInline, bool isExplicitSpecified, 2324226633Sdim bool isConstexpr, SourceLocation EndLocation) 2325249423Sdim : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, 2326226633Sdim SC_None, isInline, isConstexpr, EndLocation), 2327203955Srdivacky IsExplicitSpecified(isExplicitSpecified) { } 2328193326Sed 2329193326Sedpublic: 2330193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 2331221345Sdim SourceLocation StartLoc, 2332212904Sdim const DeclarationNameInfo &NameInfo, 2333200583Srdivacky QualType T, TypeSourceInfo *TInfo, 2334221345Sdim bool isInline, bool isExplicit, 2335226633Sdim bool isConstexpr, 2336221345Sdim SourceLocation EndLocation); 2337234353Sdim static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2338193326Sed 2339263508Sdim /// Whether this conversion function declaration is marked 2340263508Sdim /// "explicit", meaning that it can only be used for direct initialization 2341263508Sdim /// (including explitly written casts). This is a C++11 feature. 2342203955Srdivacky bool isExplicitSpecified() const { return IsExplicitSpecified; } 2343203955Srdivacky 2344263508Sdim /// \brief Whether this is an explicit conversion operator (C++11 and later). 2345263508Sdim /// 2346263508Sdim /// Explicit conversion operators are only considered for direct 2347263508Sdim /// initialization, e.g., when the user has explicitly written a cast. 2348203955Srdivacky bool isExplicit() const { 2349263508Sdim return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified(); 2350203955Srdivacky } 2351193326Sed 2352263508Sdim /// \brief Returns the type that this conversion function is converting to. 2353198092Srdivacky QualType getConversionType() const { 2354198092Srdivacky return getType()->getAs<FunctionType>()->getResultType(); 2355193326Sed } 2356193326Sed 2357234353Sdim /// \brief Determine whether this conversion function is a conversion from 2358234353Sdim /// a lambda closure type to a block pointer. 2359234353Sdim bool isLambdaToBlockPointerConversion() const; 2360234353Sdim 2361193326Sed // Implement isa/cast/dyncast/etc. 2362203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2363203955Srdivacky static bool classofKind(Kind K) { return K == CXXConversion; } 2364234353Sdim 2365212904Sdim friend class ASTDeclReader; 2366212904Sdim friend class ASTDeclWriter; 2367193326Sed}; 2368193326Sed 2369263508Sdim/// \brief Represents a linkage specification. 2370263508Sdim/// 2371263508Sdim/// For example: 2372263508Sdim/// \code 2373193326Sed/// extern "C" void foo(); 2374263508Sdim/// \endcode 2375193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 2376234353Sdim virtual void anchor(); 2377193326Sedpublic: 2378263508Sdim /// \brief Represents the language in a linkage specification. 2379263508Sdim /// 2380263508Sdim /// The values are part of the serialization ABI for 2381263508Sdim /// ASTs and cannot be changed without altering that ABI. To help 2382263508Sdim /// ensure a stable ABI for this, we choose the DW_LANG_ encodings 2383193326Sed /// from the dwarf standard. 2384208600Srdivacky enum LanguageIDs { 2385208600Srdivacky lang_c = /* DW_LANG_C */ 0x0002, 2386208600Srdivacky lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 2387208600Srdivacky }; 2388193326Sedprivate: 2389263508Sdim /// \brief The language for this linkage specification. 2390251662Sdim unsigned Language : 3; 2391263508Sdim /// \brief True if this linkage spec has braces. 2392263508Sdim /// 2393263508Sdim /// This is needed so that hasBraces() returns the correct result while the 2394263508Sdim /// linkage spec body is being parsed. Once RBraceLoc has been set this is 2395263508Sdim /// not used, so it doesn't need to be serialized. 2396251662Sdim unsigned HasBraces : 1; 2397263508Sdim /// \brief The source location for the extern keyword. 2398221345Sdim SourceLocation ExternLoc; 2399263508Sdim /// \brief The source location for the right brace (if valid). 2400221345Sdim SourceLocation RBraceLoc; 2401193326Sed 2402221345Sdim LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, 2403251662Sdim SourceLocation LangLoc, LanguageIDs lang, bool HasBraces) 2404221345Sdim : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), 2405251662Sdim Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc), 2406251662Sdim RBraceLoc(SourceLocation()) { } 2407193326Sed 2408193326Sedpublic: 2409198092Srdivacky static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 2410221345Sdim SourceLocation ExternLoc, 2411221345Sdim SourceLocation LangLoc, LanguageIDs Lang, 2412251662Sdim bool HasBraces); 2413234353Sdim static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2414234353Sdim 2415208600Srdivacky /// \brief Return the language specified by this linkage specification. 2416251662Sdim LanguageIDs getLanguage() const { return LanguageIDs(Language); } 2417208600Srdivacky /// \brief Set the language specified by this linkage specification. 2418208600Srdivacky void setLanguage(LanguageIDs L) { Language = L; } 2419208600Srdivacky 2420208600Srdivacky /// \brief Determines whether this linkage specification had braces in 2421208600Srdivacky /// its syntactic form. 2422251662Sdim bool hasBraces() const { 2423251662Sdim assert(!RBraceLoc.isValid() || HasBraces); 2424251662Sdim return HasBraces; 2425251662Sdim } 2426193326Sed 2427221345Sdim SourceLocation getExternLoc() const { return ExternLoc; } 2428221345Sdim SourceLocation getRBraceLoc() const { return RBraceLoc; } 2429221345Sdim void setExternLoc(SourceLocation L) { ExternLoc = L; } 2430251662Sdim void setRBraceLoc(SourceLocation L) { 2431251662Sdim RBraceLoc = L; 2432251662Sdim HasBraces = RBraceLoc.isValid(); 2433251662Sdim } 2434208600Srdivacky 2435234353Sdim SourceLocation getLocEnd() const LLVM_READONLY { 2436221345Sdim if (hasBraces()) 2437221345Sdim return getRBraceLoc(); 2438221345Sdim // No braces: get the end location of the (only) declaration in context 2439221345Sdim // (if present). 2440221345Sdim return decls_empty() ? getLocation() : decls_begin()->getLocEnd(); 2441221345Sdim } 2442221345Sdim 2443234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 2444221345Sdim return SourceRange(ExternLoc, getLocEnd()); 2445221345Sdim } 2446221345Sdim 2447203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2448203955Srdivacky static bool classofKind(Kind K) { return K == LinkageSpec; } 2449193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 2450193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 2451193326Sed } 2452193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 2453193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 2454193326Sed } 2455193326Sed}; 2456193326Sed 2457263508Sdim/// \brief Represents C++ using-directive. 2458193326Sed/// 2459263508Sdim/// For example: 2460263508Sdim/// \code 2461193326Sed/// using namespace std; 2462263508Sdim/// \endcode 2463193326Sed/// 2464263508Sdim/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide 2465263508Sdim/// artificial names for all using-directives in order to store 2466263508Sdim/// them in DeclContext effectively. 2467193326Sedclass UsingDirectiveDecl : public NamedDecl { 2468234353Sdim virtual void anchor(); 2469263508Sdim /// \brief The location of the \c using keyword. 2470212904Sdim SourceLocation UsingLoc; 2471234353Sdim 2472263508Sdim /// \brief The location of the \c namespace keyword. 2473193326Sed SourceLocation NamespaceLoc; 2474193326Sed 2475219077Sdim /// \brief The nested-name-specifier that precedes the namespace. 2476219077Sdim NestedNameSpecifierLoc QualifierLoc; 2477193326Sed 2478263508Sdim /// \brief The namespace nominated by this using-directive. 2479199990Srdivacky NamedDecl *NominatedNamespace; 2480193326Sed 2481199990Srdivacky /// Enclosing context containing both using-directive and nominated 2482193326Sed /// namespace. 2483193326Sed DeclContext *CommonAncestor; 2484193326Sed 2485263508Sdim /// \brief Returns special DeclarationName used by using-directives. 2486263508Sdim /// 2487263508Sdim /// This is only used by DeclContext for storing UsingDirectiveDecls in 2488263508Sdim /// its lookup structure. 2489193326Sed static DeclarationName getName() { 2490193326Sed return DeclarationName::getUsingDirectiveName(); 2491193326Sed } 2492193326Sed 2493212904Sdim UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, 2494193326Sed SourceLocation NamespcLoc, 2495219077Sdim NestedNameSpecifierLoc QualifierLoc, 2496193326Sed SourceLocation IdentLoc, 2497199990Srdivacky NamedDecl *Nominated, 2498193326Sed DeclContext *CommonAncestor) 2499212904Sdim : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), 2500219077Sdim NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), 2501219077Sdim NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { } 2502193326Sed 2503193326Sedpublic: 2504193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 2505219077Sdim /// name of the namespace, with source-location information. 2506219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2507234353Sdim 2508219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the 2509193326Sed /// name of the namespace. 2510234353Sdim NestedNameSpecifier *getQualifier() const { 2511234353Sdim return QualifierLoc.getNestedNameSpecifier(); 2512219077Sdim } 2513193326Sed 2514199990Srdivacky NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 2515199990Srdivacky const NamedDecl *getNominatedNamespaceAsWritten() const { 2516199990Srdivacky return NominatedNamespace; 2517199990Srdivacky } 2518199990Srdivacky 2519263508Sdim /// \brief Returns the namespace nominated by this using-directive. 2520199990Srdivacky NamespaceDecl *getNominatedNamespace(); 2521193326Sed 2522193326Sed const NamespaceDecl *getNominatedNamespace() const { 2523193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 2524193326Sed } 2525193326Sed 2526208600Srdivacky /// \brief Returns the common ancestor context of this using-directive and 2527208600Srdivacky /// its nominated namespace. 2528193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 2529193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 2530193326Sed 2531263508Sdim /// \brief Return the location of the \c using keyword. 2532212904Sdim SourceLocation getUsingLoc() const { return UsingLoc; } 2533234353Sdim 2534208600Srdivacky // FIXME: Could omit 'Key' in name. 2535263508Sdim /// \brief Returns the location of the \c namespace keyword. 2536193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 2537193326Sed 2538263508Sdim /// \brief Returns the location of this using declaration's identifier. 2539212904Sdim SourceLocation getIdentLocation() const { return getLocation(); } 2540193326Sed 2541193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 2542212904Sdim SourceLocation UsingLoc, 2543193326Sed SourceLocation NamespaceLoc, 2544219077Sdim NestedNameSpecifierLoc QualifierLoc, 2545193326Sed SourceLocation IdentLoc, 2546199990Srdivacky NamedDecl *Nominated, 2547193326Sed DeclContext *CommonAncestor); 2548234353Sdim static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2549234353Sdim 2550234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 2551212904Sdim return SourceRange(UsingLoc, getLocation()); 2552212904Sdim } 2553234353Sdim 2554203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2555210299Sed static bool classofKind(Kind K) { return K == UsingDirective; } 2556193326Sed 2557193326Sed // Friend for getUsingDirectiveName. 2558193326Sed friend class DeclContext; 2559234353Sdim 2560212904Sdim friend class ASTDeclReader; 2561193326Sed}; 2562193326Sed 2563239462Sdim/// \brief Represents a C++ namespace alias. 2564193326Sed/// 2565239462Sdim/// For example: 2566239462Sdim/// 2567263508Sdim/// \code 2568193326Sed/// namespace Foo = Bar; 2569263508Sdim/// \endcode 2570193326Sedclass NamespaceAliasDecl : public NamedDecl { 2571234353Sdim virtual void anchor(); 2572234353Sdim 2573263508Sdim /// \brief The location of the \c namespace keyword. 2574212904Sdim SourceLocation NamespaceLoc; 2575193326Sed 2576263508Sdim /// \brief The location of the namespace's identifier. 2577263508Sdim /// 2578263508Sdim /// This is accessed by TargetNameLoc. 2579193326Sed SourceLocation IdentLoc; 2580234353Sdim 2581219077Sdim /// \brief The nested-name-specifier that precedes the namespace. 2582219077Sdim NestedNameSpecifierLoc QualifierLoc; 2583234353Sdim 2584263508Sdim /// \brief The Decl that this alias points to, either a NamespaceDecl or 2585263508Sdim /// a NamespaceAliasDecl. 2586193326Sed NamedDecl *Namespace; 2587198092Srdivacky 2588212904Sdim NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc, 2589198092Srdivacky SourceLocation AliasLoc, IdentifierInfo *Alias, 2590219077Sdim NestedNameSpecifierLoc QualifierLoc, 2591193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 2592234353Sdim : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), 2593219077Sdim NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), 2594219077Sdim QualifierLoc(QualifierLoc), Namespace(Namespace) { } 2595193326Sed 2596212904Sdim friend class ASTDeclReader; 2597234353Sdim 2598193326Sedpublic: 2599193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 2600219077Sdim /// name of the namespace, with source-location information. 2601219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2602234353Sdim 2603219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the 2604193326Sed /// name of the namespace. 2605234353Sdim NestedNameSpecifier *getQualifier() const { 2606234353Sdim return QualifierLoc.getNestedNameSpecifier(); 2607219077Sdim } 2608234353Sdim 2609208600Srdivacky /// \brief Retrieve the namespace declaration aliased by this directive. 2610193326Sed NamespaceDecl *getNamespace() { 2611193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 2612193326Sed return AD->getNamespace(); 2613193326Sed 2614193326Sed return cast<NamespaceDecl>(Namespace); 2615193326Sed } 2616198092Srdivacky 2617193326Sed const NamespaceDecl *getNamespace() const { 2618193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 2619193326Sed } 2620193326Sed 2621203955Srdivacky /// Returns the location of the alias name, i.e. 'foo' in 2622203955Srdivacky /// "namespace foo = ns::bar;". 2623212904Sdim SourceLocation getAliasLoc() const { return getLocation(); } 2624203955Srdivacky 2625263508Sdim /// Returns the location of the \c namespace keyword. 2626212904Sdim SourceLocation getNamespaceLoc() const { return NamespaceLoc; } 2627203955Srdivacky 2628203955Srdivacky /// Returns the location of the identifier in the named namespace. 2629203955Srdivacky SourceLocation getTargetNameLoc() const { return IdentLoc; } 2630203955Srdivacky 2631193326Sed /// \brief Retrieve the namespace that this alias refers to, which 2632193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 2633193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 2634193326Sed 2635198092Srdivacky static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 2636234353Sdim SourceLocation NamespaceLoc, 2637212904Sdim SourceLocation AliasLoc, 2638198092Srdivacky IdentifierInfo *Alias, 2639219077Sdim NestedNameSpecifierLoc QualifierLoc, 2640198092Srdivacky SourceLocation IdentLoc, 2641193326Sed NamedDecl *Namespace); 2642198092Srdivacky 2643234353Sdim static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2644234353Sdim 2645234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY { 2646212904Sdim return SourceRange(NamespaceLoc, IdentLoc); 2647212904Sdim } 2648234353Sdim 2649203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2650210299Sed static bool classofKind(Kind K) { return K == NamespaceAlias; } 2651193326Sed}; 2652194613Sed 2653239462Sdim/// \brief Represents a shadow declaration introduced into a scope by a 2654239462Sdim/// (resolved) using declaration. 2655199482Srdivacky/// 2656239462Sdim/// For example, 2657263508Sdim/// \code 2658199482Srdivacky/// namespace A { 2659199482Srdivacky/// void foo(); 2660199482Srdivacky/// } 2661199482Srdivacky/// namespace B { 2662239462Sdim/// using A::foo; // <- a UsingDecl 2663239462Sdim/// // Also creates a UsingShadowDecl for A::foo() in B 2664199482Srdivacky/// } 2665263508Sdim/// \endcode 2666263508Sdimclass UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { 2667234353Sdim virtual void anchor(); 2668234353Sdim 2669199482Srdivacky /// The referenced declaration. 2670199482Srdivacky NamedDecl *Underlying; 2671199482Srdivacky 2672218893Sdim /// \brief The using declaration which introduced this decl or the next using 2673218893Sdim /// shadow declaration contained in the aforementioned using declaration. 2674218893Sdim NamedDecl *UsingOrNextShadow; 2675218893Sdim friend class UsingDecl; 2676199482Srdivacky 2677199482Srdivacky UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 2678199482Srdivacky NamedDecl *Target) 2679210299Sed : NamedDecl(UsingShadow, DC, Loc, DeclarationName()), 2680218893Sdim Underlying(Target), 2681218893Sdim UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) { 2682210299Sed if (Target) { 2683210299Sed setDeclName(Target->getDeclName()); 2684210299Sed IdentifierNamespace = Target->getIdentifierNamespace(); 2685210299Sed } 2686199482Srdivacky setImplicit(); 2687199482Srdivacky } 2688199482Srdivacky 2689263508Sdim typedef Redeclarable<UsingShadowDecl> redeclarable_base; 2690263508Sdim virtual UsingShadowDecl *getNextRedeclaration() { 2691263508Sdim return RedeclLink.getNext(); 2692263508Sdim } 2693263508Sdim virtual UsingShadowDecl *getPreviousDeclImpl() { 2694263508Sdim return getPreviousDecl(); 2695263508Sdim } 2696263508Sdim virtual UsingShadowDecl *getMostRecentDeclImpl() { 2697263508Sdim return getMostRecentDecl(); 2698263508Sdim } 2699263508Sdim 2700199482Srdivackypublic: 2701199482Srdivacky static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 2702199482Srdivacky SourceLocation Loc, UsingDecl *Using, 2703199482Srdivacky NamedDecl *Target) { 2704199482Srdivacky return new (C) UsingShadowDecl(DC, Loc, Using, Target); 2705199482Srdivacky } 2706199482Srdivacky 2707234353Sdim static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2708263508Sdim 2709263508Sdim typedef redeclarable_base::redecl_iterator redecl_iterator; 2710263508Sdim using redeclarable_base::redecls_begin; 2711263508Sdim using redeclarable_base::redecls_end; 2712263508Sdim using redeclarable_base::getPreviousDecl; 2713263508Sdim using redeclarable_base::getMostRecentDecl; 2714263508Sdim 2715263508Sdim virtual UsingShadowDecl *getCanonicalDecl() { 2716263508Sdim return getFirstDecl(); 2717263508Sdim } 2718263508Sdim virtual const UsingShadowDecl *getCanonicalDecl() const { 2719263508Sdim return getFirstDecl(); 2720263508Sdim } 2721263508Sdim 2722208600Srdivacky /// \brief Gets the underlying declaration which has been brought into the 2723199482Srdivacky /// local scope. 2724208600Srdivacky NamedDecl *getTargetDecl() const { return Underlying; } 2725199482Srdivacky 2726208600Srdivacky /// \brief Sets the underlying declaration which has been brought into the 2727208600Srdivacky /// local scope. 2728210299Sed void setTargetDecl(NamedDecl* ND) { 2729210299Sed assert(ND && "Target decl is null!"); 2730210299Sed Underlying = ND; 2731210299Sed IdentifierNamespace = ND->getIdentifierNamespace(); 2732210299Sed } 2733199482Srdivacky 2734208600Srdivacky /// \brief Gets the using declaration to which this declaration is tied. 2735218893Sdim UsingDecl *getUsingDecl() const; 2736208600Srdivacky 2737218893Sdim /// \brief The next using shadow declaration contained in the shadow decl 2738218893Sdim /// chain of the using declaration which introduced this decl. 2739218893Sdim UsingShadowDecl *getNextUsingShadowDecl() const { 2740218893Sdim return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); 2741218893Sdim } 2742208600Srdivacky 2743203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2744203955Srdivacky static bool classofKind(Kind K) { return K == Decl::UsingShadow; } 2745218893Sdim 2746218893Sdim friend class ASTDeclReader; 2747218893Sdim friend class ASTDeclWriter; 2748199482Srdivacky}; 2749199482Srdivacky 2750239462Sdim/// \brief Represents a C++ using-declaration. 2751239462Sdim/// 2752239462Sdim/// For example: 2753263508Sdim/// \code 2754194613Sed/// using someNameSpace::someIdentifier; 2755263508Sdim/// \endcode 2756194613Sedclass UsingDecl : public NamedDecl { 2757234353Sdim virtual void anchor(); 2758234353Sdim 2759263508Sdim /// \brief The source location of the 'using' keyword itself. 2760194613Sed SourceLocation UsingLocation; 2761198092Srdivacky 2762219077Sdim /// \brief The nested-name-specifier that precedes the name. 2763219077Sdim NestedNameSpecifierLoc QualifierLoc; 2764194613Sed 2765263508Sdim /// \brief Provides source/type location info for the declaration name 2766263508Sdim /// embedded in the ValueDecl base class. 2767212904Sdim DeclarationNameLoc DNLoc; 2768212904Sdim 2769218893Sdim /// \brief The first shadow declaration of the shadow decl chain associated 2770239462Sdim /// with this using declaration. 2771239462Sdim /// 2772239462Sdim /// The bool member of the pair store whether this decl has the \c typename 2773239462Sdim /// keyword. 2774234353Sdim llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; 2775199482Srdivacky 2776234353Sdim UsingDecl(DeclContext *DC, SourceLocation UL, 2777219077Sdim NestedNameSpecifierLoc QualifierLoc, 2778263508Sdim const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) 2779212904Sdim : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), 2780219077Sdim UsingLocation(UL), QualifierLoc(QualifierLoc), 2781263508Sdim DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, HasTypenameKeyword) { 2782194613Sed } 2783194613Sed 2784194613Sedpublic: 2785263508Sdim /// \brief Return the source location of the 'using' keyword. 2786263508Sdim SourceLocation getUsingLoc() const { return UsingLocation; } 2787198092Srdivacky 2788208600Srdivacky /// \brief Set the source location of the 'using' keyword. 2789263508Sdim void setUsingLoc(SourceLocation L) { UsingLocation = L; } 2790208600Srdivacky 2791219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name, 2792219077Sdim /// with source-location information. 2793219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2794219077Sdim 2795219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name. 2796234353Sdim NestedNameSpecifier *getQualifier() const { 2797234353Sdim return QualifierLoc.getNestedNameSpecifier(); 2798195099Sed } 2799198092Srdivacky 2800212904Sdim DeclarationNameInfo getNameInfo() const { 2801212904Sdim return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2802212904Sdim } 2803212904Sdim 2804263508Sdim /// \brief Return true if it is a C++03 access declaration (no 'using'). 2805263508Sdim bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } 2806263508Sdim 2807208600Srdivacky /// \brief Return true if the using declaration has 'typename'. 2808263508Sdim bool hasTypename() const { return FirstUsingShadow.getInt(); } 2809194613Sed 2810208600Srdivacky /// \brief Sets whether the using declaration has 'typename'. 2811263508Sdim void setTypename(bool TN) { FirstUsingShadow.setInt(TN); } 2812208600Srdivacky 2813263508Sdim /// \brief Iterates through the using shadow declarations associated with 2814218893Sdim /// this using declaration. 2815218893Sdim class shadow_iterator { 2816218893Sdim /// \brief The current using shadow declaration. 2817218893Sdim UsingShadowDecl *Current; 2818199482Srdivacky 2819218893Sdim public: 2820218893Sdim typedef UsingShadowDecl* value_type; 2821218893Sdim typedef UsingShadowDecl* reference; 2822218893Sdim typedef UsingShadowDecl* pointer; 2823218893Sdim typedef std::forward_iterator_tag iterator_category; 2824218893Sdim typedef std::ptrdiff_t difference_type; 2825218893Sdim 2826218893Sdim shadow_iterator() : Current(0) { } 2827218893Sdim explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { } 2828218893Sdim 2829218893Sdim reference operator*() const { return Current; } 2830218893Sdim pointer operator->() const { return Current; } 2831218893Sdim 2832218893Sdim shadow_iterator& operator++() { 2833218893Sdim Current = Current->getNextUsingShadowDecl(); 2834218893Sdim return *this; 2835199482Srdivacky } 2836218893Sdim 2837218893Sdim shadow_iterator operator++(int) { 2838218893Sdim shadow_iterator tmp(*this); 2839218893Sdim ++(*this); 2840218893Sdim return tmp; 2841199482Srdivacky } 2842218893Sdim 2843218893Sdim friend bool operator==(shadow_iterator x, shadow_iterator y) { 2844218893Sdim return x.Current == y.Current; 2845218893Sdim } 2846218893Sdim friend bool operator!=(shadow_iterator x, shadow_iterator y) { 2847218893Sdim return x.Current != y.Current; 2848218893Sdim } 2849218893Sdim }; 2850218893Sdim 2851218893Sdim shadow_iterator shadow_begin() const { 2852234353Sdim return shadow_iterator(FirstUsingShadow.getPointer()); 2853199482Srdivacky } 2854218893Sdim shadow_iterator shadow_end() const { return shadow_iterator(); } 2855199482Srdivacky 2856208600Srdivacky /// \brief Return the number of shadowed declarations associated with this 2857208600Srdivacky /// using declaration. 2858218893Sdim unsigned shadow_size() const { 2859218893Sdim return std::distance(shadow_begin(), shadow_end()); 2860208600Srdivacky } 2861208600Srdivacky 2862218893Sdim void addShadowDecl(UsingShadowDecl *S); 2863218893Sdim void removeShadowDecl(UsingShadowDecl *S); 2864218893Sdim 2865194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 2866219077Sdim SourceLocation UsingL, 2867219077Sdim NestedNameSpecifierLoc QualifierLoc, 2868212904Sdim const DeclarationNameInfo &NameInfo, 2869263508Sdim bool HasTypenameKeyword); 2870194613Sed 2871234353Sdim static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2872212904Sdim 2873263508Sdim SourceRange getSourceRange() const LLVM_READONLY; 2874263508Sdim 2875203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2876210299Sed static bool classofKind(Kind K) { return K == Using; } 2877210299Sed 2878212904Sdim friend class ASTDeclReader; 2879212904Sdim friend class ASTDeclWriter; 2880194613Sed}; 2881198092Srdivacky 2882239462Sdim/// \brief Represents a dependent using declaration which was not marked with 2883239462Sdim/// \c typename. 2884239462Sdim/// 2885239462Sdim/// Unlike non-dependent using declarations, these *only* bring through 2886199482Srdivacky/// non-types; otherwise they would break two-phase lookup. 2887199482Srdivacky/// 2888263508Sdim/// \code 2889239462Sdim/// template \<class T> class A : public Base<T> { 2890199482Srdivacky/// using Base<T>::foo; 2891199482Srdivacky/// }; 2892263508Sdim/// \endcode 2893199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl { 2894234353Sdim virtual void anchor(); 2895234353Sdim 2896199482Srdivacky /// \brief The source location of the 'using' keyword 2897199482Srdivacky SourceLocation UsingLocation; 2898198092Srdivacky 2899219077Sdim /// \brief The nested-name-specifier that precedes the name. 2900219077Sdim NestedNameSpecifierLoc QualifierLoc; 2901198092Srdivacky 2902263508Sdim /// \brief Provides source/type location info for the declaration name 2903263508Sdim /// embedded in the ValueDecl base class. 2904212904Sdim DeclarationNameLoc DNLoc; 2905212904Sdim 2906199482Srdivacky UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 2907234353Sdim SourceLocation UsingLoc, 2908219077Sdim NestedNameSpecifierLoc QualifierLoc, 2909212904Sdim const DeclarationNameInfo &NameInfo) 2910212904Sdim : ValueDecl(UnresolvedUsingValue, DC, 2911212904Sdim NameInfo.getLoc(), NameInfo.getName(), Ty), 2912219077Sdim UsingLocation(UsingLoc), QualifierLoc(QualifierLoc), 2913219077Sdim DNLoc(NameInfo.getInfo()) 2914199482Srdivacky { } 2915198092Srdivacky 2916199482Srdivackypublic: 2917199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 2918199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 2919199482Srdivacky 2920208600Srdivacky /// \brief Set the source location of the 'using' keyword. 2921208600Srdivacky void setUsingLoc(SourceLocation L) { UsingLocation = L; } 2922208600Srdivacky 2923263508Sdim /// \brief Return true if it is a C++03 access declaration (no 'using'). 2924263508Sdim bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } 2925263508Sdim 2926219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name, 2927219077Sdim /// with source-location information. 2928219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2929219077Sdim 2930219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name. 2931234353Sdim NestedNameSpecifier *getQualifier() const { 2932234353Sdim return QualifierLoc.getNestedNameSpecifier(); 2933219077Sdim } 2934234353Sdim 2935212904Sdim DeclarationNameInfo getNameInfo() const { 2936212904Sdim return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2937212904Sdim } 2938212904Sdim 2939199482Srdivacky static UnresolvedUsingValueDecl * 2940199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2941234353Sdim NestedNameSpecifierLoc QualifierLoc, 2942212904Sdim const DeclarationNameInfo &NameInfo); 2943199482Srdivacky 2944234353Sdim static UnresolvedUsingValueDecl * 2945234353Sdim CreateDeserialized(ASTContext &C, unsigned ID); 2946234353Sdim 2947263508Sdim SourceRange getSourceRange() const LLVM_READONLY; 2948212904Sdim 2949203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2950210299Sed static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } 2951218893Sdim 2952218893Sdim friend class ASTDeclReader; 2953218893Sdim friend class ASTDeclWriter; 2954199482Srdivacky}; 2955199482Srdivacky 2956263508Sdim/// \brief Represents a dependent using declaration which was marked with 2957239462Sdim/// \c typename. 2958199482Srdivacky/// 2959263508Sdim/// \code 2960239462Sdim/// template \<class T> class A : public Base<T> { 2961199482Srdivacky/// using typename Base<T>::foo; 2962199482Srdivacky/// }; 2963263508Sdim/// \endcode 2964199482Srdivacky/// 2965239462Sdim/// The type associated with an unresolved using typename decl is 2966199482Srdivacky/// currently always a typename type. 2967199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl { 2968234353Sdim virtual void anchor(); 2969234353Sdim 2970199482Srdivacky /// \brief The source location of the 'typename' keyword 2971199482Srdivacky SourceLocation TypenameLocation; 2972199482Srdivacky 2973219077Sdim /// \brief The nested-name-specifier that precedes the name. 2974219077Sdim NestedNameSpecifierLoc QualifierLoc; 2975199482Srdivacky 2976199482Srdivacky UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 2977219077Sdim SourceLocation TypenameLoc, 2978219077Sdim NestedNameSpecifierLoc QualifierLoc, 2979234353Sdim SourceLocation TargetNameLoc, 2980219077Sdim IdentifierInfo *TargetName) 2981221345Sdim : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, 2982221345Sdim UsingLoc), 2983221345Sdim TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { } 2984199482Srdivacky 2985212904Sdim friend class ASTDeclReader; 2986234353Sdim 2987198092Srdivackypublic: 2988199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 2989221345Sdim SourceLocation getUsingLoc() const { return getLocStart(); } 2990198092Srdivacky 2991199482Srdivacky /// \brief Returns the source location of the 'typename' keyword. 2992199482Srdivacky SourceLocation getTypenameLoc() const { return TypenameLocation; } 2993198092Srdivacky 2994219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name, 2995219077Sdim /// with source-location information. 2996219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2997219077Sdim 2998219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name. 2999234353Sdim NestedNameSpecifier *getQualifier() const { 3000234353Sdim return QualifierLoc.getNestedNameSpecifier(); 3001219077Sdim } 3002219077Sdim 3003199482Srdivacky static UnresolvedUsingTypenameDecl * 3004199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 3005219077Sdim SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, 3006199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 3007198092Srdivacky 3008234353Sdim static UnresolvedUsingTypenameDecl * 3009234353Sdim CreateDeserialized(ASTContext &C, unsigned ID); 3010234353Sdim 3011203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3012210299Sed static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } 3013198092Srdivacky}; 3014198092Srdivacky 3015239462Sdim/// \brief Represents a C++11 static_assert declaration. 3016193326Sedclass StaticAssertDecl : public Decl { 3017234353Sdim virtual void anchor(); 3018239462Sdim llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; 3019193326Sed StringLiteral *Message; 3020221345Sdim SourceLocation RParenLoc; 3021193326Sed 3022221345Sdim StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, 3023239462Sdim Expr *AssertExpr, StringLiteral *Message, 3024239462Sdim SourceLocation RParenLoc, bool Failed) 3025239462Sdim : Decl(StaticAssert, DC, StaticAssertLoc), 3026239462Sdim AssertExprAndFailed(AssertExpr, Failed), Message(Message), 3027239462Sdim RParenLoc(RParenLoc) { } 3028198092Srdivacky 3029193326Sedpublic: 3030193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 3031221345Sdim SourceLocation StaticAssertLoc, 3032221345Sdim Expr *AssertExpr, StringLiteral *Message, 3033239462Sdim SourceLocation RParenLoc, bool Failed); 3034234353Sdim static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3035234353Sdim 3036239462Sdim Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } 3037239462Sdim const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } 3038198092Srdivacky 3039193326Sed StringLiteral *getMessage() { return Message; } 3040193326Sed const StringLiteral *getMessage() const { return Message; } 3041198092Srdivacky 3042239462Sdim bool isFailed() const { return AssertExprAndFailed.getInt(); } 3043239462Sdim 3044221345Sdim SourceLocation getRParenLoc() const { return RParenLoc; } 3045221345Sdim 3046234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 3047221345Sdim return SourceRange(getLocation(), getRParenLoc()); 3048221345Sdim } 3049221345Sdim 3050203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3051210299Sed static bool classofKind(Kind K) { return K == StaticAssert; } 3052212904Sdim 3053212904Sdim friend class ASTDeclReader; 3054193326Sed}; 3055193326Sed 3056251662Sdim/// An instance of this class represents the declaration of a property 3057251662Sdim/// member. This is a Microsoft extension to C++, first introduced in 3058251662Sdim/// Visual Studio .NET 2003 as a parallel to similar features in C# 3059251662Sdim/// and Managed C++. 3060251662Sdim/// 3061251662Sdim/// A property must always be a non-static class member. 3062251662Sdim/// 3063251662Sdim/// A property member superficially resembles a non-static data 3064251662Sdim/// member, except preceded by a property attribute: 3065251662Sdim/// __declspec(property(get=GetX, put=PutX)) int x; 3066251662Sdim/// Either (but not both) of the 'get' and 'put' names may be omitted. 3067251662Sdim/// 3068251662Sdim/// A reference to a property is always an lvalue. If the lvalue 3069251662Sdim/// undergoes lvalue-to-rvalue conversion, then a getter name is 3070251662Sdim/// required, and that member is called with no arguments. 3071251662Sdim/// If the lvalue is assigned into, then a setter name is required, 3072251662Sdim/// and that member is called with one argument, the value assigned. 3073251662Sdim/// Both operations are potentially overloaded. Compound assignments 3074251662Sdim/// are permitted, as are the increment and decrement operators. 3075251662Sdim/// 3076251662Sdim/// The getter and putter methods are permitted to be overloaded, 3077251662Sdim/// although their return and parameter types are subject to certain 3078251662Sdim/// restrictions according to the type of the property. 3079251662Sdim/// 3080251662Sdim/// A property declared using an incomplete array type may 3081251662Sdim/// additionally be subscripted, adding extra parameters to the getter 3082251662Sdim/// and putter methods. 3083251662Sdimclass MSPropertyDecl : public DeclaratorDecl { 3084251662Sdim IdentifierInfo *GetterId, *SetterId; 3085251662Sdim 3086251662Sdimpublic: 3087251662Sdim MSPropertyDecl(DeclContext *DC, SourceLocation L, 3088251662Sdim DeclarationName N, QualType T, TypeSourceInfo *TInfo, 3089251662Sdim SourceLocation StartL, IdentifierInfo *Getter, 3090251662Sdim IdentifierInfo *Setter): 3091251662Sdim DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), GetterId(Getter), 3092251662Sdim SetterId(Setter) {} 3093251662Sdim 3094251662Sdim static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3095251662Sdim 3096251662Sdim static bool classof(const Decl *D) { return D->getKind() == MSProperty; } 3097251662Sdim 3098251662Sdim bool hasGetter() const { return GetterId != NULL; } 3099251662Sdim IdentifierInfo* getGetterId() const { return GetterId; } 3100251662Sdim bool hasSetter() const { return SetterId != NULL; } 3101251662Sdim IdentifierInfo* getSetterId() const { return SetterId; } 3102251662Sdim 3103251662Sdim friend class ASTDeclReader; 3104251662Sdim}; 3105251662Sdim 3106239462Sdim/// Insertion operator for diagnostics. This allows sending an AccessSpecifier 3107193326Sed/// into a diagnostic with <<. 3108193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3109193326Sed AccessSpecifier AS); 3110198092Srdivacky 3111234353Sdimconst PartialDiagnostic &operator<<(const PartialDiagnostic &DB, 3112234353Sdim AccessSpecifier AS); 3113234353Sdim 3114193326Sed} // end namespace clang 3115193326Sed 3116193326Sed#endif 3117