DeclCXX.h revision 195341
1193326Sed//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the C++ Decl subclasses. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H 15193326Sed#define LLVM_CLANG_AST_DECLCXX_H 16193326Sed 17193326Sed#include "clang/AST/Decl.h" 18193326Sed#include "llvm/ADT/SmallVector.h" 19193326Sed 20193326Sednamespace clang { 21193326Sed 22193326Sedclass ClassTemplateDecl; 23193326Sedclass CXXRecordDecl; 24193326Sedclass CXXConstructorDecl; 25193326Sedclass CXXDestructorDecl; 26193326Sedclass CXXConversionDecl; 27193326Sedclass CXXMethodDecl; 28193326Sedclass ClassTemplateSpecializationDecl; 29193326Sed 30195099Sed/// \brief Represents any kind of function declaration, whether it is a 31195099Sed/// concrete function or a function template. 32195099Sedclass AnyFunctionDecl { 33195099Sed NamedDecl *Function; 34195099Sed 35195341Sed AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 36195341Sed 37195099Sedpublic: 38195099Sed AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 39195099Sed AnyFunctionDecl(FunctionTemplateDecl *FTD); 40195099Sed 41195099Sed /// \brief Implicily converts any function or function template into a 42195099Sed /// named declaration. 43195099Sed operator NamedDecl *() const { return Function; } 44195099Sed 45195099Sed /// \brief Retrieve the underlying function or function template. 46195099Sed NamedDecl *get() const { return Function; } 47195341Sed 48195341Sed static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 49195341Sed return AnyFunctionDecl(ND); 50195341Sed } 51195099Sed}; 52195099Sed 53195099Sed} // end namespace clang 54195099Sed 55195099Sednamespace llvm { 56195099Sed /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 57195099Sed /// AnyFunctionDecl to any function or function template declaration. 58195099Sed template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 59195099Sed typedef ::clang::NamedDecl* SimpleType; 60195099Sed static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 61195099Sed return Val; 62195099Sed } 63195099Sed }; 64195099Sed template<> struct simplify_type< ::clang::AnyFunctionDecl> 65195099Sed : public simplify_type<const ::clang::AnyFunctionDecl> {}; 66195341Sed 67195341Sed // Provide PointerLikeTypeTraits for non-cvr pointers. 68195341Sed template<> 69195341Sed class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 70195341Sed public: 71195341Sed static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 72195341Sed return F.get(); 73195341Sed } 74195341Sed static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 75195341Sed return ::clang::AnyFunctionDecl::getFromNamedDecl( 76195341Sed static_cast< ::clang::NamedDecl*>(P)); 77195341Sed } 78195341Sed 79195341Sed enum { NumLowBitsAvailable = 2 }; 80195341Sed }; 81195341Sed 82195099Sed} // end namespace llvm 83195099Sed 84195099Sednamespace clang { 85195099Sed 86193326Sed/// OverloadedFunctionDecl - An instance of this class represents a 87193326Sed/// set of overloaded functions. All of the functions have the same 88193326Sed/// name and occur within the same scope. 89193326Sed/// 90193326Sed/// An OverloadedFunctionDecl has no ownership over the FunctionDecl 91193326Sed/// nodes it contains. Rather, the FunctionDecls are owned by the 92193326Sed/// enclosing scope (which also owns the OverloadedFunctionDecl 93193326Sed/// node). OverloadedFunctionDecl is used primarily to store a set of 94193326Sed/// overloaded functions for name lookup. 95193326Sedclass OverloadedFunctionDecl : public NamedDecl { 96193326Sedprotected: 97193326Sed OverloadedFunctionDecl(DeclContext *DC, DeclarationName N) 98193326Sed : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { } 99193326Sed 100193326Sed /// Functions - the set of overloaded functions contained in this 101193326Sed /// overload set. 102195099Sed llvm::SmallVector<AnyFunctionDecl, 4> Functions; 103193326Sed 104193326Sed // FIXME: This should go away when we stop using 105193326Sed // OverloadedFunctionDecl to store conversions in CXXRecordDecl. 106193326Sed friend class CXXRecordDecl; 107193326Sed 108193326Sedpublic: 109195099Sed typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator; 110195099Sed typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator 111193326Sed function_const_iterator; 112193326Sed 113193326Sed static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC, 114193326Sed DeclarationName N); 115193326Sed 116195341Sed /// \brief Add a new overloaded function or function template to the set 117195341Sed /// of overloaded function templates. 118195341Sed void addOverload(AnyFunctionDecl F); 119193326Sed 120193326Sed function_iterator function_begin() { return Functions.begin(); } 121193326Sed function_iterator function_end() { return Functions.end(); } 122193326Sed function_const_iterator function_begin() const { return Functions.begin(); } 123193326Sed function_const_iterator function_end() const { return Functions.end(); } 124193326Sed 125195099Sed /// \brief Returns the number of overloaded functions stored in 126193326Sed /// this set. 127195099Sed unsigned size() const { return Functions.size(); } 128193326Sed 129193326Sed // Implement isa/cast/dyncast/etc. 130193326Sed static bool classof(const Decl *D) { 131193326Sed return D->getKind() == OverloadedFunction; 132193326Sed } 133193326Sed static bool classof(const OverloadedFunctionDecl *D) { return true; } 134193326Sed}; 135193326Sed 136193326Sed/// CXXBaseSpecifier - A base class of a C++ class. 137193326Sed/// 138193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 139193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 140193326Sed/// base class, whether it is a virtual or non-virtual base, and what 141193326Sed/// level of access (public, protected, private) is used for the 142193326Sed/// derivation. For example: 143193326Sed/// 144193326Sed/// @code 145193326Sed/// class A { }; 146193326Sed/// class B { }; 147193326Sed/// class C : public virtual A, protected B { }; 148193326Sed/// @endcode 149193326Sed/// 150193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 151193326Sed/// virtual A" and the other for "protected B". 152193326Sedclass CXXBaseSpecifier { 153193326Sed /// Range - The source code range that covers the full base 154193326Sed /// specifier, including the "virtual" (if present) and access 155193326Sed /// specifier (if present). 156193326Sed SourceRange Range; 157193326Sed 158193326Sed /// Virtual - Whether this is a virtual base class or not. 159193326Sed bool Virtual : 1; 160193326Sed 161193326Sed /// BaseOfClass - Whether this is the base of a class (true) or of a 162193326Sed /// struct (false). This determines the mapping from the access 163193326Sed /// specifier as written in the source code to the access specifier 164193326Sed /// used for semantic analysis. 165193326Sed bool BaseOfClass : 1; 166193326Sed 167193326Sed /// Access - Access specifier as written in the source code (which 168193326Sed /// may be AS_none). The actual type of data stored here is an 169193326Sed /// AccessSpecifier, but we use "unsigned" here to work around a 170193326Sed /// VC++ bug. 171193326Sed unsigned Access : 2; 172193326Sed 173193326Sed /// BaseType - The type of the base class. This will be a class or 174193326Sed /// struct (or a typedef of such). 175193326Sed QualType BaseType; 176193326Sed 177193326Sedpublic: 178193326Sed CXXBaseSpecifier() { } 179193326Sed 180193326Sed CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 181193326Sed : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 182193326Sed 183193326Sed /// getSourceRange - Retrieves the source range that contains the 184193326Sed /// entire base specifier. 185193326Sed SourceRange getSourceRange() const { return Range; } 186193326Sed 187193326Sed /// isVirtual - Determines whether the base class is a virtual base 188193326Sed /// class (or not). 189193326Sed bool isVirtual() const { return Virtual; } 190193326Sed 191193326Sed /// getAccessSpecifier - Returns the access specifier for this base 192193326Sed /// specifier. This is the actual base specifier as used for 193193326Sed /// semantic analysis, so the result can never be AS_none. To 194193326Sed /// retrieve the access specifier as written in the source code, use 195193326Sed /// getAccessSpecifierAsWritten(). 196193326Sed AccessSpecifier getAccessSpecifier() const { 197193326Sed if ((AccessSpecifier)Access == AS_none) 198193326Sed return BaseOfClass? AS_private : AS_public; 199193326Sed else 200193326Sed return (AccessSpecifier)Access; 201193326Sed } 202193326Sed 203193326Sed /// getAccessSpecifierAsWritten - Retrieves the access specifier as 204193326Sed /// written in the source code (which may mean that no access 205193326Sed /// specifier was explicitly written). Use getAccessSpecifier() to 206193326Sed /// retrieve the access specifier for use in semantic analysis. 207193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 208193326Sed return (AccessSpecifier)Access; 209193326Sed } 210193326Sed 211193326Sed /// getType - Retrieves the type of the base class. This type will 212193326Sed /// always be an unqualified class type. 213193326Sed QualType getType() const { return BaseType; } 214193326Sed}; 215193326Sed 216193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class. 217193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 218193326Sed/// to deal with C++-specific things. 219193326Sedclass CXXRecordDecl : public RecordDecl { 220193326Sed /// UserDeclaredConstructor - True when this class has a 221193326Sed /// user-declared constructor. 222193326Sed bool UserDeclaredConstructor : 1; 223193326Sed 224193326Sed /// UserDeclaredCopyConstructor - True when this class has a 225193326Sed /// user-declared copy constructor. 226193326Sed bool UserDeclaredCopyConstructor : 1; 227193326Sed 228193326Sed /// UserDeclaredCopyAssignment - True when this class has a 229193326Sed /// user-declared copy assignment operator. 230193326Sed bool UserDeclaredCopyAssignment : 1; 231193326Sed 232193326Sed /// UserDeclaredDestructor - True when this class has a 233193326Sed /// user-declared destructor. 234193326Sed bool UserDeclaredDestructor : 1; 235193326Sed 236193326Sed /// Aggregate - True when this class is an aggregate. 237193326Sed bool Aggregate : 1; 238193326Sed 239193326Sed /// PlainOldData - True when this class is a POD-type. 240193326Sed bool PlainOldData : 1; 241193326Sed 242193326Sed /// Polymorphic - True when this class is polymorphic, i.e. has at least one 243193326Sed /// virtual member or derives from a polymorphic class. 244193326Sed bool Polymorphic : 1; 245193326Sed 246193326Sed /// Abstract - True when this class is abstract, i.e. has at least one 247193326Sed /// pure virtual function, (that can come from a base class). 248193326Sed bool Abstract : 1; 249193326Sed 250193326Sed /// HasTrivialConstructor - True when this class has a trivial constructor 251193326Sed bool HasTrivialConstructor : 1; 252193326Sed 253193326Sed /// HasTrivialDestructor - True when this class has a trivial destructor 254193326Sed bool HasTrivialDestructor : 1; 255193326Sed 256193326Sed /// Bases - Base classes of this class. 257193326Sed /// FIXME: This is wasted space for a union. 258193326Sed CXXBaseSpecifier *Bases; 259193326Sed 260193326Sed /// NumBases - The number of base class specifiers in Bases. 261193326Sed unsigned NumBases; 262193326Sed 263193326Sed /// Conversions - Overload set containing the conversion functions 264193326Sed /// of this C++ class (but not its inherited conversion 265193326Sed /// functions). Each of the entries in this overload set is a 266193326Sed /// CXXConversionDecl. 267193326Sed OverloadedFunctionDecl Conversions; 268193326Sed 269193326Sed /// \brief The template or declaration that this declaration 270193326Sed /// describes or was instantiated from, respectively. 271193326Sed /// 272193326Sed /// For non-templates, this value will be NULL. For record 273193326Sed /// declarations that describe a class template, this will be a 274193326Sed /// pointer to a ClassTemplateDecl. For member 275193326Sed /// classes of class template specializations, this will be the 276193326Sed /// RecordDecl from which the member class was instantiated. 277193326Sed llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*> 278193326Sed TemplateOrInstantiation; 279193326Sed 280193326Sedprotected: 281193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 282193326Sed SourceLocation L, IdentifierInfo *Id); 283193326Sed 284193326Sed ~CXXRecordDecl(); 285193326Sed 286193326Sedpublic: 287193326Sed /// base_class_iterator - Iterator that traverses the base classes 288193326Sed /// of a clas. 289193326Sed typedef CXXBaseSpecifier* base_class_iterator; 290193326Sed 291193326Sed /// base_class_const_iterator - Iterator that traverses the base 292193326Sed /// classes of a clas. 293193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 294193326Sed 295193326Sed static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 296193326Sed SourceLocation L, IdentifierInfo *Id, 297193326Sed CXXRecordDecl* PrevDecl=0, 298193326Sed bool DelayTypeCreation = false); 299193326Sed 300195341Sed virtual void Destroy(ASTContext& C); 301195341Sed 302193326Sed /// setBases - Sets the base classes of this struct or class. 303195341Sed void setBases(ASTContext &C, 304195341Sed CXXBaseSpecifier const * const *Bases, unsigned NumBases); 305193326Sed 306193326Sed /// getNumBases - Retrieves the number of base classes of this 307193326Sed /// class. 308193326Sed unsigned getNumBases() const { return NumBases; } 309193326Sed 310193326Sed base_class_iterator bases_begin() { return Bases; } 311193326Sed base_class_const_iterator bases_begin() const { return Bases; } 312193326Sed base_class_iterator bases_end() { return Bases + NumBases; } 313193326Sed base_class_const_iterator bases_end() const { return Bases + NumBases; } 314193326Sed 315193326Sed /// hasConstCopyConstructor - Determines whether this class has a 316193326Sed /// copy constructor that accepts a const-qualified argument. 317193326Sed bool hasConstCopyConstructor(ASTContext &Context) const; 318193326Sed 319194711Sed /// getCopyConstructor - Returns the copy constructor for this class 320194711Sed CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 321194711Sed unsigned TypeQuals) const; 322194711Sed 323193326Sed /// hasConstCopyAssignment - Determines whether this class has a 324193326Sed /// copy assignment operator that accepts a const-qualified argument. 325193326Sed bool hasConstCopyAssignment(ASTContext &Context) const; 326193326Sed 327193326Sed /// addedConstructor - Notify the class that another constructor has 328193326Sed /// been added. This routine helps maintain information about the 329193326Sed /// class based on which constructors have been added. 330193326Sed void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 331193326Sed 332193326Sed /// hasUserDeclaredConstructor - Whether this class has any 333193326Sed /// user-declared constructors. When true, a default constructor 334193326Sed /// will not be implicitly declared. 335193326Sed bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; } 336193326Sed 337193326Sed /// hasUserDeclaredCopyConstructor - Whether this class has a 338193326Sed /// user-declared copy constructor. When false, a copy constructor 339193326Sed /// will be implicitly declared. 340193326Sed bool hasUserDeclaredCopyConstructor() const { 341193326Sed return UserDeclaredCopyConstructor; 342193326Sed } 343193326Sed 344193326Sed /// addedAssignmentOperator - Notify the class that another assignment 345193326Sed /// operator has been added. This routine helps maintain information about the 346193326Sed /// class based on which operators have been added. 347193326Sed void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 348193326Sed 349193326Sed /// hasUserDeclaredCopyAssignment - Whether this class has a 350193326Sed /// user-declared copy assignment operator. When false, a copy 351193326Sed /// assigment operator will be implicitly declared. 352193326Sed bool hasUserDeclaredCopyAssignment() const { 353193326Sed return UserDeclaredCopyAssignment; 354193326Sed } 355193326Sed 356193326Sed /// hasUserDeclaredDestructor - Whether this class has a 357193326Sed /// user-declared destructor. When false, a destructor will be 358193326Sed /// implicitly declared. 359193326Sed bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 360193326Sed 361193326Sed /// setUserDeclaredDestructor - Set whether this class has a 362193326Sed /// user-declared destructor. If not set by the time the class is 363193326Sed /// fully defined, a destructor will be implicitly declared. 364193326Sed void setUserDeclaredDestructor(bool UCD) { 365193326Sed UserDeclaredDestructor = UCD; 366193326Sed } 367193326Sed 368193326Sed /// getConversions - Retrieve the overload set containing all of the 369193326Sed /// conversion functions in this class. 370193326Sed OverloadedFunctionDecl *getConversionFunctions() { 371193326Sed return &Conversions; 372193326Sed } 373193326Sed const OverloadedFunctionDecl *getConversionFunctions() const { 374193326Sed return &Conversions; 375193326Sed } 376193326Sed 377193326Sed /// addConversionFunction - Add a new conversion function to the 378193326Sed /// list of conversion functions. 379193326Sed void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl); 380193326Sed 381193326Sed /// isAggregate - Whether this class is an aggregate (C++ 382193326Sed /// [dcl.init.aggr]), which is a class with no user-declared 383193326Sed /// constructors, no private or protected non-static data members, 384193326Sed /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 385193326Sed bool isAggregate() const { return Aggregate; } 386193326Sed 387193326Sed /// setAggregate - Set whether this class is an aggregate (C++ 388193326Sed /// [dcl.init.aggr]). 389193326Sed void setAggregate(bool Agg) { Aggregate = Agg; } 390193326Sed 391193326Sed /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 392193326Sed /// that is an aggregate that has no non-static non-POD data members, no 393193326Sed /// reference data members, no user-defined copy assignment operator and no 394193326Sed /// user-defined destructor. 395193326Sed bool isPOD() const { return PlainOldData; } 396193326Sed 397193326Sed /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 398193326Sed void setPOD(bool POD) { PlainOldData = POD; } 399193326Sed 400193326Sed /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 401193326Sed /// which means that the class contains or inherits a virtual function. 402193326Sed bool isPolymorphic() const { return Polymorphic; } 403193326Sed 404193326Sed /// setPolymorphic - Set whether this class is polymorphic (C++ 405193326Sed /// [class.virtual]). 406193326Sed void setPolymorphic(bool Poly) { Polymorphic = Poly; } 407193326Sed 408193326Sed /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 409193326Sed /// which means that the class contains or inherits a pure virtual function. 410193326Sed bool isAbstract() const { return Abstract; } 411193326Sed 412193326Sed /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 413193326Sed void setAbstract(bool Abs) { Abstract = Abs; } 414193326Sed 415193326Sed // hasTrivialConstructor - Whether this class has a trivial constructor 416193326Sed // (C++ [class.ctor]p5) 417193326Sed bool hasTrivialConstructor() const { return HasTrivialConstructor; } 418193326Sed 419193326Sed // setHasTrivialConstructor - Set whether this class has a trivial constructor 420193326Sed // (C++ [class.ctor]p5) 421193326Sed void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 422193326Sed 423193326Sed // hasTrivialDestructor - Whether this class has a trivial destructor 424193326Sed // (C++ [class.dtor]p3) 425193326Sed bool hasTrivialDestructor() const { return HasTrivialDestructor; } 426193326Sed 427193326Sed // setHasTrivialDestructor - Set whether this class has a trivial destructor 428193326Sed // (C++ [class.dtor]p3) 429193326Sed void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 430193326Sed 431193326Sed /// \brief If this record is an instantiation of a member class, 432193326Sed /// retrieves the member class from which it was instantiated. 433193326Sed /// 434193326Sed /// This routine will return non-NULL for (non-templated) member 435193326Sed /// classes of class templates. For example, given: 436193326Sed /// 437193326Sed /// \code 438193326Sed /// template<typename T> 439193326Sed /// struct X { 440193326Sed /// struct A { }; 441193326Sed /// }; 442193326Sed /// \endcode 443193326Sed /// 444193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 445193326Sed /// whose parent is the class template specialization X<int>. For 446193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 447193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 448193326Sed /// X<int>::A is required, it will be instantiated from the 449193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 450193326Sed CXXRecordDecl *getInstantiatedFromMemberClass() const { 451193326Sed return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>(); 452193326Sed } 453193326Sed 454193326Sed /// \brief Specify that this record is an instantiation of the 455193326Sed /// member class RD. 456193326Sed void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 457193326Sed TemplateOrInstantiation = RD; 458193326Sed } 459193326Sed 460193326Sed /// \brief Retrieves the class template that is described by this 461193326Sed /// class declaration. 462193326Sed /// 463193326Sed /// Every class template is represented as a ClassTemplateDecl and a 464193326Sed /// CXXRecordDecl. The former contains template properties (such as 465193326Sed /// the template parameter lists) while the latter contains the 466193326Sed /// actual description of the template's 467193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 468193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 469193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 470193326Sed /// a CXXRecordDecl. 471193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 472193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 473193326Sed } 474193326Sed 475193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 476193326Sed TemplateOrInstantiation = Template; 477193326Sed } 478193326Sed 479194613Sed /// getDefaultConstructor - Returns the default constructor for this class 480194613Sed CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 481194613Sed 482193326Sed /// getDestructor - Returns the destructor decl for this class. 483193326Sed const CXXDestructorDecl *getDestructor(ASTContext &Context); 484193326Sed 485195099Sed /// isLocalClass - If the class is a local class [class.local], returns 486195099Sed /// the enclosing function declaration. 487195099Sed const FunctionDecl *isLocalClass() const { 488195099Sed if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 489195099Sed return RD->isLocalClass(); 490195099Sed 491195099Sed return dyn_cast<FunctionDecl>(getDeclContext()); 492195099Sed } 493195099Sed 494193326Sed /// viewInheritance - Renders and displays an inheritance diagram 495193326Sed /// for this C++ class and all of its base classes (transitively) using 496193326Sed /// GraphViz. 497193326Sed void viewInheritance(ASTContext& Context) const; 498193326Sed 499193326Sed static bool classof(const Decl *D) { 500193326Sed return D->getKind() == CXXRecord || 501193326Sed D->getKind() == ClassTemplateSpecialization || 502193326Sed D->getKind() == ClassTemplatePartialSpecialization; 503193326Sed } 504193326Sed static bool classof(const CXXRecordDecl *D) { return true; } 505193326Sed static bool classof(const ClassTemplateSpecializationDecl *D) { 506193326Sed return true; 507193326Sed } 508193326Sed}; 509193326Sed 510193326Sed/// CXXMethodDecl - Represents a static or instance method of a 511193326Sed/// struct/union/class. 512193326Sedclass CXXMethodDecl : public FunctionDecl { 513193326Sedprotected: 514193326Sed CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 515193326Sed DeclarationName N, QualType T, 516193326Sed bool isStatic, bool isInline) 517193326Sed : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None), 518193326Sed isInline) {} 519193326Sed 520193326Sedpublic: 521193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 522193326Sed SourceLocation L, DeclarationName N, 523193326Sed QualType T, bool isStatic = false, 524193326Sed bool isInline = false); 525193326Sed 526193326Sed bool isStatic() const { return getStorageClass() == Static; } 527193326Sed bool isInstance() const { return !isStatic(); } 528193326Sed 529193326Sed bool isVirtual() const { 530193326Sed return isVirtualAsWritten() || 531193326Sed (begin_overridden_methods() != end_overridden_methods()); 532193326Sed } 533193326Sed 534193326Sed /// 535193326Sed void addOverriddenMethod(const CXXMethodDecl *MD); 536193326Sed 537193326Sed typedef const CXXMethodDecl ** method_iterator; 538193326Sed 539193326Sed method_iterator begin_overridden_methods() const; 540193326Sed method_iterator end_overridden_methods() const; 541193326Sed 542193326Sed /// getParent - Returns the parent of this method declaration, which 543193326Sed /// is the class in which this method is defined. 544193326Sed const CXXRecordDecl *getParent() const { 545193326Sed return cast<CXXRecordDecl>(FunctionDecl::getParent()); 546193326Sed } 547193326Sed 548193326Sed /// getParent - Returns the parent of this method declaration, which 549193326Sed /// is the class in which this method is defined. 550193326Sed CXXRecordDecl *getParent() { 551193326Sed return const_cast<CXXRecordDecl *>( 552193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 553193326Sed } 554193326Sed 555193326Sed /// getThisType - Returns the type of 'this' pointer. 556193326Sed /// Should only be called for instance methods. 557193326Sed QualType getThisType(ASTContext &C) const; 558193326Sed 559193326Sed unsigned getTypeQualifiers() const { 560193326Sed return getType()->getAsFunctionProtoType()->getTypeQuals(); 561193326Sed } 562193326Sed 563193326Sed // Implement isa/cast/dyncast/etc. 564193326Sed static bool classof(const Decl *D) { 565193326Sed return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 566193326Sed } 567193326Sed static bool classof(const CXXMethodDecl *D) { return true; } 568193326Sed}; 569193326Sed 570193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member 571193326Sed/// initializer, which is part of a constructor initializer that 572193326Sed/// initializes one non-static member variable or one base class. For 573193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 574193326Sed/// initializers: 575193326Sed/// 576193326Sed/// @code 577193326Sed/// class A { }; 578193326Sed/// class B : public A { 579193326Sed/// float f; 580193326Sed/// public: 581193326Sed/// B(A& a) : A(a), f(3.14159) { } 582193326Sed/// }; 583194613Sed/// @endcode 584193326Sedclass CXXBaseOrMemberInitializer { 585193326Sed /// BaseOrMember - This points to the entity being initialized, 586193326Sed /// which is either a base class (a Type) or a non-static data 587193326Sed /// member. When the low bit is 1, it's a base 588193326Sed /// class; when the low bit is 0, it's a member. 589193326Sed uintptr_t BaseOrMember; 590193326Sed 591193326Sed /// Args - The arguments used to initialize the base or member. 592193326Sed Expr **Args; 593193326Sed unsigned NumArgs; 594195341Sed 595195341Sed /// IdLoc - Location of the id in ctor-initializer list. 596195341Sed SourceLocation IdLoc; 597193326Sed 598193326Sedpublic: 599193326Sed /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 600193326Sed explicit 601195341Sed CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, 602195341Sed SourceLocation L); 603193326Sed 604193326Sed /// CXXBaseOrMemberInitializer - Creates a new member initializer. 605193326Sed explicit 606195341Sed CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, 607195341Sed SourceLocation L); 608193326Sed 609193326Sed /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer. 610193326Sed ~CXXBaseOrMemberInitializer(); 611193326Sed 612193326Sed /// arg_iterator - Iterates through the member initialization 613193326Sed /// arguments. 614193326Sed typedef Expr **arg_iterator; 615193326Sed 616193326Sed /// arg_const_iterator - Iterates through the member initialization 617193326Sed /// arguments. 618193326Sed typedef Expr * const * arg_const_iterator; 619193326Sed 620195341Sed /// getBaseOrMember - get the generic 'member' representing either the field 621195341Sed /// or a base class. 622195341Sed void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); } 623195341Sed 624193326Sed /// isBaseInitializer - Returns true when this initializer is 625193326Sed /// initializing a base class. 626193326Sed bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; } 627193326Sed 628193326Sed /// isMemberInitializer - Returns true when this initializer is 629193326Sed /// initializing a non-static data member. 630193326Sed bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; } 631193326Sed 632193326Sed /// getBaseClass - If this is a base class initializer, returns the 633193326Sed /// type used to specify the initializer. The resulting type will be 634193326Sed /// a class type or a typedef of a class type. If this is not a base 635193326Sed /// class initializer, returns NULL. 636193326Sed Type *getBaseClass() { 637193326Sed if (isBaseInitializer()) 638193326Sed return reinterpret_cast<Type*>(BaseOrMember & ~0x01); 639193326Sed else 640193326Sed return 0; 641193326Sed } 642193326Sed 643193326Sed /// getBaseClass - If this is a base class initializer, returns the 644193326Sed /// type used to specify the initializer. The resulting type will be 645193326Sed /// a class type or a typedef of a class type. If this is not a base 646193326Sed /// class initializer, returns NULL. 647193326Sed const Type *getBaseClass() const { 648193326Sed if (isBaseInitializer()) 649193326Sed return reinterpret_cast<const Type*>(BaseOrMember & ~0x01); 650193326Sed else 651193326Sed return 0; 652193326Sed } 653193326Sed 654193326Sed /// getMember - If this is a member initializer, returns the 655193326Sed /// declaration of the non-static data member being 656193326Sed /// initialized. Otherwise, returns NULL. 657193326Sed FieldDecl *getMember() { 658193326Sed if (isMemberInitializer()) 659193326Sed return reinterpret_cast<FieldDecl *>(BaseOrMember); 660193326Sed else 661193326Sed return 0; 662193326Sed } 663193326Sed 664195341Sed SourceLocation getSourceLocation() const { return IdLoc; } 665195341Sed 666193326Sed /// begin() - Retrieve an iterator to the first initializer argument. 667193326Sed arg_iterator begin() { return Args; } 668193326Sed /// begin() - Retrieve an iterator to the first initializer argument. 669193326Sed arg_const_iterator begin() const { return Args; } 670193326Sed 671193326Sed /// end() - Retrieve an iterator past the last initializer argument. 672193326Sed arg_iterator end() { return Args + NumArgs; } 673193326Sed /// end() - Retrieve an iterator past the last initializer argument. 674193326Sed arg_const_iterator end() const { return Args + NumArgs; } 675193326Sed 676193326Sed /// getNumArgs - Determine the number of arguments used to 677193326Sed /// initialize the member or base. 678193326Sed unsigned getNumArgs() const { return NumArgs; } 679193326Sed}; 680193326Sed 681193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a 682193326Sed/// class. For example: 683193326Sed/// 684193326Sed/// @code 685193326Sed/// class X { 686193326Sed/// public: 687193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 688193326Sed/// }; 689193326Sed/// @endcode 690193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 691193326Sed /// Explicit - Whether this constructor is explicit. 692193326Sed bool Explicit : 1; 693193326Sed 694193326Sed /// ImplicitlyDefined - Whether this constructor was implicitly 695193326Sed /// defined by the compiler. When false, the constructor was defined 696193326Sed /// by the user. In C++03, this flag will have the same value as 697193326Sed /// Implicit. In C++0x, however, a constructor that is 698193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 699193326Sed /// @c !Implicit && ImplicitlyDefined. 700193326Sed bool ImplicitlyDefined : 1; 701194613Sed 702195341Sed /// Support for base and member initializers. 703195341Sed /// BaseOrMemberInitializers - The arguments used to initialize the base 704195341Sed /// or member. 705195341Sed CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 706195341Sed unsigned NumBaseOrMemberInitializers; 707195341Sed 708193326Sed CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 709193326Sed DeclarationName N, QualType T, 710193326Sed bool isExplicit, bool isInline, bool isImplicitlyDeclared) 711193326Sed : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline), 712195341Sed Explicit(isExplicit), ImplicitlyDefined(false), 713195341Sed BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 714193326Sed setImplicit(isImplicitlyDeclared); 715193326Sed } 716195341Sed virtual void Destroy(ASTContext& C); 717195341Sed 718193326Sedpublic: 719193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 720193326Sed SourceLocation L, DeclarationName N, 721193326Sed QualType T, bool isExplicit, 722193326Sed bool isInline, bool isImplicitlyDeclared); 723193326Sed 724193326Sed /// isExplicit - Whether this constructor was marked "explicit" or not. 725193326Sed bool isExplicit() const { return Explicit; } 726193326Sed 727193326Sed /// isImplicitlyDefined - Whether this constructor was implicitly 728193326Sed /// defined. If false, then this constructor was defined by the 729193326Sed /// user. This operation can only be invoked if the constructor has 730193326Sed /// already been defined. 731193326Sed bool isImplicitlyDefined(ASTContext &C) const { 732193326Sed assert(isThisDeclarationADefinition() && 733195341Sed "Can only get the implicit-definition flag once the " 734195341Sed "constructor has been defined"); 735193326Sed return ImplicitlyDefined; 736193326Sed } 737193326Sed 738193326Sed /// setImplicitlyDefined - Set whether this constructor was 739193326Sed /// implicitly defined or not. 740193326Sed void setImplicitlyDefined(bool ID) { 741193326Sed assert(isThisDeclarationADefinition() && 742195341Sed "Can only set the implicit-definition flag once the constructor " 743195341Sed "has been defined"); 744193326Sed ImplicitlyDefined = ID; 745193326Sed } 746194613Sed 747195341Sed /// init_iterator - Iterates through the member/base initializer list. 748195341Sed typedef CXXBaseOrMemberInitializer **init_iterator; 749195341Sed 750195341Sed /// init_const_iterator - Iterates through the memberbase initializer list. 751195341Sed typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 752195341Sed 753195341Sed /// begin() - Retrieve an iterator to the first initializer. 754195341Sed init_iterator begin() { return BaseOrMemberInitializers; } 755195341Sed /// begin() - Retrieve an iterator to the first initializer. 756195341Sed init_const_iterator begin() const { return BaseOrMemberInitializers; } 757195341Sed 758195341Sed /// end() - Retrieve an iterator past the last initializer. 759195341Sed init_iterator end() { 760195341Sed return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 761195341Sed } 762195341Sed /// end() - Retrieve an iterator past the last initializer. 763195341Sed init_const_iterator end() const { 764195341Sed return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 765195341Sed } 766195341Sed 767195341Sed /// getNumArgs - Determine the number of arguments used to 768195341Sed /// initialize the member or base. 769195341Sed unsigned getNumBaseOrMemberInitializers() const { 770195341Sed return NumBaseOrMemberInitializers; 771195341Sed } 772195341Sed 773195341Sed void setBaseOrMemberInitializers(ASTContext &C, 774195341Sed CXXBaseOrMemberInitializer **Initializers, 775195341Sed unsigned NumInitializers); 776195341Sed 777193326Sed /// isDefaultConstructor - Whether this constructor is a default 778193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 779193326Sed /// default-initialize a class of this type. 780193326Sed bool isDefaultConstructor() const; 781193326Sed 782193326Sed /// isCopyConstructor - Whether this constructor is a copy 783193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 784193326Sed /// class. @p TypeQuals will be set to the qualifiers on the 785193326Sed /// argument type. For example, @p TypeQuals would be set to @c 786193326Sed /// QualType::Const for the following copy constructor: 787193326Sed /// 788193326Sed /// @code 789193326Sed /// class X { 790193326Sed /// public: 791193326Sed /// X(const X&); 792193326Sed /// }; 793193326Sed /// @endcode 794193326Sed bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 795193326Sed 796193326Sed /// isCopyConstructor - Whether this constructor is a copy 797193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 798193326Sed /// class. 799193326Sed bool isCopyConstructor(ASTContext &Context) const { 800193326Sed unsigned TypeQuals = 0; 801193326Sed return isCopyConstructor(Context, TypeQuals); 802193326Sed } 803193326Sed 804193326Sed /// isConvertingConstructor - Whether this constructor is a 805193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 806193326Sed /// used for user-defined conversions. 807193326Sed bool isConvertingConstructor() const; 808193326Sed 809193326Sed // Implement isa/cast/dyncast/etc. 810193326Sed static bool classof(const Decl *D) { 811193326Sed return D->getKind() == CXXConstructor; 812193326Sed } 813193326Sed static bool classof(const CXXConstructorDecl *D) { return true; } 814193326Sed}; 815193326Sed 816193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a 817193326Sed/// class. For example: 818193326Sed/// 819193326Sed/// @code 820193326Sed/// class X { 821193326Sed/// public: 822193326Sed/// ~X(); // represented by a CXXDestructorDecl. 823193326Sed/// }; 824193326Sed/// @endcode 825193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 826193326Sed /// ImplicitlyDefined - Whether this destructor was implicitly 827193326Sed /// defined by the compiler. When false, the destructor was defined 828193326Sed /// by the user. In C++03, this flag will have the same value as 829193326Sed /// Implicit. In C++0x, however, a destructor that is 830193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 831193326Sed /// @c !Implicit && ImplicitlyDefined. 832193326Sed bool ImplicitlyDefined : 1; 833193326Sed 834193326Sed CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 835193326Sed DeclarationName N, QualType T, 836193326Sed bool isInline, bool isImplicitlyDeclared) 837193326Sed : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline), 838193326Sed ImplicitlyDefined(false) { 839193326Sed setImplicit(isImplicitlyDeclared); 840193326Sed } 841193326Sed 842193326Sedpublic: 843193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 844193326Sed SourceLocation L, DeclarationName N, 845193326Sed QualType T, bool isInline, 846193326Sed bool isImplicitlyDeclared); 847193326Sed 848193326Sed /// isImplicitlyDefined - Whether this destructor was implicitly 849193326Sed /// defined. If false, then this destructor was defined by the 850193326Sed /// user. This operation can only be invoked if the destructor has 851193326Sed /// already been defined. 852193326Sed bool isImplicitlyDefined() const { 853193326Sed assert(isThisDeclarationADefinition() && 854193326Sed "Can only get the implicit-definition flag once the destructor has been defined"); 855193326Sed return ImplicitlyDefined; 856193326Sed } 857193326Sed 858193326Sed /// setImplicitlyDefined - Set whether this destructor was 859193326Sed /// implicitly defined or not. 860193326Sed void setImplicitlyDefined(bool ID) { 861193326Sed assert(isThisDeclarationADefinition() && 862193326Sed "Can only set the implicit-definition flag once the destructor has been defined"); 863193326Sed ImplicitlyDefined = ID; 864193326Sed } 865193326Sed 866193326Sed // Implement isa/cast/dyncast/etc. 867193326Sed static bool classof(const Decl *D) { 868193326Sed return D->getKind() == CXXDestructor; 869193326Sed } 870193326Sed static bool classof(const CXXDestructorDecl *D) { return true; } 871193326Sed}; 872193326Sed 873193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a 874193326Sed/// class. For example: 875193326Sed/// 876193326Sed/// @code 877193326Sed/// class X { 878193326Sed/// public: 879193326Sed/// operator bool(); 880193326Sed/// }; 881193326Sed/// @endcode 882193326Sedclass CXXConversionDecl : public CXXMethodDecl { 883193326Sed /// Explicit - Whether this conversion function is marked 884193326Sed /// "explicit", meaning that it can only be applied when the user 885193326Sed /// explicitly wrote a cast. This is a C++0x feature. 886193326Sed bool Explicit : 1; 887193326Sed 888193326Sed CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 889193326Sed DeclarationName N, QualType T, 890193326Sed bool isInline, bool isExplicit) 891193326Sed : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline), 892193326Sed Explicit(isExplicit) { } 893193326Sed 894193326Sedpublic: 895193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 896193326Sed SourceLocation L, DeclarationName N, 897193326Sed QualType T, bool isInline, 898193326Sed bool isExplicit); 899193326Sed 900193326Sed /// isExplicit - Whether this is an explicit conversion operator 901193326Sed /// (C++0x only). Explicit conversion operators are only considered 902193326Sed /// when the user has explicitly written a cast. 903193326Sed bool isExplicit() const { return Explicit; } 904193326Sed 905193326Sed /// getConversionType - Returns the type that this conversion 906193326Sed /// function is converting to. 907193326Sed QualType getConversionType() const { 908193326Sed return getType()->getAsFunctionType()->getResultType(); 909193326Sed } 910193326Sed 911193326Sed // Implement isa/cast/dyncast/etc. 912193326Sed static bool classof(const Decl *D) { 913193326Sed return D->getKind() == CXXConversion; 914193326Sed } 915193326Sed static bool classof(const CXXConversionDecl *D) { return true; } 916193326Sed}; 917193326Sed 918193326Sed/// LinkageSpecDecl - This represents a linkage specification. For example: 919193326Sed/// extern "C" void foo(); 920193326Sed/// 921193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 922193326Sedpublic: 923193326Sed /// LanguageIDs - Used to represent the language in a linkage 924193326Sed /// specification. The values are part of the serialization abi for 925193326Sed /// ASTs and cannot be changed without altering that abi. To help 926193326Sed /// ensure a stable abi for this, we choose the DW_LANG_ encodings 927193326Sed /// from the dwarf standard. 928193326Sed enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 929193326Sed lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 930193326Sedprivate: 931193326Sed /// Language - The language for this linkage specification. 932193326Sed LanguageIDs Language; 933193326Sed 934193326Sed /// HadBraces - Whether this linkage specification had curly braces or not. 935193326Sed bool HadBraces : 1; 936193326Sed 937193326Sed LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 938193326Sed bool Braces) 939193326Sed : Decl(LinkageSpec, DC, L), 940193326Sed DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 941193326Sed 942193326Sedpublic: 943193326Sed static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 944193326Sed SourceLocation L, LanguageIDs Lang, 945193326Sed bool Braces); 946193326Sed 947193326Sed LanguageIDs getLanguage() const { return Language; } 948193326Sed 949193326Sed /// hasBraces - Determines whether this linkage specification had 950193326Sed /// braces in its syntactic form. 951193326Sed bool hasBraces() const { return HadBraces; } 952193326Sed 953193326Sed static bool classof(const Decl *D) { 954193326Sed return D->getKind() == LinkageSpec; 955193326Sed } 956193326Sed static bool classof(const LinkageSpecDecl *D) { return true; } 957193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 958193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 959193326Sed } 960193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 961193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 962193326Sed } 963193326Sed}; 964193326Sed 965193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example: 966193326Sed/// 967193326Sed/// using namespace std; 968193326Sed/// 969193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 970193326Sed// artificial name, for all using-directives in order to store 971193326Sed// them in DeclContext effectively. 972193326Sedclass UsingDirectiveDecl : public NamedDecl { 973193326Sed 974193326Sed /// SourceLocation - Location of 'namespace' token. 975193326Sed SourceLocation NamespaceLoc; 976193326Sed 977193326Sed /// \brief The source range that covers the nested-name-specifier 978193326Sed /// preceding the namespace name. 979193326Sed SourceRange QualifierRange; 980193326Sed 981193326Sed /// \brief The nested-name-specifier that precedes the namespace 982193326Sed /// name, if any. 983193326Sed NestedNameSpecifier *Qualifier; 984193326Sed 985193326Sed /// IdentLoc - Location of nominated namespace-name identifier. 986193326Sed // FIXME: We don't store location of scope specifier. 987193326Sed SourceLocation IdentLoc; 988193326Sed 989193326Sed /// NominatedNamespace - Namespace nominated by using-directive. 990193326Sed NamespaceDecl *NominatedNamespace; 991193326Sed 992193326Sed /// Enclosing context containing both using-directive and nomintated 993193326Sed /// namespace. 994193326Sed DeclContext *CommonAncestor; 995193326Sed 996193326Sed /// getUsingDirectiveName - Returns special DeclarationName used by 997193326Sed /// using-directives. This is only used by DeclContext for storing 998193326Sed /// UsingDirectiveDecls in its lookup structure. 999193326Sed static DeclarationName getName() { 1000193326Sed return DeclarationName::getUsingDirectiveName(); 1001193326Sed } 1002193326Sed 1003193326Sed UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1004193326Sed SourceLocation NamespcLoc, 1005193326Sed SourceRange QualifierRange, 1006193326Sed NestedNameSpecifier *Qualifier, 1007193326Sed SourceLocation IdentLoc, 1008193326Sed NamespaceDecl *Nominated, 1009193326Sed DeclContext *CommonAncestor) 1010193326Sed : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1011193326Sed NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1012193326Sed Qualifier(Qualifier), IdentLoc(IdentLoc), 1013193326Sed NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0), 1014193326Sed CommonAncestor(CommonAncestor) { 1015193326Sed } 1016193326Sed 1017193326Sedpublic: 1018193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1019193326Sed /// that qualifiers the namespace name. 1020193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1021193326Sed 1022193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1023193326Sed /// name of the namespace. 1024193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1025193326Sed 1026193326Sed /// getNominatedNamespace - Returns namespace nominated by using-directive. 1027193326Sed NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; } 1028193326Sed 1029193326Sed const NamespaceDecl *getNominatedNamespace() const { 1030193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1031193326Sed } 1032193326Sed 1033193326Sed /// getCommonAncestor - returns common ancestor context of using-directive, 1034193326Sed /// and nominated by it namespace. 1035193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 1036193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1037193326Sed 1038193326Sed /// getNamespaceKeyLocation - Returns location of namespace keyword. 1039193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1040193326Sed 1041193326Sed /// getIdentLocation - Returns location of identifier. 1042193326Sed SourceLocation getIdentLocation() const { return IdentLoc; } 1043193326Sed 1044193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1045193326Sed SourceLocation L, 1046193326Sed SourceLocation NamespaceLoc, 1047193326Sed SourceRange QualifierRange, 1048193326Sed NestedNameSpecifier *Qualifier, 1049193326Sed SourceLocation IdentLoc, 1050193326Sed NamespaceDecl *Nominated, 1051193326Sed DeclContext *CommonAncestor); 1052193326Sed 1053193326Sed static bool classof(const Decl *D) { 1054193326Sed return D->getKind() == Decl::UsingDirective; 1055193326Sed } 1056193326Sed static bool classof(const UsingDirectiveDecl *D) { return true; } 1057193326Sed 1058193326Sed // Friend for getUsingDirectiveName. 1059193326Sed friend class DeclContext; 1060193326Sed}; 1061193326Sed 1062193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1063193326Sed/// 1064193326Sed/// @code 1065193326Sed/// namespace Foo = Bar; 1066193326Sed/// @endcode 1067193326Sedclass NamespaceAliasDecl : public NamedDecl { 1068193326Sed SourceLocation AliasLoc; 1069193326Sed 1070193326Sed /// \brief The source range that covers the nested-name-specifier 1071193326Sed /// preceding the namespace name. 1072193326Sed SourceRange QualifierRange; 1073193326Sed 1074193326Sed /// \brief The nested-name-specifier that precedes the namespace 1075193326Sed /// name, if any. 1076193326Sed NestedNameSpecifier *Qualifier; 1077193326Sed 1078193326Sed /// IdentLoc - Location of namespace identifier. 1079193326Sed SourceLocation IdentLoc; 1080193326Sed 1081193326Sed /// Namespace - The Decl that this alias points to. Can either be a 1082193326Sed /// NamespaceDecl or a NamespaceAliasDecl. 1083193326Sed NamedDecl *Namespace; 1084193326Sed 1085193326Sed NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1086193326Sed SourceLocation AliasLoc, IdentifierInfo *Alias, 1087193326Sed SourceRange QualifierRange, 1088193326Sed NestedNameSpecifier *Qualifier, 1089193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 1090193326Sed : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1091193326Sed QualifierRange(QualifierRange), Qualifier(Qualifier), 1092193326Sed IdentLoc(IdentLoc), Namespace(Namespace) { } 1093193326Sed 1094193326Sedpublic: 1095193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1096193326Sed /// that qualifiers the namespace name. 1097193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1098193326Sed 1099193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1100193326Sed /// name of the namespace. 1101193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1102193326Sed 1103193326Sed NamespaceDecl *getNamespace() { 1104193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1105193326Sed return AD->getNamespace(); 1106193326Sed 1107193326Sed return cast<NamespaceDecl>(Namespace); 1108193326Sed } 1109193326Sed 1110193326Sed const NamespaceDecl *getNamespace() const { 1111193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1112193326Sed } 1113193326Sed 1114193326Sed /// \brief Retrieve the namespace that this alias refers to, which 1115193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1116193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 1117193326Sed 1118193326Sed static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1119193326Sed SourceLocation L, SourceLocation AliasLoc, 1120193326Sed IdentifierInfo *Alias, 1121193326Sed SourceRange QualifierRange, 1122193326Sed NestedNameSpecifier *Qualifier, 1123193326Sed SourceLocation IdentLoc, 1124193326Sed NamedDecl *Namespace); 1125193326Sed 1126193326Sed static bool classof(const Decl *D) { 1127193326Sed return D->getKind() == Decl::NamespaceAlias; 1128193326Sed } 1129193326Sed static bool classof(const NamespaceAliasDecl *D) { return true; } 1130193326Sed}; 1131194613Sed 1132194613Sed/// UsingDecl - Represents a C++ using-declaration. For example: 1133194613Sed/// using someNameSpace::someIdentifier; 1134194613Sedclass UsingDecl : public NamedDecl { 1135194613Sed 1136194613Sed /// \brief The source range that covers the nested-name-specifier 1137194613Sed /// preceding the declaration name. 1138194613Sed SourceRange NestedNameRange; 1139194613Sed /// \brief The source location of the target declaration name. 1140194613Sed SourceLocation TargetNameLocation; 1141194613Sed /// \brief The source location of the "using" location itself. 1142194613Sed SourceLocation UsingLocation; 1143194613Sed /// \brief Target declaration. 1144194613Sed NamedDecl* TargetDecl; 1145194613Sed /// \brief Target declaration. 1146194613Sed NestedNameSpecifier* TargetNestedNameDecl; 1147194613Sed 1148194613Sed // Had 'typename' keyword. 1149194613Sed bool IsTypeName; 1150194613Sed 1151194613Sed UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1152194613Sed SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target, 1153194613Sed NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) 1154194613Sed : NamedDecl(Decl::Using, DC, L, Target->getDeclName()), 1155194613Sed NestedNameRange(NNR), TargetNameLocation(TargetNL), 1156194613Sed UsingLocation(UL), TargetDecl(Target), 1157194613Sed TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { 1158194613Sed this->IdentifierNamespace = TargetDecl->getIdentifierNamespace(); 1159194613Sed } 1160194613Sed 1161194613Sedpublic: 1162194613Sed /// \brief Returns the source range that covers the nested-name-specifier 1163194613Sed /// preceding the namespace name. 1164195099Sed SourceRange getNestedNameRange() { return NestedNameRange; } 1165195099Sed 1166194613Sed /// \brief Returns the source location of the target declaration name. 1167195099Sed SourceLocation getTargetNameLocation() { return TargetNameLocation; } 1168195099Sed 1169194613Sed /// \brief Returns the source location of the "using" location itself. 1170195099Sed SourceLocation getUsingLocation() { return UsingLocation; } 1171195099Sed 1172194613Sed /// \brief getTargetDecl - Returns target specified by using-decl. 1173195099Sed NamedDecl *getTargetDecl() { return TargetDecl; } 1174195099Sed const NamedDecl *getTargetDecl() const { return TargetDecl; } 1175195099Sed 1176194613Sed /// \brief Get target nested name declaration. 1177195099Sed NestedNameSpecifier* getTargetNestedNameDecl() { 1178195099Sed return TargetNestedNameDecl; 1179195099Sed } 1180195099Sed 1181194613Sed /// isTypeName - Return true if using decl had 'typename'. 1182195099Sed bool isTypeName() const { return IsTypeName; } 1183194613Sed 1184194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1185194613Sed SourceLocation L, SourceRange NNR, SourceLocation TargetNL, 1186194613Sed SourceLocation UL, NamedDecl* Target, 1187194613Sed NestedNameSpecifier* TargetNNS, bool IsTypeNameArg); 1188194613Sed 1189194613Sed static bool classof(const Decl *D) { 1190194613Sed return D->getKind() == Decl::Using; 1191194613Sed } 1192194613Sed static bool classof(const UsingDecl *D) { return true; } 1193194613Sed}; 1194193326Sed 1195193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1196193326Sedclass StaticAssertDecl : public Decl { 1197193326Sed Expr *AssertExpr; 1198193326Sed StringLiteral *Message; 1199193326Sed 1200193326Sed StaticAssertDecl(DeclContext *DC, SourceLocation L, 1201193326Sed Expr *assertexpr, StringLiteral *message) 1202193326Sed : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1203193326Sed 1204193326Sedpublic: 1205193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1206193326Sed SourceLocation L, Expr *AssertExpr, 1207193326Sed StringLiteral *Message); 1208193326Sed 1209193326Sed Expr *getAssertExpr() { return AssertExpr; } 1210193326Sed const Expr *getAssertExpr() const { return AssertExpr; } 1211193326Sed 1212193326Sed StringLiteral *getMessage() { return Message; } 1213193326Sed const StringLiteral *getMessage() const { return Message; } 1214193326Sed 1215193326Sed virtual ~StaticAssertDecl(); 1216193326Sed virtual void Destroy(ASTContext& C); 1217193326Sed 1218193326Sed static bool classof(const Decl *D) { 1219193326Sed return D->getKind() == Decl::StaticAssert; 1220193326Sed } 1221193326Sed static bool classof(StaticAssertDecl *D) { return true; } 1222193326Sed}; 1223193326Sed 1224193326Sed/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1225193326Sed/// into a diagnostic with <<. 1226193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1227193326Sed AccessSpecifier AS); 1228193326Sed 1229193326Sed} // end namespace clang 1230193326Sed 1231193326Sed#endif 1232