DeclCXX.h revision 194613
1193326Sed//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the C++ Decl subclasses. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H 15193326Sed#define LLVM_CLANG_AST_DECLCXX_H 16193326Sed 17193326Sed#include "clang/AST/Decl.h" 18193326Sed#include "llvm/ADT/SmallVector.h" 19193326Sed 20193326Sednamespace clang { 21193326Sed 22193326Sedclass ClassTemplateDecl; 23193326Sedclass CXXRecordDecl; 24193326Sedclass CXXConstructorDecl; 25193326Sedclass CXXDestructorDecl; 26193326Sedclass CXXConversionDecl; 27193326Sedclass CXXMethodDecl; 28193326Sedclass ClassTemplateSpecializationDecl; 29193326Sed 30193326Sed/// OverloadedFunctionDecl - An instance of this class represents a 31193326Sed/// set of overloaded functions. All of the functions have the same 32193326Sed/// name and occur within the same scope. 33193326Sed/// 34193326Sed/// An OverloadedFunctionDecl has no ownership over the FunctionDecl 35193326Sed/// nodes it contains. Rather, the FunctionDecls are owned by the 36193326Sed/// enclosing scope (which also owns the OverloadedFunctionDecl 37193326Sed/// node). OverloadedFunctionDecl is used primarily to store a set of 38193326Sed/// overloaded functions for name lookup. 39193326Sedclass OverloadedFunctionDecl : public NamedDecl { 40193326Sedprotected: 41193326Sed OverloadedFunctionDecl(DeclContext *DC, DeclarationName N) 42193326Sed : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { } 43193326Sed 44193326Sed /// Functions - the set of overloaded functions contained in this 45193326Sed /// overload set. 46193326Sed llvm::SmallVector<FunctionDecl *, 4> Functions; 47193326Sed 48193326Sed // FIXME: This should go away when we stop using 49193326Sed // OverloadedFunctionDecl to store conversions in CXXRecordDecl. 50193326Sed friend class CXXRecordDecl; 51193326Sed 52193326Sedpublic: 53193326Sed typedef llvm::SmallVector<FunctionDecl *, 4>::iterator function_iterator; 54193326Sed typedef llvm::SmallVector<FunctionDecl *, 4>::const_iterator 55193326Sed function_const_iterator; 56193326Sed 57193326Sed static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC, 58193326Sed DeclarationName N); 59193326Sed 60193326Sed /// addOverload - Add an overloaded function FD to this set of 61193326Sed /// overloaded functions. 62193326Sed void addOverload(FunctionDecl *FD) { 63193326Sed assert((FD->getDeclName() == getDeclName() || 64193326Sed isa<CXXConversionDecl>(FD) || isa<CXXConstructorDecl>(FD)) && 65193326Sed "Overloaded functions must have the same name"); 66193326Sed Functions.push_back(FD); 67193326Sed 68193326Sed // An overloaded function declaration always has the location of 69193326Sed // the most-recently-added function declaration. 70193326Sed if (FD->getLocation().isValid()) 71193326Sed this->setLocation(FD->getLocation()); 72193326Sed } 73193326Sed 74193326Sed function_iterator function_begin() { return Functions.begin(); } 75193326Sed function_iterator function_end() { return Functions.end(); } 76193326Sed function_const_iterator function_begin() const { return Functions.begin(); } 77193326Sed function_const_iterator function_end() const { return Functions.end(); } 78193326Sed 79193326Sed /// getNumFunctions - the number of overloaded functions stored in 80193326Sed /// this set. 81193326Sed unsigned getNumFunctions() const { return Functions.size(); } 82193326Sed 83193326Sed /// getFunction - retrieve the ith function in the overload set. 84193326Sed const FunctionDecl *getFunction(unsigned i) const { 85193326Sed assert(i < getNumFunctions() && "Illegal function #"); 86193326Sed return Functions[i]; 87193326Sed } 88193326Sed FunctionDecl *getFunction(unsigned i) { 89193326Sed assert(i < getNumFunctions() && "Illegal function #"); 90193326Sed return Functions[i]; 91193326Sed } 92193326Sed 93193326Sed // getDeclContext - Get the context of these overloaded functions. 94193326Sed DeclContext *getDeclContext() { 95193326Sed assert(getNumFunctions() > 0 && "Context of an empty overload set"); 96193326Sed return getFunction(0)->getDeclContext(); 97193326Sed } 98193326Sed 99193326Sed // Implement isa/cast/dyncast/etc. 100193326Sed static bool classof(const Decl *D) { 101193326Sed return D->getKind() == OverloadedFunction; 102193326Sed } 103193326Sed static bool classof(const OverloadedFunctionDecl *D) { return true; } 104193326Sed}; 105193326Sed 106193326Sed/// CXXBaseSpecifier - A base class of a C++ class. 107193326Sed/// 108193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or 109193326Sed/// struct) of a C++ class (or struct). It specifies the type of that 110193326Sed/// base class, whether it is a virtual or non-virtual base, and what 111193326Sed/// level of access (public, protected, private) is used for the 112193326Sed/// derivation. For example: 113193326Sed/// 114193326Sed/// @code 115193326Sed/// class A { }; 116193326Sed/// class B { }; 117193326Sed/// class C : public virtual A, protected B { }; 118193326Sed/// @endcode 119193326Sed/// 120193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public 121193326Sed/// virtual A" and the other for "protected B". 122193326Sedclass CXXBaseSpecifier { 123193326Sed /// Range - The source code range that covers the full base 124193326Sed /// specifier, including the "virtual" (if present) and access 125193326Sed /// specifier (if present). 126193326Sed SourceRange Range; 127193326Sed 128193326Sed /// Virtual - Whether this is a virtual base class or not. 129193326Sed bool Virtual : 1; 130193326Sed 131193326Sed /// BaseOfClass - Whether this is the base of a class (true) or of a 132193326Sed /// struct (false). This determines the mapping from the access 133193326Sed /// specifier as written in the source code to the access specifier 134193326Sed /// used for semantic analysis. 135193326Sed bool BaseOfClass : 1; 136193326Sed 137193326Sed /// Access - Access specifier as written in the source code (which 138193326Sed /// may be AS_none). The actual type of data stored here is an 139193326Sed /// AccessSpecifier, but we use "unsigned" here to work around a 140193326Sed /// VC++ bug. 141193326Sed unsigned Access : 2; 142193326Sed 143193326Sed /// BaseType - The type of the base class. This will be a class or 144193326Sed /// struct (or a typedef of such). 145193326Sed QualType BaseType; 146193326Sed 147193326Sedpublic: 148193326Sed CXXBaseSpecifier() { } 149193326Sed 150193326Sed CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 151193326Sed : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 152193326Sed 153193326Sed /// getSourceRange - Retrieves the source range that contains the 154193326Sed /// entire base specifier. 155193326Sed SourceRange getSourceRange() const { return Range; } 156193326Sed 157193326Sed /// isVirtual - Determines whether the base class is a virtual base 158193326Sed /// class (or not). 159193326Sed bool isVirtual() const { return Virtual; } 160193326Sed 161193326Sed /// getAccessSpecifier - Returns the access specifier for this base 162193326Sed /// specifier. This is the actual base specifier as used for 163193326Sed /// semantic analysis, so the result can never be AS_none. To 164193326Sed /// retrieve the access specifier as written in the source code, use 165193326Sed /// getAccessSpecifierAsWritten(). 166193326Sed AccessSpecifier getAccessSpecifier() const { 167193326Sed if ((AccessSpecifier)Access == AS_none) 168193326Sed return BaseOfClass? AS_private : AS_public; 169193326Sed else 170193326Sed return (AccessSpecifier)Access; 171193326Sed } 172193326Sed 173193326Sed /// getAccessSpecifierAsWritten - Retrieves the access specifier as 174193326Sed /// written in the source code (which may mean that no access 175193326Sed /// specifier was explicitly written). Use getAccessSpecifier() to 176193326Sed /// retrieve the access specifier for use in semantic analysis. 177193326Sed AccessSpecifier getAccessSpecifierAsWritten() const { 178193326Sed return (AccessSpecifier)Access; 179193326Sed } 180193326Sed 181193326Sed /// getType - Retrieves the type of the base class. This type will 182193326Sed /// always be an unqualified class type. 183193326Sed QualType getType() const { return BaseType; } 184193326Sed}; 185193326Sed 186193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class. 187193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl 188193326Sed/// to deal with C++-specific things. 189193326Sedclass CXXRecordDecl : public RecordDecl { 190193326Sed /// UserDeclaredConstructor - True when this class has a 191193326Sed /// user-declared constructor. 192193326Sed bool UserDeclaredConstructor : 1; 193193326Sed 194193326Sed /// UserDeclaredCopyConstructor - True when this class has a 195193326Sed /// user-declared copy constructor. 196193326Sed bool UserDeclaredCopyConstructor : 1; 197193326Sed 198193326Sed /// UserDeclaredCopyAssignment - True when this class has a 199193326Sed /// user-declared copy assignment operator. 200193326Sed bool UserDeclaredCopyAssignment : 1; 201193326Sed 202193326Sed /// UserDeclaredDestructor - True when this class has a 203193326Sed /// user-declared destructor. 204193326Sed bool UserDeclaredDestructor : 1; 205193326Sed 206193326Sed /// Aggregate - True when this class is an aggregate. 207193326Sed bool Aggregate : 1; 208193326Sed 209193326Sed /// PlainOldData - True when this class is a POD-type. 210193326Sed bool PlainOldData : 1; 211193326Sed 212193326Sed /// Polymorphic - True when this class is polymorphic, i.e. has at least one 213193326Sed /// virtual member or derives from a polymorphic class. 214193326Sed bool Polymorphic : 1; 215193326Sed 216193326Sed /// Abstract - True when this class is abstract, i.e. has at least one 217193326Sed /// pure virtual function, (that can come from a base class). 218193326Sed bool Abstract : 1; 219193326Sed 220193326Sed /// HasTrivialConstructor - True when this class has a trivial constructor 221193326Sed bool HasTrivialConstructor : 1; 222193326Sed 223193326Sed /// HasTrivialDestructor - True when this class has a trivial destructor 224193326Sed bool HasTrivialDestructor : 1; 225193326Sed 226193326Sed /// Bases - Base classes of this class. 227193326Sed /// FIXME: This is wasted space for a union. 228193326Sed CXXBaseSpecifier *Bases; 229193326Sed 230193326Sed /// NumBases - The number of base class specifiers in Bases. 231193326Sed unsigned NumBases; 232193326Sed 233193326Sed /// Conversions - Overload set containing the conversion functions 234193326Sed /// of this C++ class (but not its inherited conversion 235193326Sed /// functions). Each of the entries in this overload set is a 236193326Sed /// CXXConversionDecl. 237193326Sed OverloadedFunctionDecl Conversions; 238193326Sed 239193326Sed /// \brief The template or declaration that this declaration 240193326Sed /// describes or was instantiated from, respectively. 241193326Sed /// 242193326Sed /// For non-templates, this value will be NULL. For record 243193326Sed /// declarations that describe a class template, this will be a 244193326Sed /// pointer to a ClassTemplateDecl. For member 245193326Sed /// classes of class template specializations, this will be the 246193326Sed /// RecordDecl from which the member class was instantiated. 247193326Sed llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*> 248193326Sed TemplateOrInstantiation; 249193326Sed 250193326Sedprotected: 251193326Sed CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 252193326Sed SourceLocation L, IdentifierInfo *Id); 253193326Sed 254193326Sed ~CXXRecordDecl(); 255193326Sed 256193326Sedpublic: 257193326Sed /// base_class_iterator - Iterator that traverses the base classes 258193326Sed /// of a clas. 259193326Sed typedef CXXBaseSpecifier* base_class_iterator; 260193326Sed 261193326Sed /// base_class_const_iterator - Iterator that traverses the base 262193326Sed /// classes of a clas. 263193326Sed typedef const CXXBaseSpecifier* base_class_const_iterator; 264193326Sed 265193326Sed static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 266193326Sed SourceLocation L, IdentifierInfo *Id, 267193326Sed CXXRecordDecl* PrevDecl=0, 268193326Sed bool DelayTypeCreation = false); 269193326Sed 270193326Sed /// setBases - Sets the base classes of this struct or class. 271193326Sed void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 272193326Sed 273193326Sed /// getNumBases - Retrieves the number of base classes of this 274193326Sed /// class. 275193326Sed unsigned getNumBases() const { return NumBases; } 276193326Sed 277193326Sed base_class_iterator bases_begin() { return Bases; } 278193326Sed base_class_const_iterator bases_begin() const { return Bases; } 279193326Sed base_class_iterator bases_end() { return Bases + NumBases; } 280193326Sed base_class_const_iterator bases_end() const { return Bases + NumBases; } 281193326Sed 282193326Sed /// hasConstCopyConstructor - Determines whether this class has a 283193326Sed /// copy constructor that accepts a const-qualified argument. 284193326Sed bool hasConstCopyConstructor(ASTContext &Context) const; 285193326Sed 286193326Sed /// hasConstCopyAssignment - Determines whether this class has a 287193326Sed /// copy assignment operator that accepts a const-qualified argument. 288193326Sed bool hasConstCopyAssignment(ASTContext &Context) const; 289193326Sed 290193326Sed /// addedConstructor - Notify the class that another constructor has 291193326Sed /// been added. This routine helps maintain information about the 292193326Sed /// class based on which constructors have been added. 293193326Sed void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 294193326Sed 295193326Sed /// hasUserDeclaredConstructor - Whether this class has any 296193326Sed /// user-declared constructors. When true, a default constructor 297193326Sed /// will not be implicitly declared. 298193326Sed bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; } 299193326Sed 300193326Sed /// hasUserDeclaredCopyConstructor - Whether this class has a 301193326Sed /// user-declared copy constructor. When false, a copy constructor 302193326Sed /// will be implicitly declared. 303193326Sed bool hasUserDeclaredCopyConstructor() const { 304193326Sed return UserDeclaredCopyConstructor; 305193326Sed } 306193326Sed 307193326Sed /// addedAssignmentOperator - Notify the class that another assignment 308193326Sed /// operator has been added. This routine helps maintain information about the 309193326Sed /// class based on which operators have been added. 310193326Sed void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 311193326Sed 312193326Sed /// hasUserDeclaredCopyAssignment - Whether this class has a 313193326Sed /// user-declared copy assignment operator. When false, a copy 314193326Sed /// assigment operator will be implicitly declared. 315193326Sed bool hasUserDeclaredCopyAssignment() const { 316193326Sed return UserDeclaredCopyAssignment; 317193326Sed } 318193326Sed 319193326Sed /// hasUserDeclaredDestructor - Whether this class has a 320193326Sed /// user-declared destructor. When false, a destructor will be 321193326Sed /// implicitly declared. 322193326Sed bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 323193326Sed 324193326Sed /// setUserDeclaredDestructor - Set whether this class has a 325193326Sed /// user-declared destructor. If not set by the time the class is 326193326Sed /// fully defined, a destructor will be implicitly declared. 327193326Sed void setUserDeclaredDestructor(bool UCD) { 328193326Sed UserDeclaredDestructor = UCD; 329193326Sed } 330193326Sed 331193326Sed /// getConversions - Retrieve the overload set containing all of the 332193326Sed /// conversion functions in this class. 333193326Sed OverloadedFunctionDecl *getConversionFunctions() { 334193326Sed return &Conversions; 335193326Sed } 336193326Sed const OverloadedFunctionDecl *getConversionFunctions() const { 337193326Sed return &Conversions; 338193326Sed } 339193326Sed 340193326Sed /// addConversionFunction - Add a new conversion function to the 341193326Sed /// list of conversion functions. 342193326Sed void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl); 343193326Sed 344193326Sed /// isAggregate - Whether this class is an aggregate (C++ 345193326Sed /// [dcl.init.aggr]), which is a class with no user-declared 346193326Sed /// constructors, no private or protected non-static data members, 347193326Sed /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 348193326Sed bool isAggregate() const { return Aggregate; } 349193326Sed 350193326Sed /// setAggregate - Set whether this class is an aggregate (C++ 351193326Sed /// [dcl.init.aggr]). 352193326Sed void setAggregate(bool Agg) { Aggregate = Agg; } 353193326Sed 354193326Sed /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 355193326Sed /// that is an aggregate that has no non-static non-POD data members, no 356193326Sed /// reference data members, no user-defined copy assignment operator and no 357193326Sed /// user-defined destructor. 358193326Sed bool isPOD() const { return PlainOldData; } 359193326Sed 360193326Sed /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 361193326Sed void setPOD(bool POD) { PlainOldData = POD; } 362193326Sed 363193326Sed /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 364193326Sed /// which means that the class contains or inherits a virtual function. 365193326Sed bool isPolymorphic() const { return Polymorphic; } 366193326Sed 367193326Sed /// setPolymorphic - Set whether this class is polymorphic (C++ 368193326Sed /// [class.virtual]). 369193326Sed void setPolymorphic(bool Poly) { Polymorphic = Poly; } 370193326Sed 371193326Sed /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 372193326Sed /// which means that the class contains or inherits a pure virtual function. 373193326Sed bool isAbstract() const { return Abstract; } 374193326Sed 375193326Sed /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 376193326Sed void setAbstract(bool Abs) { Abstract = Abs; } 377193326Sed 378193326Sed // hasTrivialConstructor - Whether this class has a trivial constructor 379193326Sed // (C++ [class.ctor]p5) 380193326Sed bool hasTrivialConstructor() const { return HasTrivialConstructor; } 381193326Sed 382193326Sed // setHasTrivialConstructor - Set whether this class has a trivial constructor 383193326Sed // (C++ [class.ctor]p5) 384193326Sed void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 385193326Sed 386193326Sed // hasTrivialDestructor - Whether this class has a trivial destructor 387193326Sed // (C++ [class.dtor]p3) 388193326Sed bool hasTrivialDestructor() const { return HasTrivialDestructor; } 389193326Sed 390193326Sed // setHasTrivialDestructor - Set whether this class has a trivial destructor 391193326Sed // (C++ [class.dtor]p3) 392193326Sed void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 393193326Sed 394193326Sed /// \brief If this record is an instantiation of a member class, 395193326Sed /// retrieves the member class from which it was instantiated. 396193326Sed /// 397193326Sed /// This routine will return non-NULL for (non-templated) member 398193326Sed /// classes of class templates. For example, given: 399193326Sed /// 400193326Sed /// \code 401193326Sed /// template<typename T> 402193326Sed /// struct X { 403193326Sed /// struct A { }; 404193326Sed /// }; 405193326Sed /// \endcode 406193326Sed /// 407193326Sed /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 408193326Sed /// whose parent is the class template specialization X<int>. For 409193326Sed /// this declaration, getInstantiatedFromMemberClass() will return 410193326Sed /// the CXXRecordDecl X<T>::A. When a complete definition of 411193326Sed /// X<int>::A is required, it will be instantiated from the 412193326Sed /// declaration returned by getInstantiatedFromMemberClass(). 413193326Sed CXXRecordDecl *getInstantiatedFromMemberClass() const { 414193326Sed return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>(); 415193326Sed } 416193326Sed 417193326Sed /// \brief Specify that this record is an instantiation of the 418193326Sed /// member class RD. 419193326Sed void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 420193326Sed TemplateOrInstantiation = RD; 421193326Sed } 422193326Sed 423193326Sed /// \brief Retrieves the class template that is described by this 424193326Sed /// class declaration. 425193326Sed /// 426193326Sed /// Every class template is represented as a ClassTemplateDecl and a 427193326Sed /// CXXRecordDecl. The former contains template properties (such as 428193326Sed /// the template parameter lists) while the latter contains the 429193326Sed /// actual description of the template's 430193326Sed /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 431193326Sed /// CXXRecordDecl that from a ClassTemplateDecl, while 432193326Sed /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 433193326Sed /// a CXXRecordDecl. 434193326Sed ClassTemplateDecl *getDescribedClassTemplate() const { 435193326Sed return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 436193326Sed } 437193326Sed 438193326Sed void setDescribedClassTemplate(ClassTemplateDecl *Template) { 439193326Sed TemplateOrInstantiation = Template; 440193326Sed } 441193326Sed 442194613Sed /// getDefaultConstructor - Returns the default constructor for this class 443194613Sed CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 444194613Sed 445193326Sed /// getDestructor - Returns the destructor decl for this class. 446193326Sed const CXXDestructorDecl *getDestructor(ASTContext &Context); 447193326Sed 448193326Sed /// viewInheritance - Renders and displays an inheritance diagram 449193326Sed /// for this C++ class and all of its base classes (transitively) using 450193326Sed /// GraphViz. 451193326Sed void viewInheritance(ASTContext& Context) const; 452193326Sed 453193326Sed static bool classof(const Decl *D) { 454193326Sed return D->getKind() == CXXRecord || 455193326Sed D->getKind() == ClassTemplateSpecialization || 456193326Sed D->getKind() == ClassTemplatePartialSpecialization; 457193326Sed } 458193326Sed static bool classof(const CXXRecordDecl *D) { return true; } 459193326Sed static bool classof(const ClassTemplateSpecializationDecl *D) { 460193326Sed return true; 461193326Sed } 462193326Sed}; 463193326Sed 464193326Sed/// CXXMethodDecl - Represents a static or instance method of a 465193326Sed/// struct/union/class. 466193326Sedclass CXXMethodDecl : public FunctionDecl { 467193326Sedprotected: 468193326Sed CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 469193326Sed DeclarationName N, QualType T, 470193326Sed bool isStatic, bool isInline) 471193326Sed : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None), 472193326Sed isInline) {} 473193326Sed 474193326Sedpublic: 475193326Sed static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 476193326Sed SourceLocation L, DeclarationName N, 477193326Sed QualType T, bool isStatic = false, 478193326Sed bool isInline = false); 479193326Sed 480193326Sed bool isStatic() const { return getStorageClass() == Static; } 481193326Sed bool isInstance() const { return !isStatic(); } 482193326Sed 483193326Sed bool isVirtual() const { 484193326Sed return isVirtualAsWritten() || 485193326Sed (begin_overridden_methods() != end_overridden_methods()); 486193326Sed } 487193326Sed 488193326Sed /// 489193326Sed void addOverriddenMethod(const CXXMethodDecl *MD); 490193326Sed 491193326Sed typedef const CXXMethodDecl ** method_iterator; 492193326Sed 493193326Sed method_iterator begin_overridden_methods() const; 494193326Sed method_iterator end_overridden_methods() const; 495193326Sed 496193326Sed /// getParent - Returns the parent of this method declaration, which 497193326Sed /// is the class in which this method is defined. 498193326Sed const CXXRecordDecl *getParent() const { 499193326Sed return cast<CXXRecordDecl>(FunctionDecl::getParent()); 500193326Sed } 501193326Sed 502193326Sed /// getParent - Returns the parent of this method declaration, which 503193326Sed /// is the class in which this method is defined. 504193326Sed CXXRecordDecl *getParent() { 505193326Sed return const_cast<CXXRecordDecl *>( 506193326Sed cast<CXXRecordDecl>(FunctionDecl::getParent())); 507193326Sed } 508193326Sed 509193326Sed /// getThisType - Returns the type of 'this' pointer. 510193326Sed /// Should only be called for instance methods. 511193326Sed QualType getThisType(ASTContext &C) const; 512193326Sed 513193326Sed unsigned getTypeQualifiers() const { 514193326Sed return getType()->getAsFunctionProtoType()->getTypeQuals(); 515193326Sed } 516193326Sed 517193326Sed // Implement isa/cast/dyncast/etc. 518193326Sed static bool classof(const Decl *D) { 519193326Sed return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 520193326Sed } 521193326Sed static bool classof(const CXXMethodDecl *D) { return true; } 522193326Sed}; 523193326Sed 524193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member 525193326Sed/// initializer, which is part of a constructor initializer that 526193326Sed/// initializes one non-static member variable or one base class. For 527193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 528193326Sed/// initializers: 529193326Sed/// 530193326Sed/// @code 531193326Sed/// class A { }; 532193326Sed/// class B : public A { 533193326Sed/// float f; 534193326Sed/// public: 535193326Sed/// B(A& a) : A(a), f(3.14159) { } 536193326Sed/// }; 537194613Sed/// @endcode 538193326Sedclass CXXBaseOrMemberInitializer { 539193326Sed /// BaseOrMember - This points to the entity being initialized, 540193326Sed /// which is either a base class (a Type) or a non-static data 541193326Sed /// member. When the low bit is 1, it's a base 542193326Sed /// class; when the low bit is 0, it's a member. 543193326Sed uintptr_t BaseOrMember; 544193326Sed 545193326Sed /// Args - The arguments used to initialize the base or member. 546193326Sed Expr **Args; 547193326Sed unsigned NumArgs; 548193326Sed 549193326Sedpublic: 550193326Sed /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 551193326Sed explicit 552193326Sed CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs); 553193326Sed 554193326Sed /// CXXBaseOrMemberInitializer - Creates a new member initializer. 555193326Sed explicit 556193326Sed CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs); 557193326Sed 558193326Sed /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer. 559193326Sed ~CXXBaseOrMemberInitializer(); 560193326Sed 561193326Sed /// arg_iterator - Iterates through the member initialization 562193326Sed /// arguments. 563193326Sed typedef Expr **arg_iterator; 564193326Sed 565193326Sed /// arg_const_iterator - Iterates through the member initialization 566193326Sed /// arguments. 567193326Sed typedef Expr * const * arg_const_iterator; 568193326Sed 569193326Sed /// isBaseInitializer - Returns true when this initializer is 570193326Sed /// initializing a base class. 571193326Sed bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; } 572193326Sed 573193326Sed /// isMemberInitializer - Returns true when this initializer is 574193326Sed /// initializing a non-static data member. 575193326Sed bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; } 576193326Sed 577193326Sed /// getBaseClass - If this is a base class initializer, returns the 578193326Sed /// type used to specify the initializer. The resulting type will be 579193326Sed /// a class type or a typedef of a class type. If this is not a base 580193326Sed /// class initializer, returns NULL. 581193326Sed Type *getBaseClass() { 582193326Sed if (isBaseInitializer()) 583193326Sed return reinterpret_cast<Type*>(BaseOrMember & ~0x01); 584193326Sed else 585193326Sed return 0; 586193326Sed } 587193326Sed 588193326Sed /// getBaseClass - If this is a base class initializer, returns the 589193326Sed /// type used to specify the initializer. The resulting type will be 590193326Sed /// a class type or a typedef of a class type. If this is not a base 591193326Sed /// class initializer, returns NULL. 592193326Sed const Type *getBaseClass() const { 593193326Sed if (isBaseInitializer()) 594193326Sed return reinterpret_cast<const Type*>(BaseOrMember & ~0x01); 595193326Sed else 596193326Sed return 0; 597193326Sed } 598193326Sed 599193326Sed /// getMember - If this is a member initializer, returns the 600193326Sed /// declaration of the non-static data member being 601193326Sed /// initialized. Otherwise, returns NULL. 602193326Sed FieldDecl *getMember() { 603193326Sed if (isMemberInitializer()) 604193326Sed return reinterpret_cast<FieldDecl *>(BaseOrMember); 605193326Sed else 606193326Sed return 0; 607193326Sed } 608193326Sed 609193326Sed /// begin() - Retrieve an iterator to the first initializer argument. 610193326Sed arg_iterator begin() { return Args; } 611193326Sed /// begin() - Retrieve an iterator to the first initializer argument. 612193326Sed arg_const_iterator begin() const { return Args; } 613193326Sed 614193326Sed /// end() - Retrieve an iterator past the last initializer argument. 615193326Sed arg_iterator end() { return Args + NumArgs; } 616193326Sed /// end() - Retrieve an iterator past the last initializer argument. 617193326Sed arg_const_iterator end() const { return Args + NumArgs; } 618193326Sed 619193326Sed /// getNumArgs - Determine the number of arguments used to 620193326Sed /// initialize the member or base. 621193326Sed unsigned getNumArgs() const { return NumArgs; } 622193326Sed}; 623193326Sed 624193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a 625193326Sed/// class. For example: 626193326Sed/// 627193326Sed/// @code 628193326Sed/// class X { 629193326Sed/// public: 630193326Sed/// explicit X(int); // represented by a CXXConstructorDecl. 631193326Sed/// }; 632193326Sed/// @endcode 633193326Sedclass CXXConstructorDecl : public CXXMethodDecl { 634193326Sed /// Explicit - Whether this constructor is explicit. 635193326Sed bool Explicit : 1; 636193326Sed 637193326Sed /// ImplicitlyDefined - Whether this constructor was implicitly 638193326Sed /// defined by the compiler. When false, the constructor was defined 639193326Sed /// by the user. In C++03, this flag will have the same value as 640193326Sed /// Implicit. In C++0x, however, a constructor that is 641193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 642193326Sed /// @c !Implicit && ImplicitlyDefined. 643193326Sed bool ImplicitlyDefined : 1; 644194613Sed 645194613Sed /// ImplicitMustBeDefined - Implicit constructor was used to create an 646194613Sed /// object of its class type. It must be defined. 647194613Sed bool ImplicitMustBeDefined : 1; 648193326Sed 649193326Sed /// FIXME: Add support for base and member initializers. 650193326Sed 651193326Sed CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 652193326Sed DeclarationName N, QualType T, 653193326Sed bool isExplicit, bool isInline, bool isImplicitlyDeclared) 654193326Sed : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline), 655194613Sed Explicit(isExplicit), ImplicitlyDefined(false), 656194613Sed ImplicitMustBeDefined(false) { 657193326Sed setImplicit(isImplicitlyDeclared); 658193326Sed } 659193326Sed 660193326Sedpublic: 661193326Sed static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 662193326Sed SourceLocation L, DeclarationName N, 663193326Sed QualType T, bool isExplicit, 664193326Sed bool isInline, bool isImplicitlyDeclared); 665193326Sed 666193326Sed /// isExplicit - Whether this constructor was marked "explicit" or not. 667193326Sed bool isExplicit() const { return Explicit; } 668193326Sed 669193326Sed /// isImplicitlyDefined - Whether this constructor was implicitly 670193326Sed /// defined. If false, then this constructor was defined by the 671193326Sed /// user. This operation can only be invoked if the constructor has 672193326Sed /// already been defined. 673193326Sed bool isImplicitlyDefined(ASTContext &C) const { 674193326Sed assert(isThisDeclarationADefinition() && 675193326Sed "Can only get the implicit-definition flag once the constructor has been defined"); 676193326Sed return ImplicitlyDefined; 677193326Sed } 678193326Sed 679193326Sed /// setImplicitlyDefined - Set whether this constructor was 680193326Sed /// implicitly defined or not. 681193326Sed void setImplicitlyDefined(bool ID) { 682193326Sed assert(isThisDeclarationADefinition() && 683193326Sed "Can only set the implicit-definition flag once the constructor has been defined"); 684193326Sed ImplicitlyDefined = ID; 685193326Sed } 686193326Sed 687194613Sed /// isImplicitMustBeDefined - Whether a definition must be synthesized for 688194613Sed /// the implicit constructor. 689194613Sed bool isImplicitMustBeDefined() const { 690194613Sed return isImplicit() && ImplicitMustBeDefined; 691194613Sed } 692194613Sed 693194613Sed /// setImplicitMustBeDefined - constructor must be implicitly defined. 694194613Sed void setImplicitMustBeDefined() { 695194613Sed ImplicitMustBeDefined = true; 696194613Sed } 697194613Sed 698193326Sed /// isDefaultConstructor - Whether this constructor is a default 699193326Sed /// constructor (C++ [class.ctor]p5), which can be used to 700193326Sed /// default-initialize a class of this type. 701193326Sed bool isDefaultConstructor() const; 702193326Sed 703193326Sed /// isCopyConstructor - Whether this constructor is a copy 704193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 705193326Sed /// class. @p TypeQuals will be set to the qualifiers on the 706193326Sed /// argument type. For example, @p TypeQuals would be set to @c 707193326Sed /// QualType::Const for the following copy constructor: 708193326Sed /// 709193326Sed /// @code 710193326Sed /// class X { 711193326Sed /// public: 712193326Sed /// X(const X&); 713193326Sed /// }; 714193326Sed /// @endcode 715193326Sed bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 716193326Sed 717193326Sed /// isCopyConstructor - Whether this constructor is a copy 718193326Sed /// constructor (C++ [class.copy]p2, which can be used to copy the 719193326Sed /// class. 720193326Sed bool isCopyConstructor(ASTContext &Context) const { 721193326Sed unsigned TypeQuals = 0; 722193326Sed return isCopyConstructor(Context, TypeQuals); 723193326Sed } 724193326Sed 725193326Sed /// isConvertingConstructor - Whether this constructor is a 726193326Sed /// converting constructor (C++ [class.conv.ctor]), which can be 727193326Sed /// used for user-defined conversions. 728193326Sed bool isConvertingConstructor() const; 729193326Sed 730193326Sed // Implement isa/cast/dyncast/etc. 731193326Sed static bool classof(const Decl *D) { 732193326Sed return D->getKind() == CXXConstructor; 733193326Sed } 734193326Sed static bool classof(const CXXConstructorDecl *D) { return true; } 735193326Sed}; 736193326Sed 737193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a 738193326Sed/// class. For example: 739193326Sed/// 740193326Sed/// @code 741193326Sed/// class X { 742193326Sed/// public: 743193326Sed/// ~X(); // represented by a CXXDestructorDecl. 744193326Sed/// }; 745193326Sed/// @endcode 746193326Sedclass CXXDestructorDecl : public CXXMethodDecl { 747193326Sed /// ImplicitlyDefined - Whether this destructor was implicitly 748193326Sed /// defined by the compiler. When false, the destructor was defined 749193326Sed /// by the user. In C++03, this flag will have the same value as 750193326Sed /// Implicit. In C++0x, however, a destructor that is 751193326Sed /// explicitly defaulted (i.e., defined with " = default") will have 752193326Sed /// @c !Implicit && ImplicitlyDefined. 753193326Sed bool ImplicitlyDefined : 1; 754193326Sed 755193326Sed CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 756193326Sed DeclarationName N, QualType T, 757193326Sed bool isInline, bool isImplicitlyDeclared) 758193326Sed : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline), 759193326Sed ImplicitlyDefined(false) { 760193326Sed setImplicit(isImplicitlyDeclared); 761193326Sed } 762193326Sed 763193326Sedpublic: 764193326Sed static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 765193326Sed SourceLocation L, DeclarationName N, 766193326Sed QualType T, bool isInline, 767193326Sed bool isImplicitlyDeclared); 768193326Sed 769193326Sed /// isImplicitlyDefined - Whether this destructor was implicitly 770193326Sed /// defined. If false, then this destructor was defined by the 771193326Sed /// user. This operation can only be invoked if the destructor has 772193326Sed /// already been defined. 773193326Sed bool isImplicitlyDefined() const { 774193326Sed assert(isThisDeclarationADefinition() && 775193326Sed "Can only get the implicit-definition flag once the destructor has been defined"); 776193326Sed return ImplicitlyDefined; 777193326Sed } 778193326Sed 779193326Sed /// setImplicitlyDefined - Set whether this destructor was 780193326Sed /// implicitly defined or not. 781193326Sed void setImplicitlyDefined(bool ID) { 782193326Sed assert(isThisDeclarationADefinition() && 783193326Sed "Can only set the implicit-definition flag once the destructor has been defined"); 784193326Sed ImplicitlyDefined = ID; 785193326Sed } 786193326Sed 787193326Sed // Implement isa/cast/dyncast/etc. 788193326Sed static bool classof(const Decl *D) { 789193326Sed return D->getKind() == CXXDestructor; 790193326Sed } 791193326Sed static bool classof(const CXXDestructorDecl *D) { return true; } 792193326Sed}; 793193326Sed 794193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a 795193326Sed/// class. For example: 796193326Sed/// 797193326Sed/// @code 798193326Sed/// class X { 799193326Sed/// public: 800193326Sed/// operator bool(); 801193326Sed/// }; 802193326Sed/// @endcode 803193326Sedclass CXXConversionDecl : public CXXMethodDecl { 804193326Sed /// Explicit - Whether this conversion function is marked 805193326Sed /// "explicit", meaning that it can only be applied when the user 806193326Sed /// explicitly wrote a cast. This is a C++0x feature. 807193326Sed bool Explicit : 1; 808193326Sed 809193326Sed CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 810193326Sed DeclarationName N, QualType T, 811193326Sed bool isInline, bool isExplicit) 812193326Sed : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline), 813193326Sed Explicit(isExplicit) { } 814193326Sed 815193326Sedpublic: 816193326Sed static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 817193326Sed SourceLocation L, DeclarationName N, 818193326Sed QualType T, bool isInline, 819193326Sed bool isExplicit); 820193326Sed 821193326Sed /// isExplicit - Whether this is an explicit conversion operator 822193326Sed /// (C++0x only). Explicit conversion operators are only considered 823193326Sed /// when the user has explicitly written a cast. 824193326Sed bool isExplicit() const { return Explicit; } 825193326Sed 826193326Sed /// getConversionType - Returns the type that this conversion 827193326Sed /// function is converting to. 828193326Sed QualType getConversionType() const { 829193326Sed return getType()->getAsFunctionType()->getResultType(); 830193326Sed } 831193326Sed 832193326Sed // Implement isa/cast/dyncast/etc. 833193326Sed static bool classof(const Decl *D) { 834193326Sed return D->getKind() == CXXConversion; 835193326Sed } 836193326Sed static bool classof(const CXXConversionDecl *D) { return true; } 837193326Sed}; 838193326Sed 839193326Sed/// LinkageSpecDecl - This represents a linkage specification. For example: 840193326Sed/// extern "C" void foo(); 841193326Sed/// 842193326Sedclass LinkageSpecDecl : public Decl, public DeclContext { 843193326Sedpublic: 844193326Sed /// LanguageIDs - Used to represent the language in a linkage 845193326Sed /// specification. The values are part of the serialization abi for 846193326Sed /// ASTs and cannot be changed without altering that abi. To help 847193326Sed /// ensure a stable abi for this, we choose the DW_LANG_ encodings 848193326Sed /// from the dwarf standard. 849193326Sed enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 850193326Sed lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 851193326Sedprivate: 852193326Sed /// Language - The language for this linkage specification. 853193326Sed LanguageIDs Language; 854193326Sed 855193326Sed /// HadBraces - Whether this linkage specification had curly braces or not. 856193326Sed bool HadBraces : 1; 857193326Sed 858193326Sed LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 859193326Sed bool Braces) 860193326Sed : Decl(LinkageSpec, DC, L), 861193326Sed DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 862193326Sed 863193326Sedpublic: 864193326Sed static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 865193326Sed SourceLocation L, LanguageIDs Lang, 866193326Sed bool Braces); 867193326Sed 868193326Sed LanguageIDs getLanguage() const { return Language; } 869193326Sed 870193326Sed /// hasBraces - Determines whether this linkage specification had 871193326Sed /// braces in its syntactic form. 872193326Sed bool hasBraces() const { return HadBraces; } 873193326Sed 874193326Sed static bool classof(const Decl *D) { 875193326Sed return D->getKind() == LinkageSpec; 876193326Sed } 877193326Sed static bool classof(const LinkageSpecDecl *D) { return true; } 878193326Sed static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 879193326Sed return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 880193326Sed } 881193326Sed static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 882193326Sed return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 883193326Sed } 884193326Sed}; 885193326Sed 886193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example: 887193326Sed/// 888193326Sed/// using namespace std; 889193326Sed/// 890193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 891193326Sed// artificial name, for all using-directives in order to store 892193326Sed// them in DeclContext effectively. 893193326Sedclass UsingDirectiveDecl : public NamedDecl { 894193326Sed 895193326Sed /// SourceLocation - Location of 'namespace' token. 896193326Sed SourceLocation NamespaceLoc; 897193326Sed 898193326Sed /// \brief The source range that covers the nested-name-specifier 899193326Sed /// preceding the namespace name. 900193326Sed SourceRange QualifierRange; 901193326Sed 902193326Sed /// \brief The nested-name-specifier that precedes the namespace 903193326Sed /// name, if any. 904193326Sed NestedNameSpecifier *Qualifier; 905193326Sed 906193326Sed /// IdentLoc - Location of nominated namespace-name identifier. 907193326Sed // FIXME: We don't store location of scope specifier. 908193326Sed SourceLocation IdentLoc; 909193326Sed 910193326Sed /// NominatedNamespace - Namespace nominated by using-directive. 911193326Sed NamespaceDecl *NominatedNamespace; 912193326Sed 913193326Sed /// Enclosing context containing both using-directive and nomintated 914193326Sed /// namespace. 915193326Sed DeclContext *CommonAncestor; 916193326Sed 917193326Sed /// getUsingDirectiveName - Returns special DeclarationName used by 918193326Sed /// using-directives. This is only used by DeclContext for storing 919193326Sed /// UsingDirectiveDecls in its lookup structure. 920193326Sed static DeclarationName getName() { 921193326Sed return DeclarationName::getUsingDirectiveName(); 922193326Sed } 923193326Sed 924193326Sed UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 925193326Sed SourceLocation NamespcLoc, 926193326Sed SourceRange QualifierRange, 927193326Sed NestedNameSpecifier *Qualifier, 928193326Sed SourceLocation IdentLoc, 929193326Sed NamespaceDecl *Nominated, 930193326Sed DeclContext *CommonAncestor) 931193326Sed : NamedDecl(Decl::UsingDirective, DC, L, getName()), 932193326Sed NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 933193326Sed Qualifier(Qualifier), IdentLoc(IdentLoc), 934193326Sed NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0), 935193326Sed CommonAncestor(CommonAncestor) { 936193326Sed } 937193326Sed 938193326Sedpublic: 939193326Sed /// \brief Retrieve the source range of the nested-name-specifier 940193326Sed /// that qualifiers the namespace name. 941193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 942193326Sed 943193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 944193326Sed /// name of the namespace. 945193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 946193326Sed 947193326Sed /// getNominatedNamespace - Returns namespace nominated by using-directive. 948193326Sed NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; } 949193326Sed 950193326Sed const NamespaceDecl *getNominatedNamespace() const { 951193326Sed return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 952193326Sed } 953193326Sed 954193326Sed /// getCommonAncestor - returns common ancestor context of using-directive, 955193326Sed /// and nominated by it namespace. 956193326Sed DeclContext *getCommonAncestor() { return CommonAncestor; } 957193326Sed const DeclContext *getCommonAncestor() const { return CommonAncestor; } 958193326Sed 959193326Sed /// getNamespaceKeyLocation - Returns location of namespace keyword. 960193326Sed SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 961193326Sed 962193326Sed /// getIdentLocation - Returns location of identifier. 963193326Sed SourceLocation getIdentLocation() const { return IdentLoc; } 964193326Sed 965193326Sed static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 966193326Sed SourceLocation L, 967193326Sed SourceLocation NamespaceLoc, 968193326Sed SourceRange QualifierRange, 969193326Sed NestedNameSpecifier *Qualifier, 970193326Sed SourceLocation IdentLoc, 971193326Sed NamespaceDecl *Nominated, 972193326Sed DeclContext *CommonAncestor); 973193326Sed 974193326Sed static bool classof(const Decl *D) { 975193326Sed return D->getKind() == Decl::UsingDirective; 976193326Sed } 977193326Sed static bool classof(const UsingDirectiveDecl *D) { return true; } 978193326Sed 979193326Sed // Friend for getUsingDirectiveName. 980193326Sed friend class DeclContext; 981193326Sed}; 982193326Sed 983193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 984193326Sed/// 985193326Sed/// @code 986193326Sed/// namespace Foo = Bar; 987193326Sed/// @endcode 988193326Sedclass NamespaceAliasDecl : public NamedDecl { 989193326Sed SourceLocation AliasLoc; 990193326Sed 991193326Sed /// \brief The source range that covers the nested-name-specifier 992193326Sed /// preceding the namespace name. 993193326Sed SourceRange QualifierRange; 994193326Sed 995193326Sed /// \brief The nested-name-specifier that precedes the namespace 996193326Sed /// name, if any. 997193326Sed NestedNameSpecifier *Qualifier; 998193326Sed 999193326Sed /// IdentLoc - Location of namespace identifier. 1000193326Sed SourceLocation IdentLoc; 1001193326Sed 1002193326Sed /// Namespace - The Decl that this alias points to. Can either be a 1003193326Sed /// NamespaceDecl or a NamespaceAliasDecl. 1004193326Sed NamedDecl *Namespace; 1005193326Sed 1006193326Sed NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1007193326Sed SourceLocation AliasLoc, IdentifierInfo *Alias, 1008193326Sed SourceRange QualifierRange, 1009193326Sed NestedNameSpecifier *Qualifier, 1010193326Sed SourceLocation IdentLoc, NamedDecl *Namespace) 1011193326Sed : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1012193326Sed QualifierRange(QualifierRange), Qualifier(Qualifier), 1013193326Sed IdentLoc(IdentLoc), Namespace(Namespace) { } 1014193326Sed 1015193326Sedpublic: 1016193326Sed /// \brief Retrieve the source range of the nested-name-specifier 1017193326Sed /// that qualifiers the namespace name. 1018193326Sed SourceRange getQualifierRange() const { return QualifierRange; } 1019193326Sed 1020193326Sed /// \brief Retrieve the nested-name-specifier that qualifies the 1021193326Sed /// name of the namespace. 1022193326Sed NestedNameSpecifier *getQualifier() const { return Qualifier; } 1023193326Sed 1024193326Sed NamespaceDecl *getNamespace() { 1025193326Sed if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1026193326Sed return AD->getNamespace(); 1027193326Sed 1028193326Sed return cast<NamespaceDecl>(Namespace); 1029193326Sed } 1030193326Sed 1031193326Sed const NamespaceDecl *getNamespace() const { 1032193326Sed return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1033193326Sed } 1034193326Sed 1035193326Sed /// \brief Retrieve the namespace that this alias refers to, which 1036193326Sed /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1037193326Sed NamedDecl *getAliasedNamespace() const { return Namespace; } 1038193326Sed 1039193326Sed static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1040193326Sed SourceLocation L, SourceLocation AliasLoc, 1041193326Sed IdentifierInfo *Alias, 1042193326Sed SourceRange QualifierRange, 1043193326Sed NestedNameSpecifier *Qualifier, 1044193326Sed SourceLocation IdentLoc, 1045193326Sed NamedDecl *Namespace); 1046193326Sed 1047193326Sed static bool classof(const Decl *D) { 1048193326Sed return D->getKind() == Decl::NamespaceAlias; 1049193326Sed } 1050193326Sed static bool classof(const NamespaceAliasDecl *D) { return true; } 1051193326Sed}; 1052194613Sed 1053194613Sed/// UsingDecl - Represents a C++ using-declaration. For example: 1054194613Sed/// using someNameSpace::someIdentifier; 1055194613Sedclass UsingDecl : public NamedDecl { 1056194613Sed 1057194613Sed /// \brief The source range that covers the nested-name-specifier 1058194613Sed /// preceding the declaration name. 1059194613Sed SourceRange NestedNameRange; 1060194613Sed /// \brief The source location of the target declaration name. 1061194613Sed SourceLocation TargetNameLocation; 1062194613Sed /// \brief The source location of the "using" location itself. 1063194613Sed SourceLocation UsingLocation; 1064194613Sed /// \brief Target declaration. 1065194613Sed NamedDecl* TargetDecl; 1066194613Sed /// \brief Target declaration. 1067194613Sed NestedNameSpecifier* TargetNestedNameDecl; 1068194613Sed 1069194613Sed // Had 'typename' keyword. 1070194613Sed bool IsTypeName; 1071194613Sed 1072194613Sed UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1073194613Sed SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target, 1074194613Sed NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) 1075194613Sed : NamedDecl(Decl::Using, DC, L, Target->getDeclName()), 1076194613Sed NestedNameRange(NNR), TargetNameLocation(TargetNL), 1077194613Sed UsingLocation(UL), TargetDecl(Target), 1078194613Sed TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { 1079194613Sed this->IdentifierNamespace = TargetDecl->getIdentifierNamespace(); 1080194613Sed } 1081194613Sed 1082194613Sedpublic: 1083194613Sed /// \brief Returns the source range that covers the nested-name-specifier 1084194613Sed /// preceding the namespace name. 1085194613Sed SourceRange getNestedNameRange() { return(NestedNameRange); } 1086194613Sed /// \brief Returns the source location of the target declaration name. 1087194613Sed SourceLocation getTargetNameLocation() { return(TargetNameLocation); } 1088194613Sed /// \brief Returns the source location of the "using" location itself. 1089194613Sed SourceLocation getUsingLocation() { return(UsingLocation); } 1090194613Sed /// \brief getTargetDecl - Returns target specified by using-decl. 1091194613Sed NamedDecl *getTargetDecl() { return(TargetDecl); } 1092194613Sed /// \brief Get target nested name declaration. 1093194613Sed NestedNameSpecifier* getTargetNestedNameDecl() { return(TargetNestedNameDecl); } 1094194613Sed /// isTypeName - Return true if using decl had 'typename'. 1095194613Sed bool isTypeName() const { return(IsTypeName); } 1096194613Sed 1097194613Sed static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1098194613Sed SourceLocation L, SourceRange NNR, SourceLocation TargetNL, 1099194613Sed SourceLocation UL, NamedDecl* Target, 1100194613Sed NestedNameSpecifier* TargetNNS, bool IsTypeNameArg); 1101194613Sed 1102194613Sed static bool classof(const Decl *D) { 1103194613Sed return D->getKind() == Decl::Using; 1104194613Sed } 1105194613Sed static bool classof(const UsingDecl *D) { return true; } 1106194613Sed}; 1107193326Sed 1108193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1109193326Sedclass StaticAssertDecl : public Decl { 1110193326Sed Expr *AssertExpr; 1111193326Sed StringLiteral *Message; 1112193326Sed 1113193326Sed StaticAssertDecl(DeclContext *DC, SourceLocation L, 1114193326Sed Expr *assertexpr, StringLiteral *message) 1115193326Sed : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1116193326Sed 1117193326Sedpublic: 1118193326Sed static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1119193326Sed SourceLocation L, Expr *AssertExpr, 1120193326Sed StringLiteral *Message); 1121193326Sed 1122193326Sed Expr *getAssertExpr() { return AssertExpr; } 1123193326Sed const Expr *getAssertExpr() const { return AssertExpr; } 1124193326Sed 1125193326Sed StringLiteral *getMessage() { return Message; } 1126193326Sed const StringLiteral *getMessage() const { return Message; } 1127193326Sed 1128193326Sed virtual ~StaticAssertDecl(); 1129193326Sed virtual void Destroy(ASTContext& C); 1130193326Sed 1131193326Sed static bool classof(const Decl *D) { 1132193326Sed return D->getKind() == Decl::StaticAssert; 1133193326Sed } 1134193326Sed static bool classof(StaticAssertDecl *D) { return true; } 1135193326Sed}; 1136193326Sed 1137193326Sed/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1138193326Sed/// into a diagnostic with <<. 1139193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1140193326Sed AccessSpecifier AS); 1141193326Sed 1142193326Sed} // end namespace clang 1143193326Sed 1144193326Sed#endif 1145