DeclCXX.h revision 199482
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 17198092Srdivacky#include "clang/AST/Expr.h" 18193326Sed#include "clang/AST/Decl.h" 19193326Sed#include "llvm/ADT/SmallVector.h" 20198092Srdivacky#include "llvm/ADT/SmallPtrSet.h" 21193326Sed 22193326Sednamespace clang { 23193326Sed 24193326Sedclass ClassTemplateDecl; 25198092Srdivackyclass ClassTemplateSpecializationDecl; 26198092Srdivackyclass CXXBasePath; 27198092Srdivackyclass CXXBasePaths; 28193326Sedclass CXXConstructorDecl; 29198092Srdivackyclass CXXConversionDecl; 30193326Sedclass CXXDestructorDecl; 31193326Sedclass CXXMethodDecl; 32198092Srdivackyclass CXXRecordDecl; 33198092Srdivackyclass CXXMemberLookupCriteria; 34198092Srdivacky 35198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a 36195099Sed/// concrete function or a function template. 37195099Sedclass AnyFunctionDecl { 38195099Sed NamedDecl *Function; 39198092Srdivacky 40195341Sed AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 41198092Srdivacky 42195099Sedpublic: 43195099Sed AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 44195099Sed AnyFunctionDecl(FunctionTemplateDecl *FTD); 45198092Srdivacky 46198092Srdivacky /// \brief Implicily converts any function or function template into a 47195099Sed /// named declaration. 48195099Sed operator NamedDecl *() const { return Function; } 49198092Srdivacky 50195099Sed /// \brief Retrieve the underlying function or function template. 51195099Sed NamedDecl *get() const { return Function; } 52198092Srdivacky 53198092Srdivacky static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 54195341Sed return AnyFunctionDecl(ND); 55195341Sed } 56195099Sed}; 57198092Srdivacky 58195099Sed} // end namespace clang 59195099Sed 60195099Sednamespace llvm { 61198092Srdivacky /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 62195099Sed /// AnyFunctionDecl to any function or function template declaration. 63195099Sed template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 64195099Sed typedef ::clang::NamedDecl* SimpleType; 65195099Sed static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 66195099Sed return Val; 67195099Sed } 68195099Sed }; 69195099Sed template<> struct simplify_type< ::clang::AnyFunctionDecl> 70195099Sed : public simplify_type<const ::clang::AnyFunctionDecl> {}; 71198092Srdivacky 72195341Sed // Provide PointerLikeTypeTraits for non-cvr pointers. 73195341Sed template<> 74195341Sed class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 75195341Sed public: 76195341Sed static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 77198092Srdivacky return F.get(); 78195341Sed } 79195341Sed static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 80195341Sed return ::clang::AnyFunctionDecl::getFromNamedDecl( 81195341Sed static_cast< ::clang::NamedDecl*>(P)); 82195341Sed } 83198092Srdivacky 84195341Sed enum { NumLowBitsAvailable = 2 }; 85195341Sed }; 86198092Srdivacky 87195099Sed} // end namespace llvm 88195099Sed 89195099Sednamespace clang { 90198092Srdivacky 91193326Sed/// OverloadedFunctionDecl - An instance of this class represents a 92193326Sed/// set of overloaded functions. All of the functions have the same 93193326Sed/// name and occur within the same scope. 94193326Sed/// 95193326Sed/// An OverloadedFunctionDecl has no ownership over the FunctionDecl 96193326Sed/// nodes it contains. Rather, the FunctionDecls are owned by the 97193326Sed/// enclosing scope (which also owns the OverloadedFunctionDecl 98193326Sed/// node). OverloadedFunctionDecl is used primarily to store a set of 99193326Sed/// overloaded functions for name lookup. 100193326Sedclass OverloadedFunctionDecl : public NamedDecl { 101193326Sedprotected: 102193326Sed OverloadedFunctionDecl(DeclContext *DC, DeclarationName N) 103193326Sed : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { } 104193326Sed 105193326Sed /// Functions - the set of overloaded functions contained in this 106193326Sed /// overload set. 107195099Sed llvm::SmallVector<AnyFunctionDecl, 4> Functions; 108193326Sed 109193326Sed // FIXME: This should go away when we stop using 110193326Sed // OverloadedFunctionDecl to store conversions in CXXRecordDecl. 111193326Sed friend class CXXRecordDecl; 112193326Sed 113193326Sedpublic: 114195099Sed typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator; 115195099Sed typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator 116193326Sed function_const_iterator; 117193326Sed 118193326Sed static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC, 119193326Sed DeclarationName N); 120193326Sed 121195341Sed /// \brief Add a new overloaded function or function template to the set 122195341Sed /// of overloaded function templates. 123195341Sed void addOverload(AnyFunctionDecl F); 124193326Sed 125193326Sed function_iterator function_begin() { return Functions.begin(); } 126193326Sed function_iterator function_end() { return Functions.end(); } 127193326Sed function_const_iterator function_begin() const { return Functions.begin(); } 128193326Sed function_const_iterator function_end() const { return Functions.end(); } 129193326Sed 130195099Sed /// \brief Returns the number of overloaded functions stored in 131193326Sed /// this set. 132195099Sed unsigned size() const { return Functions.size(); } 133193326Sed 134193326Sed // Implement isa/cast/dyncast/etc. 135198092Srdivacky static bool classof(const Decl *D) { 136198092Srdivacky return D->getKind() == OverloadedFunction; 137193326Sed } 138193326Sed static bool classof(const OverloadedFunctionDecl *D) { return true; } 139193326Sed}; 140193326Sed 141198092Srdivacky/// \brief Provides uniform iteration syntax for an overload set, function, 142198092Srdivacky/// or function template. 143198092Srdivackyclass OverloadIterator { 144198092Srdivacky /// \brief An overloaded function set, function declaration, or 145198092Srdivacky /// function template declaration. 146198092Srdivacky NamedDecl *D; 147198092Srdivacky 148198092Srdivacky /// \brief If the declaration is an overloaded function set, this is the 149198092Srdivacky /// iterator pointing to the current position within that overloaded 150198092Srdivacky /// function set. 151198092Srdivacky OverloadedFunctionDecl::function_iterator Iter; 152198092Srdivacky 153198092Srdivackypublic: 154198092Srdivacky typedef AnyFunctionDecl value_type; 155198092Srdivacky typedef value_type reference; 156198092Srdivacky typedef NamedDecl *pointer; 157198092Srdivacky typedef int difference_type; 158198092Srdivacky typedef std::forward_iterator_tag iterator_category; 159198092Srdivacky 160198092Srdivacky OverloadIterator() : D(0) { } 161198092Srdivacky 162198092Srdivacky OverloadIterator(FunctionDecl *FD) : D(FD) { } 163198092Srdivacky OverloadIterator(FunctionTemplateDecl *FTD) 164198092Srdivacky : D(reinterpret_cast<NamedDecl*>(FTD)) { } 165198092Srdivacky OverloadIterator(OverloadedFunctionDecl *Ovl) 166198092Srdivacky : D(Ovl), Iter(Ovl->function_begin()) { } 167198092Srdivacky 168198092Srdivacky OverloadIterator(NamedDecl *ND); 169198092Srdivacky 170198092Srdivacky reference operator*() const; 171198092Srdivacky 172198092Srdivacky pointer operator->() const { return (**this).get(); } 173198092Srdivacky 174198092Srdivacky OverloadIterator &operator++(); 175198092Srdivacky 176198092Srdivacky OverloadIterator operator++(int) { 177198092Srdivacky OverloadIterator Temp(*this); 178198092Srdivacky ++(*this); 179198092Srdivacky return Temp; 180198092Srdivacky } 181198092Srdivacky 182198092Srdivacky bool Equals(const OverloadIterator &Other) const; 183198092Srdivacky}; 184198092Srdivacky 185198092Srdivackyinline bool operator==(const OverloadIterator &X, const OverloadIterator &Y) { 186198092Srdivacky return X.Equals(Y); 187198092Srdivacky} 188198092Srdivacky 189198092Srdivackyinline bool operator!=(const OverloadIterator &X, const OverloadIterator &Y) { 190198092Srdivacky return !(X == Y); 191198092Srdivacky} 192198092Srdivacky 193193326Sed/// CXXBaseSpecifier - A base class of a C++ class. 194193326Sed/// 195193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 196193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 197193326Sed/// base class, whether it is a virtual or non-virtual base, and what 198193326Sed/// level of access (public, protected, private) is used for the 199193326Sed/// derivation. For example: 200193326Sed/// 201193326Sed/// @code 202193326Sed/// class A { }; 203193326Sed/// class B { }; 204193326Sed/// class C : public virtual A, protected B { }; 205193326Sed/// @endcode 206193326Sed/// 207193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 208193326Sed/// virtual A" and the other for "protected B". 209193326Sedclass CXXBaseSpecifier { 210193326Sed /// Range - The source code range that covers the full base 211193326Sed /// specifier, including the "virtual" (if present) and access 212193326Sed /// specifier (if present). 213193326Sed SourceRange Range; 214193326Sed 215193326Sed /// Virtual - Whether this is a virtual base class or not. 216193326Sed bool Virtual : 1; 217193326Sed 218193326Sed /// BaseOfClass - Whether this is the base of a class (true) or of a 219193326Sed /// struct (false). This determines the mapping from the access 220193326Sed /// specifier as written in the source code to the access specifier 221193326Sed /// used for semantic analysis. 222198092Srdivacky bool BaseOfClass : 1; 223193326Sed 224193326Sed /// Access - Access specifier as written in the source code (which 225193326Sed /// may be AS_none). The actual type of data stored here is an 226193326Sed /// AccessSpecifier, but we use "unsigned" here to work around a 227193326Sed /// VC++ bug. 228193326Sed unsigned Access : 2; 229193326Sed 230193326Sed /// BaseType - The type of the base class. This will be a class or 231193326Sed /// struct (or a typedef of such). 232193326Sed QualType BaseType; 233198092Srdivacky 234193326Sedpublic: 235193326Sed CXXBaseSpecifier() { } 236193326Sed 237193326Sed CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 238193326Sed : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 239193326Sed 240193326Sed /// getSourceRange - Retrieves the source range that contains the 241193326Sed /// entire base specifier. 242193326Sed SourceRange getSourceRange() const { return Range; } 243198092Srdivacky 244193326Sed /// isVirtual - Determines whether the base class is a virtual base 245193326Sed /// class (or not). 246193326Sed bool isVirtual() const { return Virtual; } 247193326Sed 248193326Sed /// getAccessSpecifier - Returns the access specifier for this base 249193326Sed /// specifier. This is the actual base specifier as used for 250193326Sed /// semantic analysis, so the result can never be AS_none. To 251193326Sed /// retrieve the access specifier as written in the source code, use 252193326Sed /// getAccessSpecifierAsWritten(). 253198092Srdivacky AccessSpecifier getAccessSpecifier() const { 254193326Sed if ((AccessSpecifier)Access == AS_none) 255193326Sed return BaseOfClass? AS_private : AS_public; 256193326Sed else 257198092Srdivacky return (AccessSpecifier)Access; 258193326Sed } 259193326Sed 260193326Sed /// getAccessSpecifierAsWritten - Retrieves the access specifier as 261193326Sed /// written in the source code (which may mean that no access 262193326Sed /// specifier was explicitly written). Use getAccessSpecifier() to 263193326Sed /// retrieve the access specifier for use in semantic analysis. 264193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 265193326Sed return (AccessSpecifier)Access; 266193326Sed } 267193326Sed 268193326Sed /// getType - Retrieves the type of the base class. This type will 269193326Sed /// always be an unqualified class type. 270193326Sed QualType getType() const { return BaseType; } 271193326Sed}; 272193326Sed 273193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class. 274193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 275193326Sed/// to deal with C++-specific things. 276193326Sedclass CXXRecordDecl : public RecordDecl { 277193326Sed /// UserDeclaredConstructor - True when this class has a 278198092Srdivacky /// user-declared constructor. 279193326Sed bool UserDeclaredConstructor : 1; 280193326Sed 281193326Sed /// UserDeclaredCopyConstructor - True when this class has a 282193326Sed /// user-declared copy constructor. 283193326Sed bool UserDeclaredCopyConstructor : 1; 284193326Sed 285193326Sed /// UserDeclaredCopyAssignment - True when this class has a 286193326Sed /// user-declared copy assignment operator. 287193326Sed bool UserDeclaredCopyAssignment : 1; 288193326Sed 289193326Sed /// UserDeclaredDestructor - True when this class has a 290193326Sed /// user-declared destructor. 291193326Sed bool UserDeclaredDestructor : 1; 292193326Sed 293193326Sed /// Aggregate - True when this class is an aggregate. 294193326Sed bool Aggregate : 1; 295193326Sed 296193326Sed /// PlainOldData - True when this class is a POD-type. 297193326Sed bool PlainOldData : 1; 298193326Sed 299198092Srdivacky /// Empty - true when this class is empty for traits purposes, i.e. has no 300198092Srdivacky /// data members other than 0-width bit-fields, has no virtual function/base, 301198092Srdivacky /// and doesn't inherit from a non-empty class. Doesn't take union-ness into 302198092Srdivacky /// account. 303198092Srdivacky bool Empty : 1; 304198092Srdivacky 305193326Sed /// Polymorphic - True when this class is polymorphic, i.e. has at least one 306193326Sed /// virtual member or derives from a polymorphic class. 307193326Sed bool Polymorphic : 1; 308193326Sed 309193326Sed /// Abstract - True when this class is abstract, i.e. has at least one 310193326Sed /// pure virtual function, (that can come from a base class). 311193326Sed bool Abstract : 1; 312198092Srdivacky 313198092Srdivacky /// HasTrivialConstructor - True when this class has a trivial constructor. 314198092Srdivacky /// 315198092Srdivacky /// C++ [class.ctor]p5. A constructor is trivial if it is an 316198092Srdivacky /// implicitly-declared default constructor and if: 317198092Srdivacky /// * its class has no virtual functions and no virtual base classes, and 318198092Srdivacky /// * all the direct base classes of its class have trivial constructors, and 319198092Srdivacky /// * for all the nonstatic data members of its class that are of class type 320198092Srdivacky /// (or array thereof), each such class has a trivial constructor. 321193326Sed bool HasTrivialConstructor : 1; 322198092Srdivacky 323198092Srdivacky /// HasTrivialCopyConstructor - True when this class has a trivial copy 324198092Srdivacky /// constructor. 325198092Srdivacky /// 326198092Srdivacky /// C++ [class.copy]p6. A copy constructor for class X is trivial 327198092Srdivacky /// if it is implicitly declared and if 328198092Srdivacky /// * class X has no virtual functions and no virtual base classes, and 329198092Srdivacky /// * each direct base class of X has a trivial copy constructor, and 330198092Srdivacky /// * for all the nonstatic data members of X that are of class type (or 331198092Srdivacky /// array thereof), each such class type has a trivial copy constructor; 332198092Srdivacky /// otherwise the copy constructor is non-trivial. 333198092Srdivacky bool HasTrivialCopyConstructor : 1; 334198092Srdivacky 335198092Srdivacky /// HasTrivialCopyAssignment - True when this class has a trivial copy 336198092Srdivacky /// assignment operator. 337198092Srdivacky /// 338198092Srdivacky /// C++ [class.copy]p11. A copy assignment operator for class X is 339198092Srdivacky /// trivial if it is implicitly declared and if 340198092Srdivacky /// * class X has no virtual functions and no virtual base classes, and 341198092Srdivacky /// * each direct base class of X has a trivial copy assignment operator, and 342198092Srdivacky /// * for all the nonstatic data members of X that are of class type (or 343198092Srdivacky /// array thereof), each such class type has a trivial copy assignment 344198092Srdivacky /// operator; 345198092Srdivacky /// otherwise the copy assignment operator is non-trivial. 346198092Srdivacky bool HasTrivialCopyAssignment : 1; 347198092Srdivacky 348198092Srdivacky /// HasTrivialDestructor - True when this class has a trivial destructor. 349198092Srdivacky /// 350198092Srdivacky /// C++ [class.dtor]p3. A destructor is trivial if it is an 351198092Srdivacky /// implicitly-declared destructor and if: 352198092Srdivacky /// * all of the direct base classes of its class have trivial destructors 353198092Srdivacky /// and 354198092Srdivacky /// * for all of the non-static data members of its class that are of class 355198092Srdivacky /// type (or array thereof), each such class has a trivial destructor. 356193326Sed bool HasTrivialDestructor : 1; 357198092Srdivacky 358198092Srdivacky /// ComputedVisibleConversions - True when visible conversion functions are 359198092Srdivacky /// already computed and are available. 360198092Srdivacky bool ComputedVisibleConversions : 1; 361193326Sed 362193326Sed /// Bases - Base classes of this class. 363193326Sed /// FIXME: This is wasted space for a union. 364193326Sed CXXBaseSpecifier *Bases; 365193326Sed 366193326Sed /// NumBases - The number of base class specifiers in Bases. 367193326Sed unsigned NumBases; 368193326Sed 369198092Srdivacky /// VBases - direct and indirect virtual base classes of this class. 370198092Srdivacky CXXBaseSpecifier *VBases; 371198092Srdivacky 372198092Srdivacky /// NumVBases - The number of virtual base class specifiers in VBases. 373198092Srdivacky unsigned NumVBases; 374198092Srdivacky 375193326Sed /// Conversions - Overload set containing the conversion functions 376193326Sed /// of this C++ class (but not its inherited conversion 377193326Sed /// functions). Each of the entries in this overload set is a 378198092Srdivacky /// CXXConversionDecl. 379193326Sed OverloadedFunctionDecl Conversions; 380193326Sed 381198092Srdivacky /// VisibleConversions - Overload set containing the conversion functions 382198092Srdivacky /// of this C++ class and all those inherited conversion functions that 383198092Srdivacky /// are visible in this class. Each of the entries in this overload set is 384198092Srdivacky /// a CXXConversionDecl or a FunctionTemplateDecl. 385198092Srdivacky OverloadedFunctionDecl VisibleConversions; 386198092Srdivacky 387193326Sed /// \brief The template or declaration that this declaration 388193326Sed /// describes or was instantiated from, respectively. 389198092Srdivacky /// 390193326Sed /// For non-templates, this value will be NULL. For record 391193326Sed /// declarations that describe a class template, this will be a 392193326Sed /// pointer to a ClassTemplateDecl. For member 393193326Sed /// classes of class template specializations, this will be the 394198092Srdivacky /// MemberSpecializationInfo referring to the member class that was 395198092Srdivacky /// instantiated or specialized. 396198092Srdivacky llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 397193326Sed TemplateOrInstantiation; 398198092Srdivacky 399198092Srdivacky void getNestedVisibleConversionFunctions(CXXRecordDecl *RD, 400198092Srdivacky const llvm::SmallPtrSet<CanQualType, 8> &TopConversionsTypeSet, 401198092Srdivacky const llvm::SmallPtrSet<CanQualType, 8> &HiddenConversionTypes); 402198092Srdivacky void collectConversionFunctions( 403198092Srdivacky llvm::SmallPtrSet<CanQualType, 8>& ConversionsTypeSet); 404198092Srdivacky 405193326Sedprotected: 406193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 407198092Srdivacky SourceLocation L, IdentifierInfo *Id, 408198092Srdivacky CXXRecordDecl *PrevDecl, 409198092Srdivacky SourceLocation TKL = SourceLocation()); 410193326Sed 411193326Sed ~CXXRecordDecl(); 412193326Sed 413193326Sedpublic: 414193326Sed /// base_class_iterator - Iterator that traverses the base classes 415198092Srdivacky /// of a class. 416193326Sed typedef CXXBaseSpecifier* base_class_iterator; 417193326Sed 418193326Sed /// base_class_const_iterator - Iterator that traverses the base 419198092Srdivacky /// classes of a class. 420193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 421193326Sed 422198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 423198092Srdivacky /// of a class in reverse order. 424198092Srdivacky typedef std::reverse_iterator<base_class_iterator> 425198092Srdivacky reverse_base_class_iterator; 426198092Srdivacky 427198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 428198092Srdivacky /// of a class in reverse order. 429198092Srdivacky typedef std::reverse_iterator<base_class_const_iterator> 430198092Srdivacky reverse_base_class_const_iterator; 431198092Srdivacky 432198092Srdivacky virtual CXXRecordDecl *getCanonicalDecl() { 433198092Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 434198092Srdivacky } 435199482Srdivacky virtual const CXXRecordDecl *getCanonicalDecl() const { 436199482Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 437199482Srdivacky } 438198092Srdivacky 439193326Sed static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 440193326Sed SourceLocation L, IdentifierInfo *Id, 441198092Srdivacky SourceLocation TKL = SourceLocation(), 442193326Sed CXXRecordDecl* PrevDecl=0, 443193326Sed bool DelayTypeCreation = false); 444198092Srdivacky 445195341Sed virtual void Destroy(ASTContext& C); 446198092Srdivacky 447198092Srdivacky bool isDynamicClass() const { 448198092Srdivacky return Polymorphic || NumVBases != 0; 449198092Srdivacky } 450198092Srdivacky 451193326Sed /// setBases - Sets the base classes of this struct or class. 452195341Sed void setBases(ASTContext &C, 453195341Sed CXXBaseSpecifier const * const *Bases, unsigned NumBases); 454193326Sed 455193326Sed /// getNumBases - Retrieves the number of base classes of this 456193326Sed /// class. 457193326Sed unsigned getNumBases() const { return NumBases; } 458193326Sed 459193326Sed base_class_iterator bases_begin() { return Bases; } 460193326Sed base_class_const_iterator bases_begin() const { return Bases; } 461193326Sed base_class_iterator bases_end() { return Bases + NumBases; } 462193326Sed base_class_const_iterator bases_end() const { return Bases + NumBases; } 463198092Srdivacky reverse_base_class_iterator bases_rbegin() { 464198092Srdivacky return reverse_base_class_iterator(bases_end()); 465198092Srdivacky } 466198092Srdivacky reverse_base_class_const_iterator bases_rbegin() const { 467198092Srdivacky return reverse_base_class_const_iterator(bases_end()); 468198092Srdivacky } 469198092Srdivacky reverse_base_class_iterator bases_rend() { 470198092Srdivacky return reverse_base_class_iterator(bases_begin()); 471198092Srdivacky } 472198092Srdivacky reverse_base_class_const_iterator bases_rend() const { 473198092Srdivacky return reverse_base_class_const_iterator(bases_begin()); 474198092Srdivacky } 475193326Sed 476198092Srdivacky /// getNumVBases - Retrieves the number of virtual base classes of this 477198092Srdivacky /// class. 478198092Srdivacky unsigned getNumVBases() const { return NumVBases; } 479198092Srdivacky 480198092Srdivacky base_class_iterator vbases_begin() { return VBases; } 481198092Srdivacky base_class_const_iterator vbases_begin() const { return VBases; } 482198092Srdivacky base_class_iterator vbases_end() { return VBases + NumVBases; } 483198092Srdivacky base_class_const_iterator vbases_end() const { return VBases + NumVBases; } 484198092Srdivacky reverse_base_class_iterator vbases_rbegin() { 485198092Srdivacky return reverse_base_class_iterator(vbases_end()); 486198092Srdivacky } 487198092Srdivacky reverse_base_class_const_iterator vbases_rbegin() const { 488198092Srdivacky return reverse_base_class_const_iterator(vbases_end()); 489198092Srdivacky } 490198092Srdivacky reverse_base_class_iterator vbases_rend() { 491198092Srdivacky return reverse_base_class_iterator(vbases_begin()); 492198092Srdivacky } 493198092Srdivacky reverse_base_class_const_iterator vbases_rend() const { 494198092Srdivacky return reverse_base_class_const_iterator(vbases_begin()); 495198092Srdivacky } 496198092Srdivacky 497198092Srdivacky /// Iterator access to method members. The method iterator visits 498198092Srdivacky /// all method members of the class, including non-instance methods, 499198092Srdivacky /// special methods, etc. 500198092Srdivacky typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 501198092Srdivacky 502198092Srdivacky /// method_begin - Method begin iterator. Iterates in the order the methods 503198092Srdivacky /// were declared. 504198092Srdivacky method_iterator method_begin() const { 505198092Srdivacky return method_iterator(decls_begin()); 506198092Srdivacky } 507198092Srdivacky /// method_end - Method end iterator. 508198092Srdivacky method_iterator method_end() const { 509198092Srdivacky return method_iterator(decls_end()); 510198092Srdivacky } 511198092Srdivacky 512198092Srdivacky /// Iterator access to constructor members. 513198092Srdivacky typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 514198092Srdivacky 515198092Srdivacky ctor_iterator ctor_begin() const { 516198092Srdivacky return ctor_iterator(decls_begin()); 517198092Srdivacky } 518198092Srdivacky ctor_iterator ctor_end() const { 519198092Srdivacky return ctor_iterator(decls_end()); 520198092Srdivacky } 521198092Srdivacky 522193326Sed /// hasConstCopyConstructor - Determines whether this class has a 523193326Sed /// copy constructor that accepts a const-qualified argument. 524193326Sed bool hasConstCopyConstructor(ASTContext &Context) const; 525193326Sed 526194711Sed /// getCopyConstructor - Returns the copy constructor for this class 527198092Srdivacky CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 528194711Sed unsigned TypeQuals) const; 529194711Sed 530193326Sed /// hasConstCopyAssignment - Determines whether this class has a 531193326Sed /// copy assignment operator that accepts a const-qualified argument. 532198092Srdivacky /// It returns its decl in MD if found. 533198092Srdivacky bool hasConstCopyAssignment(ASTContext &Context, 534198092Srdivacky const CXXMethodDecl *&MD) const; 535193326Sed 536193326Sed /// addedConstructor - Notify the class that another constructor has 537193326Sed /// been added. This routine helps maintain information about the 538193326Sed /// class based on which constructors have been added. 539193326Sed void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 540193326Sed 541193326Sed /// hasUserDeclaredConstructor - Whether this class has any 542193326Sed /// user-declared constructors. When true, a default constructor 543193326Sed /// will not be implicitly declared. 544198092Srdivacky bool hasUserDeclaredConstructor() const { 545198092Srdivacky assert((isDefinition() || 546198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 547198092Srdivacky "Incomplete record decl!"); 548198092Srdivacky return UserDeclaredConstructor; 549198092Srdivacky } 550193326Sed 551193326Sed /// hasUserDeclaredCopyConstructor - Whether this class has a 552193326Sed /// user-declared copy constructor. When false, a copy constructor 553193326Sed /// will be implicitly declared. 554193326Sed bool hasUserDeclaredCopyConstructor() const { 555193326Sed return UserDeclaredCopyConstructor; 556193326Sed } 557193326Sed 558193326Sed /// addedAssignmentOperator - Notify the class that another assignment 559193326Sed /// operator has been added. This routine helps maintain information about the 560193326Sed /// class based on which operators have been added. 561193326Sed void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 562193326Sed 563193326Sed /// hasUserDeclaredCopyAssignment - Whether this class has a 564193326Sed /// user-declared copy assignment operator. When false, a copy 565193326Sed /// assigment operator will be implicitly declared. 566193326Sed bool hasUserDeclaredCopyAssignment() const { 567193326Sed return UserDeclaredCopyAssignment; 568193326Sed } 569193326Sed 570193326Sed /// hasUserDeclaredDestructor - Whether this class has a 571193326Sed /// user-declared destructor. When false, a destructor will be 572193326Sed /// implicitly declared. 573193326Sed bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 574193326Sed 575193326Sed /// setUserDeclaredDestructor - Set whether this class has a 576193326Sed /// user-declared destructor. If not set by the time the class is 577193326Sed /// fully defined, a destructor will be implicitly declared. 578198092Srdivacky void setUserDeclaredDestructor(bool UCD) { 579198092Srdivacky UserDeclaredDestructor = UCD; 580193326Sed } 581193326Sed 582193326Sed /// getConversions - Retrieve the overload set containing all of the 583193326Sed /// conversion functions in this class. 584198092Srdivacky OverloadedFunctionDecl *getConversionFunctions() { 585198092Srdivacky assert((this->isDefinition() || 586198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 587198092Srdivacky "getConversionFunctions() called on incomplete type"); 588198092Srdivacky return &Conversions; 589193326Sed } 590198092Srdivacky const OverloadedFunctionDecl *getConversionFunctions() const { 591198092Srdivacky assert((this->isDefinition() || 592198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 593198092Srdivacky "getConversionFunctions() called on incomplete type"); 594198092Srdivacky return &Conversions; 595193326Sed } 596193326Sed 597198092Srdivacky /// getVisibleConversionFunctions - get all conversion functions visible 598198092Srdivacky /// in current class; including conversion function templates. 599198092Srdivacky OverloadedFunctionDecl *getVisibleConversionFunctions(); 600198092Srdivacky /// addVisibleConversionFunction - Add a new conversion function to the 601198092Srdivacky /// list of visible conversion functions. 602198092Srdivacky void addVisibleConversionFunction(CXXConversionDecl *ConvDecl); 603198092Srdivacky 604198092Srdivacky /// \brief Add a new conversion function template to the list of visible 605198092Srdivacky /// conversion functions. 606198092Srdivacky void addVisibleConversionFunction(FunctionTemplateDecl *ConvDecl); 607198092Srdivacky 608193326Sed /// addConversionFunction - Add a new conversion function to the 609193326Sed /// list of conversion functions. 610198092Srdivacky void addConversionFunction(CXXConversionDecl *ConvDecl); 611193326Sed 612198092Srdivacky /// \brief Add a new conversion function template to the list of conversion 613198092Srdivacky /// functions. 614198092Srdivacky void addConversionFunction(FunctionTemplateDecl *ConvDecl); 615198092Srdivacky 616193326Sed /// isAggregate - Whether this class is an aggregate (C++ 617193326Sed /// [dcl.init.aggr]), which is a class with no user-declared 618193326Sed /// constructors, no private or protected non-static data members, 619193326Sed /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 620193326Sed bool isAggregate() const { return Aggregate; } 621193326Sed 622193326Sed /// setAggregate - Set whether this class is an aggregate (C++ 623193326Sed /// [dcl.init.aggr]). 624193326Sed void setAggregate(bool Agg) { Aggregate = Agg; } 625193326Sed 626193326Sed /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 627193326Sed /// that is an aggregate that has no non-static non-POD data members, no 628193326Sed /// reference data members, no user-defined copy assignment operator and no 629193326Sed /// user-defined destructor. 630193326Sed bool isPOD() const { return PlainOldData; } 631193326Sed 632193326Sed /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 633193326Sed void setPOD(bool POD) { PlainOldData = POD; } 634193326Sed 635198092Srdivacky /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 636198092Srdivacky /// means it has a virtual function, virtual base, data member (other than 637198092Srdivacky /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 638198092Srdivacky /// a check for union-ness. 639198092Srdivacky bool isEmpty() const { return Empty; } 640198092Srdivacky 641198092Srdivacky /// Set whether this class is empty (C++0x [meta.unary.prop]) 642198092Srdivacky void setEmpty(bool Emp) { Empty = Emp; } 643198092Srdivacky 644193326Sed /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 645193326Sed /// which means that the class contains or inherits a virtual function. 646193326Sed bool isPolymorphic() const { return Polymorphic; } 647193326Sed 648193326Sed /// setPolymorphic - Set whether this class is polymorphic (C++ 649193326Sed /// [class.virtual]). 650193326Sed void setPolymorphic(bool Poly) { Polymorphic = Poly; } 651193326Sed 652193326Sed /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 653193326Sed /// which means that the class contains or inherits a pure virtual function. 654193326Sed bool isAbstract() const { return Abstract; } 655198092Srdivacky 656193326Sed /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 657193326Sed void setAbstract(bool Abs) { Abstract = Abs; } 658198092Srdivacky 659193326Sed // hasTrivialConstructor - Whether this class has a trivial constructor 660193326Sed // (C++ [class.ctor]p5) 661193326Sed bool hasTrivialConstructor() const { return HasTrivialConstructor; } 662198092Srdivacky 663193326Sed // setHasTrivialConstructor - Set whether this class has a trivial constructor 664193326Sed // (C++ [class.ctor]p5) 665193326Sed void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 666198092Srdivacky 667198092Srdivacky // hasTrivialCopyConstructor - Whether this class has a trivial copy 668198092Srdivacky // constructor (C++ [class.copy]p6) 669198092Srdivacky bool hasTrivialCopyConstructor() const { return HasTrivialCopyConstructor; } 670198092Srdivacky 671198092Srdivacky // setHasTrivialCopyConstructor - Set whether this class has a trivial 672198092Srdivacky // copy constructor (C++ [class.copy]p6) 673198092Srdivacky void setHasTrivialCopyConstructor(bool TC) { HasTrivialCopyConstructor = TC; } 674198092Srdivacky 675198092Srdivacky // hasTrivialCopyAssignment - Whether this class has a trivial copy 676198092Srdivacky // assignment operator (C++ [class.copy]p11) 677198092Srdivacky bool hasTrivialCopyAssignment() const { return HasTrivialCopyAssignment; } 678198092Srdivacky 679198092Srdivacky // setHasTrivialCopyAssignment - Set whether this class has a 680198092Srdivacky // trivial copy assignment operator (C++ [class.copy]p11) 681198092Srdivacky void setHasTrivialCopyAssignment(bool TC) { HasTrivialCopyAssignment = TC; } 682198092Srdivacky 683193326Sed // hasTrivialDestructor - Whether this class has a trivial destructor 684193326Sed // (C++ [class.dtor]p3) 685193326Sed bool hasTrivialDestructor() const { return HasTrivialDestructor; } 686198092Srdivacky 687193326Sed // setHasTrivialDestructor - Set whether this class has a trivial destructor 688193326Sed // (C++ [class.dtor]p3) 689193326Sed void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 690198092Srdivacky 691193326Sed /// \brief If this record is an instantiation of a member class, 692193326Sed /// retrieves the member class from which it was instantiated. 693193326Sed /// 694193326Sed /// This routine will return non-NULL for (non-templated) member 695193326Sed /// classes of class templates. For example, given: 696193326Sed /// 697193326Sed /// \code 698193326Sed /// template<typename T> 699193326Sed /// struct X { 700193326Sed /// struct A { }; 701193326Sed /// }; 702193326Sed /// \endcode 703193326Sed /// 704193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 705193326Sed /// whose parent is the class template specialization X<int>. For 706193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 707193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 708193326Sed /// X<int>::A is required, it will be instantiated from the 709193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 710198092Srdivacky CXXRecordDecl *getInstantiatedFromMemberClass() const; 711198092Srdivacky 712198092Srdivacky /// \brief If this class is an instantiation of a member class of a 713198092Srdivacky /// class template specialization, retrieves the member specialization 714198092Srdivacky /// information. 715198092Srdivacky MemberSpecializationInfo *getMemberSpecializationInfo() const; 716198092Srdivacky 717193326Sed /// \brief Specify that this record is an instantiation of the 718193326Sed /// member class RD. 719198092Srdivacky void setInstantiationOfMemberClass(CXXRecordDecl *RD, 720198092Srdivacky TemplateSpecializationKind TSK); 721193326Sed 722193326Sed /// \brief Retrieves the class template that is described by this 723193326Sed /// class declaration. 724193326Sed /// 725193326Sed /// Every class template is represented as a ClassTemplateDecl and a 726193326Sed /// CXXRecordDecl. The former contains template properties (such as 727193326Sed /// the template parameter lists) while the latter contains the 728193326Sed /// actual description of the template's 729193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 730193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 731193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 732193326Sed /// a CXXRecordDecl. 733193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 734193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 735193326Sed } 736193326Sed 737193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 738193326Sed TemplateOrInstantiation = Template; 739193326Sed } 740193326Sed 741198092Srdivacky /// \brief Determine whether this particular class is a specialization or 742198092Srdivacky /// instantiation of a class template or member class of a class template, 743198092Srdivacky /// and how it was instantiated or specialized. 744198092Srdivacky TemplateSpecializationKind getTemplateSpecializationKind(); 745198092Srdivacky 746198092Srdivacky /// \brief Set the kind of specialization or template instantiation this is. 747198092Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 748198092Srdivacky 749194613Sed /// getDefaultConstructor - Returns the default constructor for this class 750194613Sed CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 751198092Srdivacky 752193326Sed /// getDestructor - Returns the destructor decl for this class. 753193326Sed const CXXDestructorDecl *getDestructor(ASTContext &Context); 754198092Srdivacky 755195099Sed /// isLocalClass - If the class is a local class [class.local], returns 756195099Sed /// the enclosing function declaration. 757195099Sed const FunctionDecl *isLocalClass() const { 758195099Sed if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 759195099Sed return RD->isLocalClass(); 760198092Srdivacky 761195099Sed return dyn_cast<FunctionDecl>(getDeclContext()); 762195099Sed } 763198092Srdivacky 764198092Srdivacky /// \brief Determine whether this class is derived from the class \p Base. 765198092Srdivacky /// 766198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 767198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 768198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 769198092Srdivacky /// base class subobjects. 770198092Srdivacky /// 771198092Srdivacky /// \param Base the base class we are searching for. 772198092Srdivacky /// 773198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 774199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base) const; 775195099Sed 776198092Srdivacky /// \brief Determine whether this class is derived from the type \p Base. 777198092Srdivacky /// 778198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 779198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 780198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 781198092Srdivacky /// base class subobjects. 782198092Srdivacky /// 783198092Srdivacky /// \param Base the base class we are searching for. 784198092Srdivacky /// 785198092Srdivacky /// \param Paths will contain the paths taken from the current class to the 786198092Srdivacky /// given \p Base class. 787198092Srdivacky /// 788198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 789198092Srdivacky /// 790198092Srdivacky /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 791198092Srdivacky /// tangling input and output in \p Paths 792199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const; 793198092Srdivacky 794198092Srdivacky /// \brief Function type used by lookupInBases() to determine whether a 795198092Srdivacky /// specific base class subobject matches the lookup criteria. 796198092Srdivacky /// 797198092Srdivacky /// \param Specifier the base-class specifier that describes the inheritance 798198092Srdivacky /// from the base class we are trying to match. 799198092Srdivacky /// 800198092Srdivacky /// \param Path the current path, from the most-derived class down to the 801198092Srdivacky /// base named by the \p Specifier. 802198092Srdivacky /// 803198092Srdivacky /// \param UserData a single pointer to user-specified data, provided to 804198092Srdivacky /// lookupInBases(). 805198092Srdivacky /// 806198092Srdivacky /// \returns true if this base matched the search criteria, false otherwise. 807199482Srdivacky typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 808198092Srdivacky CXXBasePath &Path, 809198092Srdivacky void *UserData); 810198092Srdivacky 811198092Srdivacky /// \brief Look for entities within the base classes of this C++ class, 812198092Srdivacky /// transitively searching all base class subobjects. 813198092Srdivacky /// 814198092Srdivacky /// This routine uses the callback function \p BaseMatches to find base 815198092Srdivacky /// classes meeting some search criteria, walking all base class subobjects 816198092Srdivacky /// and populating the given \p Paths structure with the paths through the 817198092Srdivacky /// inheritance hierarchy that resulted in a match. On a successful search, 818198092Srdivacky /// the \p Paths structure can be queried to retrieve the matching paths and 819198092Srdivacky /// to determine if there were any ambiguities. 820198092Srdivacky /// 821198092Srdivacky /// \param BaseMatches callback function used to determine whether a given 822198092Srdivacky /// base matches the user-defined search criteria. 823198092Srdivacky /// 824198092Srdivacky /// \param UserData user data pointer that will be provided to \p BaseMatches. 825198092Srdivacky /// 826198092Srdivacky /// \param Paths used to record the paths from this class to its base class 827198092Srdivacky /// subobjects that match the search criteria. 828198092Srdivacky /// 829198092Srdivacky /// \returns true if there exists any path from this class to a base class 830198092Srdivacky /// subobject that matches the search criteria. 831198092Srdivacky bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 832199482Srdivacky CXXBasePaths &Paths) const; 833198092Srdivacky 834198092Srdivacky /// \brief Base-class lookup callback that determines whether the given 835198092Srdivacky /// base class specifier refers to a specific class declaration. 836198092Srdivacky /// 837198092Srdivacky /// This callback can be used with \c lookupInBases() to determine whether 838198092Srdivacky /// a given derived class has is a base class subobject of a particular type. 839198092Srdivacky /// The user data pointer should refer to the canonical CXXRecordDecl of the 840198092Srdivacky /// base class that we are searching for. 841199482Srdivacky static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 842199482Srdivacky CXXBasePath &Path, void *BaseRecord); 843198092Srdivacky 844198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 845198092Srdivacky /// a tag with the given name. 846198092Srdivacky /// 847198092Srdivacky /// This callback can be used with \c lookupInBases() to find tag members 848198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 849198092Srdivacky /// is an opaque \c DeclarationName pointer. 850199482Srdivacky static bool FindTagMember(const CXXBaseSpecifier *Specifier, 851199482Srdivacky CXXBasePath &Path, void *Name); 852198092Srdivacky 853198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 854198092Srdivacky /// a member with the given name. 855198092Srdivacky /// 856198092Srdivacky /// This callback can be used with \c lookupInBases() to find members 857198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 858198092Srdivacky /// is an opaque \c DeclarationName pointer. 859199482Srdivacky static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 860199482Srdivacky CXXBasePath &Path, void *Name); 861198092Srdivacky 862198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 863198092Srdivacky /// a member with the given name that can be used in a nested-name-specifier. 864198092Srdivacky /// 865198092Srdivacky /// This callback can be used with \c lookupInBases() to find membes of 866198092Srdivacky /// the given name within a C++ class hierarchy that can occur within 867198092Srdivacky /// nested-name-specifiers. 868199482Srdivacky static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 869198092Srdivacky CXXBasePath &Path, 870198092Srdivacky void *UserData); 871198092Srdivacky 872193326Sed /// viewInheritance - Renders and displays an inheritance diagram 873193326Sed /// for this C++ class and all of its base classes (transitively) using 874193326Sed /// GraphViz. 875193326Sed void viewInheritance(ASTContext& Context) const; 876193326Sed 877198092Srdivacky static bool classof(const Decl *D) { 878198092Srdivacky return D->getKind() == CXXRecord || 879193326Sed D->getKind() == ClassTemplateSpecialization || 880198092Srdivacky D->getKind() == ClassTemplatePartialSpecialization; 881193326Sed } 882193326Sed static bool classof(const CXXRecordDecl *D) { return true; } 883198092Srdivacky static bool classof(const ClassTemplateSpecializationDecl *D) { 884198092Srdivacky return true; 885193326Sed } 886193326Sed}; 887193326Sed 888193326Sed/// CXXMethodDecl - Represents a static or instance method of a 889193326Sed/// struct/union/class. 890193326Sedclass CXXMethodDecl : public FunctionDecl { 891193326Sedprotected: 892193326Sed CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 893198092Srdivacky DeclarationName N, QualType T, DeclaratorInfo *DInfo, 894193326Sed bool isStatic, bool isInline) 895198092Srdivacky : FunctionDecl(DK, RD, L, N, T, DInfo, (isStatic ? Static : None), 896193326Sed isInline) {} 897193326Sed 898193326Sedpublic: 899193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 900193326Sed SourceLocation L, DeclarationName N, 901198092Srdivacky QualType T, DeclaratorInfo *DInfo, 902198092Srdivacky bool isStatic = false, 903193326Sed bool isInline = false); 904198092Srdivacky 905193326Sed bool isStatic() const { return getStorageClass() == Static; } 906193326Sed bool isInstance() const { return !isStatic(); } 907193326Sed 908198092Srdivacky bool isVirtual() const { 909198092Srdivacky CXXMethodDecl *CD = 910198092Srdivacky cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 911198092Srdivacky 912198092Srdivacky if (CD->isVirtualAsWritten()) 913198092Srdivacky return true; 914198092Srdivacky 915198092Srdivacky return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 916193326Sed } 917198092Srdivacky 918198092Srdivacky /// \brief Determine whether this is a usual deallocation function 919198092Srdivacky /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 920198092Srdivacky /// delete or delete[] operator with a particular signature. 921198092Srdivacky bool isUsualDeallocationFunction() const; 922198092Srdivacky 923198092Srdivacky const CXXMethodDecl *getCanonicalDecl() const { 924198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 925198092Srdivacky } 926198092Srdivacky CXXMethodDecl *getCanonicalDecl() { 927198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 928198092Srdivacky } 929198092Srdivacky 930198092Srdivacky /// 931198092Srdivacky void addOverriddenMethod(const CXXMethodDecl *MD); 932193326Sed 933193326Sed typedef const CXXMethodDecl ** method_iterator; 934198092Srdivacky 935193326Sed method_iterator begin_overridden_methods() const; 936193326Sed method_iterator end_overridden_methods() const; 937198092Srdivacky 938193326Sed /// getParent - Returns the parent of this method declaration, which 939193326Sed /// is the class in which this method is defined. 940198092Srdivacky const CXXRecordDecl *getParent() const { 941198092Srdivacky return cast<CXXRecordDecl>(FunctionDecl::getParent()); 942193326Sed } 943198092Srdivacky 944193326Sed /// getParent - Returns the parent of this method declaration, which 945193326Sed /// is the class in which this method is defined. 946198092Srdivacky CXXRecordDecl *getParent() { 947193326Sed return const_cast<CXXRecordDecl *>( 948193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 949193326Sed } 950193326Sed 951193326Sed /// getThisType - Returns the type of 'this' pointer. 952193326Sed /// Should only be called for instance methods. 953193326Sed QualType getThisType(ASTContext &C) const; 954193326Sed 955193326Sed unsigned getTypeQualifiers() const { 956198092Srdivacky return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 957193326Sed } 958193326Sed 959193326Sed // Implement isa/cast/dyncast/etc. 960198092Srdivacky static bool classof(const Decl *D) { 961193326Sed return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 962193326Sed } 963193326Sed static bool classof(const CXXMethodDecl *D) { return true; } 964193326Sed}; 965193326Sed 966193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member 967193326Sed/// initializer, which is part of a constructor initializer that 968193326Sed/// initializes one non-static member variable or one base class. For 969193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 970193326Sed/// initializers: 971193326Sed/// 972193326Sed/// @code 973193326Sed/// class A { }; 974193326Sed/// class B : public A { 975193326Sed/// float f; 976193326Sed/// public: 977193326Sed/// B(A& a) : A(a), f(3.14159) { } 978193326Sed/// }; 979194613Sed/// @endcode 980193326Sedclass CXXBaseOrMemberInitializer { 981193326Sed /// BaseOrMember - This points to the entity being initialized, 982193326Sed /// which is either a base class (a Type) or a non-static data 983193326Sed /// member. When the low bit is 1, it's a base 984193326Sed /// class; when the low bit is 0, it's a member. 985193326Sed uintptr_t BaseOrMember; 986193326Sed 987193326Sed /// Args - The arguments used to initialize the base or member. 988198092Srdivacky Stmt **Args; 989193326Sed unsigned NumArgs; 990198092Srdivacky 991198092Srdivacky /// \brief Stores either the constructor to call to initialize this base or 992198092Srdivacky /// member (a CXXConstructorDecl pointer), or stores the anonymous union of 993198092Srdivacky /// which the initialized value is a member. 994198092Srdivacky /// 995198092Srdivacky /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's 996198092Srdivacky /// anonymous union data member, this field holds the FieldDecl for the 997198092Srdivacky /// member of the anonymous union being initialized. 998198092Srdivacky /// @code 999198092Srdivacky /// struct X { 1000198092Srdivacky /// X() : au_i1(123) {} 1001198092Srdivacky /// union { 1002198092Srdivacky /// int au_i1; 1003198092Srdivacky /// float au_f1; 1004198092Srdivacky /// }; 1005198092Srdivacky /// }; 1006198092Srdivacky /// @endcode 1007198092Srdivacky /// In above example, BaseOrMember holds the field decl. for anonymous union 1008198092Srdivacky /// and AnonUnionMember holds field decl for au_i1. 1009198092Srdivacky llvm::PointerUnion<CXXConstructorDecl *, FieldDecl *> CtorOrAnonUnion; 1010198092Srdivacky 1011195341Sed /// IdLoc - Location of the id in ctor-initializer list. 1012195341Sed SourceLocation IdLoc; 1013193326Sed 1014198092Srdivacky /// RParenLoc - Location of the right paren of the ctor-initializer. 1015198092Srdivacky SourceLocation RParenLoc; 1016198092Srdivacky 1017193326Sedpublic: 1018193326Sed /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 1019198092Srdivacky explicit 1020195341Sed CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, 1021198092Srdivacky CXXConstructorDecl *C, 1022198092Srdivacky SourceLocation L, SourceLocation R); 1023193326Sed 1024193326Sed /// CXXBaseOrMemberInitializer - Creates a new member initializer. 1025198092Srdivacky explicit 1026195341Sed CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, 1027198092Srdivacky CXXConstructorDecl *C, 1028198092Srdivacky SourceLocation L, SourceLocation R); 1029193326Sed 1030193326Sed /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer. 1031193326Sed ~CXXBaseOrMemberInitializer(); 1032193326Sed 1033193326Sed /// arg_iterator - Iterates through the member initialization 1034193326Sed /// arguments. 1035198092Srdivacky typedef ExprIterator arg_iterator; 1036193326Sed 1037193326Sed /// arg_const_iterator - Iterates through the member initialization 1038193326Sed /// arguments. 1039198092Srdivacky typedef ConstExprIterator const_arg_iterator; 1040193326Sed 1041195341Sed /// getBaseOrMember - get the generic 'member' representing either the field 1042195341Sed /// or a base class. 1043195341Sed void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); } 1044198092Srdivacky 1045193326Sed /// isBaseInitializer - Returns true when this initializer is 1046193326Sed /// initializing a base class. 1047193326Sed bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; } 1048193326Sed 1049193326Sed /// isMemberInitializer - Returns true when this initializer is 1050193326Sed /// initializing a non-static data member. 1051193326Sed bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; } 1052193326Sed 1053193326Sed /// getBaseClass - If this is a base class initializer, returns the 1054193326Sed /// type used to specify the initializer. The resulting type will be 1055193326Sed /// a class type or a typedef of a class type. If this is not a base 1056193326Sed /// class initializer, returns NULL. 1057198092Srdivacky Type *getBaseClass() { 1058198092Srdivacky if (isBaseInitializer()) 1059193326Sed return reinterpret_cast<Type*>(BaseOrMember & ~0x01); 1060193326Sed else 1061193326Sed return 0; 1062193326Sed } 1063193326Sed 1064193326Sed /// getBaseClass - If this is a base class initializer, returns the 1065193326Sed /// type used to specify the initializer. The resulting type will be 1066193326Sed /// a class type or a typedef of a class type. If this is not a base 1067193326Sed /// class initializer, returns NULL. 1068198092Srdivacky const Type *getBaseClass() const { 1069198092Srdivacky if (isBaseInitializer()) 1070193326Sed return reinterpret_cast<const Type*>(BaseOrMember & ~0x01); 1071193326Sed else 1072193326Sed return 0; 1073193326Sed } 1074193326Sed 1075193326Sed /// getMember - If this is a member initializer, returns the 1076193326Sed /// declaration of the non-static data member being 1077193326Sed /// initialized. Otherwise, returns NULL. 1078198092Srdivacky FieldDecl *getMember() { 1079193326Sed if (isMemberInitializer()) 1080198092Srdivacky return reinterpret_cast<FieldDecl *>(BaseOrMember); 1081193326Sed else 1082193326Sed return 0; 1083193326Sed } 1084193326Sed 1085198092Srdivacky void setMember(FieldDecl * anonUnionField) { 1086198092Srdivacky BaseOrMember = reinterpret_cast<uintptr_t>(anonUnionField); 1087198092Srdivacky } 1088198092Srdivacky 1089198092Srdivacky FieldDecl *getAnonUnionMember() const { 1090198092Srdivacky return CtorOrAnonUnion.dyn_cast<FieldDecl *>(); 1091198092Srdivacky } 1092198092Srdivacky void setAnonUnionMember(FieldDecl *anonMember) { 1093198092Srdivacky CtorOrAnonUnion = anonMember; 1094198092Srdivacky } 1095198092Srdivacky 1096198092Srdivacky const CXXConstructorDecl *getConstructor() const { 1097198092Srdivacky return CtorOrAnonUnion.dyn_cast<CXXConstructorDecl *>(); 1098198092Srdivacky } 1099198092Srdivacky 1100195341Sed SourceLocation getSourceLocation() const { return IdLoc; } 1101198092Srdivacky SourceLocation getRParenLoc() const { return RParenLoc; } 1102193326Sed 1103198092Srdivacky /// arg_begin() - Retrieve an iterator to the first initializer argument. 1104198092Srdivacky arg_iterator arg_begin() { return Args; } 1105198092Srdivacky /// arg_begin() - Retrieve an iterator to the first initializer argument. 1106198092Srdivacky const_arg_iterator const_arg_begin() const { return Args; } 1107193326Sed 1108198092Srdivacky /// arg_end() - Retrieve an iterator past the last initializer argument. 1109198092Srdivacky arg_iterator arg_end() { return Args + NumArgs; } 1110198092Srdivacky /// arg_end() - Retrieve an iterator past the last initializer argument. 1111198092Srdivacky const_arg_iterator const_arg_end() const { return Args + NumArgs; } 1112198092Srdivacky 1113193326Sed /// getNumArgs - Determine the number of arguments used to 1114193326Sed /// initialize the member or base. 1115193326Sed unsigned getNumArgs() const { return NumArgs; } 1116193326Sed}; 1117193326Sed 1118193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a 1119193326Sed/// class. For example: 1120198092Srdivacky/// 1121193326Sed/// @code 1122193326Sed/// class X { 1123193326Sed/// public: 1124193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 1125193326Sed/// }; 1126193326Sed/// @endcode 1127193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 1128193326Sed /// Explicit - Whether this constructor is explicit. 1129193326Sed bool Explicit : 1; 1130193326Sed 1131193326Sed /// ImplicitlyDefined - Whether this constructor was implicitly 1132193326Sed /// defined by the compiler. When false, the constructor was defined 1133193326Sed /// by the user. In C++03, this flag will have the same value as 1134193326Sed /// Implicit. In C++0x, however, a constructor that is 1135193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1136193326Sed /// @c !Implicit && ImplicitlyDefined. 1137193326Sed bool ImplicitlyDefined : 1; 1138198092Srdivacky 1139195341Sed /// Support for base and member initializers. 1140198092Srdivacky /// BaseOrMemberInitializers - The arguments used to initialize the base 1141195341Sed /// or member. 1142195341Sed CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 1143195341Sed unsigned NumBaseOrMemberInitializers; 1144198092Srdivacky 1145193326Sed CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 1146198092Srdivacky DeclarationName N, QualType T, DeclaratorInfo *DInfo, 1147193326Sed bool isExplicit, bool isInline, bool isImplicitlyDeclared) 1148198092Srdivacky : CXXMethodDecl(CXXConstructor, RD, L, N, T, DInfo, false, isInline), 1149195341Sed Explicit(isExplicit), ImplicitlyDefined(false), 1150198092Srdivacky BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 1151193326Sed setImplicit(isImplicitlyDeclared); 1152193326Sed } 1153195341Sed virtual void Destroy(ASTContext& C); 1154198092Srdivacky 1155193326Sedpublic: 1156193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1157193326Sed SourceLocation L, DeclarationName N, 1158198092Srdivacky QualType T, DeclaratorInfo *DInfo, 1159198092Srdivacky bool isExplicit, 1160193326Sed bool isInline, bool isImplicitlyDeclared); 1161193326Sed 1162198092Srdivacky /// isExplicit - Whether this constructor was marked "explicit" or not. 1163193326Sed bool isExplicit() const { return Explicit; } 1164193326Sed 1165193326Sed /// isImplicitlyDefined - Whether this constructor was implicitly 1166193326Sed /// defined. If false, then this constructor was defined by the 1167193326Sed /// user. This operation can only be invoked if the constructor has 1168193326Sed /// already been defined. 1169198092Srdivacky bool isImplicitlyDefined(ASTContext &C) const { 1170198092Srdivacky assert(isThisDeclarationADefinition() && 1171195341Sed "Can only get the implicit-definition flag once the " 1172195341Sed "constructor has been defined"); 1173198092Srdivacky return ImplicitlyDefined; 1174193326Sed } 1175193326Sed 1176193326Sed /// setImplicitlyDefined - Set whether this constructor was 1177193326Sed /// implicitly defined or not. 1178198092Srdivacky void setImplicitlyDefined(bool ID) { 1179198092Srdivacky assert(isThisDeclarationADefinition() && 1180195341Sed "Can only set the implicit-definition flag once the constructor " 1181195341Sed "has been defined"); 1182198092Srdivacky ImplicitlyDefined = ID; 1183193326Sed } 1184198092Srdivacky 1185195341Sed /// init_iterator - Iterates through the member/base initializer list. 1186195341Sed typedef CXXBaseOrMemberInitializer **init_iterator; 1187198092Srdivacky 1188195341Sed /// init_const_iterator - Iterates through the memberbase initializer list. 1189195341Sed typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 1190198092Srdivacky 1191198092Srdivacky /// init_begin() - Retrieve an iterator to the first initializer. 1192198092Srdivacky init_iterator init_begin() { return BaseOrMemberInitializers; } 1193195341Sed /// begin() - Retrieve an iterator to the first initializer. 1194198092Srdivacky init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 1195198092Srdivacky 1196198092Srdivacky /// init_end() - Retrieve an iterator past the last initializer. 1197198092Srdivacky init_iterator init_end() { 1198198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1199195341Sed } 1200195341Sed /// end() - Retrieve an iterator past the last initializer. 1201198092Srdivacky init_const_iterator init_end() const { 1202198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1203195341Sed } 1204198092Srdivacky 1205195341Sed /// getNumArgs - Determine the number of arguments used to 1206195341Sed /// initialize the member or base. 1207198092Srdivacky unsigned getNumBaseOrMemberInitializers() const { 1208198092Srdivacky return NumBaseOrMemberInitializers; 1209195341Sed } 1210198092Srdivacky 1211198092Srdivacky void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) { 1212198092Srdivacky NumBaseOrMemberInitializers = numBaseOrMemberInitializers; 1213198092Srdivacky } 1214198092Srdivacky 1215198092Srdivacky void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) { 1216198092Srdivacky BaseOrMemberInitializers = initializers; 1217198092Srdivacky } 1218193326Sed /// isDefaultConstructor - Whether this constructor is a default 1219193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 1220193326Sed /// default-initialize a class of this type. 1221193326Sed bool isDefaultConstructor() const; 1222193326Sed 1223193326Sed /// isCopyConstructor - Whether this constructor is a copy 1224193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1225193326Sed /// class. @p TypeQuals will be set to the qualifiers on the 1226193326Sed /// argument type. For example, @p TypeQuals would be set to @c 1227193326Sed /// QualType::Const for the following copy constructor: 1228193326Sed /// 1229193326Sed /// @code 1230193326Sed /// class X { 1231193326Sed /// public: 1232193326Sed /// X(const X&); 1233193326Sed /// }; 1234193326Sed /// @endcode 1235193326Sed bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 1236193326Sed 1237193326Sed /// isCopyConstructor - Whether this constructor is a copy 1238193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1239193326Sed /// class. 1240193326Sed bool isCopyConstructor(ASTContext &Context) const { 1241193326Sed unsigned TypeQuals = 0; 1242193326Sed return isCopyConstructor(Context, TypeQuals); 1243193326Sed } 1244193326Sed 1245193326Sed /// isConvertingConstructor - Whether this constructor is a 1246193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 1247193326Sed /// used for user-defined conversions. 1248198092Srdivacky bool isConvertingConstructor(bool AllowExplicit) const; 1249193326Sed 1250199482Srdivacky /// \brief Determine whether this is a member template specialization that 1251199482Srdivacky /// looks like a copy constructor. Such constructors are never used to copy 1252199482Srdivacky /// an object. 1253199482Srdivacky bool isCopyConstructorLikeSpecialization() const; 1254199482Srdivacky 1255193326Sed // Implement isa/cast/dyncast/etc. 1256198092Srdivacky static bool classof(const Decl *D) { 1257193326Sed return D->getKind() == CXXConstructor; 1258193326Sed } 1259193326Sed static bool classof(const CXXConstructorDecl *D) { return true; } 1260193326Sed}; 1261193326Sed 1262193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a 1263193326Sed/// class. For example: 1264198092Srdivacky/// 1265193326Sed/// @code 1266193326Sed/// class X { 1267193326Sed/// public: 1268193326Sed/// ~X(); // represented by a CXXDestructorDecl. 1269193326Sed/// }; 1270193326Sed/// @endcode 1271193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 1272193326Sed /// ImplicitlyDefined - Whether this destructor was implicitly 1273193326Sed /// defined by the compiler. When false, the destructor was defined 1274193326Sed /// by the user. In C++03, this flag will have the same value as 1275193326Sed /// Implicit. In C++0x, however, a destructor that is 1276193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1277193326Sed /// @c !Implicit && ImplicitlyDefined. 1278193326Sed bool ImplicitlyDefined : 1; 1279193326Sed 1280199482Srdivacky FunctionDecl *OperatorDelete; 1281199482Srdivacky 1282193326Sed CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 1283193326Sed DeclarationName N, QualType T, 1284193326Sed bool isInline, bool isImplicitlyDeclared) 1285198092Srdivacky : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*DInfo=*/0, false, isInline), 1286199482Srdivacky ImplicitlyDefined(false), OperatorDelete(0) { 1287193326Sed setImplicit(isImplicitlyDeclared); 1288193326Sed } 1289193326Sed 1290193326Sedpublic: 1291193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1292193326Sed SourceLocation L, DeclarationName N, 1293198092Srdivacky QualType T, bool isInline, 1294193326Sed bool isImplicitlyDeclared); 1295193326Sed 1296193326Sed /// isImplicitlyDefined - Whether this destructor was implicitly 1297193326Sed /// defined. If false, then this destructor was defined by the 1298193326Sed /// user. This operation can only be invoked if the destructor has 1299193326Sed /// already been defined. 1300198092Srdivacky bool isImplicitlyDefined() const { 1301198092Srdivacky assert(isThisDeclarationADefinition() && 1302193326Sed "Can only get the implicit-definition flag once the destructor has been defined"); 1303198092Srdivacky return ImplicitlyDefined; 1304193326Sed } 1305193326Sed 1306193326Sed /// setImplicitlyDefined - Set whether this destructor was 1307193326Sed /// implicitly defined or not. 1308198092Srdivacky void setImplicitlyDefined(bool ID) { 1309198092Srdivacky assert(isThisDeclarationADefinition() && 1310193326Sed "Can only set the implicit-definition flag once the destructor has been defined"); 1311198092Srdivacky ImplicitlyDefined = ID; 1312193326Sed } 1313193326Sed 1314199482Srdivacky void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 1315199482Srdivacky const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1316198092Srdivacky 1317193326Sed // Implement isa/cast/dyncast/etc. 1318198092Srdivacky static bool classof(const Decl *D) { 1319193326Sed return D->getKind() == CXXDestructor; 1320193326Sed } 1321193326Sed static bool classof(const CXXDestructorDecl *D) { return true; } 1322193326Sed}; 1323193326Sed 1324193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a 1325193326Sed/// class. For example: 1326198092Srdivacky/// 1327193326Sed/// @code 1328193326Sed/// class X { 1329193326Sed/// public: 1330193326Sed/// operator bool(); 1331193326Sed/// }; 1332193326Sed/// @endcode 1333193326Sedclass CXXConversionDecl : public CXXMethodDecl { 1334193326Sed /// Explicit - Whether this conversion function is marked 1335193326Sed /// "explicit", meaning that it can only be applied when the user 1336193326Sed /// explicitly wrote a cast. This is a C++0x feature. 1337193326Sed bool Explicit : 1; 1338193326Sed 1339193326Sed CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1340198092Srdivacky DeclarationName N, QualType T, DeclaratorInfo *DInfo, 1341193326Sed bool isInline, bool isExplicit) 1342198092Srdivacky : CXXMethodDecl(CXXConversion, RD, L, N, T, DInfo, false, isInline), 1343193326Sed Explicit(isExplicit) { } 1344193326Sed 1345193326Sedpublic: 1346193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1347193326Sed SourceLocation L, DeclarationName N, 1348198092Srdivacky QualType T, DeclaratorInfo *DInfo, 1349198092Srdivacky bool isInline, bool isExplicit); 1350193326Sed 1351193326Sed /// isExplicit - Whether this is an explicit conversion operator 1352193326Sed /// (C++0x only). Explicit conversion operators are only considered 1353193326Sed /// when the user has explicitly written a cast. 1354193326Sed bool isExplicit() const { return Explicit; } 1355193326Sed 1356193326Sed /// getConversionType - Returns the type that this conversion 1357193326Sed /// function is converting to. 1358198092Srdivacky QualType getConversionType() const { 1359198092Srdivacky return getType()->getAs<FunctionType>()->getResultType(); 1360193326Sed } 1361193326Sed 1362193326Sed // Implement isa/cast/dyncast/etc. 1363198092Srdivacky static bool classof(const Decl *D) { 1364193326Sed return D->getKind() == CXXConversion; 1365193326Sed } 1366193326Sed static bool classof(const CXXConversionDecl *D) { return true; } 1367193326Sed}; 1368193326Sed 1369198092Srdivacky/// FriendDecl - Represents the declaration of a friend entity, 1370198092Srdivacky/// which can be a function, a type, or a templated function or type. 1371198092Srdivacky// For example: 1372198092Srdivacky/// 1373198092Srdivacky/// @code 1374198092Srdivacky/// template <typename T> class A { 1375198092Srdivacky/// friend int foo(T); 1376198092Srdivacky/// friend class B; 1377198092Srdivacky/// friend T; // only in C++0x 1378198092Srdivacky/// template <typename U> friend class C; 1379198092Srdivacky/// template <typename U> friend A& operator+=(A&, const U&) { ... } 1380198092Srdivacky/// }; 1381198092Srdivacky/// @endcode 1382198092Srdivacky/// 1383198092Srdivacky/// The semantic context of a friend decl is its declaring class. 1384198092Srdivackyclass FriendDecl : public Decl { 1385198092Srdivackypublic: 1386198092Srdivacky typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 1387198092Srdivacky 1388198092Srdivackyprivate: 1389198092Srdivacky // The declaration that's a friend of this class. 1390198092Srdivacky FriendUnion Friend; 1391198092Srdivacky 1392198092Srdivacky // Location of the 'friend' specifier. 1393198092Srdivacky SourceLocation FriendLoc; 1394198092Srdivacky 1395198092Srdivacky FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend, 1396198092Srdivacky SourceLocation FriendL) 1397198092Srdivacky : Decl(Decl::Friend, DC, L), 1398198092Srdivacky Friend(Friend), 1399198092Srdivacky FriendLoc(FriendL) { 1400198092Srdivacky } 1401198092Srdivacky 1402198092Srdivackypublic: 1403198092Srdivacky static FriendDecl *Create(ASTContext &C, DeclContext *DC, 1404198092Srdivacky SourceLocation L, FriendUnion Friend_, 1405198092Srdivacky SourceLocation FriendL); 1406198092Srdivacky 1407198092Srdivacky /// If this friend declaration names an (untemplated but 1408198092Srdivacky /// possibly dependent) type, return the type; otherwise 1409198092Srdivacky /// return null. This is used only for C++0x's unelaborated 1410198092Srdivacky /// friend type declarations. 1411198092Srdivacky Type *getFriendType() const { 1412198092Srdivacky return Friend.dyn_cast<Type*>(); 1413198092Srdivacky } 1414198092Srdivacky 1415198092Srdivacky /// If this friend declaration doesn't name an unelaborated 1416198092Srdivacky /// type, return the inner declaration. 1417198092Srdivacky NamedDecl *getFriendDecl() const { 1418198092Srdivacky return Friend.dyn_cast<NamedDecl*>(); 1419198092Srdivacky } 1420198092Srdivacky 1421198092Srdivacky /// Retrieves the location of the 'friend' keyword. 1422198092Srdivacky SourceLocation getFriendLoc() const { 1423198092Srdivacky return FriendLoc; 1424198092Srdivacky } 1425198092Srdivacky 1426198092Srdivacky // Implement isa/cast/dyncast/etc. 1427198092Srdivacky static bool classof(const Decl *D) { 1428198092Srdivacky return D->getKind() == Decl::Friend; 1429198092Srdivacky } 1430198092Srdivacky static bool classof(const FriendDecl *D) { return true; } 1431198092Srdivacky}; 1432198092Srdivacky 1433193326Sed/// LinkageSpecDecl - This represents a linkage specification. For example: 1434193326Sed/// extern "C" void foo(); 1435193326Sed/// 1436193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 1437193326Sedpublic: 1438193326Sed /// LanguageIDs - Used to represent the language in a linkage 1439193326Sed /// specification. The values are part of the serialization abi for 1440193326Sed /// ASTs and cannot be changed without altering that abi. To help 1441193326Sed /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1442193326Sed /// from the dwarf standard. 1443193326Sed enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 1444193326Sed lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 1445193326Sedprivate: 1446193326Sed /// Language - The language for this linkage specification. 1447193326Sed LanguageIDs Language; 1448193326Sed 1449193326Sed /// HadBraces - Whether this linkage specification had curly braces or not. 1450193326Sed bool HadBraces : 1; 1451193326Sed 1452198092Srdivacky LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1453193326Sed bool Braces) 1454198092Srdivacky : Decl(LinkageSpec, DC, L), 1455193326Sed DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1456193326Sed 1457193326Sedpublic: 1458198092Srdivacky static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1459198092Srdivacky SourceLocation L, LanguageIDs Lang, 1460193326Sed bool Braces); 1461193326Sed 1462193326Sed LanguageIDs getLanguage() const { return Language; } 1463193326Sed 1464193326Sed /// hasBraces - Determines whether this linkage specification had 1465193326Sed /// braces in its syntactic form. 1466193326Sed bool hasBraces() const { return HadBraces; } 1467193326Sed 1468193326Sed static bool classof(const Decl *D) { 1469193326Sed return D->getKind() == LinkageSpec; 1470193326Sed } 1471193326Sed static bool classof(const LinkageSpecDecl *D) { return true; } 1472193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1473193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1474193326Sed } 1475193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1476193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1477193326Sed } 1478193326Sed}; 1479193326Sed 1480193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1481193326Sed/// 1482193326Sed/// using namespace std; 1483193326Sed/// 1484193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1485193326Sed// artificial name, for all using-directives in order to store 1486193326Sed// them in DeclContext effectively. 1487193326Sedclass UsingDirectiveDecl : public NamedDecl { 1488193326Sed 1489193326Sed /// SourceLocation - Location of 'namespace' token. 1490193326Sed SourceLocation NamespaceLoc; 1491193326Sed 1492193326Sed /// \brief The source range that covers the nested-name-specifier 1493193326Sed /// preceding the namespace name. 1494193326Sed SourceRange QualifierRange; 1495193326Sed 1496193326Sed /// \brief The nested-name-specifier that precedes the namespace 1497193326Sed /// name, if any. 1498193326Sed NestedNameSpecifier *Qualifier; 1499193326Sed 1500193326Sed /// IdentLoc - Location of nominated namespace-name identifier. 1501193326Sed // FIXME: We don't store location of scope specifier. 1502193326Sed SourceLocation IdentLoc; 1503193326Sed 1504193326Sed /// NominatedNamespace - Namespace nominated by using-directive. 1505193326Sed NamespaceDecl *NominatedNamespace; 1506193326Sed 1507193326Sed /// Enclosing context containing both using-directive and nomintated 1508193326Sed /// namespace. 1509193326Sed DeclContext *CommonAncestor; 1510193326Sed 1511193326Sed /// getUsingDirectiveName - Returns special DeclarationName used by 1512193326Sed /// using-directives. This is only used by DeclContext for storing 1513193326Sed /// UsingDirectiveDecls in its lookup structure. 1514193326Sed static DeclarationName getName() { 1515193326Sed return DeclarationName::getUsingDirectiveName(); 1516193326Sed } 1517193326Sed 1518193326Sed UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1519193326Sed SourceLocation NamespcLoc, 1520193326Sed SourceRange QualifierRange, 1521193326Sed NestedNameSpecifier *Qualifier, 1522193326Sed SourceLocation IdentLoc, 1523193326Sed NamespaceDecl *Nominated, 1524193326Sed DeclContext *CommonAncestor) 1525193326Sed : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1526198092Srdivacky NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1527198092Srdivacky Qualifier(Qualifier), IdentLoc(IdentLoc), 1528193326Sed NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0), 1529193326Sed CommonAncestor(CommonAncestor) { 1530193326Sed } 1531193326Sed 1532193326Sedpublic: 1533193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1534193326Sed /// that qualifiers the namespace name. 1535193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1536193326Sed 1537193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1538193326Sed /// name of the namespace. 1539193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1540193326Sed 1541193326Sed /// getNominatedNamespace - Returns namespace nominated by using-directive. 1542193326Sed NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; } 1543193326Sed 1544193326Sed const NamespaceDecl *getNominatedNamespace() const { 1545193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1546193326Sed } 1547193326Sed 1548193326Sed /// getCommonAncestor - returns common ancestor context of using-directive, 1549193326Sed /// and nominated by it namespace. 1550193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 1551193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1552193326Sed 1553193326Sed /// getNamespaceKeyLocation - Returns location of namespace keyword. 1554193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1555193326Sed 1556193326Sed /// getIdentLocation - Returns location of identifier. 1557193326Sed SourceLocation getIdentLocation() const { return IdentLoc; } 1558193326Sed 1559193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1560193326Sed SourceLocation L, 1561193326Sed SourceLocation NamespaceLoc, 1562193326Sed SourceRange QualifierRange, 1563193326Sed NestedNameSpecifier *Qualifier, 1564193326Sed SourceLocation IdentLoc, 1565193326Sed NamespaceDecl *Nominated, 1566193326Sed DeclContext *CommonAncestor); 1567193326Sed 1568193326Sed static bool classof(const Decl *D) { 1569193326Sed return D->getKind() == Decl::UsingDirective; 1570193326Sed } 1571193326Sed static bool classof(const UsingDirectiveDecl *D) { return true; } 1572193326Sed 1573193326Sed // Friend for getUsingDirectiveName. 1574193326Sed friend class DeclContext; 1575193326Sed}; 1576193326Sed 1577193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1578193326Sed/// 1579193326Sed/// @code 1580193326Sed/// namespace Foo = Bar; 1581193326Sed/// @endcode 1582193326Sedclass NamespaceAliasDecl : public NamedDecl { 1583193326Sed SourceLocation AliasLoc; 1584193326Sed 1585193326Sed /// \brief The source range that covers the nested-name-specifier 1586193326Sed /// preceding the namespace name. 1587193326Sed SourceRange QualifierRange; 1588193326Sed 1589193326Sed /// \brief The nested-name-specifier that precedes the namespace 1590193326Sed /// name, if any. 1591193326Sed NestedNameSpecifier *Qualifier; 1592198092Srdivacky 1593193326Sed /// IdentLoc - Location of namespace identifier. 1594193326Sed SourceLocation IdentLoc; 1595198092Srdivacky 1596198092Srdivacky /// Namespace - The Decl that this alias points to. Can either be a 1597193326Sed /// NamespaceDecl or a NamespaceAliasDecl. 1598193326Sed NamedDecl *Namespace; 1599198092Srdivacky 1600198092Srdivacky NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1601198092Srdivacky SourceLocation AliasLoc, IdentifierInfo *Alias, 1602193326Sed SourceRange QualifierRange, 1603193326Sed NestedNameSpecifier *Qualifier, 1604193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 1605198092Srdivacky : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1606193326Sed QualifierRange(QualifierRange), Qualifier(Qualifier), 1607193326Sed IdentLoc(IdentLoc), Namespace(Namespace) { } 1608193326Sed 1609193326Sedpublic: 1610193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1611193326Sed /// that qualifiers the namespace name. 1612193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1613193326Sed 1614193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1615193326Sed /// name of the namespace. 1616193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1617193326Sed 1618193326Sed NamespaceDecl *getNamespace() { 1619193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1620193326Sed return AD->getNamespace(); 1621193326Sed 1622193326Sed return cast<NamespaceDecl>(Namespace); 1623193326Sed } 1624198092Srdivacky 1625193326Sed const NamespaceDecl *getNamespace() const { 1626193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1627193326Sed } 1628193326Sed 1629193326Sed /// \brief Retrieve the namespace that this alias refers to, which 1630193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1631193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 1632193326Sed 1633198092Srdivacky static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1634198092Srdivacky SourceLocation L, SourceLocation AliasLoc, 1635198092Srdivacky IdentifierInfo *Alias, 1636193326Sed SourceRange QualifierRange, 1637193326Sed NestedNameSpecifier *Qualifier, 1638198092Srdivacky SourceLocation IdentLoc, 1639193326Sed NamedDecl *Namespace); 1640198092Srdivacky 1641193326Sed static bool classof(const Decl *D) { 1642193326Sed return D->getKind() == Decl::NamespaceAlias; 1643193326Sed } 1644193326Sed static bool classof(const NamespaceAliasDecl *D) { return true; } 1645193326Sed}; 1646194613Sed 1647199482Srdivacky/// UsingShadowDecl - Represents a shadow declaration introduced into 1648199482Srdivacky/// a scope by a (resolved) using declaration. For example, 1649199482Srdivacky/// 1650199482Srdivacky/// namespace A { 1651199482Srdivacky/// void foo(); 1652199482Srdivacky/// } 1653199482Srdivacky/// namespace B { 1654199482Srdivacky/// using A::foo(); // <- a UsingDecl 1655199482Srdivacky/// // Also creates a UsingShadowDecl for A::foo in B 1656199482Srdivacky/// } 1657199482Srdivacky/// 1658199482Srdivackyclass UsingShadowDecl : public NamedDecl { 1659199482Srdivacky /// The referenced declaration. 1660199482Srdivacky NamedDecl *Underlying; 1661199482Srdivacky 1662199482Srdivacky /// The using declaration which introduced this decl. 1663199482Srdivacky UsingDecl *Using; 1664199482Srdivacky 1665199482Srdivacky UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 1666199482Srdivacky NamedDecl *Target) 1667199482Srdivacky : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()), 1668199482Srdivacky Underlying(Target), Using(Using) { 1669199482Srdivacky IdentifierNamespace = Target->getIdentifierNamespace(); 1670199482Srdivacky setImplicit(); 1671199482Srdivacky } 1672199482Srdivacky 1673199482Srdivackypublic: 1674199482Srdivacky static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 1675199482Srdivacky SourceLocation Loc, UsingDecl *Using, 1676199482Srdivacky NamedDecl *Target) { 1677199482Srdivacky return new (C) UsingShadowDecl(DC, Loc, Using, Target); 1678199482Srdivacky } 1679199482Srdivacky 1680199482Srdivacky /// Gets the underlying declaration which has been brought into the 1681199482Srdivacky /// local scope. 1682199482Srdivacky NamedDecl *getTargetDecl() const { 1683199482Srdivacky return Underlying; 1684199482Srdivacky } 1685199482Srdivacky 1686199482Srdivacky /// Gets the using declaration to which this declaration is tied. 1687199482Srdivacky UsingDecl *getUsingDecl() const { 1688199482Srdivacky return Using; 1689199482Srdivacky } 1690199482Srdivacky 1691199482Srdivacky static bool classof(const Decl *D) { 1692199482Srdivacky return D->getKind() == Decl::UsingShadow; 1693199482Srdivacky } 1694199482Srdivacky static bool classof(const UsingShadowDecl *D) { return true; } 1695199482Srdivacky}; 1696199482Srdivacky 1697194613Sed/// UsingDecl - Represents a C++ using-declaration. For example: 1698194613Sed/// using someNameSpace::someIdentifier; 1699194613Sedclass UsingDecl : public NamedDecl { 1700194613Sed /// \brief The source range that covers the nested-name-specifier 1701194613Sed /// preceding the declaration name. 1702194613Sed SourceRange NestedNameRange; 1703198092Srdivacky 1704194613Sed /// \brief The source location of the "using" location itself. 1705194613Sed SourceLocation UsingLocation; 1706198092Srdivacky 1707198092Srdivacky /// \brief Target nested name specifier. 1708199482Srdivacky NestedNameSpecifier* TargetNestedName; 1709194613Sed 1710199482Srdivacky /// \brief The collection of shadow declarations associated with 1711199482Srdivacky /// this using declaration. This set can change as a class is 1712199482Srdivacky /// processed. 1713199482Srdivacky llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows; 1714199482Srdivacky 1715198092Srdivacky // \brief Has 'typename' keyword. 1716194613Sed bool IsTypeName; 1717194613Sed 1718194613Sed UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1719199482Srdivacky SourceLocation UL, NestedNameSpecifier* TargetNNS, 1720199482Srdivacky DeclarationName Name, bool IsTypeNameArg) 1721199482Srdivacky : NamedDecl(Decl::Using, DC, L, Name), 1722199482Srdivacky NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS), 1723199482Srdivacky IsTypeName(IsTypeNameArg) { 1724194613Sed } 1725194613Sed 1726194613Sedpublic: 1727194613Sed /// \brief Returns the source range that covers the nested-name-specifier 1728194613Sed /// preceding the namespace name. 1729195099Sed SourceRange getNestedNameRange() { return NestedNameRange; } 1730198092Srdivacky 1731194613Sed /// \brief Returns the source location of the "using" location itself. 1732195099Sed SourceLocation getUsingLocation() { return UsingLocation; } 1733198092Srdivacky 1734194613Sed /// \brief Get target nested name declaration. 1735198092Srdivacky NestedNameSpecifier* getTargetNestedNameDecl() { 1736199482Srdivacky return TargetNestedName; 1737195099Sed } 1738198092Srdivacky 1739198092Srdivacky /// isTypeName - Return true if using decl has 'typename'. 1740195099Sed bool isTypeName() const { return IsTypeName; } 1741194613Sed 1742199482Srdivacky typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator; 1743199482Srdivacky shadow_iterator shadow_begin() const { return Shadows.begin(); } 1744199482Srdivacky shadow_iterator shadow_end() const { return Shadows.end(); } 1745199482Srdivacky 1746199482Srdivacky void addShadowDecl(UsingShadowDecl *S) { 1747199482Srdivacky assert(S->getUsingDecl() == this); 1748199482Srdivacky if (!Shadows.insert(S)) { 1749199482Srdivacky assert(false && "declaration already in set"); 1750199482Srdivacky } 1751199482Srdivacky } 1752199482Srdivacky void removeShadowDecl(UsingShadowDecl *S) { 1753199482Srdivacky assert(S->getUsingDecl() == this); 1754199482Srdivacky if (!Shadows.erase(S)) { 1755199482Srdivacky assert(false && "declaration not in set"); 1756199482Srdivacky } 1757199482Srdivacky } 1758199482Srdivacky 1759194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1760199482Srdivacky SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL, 1761199482Srdivacky NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg); 1762194613Sed 1763194613Sed static bool classof(const Decl *D) { 1764194613Sed return D->getKind() == Decl::Using; 1765194613Sed } 1766194613Sed static bool classof(const UsingDecl *D) { return true; } 1767194613Sed}; 1768198092Srdivacky 1769199482Srdivacky/// UnresolvedUsingValueDecl - Represents a dependent using 1770199482Srdivacky/// declaration which was not marked with 'typename'. Unlike 1771199482Srdivacky/// non-dependent using declarations, these *only* bring through 1772199482Srdivacky/// non-types; otherwise they would break two-phase lookup. 1773199482Srdivacky/// 1774199482Srdivacky/// template <class T> class A : public Base<T> { 1775199482Srdivacky/// using Base<T>::foo; 1776199482Srdivacky/// }; 1777199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl { 1778198092Srdivacky /// \brief The source range that covers the nested-name-specifier 1779198092Srdivacky /// preceding the declaration name. 1780198092Srdivacky SourceRange TargetNestedNameRange; 1781198092Srdivacky 1782199482Srdivacky /// \brief The source location of the 'using' keyword 1783199482Srdivacky SourceLocation UsingLocation; 1784198092Srdivacky 1785198092Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 1786198092Srdivacky 1787199482Srdivacky UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 1788199482Srdivacky SourceLocation UsingLoc, SourceRange TargetNNR, 1789199482Srdivacky NestedNameSpecifier *TargetNNS, 1790199482Srdivacky SourceLocation TargetNameLoc, 1791199482Srdivacky DeclarationName TargetName) 1792199482Srdivacky : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), 1793199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1794199482Srdivacky TargetNestedNameSpecifier(TargetNNS) 1795199482Srdivacky { } 1796198092Srdivacky 1797199482Srdivackypublic: 1798199482Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 1799199482Srdivacky /// preceding the namespace name. 1800199482Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1801198092Srdivacky 1802199482Srdivacky /// \brief Get target nested name declaration. 1803199482Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 1804199482Srdivacky return TargetNestedNameSpecifier; 1805199482Srdivacky } 1806198092Srdivacky 1807199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 1808199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 1809199482Srdivacky 1810199482Srdivacky static UnresolvedUsingValueDecl * 1811199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1812199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1813199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 1814199482Srdivacky 1815199482Srdivacky static bool classof(const Decl *D) { 1816199482Srdivacky return D->getKind() == Decl::UnresolvedUsingValue; 1817199482Srdivacky } 1818199482Srdivacky static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 1819199482Srdivacky}; 1820199482Srdivacky 1821199482Srdivacky/// UnresolvedUsingTypenameDecl - Represents a dependent using 1822199482Srdivacky/// declaration which was marked with 'typename'. 1823199482Srdivacky/// 1824199482Srdivacky/// template <class T> class A : public Base<T> { 1825199482Srdivacky/// using typename Base<T>::foo; 1826199482Srdivacky/// }; 1827199482Srdivacky/// 1828199482Srdivacky/// The type associated with a unresolved using typename decl is 1829199482Srdivacky/// currently always a typename type. 1830199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl { 1831199482Srdivacky /// \brief The source range that covers the nested-name-specifier 1832199482Srdivacky /// preceding the declaration name. 1833199482Srdivacky SourceRange TargetNestedNameRange; 1834199482Srdivacky 1835199482Srdivacky /// \brief The source location of the 'using' keyword 1836199482Srdivacky SourceLocation UsingLocation; 1837199482Srdivacky 1838199482Srdivacky /// \brief The source location of the 'typename' keyword 1839199482Srdivacky SourceLocation TypenameLocation; 1840199482Srdivacky 1841199482Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 1842199482Srdivacky 1843199482Srdivacky UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 1844199482Srdivacky SourceLocation TypenameLoc, 1845199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1846199482Srdivacky SourceLocation TargetNameLoc, IdentifierInfo *TargetName) 1847199482Srdivacky : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), 1848199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1849199482Srdivacky TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS) 1850199482Srdivacky { } 1851199482Srdivacky 1852198092Srdivackypublic: 1853198092Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 1854198092Srdivacky /// preceding the namespace name. 1855198092Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1856198092Srdivacky 1857198092Srdivacky /// \brief Get target nested name declaration. 1858198092Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 1859198092Srdivacky return TargetNestedNameSpecifier; 1860198092Srdivacky } 1861198092Srdivacky 1862199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 1863199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 1864198092Srdivacky 1865199482Srdivacky /// \brief Returns the source location of the 'typename' keyword. 1866199482Srdivacky SourceLocation getTypenameLoc() const { return TypenameLocation; } 1867198092Srdivacky 1868199482Srdivacky static UnresolvedUsingTypenameDecl * 1869199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1870199482Srdivacky SourceLocation TypenameLoc, 1871199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1872199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 1873198092Srdivacky 1874198092Srdivacky static bool classof(const Decl *D) { 1875199482Srdivacky return D->getKind() == Decl::UnresolvedUsingTypename; 1876198092Srdivacky } 1877199482Srdivacky static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 1878198092Srdivacky}; 1879198092Srdivacky 1880193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1881193326Sedclass StaticAssertDecl : public Decl { 1882193326Sed Expr *AssertExpr; 1883193326Sed StringLiteral *Message; 1884193326Sed 1885198092Srdivacky StaticAssertDecl(DeclContext *DC, SourceLocation L, 1886193326Sed Expr *assertexpr, StringLiteral *message) 1887193326Sed : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1888198092Srdivacky 1889193326Sedpublic: 1890193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1891193326Sed SourceLocation L, Expr *AssertExpr, 1892193326Sed StringLiteral *Message); 1893198092Srdivacky 1894193326Sed Expr *getAssertExpr() { return AssertExpr; } 1895193326Sed const Expr *getAssertExpr() const { return AssertExpr; } 1896198092Srdivacky 1897193326Sed StringLiteral *getMessage() { return Message; } 1898193326Sed const StringLiteral *getMessage() const { return Message; } 1899198092Srdivacky 1900193326Sed virtual ~StaticAssertDecl(); 1901193326Sed virtual void Destroy(ASTContext& C); 1902193326Sed 1903193326Sed static bool classof(const Decl *D) { 1904193326Sed return D->getKind() == Decl::StaticAssert; 1905193326Sed } 1906193326Sed static bool classof(StaticAssertDecl *D) { return true; } 1907193326Sed}; 1908193326Sed 1909193326Sed/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1910193326Sed/// into a diagnostic with <<. 1911193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1912193326Sed AccessSpecifier AS); 1913198092Srdivacky 1914193326Sed} // end namespace clang 1915193326Sed 1916193326Sed#endif 1917