DeclCXX.h revision 223017
1136849Sscottl//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2149871Sscottl// 3136849Sscottl// The LLVM Compiler Infrastructure 4136849Sscottl// 5136849Sscottl// This file is distributed under the University of Illinois Open Source 6136849Sscottl// License. See LICENSE.TXT for details. 7136849Sscottl// 8136849Sscottl//===----------------------------------------------------------------------===// 9136849Sscottl// 10136849Sscottl// This file defines the C++ Decl subclasses, other than those for 11136849Sscottl// templates (in DeclTemplate.h) and friends (in DeclFriend.h). 12136849Sscottl// 13136849Sscottl//===----------------------------------------------------------------------===// 14136849Sscottl 15136849Sscottl#ifndef LLVM_CLANG_AST_DECLCXX_H 16136849Sscottl#define LLVM_CLANG_AST_DECLCXX_H 17136849Sscottl 18136849Sscottl#include "clang/AST/Expr.h" 19136849Sscottl#include "clang/AST/Decl.h" 20136849Sscottl#include "clang/AST/TypeLoc.h" 21136849Sscottl#include "clang/AST/UnresolvedSet.h" 22136849Sscottl#include "llvm/ADT/SmallVector.h" 23136849Sscottl#include "llvm/ADT/SmallPtrSet.h" 24136849Sscottl 25142988Sscottlnamespace clang { 26142988Sscottl 27136849Sscottlclass ClassTemplateDecl; 28136849Sscottlclass ClassTemplateSpecializationDecl; 29136849Sscottlclass CXXBasePath; 30136849Sscottlclass CXXBasePaths; 31136849Sscottlclass CXXConstructorDecl; 32136849Sscottlclass CXXConversionDecl; 33136849Sscottlclass CXXDestructorDecl; 34136849Sscottlclass CXXMethodDecl; 35136849Sscottlclass CXXRecordDecl; 36136849Sscottlclass CXXMemberLookupCriteria; 37136849Sscottlclass CXXFinalOverriderMap; 38136849Sscottlclass CXXIndirectPrimaryBaseSet; 39136849Sscottlclass FriendDecl; 40136849Sscottl 41136849Sscottl/// \brief Represents any kind of function declaration, whether it is a 42136849Sscottl/// concrete function or a function template. 43136849Sscottlclass AnyFunctionDecl { 44136849Sscottl NamedDecl *Function; 45149871Sscottl 46149871Sscottl AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 47149871Sscottl 48149871Sscottlpublic: 49136849Sscottl AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 50136849Sscottl AnyFunctionDecl(FunctionTemplateDecl *FTD); 51136849Sscottl 52143039Sscottl /// \brief Implicily converts any function or function template into a 53136849Sscottl /// named declaration. 54136849Sscottl operator NamedDecl *() const { return Function; } 55136849Sscottl 56136849Sscottl /// \brief Retrieve the underlying function or function template. 57136849Sscottl NamedDecl *get() const { return Function; } 58136849Sscottl 59136849Sscottl static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 60190809Sdelphij return AnyFunctionDecl(ND); 61136849Sscottl } 62190809Sdelphij}; 63136849Sscottl 64136849Sscottl} // end namespace clang 65136849Sscottl 66136849Sscottlnamespace llvm { 67190809Sdelphij /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 68136849Sscottl /// AnyFunctionDecl to any function or function template declaration. 69149871Sscottl template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 70149871Sscottl typedef ::clang::NamedDecl* SimpleType; 71136849Sscottl static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 72136849Sscottl return Val; 73136849Sscottl } 74136849Sscottl }; 75136849Sscottl template<> struct simplify_type< ::clang::AnyFunctionDecl> 76136849Sscottl : public simplify_type<const ::clang::AnyFunctionDecl> {}; 77136849Sscottl 78136849Sscottl // Provide PointerLikeTypeTraits for non-cvr pointers. 79136849Sscottl template<> 80136849Sscottl class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 81136849Sscottl public: 82136849Sscottl static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 83136849Sscottl return F.get(); 84136849Sscottl } 85136849Sscottl static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 86136849Sscottl return ::clang::AnyFunctionDecl::getFromNamedDecl( 87136849Sscottl static_cast< ::clang::NamedDecl*>(P)); 88136849Sscottl } 89136849Sscottl 90136849Sscottl enum { NumLowBitsAvailable = 2 }; 91136849Sscottl }; 92136849Sscottl 93136849Sscottl} // end namespace llvm 94136849Sscottl 95136849Sscottlnamespace clang { 96136849Sscottl 97136849Sscottl/// AccessSpecDecl - An access specifier followed by colon ':'. 98136849Sscottl/// 99136849Sscottl/// An objects of this class represents sugar for the syntactic occurrence 100136849Sscottl/// of an access specifier followed by a colon in the list of member 101136849Sscottl/// specifiers of a C++ class definition. 102136849Sscottl/// 103136849Sscottl/// Note that they do not represent other uses of access specifiers, 104190809Sdelphij/// such as those occurring in a list of base specifiers. 105136849Sscottl/// Also note that this class has nothing to do with so-called 106190809Sdelphij/// "access declarations" (C++98 11.3 [class.access.dcl]). 107190809Sdelphijclass AccessSpecDecl : public Decl { 108190809Sdelphij /// ColonLoc - The location of the ':'. 109190809Sdelphij SourceLocation ColonLoc; 110190809Sdelphij 111190809Sdelphij AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, 112136849Sscottl SourceLocation ASLoc, SourceLocation ColonLoc) 113190809Sdelphij : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { 114136849Sscottl setAccess(AS); 115190809Sdelphij } 116190809Sdelphij AccessSpecDecl(EmptyShell Empty) 117190809Sdelphij : Decl(AccessSpec, Empty) { } 118190809Sdelphijpublic: 119136849Sscottl /// getAccessSpecifierLoc - The location of the access specifier. 120136849Sscottl SourceLocation getAccessSpecifierLoc() const { return getLocation(); } 121136849Sscottl /// setAccessSpecifierLoc - Sets the location of the access specifier. 122190809Sdelphij void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } 123190809Sdelphij 124190809Sdelphij /// getColonLoc - The location of the colon following the access specifier. 125136849Sscottl SourceLocation getColonLoc() const { return ColonLoc; } 126136849Sscottl /// setColonLoc - Sets the location of the colon. 127136849Sscottl void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } 128136849Sscottl 129190809Sdelphij SourceRange getSourceRange() const { 130136849Sscottl return SourceRange(getAccessSpecifierLoc(), getColonLoc()); 131136849Sscottl } 132136849Sscottl 133190809Sdelphij static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, 134136849Sscottl DeclContext *DC, SourceLocation ASLoc, 135136849Sscottl SourceLocation ColonLoc) { 136136849Sscottl return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); 137190809Sdelphij } 138136849Sscottl static AccessSpecDecl *Create(ASTContext &C, EmptyShell Empty) { 139136849Sscottl return new (C) AccessSpecDecl(Empty); 140136849Sscottl } 141190809Sdelphij 142136849Sscottl // Implement isa/cast/dyncast/etc. 143136849Sscottl static bool classof(const Decl *D) { return classofKind(D->getKind()); } 144136849Sscottl static bool classof(const AccessSpecDecl *D) { return true; } 145190809Sdelphij static bool classofKind(Kind K) { return K == AccessSpec; } 146136849Sscottl}; 147136849Sscottl 148136849Sscottl 149190809Sdelphij/// CXXBaseSpecifier - A base class of a C++ class. 150136849Sscottl/// 151136849Sscottl/// Each CXXBaseSpecifier represents a single, direct base class (or 152136849Sscottl/// struct) of a C++ class (or struct). It specifies the type of that 153190809Sdelphij/// base class, whether it is a virtual or non-virtual base, and what 154136849Sscottl/// level of access (public, protected, private) is used for the 155136849Sscottl/// derivation. For example: 156136849Sscottl/// 157190809Sdelphij/// @code 158136849Sscottl/// class A { }; 159136849Sscottl/// class B { }; 160136849Sscottl/// class C : public virtual A, protected B { }; 161190809Sdelphij/// @endcode 162136849Sscottl/// 163136849Sscottl/// In this code, C will have two CXXBaseSpecifiers, one for "public 164136849Sscottl/// virtual A" and the other for "protected B". 165136849Sscottlclass CXXBaseSpecifier { 166136849Sscottl /// Range - The source code range that covers the full base 167136849Sscottl /// specifier, including the "virtual" (if present) and access 168136849Sscottl /// specifier (if present). 169136849Sscottl SourceRange Range; 170136849Sscottl 171136849Sscottl /// \brief The source location of the ellipsis, if this is a pack 172190809Sdelphij /// expansion. 173136849Sscottl SourceLocation EllipsisLoc; 174136849Sscottl 175136849Sscottl /// Virtual - Whether this is a virtual base class or not. 176190809Sdelphij bool Virtual : 1; 177136849Sscottl 178136849Sscottl /// BaseOfClass - Whether this is the base of a class (true) or of a 179136849Sscottl /// struct (false). This determines the mapping from the access 180190809Sdelphij /// specifier as written in the source code to the access specifier 181136849Sscottl /// used for semantic analysis. 182136849Sscottl bool BaseOfClass : 1; 183136849Sscottl 184190809Sdelphij /// Access - Access specifier as written in the source code (which 185136849Sscottl /// may be AS_none). The actual type of data stored here is an 186136849Sscottl /// AccessSpecifier, but we use "unsigned" here to work around a 187136849Sscottl /// VC++ bug. 188190809Sdelphij unsigned Access : 2; 189136849Sscottl 190136849Sscottl /// InheritConstructors - Whether the class contains a using declaration 191136849Sscottl /// to inherit the named class's constructors. 192190809Sdelphij bool InheritConstructors : 1; 193136849Sscottl 194136849Sscottl /// BaseTypeInfo - The type of the base class. This will be a class or struct 195136849Sscottl /// (or a typedef of such). The source code range does not include the 196190809Sdelphij /// "virtual" or access specifier. 197190809Sdelphij TypeSourceInfo *BaseTypeInfo; 198136849Sscottl 199190809Sdelphijpublic: 200190809Sdelphij CXXBaseSpecifier() { } 201190809Sdelphij 202190809Sdelphij CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, 203190809Sdelphij TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) 204190809Sdelphij : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), 205190809Sdelphij Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { } 206190809Sdelphij 207190809Sdelphij /// getSourceRange - Retrieves the source range that contains the 208190809Sdelphij /// entire base specifier. 209190809Sdelphij SourceRange getSourceRange() const { return Range; } 210190809Sdelphij 211190809Sdelphij /// isVirtual - Determines whether the base class is a virtual base 212190809Sdelphij /// class (or not). 213190809Sdelphij bool isVirtual() const { return Virtual; } 214136849Sscottl 215136849Sscottl /// \brief Determine whether this base class is a base of a class declared 216136849Sscottl /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 217136849Sscottl bool isBaseOfClass() const { return BaseOfClass; } 218136849Sscottl 219190809Sdelphij /// \brief Determine whether this base specifier is a pack expansion. 220190809Sdelphij bool isPackExpansion() const { return EllipsisLoc.isValid(); } 221190809Sdelphij 222190809Sdelphij /// \brief Determine whether this base class's constructors get inherited. 223136849Sscottl bool getInheritConstructors() const { return InheritConstructors; } 224190809Sdelphij 225190809Sdelphij /// \brief Set that this base class's constructors should be inherited. 226190809Sdelphij void setInheritConstructors(bool Inherit = true) { 227190809Sdelphij InheritConstructors = Inherit; 228136849Sscottl } 229136849Sscottl 230190809Sdelphij /// \brief For a pack expansion, determine the location of the ellipsis. 231190809Sdelphij SourceLocation getEllipsisLoc() const { 232190809Sdelphij return EllipsisLoc; 233136849Sscottl } 234190809Sdelphij 235190809Sdelphij /// getAccessSpecifier - Returns the access specifier for this base 236190809Sdelphij /// specifier. This is the actual base specifier as used for 237190809Sdelphij /// semantic analysis, so the result can never be AS_none. To 238190809Sdelphij /// retrieve the access specifier as written in the source code, use 239190809Sdelphij /// getAccessSpecifierAsWritten(). 240136849Sscottl AccessSpecifier getAccessSpecifier() const { 241190809Sdelphij if ((AccessSpecifier)Access == AS_none) 242136849Sscottl return BaseOfClass? AS_private : AS_public; 243136849Sscottl else 244190809Sdelphij return (AccessSpecifier)Access; 245190809Sdelphij } 246190809Sdelphij 247190809Sdelphij /// getAccessSpecifierAsWritten - Retrieves the access specifier as 248190809Sdelphij /// written in the source code (which may mean that no access 249136849Sscottl /// specifier was explicitly written). Use getAccessSpecifier() to 250190809Sdelphij /// retrieve the access specifier for use in semantic analysis. 251190809Sdelphij AccessSpecifier getAccessSpecifierAsWritten() const { 252190809Sdelphij return (AccessSpecifier)Access; 253190809Sdelphij } 254190809Sdelphij 255190809Sdelphij /// getType - Retrieves the type of the base class. This type will 256190809Sdelphij /// always be an unqualified class type. 257190809Sdelphij QualType getType() const { return BaseTypeInfo->getType(); } 258190809Sdelphij 259190809Sdelphij /// getTypeLoc - Retrieves the type and source location of the base class. 260190809Sdelphij TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } 261190809Sdelphij}; 262190809Sdelphij 263190809Sdelphij/// CXXRecordDecl - Represents a C++ struct/union/class. 264190809Sdelphij/// FIXME: This class will disappear once we've properly taught RecordDecl 265190809Sdelphij/// to deal with C++-specific things. 266190809Sdelphijclass CXXRecordDecl : public RecordDecl { 267190809Sdelphij 268190809Sdelphij friend void TagDecl::startDefinition(); 269190809Sdelphij 270190809Sdelphij struct DefinitionData { 271136849Sscottl DefinitionData(CXXRecordDecl *D); 272136849Sscottl 273136849Sscottl /// UserDeclaredConstructor - True when this class has a 274190809Sdelphij /// user-declared constructor. 275136849Sscottl bool UserDeclaredConstructor : 1; 276136849Sscottl 277136849Sscottl /// UserDeclaredCopyConstructor - True when this class has a 278136849Sscottl /// user-declared copy constructor. 279190809Sdelphij bool UserDeclaredCopyConstructor : 1; 280136849Sscottl 281136849Sscottl /// UserDeclareMoveConstructor - True when this class has a 282136849Sscottl /// user-declared move constructor. 283136849Sscottl bool UserDeclaredMoveConstructor : 1; 284136849Sscottl 285136849Sscottl /// UserDeclaredCopyAssignment - True when this class has a 286190809Sdelphij /// user-declared copy assignment operator. 287136849Sscottl bool UserDeclaredCopyAssignment : 1; 288136849Sscottl 289136849Sscottl /// UserDeclareMoveAssignment - True when this class has a 290136849Sscottl /// user-declared move assignment. 291136849Sscottl bool UserDeclaredMoveAssignment : 1; 292190809Sdelphij 293190809Sdelphij /// UserDeclaredDestructor - True when this class has a 294136849Sscottl /// user-declared destructor. 295136849Sscottl bool UserDeclaredDestructor : 1; 296136849Sscottl 297136849Sscottl /// Aggregate - True when this class is an aggregate. 298136849Sscottl bool Aggregate : 1; 299136849Sscottl 300136849Sscottl /// PlainOldData - True when this class is a POD-type. 301190809Sdelphij bool PlainOldData : 1; 302190809Sdelphij 303190809Sdelphij /// Empty - true when this class is empty for traits purposes, 304136849Sscottl /// i.e. has no data members other than 0-width bit-fields, has no 305136849Sscottl /// virtual function/base, and doesn't inherit from a non-empty 306190809Sdelphij /// class. Doesn't take union-ness into account. 307190809Sdelphij bool Empty : 1; 308190809Sdelphij 309136849Sscottl /// Polymorphic - True when this class is polymorphic, i.e. has at 310190809Sdelphij /// least one virtual member or derives from a polymorphic class. 311136849Sscottl bool Polymorphic : 1; 312136849Sscottl 313190809Sdelphij /// Abstract - True when this class is abstract, i.e. has at least 314136849Sscottl /// one pure virtual function, (that can come from a base class). 315190809Sdelphij bool Abstract : 1; 316136849Sscottl 317190809Sdelphij /// IsStandardLayout - True when this class has standard layout. 318136849Sscottl /// 319136849Sscottl /// C++0x [class]p7. A standard-layout class is a class that: 320136849Sscottl /// * has no non-static data members of type non-standard-layout class (or 321190809Sdelphij /// array of such types) or reference, 322136849Sscottl /// * has no virtual functions (10.3) and no virtual base classes (10.1), 323136849Sscottl /// * has the same access control (Clause 11) for all non-static data members 324136849Sscottl /// * has no non-standard-layout base classes, 325190809Sdelphij /// * either has no non-static data members in the most derived class and at 326136849Sscottl /// most one base class with non-static data members, or has no base 327136849Sscottl /// classes with non-static data members, and 328136849Sscottl /// * has no base classes of the same type as the first non-static data 329190809Sdelphij /// member. 330136849Sscottl bool IsStandardLayout : 1; 331190809Sdelphij 332136849Sscottl /// HasNoNonEmptyBases - True when there are no non-empty base classes. 333136849Sscottl /// 334136849Sscottl /// This is a helper bit of state used to implement IsStandardLayout more 335190809Sdelphij /// efficiently. 336136849Sscottl bool HasNoNonEmptyBases : 1; 337190809Sdelphij 338190809Sdelphij /// HasPrivateFields - True when there are private non-static data members. 339136849Sscottl bool HasPrivateFields : 1; 340136849Sscottl 341136849Sscottl /// HasProtectedFields - True when there are protected non-static data 342136849Sscottl /// members. 343190809Sdelphij bool HasProtectedFields : 1; 344190809Sdelphij 345190809Sdelphij /// HasPublicFields - True when there are private non-static data members. 346190809Sdelphij bool HasPublicFields : 1; 347190809Sdelphij 348190809Sdelphij /// \brief True if this class (or any subobject) has mutable fields. 349190809Sdelphij bool HasMutableFields : 1; 350190809Sdelphij 351190809Sdelphij /// HasTrivialDefaultConstructor - True when, if this class has a default 352190809Sdelphij /// constructor, this default constructor is trivial. 353136849Sscottl /// 354136849Sscottl /// C++0x [class.ctor]p5 355136849Sscottl /// A default constructor is trivial if it is not user-provided and if 356149871Sscottl /// -- its class has no virtual functions and no virtual base classes, 357136849Sscottl /// and 358136849Sscottl /// -- no non-static data member of its class has a 359136849Sscottl /// brace-or-equal-initializer, and 360136849Sscottl /// -- all the direct base classes of its class have trivial 361136849Sscottl /// default constructors, and 362136849Sscottl /// -- for all the nonstatic data members of its class that are of class 363136849Sscottl /// type (or array thereof), each such class has a trivial 364136849Sscottl /// default constructor. 365136849Sscottl bool HasTrivialDefaultConstructor : 1; 366136849Sscottl 367136849Sscottl /// HasConstExprNonCopyMoveConstructor - True when this class has at least 368136849Sscottl /// one constexpr constructor which is neither the copy nor move 369136849Sscottl /// constructor. 370136849Sscottl bool HasConstExprNonCopyMoveConstructor : 1; 371136849Sscottl 372136849Sscottl /// HasTrivialCopyConstructor - True when this class has a trivial copy 373136849Sscottl /// constructor. 374136849Sscottl /// 375136849Sscottl /// C++0x [class.copy]p13: 376136849Sscottl /// A copy/move constructor for class X is trivial if it is neither 377136849Sscottl /// user-provided and if 378136849Sscottl /// -- class X has no virtual functions and no virtual base classes, and 379136849Sscottl /// -- the constructor selected to copy/move each direct base class 380136849Sscottl /// subobject is trivial, and 381136849Sscottl /// -- for each non-static data member of X that is of class type (or an 382136849Sscottl /// array thereof), the constructor selected to copy/move that member 383136849Sscottl /// is trivial; 384136849Sscottl /// otherwise the copy/move constructor is non-trivial. 385149871Sscottl bool HasTrivialCopyConstructor : 1; 386136849Sscottl 387136849Sscottl /// HasTrivialMoveConstructor - True when this class has a trivial move 388136849Sscottl /// constructor. 389136849Sscottl /// 390136849Sscottl /// C++0x [class.copy]p13: 391136849Sscottl /// A copy/move constructor for class X is trivial if it is neither 392136849Sscottl /// user-provided and if 393136849Sscottl /// -- class X has no virtual functions and no virtual base classes, and 394136849Sscottl /// -- the constructor selected to copy/move each direct base class 395136849Sscottl /// subobject is trivial, and 396136849Sscottl /// -- for each non-static data member of X that is of class type (or an 397136849Sscottl /// array thereof), the constructor selected to copy/move that member 398136849Sscottl /// is trivial; 399136849Sscottl /// otherwise the copy/move constructor is non-trivial. 400136849Sscottl bool HasTrivialMoveConstructor : 1; 401149871Sscottl 402136849Sscottl /// HasTrivialCopyAssignment - True when this class has a trivial copy 403136849Sscottl /// assignment operator. 404136849Sscottl /// 405136849Sscottl /// C++0x [class.copy]p27: 406136849Sscottl /// A copy/move assignment operator for class X is trivial if it is 407136849Sscottl /// neither user-provided nor deleted and if 408136849Sscottl /// -- class X has no virtual functions and no virtual base classes, and 409136849Sscottl /// -- the assignment operator selected to copy/move each direct base 410136849Sscottl /// class subobject is trivial, and 411136849Sscottl /// -- for each non-static data member of X that is of class type (or an 412136849Sscottl /// array thereof), the assignment operator selected to copy/move 413136849Sscottl /// that member is trivial; 414136849Sscottl /// otherwise the copy/move assignment operator is non-trivial. 415149871Sscottl bool HasTrivialCopyAssignment : 1; 416136849Sscottl 417136849Sscottl /// HasTrivialMoveAssignment - True when this class has a trivial move 418136849Sscottl /// assignment operator. 419136849Sscottl /// 420136849Sscottl /// C++0x [class.copy]p27: 421136849Sscottl /// A copy/move assignment operator for class X is trivial if it is 422136849Sscottl /// neither user-provided nor deleted and if 423136849Sscottl /// -- class X has no virtual functions and no virtual base classes, and 424136849Sscottl /// -- the assignment operator selected to copy/move each direct base 425136849Sscottl /// class subobject is trivial, and 426136849Sscottl /// -- for each non-static data member of X that is of class type (or an 427136849Sscottl /// array thereof), the assignment operator selected to copy/move 428136849Sscottl /// that member is trivial; 429136849Sscottl /// otherwise the copy/move assignment operator is non-trivial. 430136849Sscottl bool HasTrivialMoveAssignment : 1; 431136849Sscottl 432136849Sscottl /// HasTrivialDestructor - True when this class has a trivial destructor. 433149871Sscottl /// 434136849Sscottl /// C++ [class.dtor]p3. A destructor is trivial if it is an 435136849Sscottl /// implicitly-declared destructor and if: 436190809Sdelphij /// * all of the direct base classes of its class have trivial destructors 437136849Sscottl /// and 438136849Sscottl /// * for all of the non-static data members of its class that are of class 439136849Sscottl /// type (or array thereof), each such class has a trivial destructor. 440136849Sscottl bool HasTrivialDestructor : 1; 441136849Sscottl 442136849Sscottl /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least 443136849Sscottl /// one non-static data member or base class of non literal type. 444136849Sscottl bool HasNonLiteralTypeFieldsOrBases : 1; 445136849Sscottl 446149871Sscottl /// ComputedVisibleConversions - True when visible conversion functions are 447136849Sscottl /// already computed and are available. 448136849Sscottl bool ComputedVisibleConversions : 1; 449136849Sscottl 450136849Sscottl /// \brief Whether we have a C++0x user-provided default constructor (not 451136849Sscottl /// explicitly deleted or defaulted). 452136849Sscottl bool UserProvidedDefaultConstructor : 1; 453136849Sscottl 454136849Sscottl /// \brief Whether we have already declared the default constructor. 455136849Sscottl bool DeclaredDefaultConstructor : 1; 456136849Sscottl 457136849Sscottl /// \brief Whether we have already declared the copy constructor. 458136849Sscottl bool DeclaredCopyConstructor : 1; 459136849Sscottl 460136849Sscottl /// \brief Whether we have already declared the move constructor. 461136849Sscottl bool DeclaredMoveConstructor : 1; 462136849Sscottl 463136849Sscottl /// \brief Whether we have already declared the copy-assignment operator. 464136849Sscottl bool DeclaredCopyAssignment : 1; 465136849Sscottl 466136849Sscottl /// \brief Whether we have already declared the move-assignment operator. 467136849Sscottl bool DeclaredMoveAssignment : 1; 468136849Sscottl 469136849Sscottl /// \brief Whether we have already declared a destructor within the class. 470136849Sscottl bool DeclaredDestructor : 1; 471136849Sscottl 472136849Sscottl /// NumBases - The number of base class specifiers in Bases. 473136849Sscottl unsigned NumBases; 474136849Sscottl 475136849Sscottl /// NumVBases - The number of virtual base class specifiers in VBases. 476136849Sscottl unsigned NumVBases; 477136849Sscottl 478136849Sscottl /// Bases - Base classes of this class. 479149871Sscottl /// FIXME: This is wasted space for a union. 480136849Sscottl LazyCXXBaseSpecifiersPtr Bases; 481136849Sscottl 482136849Sscottl /// VBases - direct and indirect virtual base classes of this class. 483136849Sscottl LazyCXXBaseSpecifiersPtr VBases; 484136849Sscottl 485136849Sscottl /// Conversions - Overload set containing the conversion functions 486136849Sscottl /// of this C++ class (but not its inherited conversion 487136849Sscottl /// functions). Each of the entries in this overload set is a 488136849Sscottl /// CXXConversionDecl. 489136849Sscottl UnresolvedSet<4> Conversions; 490136849Sscottl 491136849Sscottl /// VisibleConversions - Overload set containing the conversion 492136849Sscottl /// functions of this C++ class and all those inherited conversion 493136849Sscottl /// functions that are visible in this class. Each of the entries 494136849Sscottl /// in this overload set is a CXXConversionDecl or a 495136849Sscottl /// FunctionTemplateDecl. 496136849Sscottl UnresolvedSet<4> VisibleConversions; 497136849Sscottl 498136849Sscottl /// Definition - The declaration which defines this record. 499136849Sscottl CXXRecordDecl *Definition; 500136849Sscottl 501136849Sscottl /// FirstFriend - The first friend declaration in this class, or 502136849Sscottl /// null if there aren't any. This is actually currently stored 503136849Sscottl /// in reverse order. 504136849Sscottl FriendDecl *FirstFriend; 505136849Sscottl 506136849Sscottl /// \brief Retrieve the set of direct base classes. 507136849Sscottl CXXBaseSpecifier *getBases() const { 508136849Sscottl return Bases.get(Definition->getASTContext().getExternalSource()); 509136849Sscottl } 510136849Sscottl 511136849Sscottl /// \brief Retrieve the set of virtual base classes. 512149871Sscottl CXXBaseSpecifier *getVBases() const { 513136849Sscottl return VBases.get(Definition->getASTContext().getExternalSource()); 514136849Sscottl } 515136849Sscottl } *DefinitionData; 516149871Sscottl 517136849Sscottl struct DefinitionData &data() { 518136849Sscottl assert(DefinitionData && "queried property of class with no definition"); 519136849Sscottl return *DefinitionData; 520190809Sdelphij } 521190809Sdelphij 522190809Sdelphij const struct DefinitionData &data() const { 523190809Sdelphij assert(DefinitionData && "queried property of class with no definition"); 524190809Sdelphij return *DefinitionData; 525190809Sdelphij } 526190809Sdelphij 527136849Sscottl /// \brief The template or declaration that this declaration 528136849Sscottl /// describes or was instantiated from, respectively. 529190809Sdelphij /// 530190809Sdelphij /// For non-templates, this value will be NULL. For record 531190809Sdelphij /// declarations that describe a class template, this will be a 532190809Sdelphij /// pointer to a ClassTemplateDecl. For member 533190809Sdelphij /// classes of class template specializations, this will be the 534190809Sdelphij /// MemberSpecializationInfo referring to the member class that was 535190809Sdelphij /// instantiated or specialized. 536190809Sdelphij llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 537190809Sdelphij TemplateOrInstantiation; 538190809Sdelphij 539190809Sdelphij friend class DeclContext; 540190809Sdelphij 541190809Sdelphij /// \brief Notify the class that member has been added. 542190809Sdelphij /// 543190809Sdelphij /// This routine helps maintain information about the class based on which 544190809Sdelphij /// members have been added. It will be invoked by DeclContext::addDecl() 545190809Sdelphij /// whenever a member is added to this record. 546190809Sdelphij void addedMember(Decl *D); 547190809Sdelphij 548190809Sdelphij void markedVirtualFunctionPure(); 549190809Sdelphij friend void FunctionDecl::setPure(bool); 550136849Sscottl 551136849Sscottlprotected: 552190809Sdelphij CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 553136849Sscottl SourceLocation StartLoc, SourceLocation IdLoc, 554190809Sdelphij IdentifierInfo *Id, CXXRecordDecl *PrevDecl); 555190809Sdelphij 556190809Sdelphijpublic: 557190809Sdelphij /// base_class_iterator - Iterator that traverses the base classes 558190809Sdelphij /// of a class. 559190809Sdelphij typedef CXXBaseSpecifier* base_class_iterator; 560190809Sdelphij 561190809Sdelphij /// base_class_const_iterator - Iterator that traverses the base 562136849Sscottl /// classes of a class. 563190809Sdelphij typedef const CXXBaseSpecifier* base_class_const_iterator; 564136849Sscottl 565136849Sscottl /// reverse_base_class_iterator = Iterator that traverses the base classes 566136849Sscottl /// of a class in reverse order. 567190809Sdelphij typedef std::reverse_iterator<base_class_iterator> 568136849Sscottl reverse_base_class_iterator; 569136849Sscottl 570136849Sscottl /// reverse_base_class_iterator = Iterator that traverses the base classes 571190809Sdelphij /// of a class in reverse order. 572190809Sdelphij typedef std::reverse_iterator<base_class_const_iterator> 573190809Sdelphij reverse_base_class_const_iterator; 574136849Sscottl 575136849Sscottl virtual CXXRecordDecl *getCanonicalDecl() { 576136849Sscottl return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 577136849Sscottl } 578136849Sscottl virtual const CXXRecordDecl *getCanonicalDecl() const { 579136849Sscottl return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 580136849Sscottl } 581136849Sscottl 582136849Sscottl const CXXRecordDecl *getPreviousDeclaration() const { 583136849Sscottl return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 584136849Sscottl } 585190809Sdelphij CXXRecordDecl *getPreviousDeclaration() { 586190809Sdelphij return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 587136849Sscottl } 588136849Sscottl 589136849Sscottl CXXRecordDecl *getDefinition() const { 590136849Sscottl if (!DefinitionData) return 0; 591136849Sscottl return data().Definition; 592136849Sscottl } 593136849Sscottl 594136849Sscottl bool hasDefinition() const { return DefinitionData != 0; } 595136849Sscottl 596136849Sscottl static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 597136849Sscottl SourceLocation StartLoc, SourceLocation IdLoc, 598136849Sscottl IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0, 599136849Sscottl bool DelayTypeCreation = false); 600136849Sscottl static CXXRecordDecl *Create(const ASTContext &C, EmptyShell Empty); 601136849Sscottl 602136849Sscottl bool isDynamicClass() const { 603136849Sscottl return data().Polymorphic || data().NumVBases != 0; 604136849Sscottl } 605136849Sscottl 606136849Sscottl /// setBases - Sets the base classes of this struct or class. 607136849Sscottl void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 608136849Sscottl 609136849Sscottl /// getNumBases - Retrieves the number of base classes of this 610136849Sscottl /// class. 611136849Sscottl unsigned getNumBases() const { return data().NumBases; } 612136849Sscottl 613136849Sscottl base_class_iterator bases_begin() { return data().getBases(); } 614136849Sscottl base_class_const_iterator bases_begin() const { return data().getBases(); } 615136849Sscottl base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 616136849Sscottl base_class_const_iterator bases_end() const { 617136849Sscottl return bases_begin() + data().NumBases; 618136849Sscottl } 619136849Sscottl reverse_base_class_iterator bases_rbegin() { 620136849Sscottl return reverse_base_class_iterator(bases_end()); 621136849Sscottl } 622136849Sscottl reverse_base_class_const_iterator bases_rbegin() const { 623136849Sscottl return reverse_base_class_const_iterator(bases_end()); 624136849Sscottl } 625136849Sscottl reverse_base_class_iterator bases_rend() { 626136849Sscottl return reverse_base_class_iterator(bases_begin()); 627136849Sscottl } 628136849Sscottl reverse_base_class_const_iterator bases_rend() const { 629136849Sscottl return reverse_base_class_const_iterator(bases_begin()); 630136849Sscottl } 631136849Sscottl 632136849Sscottl /// getNumVBases - Retrieves the number of virtual base classes of this 633136849Sscottl /// class. 634136849Sscottl unsigned getNumVBases() const { return data().NumVBases; } 635136849Sscottl 636136849Sscottl base_class_iterator vbases_begin() { return data().getVBases(); } 637136849Sscottl base_class_const_iterator vbases_begin() const { return data().getVBases(); } 638136849Sscottl base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 639136849Sscottl base_class_const_iterator vbases_end() const { 640136849Sscottl return vbases_begin() + data().NumVBases; 641136849Sscottl } 642136849Sscottl reverse_base_class_iterator vbases_rbegin() { 643136849Sscottl return reverse_base_class_iterator(vbases_end()); 644136849Sscottl } 645136849Sscottl reverse_base_class_const_iterator vbases_rbegin() const { 646136849Sscottl return reverse_base_class_const_iterator(vbases_end()); 647136849Sscottl } 648136849Sscottl reverse_base_class_iterator vbases_rend() { 649136849Sscottl return reverse_base_class_iterator(vbases_begin()); 650136849Sscottl } 651136849Sscottl reverse_base_class_const_iterator vbases_rend() const { 652136849Sscottl return reverse_base_class_const_iterator(vbases_begin()); 653136849Sscottl } 654136849Sscottl 655136849Sscottl /// \brief Determine whether this class has any dependent base classes. 656136849Sscottl bool hasAnyDependentBases() const; 657136849Sscottl 658136849Sscottl /// Iterator access to method members. The method iterator visits 659136849Sscottl /// all method members of the class, including non-instance methods, 660136849Sscottl /// special methods, etc. 661136849Sscottl typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 662136849Sscottl 663136849Sscottl /// method_begin - Method begin iterator. Iterates in the order the methods 664136849Sscottl /// were declared. 665136849Sscottl method_iterator method_begin() const { 666136849Sscottl return method_iterator(decls_begin()); 667136849Sscottl } 668136849Sscottl /// method_end - Method end iterator. 669136849Sscottl method_iterator method_end() const { 670136849Sscottl return method_iterator(decls_end()); 671136849Sscottl } 672136849Sscottl 673136849Sscottl /// Iterator access to constructor members. 674136849Sscottl typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 675136849Sscottl 676136849Sscottl ctor_iterator ctor_begin() const { 677136849Sscottl return ctor_iterator(decls_begin()); 678136849Sscottl } 679136849Sscottl ctor_iterator ctor_end() const { 680136849Sscottl return ctor_iterator(decls_end()); 681136849Sscottl } 682136849Sscottl 683136849Sscottl /// An iterator over friend declarations. All of these are defined 684136849Sscottl /// in DeclFriend.h. 685136849Sscottl class friend_iterator; 686136849Sscottl friend_iterator friend_begin() const; 687136849Sscottl friend_iterator friend_end() const; 688136849Sscottl void pushFriendDecl(FriendDecl *FD); 689136849Sscottl 690136849Sscottl /// Determines whether this record has any friends. 691136849Sscottl bool hasFriends() const { 692136849Sscottl return data().FirstFriend != 0; 693136849Sscottl } 694136849Sscottl 695136849Sscottl /// \brief Determine if we need to declare a default constructor for 696136849Sscottl /// this class. 697136849Sscottl /// 698136849Sscottl /// This value is used for lazy creation of default constructors. 699136849Sscottl bool needsImplicitDefaultConstructor() const { 700136849Sscottl return !data().UserDeclaredConstructor && 701136849Sscottl !data().DeclaredDefaultConstructor; 702136849Sscottl } 703136849Sscottl 704136849Sscottl /// hasDeclaredDefaultConstructor - Whether this class's default constructor 705136849Sscottl /// has been declared (either explicitly or implicitly). 706136849Sscottl bool hasDeclaredDefaultConstructor() const { 707136849Sscottl return data().DeclaredDefaultConstructor; 708136849Sscottl } 709136849Sscottl 710136849Sscottl /// hasConstCopyConstructor - Determines whether this class has a 711136849Sscottl /// copy constructor that accepts a const-qualified argument. 712136849Sscottl bool hasConstCopyConstructor() const; 713136849Sscottl 714136849Sscottl /// getCopyConstructor - Returns the copy constructor for this class 715136849Sscottl CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const; 716136849Sscottl 717136849Sscottl /// getMoveConstructor - Returns the move constructor for this class 718136849Sscottl CXXConstructorDecl *getMoveConstructor() const; 719136849Sscottl 720136849Sscottl /// \brief Retrieve the copy-assignment operator for this class, if available. 721136849Sscottl /// 722136849Sscottl /// This routine attempts to find the copy-assignment operator for this 723136849Sscottl /// class, using a simplistic form of overload resolution. 724136849Sscottl /// 725136849Sscottl /// \param ArgIsConst Whether the argument to the copy-assignment operator 726136849Sscottl /// is const-qualified. 727136849Sscottl /// 728136849Sscottl /// \returns The copy-assignment operator that can be invoked, or NULL if 729136849Sscottl /// a unique copy-assignment operator could not be found. 730136849Sscottl CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const; 731136849Sscottl 732136849Sscottl /// getMoveAssignmentOperator - Returns the move assignment operator for this 733136849Sscottl /// class 734136849Sscottl CXXMethodDecl *getMoveAssignmentOperator() const; 735136849Sscottl 736136849Sscottl /// hasUserDeclaredConstructor - Whether this class has any 737136849Sscottl /// user-declared constructors. When true, a default constructor 738136849Sscottl /// will not be implicitly declared. 739136849Sscottl bool hasUserDeclaredConstructor() const { 740136849Sscottl return data().UserDeclaredConstructor; 741136849Sscottl } 742136849Sscottl 743136849Sscottl /// hasUserProvidedDefaultconstructor - Whether this class has a 744136849Sscottl /// user-provided default constructor per C++0x. 745136849Sscottl bool hasUserProvidedDefaultConstructor() const { 746136849Sscottl return data().UserProvidedDefaultConstructor; 747136849Sscottl } 748136849Sscottl 749136849Sscottl /// hasUserDeclaredCopyConstructor - Whether this class has a 750136849Sscottl /// user-declared copy constructor. When false, a copy constructor 751136849Sscottl /// will be implicitly declared. 752136849Sscottl bool hasUserDeclaredCopyConstructor() const { 753136849Sscottl return data().UserDeclaredCopyConstructor; 754136849Sscottl } 755136849Sscottl 756136849Sscottl /// \brief Determine whether this class has had its copy constructor 757136849Sscottl /// declared, either via the user or via an implicit declaration. 758136849Sscottl /// 759136849Sscottl /// This value is used for lazy creation of copy constructors. 760136849Sscottl bool hasDeclaredCopyConstructor() const { 761136849Sscottl return data().DeclaredCopyConstructor; 762136849Sscottl } 763136849Sscottl 764136849Sscottl /// hasUserDeclaredMoveOperation - Whether this class has a user- 765136849Sscottl /// declared move constructor or assignment operator. When false, a 766136849Sscottl /// move constructor and assignment operator may be implicitly declared. 767136849Sscottl bool hasUserDeclaredMoveOperation() const { 768136849Sscottl return data().UserDeclaredMoveConstructor || 769136849Sscottl data().UserDeclaredMoveAssignment; 770136849Sscottl } 771136849Sscottl 772136849Sscottl /// \brief Determine whether this class has had a move constructor 773136849Sscottl /// declared by the user. 774136849Sscottl bool hasUserDeclaredMoveConstructor() const { 775136849Sscottl return data().UserDeclaredMoveConstructor; 776136849Sscottl } 777136849Sscottl 778136849Sscottl /// \brief Determine whether this class has had a move constructor 779136849Sscottl /// declared. 780136849Sscottl bool hasDeclaredMoveConstructor() const { 781136849Sscottl return data().DeclaredMoveConstructor; 782136849Sscottl } 783136849Sscottl 784136849Sscottl /// hasUserDeclaredCopyAssignment - Whether this class has a 785136849Sscottl /// user-declared copy assignment operator. When false, a copy 786136849Sscottl /// assigment operator will be implicitly declared. 787136849Sscottl bool hasUserDeclaredCopyAssignment() const { 788136849Sscottl return data().UserDeclaredCopyAssignment; 789136849Sscottl } 790136849Sscottl 791136849Sscottl /// \brief Determine whether this class has had its copy assignment operator 792136849Sscottl /// declared, either via the user or via an implicit declaration. 793136849Sscottl /// 794136849Sscottl /// This value is used for lazy creation of copy assignment operators. 795136849Sscottl bool hasDeclaredCopyAssignment() const { 796136849Sscottl return data().DeclaredCopyAssignment; 797136849Sscottl } 798136849Sscottl 799136849Sscottl /// \brief Determine whether this class has had a move assignment 800136849Sscottl /// declared by the user. 801136849Sscottl bool hasUserDeclaredMoveAssignment() const { 802136849Sscottl return data().UserDeclaredMoveAssignment; 803136849Sscottl } 804136849Sscottl 805136849Sscottl /// hasDeclaredMoveAssignment - Whether this class has a 806136849Sscottl /// declared move assignment operator. 807136849Sscottl bool hasDeclaredMoveAssignment() const { 808136849Sscottl return data().DeclaredMoveAssignment; 809136849Sscottl } 810136849Sscottl 811136849Sscottl /// hasUserDeclaredDestructor - Whether this class has a 812136849Sscottl /// user-declared destructor. When false, a destructor will be 813190809Sdelphij /// implicitly declared. 814190809Sdelphij bool hasUserDeclaredDestructor() const { 815190809Sdelphij return data().UserDeclaredDestructor; 816190809Sdelphij } 817190809Sdelphij 818190809Sdelphij /// \brief Determine whether this class has had its destructor declared, 819190809Sdelphij /// either via the user or via an implicit declaration. 820190809Sdelphij /// 821190809Sdelphij /// This value is used for lazy creation of destructors. 822190809Sdelphij bool hasDeclaredDestructor() const { return data().DeclaredDestructor; } 823190809Sdelphij 824190809Sdelphij /// getConversions - Retrieve the overload set containing all of the 825190809Sdelphij /// conversion functions in this class. 826190809Sdelphij UnresolvedSetImpl *getConversionFunctions() { 827190809Sdelphij return &data().Conversions; 828190809Sdelphij } 829136849Sscottl const UnresolvedSetImpl *getConversionFunctions() const { 830136849Sscottl return &data().Conversions; 831136849Sscottl } 832136849Sscottl 833136849Sscottl typedef UnresolvedSetImpl::iterator conversion_iterator; 834136849Sscottl conversion_iterator conversion_begin() const { 835136849Sscottl return getConversionFunctions()->begin(); 836136849Sscottl } 837136849Sscottl conversion_iterator conversion_end() const { 838136849Sscottl return getConversionFunctions()->end(); 839136849Sscottl } 840136849Sscottl 841136849Sscottl /// Removes a conversion function from this class. The conversion 842136849Sscottl /// function must currently be a member of this class. Furthermore, 843136849Sscottl /// this class must currently be in the process of being defined. 844136849Sscottl void removeConversion(const NamedDecl *Old); 845136849Sscottl 846136849Sscottl /// getVisibleConversionFunctions - get all conversion functions visible 847136849Sscottl /// in current class; including conversion function templates. 848136849Sscottl const UnresolvedSetImpl *getVisibleConversionFunctions(); 849136849Sscottl 850136849Sscottl /// isAggregate - Whether this class is an aggregate (C++ 851136849Sscottl /// [dcl.init.aggr]), which is a class with no user-declared 852136849Sscottl /// constructors, no private or protected non-static data members, 853136849Sscottl /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 854136849Sscottl bool isAggregate() const { return data().Aggregate; } 855136849Sscottl 856136849Sscottl /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 857136849Sscottl /// that is an aggregate that has no non-static non-POD data members, no 858136849Sscottl /// reference data members, no user-defined copy assignment operator and no 859136849Sscottl /// user-defined destructor. 860136849Sscottl bool isPOD() const { return data().PlainOldData; } 861136849Sscottl 862136849Sscottl /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 863136849Sscottl /// means it has a virtual function, virtual base, data member (other than 864136849Sscottl /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 865136849Sscottl /// a check for union-ness. 866136849Sscottl bool isEmpty() const { return data().Empty; } 867136849Sscottl 868136849Sscottl /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 869136849Sscottl /// which means that the class contains or inherits a virtual function. 870136849Sscottl bool isPolymorphic() const { return data().Polymorphic; } 871136849Sscottl 872136849Sscottl /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 873136849Sscottl /// which means that the class contains or inherits a pure virtual function. 874136849Sscottl bool isAbstract() const { return data().Abstract; } 875136849Sscottl 876136849Sscottl /// isStandardLayout - Whether this class has standard layout 877136849Sscottl /// (C++ [class]p7) 878136849Sscottl bool isStandardLayout() const { return data().IsStandardLayout; } 879136849Sscottl 880136849Sscottl /// \brief Whether this class, or any of its class subobjects, contains a 881136849Sscottl /// mutable field. 882136849Sscottl bool hasMutableFields() const { return data().HasMutableFields; } 883136849Sscottl 884136849Sscottl // hasTrivialDefaultConstructor - Whether this class has a trivial default 885136849Sscottl // constructor 886136849Sscottl // (C++0x [class.ctor]p5) 887136849Sscottl bool hasTrivialDefaultConstructor() const { 888136849Sscottl return data().HasTrivialDefaultConstructor && 889136849Sscottl (!data().UserDeclaredConstructor || 890136849Sscottl data().DeclaredDefaultConstructor); 891136849Sscottl } 892136849Sscottl 893136849Sscottl // hasConstExprNonCopyMoveConstructor - Whether this class has at least one 894136849Sscottl // constexpr constructor other than the copy or move constructors 895136849Sscottl bool hasConstExprNonCopyMoveConstructor() const { 896136849Sscottl return data().HasConstExprNonCopyMoveConstructor; 897136849Sscottl } 898136849Sscottl 899136849Sscottl // hasTrivialCopyConstructor - Whether this class has a trivial copy 900136849Sscottl // constructor (C++ [class.copy]p6, C++0x [class.copy]p13) 901136849Sscottl bool hasTrivialCopyConstructor() const { 902136849Sscottl return data().HasTrivialCopyConstructor; 903136849Sscottl } 904136849Sscottl 905136849Sscottl // hasTrivialMoveConstructor - Whether this class has a trivial move 906136849Sscottl // constructor (C++0x [class.copy]p13) 907136849Sscottl bool hasTrivialMoveConstructor() const { 908136849Sscottl return data().HasTrivialMoveConstructor; 909190809Sdelphij } 910136849Sscottl 911136849Sscottl // hasTrivialCopyAssignment - Whether this class has a trivial copy 912136849Sscottl // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27) 913149871Sscottl bool hasTrivialCopyAssignment() const { 914136849Sscottl return data().HasTrivialCopyAssignment; 915136849Sscottl } 916136849Sscottl 917136849Sscottl // hasTrivialMoveAssignment - Whether this class has a trivial move 918136849Sscottl // assignment operator (C++0x [class.copy]p27) 919136849Sscottl bool hasTrivialMoveAssignment() const { 920136849Sscottl return data().HasTrivialMoveAssignment; 921136849Sscottl } 922136849Sscottl 923136849Sscottl // hasTrivialDestructor - Whether this class has a trivial destructor 924136849Sscottl // (C++ [class.dtor]p3) 925136849Sscottl bool hasTrivialDestructor() const { return data().HasTrivialDestructor; } 926136849Sscottl 927136849Sscottl // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal type 928136849Sscottl // non-static data member or base class. 929136849Sscottl bool hasNonLiteralTypeFieldsOrBases() const { 930136849Sscottl return data().HasNonLiteralTypeFieldsOrBases; 931136849Sscottl } 932136849Sscottl 933136849Sscottl // isTriviallyCopyable - Whether this class is considered trivially copyable 934136849Sscottl // (C++0x [class]p6). 935136849Sscottl bool isTriviallyCopyable() const; 936136849Sscottl 937136849Sscottl // isTrivial - Whether this class is considered trivial 938136849Sscottl // 939136849Sscottl // C++0x [class]p6 940136849Sscottl // A trivial class is a class that has a trivial default constructor and 941136849Sscottl // is trivially copiable. 942136849Sscottl bool isTrivial() const { 943136849Sscottl return isTriviallyCopyable() && hasTrivialDefaultConstructor(); 944136849Sscottl } 945136849Sscottl 946190809Sdelphij /// \brief If this record is an instantiation of a member class, 947136849Sscottl /// retrieves the member class from which it was instantiated. 948136849Sscottl /// 949136849Sscottl /// This routine will return non-NULL for (non-templated) member 950136849Sscottl /// classes of class templates. For example, given: 951136849Sscottl /// 952136849Sscottl /// \code 953136849Sscottl /// template<typename T> 954136849Sscottl /// struct X { 955136849Sscottl /// struct A { }; 956136849Sscottl /// }; 957136849Sscottl /// \endcode 958136849Sscottl /// 959136849Sscottl /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 960136849Sscottl /// whose parent is the class template specialization X<int>. For 961136849Sscottl /// this declaration, getInstantiatedFromMemberClass() will return 962136849Sscottl /// the CXXRecordDecl X<T>::A. When a complete definition of 963136849Sscottl /// X<int>::A is required, it will be instantiated from the 964136849Sscottl /// declaration returned by getInstantiatedFromMemberClass(). 965136849Sscottl CXXRecordDecl *getInstantiatedFromMemberClass() const; 966136849Sscottl 967136849Sscottl /// \brief If this class is an instantiation of a member class of a 968136849Sscottl /// class template specialization, retrieves the member specialization 969136849Sscottl /// information. 970136849Sscottl MemberSpecializationInfo *getMemberSpecializationInfo() const; 971136849Sscottl 972136849Sscottl /// \brief Specify that this record is an instantiation of the 973136849Sscottl /// member class RD. 974136849Sscottl void setInstantiationOfMemberClass(CXXRecordDecl *RD, 975136849Sscottl TemplateSpecializationKind TSK); 976136849Sscottl 977136849Sscottl /// \brief Retrieves the class template that is described by this 978136849Sscottl /// class declaration. 979136849Sscottl /// 980136849Sscottl /// Every class template is represented as a ClassTemplateDecl and a 981136849Sscottl /// CXXRecordDecl. The former contains template properties (such as 982136849Sscottl /// the template parameter lists) while the latter contains the 983136849Sscottl /// actual description of the template's 984149871Sscottl /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 985136849Sscottl /// CXXRecordDecl that from a ClassTemplateDecl, while 986136849Sscottl /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 987136849Sscottl /// a CXXRecordDecl. 988136849Sscottl ClassTemplateDecl *getDescribedClassTemplate() const { 989149871Sscottl return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 990136849Sscottl } 991136849Sscottl 992136849Sscottl void setDescribedClassTemplate(ClassTemplateDecl *Template) { 993136849Sscottl TemplateOrInstantiation = Template; 994136849Sscottl } 995136849Sscottl 996136849Sscottl /// \brief Determine whether this particular class is a specialization or 997136849Sscottl /// instantiation of a class template or member class of a class template, 998136849Sscottl /// and how it was instantiated or specialized. 999136849Sscottl TemplateSpecializationKind getTemplateSpecializationKind() const; 1000136849Sscottl 1001136849Sscottl /// \brief Set the kind of specialization or template instantiation this is. 1002136849Sscottl void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 1003136849Sscottl 1004136849Sscottl /// getDestructor - Returns the destructor decl for this class. 1005149871Sscottl CXXDestructorDecl *getDestructor() const; 1006136849Sscottl 1007136849Sscottl /// isLocalClass - If the class is a local class [class.local], returns 1008136849Sscottl /// the enclosing function declaration. 1009136849Sscottl const FunctionDecl *isLocalClass() const { 1010136849Sscottl if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 1011136849Sscottl return RD->isLocalClass(); 1012136849Sscottl 1013136849Sscottl return dyn_cast<FunctionDecl>(getDeclContext()); 1014136849Sscottl } 1015136849Sscottl 1016136849Sscottl /// \brief Determine whether this class is derived from the class \p Base. 1017136849Sscottl /// 1018136849Sscottl /// This routine only determines whether this class is derived from \p Base, 1019136849Sscottl /// but does not account for factors that may make a Derived -> Base class 1020149871Sscottl /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1021136849Sscottl /// base class subobjects. 1022136849Sscottl /// 1023136849Sscottl /// \param Base the base class we are searching for. 1024149871Sscottl /// 1025136849Sscottl /// \returns true if this class is derived from Base, false otherwise. 1026136849Sscottl bool isDerivedFrom(const CXXRecordDecl *Base) const; 1027136849Sscottl 1028136849Sscottl /// \brief Determine whether this class is derived from the type \p Base. 1029136849Sscottl /// 1030136849Sscottl /// This routine only determines whether this class is derived from \p Base, 1031136849Sscottl /// but does not account for factors that may make a Derived -> Base class 1032136849Sscottl /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1033136849Sscottl /// base class subobjects. 1034136849Sscottl /// 1035136849Sscottl /// \param Base the base class we are searching for. 1036136849Sscottl /// 1037136849Sscottl /// \param Paths will contain the paths taken from the current class to the 1038136849Sscottl /// given \p Base class. 1039136849Sscottl /// 1040136849Sscottl /// \returns true if this class is derived from Base, false otherwise. 1041136849Sscottl /// 1042136849Sscottl /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 1043136849Sscottl /// tangling input and output in \p Paths 1044136849Sscottl bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; 1045136849Sscottl 1046136849Sscottl /// \brief Determine whether this class is virtually derived from 1047136849Sscottl /// the class \p Base. 1048190809Sdelphij /// 1049136849Sscottl /// This routine only determines whether this class is virtually 1050136849Sscottl /// derived from \p Base, but does not account for factors that may 1051136849Sscottl /// make a Derived -> Base class ill-formed, such as 1052190809Sdelphij /// private/protected inheritance or multiple, ambiguous base class 1053190809Sdelphij /// subobjects. 1054190809Sdelphij /// 1055190809Sdelphij /// \param Base the base class we are searching for. 1056190809Sdelphij /// 1057190809Sdelphij /// \returns true if this class is virtually derived from Base, 1058190809Sdelphij /// false otherwise. 1059136849Sscottl bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; 1060136849Sscottl 1061136849Sscottl /// \brief Determine whether this class is provably not derived from 1062190809Sdelphij /// the type \p Base. 1063190809Sdelphij bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 1064190809Sdelphij 1065190809Sdelphij /// \brief Function type used by forallBases() as a callback. 1066190809Sdelphij /// 1067190809Sdelphij /// \param Base the definition of the base class 1068136849Sscottl /// 1069136849Sscottl /// \returns true if this base matched the search criteria 1070136849Sscottl typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 1071136849Sscottl void *UserData); 1072136849Sscottl 1073190809Sdelphij /// \brief Determines if the given callback holds for all the direct 1074136849Sscottl /// or indirect base classes of this type. 1075136849Sscottl /// 1076136849Sscottl /// The class itself does not count as a base class. This routine 1077136849Sscottl /// returns false if the class has non-computable base classes. 1078190809Sdelphij /// 1079136849Sscottl /// \param AllowShortCircuit if false, forces the callback to be called 1080136849Sscottl /// for every base class, even if a dependent or non-matching base was 1081190809Sdelphij /// found. 1082190809Sdelphij bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 1083190809Sdelphij bool AllowShortCircuit = true) const; 1084190809Sdelphij 1085190809Sdelphij /// \brief Function type used by lookupInBases() to determine whether a 1086136849Sscottl /// specific base class subobject matches the lookup criteria. 1087136849Sscottl /// 1088136849Sscottl /// \param Specifier the base-class specifier that describes the inheritance 1089190809Sdelphij /// from the base class we are trying to match. 1090190809Sdelphij /// 1091190809Sdelphij /// \param Path the current path, from the most-derived class down to the 1092190809Sdelphij /// base named by the \p Specifier. 1093190809Sdelphij /// 1094136849Sscottl /// \param UserData a single pointer to user-specified data, provided to 1095136849Sscottl /// lookupInBases(). 1096136849Sscottl /// 1097190809Sdelphij /// \returns true if this base matched the search criteria, false otherwise. 1098190809Sdelphij typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 1099190809Sdelphij CXXBasePath &Path, 1100190809Sdelphij void *UserData); 1101190809Sdelphij 1102136849Sscottl /// \brief Look for entities within the base classes of this C++ class, 1103136849Sscottl /// transitively searching all base class subobjects. 1104136849Sscottl /// 1105190809Sdelphij /// This routine uses the callback function \p BaseMatches to find base 1106190809Sdelphij /// classes meeting some search criteria, walking all base class subobjects 1107190809Sdelphij /// and populating the given \p Paths structure with the paths through the 1108190809Sdelphij /// inheritance hierarchy that resulted in a match. On a successful search, 1109190809Sdelphij /// the \p Paths structure can be queried to retrieve the matching paths and 1110190809Sdelphij /// to determine if there were any ambiguities. 1111190809Sdelphij /// 1112136849Sscottl /// \param BaseMatches callback function used to determine whether a given 1113190809Sdelphij /// base matches the user-defined search criteria. 1114190809Sdelphij /// 1115136849Sscottl /// \param UserData user data pointer that will be provided to \p BaseMatches. 1116136849Sscottl /// 1117190809Sdelphij /// \param Paths used to record the paths from this class to its base class 1118136849Sscottl /// subobjects that match the search criteria. 1119136849Sscottl /// 1120136849Sscottl /// \returns true if there exists any path from this class to a base class 1121136849Sscottl /// subobject that matches the search criteria. 1122136849Sscottl bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 1123136849Sscottl CXXBasePaths &Paths) const; 1124136849Sscottl 1125136849Sscottl /// \brief Base-class lookup callback that determines whether the given 1126136849Sscottl /// base class specifier refers to a specific class declaration. 1127136849Sscottl /// 1128136849Sscottl /// This callback can be used with \c lookupInBases() to determine whether 1129136849Sscottl /// a given derived class has is a base class subobject of a particular type. 1130136849Sscottl /// The user data pointer should refer to the canonical CXXRecordDecl of the 1131136849Sscottl /// base class that we are searching for. 1132136849Sscottl static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 1133136849Sscottl CXXBasePath &Path, void *BaseRecord); 1134136849Sscottl 1135136849Sscottl /// \brief Base-class lookup callback that determines whether the 1136136849Sscottl /// given base class specifier refers to a specific class 1137136849Sscottl /// declaration and describes virtual derivation. 1138136849Sscottl /// 1139136849Sscottl /// This callback can be used with \c lookupInBases() to determine 1140136849Sscottl /// whether a given derived class has is a virtual base class 1141136849Sscottl /// subobject of a particular type. The user data pointer should 1142136849Sscottl /// refer to the canonical CXXRecordDecl of the base class that we 1143136849Sscottl /// are searching for. 1144136849Sscottl static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 1145136849Sscottl CXXBasePath &Path, void *BaseRecord); 1146136849Sscottl 1147136849Sscottl /// \brief Base-class lookup callback that determines whether there exists 1148136849Sscottl /// a tag with the given name. 1149136849Sscottl /// 1150136849Sscottl /// This callback can be used with \c lookupInBases() to find tag members 1151136849Sscottl /// of the given name within a C++ class hierarchy. The user data pointer 1152136849Sscottl /// is an opaque \c DeclarationName pointer. 1153136849Sscottl static bool FindTagMember(const CXXBaseSpecifier *Specifier, 1154136849Sscottl CXXBasePath &Path, void *Name); 1155136849Sscottl 1156136849Sscottl /// \brief Base-class lookup callback that determines whether there exists 1157136849Sscottl /// a member with the given name. 1158136849Sscottl /// 1159136849Sscottl /// This callback can be used with \c lookupInBases() to find members 1160136849Sscottl /// of the given name within a C++ class hierarchy. The user data pointer 1161136849Sscottl /// is an opaque \c DeclarationName pointer. 1162136849Sscottl static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 1163136849Sscottl CXXBasePath &Path, void *Name); 1164136849Sscottl 1165136849Sscottl /// \brief Base-class lookup callback that determines whether there exists 1166136849Sscottl /// a member with the given name that can be used in a nested-name-specifier. 1167136849Sscottl /// 1168136849Sscottl /// This callback can be used with \c lookupInBases() to find membes of 1169136849Sscottl /// the given name within a C++ class hierarchy that can occur within 1170136849Sscottl /// nested-name-specifiers. 1171136849Sscottl static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 1172136849Sscottl CXXBasePath &Path, 1173136849Sscottl void *UserData); 1174136849Sscottl 1175136849Sscottl /// \brief Retrieve the final overriders for each virtual member 1176136849Sscottl /// function in the class hierarchy where this class is the 1177136849Sscottl /// most-derived class in the class hierarchy. 1178136849Sscottl void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 1179136849Sscottl 1180136849Sscottl /// \brief Get the indirect primary bases for this class. 1181136849Sscottl void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; 1182136849Sscottl 1183136849Sscottl /// viewInheritance - Renders and displays an inheritance diagram 1184136849Sscottl /// for this C++ class and all of its base classes (transitively) using 1185136849Sscottl /// GraphViz. 1186136849Sscottl void viewInheritance(ASTContext& Context) const; 1187136849Sscottl 1188136849Sscottl /// MergeAccess - Calculates the access of a decl that is reached 1189136849Sscottl /// along a path. 1190136849Sscottl static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 1191136849Sscottl AccessSpecifier DeclAccess) { 1192136849Sscottl assert(DeclAccess != AS_none); 1193136849Sscottl if (DeclAccess == AS_private) return AS_none; 1194136849Sscottl return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 1195136849Sscottl } 1196136849Sscottl 1197136849Sscottl /// \brief Indicates that the definition of this class is now complete. 1198136849Sscottl virtual void completeDefinition(); 1199136849Sscottl 1200136849Sscottl /// \brief Indicates that the definition of this class is now complete, 1201136849Sscottl /// and provides a final overrider map to help determine 1202136849Sscottl /// 1203136849Sscottl /// \param FinalOverriders The final overrider map for this class, which can 1204136849Sscottl /// be provided as an optimization for abstract-class checking. If NULL, 1205136849Sscottl /// final overriders will be computed if they are needed to complete the 1206136849Sscottl /// definition. 1207136849Sscottl void completeDefinition(CXXFinalOverriderMap *FinalOverriders); 1208136849Sscottl 1209136849Sscottl /// \brief Determine whether this class may end up being abstract, even though 1210136849Sscottl /// it is not yet known to be abstract. 1211136849Sscottl /// 1212136849Sscottl /// \returns true if this class is not known to be abstract but has any 1213136849Sscottl /// base classes that are abstract. In this case, \c completeDefinition() 1214190809Sdelphij /// will need to compute final overriders to determine whether the class is 1215190809Sdelphij /// actually abstract. 1216190809Sdelphij bool mayBeAbstract() const; 1217190809Sdelphij 1218190809Sdelphij static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1219190809Sdelphij static bool classofKind(Kind K) { 1220190809Sdelphij return K >= firstCXXRecord && K <= lastCXXRecord; 1221190809Sdelphij } 1222190809Sdelphij static bool classof(const CXXRecordDecl *D) { return true; } 1223190809Sdelphij static bool classof(const ClassTemplateSpecializationDecl *D) { 1224190809Sdelphij return true; 1225190809Sdelphij } 1226190809Sdelphij 1227190809Sdelphij friend class ASTDeclReader; 1228190809Sdelphij friend class ASTDeclWriter; 1229190809Sdelphij friend class ASTReader; 1230190809Sdelphij friend class ASTWriter; 1231190809Sdelphij}; 1232190809Sdelphij 1233136849Sscottl/// CXXMethodDecl - Represents a static or instance method of a 1234136849Sscottl/// struct/union/class. 1235136849Sscottlclass CXXMethodDecl : public FunctionDecl { 1236136849Sscottlprotected: 1237136849Sscottl CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc, 1238136849Sscottl const DeclarationNameInfo &NameInfo, 1239190809Sdelphij QualType T, TypeSourceInfo *TInfo, 1240136849Sscottl bool isStatic, StorageClass SCAsWritten, bool isInline, 1241190809Sdelphij SourceLocation EndLocation) 1242190809Sdelphij : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo, 1243190809Sdelphij (isStatic ? SC_Static : SC_None), 1244190809Sdelphij SCAsWritten, isInline) { 1245136849Sscottl if (EndLocation.isValid()) 1246190809Sdelphij setRangeEnd(EndLocation); 1247190809Sdelphij } 1248190809Sdelphij 1249190809Sdelphijpublic: 1250190809Sdelphij static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1251190809Sdelphij SourceLocation StartLoc, 1252190809Sdelphij const DeclarationNameInfo &NameInfo, 1253190809Sdelphij QualType T, TypeSourceInfo *TInfo, 1254136849Sscottl bool isStatic, 1255136849Sscottl StorageClass SCAsWritten, 1256136849Sscottl bool isInline, 1257136849Sscottl SourceLocation EndLocation); 1258136849Sscottl 1259136849Sscottl bool isStatic() const { return getStorageClass() == SC_Static; } 1260136849Sscottl bool isInstance() const { return !isStatic(); } 1261136849Sscottl 1262136849Sscottl bool isVirtual() const { 1263136849Sscottl CXXMethodDecl *CD = 1264136849Sscottl cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 1265136849Sscottl 1266136849Sscottl if (CD->isVirtualAsWritten()) 1267136849Sscottl return true; 1268136849Sscottl 1269136849Sscottl return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 1270136849Sscottl } 1271136849Sscottl 1272136849Sscottl /// \brief Determine whether this is a usual deallocation function 1273136849Sscottl /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 1274136849Sscottl /// delete or delete[] operator with a particular signature. 1275136849Sscottl bool isUsualDeallocationFunction() const; 1276136849Sscottl 1277136849Sscottl /// \brief Determine whether this is a copy-assignment operator, regardless 1278136849Sscottl /// of whether it was declared implicitly or explicitly. 1279136849Sscottl bool isCopyAssignmentOperator() const; 1280136849Sscottl 1281136849Sscottl /// \brief Determine whether this is a move assignment operator. 1282136849Sscottl bool isMoveAssignmentOperator() const; 1283136849Sscottl 1284136849Sscottl const CXXMethodDecl *getCanonicalDecl() const { 1285136849Sscottl return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1286136849Sscottl } 1287136849Sscottl CXXMethodDecl *getCanonicalDecl() { 1288136849Sscottl return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1289190809Sdelphij } 1290190809Sdelphij 1291190809Sdelphij /// isUserProvided - True if it is either an implicit constructor or 1292190809Sdelphij /// if it was defaulted or deleted on first declaration. 1293190809Sdelphij bool isUserProvided() const { 1294190809Sdelphij return !(isDeleted() || getCanonicalDecl()->isDefaulted()); 1295190809Sdelphij } 1296190809Sdelphij 1297190809Sdelphij /// 1298190809Sdelphij void addOverriddenMethod(const CXXMethodDecl *MD); 1299190809Sdelphij 1300190809Sdelphij typedef const CXXMethodDecl ** method_iterator; 1301190809Sdelphij 1302190809Sdelphij method_iterator begin_overridden_methods() const; 1303190809Sdelphij method_iterator end_overridden_methods() const; 1304136849Sscottl unsigned size_overridden_methods() const; 1305136849Sscottl 1306136849Sscottl /// getParent - Returns the parent of this method declaration, which 1307136849Sscottl /// is the class in which this method is defined. 1308136849Sscottl const CXXRecordDecl *getParent() const { 1309136849Sscottl return cast<CXXRecordDecl>(FunctionDecl::getParent()); 1310136849Sscottl } 1311136849Sscottl 1312136849Sscottl /// getParent - Returns the parent of this method declaration, which 1313136849Sscottl /// is the class in which this method is defined. 1314136849Sscottl CXXRecordDecl *getParent() { 1315136849Sscottl return const_cast<CXXRecordDecl *>( 1316136849Sscottl cast<CXXRecordDecl>(FunctionDecl::getParent())); 1317190809Sdelphij } 1318136849Sscottl 1319136849Sscottl /// getThisType - Returns the type of 'this' pointer. 1320136849Sscottl /// Should only be called for instance methods. 1321136849Sscottl QualType getThisType(ASTContext &C) const; 1322136849Sscottl 1323136849Sscottl unsigned getTypeQualifiers() const { 1324136849Sscottl return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 1325136849Sscottl } 1326136849Sscottl 1327136849Sscottl /// \brief Retrieve the ref-qualifier associated with this method. 1328136849Sscottl /// 1329136849Sscottl /// In the following example, \c f() has an lvalue ref-qualifier, \c g() 1330136849Sscottl /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. 1331136849Sscottl /// \code 1332136849Sscottl /// struct X { 1333136849Sscottl /// void f() &; 1334136849Sscottl /// void g() &&; 1335136849Sscottl /// void h(); 1336136849Sscottl /// }; 1337136849Sscottl RefQualifierKind getRefQualifier() const { 1338136849Sscottl return getType()->getAs<FunctionProtoType>()->getRefQualifier(); 1339136849Sscottl } 1340136849Sscottl 1341136849Sscottl bool hasInlineBody() const; 1342136849Sscottl 1343136849Sscottl // Implement isa/cast/dyncast/etc. 1344136849Sscottl static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1345136849Sscottl static bool classof(const CXXMethodDecl *D) { return true; } 1346136849Sscottl static bool classofKind(Kind K) { 1347136849Sscottl return K >= firstCXXMethod && K <= lastCXXMethod; 1348136849Sscottl } 1349136849Sscottl}; 1350136849Sscottl 1351136849Sscottl/// CXXCtorInitializer - Represents a C++ base or member 1352136849Sscottl/// initializer, which is part of a constructor initializer that 1353136849Sscottl/// initializes one non-static member variable or one base class. For 1354136849Sscottl/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 1355136849Sscottl/// initializers: 1356136849Sscottl/// 1357136849Sscottl/// @code 1358136849Sscottl/// class A { }; 1359136849Sscottl/// class B : public A { 1360136849Sscottl/// float f; 1361136849Sscottl/// public: 1362136849Sscottl/// B(A& a) : A(a), f(3.14159) { } 1363136849Sscottl/// }; 1364136849Sscottl/// @endcode 1365136849Sscottlclass CXXCtorInitializer { 1366136849Sscottl /// \brief Either the base class name (stored as a TypeSourceInfo*), an normal 1367136849Sscottl /// field (FieldDecl), anonymous field (IndirectFieldDecl*), or target 1368136849Sscottl /// constructor (CXXConstructorDecl*) being initialized. 1369136849Sscottl llvm::PointerUnion4<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *, 1370136849Sscottl CXXConstructorDecl *> 1371136849Sscottl Initializee; 1372136849Sscottl 1373136849Sscottl /// \brief The source location for the field name or, for a base initializer 1374136849Sscottl /// pack expansion, the location of the ellipsis. In the case of a delegating 1375136849Sscottl /// constructor, it will still include the type's source location as the 1376136849Sscottl /// Initializee points to the CXXConstructorDecl (to allow loop detection). 1377136849Sscottl SourceLocation MemberOrEllipsisLocation; 1378136849Sscottl 1379136849Sscottl /// \brief The argument used to initialize the base or member, which may 1380136849Sscottl /// end up constructing an object (when multiple arguments are involved). 1381136849Sscottl /// If 0, this is a field initializer, and the in-class member initializer 1382136849Sscottl /// will be used. 1383136849Sscottl Stmt *Init; 1384136849Sscottl 1385136849Sscottl /// LParenLoc - Location of the left paren of the ctor-initializer. 1386136849Sscottl SourceLocation LParenLoc; 1387136849Sscottl 1388136849Sscottl /// RParenLoc - Location of the right paren of the ctor-initializer. 1389190809Sdelphij SourceLocation RParenLoc; 1390136849Sscottl 1391190809Sdelphij /// IsVirtual - If the initializer is a base initializer, this keeps track 1392190809Sdelphij /// of whether the base is virtual or not. 1393190809Sdelphij bool IsVirtual : 1; 1394136849Sscottl 1395190809Sdelphij /// IsWritten - Whether or not the initializer is explicitly written 1396190809Sdelphij /// in the sources. 1397190809Sdelphij bool IsWritten : 1; 1398190809Sdelphij 1399190809Sdelphij /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this 1400136849Sscottl /// number keeps track of the textual order of this initializer in the 1401190809Sdelphij /// original sources, counting from 0; otherwise, if IsWritten is false, 1402190809Sdelphij /// it stores the number of array index variables stored after this 1403190809Sdelphij /// object in memory. 1404190809Sdelphij unsigned SourceOrderOrNumArrayIndices : 14; 1405190809Sdelphij 1406190809Sdelphij CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1407136849Sscottl SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1408136849Sscottl SourceLocation R, VarDecl **Indices, unsigned NumIndices); 1409190809Sdelphij 1410136849Sscottlpublic: 1411190809Sdelphij /// CXXCtorInitializer - Creates a new base-class initializer. 1412190809Sdelphij explicit 1413190809Sdelphij CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, 1414190809Sdelphij SourceLocation L, Expr *Init, SourceLocation R, 1415190809Sdelphij SourceLocation EllipsisLoc); 1416190809Sdelphij 1417136849Sscottl /// CXXCtorInitializer - Creates a new member initializer. 1418190809Sdelphij explicit 1419190809Sdelphij CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1420190809Sdelphij SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1421190809Sdelphij SourceLocation R); 1422190809Sdelphij 1423190809Sdelphij /// CXXCtorInitializer - Creates a new anonymous field initializer. 1424190809Sdelphij explicit 1425190809Sdelphij CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, 1426190809Sdelphij SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1427190809Sdelphij SourceLocation R); 1428136849Sscottl 1429190809Sdelphij /// CXXCtorInitializer - Creates a new delegating Initializer. 1430190809Sdelphij explicit 1431190809Sdelphij CXXCtorInitializer(ASTContext &Context, SourceLocation D, SourceLocation L, 1432190809Sdelphij CXXConstructorDecl *Target, Expr *Init, SourceLocation R); 1433190809Sdelphij 1434190809Sdelphij /// \brief Creates a new member initializer that optionally contains 1435190809Sdelphij /// array indices used to describe an elementwise initialization. 1436190809Sdelphij static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member, 1437136849Sscottl SourceLocation MemberLoc, SourceLocation L, 1438136849Sscottl Expr *Init, SourceLocation R, 1439190809Sdelphij VarDecl **Indices, unsigned NumIndices); 1440136849Sscottl 1441136849Sscottl /// isBaseInitializer - Returns true when this initializer is 1442136849Sscottl /// initializing a base class. 1443136849Sscottl bool isBaseInitializer() const { return Initializee.is<TypeSourceInfo*>(); } 1444136849Sscottl 1445136849Sscottl /// isMemberInitializer - Returns true when this initializer is 1446136849Sscottl /// initializing a non-static data member. 1447136849Sscottl bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } 1448 1449 bool isAnyMemberInitializer() const { 1450 return isMemberInitializer() || isIndirectMemberInitializer(); 1451 } 1452 1453 bool isIndirectMemberInitializer() const { 1454 return Initializee.is<IndirectFieldDecl*>(); 1455 } 1456 1457 /// isInClassMemberInitializer - Returns true when this initializer is an 1458 /// implicit ctor initializer generated for a field with an initializer 1459 /// defined on the member declaration. 1460 bool isInClassMemberInitializer() const { 1461 return !Init; 1462 } 1463 1464 /// isDelegatingInitializer - Returns true when this initializer is creating 1465 /// a delegating constructor. 1466 bool isDelegatingInitializer() const { 1467 return Initializee.is<CXXConstructorDecl *>(); 1468 } 1469 1470 /// \brief Determine whether this initializer is a pack expansion. 1471 bool isPackExpansion() const { 1472 return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); 1473 } 1474 1475 // \brief For a pack expansion, returns the location of the ellipsis. 1476 SourceLocation getEllipsisLoc() const { 1477 assert(isPackExpansion() && "Initializer is not a pack expansion"); 1478 return MemberOrEllipsisLocation; 1479 } 1480 1481 /// If this is a base class initializer, returns the type of the 1482 /// base class with location information. Otherwise, returns an NULL 1483 /// type location. 1484 TypeLoc getBaseClassLoc() const; 1485 1486 /// If this is a base class initializer, returns the type of the base class. 1487 /// Otherwise, returns NULL. 1488 const Type *getBaseClass() const; 1489 1490 /// Returns whether the base is virtual or not. 1491 bool isBaseVirtual() const { 1492 assert(isBaseInitializer() && "Must call this on base initializer!"); 1493 1494 return IsVirtual; 1495 } 1496 1497 /// \brief Returns the declarator information for a base class initializer. 1498 TypeSourceInfo *getBaseClassInfo() const { 1499 return Initializee.dyn_cast<TypeSourceInfo *>(); 1500 } 1501 1502 /// getMember - If this is a member initializer, returns the 1503 /// declaration of the non-static data member being 1504 /// initialized. Otherwise, returns NULL. 1505 FieldDecl *getMember() const { 1506 if (isMemberInitializer()) 1507 return Initializee.get<FieldDecl*>(); 1508 else 1509 return 0; 1510 } 1511 FieldDecl *getAnyMember() const { 1512 if (isMemberInitializer()) 1513 return Initializee.get<FieldDecl*>(); 1514 else if (isIndirectMemberInitializer()) 1515 return Initializee.get<IndirectFieldDecl*>()->getAnonField(); 1516 else 1517 return 0; 1518 } 1519 1520 IndirectFieldDecl *getIndirectMember() const { 1521 if (isIndirectMemberInitializer()) 1522 return Initializee.get<IndirectFieldDecl*>(); 1523 else 1524 return 0; 1525 } 1526 1527 CXXConstructorDecl *getTargetConstructor() const { 1528 if (isDelegatingInitializer()) 1529 return Initializee.get<CXXConstructorDecl*>(); 1530 else 1531 return 0; 1532 } 1533 1534 SourceLocation getMemberLocation() const { 1535 return MemberOrEllipsisLocation; 1536 } 1537 1538 /// \brief Determine the source location of the initializer. 1539 SourceLocation getSourceLocation() const; 1540 1541 /// \brief Determine the source range covering the entire initializer. 1542 SourceRange getSourceRange() const; 1543 1544 /// isWritten - Returns true if this initializer is explicitly written 1545 /// in the source code. 1546 bool isWritten() const { return IsWritten; } 1547 1548 /// \brief Return the source position of the initializer, counting from 0. 1549 /// If the initializer was implicit, -1 is returned. 1550 int getSourceOrder() const { 1551 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1; 1552 } 1553 1554 /// \brief Set the source order of this initializer. This method can only 1555 /// be called once for each initializer; it cannot be called on an 1556 /// initializer having a positive number of (implicit) array indices. 1557 void setSourceOrder(int pos) { 1558 assert(!IsWritten && 1559 "calling twice setSourceOrder() on the same initializer"); 1560 assert(SourceOrderOrNumArrayIndices == 0 && 1561 "setSourceOrder() used when there are implicit array indices"); 1562 assert(pos >= 0 && 1563 "setSourceOrder() used to make an initializer implicit"); 1564 IsWritten = true; 1565 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos); 1566 } 1567 1568 SourceLocation getLParenLoc() const { return LParenLoc; } 1569 SourceLocation getRParenLoc() const { return RParenLoc; } 1570 1571 /// \brief Determine the number of implicit array indices used while 1572 /// described an array member initialization. 1573 unsigned getNumArrayIndices() const { 1574 return IsWritten ? 0 : SourceOrderOrNumArrayIndices; 1575 } 1576 1577 /// \brief Retrieve a particular array index variable used to 1578 /// describe an array member initialization. 1579 VarDecl *getArrayIndex(unsigned I) { 1580 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1581 return reinterpret_cast<VarDecl **>(this + 1)[I]; 1582 } 1583 const VarDecl *getArrayIndex(unsigned I) const { 1584 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1585 return reinterpret_cast<const VarDecl * const *>(this + 1)[I]; 1586 } 1587 void setArrayIndex(unsigned I, VarDecl *Index) { 1588 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1589 reinterpret_cast<VarDecl **>(this + 1)[I] = Index; 1590 } 1591 1592 /// \brief Get the initializer. This is 0 if this is an in-class initializer 1593 /// for a non-static data member which has not yet been parsed. 1594 Expr *getInit() const { 1595 if (!Init) 1596 return getAnyMember()->getInClassInitializer(); 1597 1598 return static_cast<Expr*>(Init); 1599 } 1600}; 1601 1602/// CXXConstructorDecl - Represents a C++ constructor within a 1603/// class. For example: 1604/// 1605/// @code 1606/// class X { 1607/// public: 1608/// explicit X(int); // represented by a CXXConstructorDecl. 1609/// }; 1610/// @endcode 1611class CXXConstructorDecl : public CXXMethodDecl { 1612 /// IsExplicitSpecified - Whether this constructor declaration has the 1613 /// 'explicit' keyword specified. 1614 bool IsExplicitSpecified : 1; 1615 1616 /// ImplicitlyDefined - Whether this constructor was implicitly 1617 /// defined by the compiler. When false, the constructor was defined 1618 /// by the user. In C++03, this flag will have the same value as 1619 /// Implicit. In C++0x, however, a constructor that is 1620 /// explicitly defaulted (i.e., defined with " = default") will have 1621 /// @c !Implicit && ImplicitlyDefined. 1622 bool ImplicitlyDefined : 1; 1623 1624 /// Support for base and member initializers. 1625 /// CtorInitializers - The arguments used to initialize the base 1626 /// or member. 1627 CXXCtorInitializer **CtorInitializers; 1628 unsigned NumCtorInitializers; 1629 1630 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 1631 const DeclarationNameInfo &NameInfo, 1632 QualType T, TypeSourceInfo *TInfo, 1633 bool isExplicitSpecified, bool isInline, 1634 bool isImplicitlyDeclared) 1635 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false, 1636 SC_None, isInline, SourceLocation()), 1637 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false), 1638 CtorInitializers(0), NumCtorInitializers(0) { 1639 setImplicit(isImplicitlyDeclared); 1640 } 1641 1642public: 1643 static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty); 1644 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1645 SourceLocation StartLoc, 1646 const DeclarationNameInfo &NameInfo, 1647 QualType T, TypeSourceInfo *TInfo, 1648 bool isExplicit, 1649 bool isInline, bool isImplicitlyDeclared); 1650 1651 /// isExplicitSpecified - Whether this constructor declaration has the 1652 /// 'explicit' keyword specified. 1653 bool isExplicitSpecified() const { return IsExplicitSpecified; } 1654 1655 /// isExplicit - Whether this constructor was marked "explicit" or not. 1656 bool isExplicit() const { 1657 return cast<CXXConstructorDecl>(getFirstDeclaration()) 1658 ->isExplicitSpecified(); 1659 } 1660 1661 /// isImplicitlyDefined - Whether this constructor was implicitly 1662 /// defined. If false, then this constructor was defined by the 1663 /// user. This operation can only be invoked if the constructor has 1664 /// already been defined. 1665 bool isImplicitlyDefined() const { 1666 assert(isThisDeclarationADefinition() && 1667 "Can only get the implicit-definition flag once the " 1668 "constructor has been defined"); 1669 return ImplicitlyDefined; 1670 } 1671 1672 /// setImplicitlyDefined - Set whether this constructor was 1673 /// implicitly defined or not. 1674 void setImplicitlyDefined(bool ID) { 1675 assert(isThisDeclarationADefinition() && 1676 "Can only set the implicit-definition flag once the constructor " 1677 "has been defined"); 1678 ImplicitlyDefined = ID; 1679 } 1680 1681 /// init_iterator - Iterates through the member/base initializer list. 1682 typedef CXXCtorInitializer **init_iterator; 1683 1684 /// init_const_iterator - Iterates through the memberbase initializer list. 1685 typedef CXXCtorInitializer * const * init_const_iterator; 1686 1687 /// init_begin() - Retrieve an iterator to the first initializer. 1688 init_iterator init_begin() { return CtorInitializers; } 1689 /// begin() - Retrieve an iterator to the first initializer. 1690 init_const_iterator init_begin() const { return CtorInitializers; } 1691 1692 /// init_end() - Retrieve an iterator past the last initializer. 1693 init_iterator init_end() { 1694 return CtorInitializers + NumCtorInitializers; 1695 } 1696 /// end() - Retrieve an iterator past the last initializer. 1697 init_const_iterator init_end() const { 1698 return CtorInitializers + NumCtorInitializers; 1699 } 1700 1701 typedef std::reverse_iterator<init_iterator> init_reverse_iterator; 1702 typedef std::reverse_iterator<init_const_iterator> init_const_reverse_iterator; 1703 1704 init_reverse_iterator init_rbegin() { 1705 return init_reverse_iterator(init_end()); 1706 } 1707 init_const_reverse_iterator init_rbegin() const { 1708 return init_const_reverse_iterator(init_end()); 1709 } 1710 1711 init_reverse_iterator init_rend() { 1712 return init_reverse_iterator(init_begin()); 1713 } 1714 init_const_reverse_iterator init_rend() const { 1715 return init_const_reverse_iterator(init_begin()); 1716 } 1717 1718 /// getNumArgs - Determine the number of arguments used to 1719 /// initialize the member or base. 1720 unsigned getNumCtorInitializers() const { 1721 return NumCtorInitializers; 1722 } 1723 1724 void setNumCtorInitializers(unsigned numCtorInitializers) { 1725 NumCtorInitializers = numCtorInitializers; 1726 } 1727 1728 void setCtorInitializers(CXXCtorInitializer ** initializers) { 1729 CtorInitializers = initializers; 1730 } 1731 1732 /// isDelegatingConstructor - Whether this constructor is a 1733 /// delegating constructor 1734 bool isDelegatingConstructor() const { 1735 return (getNumCtorInitializers() == 1) && 1736 CtorInitializers[0]->isDelegatingInitializer(); 1737 } 1738 1739 /// getTargetConstructor - When this constructor delegates to 1740 /// another, retrieve the target 1741 CXXConstructorDecl *getTargetConstructor() const { 1742 assert(isDelegatingConstructor() && 1743 "A non-delegating constructor has no target"); 1744 return CtorInitializers[0]->getTargetConstructor(); 1745 } 1746 1747 /// isDefaultConstructor - Whether this constructor is a default 1748 /// constructor (C++ [class.ctor]p5), which can be used to 1749 /// default-initialize a class of this type. 1750 bool isDefaultConstructor() const; 1751 1752 /// isCopyConstructor - Whether this constructor is a copy 1753 /// constructor (C++ [class.copy]p2, which can be used to copy the 1754 /// class. @p TypeQuals will be set to the qualifiers on the 1755 /// argument type. For example, @p TypeQuals would be set to @c 1756 /// QualType::Const for the following copy constructor: 1757 /// 1758 /// @code 1759 /// class X { 1760 /// public: 1761 /// X(const X&); 1762 /// }; 1763 /// @endcode 1764 bool isCopyConstructor(unsigned &TypeQuals) const; 1765 1766 /// isCopyConstructor - Whether this constructor is a copy 1767 /// constructor (C++ [class.copy]p2, which can be used to copy the 1768 /// class. 1769 bool isCopyConstructor() const { 1770 unsigned TypeQuals = 0; 1771 return isCopyConstructor(TypeQuals); 1772 } 1773 1774 /// \brief Determine whether this constructor is a move constructor 1775 /// (C++0x [class.copy]p3), which can be used to move values of the class. 1776 /// 1777 /// \param TypeQuals If this constructor is a move constructor, will be set 1778 /// to the type qualifiers on the referent of the first parameter's type. 1779 bool isMoveConstructor(unsigned &TypeQuals) const; 1780 1781 /// \brief Determine whether this constructor is a move constructor 1782 /// (C++0x [class.copy]p3), which can be used to move values of the class. 1783 bool isMoveConstructor() const { 1784 unsigned TypeQuals = 0; 1785 return isMoveConstructor(TypeQuals); 1786 } 1787 1788 /// \brief Determine whether this is a copy or move constructor. 1789 /// 1790 /// \param TypeQuals Will be set to the type qualifiers on the reference 1791 /// parameter, if in fact this is a copy or move constructor. 1792 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; 1793 1794 /// \brief Determine whether this a copy or move constructor. 1795 bool isCopyOrMoveConstructor() const { 1796 unsigned Quals; 1797 return isCopyOrMoveConstructor(Quals); 1798 } 1799 1800 /// isConvertingConstructor - Whether this constructor is a 1801 /// converting constructor (C++ [class.conv.ctor]), which can be 1802 /// used for user-defined conversions. 1803 bool isConvertingConstructor(bool AllowExplicit) const; 1804 1805 /// \brief Determine whether this is a member template specialization that 1806 /// would copy the object to itself. Such constructors are never used to copy 1807 /// an object. 1808 bool isSpecializationCopyingObject() const; 1809 1810 /// \brief Get the constructor that this inheriting constructor is based on. 1811 const CXXConstructorDecl *getInheritedConstructor() const; 1812 1813 /// \brief Set the constructor that this inheriting constructor is based on. 1814 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor); 1815 1816 const CXXConstructorDecl *getCanonicalDecl() const { 1817 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 1818 } 1819 CXXConstructorDecl *getCanonicalDecl() { 1820 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 1821 } 1822 1823 // Implement isa/cast/dyncast/etc. 1824 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1825 static bool classof(const CXXConstructorDecl *D) { return true; } 1826 static bool classofKind(Kind K) { return K == CXXConstructor; } 1827 1828 friend class ASTDeclReader; 1829 friend class ASTDeclWriter; 1830}; 1831 1832/// CXXDestructorDecl - Represents a C++ destructor within a 1833/// class. For example: 1834/// 1835/// @code 1836/// class X { 1837/// public: 1838/// ~X(); // represented by a CXXDestructorDecl. 1839/// }; 1840/// @endcode 1841class CXXDestructorDecl : public CXXMethodDecl { 1842 /// ImplicitlyDefined - Whether this destructor was implicitly 1843 /// defined by the compiler. When false, the destructor was defined 1844 /// by the user. In C++03, this flag will have the same value as 1845 /// Implicit. In C++0x, however, a destructor that is 1846 /// explicitly defaulted (i.e., defined with " = default") will have 1847 /// @c !Implicit && ImplicitlyDefined. 1848 bool ImplicitlyDefined : 1; 1849 1850 FunctionDecl *OperatorDelete; 1851 1852 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 1853 const DeclarationNameInfo &NameInfo, 1854 QualType T, TypeSourceInfo *TInfo, 1855 bool isInline, bool isImplicitlyDeclared) 1856 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false, 1857 SC_None, isInline, SourceLocation()), 1858 ImplicitlyDefined(false), OperatorDelete(0) { 1859 setImplicit(isImplicitlyDeclared); 1860 } 1861 1862public: 1863 static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty); 1864 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1865 SourceLocation StartLoc, 1866 const DeclarationNameInfo &NameInfo, 1867 QualType T, TypeSourceInfo* TInfo, 1868 bool isInline, 1869 bool isImplicitlyDeclared); 1870 1871 /// isImplicitlyDefined - Whether this destructor was implicitly 1872 /// defined. If false, then this destructor was defined by the 1873 /// user. This operation can only be invoked if the destructor has 1874 /// already been defined. 1875 bool isImplicitlyDefined() const { 1876 assert(isThisDeclarationADefinition() && 1877 "Can only get the implicit-definition flag once the destructor has been defined"); 1878 return ImplicitlyDefined; 1879 } 1880 1881 /// setImplicitlyDefined - Set whether this destructor was 1882 /// implicitly defined or not. 1883 void setImplicitlyDefined(bool ID) { 1884 assert(isThisDeclarationADefinition() && 1885 "Can only set the implicit-definition flag once the destructor has been defined"); 1886 ImplicitlyDefined = ID; 1887 } 1888 1889 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 1890 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1891 1892 // Implement isa/cast/dyncast/etc. 1893 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1894 static bool classof(const CXXDestructorDecl *D) { return true; } 1895 static bool classofKind(Kind K) { return K == CXXDestructor; } 1896 1897 friend class ASTDeclReader; 1898 friend class ASTDeclWriter; 1899}; 1900 1901/// CXXConversionDecl - Represents a C++ conversion function within a 1902/// class. For example: 1903/// 1904/// @code 1905/// class X { 1906/// public: 1907/// operator bool(); 1908/// }; 1909/// @endcode 1910class CXXConversionDecl : public CXXMethodDecl { 1911 /// IsExplicitSpecified - Whether this conversion function declaration is 1912 /// marked "explicit", meaning that it can only be applied when the user 1913 /// explicitly wrote a cast. This is a C++0x feature. 1914 bool IsExplicitSpecified : 1; 1915 1916 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 1917 const DeclarationNameInfo &NameInfo, 1918 QualType T, TypeSourceInfo *TInfo, 1919 bool isInline, bool isExplicitSpecified, 1920 SourceLocation EndLocation) 1921 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false, 1922 SC_None, isInline, EndLocation), 1923 IsExplicitSpecified(isExplicitSpecified) { } 1924 1925public: 1926 static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty); 1927 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1928 SourceLocation StartLoc, 1929 const DeclarationNameInfo &NameInfo, 1930 QualType T, TypeSourceInfo *TInfo, 1931 bool isInline, bool isExplicit, 1932 SourceLocation EndLocation); 1933 1934 /// IsExplicitSpecified - Whether this conversion function declaration is 1935 /// marked "explicit", meaning that it can only be applied when the user 1936 /// explicitly wrote a cast. This is a C++0x feature. 1937 bool isExplicitSpecified() const { return IsExplicitSpecified; } 1938 1939 /// isExplicit - Whether this is an explicit conversion operator 1940 /// (C++0x only). Explicit conversion operators are only considered 1941 /// when the user has explicitly written a cast. 1942 bool isExplicit() const { 1943 return cast<CXXConversionDecl>(getFirstDeclaration()) 1944 ->isExplicitSpecified(); 1945 } 1946 1947 /// getConversionType - Returns the type that this conversion 1948 /// function is converting to. 1949 QualType getConversionType() const { 1950 return getType()->getAs<FunctionType>()->getResultType(); 1951 } 1952 1953 // Implement isa/cast/dyncast/etc. 1954 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1955 static bool classof(const CXXConversionDecl *D) { return true; } 1956 static bool classofKind(Kind K) { return K == CXXConversion; } 1957 1958 friend class ASTDeclReader; 1959 friend class ASTDeclWriter; 1960}; 1961 1962/// LinkageSpecDecl - This represents a linkage specification. For example: 1963/// extern "C" void foo(); 1964/// 1965class LinkageSpecDecl : public Decl, public DeclContext { 1966public: 1967 /// LanguageIDs - Used to represent the language in a linkage 1968 /// specification. The values are part of the serialization abi for 1969 /// ASTs and cannot be changed without altering that abi. To help 1970 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1971 /// from the dwarf standard. 1972 enum LanguageIDs { 1973 lang_c = /* DW_LANG_C */ 0x0002, 1974 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 1975 }; 1976private: 1977 /// Language - The language for this linkage specification. 1978 LanguageIDs Language; 1979 /// ExternLoc - The source location for the extern keyword. 1980 SourceLocation ExternLoc; 1981 /// RBraceLoc - The source location for the right brace (if valid). 1982 SourceLocation RBraceLoc; 1983 1984 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, 1985 SourceLocation LangLoc, LanguageIDs lang, 1986 SourceLocation RBLoc) 1987 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), 1988 Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { } 1989 1990public: 1991 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1992 SourceLocation ExternLoc, 1993 SourceLocation LangLoc, LanguageIDs Lang, 1994 SourceLocation RBraceLoc = SourceLocation()); 1995 1996 /// \brief Return the language specified by this linkage specification. 1997 LanguageIDs getLanguage() const { return Language; } 1998 /// \brief Set the language specified by this linkage specification. 1999 void setLanguage(LanguageIDs L) { Language = L; } 2000 2001 /// \brief Determines whether this linkage specification had braces in 2002 /// its syntactic form. 2003 bool hasBraces() const { return RBraceLoc.isValid(); } 2004 2005 SourceLocation getExternLoc() const { return ExternLoc; } 2006 SourceLocation getRBraceLoc() const { return RBraceLoc; } 2007 void setExternLoc(SourceLocation L) { ExternLoc = L; } 2008 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 2009 2010 SourceLocation getLocEnd() const { 2011 if (hasBraces()) 2012 return getRBraceLoc(); 2013 // No braces: get the end location of the (only) declaration in context 2014 // (if present). 2015 return decls_empty() ? getLocation() : decls_begin()->getLocEnd(); 2016 } 2017 2018 SourceRange getSourceRange() const { 2019 return SourceRange(ExternLoc, getLocEnd()); 2020 } 2021 2022 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2023 static bool classof(const LinkageSpecDecl *D) { return true; } 2024 static bool classofKind(Kind K) { return K == LinkageSpec; } 2025 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 2026 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 2027 } 2028 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 2029 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 2030 } 2031}; 2032 2033/// UsingDirectiveDecl - Represents C++ using-directive. For example: 2034/// 2035/// using namespace std; 2036/// 2037// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 2038// artificial name, for all using-directives in order to store 2039// them in DeclContext effectively. 2040class UsingDirectiveDecl : public NamedDecl { 2041 /// \brief The location of the "using" keyword. 2042 SourceLocation UsingLoc; 2043 2044 /// SourceLocation - Location of 'namespace' token. 2045 SourceLocation NamespaceLoc; 2046 2047 /// \brief The nested-name-specifier that precedes the namespace. 2048 NestedNameSpecifierLoc QualifierLoc; 2049 2050 /// NominatedNamespace - Namespace nominated by using-directive. 2051 NamedDecl *NominatedNamespace; 2052 2053 /// Enclosing context containing both using-directive and nominated 2054 /// namespace. 2055 DeclContext *CommonAncestor; 2056 2057 /// getUsingDirectiveName - Returns special DeclarationName used by 2058 /// using-directives. This is only used by DeclContext for storing 2059 /// UsingDirectiveDecls in its lookup structure. 2060 static DeclarationName getName() { 2061 return DeclarationName::getUsingDirectiveName(); 2062 } 2063 2064 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, 2065 SourceLocation NamespcLoc, 2066 NestedNameSpecifierLoc QualifierLoc, 2067 SourceLocation IdentLoc, 2068 NamedDecl *Nominated, 2069 DeclContext *CommonAncestor) 2070 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), 2071 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), 2072 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { } 2073 2074public: 2075 /// \brief Retrieve the nested-name-specifier that qualifies the 2076 /// name of the namespace, with source-location information. 2077 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2078 2079 /// \brief Retrieve the nested-name-specifier that qualifies the 2080 /// name of the namespace. 2081 NestedNameSpecifier *getQualifier() const { 2082 return QualifierLoc.getNestedNameSpecifier(); 2083 } 2084 2085 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 2086 const NamedDecl *getNominatedNamespaceAsWritten() const { 2087 return NominatedNamespace; 2088 } 2089 2090 /// getNominatedNamespace - Returns namespace nominated by using-directive. 2091 NamespaceDecl *getNominatedNamespace(); 2092 2093 const NamespaceDecl *getNominatedNamespace() const { 2094 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 2095 } 2096 2097 /// \brief Returns the common ancestor context of this using-directive and 2098 /// its nominated namespace. 2099 DeclContext *getCommonAncestor() { return CommonAncestor; } 2100 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 2101 2102 /// \brief Return the location of the "using" keyword. 2103 SourceLocation getUsingLoc() const { return UsingLoc; } 2104 2105 // FIXME: Could omit 'Key' in name. 2106 /// getNamespaceKeyLocation - Returns location of namespace keyword. 2107 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 2108 2109 /// getIdentLocation - Returns location of identifier. 2110 SourceLocation getIdentLocation() const { return getLocation(); } 2111 2112 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 2113 SourceLocation UsingLoc, 2114 SourceLocation NamespaceLoc, 2115 NestedNameSpecifierLoc QualifierLoc, 2116 SourceLocation IdentLoc, 2117 NamedDecl *Nominated, 2118 DeclContext *CommonAncestor); 2119 2120 SourceRange getSourceRange() const { 2121 return SourceRange(UsingLoc, getLocation()); 2122 } 2123 2124 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2125 static bool classof(const UsingDirectiveDecl *D) { return true; } 2126 static bool classofKind(Kind K) { return K == UsingDirective; } 2127 2128 // Friend for getUsingDirectiveName. 2129 friend class DeclContext; 2130 2131 friend class ASTDeclReader; 2132}; 2133 2134/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 2135/// 2136/// @code 2137/// namespace Foo = Bar; 2138/// @endcode 2139class NamespaceAliasDecl : public NamedDecl { 2140 /// \brief The location of the "namespace" keyword. 2141 SourceLocation NamespaceLoc; 2142 2143 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc. 2144 SourceLocation IdentLoc; 2145 2146 /// \brief The nested-name-specifier that precedes the namespace. 2147 NestedNameSpecifierLoc QualifierLoc; 2148 2149 /// Namespace - The Decl that this alias points to. Can either be a 2150 /// NamespaceDecl or a NamespaceAliasDecl. 2151 NamedDecl *Namespace; 2152 2153 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc, 2154 SourceLocation AliasLoc, IdentifierInfo *Alias, 2155 NestedNameSpecifierLoc QualifierLoc, 2156 SourceLocation IdentLoc, NamedDecl *Namespace) 2157 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), 2158 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), 2159 QualifierLoc(QualifierLoc), Namespace(Namespace) { } 2160 2161 friend class ASTDeclReader; 2162 2163public: 2164 /// \brief Retrieve the nested-name-specifier that qualifies the 2165 /// name of the namespace, with source-location information. 2166 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2167 2168 /// \brief Retrieve the nested-name-specifier that qualifies the 2169 /// name of the namespace. 2170 NestedNameSpecifier *getQualifier() const { 2171 return QualifierLoc.getNestedNameSpecifier(); 2172 } 2173 2174 /// \brief Retrieve the namespace declaration aliased by this directive. 2175 NamespaceDecl *getNamespace() { 2176 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 2177 return AD->getNamespace(); 2178 2179 return cast<NamespaceDecl>(Namespace); 2180 } 2181 2182 const NamespaceDecl *getNamespace() const { 2183 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 2184 } 2185 2186 /// Returns the location of the alias name, i.e. 'foo' in 2187 /// "namespace foo = ns::bar;". 2188 SourceLocation getAliasLoc() const { return getLocation(); } 2189 2190 /// Returns the location of the 'namespace' keyword. 2191 SourceLocation getNamespaceLoc() const { return NamespaceLoc; } 2192 2193 /// Returns the location of the identifier in the named namespace. 2194 SourceLocation getTargetNameLoc() const { return IdentLoc; } 2195 2196 /// \brief Retrieve the namespace that this alias refers to, which 2197 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 2198 NamedDecl *getAliasedNamespace() const { return Namespace; } 2199 2200 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 2201 SourceLocation NamespaceLoc, 2202 SourceLocation AliasLoc, 2203 IdentifierInfo *Alias, 2204 NestedNameSpecifierLoc QualifierLoc, 2205 SourceLocation IdentLoc, 2206 NamedDecl *Namespace); 2207 2208 virtual SourceRange getSourceRange() const { 2209 return SourceRange(NamespaceLoc, IdentLoc); 2210 } 2211 2212 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2213 static bool classof(const NamespaceAliasDecl *D) { return true; } 2214 static bool classofKind(Kind K) { return K == NamespaceAlias; } 2215}; 2216 2217/// UsingShadowDecl - Represents a shadow declaration introduced into 2218/// a scope by a (resolved) using declaration. For example, 2219/// 2220/// namespace A { 2221/// void foo(); 2222/// } 2223/// namespace B { 2224/// using A::foo(); // <- a UsingDecl 2225/// // Also creates a UsingShadowDecl for A::foo in B 2226/// } 2227/// 2228class UsingShadowDecl : public NamedDecl { 2229 /// The referenced declaration. 2230 NamedDecl *Underlying; 2231 2232 /// \brief The using declaration which introduced this decl or the next using 2233 /// shadow declaration contained in the aforementioned using declaration. 2234 NamedDecl *UsingOrNextShadow; 2235 friend class UsingDecl; 2236 2237 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 2238 NamedDecl *Target) 2239 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()), 2240 Underlying(Target), 2241 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) { 2242 if (Target) { 2243 setDeclName(Target->getDeclName()); 2244 IdentifierNamespace = Target->getIdentifierNamespace(); 2245 } 2246 setImplicit(); 2247 } 2248 2249public: 2250 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 2251 SourceLocation Loc, UsingDecl *Using, 2252 NamedDecl *Target) { 2253 return new (C) UsingShadowDecl(DC, Loc, Using, Target); 2254 } 2255 2256 /// \brief Gets the underlying declaration which has been brought into the 2257 /// local scope. 2258 NamedDecl *getTargetDecl() const { return Underlying; } 2259 2260 /// \brief Sets the underlying declaration which has been brought into the 2261 /// local scope. 2262 void setTargetDecl(NamedDecl* ND) { 2263 assert(ND && "Target decl is null!"); 2264 Underlying = ND; 2265 IdentifierNamespace = ND->getIdentifierNamespace(); 2266 } 2267 2268 /// \brief Gets the using declaration to which this declaration is tied. 2269 UsingDecl *getUsingDecl() const; 2270 2271 /// \brief The next using shadow declaration contained in the shadow decl 2272 /// chain of the using declaration which introduced this decl. 2273 UsingShadowDecl *getNextUsingShadowDecl() const { 2274 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); 2275 } 2276 2277 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2278 static bool classof(const UsingShadowDecl *D) { return true; } 2279 static bool classofKind(Kind K) { return K == Decl::UsingShadow; } 2280 2281 friend class ASTDeclReader; 2282 friend class ASTDeclWriter; 2283}; 2284 2285/// UsingDecl - Represents a C++ using-declaration. For example: 2286/// using someNameSpace::someIdentifier; 2287class UsingDecl : public NamedDecl { 2288 /// \brief The source location of the "using" location itself. 2289 SourceLocation UsingLocation; 2290 2291 /// \brief The nested-name-specifier that precedes the name. 2292 NestedNameSpecifierLoc QualifierLoc; 2293 2294 /// DNLoc - Provides source/type location info for the 2295 /// declaration name embedded in the ValueDecl base class. 2296 DeclarationNameLoc DNLoc; 2297 2298 /// \brief The first shadow declaration of the shadow decl chain associated 2299 /// with this using declaration. 2300 UsingShadowDecl *FirstUsingShadow; 2301 2302 // \brief Has 'typename' keyword. 2303 bool IsTypeName; 2304 2305 UsingDecl(DeclContext *DC, SourceLocation UL, 2306 NestedNameSpecifierLoc QualifierLoc, 2307 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg) 2308 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), 2309 UsingLocation(UL), QualifierLoc(QualifierLoc), 2310 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg) { 2311 } 2312 2313public: 2314 /// \brief Returns the source location of the "using" keyword. 2315 SourceLocation getUsingLocation() const { return UsingLocation; } 2316 2317 /// \brief Set the source location of the 'using' keyword. 2318 void setUsingLocation(SourceLocation L) { UsingLocation = L; } 2319 2320 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2321 /// with source-location information. 2322 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2323 2324 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2325 NestedNameSpecifier *getQualifier() const { 2326 return QualifierLoc.getNestedNameSpecifier(); 2327 } 2328 2329 DeclarationNameInfo getNameInfo() const { 2330 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2331 } 2332 2333 /// \brief Return true if the using declaration has 'typename'. 2334 bool isTypeName() const { return IsTypeName; } 2335 2336 /// \brief Sets whether the using declaration has 'typename'. 2337 void setTypeName(bool TN) { IsTypeName = TN; } 2338 2339 /// \brief Iterates through the using shadow declarations assosiated with 2340 /// this using declaration. 2341 class shadow_iterator { 2342 /// \brief The current using shadow declaration. 2343 UsingShadowDecl *Current; 2344 2345 public: 2346 typedef UsingShadowDecl* value_type; 2347 typedef UsingShadowDecl* reference; 2348 typedef UsingShadowDecl* pointer; 2349 typedef std::forward_iterator_tag iterator_category; 2350 typedef std::ptrdiff_t difference_type; 2351 2352 shadow_iterator() : Current(0) { } 2353 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { } 2354 2355 reference operator*() const { return Current; } 2356 pointer operator->() const { return Current; } 2357 2358 shadow_iterator& operator++() { 2359 Current = Current->getNextUsingShadowDecl(); 2360 return *this; 2361 } 2362 2363 shadow_iterator operator++(int) { 2364 shadow_iterator tmp(*this); 2365 ++(*this); 2366 return tmp; 2367 } 2368 2369 friend bool operator==(shadow_iterator x, shadow_iterator y) { 2370 return x.Current == y.Current; 2371 } 2372 friend bool operator!=(shadow_iterator x, shadow_iterator y) { 2373 return x.Current != y.Current; 2374 } 2375 }; 2376 2377 shadow_iterator shadow_begin() const { 2378 return shadow_iterator(FirstUsingShadow); 2379 } 2380 shadow_iterator shadow_end() const { return shadow_iterator(); } 2381 2382 /// \brief Return the number of shadowed declarations associated with this 2383 /// using declaration. 2384 unsigned shadow_size() const { 2385 return std::distance(shadow_begin(), shadow_end()); 2386 } 2387 2388 void addShadowDecl(UsingShadowDecl *S); 2389 void removeShadowDecl(UsingShadowDecl *S); 2390 2391 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 2392 SourceLocation UsingL, 2393 NestedNameSpecifierLoc QualifierLoc, 2394 const DeclarationNameInfo &NameInfo, 2395 bool IsTypeNameArg); 2396 2397 SourceRange getSourceRange() const { 2398 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 2399 } 2400 2401 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2402 static bool classof(const UsingDecl *D) { return true; } 2403 static bool classofKind(Kind K) { return K == Using; } 2404 2405 friend class ASTDeclReader; 2406 friend class ASTDeclWriter; 2407}; 2408 2409/// UnresolvedUsingValueDecl - Represents a dependent using 2410/// declaration which was not marked with 'typename'. Unlike 2411/// non-dependent using declarations, these *only* bring through 2412/// non-types; otherwise they would break two-phase lookup. 2413/// 2414/// template <class T> class A : public Base<T> { 2415/// using Base<T>::foo; 2416/// }; 2417class UnresolvedUsingValueDecl : public ValueDecl { 2418 /// \brief The source location of the 'using' keyword 2419 SourceLocation UsingLocation; 2420 2421 /// \brief The nested-name-specifier that precedes the name. 2422 NestedNameSpecifierLoc QualifierLoc; 2423 2424 /// DNLoc - Provides source/type location info for the 2425 /// declaration name embedded in the ValueDecl base class. 2426 DeclarationNameLoc DNLoc; 2427 2428 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 2429 SourceLocation UsingLoc, 2430 NestedNameSpecifierLoc QualifierLoc, 2431 const DeclarationNameInfo &NameInfo) 2432 : ValueDecl(UnresolvedUsingValue, DC, 2433 NameInfo.getLoc(), NameInfo.getName(), Ty), 2434 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc), 2435 DNLoc(NameInfo.getInfo()) 2436 { } 2437 2438public: 2439 /// \brief Returns the source location of the 'using' keyword. 2440 SourceLocation getUsingLoc() const { return UsingLocation; } 2441 2442 /// \brief Set the source location of the 'using' keyword. 2443 void setUsingLoc(SourceLocation L) { UsingLocation = L; } 2444 2445 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2446 /// with source-location information. 2447 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2448 2449 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2450 NestedNameSpecifier *getQualifier() const { 2451 return QualifierLoc.getNestedNameSpecifier(); 2452 } 2453 2454 DeclarationNameInfo getNameInfo() const { 2455 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2456 } 2457 2458 static UnresolvedUsingValueDecl * 2459 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2460 NestedNameSpecifierLoc QualifierLoc, 2461 const DeclarationNameInfo &NameInfo); 2462 2463 SourceRange getSourceRange() const { 2464 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 2465 } 2466 2467 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2468 static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 2469 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } 2470 2471 friend class ASTDeclReader; 2472 friend class ASTDeclWriter; 2473}; 2474 2475/// UnresolvedUsingTypenameDecl - Represents a dependent using 2476/// declaration which was marked with 'typename'. 2477/// 2478/// template <class T> class A : public Base<T> { 2479/// using typename Base<T>::foo; 2480/// }; 2481/// 2482/// The type associated with a unresolved using typename decl is 2483/// currently always a typename type. 2484class UnresolvedUsingTypenameDecl : public TypeDecl { 2485 /// \brief The source location of the 'using' keyword 2486 SourceLocation UsingLocation; 2487 2488 /// \brief The source location of the 'typename' keyword 2489 SourceLocation TypenameLocation; 2490 2491 /// \brief The nested-name-specifier that precedes the name. 2492 NestedNameSpecifierLoc QualifierLoc; 2493 2494 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 2495 SourceLocation TypenameLoc, 2496 NestedNameSpecifierLoc QualifierLoc, 2497 SourceLocation TargetNameLoc, 2498 IdentifierInfo *TargetName) 2499 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, 2500 UsingLoc), 2501 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { } 2502 2503 friend class ASTDeclReader; 2504 2505public: 2506 /// \brief Returns the source location of the 'using' keyword. 2507 SourceLocation getUsingLoc() const { return getLocStart(); } 2508 2509 /// \brief Returns the source location of the 'typename' keyword. 2510 SourceLocation getTypenameLoc() const { return TypenameLocation; } 2511 2512 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2513 /// with source-location information. 2514 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2515 2516 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2517 NestedNameSpecifier *getQualifier() const { 2518 return QualifierLoc.getNestedNameSpecifier(); 2519 } 2520 2521 static UnresolvedUsingTypenameDecl * 2522 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2523 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, 2524 SourceLocation TargetNameLoc, DeclarationName TargetName); 2525 2526 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2527 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 2528 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } 2529}; 2530 2531/// StaticAssertDecl - Represents a C++0x static_assert declaration. 2532class StaticAssertDecl : public Decl { 2533 Expr *AssertExpr; 2534 StringLiteral *Message; 2535 SourceLocation RParenLoc; 2536 2537 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, 2538 Expr *assertexpr, StringLiteral *message, 2539 SourceLocation RParenLoc) 2540 : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr), 2541 Message(message), RParenLoc(RParenLoc) { } 2542 2543public: 2544 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 2545 SourceLocation StaticAssertLoc, 2546 Expr *AssertExpr, StringLiteral *Message, 2547 SourceLocation RParenLoc); 2548 2549 Expr *getAssertExpr() { return AssertExpr; } 2550 const Expr *getAssertExpr() const { return AssertExpr; } 2551 2552 StringLiteral *getMessage() { return Message; } 2553 const StringLiteral *getMessage() const { return Message; } 2554 2555 SourceLocation getRParenLoc() const { return RParenLoc; } 2556 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2557 2558 SourceRange getSourceRange() const { 2559 return SourceRange(getLocation(), getRParenLoc()); 2560 } 2561 2562 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2563 static bool classof(StaticAssertDecl *D) { return true; } 2564 static bool classofKind(Kind K) { return K == StaticAssert; } 2565 2566 friend class ASTDeclReader; 2567}; 2568 2569/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 2570/// into a diagnostic with <<. 2571const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 2572 AccessSpecifier AS); 2573 2574} // end namespace clang 2575 2576#endif 2577