DeclCXX.h revision 208600
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// 10205219Srdivacky// This file defines the C++ Decl subclasses, other than those for 11205219Srdivacky// templates (in DeclTemplate.h) and friends (in DeclFriend.h). 12193326Sed// 13193326Sed//===----------------------------------------------------------------------===// 14193326Sed 15193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H 16193326Sed#define LLVM_CLANG_AST_DECLCXX_H 17193326Sed 18198092Srdivacky#include "clang/AST/Expr.h" 19193326Sed#include "clang/AST/Decl.h" 20202879Srdivacky#include "clang/AST/UnresolvedSet.h" 21193326Sed#include "llvm/ADT/SmallVector.h" 22198092Srdivacky#include "llvm/ADT/SmallPtrSet.h" 23193326Sed 24193326Sednamespace clang { 25193326Sed 26193326Sedclass ClassTemplateDecl; 27198092Srdivackyclass ClassTemplateSpecializationDecl; 28198092Srdivackyclass CXXBasePath; 29198092Srdivackyclass CXXBasePaths; 30193326Sedclass CXXConstructorDecl; 31198092Srdivackyclass CXXConversionDecl; 32193326Sedclass CXXDestructorDecl; 33193326Sedclass CXXMethodDecl; 34198092Srdivackyclass CXXRecordDecl; 35198092Srdivackyclass CXXMemberLookupCriteria; 36206084Srdivackyclass CXXFinalOverriderMap; 37205219Srdivackyclass FriendDecl; 38198092Srdivacky 39198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a 40195099Sed/// concrete function or a function template. 41195099Sedclass AnyFunctionDecl { 42195099Sed NamedDecl *Function; 43198092Srdivacky 44195341Sed AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 45198092Srdivacky 46195099Sedpublic: 47195099Sed AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 48195099Sed AnyFunctionDecl(FunctionTemplateDecl *FTD); 49198092Srdivacky 50198092Srdivacky /// \brief Implicily converts any function or function template into a 51195099Sed /// named declaration. 52195099Sed operator NamedDecl *() const { return Function; } 53198092Srdivacky 54195099Sed /// \brief Retrieve the underlying function or function template. 55195099Sed NamedDecl *get() const { return Function; } 56198092Srdivacky 57198092Srdivacky static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 58195341Sed return AnyFunctionDecl(ND); 59195341Sed } 60195099Sed}; 61198092Srdivacky 62195099Sed} // end namespace clang 63195099Sed 64195099Sednamespace llvm { 65198092Srdivacky /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 66195099Sed /// AnyFunctionDecl to any function or function template declaration. 67195099Sed template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 68195099Sed typedef ::clang::NamedDecl* SimpleType; 69195099Sed static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 70195099Sed return Val; 71195099Sed } 72195099Sed }; 73195099Sed template<> struct simplify_type< ::clang::AnyFunctionDecl> 74195099Sed : public simplify_type<const ::clang::AnyFunctionDecl> {}; 75198092Srdivacky 76195341Sed // Provide PointerLikeTypeTraits for non-cvr pointers. 77195341Sed template<> 78195341Sed class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 79195341Sed public: 80195341Sed static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 81198092Srdivacky return F.get(); 82195341Sed } 83195341Sed static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 84195341Sed return ::clang::AnyFunctionDecl::getFromNamedDecl( 85195341Sed static_cast< ::clang::NamedDecl*>(P)); 86195341Sed } 87198092Srdivacky 88195341Sed enum { NumLowBitsAvailable = 2 }; 89195341Sed }; 90198092Srdivacky 91195099Sed} // end namespace llvm 92195099Sed 93195099Sednamespace clang { 94198092Srdivacky 95193326Sed/// CXXBaseSpecifier - A base class of a C++ class. 96193326Sed/// 97193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 98193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 99193326Sed/// base class, whether it is a virtual or non-virtual base, and what 100193326Sed/// level of access (public, protected, private) is used for the 101193326Sed/// derivation. For example: 102193326Sed/// 103193326Sed/// @code 104193326Sed/// class A { }; 105193326Sed/// class B { }; 106193326Sed/// class C : public virtual A, protected B { }; 107193326Sed/// @endcode 108193326Sed/// 109193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 110193326Sed/// virtual A" and the other for "protected B". 111193326Sedclass CXXBaseSpecifier { 112193326Sed /// Range - The source code range that covers the full base 113193326Sed /// specifier, including the "virtual" (if present) and access 114193326Sed /// specifier (if present). 115200583Srdivacky // FIXME: Move over to a TypeLoc! 116193326Sed SourceRange Range; 117193326Sed 118193326Sed /// Virtual - Whether this is a virtual base class or not. 119193326Sed bool Virtual : 1; 120193326Sed 121193326Sed /// BaseOfClass - Whether this is the base of a class (true) or of a 122193326Sed /// struct (false). This determines the mapping from the access 123193326Sed /// specifier as written in the source code to the access specifier 124193326Sed /// used for semantic analysis. 125198092Srdivacky bool BaseOfClass : 1; 126193326Sed 127193326Sed /// Access - Access specifier as written in the source code (which 128193326Sed /// may be AS_none). The actual type of data stored here is an 129193326Sed /// AccessSpecifier, but we use "unsigned" here to work around a 130193326Sed /// VC++ bug. 131193326Sed unsigned Access : 2; 132193326Sed 133193326Sed /// BaseType - The type of the base class. This will be a class or 134193326Sed /// struct (or a typedef of such). 135193326Sed QualType BaseType; 136198092Srdivacky 137193326Sedpublic: 138193326Sed CXXBaseSpecifier() { } 139193326Sed 140193326Sed CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 141193326Sed : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 142193326Sed 143193326Sed /// getSourceRange - Retrieves the source range that contains the 144193326Sed /// entire base specifier. 145193326Sed SourceRange getSourceRange() const { return Range; } 146198092Srdivacky 147193326Sed /// isVirtual - Determines whether the base class is a virtual base 148193326Sed /// class (or not). 149193326Sed bool isVirtual() const { return Virtual; } 150193326Sed 151203955Srdivacky /// \brief Determine whether this base class if a base of a class declared 152203955Srdivacky /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 153203955Srdivacky bool isBaseOfClass() const { return BaseOfClass; } 154203955Srdivacky 155193326Sed /// getAccessSpecifier - Returns the access specifier for this base 156193326Sed /// specifier. This is the actual base specifier as used for 157193326Sed /// semantic analysis, so the result can never be AS_none. To 158193326Sed /// retrieve the access specifier as written in the source code, use 159193326Sed /// getAccessSpecifierAsWritten(). 160198092Srdivacky AccessSpecifier getAccessSpecifier() const { 161193326Sed if ((AccessSpecifier)Access == AS_none) 162193326Sed return BaseOfClass? AS_private : AS_public; 163193326Sed else 164198092Srdivacky return (AccessSpecifier)Access; 165193326Sed } 166193326Sed 167193326Sed /// getAccessSpecifierAsWritten - Retrieves the access specifier as 168193326Sed /// written in the source code (which may mean that no access 169193326Sed /// specifier was explicitly written). Use getAccessSpecifier() to 170193326Sed /// retrieve the access specifier for use in semantic analysis. 171193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 172193326Sed return (AccessSpecifier)Access; 173193326Sed } 174193326Sed 175193326Sed /// getType - Retrieves the type of the base class. This type will 176193326Sed /// always be an unqualified class type. 177193326Sed QualType getType() const { return BaseType; } 178193326Sed}; 179193326Sed 180193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class. 181193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 182193326Sed/// to deal with C++-specific things. 183193326Sedclass CXXRecordDecl : public RecordDecl { 184193326Sed 185203955Srdivacky friend void TagDecl::startDefinition(); 186193326Sed 187203955Srdivacky struct DefinitionData { 188203955Srdivacky DefinitionData(CXXRecordDecl *D); 189193326Sed 190203955Srdivacky /// UserDeclaredConstructor - True when this class has a 191203955Srdivacky /// user-declared constructor. 192203955Srdivacky bool UserDeclaredConstructor : 1; 193193326Sed 194203955Srdivacky /// UserDeclaredCopyConstructor - True when this class has a 195203955Srdivacky /// user-declared copy constructor. 196203955Srdivacky bool UserDeclaredCopyConstructor : 1; 197193326Sed 198203955Srdivacky /// UserDeclaredCopyAssignment - True when this class has a 199203955Srdivacky /// user-declared copy assignment operator. 200203955Srdivacky bool UserDeclaredCopyAssignment : 1; 201193326Sed 202203955Srdivacky /// UserDeclaredDestructor - True when this class has a 203203955Srdivacky /// user-declared destructor. 204203955Srdivacky bool UserDeclaredDestructor : 1; 205198092Srdivacky 206203955Srdivacky /// Aggregate - True when this class is an aggregate. 207203955Srdivacky bool Aggregate : 1; 208193326Sed 209203955Srdivacky /// PlainOldData - True when this class is a POD-type. 210203955Srdivacky bool PlainOldData : 1; 211198092Srdivacky 212203955Srdivacky /// Empty - true when this class is empty for traits purposes, 213203955Srdivacky /// i.e. has no data members other than 0-width bit-fields, has no 214203955Srdivacky /// virtual function/base, and doesn't inherit from a non-empty 215203955Srdivacky /// class. Doesn't take union-ness into account. 216203955Srdivacky bool Empty : 1; 217198092Srdivacky 218203955Srdivacky /// Polymorphic - True when this class is polymorphic, i.e. has at 219203955Srdivacky /// least one virtual member or derives from a polymorphic class. 220203955Srdivacky bool Polymorphic : 1; 221198092Srdivacky 222203955Srdivacky /// Abstract - True when this class is abstract, i.e. has at least 223203955Srdivacky /// one pure virtual function, (that can come from a base class). 224203955Srdivacky bool Abstract : 1; 225198092Srdivacky 226203955Srdivacky /// HasTrivialConstructor - True when this class has a trivial constructor. 227203955Srdivacky /// 228203955Srdivacky /// C++ [class.ctor]p5. A constructor is trivial if it is an 229203955Srdivacky /// implicitly-declared default constructor and if: 230203955Srdivacky /// * its class has no virtual functions and no virtual base classes, and 231203955Srdivacky /// * all the direct base classes of its class have trivial constructors, and 232203955Srdivacky /// * for all the nonstatic data members of its class that are of class type 233203955Srdivacky /// (or array thereof), each such class has a trivial constructor. 234203955Srdivacky bool HasTrivialConstructor : 1; 235198092Srdivacky 236203955Srdivacky /// HasTrivialCopyConstructor - True when this class has a trivial copy 237203955Srdivacky /// constructor. 238203955Srdivacky /// 239203955Srdivacky /// C++ [class.copy]p6. A copy constructor for class X is trivial 240203955Srdivacky /// if it is implicitly declared and if 241203955Srdivacky /// * class X has no virtual functions and no virtual base classes, and 242203955Srdivacky /// * each direct base class of X has a trivial copy constructor, and 243203955Srdivacky /// * for all the nonstatic data members of X that are of class type (or 244203955Srdivacky /// array thereof), each such class type has a trivial copy constructor; 245203955Srdivacky /// otherwise the copy constructor is non-trivial. 246203955Srdivacky bool HasTrivialCopyConstructor : 1; 247203955Srdivacky 248203955Srdivacky /// HasTrivialCopyAssignment - True when this class has a trivial copy 249203955Srdivacky /// assignment operator. 250203955Srdivacky /// 251203955Srdivacky /// C++ [class.copy]p11. A copy assignment operator for class X is 252203955Srdivacky /// trivial if it is implicitly declared and if 253203955Srdivacky /// * class X has no virtual functions and no virtual base classes, and 254203955Srdivacky /// * each direct base class of X has a trivial copy assignment operator, and 255203955Srdivacky /// * for all the nonstatic data members of X that are of class type (or 256203955Srdivacky /// array thereof), each such class type has a trivial copy assignment 257203955Srdivacky /// operator; 258203955Srdivacky /// otherwise the copy assignment operator is non-trivial. 259203955Srdivacky bool HasTrivialCopyAssignment : 1; 260203955Srdivacky 261203955Srdivacky /// HasTrivialDestructor - True when this class has a trivial destructor. 262203955Srdivacky /// 263203955Srdivacky /// C++ [class.dtor]p3. A destructor is trivial if it is an 264203955Srdivacky /// implicitly-declared destructor and if: 265203955Srdivacky /// * all of the direct base classes of its class have trivial destructors 266203955Srdivacky /// and 267203955Srdivacky /// * for all of the non-static data members of its class that are of class 268203955Srdivacky /// type (or array thereof), each such class has a trivial destructor. 269203955Srdivacky bool HasTrivialDestructor : 1; 270203955Srdivacky 271203955Srdivacky /// ComputedVisibleConversions - True when visible conversion functions are 272203955Srdivacky /// already computed and are available. 273203955Srdivacky bool ComputedVisibleConversions : 1; 274193326Sed 275203955Srdivacky /// Bases - Base classes of this class. 276203955Srdivacky /// FIXME: This is wasted space for a union. 277203955Srdivacky CXXBaseSpecifier *Bases; 278193326Sed 279203955Srdivacky /// NumBases - The number of base class specifiers in Bases. 280203955Srdivacky unsigned NumBases; 281193326Sed 282203955Srdivacky /// VBases - direct and indirect virtual base classes of this class. 283203955Srdivacky CXXBaseSpecifier *VBases; 284198092Srdivacky 285203955Srdivacky /// NumVBases - The number of virtual base class specifiers in VBases. 286203955Srdivacky unsigned NumVBases; 287198092Srdivacky 288203955Srdivacky /// Conversions - Overload set containing the conversion functions 289203955Srdivacky /// of this C++ class (but not its inherited conversion 290203955Srdivacky /// functions). Each of the entries in this overload set is a 291203955Srdivacky /// CXXConversionDecl. 292203955Srdivacky UnresolvedSet<4> Conversions; 293193326Sed 294203955Srdivacky /// VisibleConversions - Overload set containing the conversion 295203955Srdivacky /// functions of this C++ class and all those inherited conversion 296203955Srdivacky /// functions that are visible in this class. Each of the entries 297203955Srdivacky /// in this overload set is a CXXConversionDecl or a 298203955Srdivacky /// FunctionTemplateDecl. 299203955Srdivacky UnresolvedSet<4> VisibleConversions; 300203955Srdivacky 301203955Srdivacky /// Definition - The declaration which defines this record. 302203955Srdivacky CXXRecordDecl *Definition; 303203955Srdivacky 304205219Srdivacky /// FirstFriend - The first friend declaration in this class, or 305205219Srdivacky /// null if there aren't any. This is actually currently stored 306205219Srdivacky /// in reverse order. 307205219Srdivacky FriendDecl *FirstFriend; 308205219Srdivacky 309203955Srdivacky } *DefinitionData; 310203955Srdivacky 311203955Srdivacky struct DefinitionData &data() { 312203955Srdivacky assert(DefinitionData && "queried property of class with no definition"); 313203955Srdivacky return *DefinitionData; 314203955Srdivacky } 315203955Srdivacky 316203955Srdivacky const struct DefinitionData &data() const { 317203955Srdivacky assert(DefinitionData && "queried property of class with no definition"); 318203955Srdivacky return *DefinitionData; 319203955Srdivacky } 320198092Srdivacky 321193326Sed /// \brief The template or declaration that this declaration 322193326Sed /// describes or was instantiated from, respectively. 323198092Srdivacky /// 324193326Sed /// For non-templates, this value will be NULL. For record 325193326Sed /// declarations that describe a class template, this will be a 326193326Sed /// pointer to a ClassTemplateDecl. For member 327193326Sed /// classes of class template specializations, this will be the 328198092Srdivacky /// MemberSpecializationInfo referring to the member class that was 329198092Srdivacky /// instantiated or specialized. 330198092Srdivacky llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 331193326Sed TemplateOrInstantiation; 332206084Srdivacky 333206084Srdivacky#ifndef NDEBUG 334206084Srdivacky void CheckConversionFunction(NamedDecl *D); 335206084Srdivacky#endif 336198092Srdivacky 337193326Sedprotected: 338193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 339198092Srdivacky SourceLocation L, IdentifierInfo *Id, 340198092Srdivacky CXXRecordDecl *PrevDecl, 341198092Srdivacky SourceLocation TKL = SourceLocation()); 342193326Sed 343193326Sed ~CXXRecordDecl(); 344193326Sed 345193326Sedpublic: 346193326Sed /// base_class_iterator - Iterator that traverses the base classes 347198092Srdivacky /// of a class. 348193326Sed typedef CXXBaseSpecifier* base_class_iterator; 349193326Sed 350193326Sed /// base_class_const_iterator - Iterator that traverses the base 351198092Srdivacky /// classes of a class. 352193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 353193326Sed 354198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 355198092Srdivacky /// of a class in reverse order. 356198092Srdivacky typedef std::reverse_iterator<base_class_iterator> 357198092Srdivacky reverse_base_class_iterator; 358198092Srdivacky 359198092Srdivacky /// reverse_base_class_iterator = Iterator that traverses the base classes 360198092Srdivacky /// of a class in reverse order. 361198092Srdivacky typedef std::reverse_iterator<base_class_const_iterator> 362198092Srdivacky reverse_base_class_const_iterator; 363198092Srdivacky 364198092Srdivacky virtual CXXRecordDecl *getCanonicalDecl() { 365198092Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 366198092Srdivacky } 367199482Srdivacky virtual const CXXRecordDecl *getCanonicalDecl() const { 368199482Srdivacky return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 369199482Srdivacky } 370198092Srdivacky 371203955Srdivacky CXXRecordDecl *getDefinition() const { 372203955Srdivacky if (!DefinitionData) return 0; 373203955Srdivacky return data().Definition; 374203955Srdivacky } 375203955Srdivacky 376203955Srdivacky bool hasDefinition() const { return DefinitionData != 0; } 377203955Srdivacky 378193326Sed static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 379193326Sed SourceLocation L, IdentifierInfo *Id, 380198092Srdivacky SourceLocation TKL = SourceLocation(), 381193326Sed CXXRecordDecl* PrevDecl=0, 382193326Sed bool DelayTypeCreation = false); 383198092Srdivacky 384195341Sed virtual void Destroy(ASTContext& C); 385198092Srdivacky 386198092Srdivacky bool isDynamicClass() const { 387203955Srdivacky return data().Polymorphic || data().NumVBases != 0; 388198092Srdivacky } 389198092Srdivacky 390193326Sed /// setBases - Sets the base classes of this struct or class. 391203955Srdivacky void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 392193326Sed 393193326Sed /// getNumBases - Retrieves the number of base classes of this 394193326Sed /// class. 395203955Srdivacky unsigned getNumBases() const { return data().NumBases; } 396193326Sed 397203955Srdivacky base_class_iterator bases_begin() { return data().Bases; } 398203955Srdivacky base_class_const_iterator bases_begin() const { return data().Bases; } 399203955Srdivacky base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 400203955Srdivacky base_class_const_iterator bases_end() const { 401203955Srdivacky return bases_begin() + data().NumBases; 402203955Srdivacky } 403198092Srdivacky reverse_base_class_iterator bases_rbegin() { 404198092Srdivacky return reverse_base_class_iterator(bases_end()); 405198092Srdivacky } 406198092Srdivacky reverse_base_class_const_iterator bases_rbegin() const { 407198092Srdivacky return reverse_base_class_const_iterator(bases_end()); 408198092Srdivacky } 409198092Srdivacky reverse_base_class_iterator bases_rend() { 410198092Srdivacky return reverse_base_class_iterator(bases_begin()); 411198092Srdivacky } 412198092Srdivacky reverse_base_class_const_iterator bases_rend() const { 413198092Srdivacky return reverse_base_class_const_iterator(bases_begin()); 414198092Srdivacky } 415193326Sed 416198092Srdivacky /// getNumVBases - Retrieves the number of virtual base classes of this 417198092Srdivacky /// class. 418203955Srdivacky unsigned getNumVBases() const { return data().NumVBases; } 419198092Srdivacky 420203955Srdivacky base_class_iterator vbases_begin() { return data().VBases; } 421203955Srdivacky base_class_const_iterator vbases_begin() const { return data().VBases; } 422203955Srdivacky base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 423203955Srdivacky base_class_const_iterator vbases_end() const { 424203955Srdivacky return vbases_begin() + data().NumVBases; 425203955Srdivacky } 426198092Srdivacky reverse_base_class_iterator vbases_rbegin() { 427198092Srdivacky return reverse_base_class_iterator(vbases_end()); 428198092Srdivacky } 429198092Srdivacky reverse_base_class_const_iterator vbases_rbegin() const { 430198092Srdivacky return reverse_base_class_const_iterator(vbases_end()); 431198092Srdivacky } 432198092Srdivacky reverse_base_class_iterator vbases_rend() { 433198092Srdivacky return reverse_base_class_iterator(vbases_begin()); 434198092Srdivacky } 435198092Srdivacky reverse_base_class_const_iterator vbases_rend() const { 436198092Srdivacky return reverse_base_class_const_iterator(vbases_begin()); 437198092Srdivacky } 438198092Srdivacky 439202379Srdivacky /// \brief Determine whether this class has any dependent base classes. 440202379Srdivacky bool hasAnyDependentBases() const; 441202379Srdivacky 442198092Srdivacky /// Iterator access to method members. The method iterator visits 443198092Srdivacky /// all method members of the class, including non-instance methods, 444198092Srdivacky /// special methods, etc. 445198092Srdivacky typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 446198092Srdivacky 447198092Srdivacky /// method_begin - Method begin iterator. Iterates in the order the methods 448198092Srdivacky /// were declared. 449198092Srdivacky method_iterator method_begin() const { 450198092Srdivacky return method_iterator(decls_begin()); 451198092Srdivacky } 452198092Srdivacky /// method_end - Method end iterator. 453198092Srdivacky method_iterator method_end() const { 454198092Srdivacky return method_iterator(decls_end()); 455198092Srdivacky } 456198092Srdivacky 457198092Srdivacky /// Iterator access to constructor members. 458198092Srdivacky typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 459198092Srdivacky 460198092Srdivacky ctor_iterator ctor_begin() const { 461198092Srdivacky return ctor_iterator(decls_begin()); 462198092Srdivacky } 463198092Srdivacky ctor_iterator ctor_end() const { 464198092Srdivacky return ctor_iterator(decls_end()); 465198092Srdivacky } 466198092Srdivacky 467205219Srdivacky /// An iterator over friend declarations. All of these are defined 468205219Srdivacky /// in DeclFriend.h. 469205219Srdivacky class friend_iterator; 470205219Srdivacky friend_iterator friend_begin() const; 471205219Srdivacky friend_iterator friend_end() const; 472205219Srdivacky void pushFriendDecl(FriendDecl *FD); 473205219Srdivacky 474207619Srdivacky /// Determines whether this record has any friends. 475207619Srdivacky bool hasFriends() const { 476207619Srdivacky return data().FirstFriend != 0; 477207619Srdivacky } 478207619Srdivacky 479193326Sed /// hasConstCopyConstructor - Determines whether this class has a 480193326Sed /// copy constructor that accepts a const-qualified argument. 481193326Sed bool hasConstCopyConstructor(ASTContext &Context) const; 482193326Sed 483194711Sed /// getCopyConstructor - Returns the copy constructor for this class 484198092Srdivacky CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 485194711Sed unsigned TypeQuals) const; 486194711Sed 487193326Sed /// hasConstCopyAssignment - Determines whether this class has a 488193326Sed /// copy assignment operator that accepts a const-qualified argument. 489198092Srdivacky /// It returns its decl in MD if found. 490198092Srdivacky bool hasConstCopyAssignment(ASTContext &Context, 491198092Srdivacky const CXXMethodDecl *&MD) const; 492193326Sed 493193326Sed /// addedConstructor - Notify the class that another constructor has 494193326Sed /// been added. This routine helps maintain information about the 495193326Sed /// class based on which constructors have been added. 496193326Sed void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 497193326Sed 498193326Sed /// hasUserDeclaredConstructor - Whether this class has any 499193326Sed /// user-declared constructors. When true, a default constructor 500193326Sed /// will not be implicitly declared. 501198092Srdivacky bool hasUserDeclaredConstructor() const { 502203955Srdivacky return data().UserDeclaredConstructor; 503198092Srdivacky } 504193326Sed 505193326Sed /// hasUserDeclaredCopyConstructor - Whether this class has a 506193326Sed /// user-declared copy constructor. When false, a copy constructor 507193326Sed /// will be implicitly declared. 508193326Sed bool hasUserDeclaredCopyConstructor() const { 509203955Srdivacky return data().UserDeclaredCopyConstructor; 510193326Sed } 511193326Sed 512193326Sed /// addedAssignmentOperator - Notify the class that another assignment 513193326Sed /// operator has been added. This routine helps maintain information about the 514193326Sed /// class based on which operators have been added. 515193326Sed void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 516193326Sed 517193326Sed /// hasUserDeclaredCopyAssignment - Whether this class has a 518193326Sed /// user-declared copy assignment operator. When false, a copy 519193326Sed /// assigment operator will be implicitly declared. 520193326Sed bool hasUserDeclaredCopyAssignment() const { 521203955Srdivacky return data().UserDeclaredCopyAssignment; 522193326Sed } 523193326Sed 524193326Sed /// hasUserDeclaredDestructor - Whether this class has a 525193326Sed /// user-declared destructor. When false, a destructor will be 526193326Sed /// implicitly declared. 527203955Srdivacky bool hasUserDeclaredDestructor() const { 528203955Srdivacky return data().UserDeclaredDestructor; 529203955Srdivacky } 530193326Sed 531193326Sed /// setUserDeclaredDestructor - Set whether this class has a 532193326Sed /// user-declared destructor. If not set by the time the class is 533193326Sed /// fully defined, a destructor will be implicitly declared. 534198092Srdivacky void setUserDeclaredDestructor(bool UCD) { 535203955Srdivacky data().UserDeclaredDestructor = UCD; 536193326Sed } 537193326Sed 538193326Sed /// getConversions - Retrieve the overload set containing all of the 539193326Sed /// conversion functions in this class. 540202879Srdivacky UnresolvedSetImpl *getConversionFunctions() { 541203955Srdivacky return &data().Conversions; 542193326Sed } 543202879Srdivacky const UnresolvedSetImpl *getConversionFunctions() const { 544203955Srdivacky return &data().Conversions; 545193326Sed } 546193326Sed 547202879Srdivacky typedef UnresolvedSetImpl::iterator conversion_iterator; 548203955Srdivacky conversion_iterator conversion_begin() const { 549203955Srdivacky return getConversionFunctions()->begin(); 550203955Srdivacky } 551203955Srdivacky conversion_iterator conversion_end() const { 552203955Srdivacky return getConversionFunctions()->end(); 553203955Srdivacky } 554199990Srdivacky 555199990Srdivacky /// Replaces a conversion function with a new declaration. 556199990Srdivacky /// 557199990Srdivacky /// Returns true if the old conversion was found. 558199990Srdivacky bool replaceConversion(const NamedDecl* Old, NamedDecl *New) { 559203955Srdivacky return getConversionFunctions()->replace(Old, New); 560199990Srdivacky } 561199990Srdivacky 562206084Srdivacky /// Removes a conversion function from this class. The conversion 563206084Srdivacky /// function must currently be a member of this class. Furthermore, 564206084Srdivacky /// this class must currently be in the process of being defined. 565206084Srdivacky void removeConversion(const NamedDecl *Old); 566206084Srdivacky 567198092Srdivacky /// getVisibleConversionFunctions - get all conversion functions visible 568198092Srdivacky /// in current class; including conversion function templates. 569202879Srdivacky const UnresolvedSetImpl *getVisibleConversionFunctions(); 570199990Srdivacky 571206084Srdivacky /// addConversionFunction - Registers a conversion function which 572206084Srdivacky /// this class declares directly. 573206084Srdivacky void addConversionFunction(NamedDecl *Decl) { 574206084Srdivacky#ifndef NDEBUG 575206084Srdivacky CheckConversionFunction(Decl); 576206084Srdivacky#endif 577193326Sed 578206084Srdivacky // We intentionally don't use the decl's access here because it 579206084Srdivacky // hasn't been set yet. That's really just a misdesign in Sema. 580206084Srdivacky data().Conversions.addDecl(Decl); 581206084Srdivacky } 582198092Srdivacky 583193326Sed /// isAggregate - Whether this class is an aggregate (C++ 584193326Sed /// [dcl.init.aggr]), which is a class with no user-declared 585193326Sed /// constructors, no private or protected non-static data members, 586193326Sed /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 587203955Srdivacky bool isAggregate() const { return data().Aggregate; } 588193326Sed 589193326Sed /// setAggregate - Set whether this class is an aggregate (C++ 590193326Sed /// [dcl.init.aggr]). 591203955Srdivacky void setAggregate(bool Agg) { data().Aggregate = Agg; } 592193326Sed 593200583Srdivacky /// setMethodAsVirtual - Make input method virtual and set the necesssary 594200583Srdivacky /// special function bits and other bits accordingly. 595200583Srdivacky void setMethodAsVirtual(FunctionDecl *Method); 596200583Srdivacky 597193326Sed /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 598193326Sed /// that is an aggregate that has no non-static non-POD data members, no 599193326Sed /// reference data members, no user-defined copy assignment operator and no 600193326Sed /// user-defined destructor. 601203955Srdivacky bool isPOD() const { return data().PlainOldData; } 602193326Sed 603193326Sed /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 604203955Srdivacky void setPOD(bool POD) { data().PlainOldData = POD; } 605193326Sed 606198092Srdivacky /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 607198092Srdivacky /// means it has a virtual function, virtual base, data member (other than 608198092Srdivacky /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 609198092Srdivacky /// a check for union-ness. 610203955Srdivacky bool isEmpty() const { return data().Empty; } 611198092Srdivacky 612198092Srdivacky /// Set whether this class is empty (C++0x [meta.unary.prop]) 613203955Srdivacky void setEmpty(bool Emp) { data().Empty = Emp; } 614198092Srdivacky 615193326Sed /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 616193326Sed /// which means that the class contains or inherits a virtual function. 617203955Srdivacky bool isPolymorphic() const { return data().Polymorphic; } 618193326Sed 619193326Sed /// setPolymorphic - Set whether this class is polymorphic (C++ 620193326Sed /// [class.virtual]). 621203955Srdivacky void setPolymorphic(bool Poly) { data().Polymorphic = Poly; } 622193326Sed 623193326Sed /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 624193326Sed /// which means that the class contains or inherits a pure virtual function. 625203955Srdivacky bool isAbstract() const { return data().Abstract; } 626198092Srdivacky 627193326Sed /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 628203955Srdivacky void setAbstract(bool Abs) { data().Abstract = Abs; } 629198092Srdivacky 630193326Sed // hasTrivialConstructor - Whether this class has a trivial constructor 631193326Sed // (C++ [class.ctor]p5) 632203955Srdivacky bool hasTrivialConstructor() const { return data().HasTrivialConstructor; } 633198092Srdivacky 634193326Sed // setHasTrivialConstructor - Set whether this class has a trivial constructor 635193326Sed // (C++ [class.ctor]p5) 636203955Srdivacky void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; } 637198092Srdivacky 638198092Srdivacky // hasTrivialCopyConstructor - Whether this class has a trivial copy 639198092Srdivacky // constructor (C++ [class.copy]p6) 640203955Srdivacky bool hasTrivialCopyConstructor() const { 641203955Srdivacky return data().HasTrivialCopyConstructor; 642203955Srdivacky } 643198092Srdivacky 644198092Srdivacky // setHasTrivialCopyConstructor - Set whether this class has a trivial 645198092Srdivacky // copy constructor (C++ [class.copy]p6) 646203955Srdivacky void setHasTrivialCopyConstructor(bool TC) { 647203955Srdivacky data().HasTrivialCopyConstructor = TC; 648203955Srdivacky } 649198092Srdivacky 650198092Srdivacky // hasTrivialCopyAssignment - Whether this class has a trivial copy 651198092Srdivacky // assignment operator (C++ [class.copy]p11) 652203955Srdivacky bool hasTrivialCopyAssignment() const { 653203955Srdivacky return data().HasTrivialCopyAssignment; 654203955Srdivacky } 655198092Srdivacky 656198092Srdivacky // setHasTrivialCopyAssignment - Set whether this class has a 657198092Srdivacky // trivial copy assignment operator (C++ [class.copy]p11) 658203955Srdivacky void setHasTrivialCopyAssignment(bool TC) { 659203955Srdivacky data().HasTrivialCopyAssignment = TC; 660203955Srdivacky } 661198092Srdivacky 662193326Sed // hasTrivialDestructor - Whether this class has a trivial destructor 663193326Sed // (C++ [class.dtor]p3) 664203955Srdivacky bool hasTrivialDestructor() const { return data().HasTrivialDestructor; } 665198092Srdivacky 666193326Sed // setHasTrivialDestructor - Set whether this class has a trivial destructor 667193326Sed // (C++ [class.dtor]p3) 668203955Srdivacky void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; } 669198092Srdivacky 670193326Sed /// \brief If this record is an instantiation of a member class, 671193326Sed /// retrieves the member class from which it was instantiated. 672193326Sed /// 673193326Sed /// This routine will return non-NULL for (non-templated) member 674193326Sed /// classes of class templates. For example, given: 675193326Sed /// 676193326Sed /// \code 677193326Sed /// template<typename T> 678193326Sed /// struct X { 679193326Sed /// struct A { }; 680193326Sed /// }; 681193326Sed /// \endcode 682193326Sed /// 683193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 684193326Sed /// whose parent is the class template specialization X<int>. For 685193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 686193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 687193326Sed /// X<int>::A is required, it will be instantiated from the 688193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 689198092Srdivacky CXXRecordDecl *getInstantiatedFromMemberClass() const; 690198092Srdivacky 691198092Srdivacky /// \brief If this class is an instantiation of a member class of a 692198092Srdivacky /// class template specialization, retrieves the member specialization 693198092Srdivacky /// information. 694198092Srdivacky MemberSpecializationInfo *getMemberSpecializationInfo() const; 695198092Srdivacky 696193326Sed /// \brief Specify that this record is an instantiation of the 697193326Sed /// member class RD. 698198092Srdivacky void setInstantiationOfMemberClass(CXXRecordDecl *RD, 699198092Srdivacky TemplateSpecializationKind TSK); 700193326Sed 701193326Sed /// \brief Retrieves the class template that is described by this 702193326Sed /// class declaration. 703193326Sed /// 704193326Sed /// Every class template is represented as a ClassTemplateDecl and a 705193326Sed /// CXXRecordDecl. The former contains template properties (such as 706193326Sed /// the template parameter lists) while the latter contains the 707193326Sed /// actual description of the template's 708193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 709193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 710193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 711193326Sed /// a CXXRecordDecl. 712193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 713193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 714193326Sed } 715193326Sed 716193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 717193326Sed TemplateOrInstantiation = Template; 718193326Sed } 719193326Sed 720198092Srdivacky /// \brief Determine whether this particular class is a specialization or 721198092Srdivacky /// instantiation of a class template or member class of a class template, 722198092Srdivacky /// and how it was instantiated or specialized. 723200583Srdivacky TemplateSpecializationKind getTemplateSpecializationKind() const; 724198092Srdivacky 725198092Srdivacky /// \brief Set the kind of specialization or template instantiation this is. 726198092Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 727198092Srdivacky 728194613Sed /// getDefaultConstructor - Returns the default constructor for this class 729194613Sed CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 730198092Srdivacky 731193326Sed /// getDestructor - Returns the destructor decl for this class. 732204643Srdivacky CXXDestructorDecl *getDestructor(ASTContext &Context) const; 733198092Srdivacky 734195099Sed /// isLocalClass - If the class is a local class [class.local], returns 735195099Sed /// the enclosing function declaration. 736195099Sed const FunctionDecl *isLocalClass() const { 737195099Sed if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 738195099Sed return RD->isLocalClass(); 739198092Srdivacky 740195099Sed return dyn_cast<FunctionDecl>(getDeclContext()); 741195099Sed } 742198092Srdivacky 743198092Srdivacky /// \brief Determine whether this class is derived from the class \p Base. 744198092Srdivacky /// 745198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 746198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 747198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 748198092Srdivacky /// base class subobjects. 749198092Srdivacky /// 750198092Srdivacky /// \param Base the base class we are searching for. 751198092Srdivacky /// 752198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 753199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base) const; 754195099Sed 755198092Srdivacky /// \brief Determine whether this class is derived from the type \p Base. 756198092Srdivacky /// 757198092Srdivacky /// This routine only determines whether this class is derived from \p Base, 758198092Srdivacky /// but does not account for factors that may make a Derived -> Base class 759198092Srdivacky /// ill-formed, such as private/protected inheritance or multiple, ambiguous 760198092Srdivacky /// base class subobjects. 761198092Srdivacky /// 762198092Srdivacky /// \param Base the base class we are searching for. 763198092Srdivacky /// 764198092Srdivacky /// \param Paths will contain the paths taken from the current class to the 765198092Srdivacky /// given \p Base class. 766198092Srdivacky /// 767198092Srdivacky /// \returns true if this class is derived from Base, false otherwise. 768198092Srdivacky /// 769198092Srdivacky /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 770198092Srdivacky /// tangling input and output in \p Paths 771199482Srdivacky bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const; 772200583Srdivacky 773204643Srdivacky /// \brief Determine whether this class is virtually derived from 774204643Srdivacky /// the class \p Base. 775204643Srdivacky /// 776204643Srdivacky /// This routine only determines whether this class is virtually 777204643Srdivacky /// derived from \p Base, but does not account for factors that may 778204643Srdivacky /// make a Derived -> Base class ill-formed, such as 779204643Srdivacky /// private/protected inheritance or multiple, ambiguous base class 780204643Srdivacky /// subobjects. 781204643Srdivacky /// 782204643Srdivacky /// \param Base the base class we are searching for. 783204643Srdivacky /// 784204643Srdivacky /// \returns true if this class is virtually derived from Base, 785204643Srdivacky /// false otherwise. 786204643Srdivacky bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; 787204643Srdivacky 788200583Srdivacky /// \brief Determine whether this class is provably not derived from 789200583Srdivacky /// the type \p Base. 790200583Srdivacky bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 791200583Srdivacky 792200583Srdivacky /// \brief Function type used by forallBases() as a callback. 793200583Srdivacky /// 794200583Srdivacky /// \param Base the definition of the base class 795200583Srdivacky /// 796200583Srdivacky /// \returns true if this base matched the search criteria 797200583Srdivacky typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 798200583Srdivacky void *UserData); 799200583Srdivacky 800200583Srdivacky /// \brief Determines if the given callback holds for all the direct 801200583Srdivacky /// or indirect base classes of this type. 802200583Srdivacky /// 803200583Srdivacky /// The class itself does not count as a base class. This routine 804200583Srdivacky /// returns false if the class has non-computable base classes. 805200583Srdivacky /// 806200583Srdivacky /// \param AllowShortCircuit if false, forces the callback to be called 807200583Srdivacky /// for every base class, even if a dependent or non-matching base was 808200583Srdivacky /// found. 809200583Srdivacky bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 810200583Srdivacky bool AllowShortCircuit = true) const; 811198092Srdivacky 812198092Srdivacky /// \brief Function type used by lookupInBases() to determine whether a 813198092Srdivacky /// specific base class subobject matches the lookup criteria. 814198092Srdivacky /// 815198092Srdivacky /// \param Specifier the base-class specifier that describes the inheritance 816198092Srdivacky /// from the base class we are trying to match. 817198092Srdivacky /// 818198092Srdivacky /// \param Path the current path, from the most-derived class down to the 819198092Srdivacky /// base named by the \p Specifier. 820198092Srdivacky /// 821198092Srdivacky /// \param UserData a single pointer to user-specified data, provided to 822198092Srdivacky /// lookupInBases(). 823198092Srdivacky /// 824198092Srdivacky /// \returns true if this base matched the search criteria, false otherwise. 825199482Srdivacky typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 826198092Srdivacky CXXBasePath &Path, 827198092Srdivacky void *UserData); 828198092Srdivacky 829198092Srdivacky /// \brief Look for entities within the base classes of this C++ class, 830198092Srdivacky /// transitively searching all base class subobjects. 831198092Srdivacky /// 832198092Srdivacky /// This routine uses the callback function \p BaseMatches to find base 833198092Srdivacky /// classes meeting some search criteria, walking all base class subobjects 834198092Srdivacky /// and populating the given \p Paths structure with the paths through the 835198092Srdivacky /// inheritance hierarchy that resulted in a match. On a successful search, 836198092Srdivacky /// the \p Paths structure can be queried to retrieve the matching paths and 837198092Srdivacky /// to determine if there were any ambiguities. 838198092Srdivacky /// 839198092Srdivacky /// \param BaseMatches callback function used to determine whether a given 840198092Srdivacky /// base matches the user-defined search criteria. 841198092Srdivacky /// 842198092Srdivacky /// \param UserData user data pointer that will be provided to \p BaseMatches. 843198092Srdivacky /// 844198092Srdivacky /// \param Paths used to record the paths from this class to its base class 845198092Srdivacky /// subobjects that match the search criteria. 846198092Srdivacky /// 847198092Srdivacky /// \returns true if there exists any path from this class to a base class 848198092Srdivacky /// subobject that matches the search criteria. 849198092Srdivacky bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 850199482Srdivacky CXXBasePaths &Paths) const; 851198092Srdivacky 852198092Srdivacky /// \brief Base-class lookup callback that determines whether the given 853198092Srdivacky /// base class specifier refers to a specific class declaration. 854198092Srdivacky /// 855198092Srdivacky /// This callback can be used with \c lookupInBases() to determine whether 856198092Srdivacky /// a given derived class has is a base class subobject of a particular type. 857198092Srdivacky /// The user data pointer should refer to the canonical CXXRecordDecl of the 858198092Srdivacky /// base class that we are searching for. 859199482Srdivacky static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 860199482Srdivacky CXXBasePath &Path, void *BaseRecord); 861204643Srdivacky 862204643Srdivacky /// \brief Base-class lookup callback that determines whether the 863204643Srdivacky /// given base class specifier refers to a specific class 864204643Srdivacky /// declaration and describes virtual derivation. 865204643Srdivacky /// 866204643Srdivacky /// This callback can be used with \c lookupInBases() to determine 867204643Srdivacky /// whether a given derived class has is a virtual base class 868204643Srdivacky /// subobject of a particular type. The user data pointer should 869204643Srdivacky /// refer to the canonical CXXRecordDecl of the base class that we 870204643Srdivacky /// are searching for. 871204643Srdivacky static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 872204643Srdivacky CXXBasePath &Path, void *BaseRecord); 873198092Srdivacky 874198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 875198092Srdivacky /// a tag with the given name. 876198092Srdivacky /// 877198092Srdivacky /// This callback can be used with \c lookupInBases() to find tag members 878198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 879198092Srdivacky /// is an opaque \c DeclarationName pointer. 880199482Srdivacky static bool FindTagMember(const CXXBaseSpecifier *Specifier, 881199482Srdivacky CXXBasePath &Path, void *Name); 882198092Srdivacky 883198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 884198092Srdivacky /// a member with the given name. 885198092Srdivacky /// 886198092Srdivacky /// This callback can be used with \c lookupInBases() to find members 887198092Srdivacky /// of the given name within a C++ class hierarchy. The user data pointer 888198092Srdivacky /// is an opaque \c DeclarationName pointer. 889199482Srdivacky static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 890199482Srdivacky CXXBasePath &Path, void *Name); 891198092Srdivacky 892198092Srdivacky /// \brief Base-class lookup callback that determines whether there exists 893198092Srdivacky /// a member with the given name that can be used in a nested-name-specifier. 894198092Srdivacky /// 895198092Srdivacky /// This callback can be used with \c lookupInBases() to find membes of 896198092Srdivacky /// the given name within a C++ class hierarchy that can occur within 897198092Srdivacky /// nested-name-specifiers. 898199482Srdivacky static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 899198092Srdivacky CXXBasePath &Path, 900198092Srdivacky void *UserData); 901206084Srdivacky 902206084Srdivacky /// \brief Retrieve the final overriders for each virtual member 903206084Srdivacky /// function in the class hierarchy where this class is the 904206084Srdivacky /// most-derived class in the class hierarchy. 905206084Srdivacky void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 906206084Srdivacky 907193326Sed /// viewInheritance - Renders and displays an inheritance diagram 908193326Sed /// for this C++ class and all of its base classes (transitively) using 909193326Sed /// GraphViz. 910193326Sed void viewInheritance(ASTContext& Context) const; 911193326Sed 912202879Srdivacky /// MergeAccess - Calculates the access of a decl that is reached 913202879Srdivacky /// along a path. 914202879Srdivacky static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 915202879Srdivacky AccessSpecifier DeclAccess) { 916202879Srdivacky assert(DeclAccess != AS_none); 917202879Srdivacky if (DeclAccess == AS_private) return AS_none; 918202879Srdivacky return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 919202879Srdivacky } 920202879Srdivacky 921203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 922203955Srdivacky static bool classofKind(Kind K) { 923203955Srdivacky return K == CXXRecord || 924203955Srdivacky K == ClassTemplateSpecialization || 925203955Srdivacky K == ClassTemplatePartialSpecialization; 926193326Sed } 927193326Sed static bool classof(const CXXRecordDecl *D) { return true; } 928198092Srdivacky static bool classof(const ClassTemplateSpecializationDecl *D) { 929198092Srdivacky return true; 930193326Sed } 931193326Sed}; 932193326Sed 933193326Sed/// CXXMethodDecl - Represents a static or instance method of a 934193326Sed/// struct/union/class. 935193326Sedclass CXXMethodDecl : public FunctionDecl { 936193326Sedprotected: 937193326Sed CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 938200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 939207619Srdivacky bool isStatic, StorageClass SCAsWritten, bool isInline) 940200583Srdivacky : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None), 941207619Srdivacky SCAsWritten, isInline) {} 942193326Sed 943193326Sedpublic: 944193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 945193326Sed SourceLocation L, DeclarationName N, 946200583Srdivacky QualType T, TypeSourceInfo *TInfo, 947198092Srdivacky bool isStatic = false, 948207619Srdivacky StorageClass SCAsWritten = FunctionDecl::None, 949193326Sed bool isInline = false); 950198092Srdivacky 951193326Sed bool isStatic() const { return getStorageClass() == Static; } 952193326Sed bool isInstance() const { return !isStatic(); } 953193326Sed 954198092Srdivacky bool isVirtual() const { 955198092Srdivacky CXXMethodDecl *CD = 956198092Srdivacky cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 957198092Srdivacky 958198092Srdivacky if (CD->isVirtualAsWritten()) 959198092Srdivacky return true; 960198092Srdivacky 961198092Srdivacky return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 962193326Sed } 963206084Srdivacky 964198092Srdivacky /// \brief Determine whether this is a usual deallocation function 965198092Srdivacky /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 966198092Srdivacky /// delete or delete[] operator with a particular signature. 967198092Srdivacky bool isUsualDeallocationFunction() const; 968198092Srdivacky 969207619Srdivacky /// \brief Determine whether this is a copy-assignment operator, regardless 970207619Srdivacky /// of whether it was declared implicitly or explicitly. 971207619Srdivacky bool isCopyAssignmentOperator() const; 972207619Srdivacky 973198092Srdivacky const CXXMethodDecl *getCanonicalDecl() const { 974198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 975198092Srdivacky } 976198092Srdivacky CXXMethodDecl *getCanonicalDecl() { 977198092Srdivacky return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 978198092Srdivacky } 979198092Srdivacky 980198092Srdivacky /// 981198092Srdivacky void addOverriddenMethod(const CXXMethodDecl *MD); 982193326Sed 983193326Sed typedef const CXXMethodDecl ** method_iterator; 984198092Srdivacky 985193326Sed method_iterator begin_overridden_methods() const; 986193326Sed method_iterator end_overridden_methods() const; 987198092Srdivacky 988193326Sed /// getParent - Returns the parent of this method declaration, which 989193326Sed /// is the class in which this method is defined. 990198092Srdivacky const CXXRecordDecl *getParent() const { 991198092Srdivacky return cast<CXXRecordDecl>(FunctionDecl::getParent()); 992193326Sed } 993198092Srdivacky 994193326Sed /// getParent - Returns the parent of this method declaration, which 995193326Sed /// is the class in which this method is defined. 996198092Srdivacky CXXRecordDecl *getParent() { 997193326Sed return const_cast<CXXRecordDecl *>( 998193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 999193326Sed } 1000193326Sed 1001193326Sed /// getThisType - Returns the type of 'this' pointer. 1002193326Sed /// Should only be called for instance methods. 1003193326Sed QualType getThisType(ASTContext &C) const; 1004193326Sed 1005193326Sed unsigned getTypeQualifiers() const { 1006198092Srdivacky return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 1007193326Sed } 1008193326Sed 1009200583Srdivacky bool hasInlineBody() const; 1010200583Srdivacky 1011193326Sed // Implement isa/cast/dyncast/etc. 1012203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1013203955Srdivacky static bool classof(const CXXMethodDecl *D) { return true; } 1014203955Srdivacky static bool classofKind(Kind K) { 1015203955Srdivacky return K >= CXXMethod && K <= CXXConversion; 1016193326Sed } 1017193326Sed}; 1018193326Sed 1019193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member 1020193326Sed/// initializer, which is part of a constructor initializer that 1021193326Sed/// initializes one non-static member variable or one base class. For 1022193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 1023193326Sed/// initializers: 1024193326Sed/// 1025193326Sed/// @code 1026193326Sed/// class A { }; 1027193326Sed/// class B : public A { 1028193326Sed/// float f; 1029193326Sed/// public: 1030193326Sed/// B(A& a) : A(a), f(3.14159) { } 1031193326Sed/// }; 1032194613Sed/// @endcode 1033193326Sedclass CXXBaseOrMemberInitializer { 1034200583Srdivacky /// \brief Either the base class name (stored as a TypeSourceInfo*) or the 1035200583Srdivacky /// field being initialized. 1036200583Srdivacky llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember; 1037200583Srdivacky 1038200583Srdivacky /// \brief The source location for the field name. 1039200583Srdivacky SourceLocation MemberLocation; 1040200583Srdivacky 1041203955Srdivacky /// \brief The argument used to initialize the base or member, which may 1042203955Srdivacky /// end up constructing an object (when multiple arguments are involved). 1043203955Srdivacky Stmt *Init; 1044198092Srdivacky 1045198092Srdivacky /// \brief Stores either the constructor to call to initialize this base or 1046198092Srdivacky /// member (a CXXConstructorDecl pointer), or stores the anonymous union of 1047198092Srdivacky /// which the initialized value is a member. 1048198092Srdivacky /// 1049198092Srdivacky /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's 1050198092Srdivacky /// anonymous union data member, this field holds the FieldDecl for the 1051198092Srdivacky /// member of the anonymous union being initialized. 1052198092Srdivacky /// @code 1053198092Srdivacky /// struct X { 1054198092Srdivacky /// X() : au_i1(123) {} 1055198092Srdivacky /// union { 1056198092Srdivacky /// int au_i1; 1057198092Srdivacky /// float au_f1; 1058198092Srdivacky /// }; 1059198092Srdivacky /// }; 1060198092Srdivacky /// @endcode 1061198092Srdivacky /// In above example, BaseOrMember holds the field decl. for anonymous union 1062198092Srdivacky /// and AnonUnionMember holds field decl for au_i1. 1063203955Srdivacky FieldDecl *AnonUnionMember; 1064207619Srdivacky 1065200583Srdivacky /// LParenLoc - Location of the left paren of the ctor-initializer. 1066200583Srdivacky SourceLocation LParenLoc; 1067193326Sed 1068198092Srdivacky /// RParenLoc - Location of the right paren of the ctor-initializer. 1069198092Srdivacky SourceLocation RParenLoc; 1070198092Srdivacky 1071208600Srdivacky /// IsVirtual - If the initializer is a base initializer, this keeps track 1072208600Srdivacky /// of whether the base is virtual or not. 1073208600Srdivacky bool IsVirtual : 1; 1074208600Srdivacky 1075208600Srdivacky /// IsWritten - Whether or not the initializer is explicitly written 1076208600Srdivacky /// in the sources. 1077208600Srdivacky bool IsWritten : 1; 1078208600Srdivacky /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this 1079208600Srdivacky /// number keeps track of the textual order of this initializer in the 1080208600Srdivacky /// original sources, counting from 0; otherwise, if IsWritten is false, 1081208600Srdivacky /// it stores the number of array index variables stored after this 1082208600Srdivacky /// object in memory. 1083208600Srdivacky unsigned SourceOrderOrNumArrayIndices : 14; 1084208600Srdivacky 1085208600Srdivacky CXXBaseOrMemberInitializer(ASTContext &Context, 1086208600Srdivacky FieldDecl *Member, SourceLocation MemberLoc, 1087208600Srdivacky SourceLocation L, 1088208600Srdivacky Expr *Init, 1089208600Srdivacky SourceLocation R, 1090208600Srdivacky VarDecl **Indices, 1091208600Srdivacky unsigned NumIndices); 1092208600Srdivacky 1093193326Sedpublic: 1094193326Sed /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 1095198092Srdivacky explicit 1096200583Srdivacky CXXBaseOrMemberInitializer(ASTContext &Context, 1097207619Srdivacky TypeSourceInfo *TInfo, bool IsVirtual, 1098200583Srdivacky SourceLocation L, 1099203955Srdivacky Expr *Init, 1100200583Srdivacky SourceLocation R); 1101193326Sed 1102193326Sed /// CXXBaseOrMemberInitializer - Creates a new member initializer. 1103198092Srdivacky explicit 1104200583Srdivacky CXXBaseOrMemberInitializer(ASTContext &Context, 1105200583Srdivacky FieldDecl *Member, SourceLocation MemberLoc, 1106203955Srdivacky SourceLocation L, 1107203955Srdivacky Expr *Init, 1108200583Srdivacky SourceLocation R); 1109193326Sed 1110208600Srdivacky /// \brief Creates a new member initializer that optionally contains 1111208600Srdivacky /// array indices used to describe an elementwise initialization. 1112208600Srdivacky static CXXBaseOrMemberInitializer *Create(ASTContext &Context, 1113208600Srdivacky FieldDecl *Member, 1114208600Srdivacky SourceLocation MemberLoc, 1115208600Srdivacky SourceLocation L, 1116208600Srdivacky Expr *Init, 1117208600Srdivacky SourceLocation R, 1118208600Srdivacky VarDecl **Indices, 1119208600Srdivacky unsigned NumIndices); 1120208600Srdivacky 1121200583Srdivacky /// \brief Destroy the base or member initializer. 1122200583Srdivacky void Destroy(ASTContext &Context); 1123193326Sed 1124193326Sed /// isBaseInitializer - Returns true when this initializer is 1125193326Sed /// initializing a base class. 1126200583Srdivacky bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); } 1127193326Sed 1128193326Sed /// isMemberInitializer - Returns true when this initializer is 1129193326Sed /// initializing a non-static data member. 1130200583Srdivacky bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); } 1131193326Sed 1132200583Srdivacky /// If this is a base class initializer, returns the type of the 1133200583Srdivacky /// base class with location information. Otherwise, returns an NULL 1134200583Srdivacky /// type location. 1135200583Srdivacky TypeLoc getBaseClassLoc() const; 1136193326Sed 1137200583Srdivacky /// If this is a base class initializer, returns the type of the base class. 1138200583Srdivacky /// Otherwise, returns NULL. 1139200583Srdivacky const Type *getBaseClass() const; 1140200583Srdivacky Type *getBaseClass(); 1141207619Srdivacky 1142207619Srdivacky /// Returns whether the base is virtual or not. 1143207619Srdivacky bool isBaseVirtual() const { 1144207619Srdivacky assert(isBaseInitializer() && "Must call this on base initializer!"); 1145207619Srdivacky 1146207619Srdivacky return IsVirtual; 1147207619Srdivacky } 1148207619Srdivacky 1149200583Srdivacky /// \brief Returns the declarator information for a base class initializer. 1150200583Srdivacky TypeSourceInfo *getBaseClassInfo() const { 1151200583Srdivacky return BaseOrMember.dyn_cast<TypeSourceInfo *>(); 1152193326Sed } 1153200583Srdivacky 1154193326Sed /// getMember - If this is a member initializer, returns the 1155193326Sed /// declaration of the non-static data member being 1156193326Sed /// initialized. Otherwise, returns NULL. 1157198092Srdivacky FieldDecl *getMember() { 1158193326Sed if (isMemberInitializer()) 1159200583Srdivacky return BaseOrMember.get<FieldDecl*>(); 1160193326Sed else 1161193326Sed return 0; 1162193326Sed } 1163193326Sed 1164200583Srdivacky SourceLocation getMemberLocation() const { 1165200583Srdivacky return MemberLocation; 1166198092Srdivacky } 1167198092Srdivacky 1168200583Srdivacky void setMember(FieldDecl *Member) { 1169200583Srdivacky assert(isMemberInitializer()); 1170200583Srdivacky BaseOrMember = Member; 1171200583Srdivacky } 1172200583Srdivacky 1173200583Srdivacky /// \brief Determine the source location of the initializer. 1174200583Srdivacky SourceLocation getSourceLocation() const; 1175200583Srdivacky 1176200583Srdivacky /// \brief Determine the source range covering the entire initializer. 1177200583Srdivacky SourceRange getSourceRange() const; 1178208600Srdivacky 1179208600Srdivacky /// isWritten - Returns true if this initializer is explicitly written 1180208600Srdivacky /// in the source code. 1181208600Srdivacky bool isWritten() const { return IsWritten; } 1182208600Srdivacky 1183208600Srdivacky /// \brief Return the source position of the initializer, counting from 0. 1184208600Srdivacky /// If the initializer was implicit, -1 is returned. 1185208600Srdivacky int getSourceOrder() const { 1186208600Srdivacky return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1; 1187208600Srdivacky } 1188208600Srdivacky 1189208600Srdivacky /// \brief Set the source order of this initializer. This method can only 1190208600Srdivacky /// be called once for each initializer; it cannot be called on an 1191208600Srdivacky /// initializer having a positive number of (implicit) array indices. 1192208600Srdivacky void setSourceOrder(int pos) { 1193208600Srdivacky assert(!IsWritten && 1194208600Srdivacky "calling twice setSourceOrder() on the same initializer"); 1195208600Srdivacky assert(SourceOrderOrNumArrayIndices == 0 && 1196208600Srdivacky "setSourceOrder() used when there are implicit array indices"); 1197208600Srdivacky assert(pos >= 0 && 1198208600Srdivacky "setSourceOrder() used to make an initializer implicit"); 1199208600Srdivacky IsWritten = true; 1200208600Srdivacky SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos); 1201208600Srdivacky } 1202200583Srdivacky 1203198092Srdivacky FieldDecl *getAnonUnionMember() const { 1204203955Srdivacky return AnonUnionMember; 1205198092Srdivacky } 1206198092Srdivacky void setAnonUnionMember(FieldDecl *anonMember) { 1207203955Srdivacky AnonUnionMember = anonMember; 1208198092Srdivacky } 1209198092Srdivacky 1210208600Srdivacky 1211200583Srdivacky SourceLocation getLParenLoc() const { return LParenLoc; } 1212198092Srdivacky SourceLocation getRParenLoc() const { return RParenLoc; } 1213193326Sed 1214208600Srdivacky /// \brief Determine the number of implicit array indices used while 1215208600Srdivacky /// described an array member initialization. 1216208600Srdivacky unsigned getNumArrayIndices() const { 1217208600Srdivacky return IsWritten ? 0 : SourceOrderOrNumArrayIndices; 1218208600Srdivacky } 1219208600Srdivacky 1220208600Srdivacky /// \brief Retrieve a particular array index variable used to 1221208600Srdivacky /// describe an array member initialization. 1222208600Srdivacky VarDecl *getArrayIndex(unsigned I) { 1223208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1224208600Srdivacky return reinterpret_cast<VarDecl **>(this + 1)[I]; 1225208600Srdivacky } 1226208600Srdivacky const VarDecl *getArrayIndex(unsigned I) const { 1227208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1228208600Srdivacky return reinterpret_cast<const VarDecl * const *>(this + 1)[I]; 1229208600Srdivacky } 1230208600Srdivacky void setArrayIndex(unsigned I, VarDecl *Index) { 1231208600Srdivacky assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1232208600Srdivacky reinterpret_cast<VarDecl **>(this + 1)[I] = Index; 1233208600Srdivacky } 1234208600Srdivacky 1235203955Srdivacky Expr *getInit() { return static_cast<Expr *>(Init); } 1236193326Sed}; 1237193326Sed 1238193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a 1239193326Sed/// class. For example: 1240198092Srdivacky/// 1241193326Sed/// @code 1242193326Sed/// class X { 1243193326Sed/// public: 1244193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 1245193326Sed/// }; 1246193326Sed/// @endcode 1247193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 1248203955Srdivacky /// IsExplicitSpecified - Whether this constructor declaration has the 1249203955Srdivacky /// 'explicit' keyword specified. 1250203955Srdivacky bool IsExplicitSpecified : 1; 1251193326Sed 1252193326Sed /// ImplicitlyDefined - Whether this constructor was implicitly 1253193326Sed /// defined by the compiler. When false, the constructor was defined 1254193326Sed /// by the user. In C++03, this flag will have the same value as 1255193326Sed /// Implicit. In C++0x, however, a constructor that is 1256193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1257193326Sed /// @c !Implicit && ImplicitlyDefined. 1258193326Sed bool ImplicitlyDefined : 1; 1259198092Srdivacky 1260195341Sed /// Support for base and member initializers. 1261198092Srdivacky /// BaseOrMemberInitializers - The arguments used to initialize the base 1262195341Sed /// or member. 1263195341Sed CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 1264195341Sed unsigned NumBaseOrMemberInitializers; 1265198092Srdivacky 1266193326Sed CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 1267200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 1268203955Srdivacky bool isExplicitSpecified, bool isInline, 1269203955Srdivacky bool isImplicitlyDeclared) 1270207619Srdivacky : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, 1271207619Srdivacky FunctionDecl::None, isInline), 1272203955Srdivacky IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false), 1273198092Srdivacky BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 1274193326Sed setImplicit(isImplicitlyDeclared); 1275193326Sed } 1276195341Sed virtual void Destroy(ASTContext& C); 1277198092Srdivacky 1278193326Sedpublic: 1279208600Srdivacky static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty); 1280193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1281193326Sed SourceLocation L, DeclarationName N, 1282200583Srdivacky QualType T, TypeSourceInfo *TInfo, 1283198092Srdivacky bool isExplicit, 1284193326Sed bool isInline, bool isImplicitlyDeclared); 1285193326Sed 1286203955Srdivacky /// isExplicitSpecified - Whether this constructor declaration has the 1287203955Srdivacky /// 'explicit' keyword specified. 1288203955Srdivacky bool isExplicitSpecified() const { return IsExplicitSpecified; } 1289203955Srdivacky 1290198092Srdivacky /// isExplicit - Whether this constructor was marked "explicit" or not. 1291203955Srdivacky bool isExplicit() const { 1292203955Srdivacky return cast<CXXConstructorDecl>(getFirstDeclaration()) 1293203955Srdivacky ->isExplicitSpecified(); 1294203955Srdivacky } 1295193326Sed 1296193326Sed /// isImplicitlyDefined - Whether this constructor was implicitly 1297193326Sed /// defined. If false, then this constructor was defined by the 1298193326Sed /// user. This operation can only be invoked if the constructor has 1299193326Sed /// already been defined. 1300207619Srdivacky bool isImplicitlyDefined() const { 1301198092Srdivacky assert(isThisDeclarationADefinition() && 1302195341Sed "Can only get the implicit-definition flag once the " 1303195341Sed "constructor has been defined"); 1304198092Srdivacky return ImplicitlyDefined; 1305193326Sed } 1306193326Sed 1307193326Sed /// setImplicitlyDefined - Set whether this constructor was 1308193326Sed /// implicitly defined or not. 1309198092Srdivacky void setImplicitlyDefined(bool ID) { 1310198092Srdivacky assert(isThisDeclarationADefinition() && 1311195341Sed "Can only set the implicit-definition flag once the constructor " 1312195341Sed "has been defined"); 1313198092Srdivacky ImplicitlyDefined = ID; 1314193326Sed } 1315198092Srdivacky 1316195341Sed /// init_iterator - Iterates through the member/base initializer list. 1317195341Sed typedef CXXBaseOrMemberInitializer **init_iterator; 1318198092Srdivacky 1319195341Sed /// init_const_iterator - Iterates through the memberbase initializer list. 1320195341Sed typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 1321198092Srdivacky 1322198092Srdivacky /// init_begin() - Retrieve an iterator to the first initializer. 1323198092Srdivacky init_iterator init_begin() { return BaseOrMemberInitializers; } 1324195341Sed /// begin() - Retrieve an iterator to the first initializer. 1325198092Srdivacky init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 1326198092Srdivacky 1327198092Srdivacky /// init_end() - Retrieve an iterator past the last initializer. 1328198092Srdivacky init_iterator init_end() { 1329198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1330195341Sed } 1331195341Sed /// end() - Retrieve an iterator past the last initializer. 1332198092Srdivacky init_const_iterator init_end() const { 1333198092Srdivacky return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1334195341Sed } 1335198092Srdivacky 1336195341Sed /// getNumArgs - Determine the number of arguments used to 1337195341Sed /// initialize the member or base. 1338198092Srdivacky unsigned getNumBaseOrMemberInitializers() const { 1339198092Srdivacky return NumBaseOrMemberInitializers; 1340195341Sed } 1341198092Srdivacky 1342198092Srdivacky void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) { 1343198092Srdivacky NumBaseOrMemberInitializers = numBaseOrMemberInitializers; 1344198092Srdivacky } 1345198092Srdivacky 1346198092Srdivacky void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) { 1347198092Srdivacky BaseOrMemberInitializers = initializers; 1348198092Srdivacky } 1349193326Sed /// isDefaultConstructor - Whether this constructor is a default 1350193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 1351193326Sed /// default-initialize a class of this type. 1352193326Sed bool isDefaultConstructor() const; 1353193326Sed 1354193326Sed /// isCopyConstructor - Whether this constructor is a copy 1355193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1356193326Sed /// class. @p TypeQuals will be set to the qualifiers on the 1357193326Sed /// argument type. For example, @p TypeQuals would be set to @c 1358193326Sed /// QualType::Const for the following copy constructor: 1359193326Sed /// 1360193326Sed /// @code 1361193326Sed /// class X { 1362193326Sed /// public: 1363193326Sed /// X(const X&); 1364193326Sed /// }; 1365193326Sed /// @endcode 1366201361Srdivacky bool isCopyConstructor(unsigned &TypeQuals) const; 1367193326Sed 1368193326Sed /// isCopyConstructor - Whether this constructor is a copy 1369193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 1370193326Sed /// class. 1371201361Srdivacky bool isCopyConstructor() const { 1372193326Sed unsigned TypeQuals = 0; 1373201361Srdivacky return isCopyConstructor(TypeQuals); 1374193326Sed } 1375193326Sed 1376193326Sed /// isConvertingConstructor - Whether this constructor is a 1377193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 1378193326Sed /// used for user-defined conversions. 1379198092Srdivacky bool isConvertingConstructor(bool AllowExplicit) const; 1380193326Sed 1381199482Srdivacky /// \brief Determine whether this is a member template specialization that 1382199482Srdivacky /// looks like a copy constructor. Such constructors are never used to copy 1383199482Srdivacky /// an object. 1384199482Srdivacky bool isCopyConstructorLikeSpecialization() const; 1385199482Srdivacky 1386193326Sed // Implement isa/cast/dyncast/etc. 1387203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1388193326Sed static bool classof(const CXXConstructorDecl *D) { return true; } 1389203955Srdivacky static bool classofKind(Kind K) { return K == CXXConstructor; } 1390193326Sed}; 1391193326Sed 1392193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a 1393193326Sed/// class. For example: 1394198092Srdivacky/// 1395193326Sed/// @code 1396193326Sed/// class X { 1397193326Sed/// public: 1398193326Sed/// ~X(); // represented by a CXXDestructorDecl. 1399193326Sed/// }; 1400193326Sed/// @endcode 1401193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 1402193326Sed /// ImplicitlyDefined - Whether this destructor was implicitly 1403193326Sed /// defined by the compiler. When false, the destructor was defined 1404193326Sed /// by the user. In C++03, this flag will have the same value as 1405193326Sed /// Implicit. In C++0x, however, a destructor that is 1406193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 1407193326Sed /// @c !Implicit && ImplicitlyDefined. 1408193326Sed bool ImplicitlyDefined : 1; 1409193326Sed 1410199482Srdivacky FunctionDecl *OperatorDelete; 1411199482Srdivacky 1412193326Sed CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 1413193326Sed DeclarationName N, QualType T, 1414193326Sed bool isInline, bool isImplicitlyDeclared) 1415207619Srdivacky : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, 1416207619Srdivacky FunctionDecl::None, isInline), 1417199482Srdivacky ImplicitlyDefined(false), OperatorDelete(0) { 1418193326Sed setImplicit(isImplicitlyDeclared); 1419193326Sed } 1420193326Sed 1421193326Sedpublic: 1422208600Srdivacky static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty); 1423193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1424193326Sed SourceLocation L, DeclarationName N, 1425198092Srdivacky QualType T, bool isInline, 1426193326Sed bool isImplicitlyDeclared); 1427193326Sed 1428193326Sed /// isImplicitlyDefined - Whether this destructor was implicitly 1429193326Sed /// defined. If false, then this destructor was defined by the 1430193326Sed /// user. This operation can only be invoked if the destructor has 1431193326Sed /// already been defined. 1432198092Srdivacky bool isImplicitlyDefined() const { 1433198092Srdivacky assert(isThisDeclarationADefinition() && 1434193326Sed "Can only get the implicit-definition flag once the destructor has been defined"); 1435198092Srdivacky return ImplicitlyDefined; 1436193326Sed } 1437193326Sed 1438193326Sed /// setImplicitlyDefined - Set whether this destructor was 1439193326Sed /// implicitly defined or not. 1440198092Srdivacky void setImplicitlyDefined(bool ID) { 1441198092Srdivacky assert(isThisDeclarationADefinition() && 1442193326Sed "Can only set the implicit-definition flag once the destructor has been defined"); 1443198092Srdivacky ImplicitlyDefined = ID; 1444193326Sed } 1445193326Sed 1446199482Srdivacky void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 1447199482Srdivacky const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1448198092Srdivacky 1449193326Sed // Implement isa/cast/dyncast/etc. 1450203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1451193326Sed static bool classof(const CXXDestructorDecl *D) { return true; } 1452203955Srdivacky static bool classofKind(Kind K) { return K == CXXDestructor; } 1453193326Sed}; 1454193326Sed 1455193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a 1456193326Sed/// class. For example: 1457198092Srdivacky/// 1458193326Sed/// @code 1459193326Sed/// class X { 1460193326Sed/// public: 1461193326Sed/// operator bool(); 1462193326Sed/// }; 1463193326Sed/// @endcode 1464193326Sedclass CXXConversionDecl : public CXXMethodDecl { 1465203955Srdivacky /// IsExplicitSpecified - Whether this conversion function declaration is 1466203955Srdivacky /// marked "explicit", meaning that it can only be applied when the user 1467193326Sed /// explicitly wrote a cast. This is a C++0x feature. 1468203955Srdivacky bool IsExplicitSpecified : 1; 1469193326Sed 1470193326Sed CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1471200583Srdivacky DeclarationName N, QualType T, TypeSourceInfo *TInfo, 1472203955Srdivacky bool isInline, bool isExplicitSpecified) 1473207619Srdivacky : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, 1474207619Srdivacky FunctionDecl::None, isInline), 1475203955Srdivacky IsExplicitSpecified(isExplicitSpecified) { } 1476193326Sed 1477193326Sedpublic: 1478208600Srdivacky static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty); 1479193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1480193326Sed SourceLocation L, DeclarationName N, 1481200583Srdivacky QualType T, TypeSourceInfo *TInfo, 1482198092Srdivacky bool isInline, bool isExplicit); 1483193326Sed 1484203955Srdivacky /// IsExplicitSpecified - Whether this conversion function declaration is 1485203955Srdivacky /// marked "explicit", meaning that it can only be applied when the user 1486203955Srdivacky /// explicitly wrote a cast. This is a C++0x feature. 1487203955Srdivacky bool isExplicitSpecified() const { return IsExplicitSpecified; } 1488203955Srdivacky 1489193326Sed /// isExplicit - Whether this is an explicit conversion operator 1490193326Sed /// (C++0x only). Explicit conversion operators are only considered 1491193326Sed /// when the user has explicitly written a cast. 1492203955Srdivacky bool isExplicit() const { 1493203955Srdivacky return cast<CXXConversionDecl>(getFirstDeclaration()) 1494203955Srdivacky ->isExplicitSpecified(); 1495203955Srdivacky } 1496193326Sed 1497193326Sed /// getConversionType - Returns the type that this conversion 1498193326Sed /// function is converting to. 1499198092Srdivacky QualType getConversionType() const { 1500198092Srdivacky return getType()->getAs<FunctionType>()->getResultType(); 1501193326Sed } 1502193326Sed 1503193326Sed // Implement isa/cast/dyncast/etc. 1504203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1505193326Sed static bool classof(const CXXConversionDecl *D) { return true; } 1506203955Srdivacky static bool classofKind(Kind K) { return K == CXXConversion; } 1507193326Sed}; 1508193326Sed 1509193326Sed/// LinkageSpecDecl - This represents a linkage specification. For example: 1510193326Sed/// extern "C" void foo(); 1511193326Sed/// 1512193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 1513193326Sedpublic: 1514193326Sed /// LanguageIDs - Used to represent the language in a linkage 1515193326Sed /// specification. The values are part of the serialization abi for 1516193326Sed /// ASTs and cannot be changed without altering that abi. To help 1517193326Sed /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1518193326Sed /// from the dwarf standard. 1519208600Srdivacky enum LanguageIDs { 1520208600Srdivacky lang_c = /* DW_LANG_C */ 0x0002, 1521208600Srdivacky lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 1522208600Srdivacky }; 1523193326Sedprivate: 1524193326Sed /// Language - The language for this linkage specification. 1525193326Sed LanguageIDs Language; 1526193326Sed 1527193326Sed /// HadBraces - Whether this linkage specification had curly braces or not. 1528193326Sed bool HadBraces : 1; 1529193326Sed 1530198092Srdivacky LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1531193326Sed bool Braces) 1532198092Srdivacky : Decl(LinkageSpec, DC, L), 1533193326Sed DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1534193326Sed 1535193326Sedpublic: 1536198092Srdivacky static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1537198092Srdivacky SourceLocation L, LanguageIDs Lang, 1538193326Sed bool Braces); 1539193326Sed 1540208600Srdivacky /// \brief Return the language specified by this linkage specification. 1541193326Sed LanguageIDs getLanguage() const { return Language; } 1542193326Sed 1543208600Srdivacky /// \brief Set the language specified by this linkage specification. 1544208600Srdivacky void setLanguage(LanguageIDs L) { Language = L; } 1545208600Srdivacky 1546208600Srdivacky /// \brief Determines whether this linkage specification had braces in 1547208600Srdivacky /// its syntactic form. 1548193326Sed bool hasBraces() const { return HadBraces; } 1549193326Sed 1550208600Srdivacky /// \brief Set whether this linkage specification has braces in its 1551208600Srdivacky /// syntactic form. 1552208600Srdivacky void setHasBraces(bool B) { HadBraces = B; } 1553208600Srdivacky 1554203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1555193326Sed static bool classof(const LinkageSpecDecl *D) { return true; } 1556203955Srdivacky static bool classofKind(Kind K) { return K == LinkageSpec; } 1557193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1558193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1559193326Sed } 1560193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1561193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1562193326Sed } 1563193326Sed}; 1564193326Sed 1565193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1566193326Sed/// 1567193326Sed/// using namespace std; 1568193326Sed/// 1569193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1570193326Sed// artificial name, for all using-directives in order to store 1571193326Sed// them in DeclContext effectively. 1572193326Sedclass UsingDirectiveDecl : public NamedDecl { 1573193326Sed 1574193326Sed /// SourceLocation - Location of 'namespace' token. 1575193326Sed SourceLocation NamespaceLoc; 1576193326Sed 1577193326Sed /// \brief The source range that covers the nested-name-specifier 1578193326Sed /// preceding the namespace name. 1579193326Sed SourceRange QualifierRange; 1580193326Sed 1581193326Sed /// \brief The nested-name-specifier that precedes the namespace 1582193326Sed /// name, if any. 1583193326Sed NestedNameSpecifier *Qualifier; 1584193326Sed 1585193326Sed /// IdentLoc - Location of nominated namespace-name identifier. 1586193326Sed // FIXME: We don't store location of scope specifier. 1587193326Sed SourceLocation IdentLoc; 1588193326Sed 1589193326Sed /// NominatedNamespace - Namespace nominated by using-directive. 1590199990Srdivacky NamedDecl *NominatedNamespace; 1591193326Sed 1592199990Srdivacky /// Enclosing context containing both using-directive and nominated 1593193326Sed /// namespace. 1594193326Sed DeclContext *CommonAncestor; 1595193326Sed 1596193326Sed /// getUsingDirectiveName - Returns special DeclarationName used by 1597193326Sed /// using-directives. This is only used by DeclContext for storing 1598193326Sed /// UsingDirectiveDecls in its lookup structure. 1599193326Sed static DeclarationName getName() { 1600193326Sed return DeclarationName::getUsingDirectiveName(); 1601193326Sed } 1602193326Sed 1603193326Sed UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1604193326Sed SourceLocation NamespcLoc, 1605193326Sed SourceRange QualifierRange, 1606193326Sed NestedNameSpecifier *Qualifier, 1607193326Sed SourceLocation IdentLoc, 1608199990Srdivacky NamedDecl *Nominated, 1609193326Sed DeclContext *CommonAncestor) 1610193326Sed : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1611198092Srdivacky NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1612198092Srdivacky Qualifier(Qualifier), IdentLoc(IdentLoc), 1613199990Srdivacky NominatedNamespace(Nominated), 1614193326Sed CommonAncestor(CommonAncestor) { 1615193326Sed } 1616193326Sed 1617193326Sedpublic: 1618193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1619208600Srdivacky /// that qualifies the namespace name. 1620193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1621193326Sed 1622208600Srdivacky /// \brief Set the source range of the nested-name-specifier that 1623208600Srdivacky /// qualifies the namespace name. 1624208600Srdivacky void setQualifierRange(SourceRange R) { QualifierRange = R; } 1625208600Srdivacky 1626193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1627193326Sed /// name of the namespace. 1628193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1629193326Sed 1630208600Srdivacky /// \brief Set the nested-name-specifier that qualifes the name of the 1631208600Srdivacky /// namespace. 1632208600Srdivacky void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1633208600Srdivacky 1634199990Srdivacky NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 1635199990Srdivacky const NamedDecl *getNominatedNamespaceAsWritten() const { 1636199990Srdivacky return NominatedNamespace; 1637199990Srdivacky } 1638199990Srdivacky 1639193326Sed /// getNominatedNamespace - Returns namespace nominated by using-directive. 1640199990Srdivacky NamespaceDecl *getNominatedNamespace(); 1641193326Sed 1642193326Sed const NamespaceDecl *getNominatedNamespace() const { 1643193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1644193326Sed } 1645193326Sed 1646208600Srdivacky /// setNominatedNamespace - Set the namespace nominataed by the 1647208600Srdivacky /// using-directive. 1648208600Srdivacky void setNominatedNamespace(NamedDecl* NS); 1649208600Srdivacky 1650208600Srdivacky /// \brief Returns the common ancestor context of this using-directive and 1651208600Srdivacky /// its nominated namespace. 1652193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 1653193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1654193326Sed 1655208600Srdivacky /// \brief Set the common ancestor context of this using-directive and its 1656208600Srdivacky /// nominated namespace. 1657208600Srdivacky void setCommonAncestor(DeclContext* Cxt) { CommonAncestor = Cxt; } 1658208600Srdivacky 1659208600Srdivacky // FIXME: Could omit 'Key' in name. 1660193326Sed /// getNamespaceKeyLocation - Returns location of namespace keyword. 1661193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1662193326Sed 1663208600Srdivacky /// setNamespaceKeyLocation - Set the the location of the namespacekeyword. 1664208600Srdivacky void setNamespaceKeyLocation(SourceLocation L) { NamespaceLoc = L; } 1665208600Srdivacky 1666193326Sed /// getIdentLocation - Returns location of identifier. 1667193326Sed SourceLocation getIdentLocation() const { return IdentLoc; } 1668193326Sed 1669208600Srdivacky /// setIdentLocation - set the location of the identifier. 1670208600Srdivacky void setIdentLocation(SourceLocation L) { IdentLoc = L; } 1671208600Srdivacky 1672193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1673193326Sed SourceLocation L, 1674193326Sed SourceLocation NamespaceLoc, 1675193326Sed SourceRange QualifierRange, 1676193326Sed NestedNameSpecifier *Qualifier, 1677193326Sed SourceLocation IdentLoc, 1678199990Srdivacky NamedDecl *Nominated, 1679193326Sed DeclContext *CommonAncestor); 1680193326Sed 1681203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1682193326Sed static bool classof(const UsingDirectiveDecl *D) { return true; } 1683203955Srdivacky static bool classofKind(Kind K) { return K == Decl::UsingDirective; } 1684193326Sed 1685193326Sed // Friend for getUsingDirectiveName. 1686193326Sed friend class DeclContext; 1687193326Sed}; 1688193326Sed 1689193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1690193326Sed/// 1691193326Sed/// @code 1692193326Sed/// namespace Foo = Bar; 1693193326Sed/// @endcode 1694193326Sedclass NamespaceAliasDecl : public NamedDecl { 1695193326Sed SourceLocation AliasLoc; 1696193326Sed 1697193326Sed /// \brief The source range that covers the nested-name-specifier 1698193326Sed /// preceding the namespace name. 1699193326Sed SourceRange QualifierRange; 1700193326Sed 1701193326Sed /// \brief The nested-name-specifier that precedes the namespace 1702193326Sed /// name, if any. 1703193326Sed NestedNameSpecifier *Qualifier; 1704198092Srdivacky 1705208600Srdivacky /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc. 1706193326Sed SourceLocation IdentLoc; 1707198092Srdivacky 1708198092Srdivacky /// Namespace - The Decl that this alias points to. Can either be a 1709193326Sed /// NamespaceDecl or a NamespaceAliasDecl. 1710193326Sed NamedDecl *Namespace; 1711198092Srdivacky 1712198092Srdivacky NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1713198092Srdivacky SourceLocation AliasLoc, IdentifierInfo *Alias, 1714193326Sed SourceRange QualifierRange, 1715193326Sed NestedNameSpecifier *Qualifier, 1716193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 1717198092Srdivacky : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1718193326Sed QualifierRange(QualifierRange), Qualifier(Qualifier), 1719193326Sed IdentLoc(IdentLoc), Namespace(Namespace) { } 1720193326Sed 1721193326Sedpublic: 1722193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1723193326Sed /// that qualifiers the namespace name. 1724193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1725193326Sed 1726208600Srdivacky /// \brief Set the source range of the nested-name-specifier that qualifies 1727208600Srdivacky /// the namespace name. 1728208600Srdivacky void setQualifierRange(SourceRange R) { QualifierRange = R; } 1729208600Srdivacky 1730193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1731193326Sed /// name of the namespace. 1732193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1733193326Sed 1734208600Srdivacky /// \brief Set the nested-name-specifier that qualifies the name of the 1735208600Srdivacky /// namespace. 1736208600Srdivacky void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1737208600Srdivacky 1738208600Srdivacky /// \brief Retrieve the namespace declaration aliased by this directive. 1739193326Sed NamespaceDecl *getNamespace() { 1740193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1741193326Sed return AD->getNamespace(); 1742193326Sed 1743193326Sed return cast<NamespaceDecl>(Namespace); 1744193326Sed } 1745198092Srdivacky 1746193326Sed const NamespaceDecl *getNamespace() const { 1747193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1748193326Sed } 1749193326Sed 1750203955Srdivacky /// Returns the location of the alias name, i.e. 'foo' in 1751203955Srdivacky /// "namespace foo = ns::bar;". 1752203955Srdivacky SourceLocation getAliasLoc() const { return AliasLoc; } 1753203955Srdivacky 1754208600Srdivacky /// Set the location o;f the alias name, e.e., 'foo' in 1755208600Srdivacky /// "namespace foo = ns::bar;". 1756208600Srdivacky void setAliasLoc(SourceLocation L) { AliasLoc = L; } 1757208600Srdivacky 1758203955Srdivacky /// Returns the location of the 'namespace' keyword. 1759203955Srdivacky SourceLocation getNamespaceLoc() const { return getLocation(); } 1760203955Srdivacky 1761203955Srdivacky /// Returns the location of the identifier in the named namespace. 1762203955Srdivacky SourceLocation getTargetNameLoc() const { return IdentLoc; } 1763203955Srdivacky 1764208600Srdivacky /// Set the location of the identifier in the named namespace. 1765208600Srdivacky void setTargetNameLoc(SourceLocation L) { IdentLoc = L; } 1766208600Srdivacky 1767193326Sed /// \brief Retrieve the namespace that this alias refers to, which 1768193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1769193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 1770193326Sed 1771208600Srdivacky /// \brief Set the namespace or namespace alias pointed to by this 1772208600Srdivacky /// alias decl. 1773208600Srdivacky void setAliasedNamespace(NamedDecl *ND) { 1774208600Srdivacky assert((isa<NamespaceAliasDecl>(ND) || isa<NamespaceDecl>(ND)) && 1775208600Srdivacky "expecting namespace or namespace alias decl"); 1776208600Srdivacky Namespace = ND; 1777208600Srdivacky } 1778208600Srdivacky 1779198092Srdivacky static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1780198092Srdivacky SourceLocation L, SourceLocation AliasLoc, 1781198092Srdivacky IdentifierInfo *Alias, 1782193326Sed SourceRange QualifierRange, 1783193326Sed NestedNameSpecifier *Qualifier, 1784198092Srdivacky SourceLocation IdentLoc, 1785193326Sed NamedDecl *Namespace); 1786198092Srdivacky 1787203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1788193326Sed static bool classof(const NamespaceAliasDecl *D) { return true; } 1789203955Srdivacky static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; } 1790193326Sed}; 1791194613Sed 1792199482Srdivacky/// UsingShadowDecl - Represents a shadow declaration introduced into 1793199482Srdivacky/// a scope by a (resolved) using declaration. For example, 1794199482Srdivacky/// 1795199482Srdivacky/// namespace A { 1796199482Srdivacky/// void foo(); 1797199482Srdivacky/// } 1798199482Srdivacky/// namespace B { 1799199482Srdivacky/// using A::foo(); // <- a UsingDecl 1800199482Srdivacky/// // Also creates a UsingShadowDecl for A::foo in B 1801199482Srdivacky/// } 1802199482Srdivacky/// 1803199482Srdivackyclass UsingShadowDecl : public NamedDecl { 1804199482Srdivacky /// The referenced declaration. 1805199482Srdivacky NamedDecl *Underlying; 1806199482Srdivacky 1807199482Srdivacky /// The using declaration which introduced this decl. 1808199482Srdivacky UsingDecl *Using; 1809199482Srdivacky 1810199482Srdivacky UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 1811199482Srdivacky NamedDecl *Target) 1812199482Srdivacky : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()), 1813199482Srdivacky Underlying(Target), Using(Using) { 1814199482Srdivacky IdentifierNamespace = Target->getIdentifierNamespace(); 1815199482Srdivacky setImplicit(); 1816199482Srdivacky } 1817199482Srdivacky 1818199482Srdivackypublic: 1819199482Srdivacky static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 1820199482Srdivacky SourceLocation Loc, UsingDecl *Using, 1821199482Srdivacky NamedDecl *Target) { 1822199482Srdivacky return new (C) UsingShadowDecl(DC, Loc, Using, Target); 1823199482Srdivacky } 1824199482Srdivacky 1825208600Srdivacky /// \brief Gets the underlying declaration which has been brought into the 1826199482Srdivacky /// local scope. 1827208600Srdivacky NamedDecl *getTargetDecl() const { return Underlying; } 1828199482Srdivacky 1829208600Srdivacky /// \brief Sets the underlying declaration which has been brought into the 1830208600Srdivacky /// local scope. 1831208600Srdivacky void setTargetDecl(NamedDecl* ND) { Underlying = ND; } 1832199482Srdivacky 1833208600Srdivacky /// \brief Gets the using declaration to which this declaration is tied. 1834208600Srdivacky UsingDecl *getUsingDecl() const { return Using; } 1835208600Srdivacky 1836208600Srdivacky /// \brief Sets the using declaration that introduces this target 1837208600Srdivacky /// declaration. 1838208600Srdivacky void setUsingDecl(UsingDecl* UD) { Using = UD; } 1839208600Srdivacky 1840203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1841199482Srdivacky static bool classof(const UsingShadowDecl *D) { return true; } 1842203955Srdivacky static bool classofKind(Kind K) { return K == Decl::UsingShadow; } 1843199482Srdivacky}; 1844199482Srdivacky 1845194613Sed/// UsingDecl - Represents a C++ using-declaration. For example: 1846194613Sed/// using someNameSpace::someIdentifier; 1847194613Sedclass UsingDecl : public NamedDecl { 1848194613Sed /// \brief The source range that covers the nested-name-specifier 1849194613Sed /// preceding the declaration name. 1850194613Sed SourceRange NestedNameRange; 1851198092Srdivacky 1852194613Sed /// \brief The source location of the "using" location itself. 1853194613Sed SourceLocation UsingLocation; 1854198092Srdivacky 1855198092Srdivacky /// \brief Target nested name specifier. 1856199482Srdivacky NestedNameSpecifier* TargetNestedName; 1857194613Sed 1858199482Srdivacky /// \brief The collection of shadow declarations associated with 1859199482Srdivacky /// this using declaration. This set can change as a class is 1860199482Srdivacky /// processed. 1861199482Srdivacky llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows; 1862199482Srdivacky 1863198092Srdivacky // \brief Has 'typename' keyword. 1864194613Sed bool IsTypeName; 1865194613Sed 1866194613Sed UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1867199482Srdivacky SourceLocation UL, NestedNameSpecifier* TargetNNS, 1868199482Srdivacky DeclarationName Name, bool IsTypeNameArg) 1869199482Srdivacky : NamedDecl(Decl::Using, DC, L, Name), 1870199482Srdivacky NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS), 1871199482Srdivacky IsTypeName(IsTypeNameArg) { 1872194613Sed } 1873194613Sed 1874194613Sedpublic: 1875208600Srdivacky // FIXME: Should be const? 1876194613Sed /// \brief Returns the source range that covers the nested-name-specifier 1877194613Sed /// preceding the namespace name. 1878195099Sed SourceRange getNestedNameRange() { return NestedNameRange; } 1879198092Srdivacky 1880208600Srdivacky /// \brief Set the source range of the nested-name-specifier. 1881208600Srdivacky void setNestedNameRange(SourceRange R) { NestedNameRange = R; } 1882208600Srdivacky 1883208600Srdivacky // FIXME; Should be const? 1884208600Srdivacky // FIXME: Naming is inconsistent with other get*Loc functions. 1885208600Srdivacky /// \brief Returns the source location of the "using" keyword. 1886195099Sed SourceLocation getUsingLocation() { return UsingLocation; } 1887198092Srdivacky 1888208600Srdivacky /// \brief Set the source location of the 'using' keyword. 1889208600Srdivacky void setUsingLocation(SourceLocation L) { UsingLocation = L; } 1890208600Srdivacky 1891208600Srdivacky 1892208600Srdivacky /// \brief Get the target nested name declaration. 1893198092Srdivacky NestedNameSpecifier* getTargetNestedNameDecl() { 1894199482Srdivacky return TargetNestedName; 1895195099Sed } 1896198092Srdivacky 1897208600Srdivacky /// \brief Set the target nested name declaration. 1898208600Srdivacky void setTargetNestedNameDecl(NestedNameSpecifier *NNS) { 1899208600Srdivacky TargetNestedName = NNS; 1900208600Srdivacky } 1901208600Srdivacky 1902208600Srdivacky /// \brief Return true if the using declaration has 'typename'. 1903195099Sed bool isTypeName() const { return IsTypeName; } 1904194613Sed 1905208600Srdivacky /// \brief Sets whether the using declaration has 'typename'. 1906208600Srdivacky void setTypeName(bool TN) { IsTypeName = TN; } 1907208600Srdivacky 1908199482Srdivacky typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator; 1909199482Srdivacky shadow_iterator shadow_begin() const { return Shadows.begin(); } 1910199482Srdivacky shadow_iterator shadow_end() const { return Shadows.end(); } 1911199482Srdivacky 1912199482Srdivacky void addShadowDecl(UsingShadowDecl *S) { 1913199482Srdivacky assert(S->getUsingDecl() == this); 1914199482Srdivacky if (!Shadows.insert(S)) { 1915199482Srdivacky assert(false && "declaration already in set"); 1916199482Srdivacky } 1917199482Srdivacky } 1918199482Srdivacky void removeShadowDecl(UsingShadowDecl *S) { 1919199482Srdivacky assert(S->getUsingDecl() == this); 1920199482Srdivacky if (!Shadows.erase(S)) { 1921199482Srdivacky assert(false && "declaration not in set"); 1922199482Srdivacky } 1923199482Srdivacky } 1924199482Srdivacky 1925208600Srdivacky /// \brief Return the number of shadowed declarations associated with this 1926208600Srdivacky /// using declaration. 1927208600Srdivacky unsigned getNumShadowDecls() const { 1928208600Srdivacky return Shadows.size(); 1929208600Srdivacky } 1930208600Srdivacky 1931194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1932199482Srdivacky SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL, 1933199482Srdivacky NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg); 1934194613Sed 1935203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1936194613Sed static bool classof(const UsingDecl *D) { return true; } 1937203955Srdivacky static bool classofKind(Kind K) { return K == Decl::Using; } 1938194613Sed}; 1939198092Srdivacky 1940199482Srdivacky/// UnresolvedUsingValueDecl - Represents a dependent using 1941199482Srdivacky/// declaration which was not marked with 'typename'. Unlike 1942199482Srdivacky/// non-dependent using declarations, these *only* bring through 1943199482Srdivacky/// non-types; otherwise they would break two-phase lookup. 1944199482Srdivacky/// 1945199482Srdivacky/// template <class T> class A : public Base<T> { 1946199482Srdivacky/// using Base<T>::foo; 1947199482Srdivacky/// }; 1948199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl { 1949198092Srdivacky /// \brief The source range that covers the nested-name-specifier 1950198092Srdivacky /// preceding the declaration name. 1951198092Srdivacky SourceRange TargetNestedNameRange; 1952198092Srdivacky 1953199482Srdivacky /// \brief The source location of the 'using' keyword 1954199482Srdivacky SourceLocation UsingLocation; 1955198092Srdivacky 1956198092Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 1957198092Srdivacky 1958199482Srdivacky UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 1959199482Srdivacky SourceLocation UsingLoc, SourceRange TargetNNR, 1960199482Srdivacky NestedNameSpecifier *TargetNNS, 1961199482Srdivacky SourceLocation TargetNameLoc, 1962199482Srdivacky DeclarationName TargetName) 1963199482Srdivacky : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), 1964199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1965199482Srdivacky TargetNestedNameSpecifier(TargetNNS) 1966199482Srdivacky { } 1967198092Srdivacky 1968199482Srdivackypublic: 1969199482Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 1970199482Srdivacky /// preceding the namespace name. 1971199482Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1972198092Srdivacky 1973208600Srdivacky /// \brief Set the source range coverting the nested-name-specifier preceding 1974208600Srdivacky /// the namespace name. 1975208600Srdivacky void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; } 1976208600Srdivacky 1977199482Srdivacky /// \brief Get target nested name declaration. 1978199482Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 1979199482Srdivacky return TargetNestedNameSpecifier; 1980199482Srdivacky } 1981198092Srdivacky 1982208600Srdivacky /// \brief Set the nested name declaration. 1983208600Srdivacky void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) { 1984208600Srdivacky TargetNestedNameSpecifier = NNS; 1985208600Srdivacky } 1986208600Srdivacky 1987199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 1988199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 1989199482Srdivacky 1990208600Srdivacky /// \brief Set the source location of the 'using' keyword. 1991208600Srdivacky void setUsingLoc(SourceLocation L) { UsingLocation = L; } 1992208600Srdivacky 1993199482Srdivacky static UnresolvedUsingValueDecl * 1994199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1995199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1996199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 1997199482Srdivacky 1998203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1999199482Srdivacky static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 2000203955Srdivacky static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; } 2001199482Srdivacky}; 2002199482Srdivacky 2003199482Srdivacky/// UnresolvedUsingTypenameDecl - Represents a dependent using 2004199482Srdivacky/// declaration which was marked with 'typename'. 2005199482Srdivacky/// 2006199482Srdivacky/// template <class T> class A : public Base<T> { 2007199482Srdivacky/// using typename Base<T>::foo; 2008199482Srdivacky/// }; 2009199482Srdivacky/// 2010199482Srdivacky/// The type associated with a unresolved using typename decl is 2011199482Srdivacky/// currently always a typename type. 2012199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl { 2013199482Srdivacky /// \brief The source range that covers the nested-name-specifier 2014199482Srdivacky /// preceding the declaration name. 2015199482Srdivacky SourceRange TargetNestedNameRange; 2016199482Srdivacky 2017199482Srdivacky /// \brief The source location of the 'using' keyword 2018199482Srdivacky SourceLocation UsingLocation; 2019199482Srdivacky 2020199482Srdivacky /// \brief The source location of the 'typename' keyword 2021199482Srdivacky SourceLocation TypenameLocation; 2022199482Srdivacky 2023199482Srdivacky NestedNameSpecifier *TargetNestedNameSpecifier; 2024199482Srdivacky 2025199482Srdivacky UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 2026199482Srdivacky SourceLocation TypenameLoc, 2027199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 2028199482Srdivacky SourceLocation TargetNameLoc, IdentifierInfo *TargetName) 2029199482Srdivacky : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), 2030199482Srdivacky TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 2031199482Srdivacky TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS) 2032199482Srdivacky { } 2033199482Srdivacky 2034198092Srdivackypublic: 2035198092Srdivacky /// \brief Returns the source range that covers the nested-name-specifier 2036198092Srdivacky /// preceding the namespace name. 2037198092Srdivacky SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 2038198092Srdivacky 2039208600Srdivacky /// \brief Set the source range coverting the nested-name-specifier preceding 2040208600Srdivacky /// the namespace name. 2041208600Srdivacky void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; } 2042208600Srdivacky 2043198092Srdivacky /// \brief Get target nested name declaration. 2044198092Srdivacky NestedNameSpecifier* getTargetNestedNameSpecifier() { 2045198092Srdivacky return TargetNestedNameSpecifier; 2046198092Srdivacky } 2047198092Srdivacky 2048208600Srdivacky /// \brief Set the nested name declaration. 2049208600Srdivacky void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) { 2050208600Srdivacky TargetNestedNameSpecifier = NNS; 2051208600Srdivacky } 2052208600Srdivacky 2053199482Srdivacky /// \brief Returns the source location of the 'using' keyword. 2054199482Srdivacky SourceLocation getUsingLoc() const { return UsingLocation; } 2055198092Srdivacky 2056208600Srdivacky /// \brief Set the source location of the 'using' keyword. 2057208600Srdivacky void setUsingLoc(SourceLocation L) { UsingLocation = L; } 2058208600Srdivacky 2059199482Srdivacky /// \brief Returns the source location of the 'typename' keyword. 2060199482Srdivacky SourceLocation getTypenameLoc() const { return TypenameLocation; } 2061198092Srdivacky 2062208600Srdivacky /// \brief Set the source location of the 'typename' keyword. 2063208600Srdivacky void setTypenameLoc(SourceLocation L) { TypenameLocation = L; } 2064208600Srdivacky 2065199482Srdivacky static UnresolvedUsingTypenameDecl * 2066199482Srdivacky Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2067199482Srdivacky SourceLocation TypenameLoc, 2068199482Srdivacky SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 2069199482Srdivacky SourceLocation TargetNameLoc, DeclarationName TargetName); 2070198092Srdivacky 2071203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2072199482Srdivacky static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 2073203955Srdivacky static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; } 2074198092Srdivacky}; 2075198092Srdivacky 2076193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration. 2077193326Sedclass StaticAssertDecl : public Decl { 2078193326Sed Expr *AssertExpr; 2079193326Sed StringLiteral *Message; 2080193326Sed 2081198092Srdivacky StaticAssertDecl(DeclContext *DC, SourceLocation L, 2082193326Sed Expr *assertexpr, StringLiteral *message) 2083193326Sed : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 2084198092Srdivacky 2085193326Sedpublic: 2086193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 2087193326Sed SourceLocation L, Expr *AssertExpr, 2088193326Sed StringLiteral *Message); 2089198092Srdivacky 2090193326Sed Expr *getAssertExpr() { return AssertExpr; } 2091193326Sed const Expr *getAssertExpr() const { return AssertExpr; } 2092198092Srdivacky 2093193326Sed StringLiteral *getMessage() { return Message; } 2094193326Sed const StringLiteral *getMessage() const { return Message; } 2095198092Srdivacky 2096193326Sed virtual ~StaticAssertDecl(); 2097193326Sed virtual void Destroy(ASTContext& C); 2098193326Sed 2099203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2100193326Sed static bool classof(StaticAssertDecl *D) { return true; } 2101203955Srdivacky static bool classofKind(Kind K) { return K == Decl::StaticAssert; } 2102193326Sed}; 2103193326Sed 2104193326Sed/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 2105193326Sed/// into a diagnostic with <<. 2106193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 2107193326Sed AccessSpecifier AS); 2108198092Srdivacky 2109193326Sed} // end namespace clang 2110193326Sed 2111193326Sed#endif 2112