DeclCXX.h revision 201361
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/// CXXBaseSpecifier - A base class of a C++ class. 92193326Sed/// 93193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 94193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 95193326Sed/// base class, whether it is a virtual or non-virtual base, and what 96193326Sed/// level of access (public, protected, private) is used for the 97193326Sed/// derivation. For example: 98193326Sed/// 99193326Sed/// @code 100193326Sed/// class A { }; 101193326Sed/// class B { }; 102193326Sed/// class C : public virtual A, protected B { }; 103193326Sed/// @endcode 104193326Sed/// 105193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 106193326Sed/// virtual A" and the other for "protected B". 107193326Sedclass CXXBaseSpecifier { 108193326Sed /// Range - The source code range that covers the full base 109193326Sed /// specifier, including the "virtual" (if present) and access 110193326Sed /// specifier (if present). 111200583Srdivacky // FIXME: Move over to a TypeLoc! 112193326Sed SourceRange Range; 113193326Sed 114193326Sed /// Virtual - Whether this is a virtual base class or not. 115193326Sed bool Virtual : 1; 116193326Sed 117193326Sed /// BaseOfClass - Whether this is the base of a class (true) or of a 118193326Sed /// struct (false). This determines the mapping from the access 119193326Sed /// specifier as written in the source code to the access specifier 120193326Sed /// used for semantic analysis. 121198092Srdivacky bool BaseOfClass : 1; 122193326Sed 123193326Sed /// Access - Access specifier as written in the source code (which 124193326Sed /// may be AS_none). The actual type of data stored here is an 125193326Sed /// AccessSpecifier, but we use "unsigned" here to work around a 126193326Sed /// VC++ bug. 127193326Sed unsigned Access : 2; 128193326Sed 129193326Sed /// BaseType - The type of the base class. This will be a class or 130193326Sed /// struct (or a typedef of such). 131193326Sed QualType BaseType; 132198092Srdivacky 133193326Sedpublic: 134193326Sed CXXBaseSpecifier() { } 135193326Sed 136193326Sed CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 137193326Sed : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 138193326Sed 139193326Sed /// getSourceRange - Retrieves the source range that contains the 140193326Sed /// entire base specifier. 141193326Sed SourceRange getSourceRange() const { return Range; } 142198092Srdivacky 143193326Sed /// isVirtual - Determines whether the base class is a virtual base 144193326Sed /// class (or not). 145193326Sed bool isVirtual() const { return Virtual; } 146193326Sed 147193326Sed /// getAccessSpecifier - Returns the access specifier for this base 148193326Sed /// specifier. This is the actual base specifier as used for 149193326Sed /// semantic analysis, so the result can never be AS_none. To 150193326Sed /// retrieve the access specifier as written in the source code, use 151193326Sed /// getAccessSpecifierAsWritten(). 152198092Srdivacky AccessSpecifier getAccessSpecifier() const { 153193326Sed if ((AccessSpecifier)Access == AS_none) 154193326Sed return BaseOfClass? AS_private : AS_public; 155193326Sed else 156198092Srdivacky return (AccessSpecifier)Access; 157193326Sed } 158193326Sed 159193326Sed /// getAccessSpecifierAsWritten - Retrieves the access specifier as 160193326Sed /// written in the source code (which may mean that no access 161193326Sed /// specifier was explicitly written). Use getAccessSpecifier() to 162193326Sed /// retrieve the access specifier for use in semantic analysis. 163193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 164193326Sed return (AccessSpecifier)Access; 165193326Sed } 166193326Sed 167193326Sed /// getType - Retrieves the type of the base class. This type will 168193326Sed /// always be an unqualified class type. 169193326Sed QualType getType() const { return BaseType; } 170193326Sed}; 171193326Sed 172193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class. 173193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 174193326Sed/// to deal with C++-specific things. 175193326Sedclass CXXRecordDecl : public RecordDecl { 176193326Sed /// UserDeclaredConstructor - True when this class has a 177198092Srdivacky /// user-declared constructor. 178193326Sed bool UserDeclaredConstructor : 1; 179193326Sed 180193326Sed /// UserDeclaredCopyConstructor - True when this class has a 181193326Sed /// user-declared copy constructor. 182193326Sed bool UserDeclaredCopyConstructor : 1; 183193326Sed 184193326Sed /// UserDeclaredCopyAssignment - True when this class has a 185193326Sed /// user-declared copy assignment operator. 186193326Sed bool UserDeclaredCopyAssignment : 1; 187193326Sed 188193326Sed /// UserDeclaredDestructor - True when this class has a 189193326Sed /// user-declared destructor. 190193326Sed bool UserDeclaredDestructor : 1; 191193326Sed 192193326Sed /// Aggregate - True when this class is an aggregate. 193193326Sed bool Aggregate : 1; 194193326Sed 195193326Sed /// PlainOldData - True when this class is a POD-type. 196193326Sed bool PlainOldData : 1; 197193326Sed 198198092Srdivacky /// Empty - true when this class is empty for traits purposes, i.e. has no 199198092Srdivacky /// data members other than 0-width bit-fields, has no virtual function/base, 200198092Srdivacky /// and doesn't inherit from a non-empty class. Doesn't take union-ness into 201198092Srdivacky /// account. 202198092Srdivacky bool Empty : 1; 203198092Srdivacky 204193326Sed /// Polymorphic - True when this class is polymorphic, i.e. has at least one 205193326Sed /// virtual member or derives from a polymorphic class. 206193326Sed bool Polymorphic : 1; 207193326Sed 208193326Sed /// Abstract - True when this class is abstract, i.e. has at least one 209193326Sed /// pure virtual function, (that can come from a base class). 210193326Sed bool Abstract : 1; 211198092Srdivacky 212198092Srdivacky /// HasTrivialConstructor - True when this class has a trivial constructor. 213198092Srdivacky /// 214198092Srdivacky /// C++ [class.ctor]p5. A constructor is trivial if it is an 215198092Srdivacky /// implicitly-declared default constructor and if: 216198092Srdivacky /// * its class has no virtual functions and no virtual base classes, and 217198092Srdivacky /// * all the direct base classes of its class have trivial constructors, and 218198092Srdivacky /// * for all the nonstatic data members of its class that are of class type 219198092Srdivacky /// (or array thereof), each such class has a trivial constructor. 220193326Sed bool HasTrivialConstructor : 1; 221198092Srdivacky 222198092Srdivacky /// HasTrivialCopyConstructor - True when this class has a trivial copy 223198092Srdivacky /// constructor. 224198092Srdivacky /// 225198092Srdivacky /// C++ [class.copy]p6. A copy constructor for class X is trivial 226198092Srdivacky /// if it is implicitly declared and if 227198092Srdivacky /// * class X has no virtual functions and no virtual base classes, and 228198092Srdivacky /// * each direct base class of X has a trivial copy constructor, and 229198092Srdivacky /// * for all the nonstatic data members of X that are of class type (or 230198092Srdivacky /// array thereof), each such class type has a trivial copy constructor; 231198092Srdivacky /// otherwise the copy constructor is non-trivial. 232198092Srdivacky bool HasTrivialCopyConstructor : 1; 233198092Srdivacky 234198092Srdivacky /// HasTrivialCopyAssignment - True when this class has a trivial copy 235198092Srdivacky /// assignment operator. 236198092Srdivacky /// 237198092Srdivacky /// C++ [class.copy]p11. A copy assignment operator for class X is 238198092Srdivacky /// trivial if it is implicitly declared and if 239198092Srdivacky /// * class X has no virtual functions and no virtual base classes, and 240198092Srdivacky /// * each direct base class of X has a trivial copy assignment operator, and 241198092Srdivacky /// * for all the nonstatic data members of X that are of class type (or 242198092Srdivacky /// array thereof), each such class type has a trivial copy assignment 243198092Srdivacky /// operator; 244198092Srdivacky /// otherwise the copy assignment operator is non-trivial. 245198092Srdivacky bool HasTrivialCopyAssignment : 1; 246198092Srdivacky 247198092Srdivacky /// HasTrivialDestructor - True when this class has a trivial destructor. 248198092Srdivacky /// 249198092Srdivacky /// C++ [class.dtor]p3. A destructor is trivial if it is an 250198092Srdivacky /// implicitly-declared destructor and if: 251198092Srdivacky /// * all of the direct base classes of its class have trivial destructors 252198092Srdivacky /// and 253198092Srdivacky /// * for all of the non-static data members of its class that are of class 254198092Srdivacky /// type (or array thereof), each such class has a trivial destructor. 255193326Sed bool HasTrivialDestructor : 1; 256198092Srdivacky 257198092Srdivacky /// ComputedVisibleConversions - True when visible conversion functions are 258198092Srdivacky /// already computed and are available. 259198092Srdivacky bool ComputedVisibleConversions : 1; 260193326Sed 261193326Sed /// Bases - Base classes of this class. 262193326Sed /// FIXME: This is wasted space for a union. 263193326Sed CXXBaseSpecifier *Bases; 264193326Sed 265193326Sed /// NumBases - The number of base class specifiers in Bases. 266193326Sed unsigned NumBases; 267193326Sed 268198092Srdivacky /// VBases - direct and indirect virtual base classes of this class. 269198092Srdivacky CXXBaseSpecifier *VBases; 270198092Srdivacky 271198092Srdivacky /// NumVBases - The number of virtual base class specifiers in VBases. 272198092Srdivacky unsigned NumVBases; 273198092Srdivacky 274193326Sed /// Conversions - Overload set containing the conversion functions 275193326Sed /// of this C++ class (but not its inherited conversion 276193326Sed /// functions). Each of the entries in this overload set is a 277198092Srdivacky /// CXXConversionDecl. 278199990Srdivacky UnresolvedSet Conversions; 279193326Sed 280198092Srdivacky /// VisibleConversions - Overload set containing the conversion functions 281198092Srdivacky /// of this C++ class and all those inherited conversion functions that 282198092Srdivacky /// are visible in this class. Each of the entries in this overload set is 283198092Srdivacky /// a CXXConversionDecl or a FunctionTemplateDecl. 284199990Srdivacky UnresolvedSet VisibleConversions; 285198092Srdivacky 286193326Sed /// \brief The template or declaration that this declaration 287193326Sed /// describes or was instantiated from, respectively. 288198092Srdivacky /// 289193326Sed /// For non-templates, this value will be NULL. For record 290193326Sed /// declarations that describe a class template, this will be a 291193326Sed /// pointer to a ClassTemplateDecl. For member 292193326Sed /// classes of class template specializations, this will be the 293198092Srdivacky /// MemberSpecializationInfo referring to the member class that was 294198092Srdivacky /// instantiated or specialized. 295198092Srdivacky llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 296193326Sed TemplateOrInstantiation; 297198092Srdivacky 298198092Srdivacky void getNestedVisibleConversionFunctions(CXXRecordDecl *RD, 299198092Srdivacky const llvm::SmallPtrSet<CanQualType, 8> &TopConversionsTypeSet, 300198092Srdivacky const llvm::SmallPtrSet<CanQualType, 8> &HiddenConversionTypes); 301198092Srdivacky void collectConversionFunctions( 302199990Srdivacky llvm::SmallPtrSet<CanQualType, 8>& ConversionsTypeSet) const; 303198092Srdivacky 304193326Sedprotected: 305193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 306198092Srdivacky SourceLocation L, IdentifierInfo *Id, 307198092Srdivacky CXXRecordDecl *PrevDecl, 308198092Srdivacky SourceLocation TKL = SourceLocation()); 309193326Sed 310193326Sed ~CXXRecordDecl(); 311193326Sed 312193326Sedpublic: 313193326Sed /// base_class_iterator - Iterator that traverses the base classes 314198092Srdivacky /// of a class. 315193326Sed typedef CXXBaseSpecifier* base_class_iterator; 316193326Sed 317193326Sed /// base_class_const_iterator - Iterator that traverses the base 318198092Srdivacky /// classes of a class. 319193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 320193326Sed 321198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 322198092Srdivacky /// of a class in reverse order. 323198092Srdivacky typedef std::reverse_iterator<base_class_iterator> 324198092Srdivacky reverse_base_class_iterator; 325198092Srdivacky 326198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 327198092Srdivacky /// of a class in reverse order. 328198092Srdivacky typedef std::reverse_iterator<base_class_const_iterator> 329198092Srdivacky reverse_base_class_const_iterator; 330198092Srdivacky 331198092Srdivacky virtual CXXRecordDecl *getCanonicalDecl() { 332198092Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 333198092Srdivacky } 334199482Srdivacky virtual const CXXRecordDecl *getCanonicalDecl() const { 335199482Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 336199482Srdivacky } 337198092Srdivacky 338193326Sed static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 339193326Sed SourceLocation L, IdentifierInfo *Id, 340198092Srdivacky SourceLocation TKL = SourceLocation(), 341193326Sed CXXRecordDecl* PrevDecl=0, 342193326Sed bool DelayTypeCreation = false); 343198092Srdivacky 344195341Sed virtual void Destroy(ASTContext& C); 345198092Srdivacky 346198092Srdivacky bool isDynamicClass() const { 347198092Srdivacky return Polymorphic || NumVBases != 0; 348198092Srdivacky } 349198092Srdivacky 350193326Sed /// setBases - Sets the base classes of this struct or class. 351195341Sed void setBases(ASTContext &C, 352195341Sed CXXBaseSpecifier const * const *Bases, unsigned NumBases); 353193326Sed 354193326Sed /// getNumBases - Retrieves the number of base classes of this 355193326Sed /// class. 356193326Sed unsigned getNumBases() const { return NumBases; } 357193326Sed 358193326Sed base_class_iterator bases_begin() { return Bases; } 359193326Sed base_class_const_iterator bases_begin() const { return Bases; } 360193326Sed base_class_iterator bases_end() { return Bases + NumBases; } 361193326Sed base_class_const_iterator bases_end() const { return Bases + NumBases; } 362198092Srdivacky reverse_base_class_iterator bases_rbegin() { 363198092Srdivacky return reverse_base_class_iterator(bases_end()); 364198092Srdivacky } 365198092Srdivacky reverse_base_class_const_iterator bases_rbegin() const { 366198092Srdivacky return reverse_base_class_const_iterator(bases_end()); 367198092Srdivacky } 368198092Srdivacky reverse_base_class_iterator bases_rend() { 369198092Srdivacky return reverse_base_class_iterator(bases_begin()); 370198092Srdivacky } 371198092Srdivacky reverse_base_class_const_iterator bases_rend() const { 372198092Srdivacky return reverse_base_class_const_iterator(bases_begin()); 373198092Srdivacky } 374193326Sed 375198092Srdivacky /// getNumVBases - Retrieves the number of virtual base classes of this 376198092Srdivacky /// class. 377198092Srdivacky unsigned getNumVBases() const { return NumVBases; } 378198092Srdivacky 379198092Srdivacky base_class_iterator vbases_begin() { return VBases; } 380198092Srdivacky base_class_const_iterator vbases_begin() const { return VBases; } 381198092Srdivacky base_class_iterator vbases_end() { return VBases + NumVBases; } 382198092Srdivacky base_class_const_iterator vbases_end() const { return VBases + NumVBases; } 383198092Srdivacky reverse_base_class_iterator vbases_rbegin() { 384198092Srdivacky return reverse_base_class_iterator(vbases_end()); 385198092Srdivacky } 386198092Srdivacky reverse_base_class_const_iterator vbases_rbegin() const { 387198092Srdivacky return reverse_base_class_const_iterator(vbases_end()); 388198092Srdivacky } 389198092Srdivacky reverse_base_class_iterator vbases_rend() { 390198092Srdivacky return reverse_base_class_iterator(vbases_begin()); 391198092Srdivacky } 392198092Srdivacky reverse_base_class_const_iterator vbases_rend() const { 393198092Srdivacky return reverse_base_class_const_iterator(vbases_begin()); 394198092Srdivacky } 395198092Srdivacky 396198092Srdivacky /// Iterator access to method members. The method iterator visits 397198092Srdivacky /// all method members of the class, including non-instance methods, 398198092Srdivacky /// special methods, etc. 399198092Srdivacky typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 400198092Srdivacky 401198092Srdivacky /// method_begin - Method begin iterator. Iterates in the order the methods 402198092Srdivacky /// were declared. 403198092Srdivacky method_iterator method_begin() const { 404198092Srdivacky return method_iterator(decls_begin()); 405198092Srdivacky } 406198092Srdivacky /// method_end - Method end iterator. 407198092Srdivacky method_iterator method_end() const { 408198092Srdivacky return method_iterator(decls_end()); 409198092Srdivacky } 410198092Srdivacky 411198092Srdivacky /// Iterator access to constructor members. 412198092Srdivacky typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 413198092Srdivacky 414198092Srdivacky ctor_iterator ctor_begin() const { 415198092Srdivacky return ctor_iterator(decls_begin()); 416198092Srdivacky } 417198092Srdivacky ctor_iterator ctor_end() const { 418198092Srdivacky return ctor_iterator(decls_end()); 419198092Srdivacky } 420198092Srdivacky 421193326Sed /// hasConstCopyConstructor - Determines whether this class has a 422193326Sed /// copy constructor that accepts a const-qualified argument. 423193326Sed bool hasConstCopyConstructor(ASTContext &Context) const; 424193326Sed 425194711Sed /// getCopyConstructor - Returns the copy constructor for this class 426198092Srdivacky CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 427194711Sed unsigned TypeQuals) const; 428194711Sed 429193326Sed /// hasConstCopyAssignment - Determines whether this class has a 430193326Sed /// copy assignment operator that accepts a const-qualified argument. 431198092Srdivacky /// It returns its decl in MD if found. 432198092Srdivacky bool hasConstCopyAssignment(ASTContext &Context, 433198092Srdivacky const CXXMethodDecl *&MD) const; 434193326Sed 435193326Sed /// addedConstructor - Notify the class that another constructor has 436193326Sed /// been added. This routine helps maintain information about the 437193326Sed /// class based on which constructors have been added. 438193326Sed void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 439193326Sed 440193326Sed /// hasUserDeclaredConstructor - Whether this class has any 441193326Sed /// user-declared constructors. When true, a default constructor 442193326Sed /// will not be implicitly declared. 443198092Srdivacky bool hasUserDeclaredConstructor() const { 444198092Srdivacky assert((isDefinition() || 445198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 446198092Srdivacky "Incomplete record decl!"); 447198092Srdivacky return UserDeclaredConstructor; 448198092Srdivacky } 449193326Sed 450193326Sed /// hasUserDeclaredCopyConstructor - Whether this class has a 451193326Sed /// user-declared copy constructor. When false, a copy constructor 452193326Sed /// will be implicitly declared. 453193326Sed bool hasUserDeclaredCopyConstructor() const { 454193326Sed return UserDeclaredCopyConstructor; 455193326Sed } 456193326Sed 457193326Sed /// addedAssignmentOperator - Notify the class that another assignment 458193326Sed /// operator has been added. This routine helps maintain information about the 459193326Sed /// class based on which operators have been added. 460193326Sed void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 461193326Sed 462193326Sed /// hasUserDeclaredCopyAssignment - Whether this class has a 463193326Sed /// user-declared copy assignment operator. When false, a copy 464193326Sed /// assigment operator will be implicitly declared. 465193326Sed bool hasUserDeclaredCopyAssignment() const { 466193326Sed return UserDeclaredCopyAssignment; 467193326Sed } 468193326Sed 469193326Sed /// hasUserDeclaredDestructor - Whether this class has a 470193326Sed /// user-declared destructor. When false, a destructor will be 471193326Sed /// implicitly declared. 472193326Sed bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 473193326Sed 474193326Sed /// setUserDeclaredDestructor - Set whether this class has a 475193326Sed /// user-declared destructor. If not set by the time the class is 476193326Sed /// fully defined, a destructor will be implicitly declared. 477198092Srdivacky void setUserDeclaredDestructor(bool UCD) { 478198092Srdivacky UserDeclaredDestructor = UCD; 479193326Sed } 480193326Sed 481193326Sed /// getConversions - Retrieve the overload set containing all of the 482193326Sed /// conversion functions in this class. 483199990Srdivacky UnresolvedSet *getConversionFunctions() { 484198092Srdivacky assert((this->isDefinition() || 485198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 486198092Srdivacky "getConversionFunctions() called on incomplete type"); 487198092Srdivacky return &Conversions; 488193326Sed } 489199990Srdivacky const UnresolvedSet *getConversionFunctions() const { 490198092Srdivacky assert((this->isDefinition() || 491198092Srdivacky cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 492198092Srdivacky "getConversionFunctions() called on incomplete type"); 493198092Srdivacky return &Conversions; 494193326Sed } 495193326Sed 496199990Srdivacky typedef UnresolvedSet::iterator conversion_iterator; 497199990Srdivacky conversion_iterator conversion_begin() const { return Conversions.begin(); } 498199990Srdivacky conversion_iterator conversion_end() const { return Conversions.end(); } 499199990Srdivacky 500199990Srdivacky /// Replaces a conversion function with a new declaration. 501199990Srdivacky /// 502199990Srdivacky /// Returns true if the old conversion was found. 503199990Srdivacky bool replaceConversion(const NamedDecl* Old, NamedDecl *New) { 504199990Srdivacky return Conversions.replace(Old, New); 505199990Srdivacky } 506199990Srdivacky 507198092Srdivacky /// getVisibleConversionFunctions - get all conversion functions visible 508198092Srdivacky /// in current class; including conversion function templates. 509199990Srdivacky const UnresolvedSet *getVisibleConversionFunctions(); 510199990Srdivacky 511198092Srdivacky /// addVisibleConversionFunction - Add a new conversion function to the 512198092Srdivacky /// list of visible conversion functions. 513198092Srdivacky void addVisibleConversionFunction(CXXConversionDecl *ConvDecl); 514198092Srdivacky 515198092Srdivacky /// \brief Add a new conversion function template to the list of visible 516198092Srdivacky /// conversion functions. 517198092Srdivacky void addVisibleConversionFunction(FunctionTemplateDecl *ConvDecl); 518198092Srdivacky 519193326Sed /// addConversionFunction - Add a new conversion function to the 520193326Sed /// list of conversion functions. 521198092Srdivacky void addConversionFunction(CXXConversionDecl *ConvDecl); 522193326Sed 523198092Srdivacky /// \brief Add a new conversion function template to the list of conversion 524198092Srdivacky /// functions. 525198092Srdivacky void addConversionFunction(FunctionTemplateDecl *ConvDecl); 526198092Srdivacky 527193326Sed /// isAggregate - Whether this class is an aggregate (C++ 528193326Sed /// [dcl.init.aggr]), which is a class with no user-declared 529193326Sed /// constructors, no private or protected non-static data members, 530193326Sed /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 531193326Sed bool isAggregate() const { return Aggregate; } 532193326Sed 533193326Sed /// setAggregate - Set whether this class is an aggregate (C++ 534193326Sed /// [dcl.init.aggr]). 535193326Sed void setAggregate(bool Agg) { Aggregate = Agg; } 536193326Sed 537200583Srdivacky /// setMethodAsVirtual - Make input method virtual and set the necesssary 538200583Srdivacky /// special function bits and other bits accordingly. 539200583Srdivacky void setMethodAsVirtual(FunctionDecl *Method); 540200583Srdivacky 541193326Sed /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 542193326Sed /// that is an aggregate that has no non-static non-POD data members, no 543193326Sed /// reference data members, no user-defined copy assignment operator and no 544193326Sed /// user-defined destructor. 545193326Sed bool isPOD() const { return PlainOldData; } 546193326Sed 547193326Sed /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 548193326Sed void setPOD(bool POD) { PlainOldData = POD; } 549193326Sed 550198092Srdivacky /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 551198092Srdivacky /// means it has a virtual function, virtual base, data member (other than 552198092Srdivacky /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 553198092Srdivacky /// a check for union-ness. 554198092Srdivacky bool isEmpty() const { return Empty; } 555198092Srdivacky 556198092Srdivacky /// Set whether this class is empty (C++0x [meta.unary.prop]) 557198092Srdivacky void setEmpty(bool Emp) { Empty = Emp; } 558198092Srdivacky 559193326Sed /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 560193326Sed /// which means that the class contains or inherits a virtual function. 561193326Sed bool isPolymorphic() const { return Polymorphic; } 562193326Sed 563193326Sed /// setPolymorphic - Set whether this class is polymorphic (C++ 564193326Sed /// [class.virtual]). 565193326Sed void setPolymorphic(bool Poly) { Polymorphic = Poly; } 566193326Sed 567193326Sed /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 568193326Sed /// which means that the class contains or inherits a pure virtual function. 569193326Sed bool isAbstract() const { return Abstract; } 570198092Srdivacky 571193326Sed /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 572193326Sed void setAbstract(bool Abs) { Abstract = Abs; } 573198092Srdivacky 574193326Sed // hasTrivialConstructor - Whether this class has a trivial constructor 575193326Sed // (C++ [class.ctor]p5) 576193326Sed bool hasTrivialConstructor() const { return HasTrivialConstructor; } 577198092Srdivacky 578193326Sed // setHasTrivialConstructor - Set whether this class has a trivial constructor 579193326Sed // (C++ [class.ctor]p5) 580193326Sed void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 581198092Srdivacky 582198092Srdivacky // hasTrivialCopyConstructor - Whether this class has a trivial copy 583198092Srdivacky // constructor (C++ [class.copy]p6) 584198092Srdivacky bool hasTrivialCopyConstructor() const { return HasTrivialCopyConstructor; } 585198092Srdivacky 586198092Srdivacky // setHasTrivialCopyConstructor - Set whether this class has a trivial 587198092Srdivacky // copy constructor (C++ [class.copy]p6) 588198092Srdivacky void setHasTrivialCopyConstructor(bool TC) { HasTrivialCopyConstructor = TC; } 589198092Srdivacky 590198092Srdivacky // hasTrivialCopyAssignment - Whether this class has a trivial copy 591198092Srdivacky // assignment operator (C++ [class.copy]p11) 592198092Srdivacky bool hasTrivialCopyAssignment() const { return HasTrivialCopyAssignment; } 593198092Srdivacky 594198092Srdivacky // setHasTrivialCopyAssignment - Set whether this class has a 595198092Srdivacky // trivial copy assignment operator (C++ [class.copy]p11) 596198092Srdivacky void setHasTrivialCopyAssignment(bool TC) { HasTrivialCopyAssignment = TC; } 597198092Srdivacky 598193326Sed // hasTrivialDestructor - Whether this class has a trivial destructor 599193326Sed // (C++ [class.dtor]p3) 600193326Sed bool hasTrivialDestructor() const { return HasTrivialDestructor; } 601198092Srdivacky 602193326Sed // setHasTrivialDestructor - Set whether this class has a trivial destructor 603193326Sed // (C++ [class.dtor]p3) 604193326Sed void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 605198092Srdivacky 606193326Sed /// \brief If this record is an instantiation of a member class, 607193326Sed /// retrieves the member class from which it was instantiated. 608193326Sed /// 609193326Sed /// This routine will return non-NULL for (non-templated) member 610193326Sed /// classes of class templates. For example, given: 611193326Sed /// 612193326Sed /// \code 613193326Sed /// template<typename T> 614193326Sed /// struct X { 615193326Sed /// struct A { }; 616193326Sed /// }; 617193326Sed /// \endcode 618193326Sed /// 619193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 620193326Sed /// whose parent is the class template specialization X<int>. For 621193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 622193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 623193326Sed /// X<int>::A is required, it will be instantiated from the 624193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 625198092Srdivacky CXXRecordDecl *getInstantiatedFromMemberClass() const; 626198092Srdivacky 627198092Srdivacky /// \brief If this class is an instantiation of a member class of a 628198092Srdivacky /// class template specialization, retrieves the member specialization 629198092Srdivacky /// information. 630198092Srdivacky MemberSpecializationInfo *getMemberSpecializationInfo() const; 631198092Srdivacky 632193326Sed /// \brief Specify that this record is an instantiation of the 633193326Sed /// member class RD. 634198092Srdivacky void setInstantiationOfMemberClass(CXXRecordDecl *RD, 635198092Srdivacky TemplateSpecializationKind TSK); 636193326Sed 637193326Sed /// \brief Retrieves the class template that is described by this 638193326Sed /// class declaration. 639193326Sed /// 640193326Sed /// Every class template is represented as a ClassTemplateDecl and a 641193326Sed /// CXXRecordDecl. The former contains template properties (such as 642193326Sed /// the template parameter lists) while the latter contains the 643193326Sed /// actual description of the template's 644193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 645193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 646193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 647193326Sed /// a CXXRecordDecl. 648193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 649193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 650193326Sed } 651193326Sed 652193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 653193326Sed TemplateOrInstantiation = Template; 654193326Sed } 655193326Sed 656198092Srdivacky /// \brief Determine whether this particular class is a specialization or 657198092Srdivacky /// instantiation of a class template or member class of a class template, 658198092Srdivacky /// and how it was instantiated or specialized. 659200583Srdivacky TemplateSpecializationKind getTemplateSpecializationKind() const; 660198092Srdivacky 661198092Srdivacky /// \brief Set the kind of specialization or template instantiation this is. 662198092Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 663198092Srdivacky 664194613Sed /// getDefaultConstructor - Returns the default constructor for this class 665194613Sed CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 666198092Srdivacky 667193326Sed /// getDestructor - Returns the destructor decl for this class. 668200583Srdivacky CXXDestructorDecl *getDestructor(ASTContext &Context); 669198092Srdivacky 670195099Sed /// isLocalClass - If the class is a local class [class.local], returns 671195099Sed /// the enclosing function declaration. 672195099Sed const FunctionDecl *isLocalClass() const { 673195099Sed if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 674195099Sed return RD->isLocalClass(); 675198092Srdivacky 676195099Sed return dyn_cast<FunctionDecl>(getDeclContext()); 677195099Sed } 678198092Srdivacky 679198092Srdivacky /// \brief Determine whether this class is derived from the class \p Base. 680198092Srdivacky /// 681198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 682198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 683198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 684198092Srdivacky /// base class subobjects. 685198092Srdivacky /// 686198092Srdivacky /// \param Base the base class we are searching for. 687198092Srdivacky /// 688198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 689199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base) const; 690195099Sed 691198092Srdivacky /// \brief Determine whether this class is derived from the type \p Base. 692198092Srdivacky /// 693198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 694198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 695198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 696198092Srdivacky /// base class subobjects. 697198092Srdivacky /// 698198092Srdivacky /// \param Base the base class we are searching for. 699198092Srdivacky /// 700198092Srdivacky /// \param Paths will contain the paths taken from the current class to the 701198092Srdivacky /// given \p Base class. 702198092Srdivacky /// 703198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 704198092Srdivacky /// 705198092Srdivacky /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 706198092Srdivacky /// tangling input and output in \p Paths 707199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const; 708200583Srdivacky 709200583Srdivacky /// \brief Determine whether this class is provably not derived from 710200583Srdivacky /// the type \p Base. 711200583Srdivacky bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 712200583Srdivacky 713200583Srdivacky /// \brief Function type used by forallBases() as a callback. 714200583Srdivacky /// 715200583Srdivacky /// \param Base the definition of the base class 716200583Srdivacky /// 717200583Srdivacky /// \returns true if this base matched the search criteria 718200583Srdivacky typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 719200583Srdivacky void *UserData); 720200583Srdivacky 721200583Srdivacky /// \brief Determines if the given callback holds for all the direct 722200583Srdivacky /// or indirect base classes of this type. 723200583Srdivacky /// 724200583Srdivacky /// The class itself does not count as a base class. This routine 725200583Srdivacky /// returns false if the class has non-computable base classes. 726200583Srdivacky /// 727200583Srdivacky /// \param AllowShortCircuit if false, forces the callback to be called 728200583Srdivacky /// for every base class, even if a dependent or non-matching base was 729200583Srdivacky /// found. 730200583Srdivacky bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 731200583Srdivacky bool AllowShortCircuit = true) const; 732198092Srdivacky 733198092Srdivacky /// \brief Function type used by lookupInBases() to determine whether a 734198092Srdivacky /// specific base class subobject matches the lookup criteria. 735198092Srdivacky /// 736198092Srdivacky /// \param Specifier the base-class specifier that describes the inheritance 737198092Srdivacky /// from the base class we are trying to match. 738198092Srdivacky /// 739198092Srdivacky /// \param Path the current path, from the most-derived class down to the 740198092Srdivacky /// base named by the \p Specifier. 741198092Srdivacky /// 742198092Srdivacky /// \param UserData a single pointer to user-specified data, provided to 743198092Srdivacky /// lookupInBases(). 744198092Srdivacky /// 745198092Srdivacky /// \returns true if this base matched the search criteria, false otherwise. 746199482Srdivacky typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 747198092Srdivacky CXXBasePath &Path, 748198092Srdivacky void *UserData); 749198092Srdivacky 750198092Srdivacky /// \brief Look for entities within the base classes of this C++ class, 751198092Srdivacky /// transitively searching all base class subobjects. 752198092Srdivacky /// 753198092Srdivacky /// This routine uses the callback function \p BaseMatches to find base 754198092Srdivacky /// classes meeting some search criteria, walking all base class subobjects 755198092Srdivacky /// and populating the given \p Paths structure with the paths through the 756198092Srdivacky /// inheritance hierarchy that resulted in a match. On a successful search, 757198092Srdivacky /// the \p Paths structure can be queried to retrieve the matching paths and 758198092Srdivacky /// to determine if there were any ambiguities. 759198092Srdivacky /// 760198092Srdivacky /// \param BaseMatches callback function used to determine whether a given 761198092Srdivacky /// base matches the user-defined search criteria. 762198092Srdivacky /// 763198092Srdivacky /// \param UserData user data pointer that will be provided to \p BaseMatches. 764198092Srdivacky /// 765198092Srdivacky /// \param Paths used to record the paths from this class to its base class 766198092Srdivacky /// subobjects that match the search criteria. 767198092Srdivacky /// 768198092Srdivacky /// \returns true if there exists any path from this class to a base class 769198092Srdivacky /// subobject that matches the search criteria. 770198092Srdivacky bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 771199482Srdivacky CXXBasePaths &Paths) const; 772198092Srdivacky 773198092Srdivacky /// \brief Base-class lookup callback that determines whether the given 774198092Srdivacky /// base class specifier refers to a specific class declaration. 775198092Srdivacky /// 776198092Srdivacky /// This callback can be used with \c lookupInBases() to determine whether 777198092Srdivacky /// a given derived class has is a base class subobject of a particular type. 778198092Srdivacky /// The user data pointer should refer to the canonical CXXRecordDecl of the 779198092Srdivacky /// base class that we are searching for. 780199482Srdivacky static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 781199482Srdivacky CXXBasePath &Path, void *BaseRecord); 782198092Srdivacky 783198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 784198092Srdivacky /// a tag with the given name. 785198092Srdivacky /// 786198092Srdivacky /// This callback can be used with \c lookupInBases() to find tag members 787198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 788198092Srdivacky /// is an opaque \c DeclarationName pointer. 789199482Srdivacky static bool FindTagMember(const CXXBaseSpecifier *Specifier, 790199482Srdivacky CXXBasePath &Path, void *Name); 791198092Srdivacky 792198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 793198092Srdivacky /// a member with the given name. 794198092Srdivacky /// 795198092Srdivacky /// This callback can be used with \c lookupInBases() to find members 796198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 797198092Srdivacky /// is an opaque \c DeclarationName pointer. 798199482Srdivacky static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 799199482Srdivacky CXXBasePath &Path, void *Name); 800198092Srdivacky 801198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 802198092Srdivacky /// a member with the given name that can be used in a nested-name-specifier. 803198092Srdivacky /// 804198092Srdivacky /// This callback can be used with \c lookupInBases() to find membes of 805198092Srdivacky /// the given name within a C++ class hierarchy that can occur within 806198092Srdivacky /// nested-name-specifiers. 807199482Srdivacky static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 808198092Srdivacky CXXBasePath &Path, 809198092Srdivacky void *UserData); 810198092Srdivacky 811193326Sed /// viewInheritance - Renders and displays an inheritance diagram 812193326Sed /// for this C++ class and all of its base classes (transitively) using 813193326Sed /// GraphViz. 814193326Sed void viewInheritance(ASTContext& Context) const; 815193326Sed 816198092Srdivacky static bool classof(const Decl *D) { 817198092Srdivacky return D->getKind() == CXXRecord || 818193326Sed D->getKind() == ClassTemplateSpecialization || 819198092Srdivacky D->getKind() == ClassTemplatePartialSpecialization; 820193326Sed } 821193326Sed static bool classof(const CXXRecordDecl *D) { return true; } 822198092Srdivacky static bool classof(const ClassTemplateSpecializationDecl *D) { 823198092Srdivacky return true; 824193326Sed } 825193326Sed}; 826193326Sed 827193326Sed/// CXXMethodDecl - Represents a static or instance method of a 828193326Sed/// struct/union/class. 829193326Sedclass CXXMethodDecl : public FunctionDecl { 830193326Sedprotected: 831193326Sed CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 832200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 833193326Sed bool isStatic, bool isInline) 834200583Srdivacky : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None), 835193326Sed isInline) {} 836193326Sed 837193326Sedpublic: 838193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 839193326Sed SourceLocation L, DeclarationName N, 840200583Srdivacky QualType T, TypeSourceInfo *TInfo, 841198092Srdivacky bool isStatic = false, 842193326Sed bool isInline = false); 843198092Srdivacky 844193326Sed bool isStatic() const { return getStorageClass() == Static; } 845193326Sed bool isInstance() const { return !isStatic(); } 846193326Sed 847198092Srdivacky bool isVirtual() const { 848198092Srdivacky CXXMethodDecl *CD = 849198092Srdivacky cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 850198092Srdivacky 851198092Srdivacky if (CD->isVirtualAsWritten()) 852198092Srdivacky return true; 853198092Srdivacky 854198092Srdivacky return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 855193326Sed } 856198092Srdivacky 857198092Srdivacky /// \brief Determine whether this is a usual deallocation function 858198092Srdivacky /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 859198092Srdivacky /// delete or delete[] operator with a particular signature. 860198092Srdivacky bool isUsualDeallocationFunction() const; 861198092Srdivacky 862198092Srdivacky const CXXMethodDecl *getCanonicalDecl() const { 863198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 864198092Srdivacky } 865198092Srdivacky CXXMethodDecl *getCanonicalDecl() { 866198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 867198092Srdivacky } 868198092Srdivacky 869198092Srdivacky /// 870198092Srdivacky void addOverriddenMethod(const CXXMethodDecl *MD); 871193326Sed 872193326Sed typedef const CXXMethodDecl ** method_iterator; 873198092Srdivacky 874193326Sed method_iterator begin_overridden_methods() const; 875193326Sed method_iterator end_overridden_methods() const; 876198092Srdivacky 877193326Sed /// getParent - Returns the parent of this method declaration, which 878193326Sed /// is the class in which this method is defined. 879198092Srdivacky const CXXRecordDecl *getParent() const { 880198092Srdivacky return cast<CXXRecordDecl>(FunctionDecl::getParent()); 881193326Sed } 882198092Srdivacky 883193326Sed /// getParent - Returns the parent of this method declaration, which 884193326Sed /// is the class in which this method is defined. 885198092Srdivacky CXXRecordDecl *getParent() { 886193326Sed return const_cast<CXXRecordDecl *>( 887193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 888193326Sed } 889193326Sed 890193326Sed /// getThisType - Returns the type of 'this' pointer. 891193326Sed /// Should only be called for instance methods. 892193326Sed QualType getThisType(ASTContext &C) const; 893193326Sed 894193326Sed unsigned getTypeQualifiers() const { 895198092Srdivacky return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 896193326Sed } 897193326Sed 898200583Srdivacky bool hasInlineBody() const; 899200583Srdivacky 900193326Sed // Implement isa/cast/dyncast/etc. 901198092Srdivacky static bool classof(const Decl *D) { 902193326Sed return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 903193326Sed } 904193326Sed static bool classof(const CXXMethodDecl *D) { return true; } 905193326Sed}; 906193326Sed 907193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member 908193326Sed/// initializer, which is part of a constructor initializer that 909193326Sed/// initializes one non-static member variable or one base class. For 910193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 911193326Sed/// initializers: 912193326Sed/// 913193326Sed/// @code 914193326Sed/// class A { }; 915193326Sed/// class B : public A { 916193326Sed/// float f; 917193326Sed/// public: 918193326Sed/// B(A& a) : A(a), f(3.14159) { } 919193326Sed/// }; 920194613Sed/// @endcode 921193326Sedclass CXXBaseOrMemberInitializer { 922200583Srdivacky /// \brief Either the base class name (stored as a TypeSourceInfo*) or the 923200583Srdivacky /// field being initialized. 924200583Srdivacky llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember; 925200583Srdivacky 926200583Srdivacky /// \brief The source location for the field name. 927200583Srdivacky SourceLocation MemberLocation; 928200583Srdivacky 929193326Sed /// Args - The arguments used to initialize the base or member. 930198092Srdivacky Stmt **Args; 931193326Sed unsigned NumArgs; 932198092Srdivacky 933198092Srdivacky /// \brief Stores either the constructor to call to initialize this base or 934198092Srdivacky /// member (a CXXConstructorDecl pointer), or stores the anonymous union of 935198092Srdivacky /// which the initialized value is a member. 936198092Srdivacky /// 937198092Srdivacky /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's 938198092Srdivacky /// anonymous union data member, this field holds the FieldDecl for the 939198092Srdivacky /// member of the anonymous union being initialized. 940198092Srdivacky /// @code 941198092Srdivacky /// struct X { 942198092Srdivacky /// X() : au_i1(123) {} 943198092Srdivacky /// union { 944198092Srdivacky /// int au_i1; 945198092Srdivacky /// float au_f1; 946198092Srdivacky /// }; 947198092Srdivacky /// }; 948198092Srdivacky /// @endcode 949198092Srdivacky /// In above example, BaseOrMember holds the field decl. for anonymous union 950198092Srdivacky /// and AnonUnionMember holds field decl for au_i1. 951198092Srdivacky llvm::PointerUnion<CXXConstructorDecl *, FieldDecl *> CtorOrAnonUnion; 952198092Srdivacky 953200583Srdivacky /// LParenLoc - Location of the left paren of the ctor-initializer. 954200583Srdivacky SourceLocation LParenLoc; 955193326Sed 956198092Srdivacky /// RParenLoc - Location of the right paren of the ctor-initializer. 957198092Srdivacky SourceLocation RParenLoc; 958198092Srdivacky 959193326Sedpublic: 960193326Sed /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 961198092Srdivacky explicit 962200583Srdivacky CXXBaseOrMemberInitializer(ASTContext &Context, 963200583Srdivacky TypeSourceInfo *TInfo, CXXConstructorDecl *C, 964200583Srdivacky SourceLocation L, 965200583Srdivacky Expr **Args, unsigned NumArgs, 966200583Srdivacky SourceLocation R); 967193326Sed 968193326Sed /// CXXBaseOrMemberInitializer - Creates a new member initializer. 969198092Srdivacky explicit 970200583Srdivacky CXXBaseOrMemberInitializer(ASTContext &Context, 971200583Srdivacky FieldDecl *Member, SourceLocation MemberLoc, 972200583Srdivacky CXXConstructorDecl *C, SourceLocation L, 973200583Srdivacky Expr **Args, unsigned NumArgs, 974200583Srdivacky SourceLocation R); 975193326Sed 976200583Srdivacky /// \brief Destroy the base or member initializer. 977200583Srdivacky void Destroy(ASTContext &Context); 978193326Sed 979193326Sed /// arg_iterator - Iterates through the member initialization 980193326Sed /// arguments. 981198092Srdivacky typedef ExprIterator arg_iterator; 982193326Sed 983193326Sed /// arg_const_iterator - Iterates through the member initialization 984193326Sed /// arguments. 985198092Srdivacky typedef ConstExprIterator const_arg_iterator; 986193326Sed 987193326Sed /// isBaseInitializer - Returns true when this initializer is 988193326Sed /// initializing a base class. 989200583Srdivacky bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); } 990193326Sed 991193326Sed /// isMemberInitializer - Returns true when this initializer is 992193326Sed /// initializing a non-static data member. 993200583Srdivacky bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); } 994193326Sed 995200583Srdivacky /// If this is a base class initializer, returns the type of the 996200583Srdivacky /// base class with location information. Otherwise, returns an NULL 997200583Srdivacky /// type location. 998200583Srdivacky TypeLoc getBaseClassLoc() const; 999193326Sed 1000200583Srdivacky /// If this is a base class initializer, returns the type of the base class. 1001200583Srdivacky /// Otherwise, returns NULL. 1002200583Srdivacky const Type *getBaseClass() const; 1003200583Srdivacky Type *getBaseClass(); 1004200583Srdivacky 1005200583Srdivacky /// \brief Returns the declarator information for a base class initializer. 1006200583Srdivacky TypeSourceInfo *getBaseClassInfo() const { 1007200583Srdivacky return BaseOrMember.dyn_cast<TypeSourceInfo *>(); 1008193326Sed } 1009200583Srdivacky 1010193326Sed /// getMember - If this is a member initializer, returns the 1011193326Sed /// declaration of the non-static data member being 1012193326Sed /// initialized. Otherwise, returns NULL. 1013198092Srdivacky FieldDecl *getMember() { 1014193326Sed if (isMemberInitializer()) 1015200583Srdivacky return BaseOrMember.get<FieldDecl*>(); 1016193326Sed else 1017193326Sed return 0; 1018193326Sed } 1019193326Sed 1020200583Srdivacky SourceLocation getMemberLocation() const { 1021200583Srdivacky return MemberLocation; 1022198092Srdivacky } 1023198092Srdivacky 1024200583Srdivacky void setMember(FieldDecl *Member) { 1025200583Srdivacky assert(isMemberInitializer()); 1026200583Srdivacky BaseOrMember = Member; 1027200583Srdivacky } 1028200583Srdivacky 1029200583Srdivacky /// \brief Determine the source location of the initializer. 1030200583Srdivacky SourceLocation getSourceLocation() const; 1031200583Srdivacky 1032200583Srdivacky /// \brief Determine the source range covering the entire initializer. 1033200583Srdivacky SourceRange getSourceRange() const; 1034200583Srdivacky 1035198092Srdivacky FieldDecl *getAnonUnionMember() const { 1036198092Srdivacky return CtorOrAnonUnion.dyn_cast<FieldDecl *>(); 1037198092Srdivacky } 1038198092Srdivacky void setAnonUnionMember(FieldDecl *anonMember) { 1039198092Srdivacky CtorOrAnonUnion = anonMember; 1040198092Srdivacky } 1041198092Srdivacky 1042198092Srdivacky const CXXConstructorDecl *getConstructor() const { 1043198092Srdivacky return CtorOrAnonUnion.dyn_cast<CXXConstructorDecl *>(); 1044198092Srdivacky } 1045198092Srdivacky 1046200583Srdivacky SourceLocation getLParenLoc() const { return LParenLoc; } 1047198092Srdivacky SourceLocation getRParenLoc() const { return RParenLoc; } 1048193326Sed 1049198092Srdivacky /// arg_begin() - Retrieve an iterator to the first initializer argument. 1050198092Srdivacky arg_iterator arg_begin() { return Args; } 1051198092Srdivacky /// arg_begin() - Retrieve an iterator to the first initializer argument. 1052198092Srdivacky const_arg_iterator const_arg_begin() const { return Args; } 1053193326Sed 1054198092Srdivacky /// arg_end() - Retrieve an iterator past the last initializer argument. 1055198092Srdivacky arg_iterator arg_end() { return Args + NumArgs; } 1056198092Srdivacky /// arg_end() - Retrieve an iterator past the last initializer argument. 1057198092Srdivacky const_arg_iterator const_arg_end() const { return Args + NumArgs; } 1058198092Srdivacky 1059193326Sed /// getNumArgs - Determine the number of arguments used to 1060193326Sed /// initialize the member or base. 1061193326Sed unsigned getNumArgs() const { return NumArgs; } 1062193326Sed}; 1063193326Sed 1064193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a 1065193326Sed/// class. For example: 1066198092Srdivacky/// 1067193326Sed/// @code 1068193326Sed/// class X { 1069193326Sed/// public: 1070193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 1071193326Sed/// }; 1072193326Sed/// @endcode 1073193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 1074193326Sed /// Explicit - Whether this constructor is explicit. 1075193326Sed bool Explicit : 1; 1076193326Sed 1077193326Sed /// ImplicitlyDefined - Whether this constructor was implicitly 1078193326Sed /// defined by the compiler. When false, the constructor was defined 1079193326Sed /// by the user. In C++03, this flag will have the same value as 1080193326Sed /// Implicit. In C++0x, however, a constructor that is 1081193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1082193326Sed /// @c !Implicit && ImplicitlyDefined. 1083193326Sed bool ImplicitlyDefined : 1; 1084198092Srdivacky 1085195341Sed /// Support for base and member initializers. 1086198092Srdivacky /// BaseOrMemberInitializers - The arguments used to initialize the base 1087195341Sed /// or member. 1088195341Sed CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 1089195341Sed unsigned NumBaseOrMemberInitializers; 1090198092Srdivacky 1091193326Sed CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 1092200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 1093193326Sed bool isExplicit, bool isInline, bool isImplicitlyDeclared) 1094200583Srdivacky : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline), 1095195341Sed Explicit(isExplicit), ImplicitlyDefined(false), 1096198092Srdivacky BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 1097193326Sed setImplicit(isImplicitlyDeclared); 1098193326Sed } 1099195341Sed virtual void Destroy(ASTContext& C); 1100198092Srdivacky 1101193326Sedpublic: 1102193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1103193326Sed SourceLocation L, DeclarationName N, 1104200583Srdivacky QualType T, TypeSourceInfo *TInfo, 1105198092Srdivacky bool isExplicit, 1106193326Sed bool isInline, bool isImplicitlyDeclared); 1107193326Sed 1108198092Srdivacky /// isExplicit - Whether this constructor was marked "explicit" or not. 1109193326Sed bool isExplicit() const { return Explicit; } 1110193326Sed 1111193326Sed /// isImplicitlyDefined - Whether this constructor was implicitly 1112193326Sed /// defined. If false, then this constructor was defined by the 1113193326Sed /// user. This operation can only be invoked if the constructor has 1114193326Sed /// already been defined. 1115198092Srdivacky bool isImplicitlyDefined(ASTContext &C) const { 1116198092Srdivacky assert(isThisDeclarationADefinition() && 1117195341Sed "Can only get the implicit-definition flag once the " 1118195341Sed "constructor has been defined"); 1119198092Srdivacky return ImplicitlyDefined; 1120193326Sed } 1121193326Sed 1122193326Sed /// setImplicitlyDefined - Set whether this constructor was 1123193326Sed /// implicitly defined or not. 1124198092Srdivacky void setImplicitlyDefined(bool ID) { 1125198092Srdivacky assert(isThisDeclarationADefinition() && 1126195341Sed "Can only set the implicit-definition flag once the constructor " 1127195341Sed "has been defined"); 1128198092Srdivacky ImplicitlyDefined = ID; 1129193326Sed } 1130198092Srdivacky 1131195341Sed /// init_iterator - Iterates through the member/base initializer list. 1132195341Sed typedef CXXBaseOrMemberInitializer **init_iterator; 1133198092Srdivacky 1134195341Sed /// init_const_iterator - Iterates through the memberbase initializer list. 1135195341Sed typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 1136198092Srdivacky 1137198092Srdivacky /// init_begin() - Retrieve an iterator to the first initializer. 1138198092Srdivacky init_iterator init_begin() { return BaseOrMemberInitializers; } 1139195341Sed /// begin() - Retrieve an iterator to the first initializer. 1140198092Srdivacky init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 1141198092Srdivacky 1142198092Srdivacky /// init_end() - Retrieve an iterator past the last initializer. 1143198092Srdivacky init_iterator init_end() { 1144198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1145195341Sed } 1146195341Sed /// end() - Retrieve an iterator past the last initializer. 1147198092Srdivacky init_const_iterator init_end() const { 1148198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1149195341Sed } 1150198092Srdivacky 1151195341Sed /// getNumArgs - Determine the number of arguments used to 1152195341Sed /// initialize the member or base. 1153198092Srdivacky unsigned getNumBaseOrMemberInitializers() const { 1154198092Srdivacky return NumBaseOrMemberInitializers; 1155195341Sed } 1156198092Srdivacky 1157198092Srdivacky void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) { 1158198092Srdivacky NumBaseOrMemberInitializers = numBaseOrMemberInitializers; 1159198092Srdivacky } 1160198092Srdivacky 1161198092Srdivacky void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) { 1162198092Srdivacky BaseOrMemberInitializers = initializers; 1163198092Srdivacky } 1164193326Sed /// isDefaultConstructor - Whether this constructor is a default 1165193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 1166193326Sed /// default-initialize a class of this type. 1167193326Sed bool isDefaultConstructor() const; 1168193326Sed 1169193326Sed /// isCopyConstructor - Whether this constructor is a copy 1170193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1171193326Sed /// class. @p TypeQuals will be set to the qualifiers on the 1172193326Sed /// argument type. For example, @p TypeQuals would be set to @c 1173193326Sed /// QualType::Const for the following copy constructor: 1174193326Sed /// 1175193326Sed /// @code 1176193326Sed /// class X { 1177193326Sed /// public: 1178193326Sed /// X(const X&); 1179193326Sed /// }; 1180193326Sed /// @endcode 1181201361Srdivacky bool isCopyConstructor(unsigned &TypeQuals) const; 1182193326Sed 1183193326Sed /// isCopyConstructor - Whether this constructor is a copy 1184193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1185193326Sed /// class. 1186201361Srdivacky bool isCopyConstructor() const { 1187193326Sed unsigned TypeQuals = 0; 1188201361Srdivacky return isCopyConstructor(TypeQuals); 1189193326Sed } 1190193326Sed 1191193326Sed /// isConvertingConstructor - Whether this constructor is a 1192193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 1193193326Sed /// used for user-defined conversions. 1194198092Srdivacky bool isConvertingConstructor(bool AllowExplicit) const; 1195193326Sed 1196199482Srdivacky /// \brief Determine whether this is a member template specialization that 1197199482Srdivacky /// looks like a copy constructor. Such constructors are never used to copy 1198199482Srdivacky /// an object. 1199199482Srdivacky bool isCopyConstructorLikeSpecialization() const; 1200199482Srdivacky 1201193326Sed // Implement isa/cast/dyncast/etc. 1202198092Srdivacky static bool classof(const Decl *D) { 1203193326Sed return D->getKind() == CXXConstructor; 1204193326Sed } 1205193326Sed static bool classof(const CXXConstructorDecl *D) { return true; } 1206193326Sed}; 1207193326Sed 1208193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a 1209193326Sed/// class. For example: 1210198092Srdivacky/// 1211193326Sed/// @code 1212193326Sed/// class X { 1213193326Sed/// public: 1214193326Sed/// ~X(); // represented by a CXXDestructorDecl. 1215193326Sed/// }; 1216193326Sed/// @endcode 1217193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 1218193326Sed /// ImplicitlyDefined - Whether this destructor was implicitly 1219193326Sed /// defined by the compiler. When false, the destructor was defined 1220193326Sed /// by the user. In C++03, this flag will have the same value as 1221193326Sed /// Implicit. In C++0x, however, a destructor that is 1222193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1223193326Sed /// @c !Implicit && ImplicitlyDefined. 1224193326Sed bool ImplicitlyDefined : 1; 1225193326Sed 1226199482Srdivacky FunctionDecl *OperatorDelete; 1227199482Srdivacky 1228193326Sed CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 1229193326Sed DeclarationName N, QualType T, 1230193326Sed bool isInline, bool isImplicitlyDeclared) 1231200583Srdivacky : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline), 1232199482Srdivacky ImplicitlyDefined(false), OperatorDelete(0) { 1233193326Sed setImplicit(isImplicitlyDeclared); 1234193326Sed } 1235193326Sed 1236193326Sedpublic: 1237193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1238193326Sed SourceLocation L, DeclarationName N, 1239198092Srdivacky QualType T, bool isInline, 1240193326Sed bool isImplicitlyDeclared); 1241193326Sed 1242193326Sed /// isImplicitlyDefined - Whether this destructor was implicitly 1243193326Sed /// defined. If false, then this destructor was defined by the 1244193326Sed /// user. This operation can only be invoked if the destructor has 1245193326Sed /// already been defined. 1246198092Srdivacky bool isImplicitlyDefined() const { 1247198092Srdivacky assert(isThisDeclarationADefinition() && 1248193326Sed "Can only get the implicit-definition flag once the destructor has been defined"); 1249198092Srdivacky return ImplicitlyDefined; 1250193326Sed } 1251193326Sed 1252193326Sed /// setImplicitlyDefined - Set whether this destructor was 1253193326Sed /// implicitly defined or not. 1254198092Srdivacky void setImplicitlyDefined(bool ID) { 1255198092Srdivacky assert(isThisDeclarationADefinition() && 1256193326Sed "Can only set the implicit-definition flag once the destructor has been defined"); 1257198092Srdivacky ImplicitlyDefined = ID; 1258193326Sed } 1259193326Sed 1260199482Srdivacky void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 1261199482Srdivacky const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1262198092Srdivacky 1263193326Sed // Implement isa/cast/dyncast/etc. 1264198092Srdivacky static bool classof(const Decl *D) { 1265193326Sed return D->getKind() == CXXDestructor; 1266193326Sed } 1267193326Sed static bool classof(const CXXDestructorDecl *D) { return true; } 1268193326Sed}; 1269193326Sed 1270193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a 1271193326Sed/// class. For example: 1272198092Srdivacky/// 1273193326Sed/// @code 1274193326Sed/// class X { 1275193326Sed/// public: 1276193326Sed/// operator bool(); 1277193326Sed/// }; 1278193326Sed/// @endcode 1279193326Sedclass CXXConversionDecl : public CXXMethodDecl { 1280193326Sed /// Explicit - Whether this conversion function is marked 1281193326Sed /// "explicit", meaning that it can only be applied when the user 1282193326Sed /// explicitly wrote a cast. This is a C++0x feature. 1283193326Sed bool Explicit : 1; 1284193326Sed 1285193326Sed CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1286200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 1287193326Sed bool isInline, bool isExplicit) 1288200583Srdivacky : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline), 1289193326Sed Explicit(isExplicit) { } 1290193326Sed 1291193326Sedpublic: 1292193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1293193326Sed SourceLocation L, DeclarationName N, 1294200583Srdivacky QualType T, TypeSourceInfo *TInfo, 1295198092Srdivacky bool isInline, bool isExplicit); 1296193326Sed 1297193326Sed /// isExplicit - Whether this is an explicit conversion operator 1298193326Sed /// (C++0x only). Explicit conversion operators are only considered 1299193326Sed /// when the user has explicitly written a cast. 1300193326Sed bool isExplicit() const { return Explicit; } 1301193326Sed 1302193326Sed /// getConversionType - Returns the type that this conversion 1303193326Sed /// function is converting to. 1304198092Srdivacky QualType getConversionType() const { 1305198092Srdivacky return getType()->getAs<FunctionType>()->getResultType(); 1306193326Sed } 1307193326Sed 1308193326Sed // Implement isa/cast/dyncast/etc. 1309198092Srdivacky static bool classof(const Decl *D) { 1310193326Sed return D->getKind() == CXXConversion; 1311193326Sed } 1312193326Sed static bool classof(const CXXConversionDecl *D) { return true; } 1313193326Sed}; 1314193326Sed 1315198092Srdivacky/// FriendDecl - Represents the declaration of a friend entity, 1316198092Srdivacky/// which can be a function, a type, or a templated function or type. 1317198092Srdivacky// For example: 1318198092Srdivacky/// 1319198092Srdivacky/// @code 1320198092Srdivacky/// template <typename T> class A { 1321198092Srdivacky/// friend int foo(T); 1322198092Srdivacky/// friend class B; 1323198092Srdivacky/// friend T; // only in C++0x 1324198092Srdivacky/// template <typename U> friend class C; 1325198092Srdivacky/// template <typename U> friend A& operator+=(A&, const U&) { ... } 1326198092Srdivacky/// }; 1327198092Srdivacky/// @endcode 1328198092Srdivacky/// 1329198092Srdivacky/// The semantic context of a friend decl is its declaring class. 1330198092Srdivackyclass FriendDecl : public Decl { 1331198092Srdivackypublic: 1332198092Srdivacky typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 1333198092Srdivacky 1334198092Srdivackyprivate: 1335198092Srdivacky // The declaration that's a friend of this class. 1336198092Srdivacky FriendUnion Friend; 1337198092Srdivacky 1338198092Srdivacky // Location of the 'friend' specifier. 1339198092Srdivacky SourceLocation FriendLoc; 1340198092Srdivacky 1341201361Srdivacky // FIXME: Hack to keep track of whether this was a friend function 1342201361Srdivacky // template specialization. 1343201361Srdivacky bool WasSpecialization; 1344201361Srdivacky 1345198092Srdivacky FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend, 1346198092Srdivacky SourceLocation FriendL) 1347198092Srdivacky : Decl(Decl::Friend, DC, L), 1348198092Srdivacky Friend(Friend), 1349201361Srdivacky FriendLoc(FriendL), 1350201361Srdivacky WasSpecialization(false) { 1351198092Srdivacky } 1352198092Srdivacky 1353198092Srdivackypublic: 1354198092Srdivacky static FriendDecl *Create(ASTContext &C, DeclContext *DC, 1355198092Srdivacky SourceLocation L, FriendUnion Friend_, 1356198092Srdivacky SourceLocation FriendL); 1357198092Srdivacky 1358198092Srdivacky /// If this friend declaration names an (untemplated but 1359198092Srdivacky /// possibly dependent) type, return the type; otherwise 1360198092Srdivacky /// return null. This is used only for C++0x's unelaborated 1361198092Srdivacky /// friend type declarations. 1362198092Srdivacky Type *getFriendType() const { 1363198092Srdivacky return Friend.dyn_cast<Type*>(); 1364198092Srdivacky } 1365198092Srdivacky 1366198092Srdivacky /// If this friend declaration doesn't name an unelaborated 1367198092Srdivacky /// type, return the inner declaration. 1368198092Srdivacky NamedDecl *getFriendDecl() const { 1369198092Srdivacky return Friend.dyn_cast<NamedDecl*>(); 1370198092Srdivacky } 1371198092Srdivacky 1372198092Srdivacky /// Retrieves the location of the 'friend' keyword. 1373198092Srdivacky SourceLocation getFriendLoc() const { 1374198092Srdivacky return FriendLoc; 1375198092Srdivacky } 1376198092Srdivacky 1377201361Srdivacky bool wasSpecialization() const { return WasSpecialization; } 1378201361Srdivacky void setSpecialization(bool WS) { WasSpecialization = WS; } 1379201361Srdivacky 1380198092Srdivacky // Implement isa/cast/dyncast/etc. 1381198092Srdivacky static bool classof(const Decl *D) { 1382198092Srdivacky return D->getKind() == Decl::Friend; 1383198092Srdivacky } 1384198092Srdivacky static bool classof(const FriendDecl *D) { return true; } 1385198092Srdivacky}; 1386198092Srdivacky 1387193326Sed/// LinkageSpecDecl - This represents a linkage specification. For example: 1388193326Sed/// extern "C" void foo(); 1389193326Sed/// 1390193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 1391193326Sedpublic: 1392193326Sed /// LanguageIDs - Used to represent the language in a linkage 1393193326Sed /// specification. The values are part of the serialization abi for 1394193326Sed /// ASTs and cannot be changed without altering that abi. To help 1395193326Sed /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1396193326Sed /// from the dwarf standard. 1397193326Sed enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 1398193326Sed lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 1399193326Sedprivate: 1400193326Sed /// Language - The language for this linkage specification. 1401193326Sed LanguageIDs Language; 1402193326Sed 1403193326Sed /// HadBraces - Whether this linkage specification had curly braces or not. 1404193326Sed bool HadBraces : 1; 1405193326Sed 1406198092Srdivacky LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1407193326Sed bool Braces) 1408198092Srdivacky : Decl(LinkageSpec, DC, L), 1409193326Sed DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1410193326Sed 1411193326Sedpublic: 1412198092Srdivacky static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1413198092Srdivacky SourceLocation L, LanguageIDs Lang, 1414193326Sed bool Braces); 1415193326Sed 1416193326Sed LanguageIDs getLanguage() const { return Language; } 1417193326Sed 1418193326Sed /// hasBraces - Determines whether this linkage specification had 1419193326Sed /// braces in its syntactic form. 1420193326Sed bool hasBraces() const { return HadBraces; } 1421193326Sed 1422193326Sed static bool classof(const Decl *D) { 1423193326Sed return D->getKind() == LinkageSpec; 1424193326Sed } 1425193326Sed static bool classof(const LinkageSpecDecl *D) { return true; } 1426193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1427193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1428193326Sed } 1429193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1430193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1431193326Sed } 1432193326Sed}; 1433193326Sed 1434193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1435193326Sed/// 1436193326Sed/// using namespace std; 1437193326Sed/// 1438193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1439193326Sed// artificial name, for all using-directives in order to store 1440193326Sed// them in DeclContext effectively. 1441193326Sedclass UsingDirectiveDecl : public NamedDecl { 1442193326Sed 1443193326Sed /// SourceLocation - Location of 'namespace' token. 1444193326Sed SourceLocation NamespaceLoc; 1445193326Sed 1446193326Sed /// \brief The source range that covers the nested-name-specifier 1447193326Sed /// preceding the namespace name. 1448193326Sed SourceRange QualifierRange; 1449193326Sed 1450193326Sed /// \brief The nested-name-specifier that precedes the namespace 1451193326Sed /// name, if any. 1452193326Sed NestedNameSpecifier *Qualifier; 1453193326Sed 1454193326Sed /// IdentLoc - Location of nominated namespace-name identifier. 1455193326Sed // FIXME: We don't store location of scope specifier. 1456193326Sed SourceLocation IdentLoc; 1457193326Sed 1458193326Sed /// NominatedNamespace - Namespace nominated by using-directive. 1459199990Srdivacky NamedDecl *NominatedNamespace; 1460193326Sed 1461199990Srdivacky /// Enclosing context containing both using-directive and nominated 1462193326Sed /// namespace. 1463193326Sed DeclContext *CommonAncestor; 1464193326Sed 1465193326Sed /// getUsingDirectiveName - Returns special DeclarationName used by 1466193326Sed /// using-directives. This is only used by DeclContext for storing 1467193326Sed /// UsingDirectiveDecls in its lookup structure. 1468193326Sed static DeclarationName getName() { 1469193326Sed return DeclarationName::getUsingDirectiveName(); 1470193326Sed } 1471193326Sed 1472193326Sed UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1473193326Sed SourceLocation NamespcLoc, 1474193326Sed SourceRange QualifierRange, 1475193326Sed NestedNameSpecifier *Qualifier, 1476193326Sed SourceLocation IdentLoc, 1477199990Srdivacky NamedDecl *Nominated, 1478193326Sed DeclContext *CommonAncestor) 1479193326Sed : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1480198092Srdivacky NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1481198092Srdivacky Qualifier(Qualifier), IdentLoc(IdentLoc), 1482199990Srdivacky NominatedNamespace(Nominated), 1483193326Sed CommonAncestor(CommonAncestor) { 1484193326Sed } 1485193326Sed 1486193326Sedpublic: 1487193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1488193326Sed /// that qualifiers the namespace name. 1489193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1490193326Sed 1491193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1492193326Sed /// name of the namespace. 1493193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1494193326Sed 1495199990Srdivacky NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 1496199990Srdivacky const NamedDecl *getNominatedNamespaceAsWritten() const { 1497199990Srdivacky return NominatedNamespace; 1498199990Srdivacky } 1499199990Srdivacky 1500193326Sed /// getNominatedNamespace - Returns namespace nominated by using-directive. 1501199990Srdivacky NamespaceDecl *getNominatedNamespace(); 1502193326Sed 1503193326Sed const NamespaceDecl *getNominatedNamespace() const { 1504193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1505193326Sed } 1506193326Sed 1507193326Sed /// getCommonAncestor - returns common ancestor context of using-directive, 1508193326Sed /// and nominated by it namespace. 1509193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 1510193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1511193326Sed 1512193326Sed /// getNamespaceKeyLocation - Returns location of namespace keyword. 1513193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1514193326Sed 1515193326Sed /// getIdentLocation - Returns location of identifier. 1516193326Sed SourceLocation getIdentLocation() const { return IdentLoc; } 1517193326Sed 1518193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1519193326Sed SourceLocation L, 1520193326Sed SourceLocation NamespaceLoc, 1521193326Sed SourceRange QualifierRange, 1522193326Sed NestedNameSpecifier *Qualifier, 1523193326Sed SourceLocation IdentLoc, 1524199990Srdivacky NamedDecl *Nominated, 1525193326Sed DeclContext *CommonAncestor); 1526193326Sed 1527193326Sed static bool classof(const Decl *D) { 1528193326Sed return D->getKind() == Decl::UsingDirective; 1529193326Sed } 1530193326Sed static bool classof(const UsingDirectiveDecl *D) { return true; } 1531193326Sed 1532193326Sed // Friend for getUsingDirectiveName. 1533193326Sed friend class DeclContext; 1534193326Sed}; 1535193326Sed 1536193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1537193326Sed/// 1538193326Sed/// @code 1539193326Sed/// namespace Foo = Bar; 1540193326Sed/// @endcode 1541193326Sedclass NamespaceAliasDecl : public NamedDecl { 1542193326Sed SourceLocation AliasLoc; 1543193326Sed 1544193326Sed /// \brief The source range that covers the nested-name-specifier 1545193326Sed /// preceding the namespace name. 1546193326Sed SourceRange QualifierRange; 1547193326Sed 1548193326Sed /// \brief The nested-name-specifier that precedes the namespace 1549193326Sed /// name, if any. 1550193326Sed NestedNameSpecifier *Qualifier; 1551198092Srdivacky 1552193326Sed /// IdentLoc - Location of namespace identifier. 1553193326Sed SourceLocation IdentLoc; 1554198092Srdivacky 1555198092Srdivacky /// Namespace - The Decl that this alias points to. Can either be a 1556193326Sed /// NamespaceDecl or a NamespaceAliasDecl. 1557193326Sed NamedDecl *Namespace; 1558198092Srdivacky 1559198092Srdivacky NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1560198092Srdivacky SourceLocation AliasLoc, IdentifierInfo *Alias, 1561193326Sed SourceRange QualifierRange, 1562193326Sed NestedNameSpecifier *Qualifier, 1563193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 1564198092Srdivacky : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1565193326Sed QualifierRange(QualifierRange), Qualifier(Qualifier), 1566193326Sed IdentLoc(IdentLoc), Namespace(Namespace) { } 1567193326Sed 1568193326Sedpublic: 1569193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1570193326Sed /// that qualifiers the namespace name. 1571193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1572193326Sed 1573193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1574193326Sed /// name of the namespace. 1575193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1576193326Sed 1577193326Sed NamespaceDecl *getNamespace() { 1578193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1579193326Sed return AD->getNamespace(); 1580193326Sed 1581193326Sed return cast<NamespaceDecl>(Namespace); 1582193326Sed } 1583198092Srdivacky 1584193326Sed const NamespaceDecl *getNamespace() const { 1585193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1586193326Sed } 1587193326Sed 1588193326Sed /// \brief Retrieve the namespace that this alias refers to, which 1589193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1590193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 1591193326Sed 1592198092Srdivacky static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1593198092Srdivacky SourceLocation L, SourceLocation AliasLoc, 1594198092Srdivacky IdentifierInfo *Alias, 1595193326Sed SourceRange QualifierRange, 1596193326Sed NestedNameSpecifier *Qualifier, 1597198092Srdivacky SourceLocation IdentLoc, 1598193326Sed NamedDecl *Namespace); 1599198092Srdivacky 1600193326Sed static bool classof(const Decl *D) { 1601193326Sed return D->getKind() == Decl::NamespaceAlias; 1602193326Sed } 1603193326Sed static bool classof(const NamespaceAliasDecl *D) { return true; } 1604193326Sed}; 1605194613Sed 1606199482Srdivacky/// UsingShadowDecl - Represents a shadow declaration introduced into 1607199482Srdivacky/// a scope by a (resolved) using declaration. For example, 1608199482Srdivacky/// 1609199482Srdivacky/// namespace A { 1610199482Srdivacky/// void foo(); 1611199482Srdivacky/// } 1612199482Srdivacky/// namespace B { 1613199482Srdivacky/// using A::foo(); // <- a UsingDecl 1614199482Srdivacky/// // Also creates a UsingShadowDecl for A::foo in B 1615199482Srdivacky/// } 1616199482Srdivacky/// 1617199482Srdivackyclass UsingShadowDecl : public NamedDecl { 1618199482Srdivacky /// The referenced declaration. 1619199482Srdivacky NamedDecl *Underlying; 1620199482Srdivacky 1621199482Srdivacky /// The using declaration which introduced this decl. 1622199482Srdivacky UsingDecl *Using; 1623199482Srdivacky 1624199482Srdivacky UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 1625199482Srdivacky NamedDecl *Target) 1626199482Srdivacky : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()), 1627199482Srdivacky Underlying(Target), Using(Using) { 1628199482Srdivacky IdentifierNamespace = Target->getIdentifierNamespace(); 1629199482Srdivacky setImplicit(); 1630199482Srdivacky } 1631199482Srdivacky 1632199482Srdivackypublic: 1633199482Srdivacky static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 1634199482Srdivacky SourceLocation Loc, UsingDecl *Using, 1635199482Srdivacky NamedDecl *Target) { 1636199482Srdivacky return new (C) UsingShadowDecl(DC, Loc, Using, Target); 1637199482Srdivacky } 1638199482Srdivacky 1639199482Srdivacky /// Gets the underlying declaration which has been brought into the 1640199482Srdivacky /// local scope. 1641199482Srdivacky NamedDecl *getTargetDecl() const { 1642199482Srdivacky return Underlying; 1643199482Srdivacky } 1644199482Srdivacky 1645199482Srdivacky /// Gets the using declaration to which this declaration is tied. 1646199482Srdivacky UsingDecl *getUsingDecl() const { 1647199482Srdivacky return Using; 1648199482Srdivacky } 1649199482Srdivacky 1650199482Srdivacky static bool classof(const Decl *D) { 1651199482Srdivacky return D->getKind() == Decl::UsingShadow; 1652199482Srdivacky } 1653199482Srdivacky static bool classof(const UsingShadowDecl *D) { return true; } 1654199482Srdivacky}; 1655199482Srdivacky 1656194613Sed/// UsingDecl - Represents a C++ using-declaration. For example: 1657194613Sed/// using someNameSpace::someIdentifier; 1658194613Sedclass UsingDecl : public NamedDecl { 1659194613Sed /// \brief The source range that covers the nested-name-specifier 1660194613Sed /// preceding the declaration name. 1661194613Sed SourceRange NestedNameRange; 1662198092Srdivacky 1663194613Sed /// \brief The source location of the "using" location itself. 1664194613Sed SourceLocation UsingLocation; 1665198092Srdivacky 1666198092Srdivacky /// \brief Target nested name specifier. 1667199482Srdivacky NestedNameSpecifier* TargetNestedName; 1668194613Sed 1669199482Srdivacky /// \brief The collection of shadow declarations associated with 1670199482Srdivacky /// this using declaration. This set can change as a class is 1671199482Srdivacky /// processed. 1672199482Srdivacky llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows; 1673199482Srdivacky 1674198092Srdivacky // \brief Has 'typename' keyword. 1675194613Sed bool IsTypeName; 1676194613Sed 1677194613Sed UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1678199482Srdivacky SourceLocation UL, NestedNameSpecifier* TargetNNS, 1679199482Srdivacky DeclarationName Name, bool IsTypeNameArg) 1680199482Srdivacky : NamedDecl(Decl::Using, DC, L, Name), 1681199482Srdivacky NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS), 1682199482Srdivacky IsTypeName(IsTypeNameArg) { 1683194613Sed } 1684194613Sed 1685194613Sedpublic: 1686194613Sed /// \brief Returns the source range that covers the nested-name-specifier 1687194613Sed /// preceding the namespace name. 1688195099Sed SourceRange getNestedNameRange() { return NestedNameRange; } 1689198092Srdivacky 1690194613Sed /// \brief Returns the source location of the "using" location itself. 1691195099Sed SourceLocation getUsingLocation() { return UsingLocation; } 1692198092Srdivacky 1693194613Sed /// \brief Get target nested name declaration. 1694198092Srdivacky NestedNameSpecifier* getTargetNestedNameDecl() { 1695199482Srdivacky return TargetNestedName; 1696195099Sed } 1697198092Srdivacky 1698198092Srdivacky /// isTypeName - Return true if using decl has 'typename'. 1699195099Sed bool isTypeName() const { return IsTypeName; } 1700194613Sed 1701199482Srdivacky typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator; 1702199482Srdivacky shadow_iterator shadow_begin() const { return Shadows.begin(); } 1703199482Srdivacky shadow_iterator shadow_end() const { return Shadows.end(); } 1704199482Srdivacky 1705199482Srdivacky void addShadowDecl(UsingShadowDecl *S) { 1706199482Srdivacky assert(S->getUsingDecl() == this); 1707199482Srdivacky if (!Shadows.insert(S)) { 1708199482Srdivacky assert(false && "declaration already in set"); 1709199482Srdivacky } 1710199482Srdivacky } 1711199482Srdivacky void removeShadowDecl(UsingShadowDecl *S) { 1712199482Srdivacky assert(S->getUsingDecl() == this); 1713199482Srdivacky if (!Shadows.erase(S)) { 1714199482Srdivacky assert(false && "declaration not in set"); 1715199482Srdivacky } 1716199482Srdivacky } 1717199482Srdivacky 1718194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1719199482Srdivacky SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL, 1720199482Srdivacky NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg); 1721194613Sed 1722194613Sed static bool classof(const Decl *D) { 1723194613Sed return D->getKind() == Decl::Using; 1724194613Sed } 1725194613Sed static bool classof(const UsingDecl *D) { return true; } 1726194613Sed}; 1727198092Srdivacky 1728199482Srdivacky/// UnresolvedUsingValueDecl - Represents a dependent using 1729199482Srdivacky/// declaration which was not marked with 'typename'. Unlike 1730199482Srdivacky/// non-dependent using declarations, these *only* bring through 1731199482Srdivacky/// non-types; otherwise they would break two-phase lookup. 1732199482Srdivacky/// 1733199482Srdivacky/// template <class T> class A : public Base<T> { 1734199482Srdivacky/// using Base<T>::foo; 1735199482Srdivacky/// }; 1736199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl { 1737198092Srdivacky /// \brief The source range that covers the nested-name-specifier 1738198092Srdivacky /// preceding the declaration name. 1739198092Srdivacky SourceRange TargetNestedNameRange; 1740198092Srdivacky 1741199482Srdivacky /// \brief The source location of the 'using' keyword 1742199482Srdivacky SourceLocation UsingLocation; 1743198092Srdivacky 1744198092Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 1745198092Srdivacky 1746199482Srdivacky UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 1747199482Srdivacky SourceLocation UsingLoc, SourceRange TargetNNR, 1748199482Srdivacky NestedNameSpecifier *TargetNNS, 1749199482Srdivacky SourceLocation TargetNameLoc, 1750199482Srdivacky DeclarationName TargetName) 1751199482Srdivacky : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), 1752199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1753199482Srdivacky TargetNestedNameSpecifier(TargetNNS) 1754199482Srdivacky { } 1755198092Srdivacky 1756199482Srdivackypublic: 1757199482Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 1758199482Srdivacky /// preceding the namespace name. 1759199482Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1760198092Srdivacky 1761199482Srdivacky /// \brief Get target nested name declaration. 1762199482Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 1763199482Srdivacky return TargetNestedNameSpecifier; 1764199482Srdivacky } 1765198092Srdivacky 1766199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 1767199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 1768199482Srdivacky 1769199482Srdivacky static UnresolvedUsingValueDecl * 1770199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1771199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1772199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 1773199482Srdivacky 1774199482Srdivacky static bool classof(const Decl *D) { 1775199482Srdivacky return D->getKind() == Decl::UnresolvedUsingValue; 1776199482Srdivacky } 1777199482Srdivacky static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 1778199482Srdivacky}; 1779199482Srdivacky 1780199482Srdivacky/// UnresolvedUsingTypenameDecl - Represents a dependent using 1781199482Srdivacky/// declaration which was marked with 'typename'. 1782199482Srdivacky/// 1783199482Srdivacky/// template <class T> class A : public Base<T> { 1784199482Srdivacky/// using typename Base<T>::foo; 1785199482Srdivacky/// }; 1786199482Srdivacky/// 1787199482Srdivacky/// The type associated with a unresolved using typename decl is 1788199482Srdivacky/// currently always a typename type. 1789199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl { 1790199482Srdivacky /// \brief The source range that covers the nested-name-specifier 1791199482Srdivacky /// preceding the declaration name. 1792199482Srdivacky SourceRange TargetNestedNameRange; 1793199482Srdivacky 1794199482Srdivacky /// \brief The source location of the 'using' keyword 1795199482Srdivacky SourceLocation UsingLocation; 1796199482Srdivacky 1797199482Srdivacky /// \brief The source location of the 'typename' keyword 1798199482Srdivacky SourceLocation TypenameLocation; 1799199482Srdivacky 1800199482Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 1801199482Srdivacky 1802199482Srdivacky UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 1803199482Srdivacky SourceLocation TypenameLoc, 1804199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1805199482Srdivacky SourceLocation TargetNameLoc, IdentifierInfo *TargetName) 1806199482Srdivacky : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), 1807199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1808199482Srdivacky TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS) 1809199482Srdivacky { } 1810199482Srdivacky 1811198092Srdivackypublic: 1812198092Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 1813198092Srdivacky /// preceding the namespace name. 1814198092Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1815198092Srdivacky 1816198092Srdivacky /// \brief Get target nested name declaration. 1817198092Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 1818198092Srdivacky return TargetNestedNameSpecifier; 1819198092Srdivacky } 1820198092Srdivacky 1821199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 1822199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 1823198092Srdivacky 1824199482Srdivacky /// \brief Returns the source location of the 'typename' keyword. 1825199482Srdivacky SourceLocation getTypenameLoc() const { return TypenameLocation; } 1826198092Srdivacky 1827199482Srdivacky static UnresolvedUsingTypenameDecl * 1828199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1829199482Srdivacky SourceLocation TypenameLoc, 1830199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1831199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 1832198092Srdivacky 1833198092Srdivacky static bool classof(const Decl *D) { 1834199482Srdivacky return D->getKind() == Decl::UnresolvedUsingTypename; 1835198092Srdivacky } 1836199482Srdivacky static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 1837198092Srdivacky}; 1838198092Srdivacky 1839193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1840193326Sedclass StaticAssertDecl : public Decl { 1841193326Sed Expr *AssertExpr; 1842193326Sed StringLiteral *Message; 1843193326Sed 1844198092Srdivacky StaticAssertDecl(DeclContext *DC, SourceLocation L, 1845193326Sed Expr *assertexpr, StringLiteral *message) 1846193326Sed : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1847198092Srdivacky 1848193326Sedpublic: 1849193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1850193326Sed SourceLocation L, Expr *AssertExpr, 1851193326Sed StringLiteral *Message); 1852198092Srdivacky 1853193326Sed Expr *getAssertExpr() { return AssertExpr; } 1854193326Sed const Expr *getAssertExpr() const { return AssertExpr; } 1855198092Srdivacky 1856193326Sed StringLiteral *getMessage() { return Message; } 1857193326Sed const StringLiteral *getMessage() const { return Message; } 1858198092Srdivacky 1859193326Sed virtual ~StaticAssertDecl(); 1860193326Sed virtual void Destroy(ASTContext& C); 1861193326Sed 1862193326Sed static bool classof(const Decl *D) { 1863193326Sed return D->getKind() == Decl::StaticAssert; 1864193326Sed } 1865193326Sed static bool classof(StaticAssertDecl *D) { return true; } 1866193326Sed}; 1867193326Sed 1868193326Sed/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1869193326Sed/// into a diagnostic with <<. 1870193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1871193326Sed AccessSpecifier AS); 1872198092Srdivacky 1873193326Sed} // end namespace clang 1874193326Sed 1875193326Sed#endif 1876