DeclCXX.h revision 1e68ecc4fcce12f683c4fd38acfd1a004001b04f
1//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the C++ Decl subclasses, other than those for 11// templates (in DeclTemplate.h) and friends (in DeclFriend.h). 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_AST_DECLCXX_H 16#define LLVM_CLANG_AST_DECLCXX_H 17 18#include "clang/AST/Expr.h" 19#include "clang/AST/Decl.h" 20#include "clang/AST/TypeLoc.h" 21#include "clang/AST/UnresolvedSet.h" 22#include "llvm/ADT/SmallPtrSet.h" 23 24namespace clang { 25 26class ClassTemplateDecl; 27class ClassTemplateSpecializationDecl; 28class CXXBasePath; 29class CXXBasePaths; 30class CXXConstructorDecl; 31class CXXConversionDecl; 32class CXXDestructorDecl; 33class CXXMethodDecl; 34class CXXRecordDecl; 35class CXXMemberLookupCriteria; 36class CXXFinalOverriderMap; 37class CXXIndirectPrimaryBaseSet; 38class FriendDecl; 39 40/// \brief Represents any kind of function declaration, whether it is a 41/// concrete function or a function template. 42class AnyFunctionDecl { 43 NamedDecl *Function; 44 45 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 46 47public: 48 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 49 AnyFunctionDecl(FunctionTemplateDecl *FTD); 50 51 /// \brief Implicily converts any function or function template into a 52 /// named declaration. 53 operator NamedDecl *() const { return Function; } 54 55 /// \brief Retrieve the underlying function or function template. 56 NamedDecl *get() const { return Function; } 57 58 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 59 return AnyFunctionDecl(ND); 60 } 61}; 62 63} // end namespace clang 64 65namespace llvm { 66 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 67 /// AnyFunctionDecl to any function or function template declaration. 68 template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 69 typedef ::clang::NamedDecl* SimpleType; 70 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 71 return Val; 72 } 73 }; 74 template<> struct simplify_type< ::clang::AnyFunctionDecl> 75 : public simplify_type<const ::clang::AnyFunctionDecl> {}; 76 77 // Provide PointerLikeTypeTraits for non-cvr pointers. 78 template<> 79 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 80 public: 81 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 82 return F.get(); 83 } 84 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 85 return ::clang::AnyFunctionDecl::getFromNamedDecl( 86 static_cast< ::clang::NamedDecl*>(P)); 87 } 88 89 enum { NumLowBitsAvailable = 2 }; 90 }; 91 92} // end namespace llvm 93 94namespace clang { 95 96/// AccessSpecDecl - An access specifier followed by colon ':'. 97/// 98/// An objects of this class represents sugar for the syntactic occurrence 99/// of an access specifier followed by a colon in the list of member 100/// specifiers of a C++ class definition. 101/// 102/// Note that they do not represent other uses of access specifiers, 103/// such as those occurring in a list of base specifiers. 104/// Also note that this class has nothing to do with so-called 105/// "access declarations" (C++98 11.3 [class.access.dcl]). 106class AccessSpecDecl : public Decl { 107 virtual void anchor(); 108 /// ColonLoc - The location of the ':'. 109 SourceLocation ColonLoc; 110 111 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, 112 SourceLocation ASLoc, SourceLocation ColonLoc) 113 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { 114 setAccess(AS); 115 } 116 AccessSpecDecl(EmptyShell Empty) 117 : Decl(AccessSpec, Empty) { } 118public: 119 /// getAccessSpecifierLoc - The location of the access specifier. 120 SourceLocation getAccessSpecifierLoc() const { return getLocation(); } 121 /// setAccessSpecifierLoc - Sets the location of the access specifier. 122 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } 123 124 /// getColonLoc - The location of the colon following the access specifier. 125 SourceLocation getColonLoc() const { return ColonLoc; } 126 /// setColonLoc - Sets the location of the colon. 127 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } 128 129 SourceRange getSourceRange() const { 130 return SourceRange(getAccessSpecifierLoc(), getColonLoc()); 131 } 132 133 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, 134 DeclContext *DC, SourceLocation ASLoc, 135 SourceLocation ColonLoc) { 136 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); 137 } 138 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 139 140 // Implement isa/cast/dyncast/etc. 141 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 142 static bool classof(const AccessSpecDecl *D) { return true; } 143 static bool classofKind(Kind K) { return K == AccessSpec; } 144}; 145 146 147/// CXXBaseSpecifier - A base class of a C++ class. 148/// 149/// Each CXXBaseSpecifier represents a single, direct base class (or 150/// struct) of a C++ class (or struct). It specifies the type of that 151/// base class, whether it is a virtual or non-virtual base, and what 152/// level of access (public, protected, private) is used for the 153/// derivation. For example: 154/// 155/// @code 156/// class A { }; 157/// class B { }; 158/// class C : public virtual A, protected B { }; 159/// @endcode 160/// 161/// In this code, C will have two CXXBaseSpecifiers, one for "public 162/// virtual A" and the other for "protected B". 163class CXXBaseSpecifier { 164 /// Range - The source code range that covers the full base 165 /// specifier, including the "virtual" (if present) and access 166 /// specifier (if present). 167 SourceRange Range; 168 169 /// \brief The source location of the ellipsis, if this is a pack 170 /// expansion. 171 SourceLocation EllipsisLoc; 172 173 /// Virtual - Whether this is a virtual base class or not. 174 bool Virtual : 1; 175 176 /// BaseOfClass - Whether this is the base of a class (true) or of a 177 /// struct (false). This determines the mapping from the access 178 /// specifier as written in the source code to the access specifier 179 /// used for semantic analysis. 180 bool BaseOfClass : 1; 181 182 /// Access - Access specifier as written in the source code (which 183 /// may be AS_none). The actual type of data stored here is an 184 /// AccessSpecifier, but we use "unsigned" here to work around a 185 /// VC++ bug. 186 unsigned Access : 2; 187 188 /// InheritConstructors - Whether the class contains a using declaration 189 /// to inherit the named class's constructors. 190 bool InheritConstructors : 1; 191 192 /// BaseTypeInfo - The type of the base class. This will be a class or struct 193 /// (or a typedef of such). The source code range does not include the 194 /// "virtual" or access specifier. 195 TypeSourceInfo *BaseTypeInfo; 196 197public: 198 CXXBaseSpecifier() { } 199 200 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, 201 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) 202 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), 203 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { } 204 205 /// getSourceRange - Retrieves the source range that contains the 206 /// entire base specifier. 207 SourceRange getSourceRange() const { return Range; } 208 209 /// isVirtual - Determines whether the base class is a virtual base 210 /// class (or not). 211 bool isVirtual() const { return Virtual; } 212 213 /// \brief Determine whether this base class is a base of a class declared 214 /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 215 bool isBaseOfClass() const { return BaseOfClass; } 216 217 /// \brief Determine whether this base specifier is a pack expansion. 218 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 219 220 /// \brief Determine whether this base class's constructors get inherited. 221 bool getInheritConstructors() const { return InheritConstructors; } 222 223 /// \brief Set that this base class's constructors should be inherited. 224 void setInheritConstructors(bool Inherit = true) { 225 InheritConstructors = Inherit; 226 } 227 228 /// \brief For a pack expansion, determine the location of the ellipsis. 229 SourceLocation getEllipsisLoc() const { 230 return EllipsisLoc; 231 } 232 233 /// getAccessSpecifier - Returns the access specifier for this base 234 /// specifier. This is the actual base specifier as used for 235 /// semantic analysis, so the result can never be AS_none. To 236 /// retrieve the access specifier as written in the source code, use 237 /// getAccessSpecifierAsWritten(). 238 AccessSpecifier getAccessSpecifier() const { 239 if ((AccessSpecifier)Access == AS_none) 240 return BaseOfClass? AS_private : AS_public; 241 else 242 return (AccessSpecifier)Access; 243 } 244 245 /// getAccessSpecifierAsWritten - Retrieves the access specifier as 246 /// written in the source code (which may mean that no access 247 /// specifier was explicitly written). Use getAccessSpecifier() to 248 /// retrieve the access specifier for use in semantic analysis. 249 AccessSpecifier getAccessSpecifierAsWritten() const { 250 return (AccessSpecifier)Access; 251 } 252 253 /// getType - Retrieves the type of the base class. This type will 254 /// always be an unqualified class type. 255 QualType getType() const { return BaseTypeInfo->getType(); } 256 257 /// getTypeLoc - Retrieves the type and source location of the base class. 258 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } 259}; 260 261/// CXXRecordDecl - Represents a C++ struct/union/class. 262/// FIXME: This class will disappear once we've properly taught RecordDecl 263/// to deal with C++-specific things. 264class CXXRecordDecl : public RecordDecl { 265 266 friend void TagDecl::startDefinition(); 267 268 struct DefinitionData { 269 DefinitionData(CXXRecordDecl *D); 270 271 /// UserDeclaredConstructor - True when this class has a 272 /// user-declared constructor. 273 bool UserDeclaredConstructor : 1; 274 275 /// UserDeclaredCopyConstructor - True when this class has a 276 /// user-declared copy constructor. 277 bool UserDeclaredCopyConstructor : 1; 278 279 /// UserDeclareMoveConstructor - True when this class has a 280 /// user-declared move constructor. 281 bool UserDeclaredMoveConstructor : 1; 282 283 /// UserDeclaredCopyAssignment - True when this class has a 284 /// user-declared copy assignment operator. 285 bool UserDeclaredCopyAssignment : 1; 286 287 /// UserDeclareMoveAssignment - True when this class has a 288 /// user-declared move assignment. 289 bool UserDeclaredMoveAssignment : 1; 290 291 /// UserDeclaredDestructor - True when this class has a 292 /// user-declared destructor. 293 bool UserDeclaredDestructor : 1; 294 295 /// Aggregate - True when this class is an aggregate. 296 bool Aggregate : 1; 297 298 /// PlainOldData - True when this class is a POD-type. 299 bool PlainOldData : 1; 300 301 /// Empty - true when this class is empty for traits purposes, 302 /// i.e. has no data members other than 0-width bit-fields, has no 303 /// virtual function/base, and doesn't inherit from a non-empty 304 /// class. Doesn't take union-ness into account. 305 bool Empty : 1; 306 307 /// Polymorphic - True when this class is polymorphic, i.e. has at 308 /// least one virtual member or derives from a polymorphic class. 309 bool Polymorphic : 1; 310 311 /// Abstract - True when this class is abstract, i.e. has at least 312 /// one pure virtual function, (that can come from a base class). 313 bool Abstract : 1; 314 315 /// IsStandardLayout - True when this class has standard layout. 316 /// 317 /// C++0x [class]p7. A standard-layout class is a class that: 318 /// * has no non-static data members of type non-standard-layout class (or 319 /// array of such types) or reference, 320 /// * has no virtual functions (10.3) and no virtual base classes (10.1), 321 /// * has the same access control (Clause 11) for all non-static data 322 /// members 323 /// * has no non-standard-layout base classes, 324 /// * either has no non-static data members in the most derived class and at 325 /// most one base class with non-static data members, or has no base 326 /// classes with non-static data members, and 327 /// * has no base classes of the same type as the first non-static data 328 /// member. 329 bool IsStandardLayout : 1; 330 331 /// HasNoNonEmptyBases - True when there are no non-empty base classes. 332 /// 333 /// This is a helper bit of state used to implement IsStandardLayout more 334 /// efficiently. 335 bool HasNoNonEmptyBases : 1; 336 337 /// HasPrivateFields - True when there are private non-static data members. 338 bool HasPrivateFields : 1; 339 340 /// HasProtectedFields - True when there are protected non-static data 341 /// members. 342 bool HasProtectedFields : 1; 343 344 /// HasPublicFields - True when there are private non-static data members. 345 bool HasPublicFields : 1; 346 347 /// \brief True if this class (or any subobject) has mutable fields. 348 bool HasMutableFields : 1; 349 350 /// HasTrivialDefaultConstructor - True when, if this class has a default 351 /// constructor, this default constructor is trivial. 352 /// 353 /// C++0x [class.ctor]p5 354 /// A default constructor is trivial if it is not user-provided and if 355 /// -- its class has no virtual functions and no virtual base classes, 356 /// and 357 /// -- no non-static data member of its class has a 358 /// brace-or-equal-initializer, and 359 /// -- all the direct base classes of its class have trivial 360 /// default constructors, and 361 /// -- for all the nonstatic data members of its class that are of class 362 /// type (or array thereof), each such class has a trivial 363 /// default constructor. 364 bool HasTrivialDefaultConstructor : 1; 365 366 /// HasConstexprNonCopyMoveConstructor - True when this class has at least 367 /// one user-declared constexpr constructor which is neither the copy nor 368 /// move constructor. 369 bool HasConstexprNonCopyMoveConstructor : 1; 370 371 /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default 372 /// constructor for this class would be constexpr. 373 bool DefaultedDefaultConstructorIsConstexpr : 1; 374 375 /// DefaultedCopyConstructorIsConstexpr - True if a defaulted copy 376 /// constructor for this class would be constexpr. 377 bool DefaultedCopyConstructorIsConstexpr : 1; 378 379 /// DefaultedMoveConstructorIsConstexpr - True if a defaulted move 380 /// constructor for this class would be constexpr. 381 bool DefaultedMoveConstructorIsConstexpr : 1; 382 383 /// HasConstexprDefaultConstructor - True if this class has a constexpr 384 /// default constructor (either user-declared or implicitly declared). 385 bool HasConstexprDefaultConstructor : 1; 386 387 /// HasConstexprCopyConstructor - True if this class has a constexpr copy 388 /// constructor (either user-declared or implicitly declared). 389 bool HasConstexprCopyConstructor : 1; 390 391 /// HasConstexprMoveConstructor - True if this class has a constexpr move 392 /// constructor (either user-declared or implicitly declared). 393 bool HasConstexprMoveConstructor : 1; 394 395 /// HasTrivialCopyConstructor - True when this class has a trivial copy 396 /// constructor. 397 /// 398 /// C++0x [class.copy]p13: 399 /// A copy/move constructor for class X is trivial if it is neither 400 /// user-provided and if 401 /// -- class X has no virtual functions and no virtual base classes, and 402 /// -- the constructor selected to copy/move each direct base class 403 /// subobject is trivial, and 404 /// -- for each non-static data member of X that is of class type (or an 405 /// array thereof), the constructor selected to copy/move that member 406 /// is trivial; 407 /// otherwise the copy/move constructor is non-trivial. 408 bool HasTrivialCopyConstructor : 1; 409 410 /// HasTrivialMoveConstructor - True when this class has a trivial move 411 /// constructor. 412 /// 413 /// C++0x [class.copy]p13: 414 /// A copy/move constructor for class X is trivial if it is neither 415 /// user-provided and if 416 /// -- class X has no virtual functions and no virtual base classes, and 417 /// -- the constructor selected to copy/move each direct base class 418 /// subobject is trivial, and 419 /// -- for each non-static data member of X that is of class type (or an 420 /// array thereof), the constructor selected to copy/move that member 421 /// is trivial; 422 /// otherwise the copy/move constructor is non-trivial. 423 bool HasTrivialMoveConstructor : 1; 424 425 /// HasTrivialCopyAssignment - True when this class has a trivial copy 426 /// assignment operator. 427 /// 428 /// C++0x [class.copy]p27: 429 /// A copy/move assignment operator for class X is trivial if it is 430 /// neither user-provided nor deleted and if 431 /// -- class X has no virtual functions and no virtual base classes, and 432 /// -- the assignment operator selected to copy/move each direct base 433 /// class subobject is trivial, and 434 /// -- for each non-static data member of X that is of class type (or an 435 /// array thereof), the assignment operator selected to copy/move 436 /// that member is trivial; 437 /// otherwise the copy/move assignment operator is non-trivial. 438 bool HasTrivialCopyAssignment : 1; 439 440 /// HasTrivialMoveAssignment - True when this class has a trivial move 441 /// assignment operator. 442 /// 443 /// C++0x [class.copy]p27: 444 /// A copy/move assignment operator for class X is trivial if it is 445 /// neither user-provided nor deleted and if 446 /// -- class X has no virtual functions and no virtual base classes, and 447 /// -- the assignment operator selected to copy/move each direct base 448 /// class subobject is trivial, and 449 /// -- for each non-static data member of X that is of class type (or an 450 /// array thereof), the assignment operator selected to copy/move 451 /// that member is trivial; 452 /// otherwise the copy/move assignment operator is non-trivial. 453 bool HasTrivialMoveAssignment : 1; 454 455 /// HasTrivialDestructor - True when this class has a trivial destructor. 456 /// 457 /// C++ [class.dtor]p3. A destructor is trivial if it is an 458 /// implicitly-declared destructor and if: 459 /// * all of the direct base classes of its class have trivial destructors 460 /// and 461 /// * for all of the non-static data members of its class that are of class 462 /// type (or array thereof), each such class has a trivial destructor. 463 bool HasTrivialDestructor : 1; 464 465 /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least 466 /// one non-static data member or base class of non literal type. 467 bool HasNonLiteralTypeFieldsOrBases : 1; 468 469 /// ComputedVisibleConversions - True when visible conversion functions are 470 /// already computed and are available. 471 bool ComputedVisibleConversions : 1; 472 473 /// \brief Whether we have a C++0x user-provided default constructor (not 474 /// explicitly deleted or defaulted). 475 bool UserProvidedDefaultConstructor : 1; 476 477 /// \brief Whether we have already declared the default constructor. 478 bool DeclaredDefaultConstructor : 1; 479 480 /// \brief Whether we have already declared the copy constructor. 481 bool DeclaredCopyConstructor : 1; 482 483 /// \brief Whether we have already declared the move constructor. 484 bool DeclaredMoveConstructor : 1; 485 486 /// \brief Whether we have already declared the copy-assignment operator. 487 bool DeclaredCopyAssignment : 1; 488 489 /// \brief Whether we have already declared the move-assignment operator. 490 bool DeclaredMoveAssignment : 1; 491 492 /// \brief Whether we have already declared a destructor within the class. 493 bool DeclaredDestructor : 1; 494 495 /// \brief Whether an implicit move constructor was attempted to be declared 496 /// but would have been deleted. 497 bool FailedImplicitMoveConstructor : 1; 498 499 /// \brief Whether an implicit move assignment operator was attempted to be 500 /// declared but would have been deleted. 501 bool FailedImplicitMoveAssignment : 1; 502 503 /// NumBases - The number of base class specifiers in Bases. 504 unsigned NumBases; 505 506 /// NumVBases - The number of virtual base class specifiers in VBases. 507 unsigned NumVBases; 508 509 /// Bases - Base classes of this class. 510 /// FIXME: This is wasted space for a union. 511 LazyCXXBaseSpecifiersPtr Bases; 512 513 /// VBases - direct and indirect virtual base classes of this class. 514 LazyCXXBaseSpecifiersPtr VBases; 515 516 /// Conversions - Overload set containing the conversion functions 517 /// of this C++ class (but not its inherited conversion 518 /// functions). Each of the entries in this overload set is a 519 /// CXXConversionDecl. 520 UnresolvedSet<4> Conversions; 521 522 /// VisibleConversions - Overload set containing the conversion 523 /// functions of this C++ class and all those inherited conversion 524 /// functions that are visible in this class. Each of the entries 525 /// in this overload set is a CXXConversionDecl or a 526 /// FunctionTemplateDecl. 527 UnresolvedSet<4> VisibleConversions; 528 529 /// Definition - The declaration which defines this record. 530 CXXRecordDecl *Definition; 531 532 /// FirstFriend - The first friend declaration in this class, or 533 /// null if there aren't any. This is actually currently stored 534 /// in reverse order. 535 FriendDecl *FirstFriend; 536 537 /// \brief Retrieve the set of direct base classes. 538 CXXBaseSpecifier *getBases() const { 539 return Bases.get(Definition->getASTContext().getExternalSource()); 540 } 541 542 /// \brief Retrieve the set of virtual base classes. 543 CXXBaseSpecifier *getVBases() const { 544 return VBases.get(Definition->getASTContext().getExternalSource()); 545 } 546 } *DefinitionData; 547 548 struct DefinitionData &data() { 549 assert(DefinitionData && "queried property of class with no definition"); 550 return *DefinitionData; 551 } 552 553 const struct DefinitionData &data() const { 554 assert(DefinitionData && "queried property of class with no definition"); 555 return *DefinitionData; 556 } 557 558 /// \brief The template or declaration that this declaration 559 /// describes or was instantiated from, respectively. 560 /// 561 /// For non-templates, this value will be NULL. For record 562 /// declarations that describe a class template, this will be a 563 /// pointer to a ClassTemplateDecl. For member 564 /// classes of class template specializations, this will be the 565 /// MemberSpecializationInfo referring to the member class that was 566 /// instantiated or specialized. 567 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 568 TemplateOrInstantiation; 569 570 friend class DeclContext; 571 572 /// \brief Notify the class that member has been added. 573 /// 574 /// This routine helps maintain information about the class based on which 575 /// members have been added. It will be invoked by DeclContext::addDecl() 576 /// whenever a member is added to this record. 577 void addedMember(Decl *D); 578 579 void markedVirtualFunctionPure(); 580 friend void FunctionDecl::setPure(bool); 581 582 friend class ASTNodeImporter; 583 584protected: 585 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 586 SourceLocation StartLoc, SourceLocation IdLoc, 587 IdentifierInfo *Id, CXXRecordDecl *PrevDecl); 588 589public: 590 /// base_class_iterator - Iterator that traverses the base classes 591 /// of a class. 592 typedef CXXBaseSpecifier* base_class_iterator; 593 594 /// base_class_const_iterator - Iterator that traverses the base 595 /// classes of a class. 596 typedef const CXXBaseSpecifier* base_class_const_iterator; 597 598 /// reverse_base_class_iterator = Iterator that traverses the base classes 599 /// of a class in reverse order. 600 typedef std::reverse_iterator<base_class_iterator> 601 reverse_base_class_iterator; 602 603 /// reverse_base_class_iterator = Iterator that traverses the base classes 604 /// of a class in reverse order. 605 typedef std::reverse_iterator<base_class_const_iterator> 606 reverse_base_class_const_iterator; 607 608 virtual CXXRecordDecl *getCanonicalDecl() { 609 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 610 } 611 virtual const CXXRecordDecl *getCanonicalDecl() const { 612 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 613 } 614 615 const CXXRecordDecl *getPreviousDeclaration() const { 616 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 617 } 618 CXXRecordDecl *getPreviousDeclaration() { 619 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 620 } 621 622 CXXRecordDecl *getDefinition() const { 623 if (!DefinitionData) return 0; 624 return data().Definition; 625 } 626 627 bool hasDefinition() const { return DefinitionData != 0; } 628 629 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 630 SourceLocation StartLoc, SourceLocation IdLoc, 631 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0, 632 bool DelayTypeCreation = false); 633 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); 634 635 bool isDynamicClass() const { 636 return data().Polymorphic || data().NumVBases != 0; 637 } 638 639 /// setBases - Sets the base classes of this struct or class. 640 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 641 642 /// getNumBases - Retrieves the number of base classes of this 643 /// class. 644 unsigned getNumBases() const { return data().NumBases; } 645 646 base_class_iterator bases_begin() { return data().getBases(); } 647 base_class_const_iterator bases_begin() const { return data().getBases(); } 648 base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 649 base_class_const_iterator bases_end() const { 650 return bases_begin() + data().NumBases; 651 } 652 reverse_base_class_iterator bases_rbegin() { 653 return reverse_base_class_iterator(bases_end()); 654 } 655 reverse_base_class_const_iterator bases_rbegin() const { 656 return reverse_base_class_const_iterator(bases_end()); 657 } 658 reverse_base_class_iterator bases_rend() { 659 return reverse_base_class_iterator(bases_begin()); 660 } 661 reverse_base_class_const_iterator bases_rend() const { 662 return reverse_base_class_const_iterator(bases_begin()); 663 } 664 665 /// getNumVBases - Retrieves the number of virtual base classes of this 666 /// class. 667 unsigned getNumVBases() const { return data().NumVBases; } 668 669 base_class_iterator vbases_begin() { return data().getVBases(); } 670 base_class_const_iterator vbases_begin() const { return data().getVBases(); } 671 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 672 base_class_const_iterator vbases_end() const { 673 return vbases_begin() + data().NumVBases; 674 } 675 reverse_base_class_iterator vbases_rbegin() { 676 return reverse_base_class_iterator(vbases_end()); 677 } 678 reverse_base_class_const_iterator vbases_rbegin() const { 679 return reverse_base_class_const_iterator(vbases_end()); 680 } 681 reverse_base_class_iterator vbases_rend() { 682 return reverse_base_class_iterator(vbases_begin()); 683 } 684 reverse_base_class_const_iterator vbases_rend() const { 685 return reverse_base_class_const_iterator(vbases_begin()); 686 } 687 688 /// \brief Determine whether this class has any dependent base classes. 689 bool hasAnyDependentBases() const; 690 691 /// Iterator access to method members. The method iterator visits 692 /// all method members of the class, including non-instance methods, 693 /// special methods, etc. 694 typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 695 696 /// method_begin - Method begin iterator. Iterates in the order the methods 697 /// were declared. 698 method_iterator method_begin() const { 699 return method_iterator(decls_begin()); 700 } 701 /// method_end - Method end iterator. 702 method_iterator method_end() const { 703 return method_iterator(decls_end()); 704 } 705 706 /// Iterator access to constructor members. 707 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 708 709 ctor_iterator ctor_begin() const { 710 return ctor_iterator(decls_begin()); 711 } 712 ctor_iterator ctor_end() const { 713 return ctor_iterator(decls_end()); 714 } 715 716 /// An iterator over friend declarations. All of these are defined 717 /// in DeclFriend.h. 718 class friend_iterator; 719 friend_iterator friend_begin() const; 720 friend_iterator friend_end() const; 721 void pushFriendDecl(FriendDecl *FD); 722 723 /// Determines whether this record has any friends. 724 bool hasFriends() const { 725 return data().FirstFriend != 0; 726 } 727 728 /// \brief Determine if we need to declare a default constructor for 729 /// this class. 730 /// 731 /// This value is used for lazy creation of default constructors. 732 bool needsImplicitDefaultConstructor() const { 733 return !data().UserDeclaredConstructor && 734 !data().DeclaredDefaultConstructor; 735 } 736 737 /// hasDeclaredDefaultConstructor - Whether this class's default constructor 738 /// has been declared (either explicitly or implicitly). 739 bool hasDeclaredDefaultConstructor() const { 740 return data().DeclaredDefaultConstructor; 741 } 742 743 /// hasConstCopyConstructor - Determines whether this class has a 744 /// copy constructor that accepts a const-qualified argument. 745 bool hasConstCopyConstructor() const; 746 747 /// getCopyConstructor - Returns the copy constructor for this class 748 CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const; 749 750 /// getMoveConstructor - Returns the move constructor for this class 751 CXXConstructorDecl *getMoveConstructor() const; 752 753 /// \brief Retrieve the copy-assignment operator for this class, if available. 754 /// 755 /// This routine attempts to find the copy-assignment operator for this 756 /// class, using a simplistic form of overload resolution. 757 /// 758 /// \param ArgIsConst Whether the argument to the copy-assignment operator 759 /// is const-qualified. 760 /// 761 /// \returns The copy-assignment operator that can be invoked, or NULL if 762 /// a unique copy-assignment operator could not be found. 763 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const; 764 765 /// getMoveAssignmentOperator - Returns the move assignment operator for this 766 /// class 767 CXXMethodDecl *getMoveAssignmentOperator() const; 768 769 /// hasUserDeclaredConstructor - Whether this class has any 770 /// user-declared constructors. When true, a default constructor 771 /// will not be implicitly declared. 772 bool hasUserDeclaredConstructor() const { 773 return data().UserDeclaredConstructor; 774 } 775 776 /// hasUserProvidedDefaultconstructor - Whether this class has a 777 /// user-provided default constructor per C++0x. 778 bool hasUserProvidedDefaultConstructor() const { 779 return data().UserProvidedDefaultConstructor; 780 } 781 782 /// hasUserDeclaredCopyConstructor - Whether this class has a 783 /// user-declared copy constructor. When false, a copy constructor 784 /// will be implicitly declared. 785 bool hasUserDeclaredCopyConstructor() const { 786 return data().UserDeclaredCopyConstructor; 787 } 788 789 /// \brief Determine whether this class has had its copy constructor 790 /// declared, either via the user or via an implicit declaration. 791 /// 792 /// This value is used for lazy creation of copy constructors. 793 bool hasDeclaredCopyConstructor() const { 794 return data().DeclaredCopyConstructor; 795 } 796 797 /// hasUserDeclaredMoveOperation - Whether this class has a user- 798 /// declared move constructor or assignment operator. When false, a 799 /// move constructor and assignment operator may be implicitly declared. 800 bool hasUserDeclaredMoveOperation() const { 801 return data().UserDeclaredMoveConstructor || 802 data().UserDeclaredMoveAssignment; 803 } 804 805 /// \brief Determine whether this class has had a move constructor 806 /// declared by the user. 807 bool hasUserDeclaredMoveConstructor() const { 808 return data().UserDeclaredMoveConstructor; 809 } 810 811 /// \brief Determine whether this class has had a move constructor 812 /// declared. 813 bool hasDeclaredMoveConstructor() const { 814 return data().DeclaredMoveConstructor; 815 } 816 817 /// \brief Determine whether implicit move constructor generation for this 818 /// class has failed before. 819 bool hasFailedImplicitMoveConstructor() const { 820 return data().FailedImplicitMoveConstructor; 821 } 822 823 /// \brief Set whether implicit move constructor generation for this class 824 /// has failed before. 825 void setFailedImplicitMoveConstructor(bool Failed = true) { 826 data().FailedImplicitMoveConstructor = Failed; 827 } 828 829 /// \brief Determine whether this class should get an implicit move 830 /// constructor or if any existing special member function inhibits this. 831 /// 832 /// Covers all bullets of C++0x [class.copy]p9 except the last, that the 833 /// constructor wouldn't be deleted, which is only looked up from a cached 834 /// result. 835 bool needsImplicitMoveConstructor() const { 836 return !hasFailedImplicitMoveConstructor() && 837 !hasDeclaredMoveConstructor() && 838 !hasUserDeclaredCopyConstructor() && 839 !hasUserDeclaredCopyAssignment() && 840 !hasUserDeclaredMoveAssignment() && 841 !hasUserDeclaredDestructor(); 842 } 843 844 /// hasUserDeclaredCopyAssignment - Whether this class has a 845 /// user-declared copy assignment operator. When false, a copy 846 /// assigment operator will be implicitly declared. 847 bool hasUserDeclaredCopyAssignment() const { 848 return data().UserDeclaredCopyAssignment; 849 } 850 851 /// \brief Determine whether this class has had its copy assignment operator 852 /// declared, either via the user or via an implicit declaration. 853 /// 854 /// This value is used for lazy creation of copy assignment operators. 855 bool hasDeclaredCopyAssignment() const { 856 return data().DeclaredCopyAssignment; 857 } 858 859 /// \brief Determine whether this class has had a move assignment 860 /// declared by the user. 861 bool hasUserDeclaredMoveAssignment() const { 862 return data().UserDeclaredMoveAssignment; 863 } 864 865 /// hasDeclaredMoveAssignment - Whether this class has a 866 /// declared move assignment operator. 867 bool hasDeclaredMoveAssignment() const { 868 return data().DeclaredMoveAssignment; 869 } 870 871 /// \brief Determine whether implicit move assignment generation for this 872 /// class has failed before. 873 bool hasFailedImplicitMoveAssignment() const { 874 return data().FailedImplicitMoveAssignment; 875 } 876 877 /// \brief Set whether implicit move assignment generation for this class 878 /// has failed before. 879 void setFailedImplicitMoveAssignment(bool Failed = true) { 880 data().FailedImplicitMoveAssignment = Failed; 881 } 882 883 /// \brief Determine whether this class should get an implicit move 884 /// assignment operator or if any existing special member function inhibits 885 /// this. 886 /// 887 /// Covers all bullets of C++0x [class.copy]p20 except the last, that the 888 /// constructor wouldn't be deleted. 889 bool needsImplicitMoveAssignment() const { 890 return !hasFailedImplicitMoveAssignment() && 891 !hasDeclaredMoveAssignment() && 892 !hasUserDeclaredCopyConstructor() && 893 !hasUserDeclaredCopyAssignment() && 894 !hasUserDeclaredMoveConstructor() && 895 !hasUserDeclaredDestructor(); 896 } 897 898 /// hasUserDeclaredDestructor - Whether this class has a 899 /// user-declared destructor. When false, a destructor will be 900 /// implicitly declared. 901 bool hasUserDeclaredDestructor() const { 902 return data().UserDeclaredDestructor; 903 } 904 905 /// \brief Determine whether this class has had its destructor declared, 906 /// either via the user or via an implicit declaration. 907 /// 908 /// This value is used for lazy creation of destructors. 909 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; } 910 911 /// getConversions - Retrieve the overload set containing all of the 912 /// conversion functions in this class. 913 UnresolvedSetImpl *getConversionFunctions() { 914 return &data().Conversions; 915 } 916 const UnresolvedSetImpl *getConversionFunctions() const { 917 return &data().Conversions; 918 } 919 920 typedef UnresolvedSetImpl::iterator conversion_iterator; 921 conversion_iterator conversion_begin() const { 922 return getConversionFunctions()->begin(); 923 } 924 conversion_iterator conversion_end() const { 925 return getConversionFunctions()->end(); 926 } 927 928 /// Removes a conversion function from this class. The conversion 929 /// function must currently be a member of this class. Furthermore, 930 /// this class must currently be in the process of being defined. 931 void removeConversion(const NamedDecl *Old); 932 933 /// getVisibleConversionFunctions - get all conversion functions visible 934 /// in current class; including conversion function templates. 935 const UnresolvedSetImpl *getVisibleConversionFunctions(); 936 937 /// isAggregate - Whether this class is an aggregate (C++ 938 /// [dcl.init.aggr]), which is a class with no user-declared 939 /// constructors, no private or protected non-static data members, 940 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 941 bool isAggregate() const { return data().Aggregate; } 942 943 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 944 /// that is an aggregate that has no non-static non-POD data members, no 945 /// reference data members, no user-defined copy assignment operator and no 946 /// user-defined destructor. 947 bool isPOD() const { return data().PlainOldData; } 948 949 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 950 /// means it has a virtual function, virtual base, data member (other than 951 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 952 /// a check for union-ness. 953 bool isEmpty() const { return data().Empty; } 954 955 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 956 /// which means that the class contains or inherits a virtual function. 957 bool isPolymorphic() const { return data().Polymorphic; } 958 959 /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 960 /// which means that the class contains or inherits a pure virtual function. 961 bool isAbstract() const { return data().Abstract; } 962 963 /// isStandardLayout - Whether this class has standard layout 964 /// (C++ [class]p7) 965 bool isStandardLayout() const { return data().IsStandardLayout; } 966 967 /// \brief Whether this class, or any of its class subobjects, contains a 968 /// mutable field. 969 bool hasMutableFields() const { return data().HasMutableFields; } 970 971 /// hasTrivialDefaultConstructor - Whether this class has a trivial default 972 /// constructor (C++11 [class.ctor]p5). 973 bool hasTrivialDefaultConstructor() const { 974 return data().HasTrivialDefaultConstructor && 975 (!data().UserDeclaredConstructor || 976 data().DeclaredDefaultConstructor); 977 } 978 979 /// hasConstexprNonCopyMoveConstructor - Whether this class has at least one 980 /// constexpr constructor other than the copy or move constructors. 981 bool hasConstexprNonCopyMoveConstructor() const { 982 return data().HasConstexprNonCopyMoveConstructor || 983 (!hasUserDeclaredConstructor() && 984 defaultedDefaultConstructorIsConstexpr()); 985 } 986 987 /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default 988 /// constructor for this class would be constexpr. 989 bool defaultedDefaultConstructorIsConstexpr() const { 990 return data().DefaultedDefaultConstructorIsConstexpr; 991 } 992 993 /// defaultedCopyConstructorIsConstexpr - Whether a defaulted copy 994 /// constructor for this class would be constexpr. 995 bool defaultedCopyConstructorIsConstexpr() const { 996 return data().DefaultedCopyConstructorIsConstexpr; 997 } 998 999 /// defaultedMoveConstructorIsConstexpr - Whether a defaulted move 1000 /// constructor for this class would be constexpr. 1001 bool defaultedMoveConstructorIsConstexpr() const { 1002 return data().DefaultedMoveConstructorIsConstexpr; 1003 } 1004 1005 /// hasConstexprDefaultConstructor - Whether this class has a constexpr 1006 /// default constructor. 1007 bool hasConstexprDefaultConstructor() const { 1008 return data().HasConstexprDefaultConstructor || 1009 (!data().UserDeclaredConstructor && 1010 data().DefaultedDefaultConstructorIsConstexpr && isLiteral()); 1011 } 1012 1013 /// hasConstexprCopyConstructor - Whether this class has a constexpr copy 1014 /// constructor. 1015 bool hasConstexprCopyConstructor() const { 1016 return data().HasConstexprCopyConstructor || 1017 (!data().DeclaredCopyConstructor && 1018 data().DefaultedCopyConstructorIsConstexpr && isLiteral()); 1019 } 1020 1021 /// hasConstexprMoveConstructor - Whether this class has a constexpr move 1022 /// constructor. 1023 bool hasConstexprMoveConstructor() const { 1024 return data().HasConstexprMoveConstructor || 1025 (needsImplicitMoveConstructor() && 1026 data().DefaultedMoveConstructorIsConstexpr && isLiteral()); 1027 } 1028 1029 // hasTrivialCopyConstructor - Whether this class has a trivial copy 1030 // constructor (C++ [class.copy]p6, C++0x [class.copy]p13) 1031 bool hasTrivialCopyConstructor() const { 1032 return data().HasTrivialCopyConstructor; 1033 } 1034 1035 // hasTrivialMoveConstructor - Whether this class has a trivial move 1036 // constructor (C++0x [class.copy]p13) 1037 bool hasTrivialMoveConstructor() const { 1038 return data().HasTrivialMoveConstructor; 1039 } 1040 1041 // hasTrivialCopyAssignment - Whether this class has a trivial copy 1042 // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27) 1043 bool hasTrivialCopyAssignment() const { 1044 return data().HasTrivialCopyAssignment; 1045 } 1046 1047 // hasTrivialMoveAssignment - Whether this class has a trivial move 1048 // assignment operator (C++0x [class.copy]p27) 1049 bool hasTrivialMoveAssignment() const { 1050 return data().HasTrivialMoveAssignment; 1051 } 1052 1053 // hasTrivialDestructor - Whether this class has a trivial destructor 1054 // (C++ [class.dtor]p3) 1055 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; } 1056 1057 // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal type 1058 // non-static data member or base class. 1059 bool hasNonLiteralTypeFieldsOrBases() const { 1060 return data().HasNonLiteralTypeFieldsOrBases; 1061 } 1062 1063 // isTriviallyCopyable - Whether this class is considered trivially copyable 1064 // (C++0x [class]p6). 1065 bool isTriviallyCopyable() const; 1066 1067 // isTrivial - Whether this class is considered trivial 1068 // 1069 // C++0x [class]p6 1070 // A trivial class is a class that has a trivial default constructor and 1071 // is trivially copiable. 1072 bool isTrivial() const { 1073 return isTriviallyCopyable() && hasTrivialDefaultConstructor(); 1074 } 1075 1076 // isLiteral - Whether this class is a literal type. 1077 // 1078 // C++0x [basic.types]p10 1079 // A class type that has all the following properties: 1080 // -- a trivial destructor 1081 // -- every constructor call and full-expression in the 1082 // brace-or-equal-intializers for non-static data members (if any) is 1083 // a constant expression. 1084 // -- it is an aggregate type or has at least one constexpr constructor or 1085 // constructor template that is not a copy or move constructor, and 1086 // -- all non-static data members and base classes of literal types 1087 // 1088 // We resolve DR1361 by ignoring the second bullet. 1089 bool isLiteral() const { 1090 return hasTrivialDestructor() && 1091 (isAggregate() || hasConstexprNonCopyMoveConstructor()) && 1092 !hasNonLiteralTypeFieldsOrBases(); 1093 } 1094 1095 /// \brief If this record is an instantiation of a member class, 1096 /// retrieves the member class from which it was instantiated. 1097 /// 1098 /// This routine will return non-NULL for (non-templated) member 1099 /// classes of class templates. For example, given: 1100 /// 1101 /// \code 1102 /// template<typename T> 1103 /// struct X { 1104 /// struct A { }; 1105 /// }; 1106 /// \endcode 1107 /// 1108 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 1109 /// whose parent is the class template specialization X<int>. For 1110 /// this declaration, getInstantiatedFromMemberClass() will return 1111 /// the CXXRecordDecl X<T>::A. When a complete definition of 1112 /// X<int>::A is required, it will be instantiated from the 1113 /// declaration returned by getInstantiatedFromMemberClass(). 1114 CXXRecordDecl *getInstantiatedFromMemberClass() const; 1115 1116 /// \brief If this class is an instantiation of a member class of a 1117 /// class template specialization, retrieves the member specialization 1118 /// information. 1119 MemberSpecializationInfo *getMemberSpecializationInfo() const; 1120 1121 /// \brief Specify that this record is an instantiation of the 1122 /// member class RD. 1123 void setInstantiationOfMemberClass(CXXRecordDecl *RD, 1124 TemplateSpecializationKind TSK); 1125 1126 /// \brief Retrieves the class template that is described by this 1127 /// class declaration. 1128 /// 1129 /// Every class template is represented as a ClassTemplateDecl and a 1130 /// CXXRecordDecl. The former contains template properties (such as 1131 /// the template parameter lists) while the latter contains the 1132 /// actual description of the template's 1133 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 1134 /// CXXRecordDecl that from a ClassTemplateDecl, while 1135 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 1136 /// a CXXRecordDecl. 1137 ClassTemplateDecl *getDescribedClassTemplate() const { 1138 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 1139 } 1140 1141 void setDescribedClassTemplate(ClassTemplateDecl *Template) { 1142 TemplateOrInstantiation = Template; 1143 } 1144 1145 /// \brief Determine whether this particular class is a specialization or 1146 /// instantiation of a class template or member class of a class template, 1147 /// and how it was instantiated or specialized. 1148 TemplateSpecializationKind getTemplateSpecializationKind() const; 1149 1150 /// \brief Set the kind of specialization or template instantiation this is. 1151 void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 1152 1153 /// getDestructor - Returns the destructor decl for this class. 1154 CXXDestructorDecl *getDestructor() const; 1155 1156 /// isLocalClass - If the class is a local class [class.local], returns 1157 /// the enclosing function declaration. 1158 const FunctionDecl *isLocalClass() const { 1159 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 1160 return RD->isLocalClass(); 1161 1162 return dyn_cast<FunctionDecl>(getDeclContext()); 1163 } 1164 1165 /// \brief Determine whether this class is derived from the class \p Base. 1166 /// 1167 /// This routine only determines whether this class is derived from \p Base, 1168 /// but does not account for factors that may make a Derived -> Base class 1169 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1170 /// base class subobjects. 1171 /// 1172 /// \param Base the base class we are searching for. 1173 /// 1174 /// \returns true if this class is derived from Base, false otherwise. 1175 bool isDerivedFrom(const CXXRecordDecl *Base) const; 1176 1177 /// \brief Determine whether this class is derived from the type \p Base. 1178 /// 1179 /// This routine only determines whether this class is derived from \p Base, 1180 /// but does not account for factors that may make a Derived -> Base class 1181 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1182 /// base class subobjects. 1183 /// 1184 /// \param Base the base class we are searching for. 1185 /// 1186 /// \param Paths will contain the paths taken from the current class to the 1187 /// given \p Base class. 1188 /// 1189 /// \returns true if this class is derived from Base, false otherwise. 1190 /// 1191 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 1192 /// tangling input and output in \p Paths 1193 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; 1194 1195 /// \brief Determine whether this class is virtually derived from 1196 /// the class \p Base. 1197 /// 1198 /// This routine only determines whether this class is virtually 1199 /// derived from \p Base, but does not account for factors that may 1200 /// make a Derived -> Base class ill-formed, such as 1201 /// private/protected inheritance or multiple, ambiguous base class 1202 /// subobjects. 1203 /// 1204 /// \param Base the base class we are searching for. 1205 /// 1206 /// \returns true if this class is virtually derived from Base, 1207 /// false otherwise. 1208 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; 1209 1210 /// \brief Determine whether this class is provably not derived from 1211 /// the type \p Base. 1212 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 1213 1214 /// \brief Function type used by forallBases() as a callback. 1215 /// 1216 /// \param Base the definition of the base class 1217 /// 1218 /// \returns true if this base matched the search criteria 1219 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 1220 void *UserData); 1221 1222 /// \brief Determines if the given callback holds for all the direct 1223 /// or indirect base classes of this type. 1224 /// 1225 /// The class itself does not count as a base class. This routine 1226 /// returns false if the class has non-computable base classes. 1227 /// 1228 /// \param AllowShortCircuit if false, forces the callback to be called 1229 /// for every base class, even if a dependent or non-matching base was 1230 /// found. 1231 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 1232 bool AllowShortCircuit = true) const; 1233 1234 /// \brief Function type used by lookupInBases() to determine whether a 1235 /// specific base class subobject matches the lookup criteria. 1236 /// 1237 /// \param Specifier the base-class specifier that describes the inheritance 1238 /// from the base class we are trying to match. 1239 /// 1240 /// \param Path the current path, from the most-derived class down to the 1241 /// base named by the \p Specifier. 1242 /// 1243 /// \param UserData a single pointer to user-specified data, provided to 1244 /// lookupInBases(). 1245 /// 1246 /// \returns true if this base matched the search criteria, false otherwise. 1247 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 1248 CXXBasePath &Path, 1249 void *UserData); 1250 1251 /// \brief Look for entities within the base classes of this C++ class, 1252 /// transitively searching all base class subobjects. 1253 /// 1254 /// This routine uses the callback function \p BaseMatches to find base 1255 /// classes meeting some search criteria, walking all base class subobjects 1256 /// and populating the given \p Paths structure with the paths through the 1257 /// inheritance hierarchy that resulted in a match. On a successful search, 1258 /// the \p Paths structure can be queried to retrieve the matching paths and 1259 /// to determine if there were any ambiguities. 1260 /// 1261 /// \param BaseMatches callback function used to determine whether a given 1262 /// base matches the user-defined search criteria. 1263 /// 1264 /// \param UserData user data pointer that will be provided to \p BaseMatches. 1265 /// 1266 /// \param Paths used to record the paths from this class to its base class 1267 /// subobjects that match the search criteria. 1268 /// 1269 /// \returns true if there exists any path from this class to a base class 1270 /// subobject that matches the search criteria. 1271 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 1272 CXXBasePaths &Paths) const; 1273 1274 /// \brief Base-class lookup callback that determines whether the given 1275 /// base class specifier refers to a specific class declaration. 1276 /// 1277 /// This callback can be used with \c lookupInBases() to determine whether 1278 /// a given derived class has is a base class subobject of a particular type. 1279 /// The user data pointer should refer to the canonical CXXRecordDecl of the 1280 /// base class that we are searching for. 1281 static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 1282 CXXBasePath &Path, void *BaseRecord); 1283 1284 /// \brief Base-class lookup callback that determines whether the 1285 /// given base class specifier refers to a specific class 1286 /// declaration and describes virtual derivation. 1287 /// 1288 /// This callback can be used with \c lookupInBases() to determine 1289 /// whether a given derived class has is a virtual base class 1290 /// subobject of a particular type. The user data pointer should 1291 /// refer to the canonical CXXRecordDecl of the base class that we 1292 /// are searching for. 1293 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 1294 CXXBasePath &Path, void *BaseRecord); 1295 1296 /// \brief Base-class lookup callback that determines whether there exists 1297 /// a tag with the given name. 1298 /// 1299 /// This callback can be used with \c lookupInBases() to find tag members 1300 /// of the given name within a C++ class hierarchy. The user data pointer 1301 /// is an opaque \c DeclarationName pointer. 1302 static bool FindTagMember(const CXXBaseSpecifier *Specifier, 1303 CXXBasePath &Path, void *Name); 1304 1305 /// \brief Base-class lookup callback that determines whether there exists 1306 /// a member with the given name. 1307 /// 1308 /// This callback can be used with \c lookupInBases() to find members 1309 /// of the given name within a C++ class hierarchy. The user data pointer 1310 /// is an opaque \c DeclarationName pointer. 1311 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 1312 CXXBasePath &Path, void *Name); 1313 1314 /// \brief Base-class lookup callback that determines whether there exists 1315 /// a member with the given name that can be used in a nested-name-specifier. 1316 /// 1317 /// This callback can be used with \c lookupInBases() to find membes of 1318 /// the given name within a C++ class hierarchy that can occur within 1319 /// nested-name-specifiers. 1320 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 1321 CXXBasePath &Path, 1322 void *UserData); 1323 1324 /// \brief Retrieve the final overriders for each virtual member 1325 /// function in the class hierarchy where this class is the 1326 /// most-derived class in the class hierarchy. 1327 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 1328 1329 /// \brief Get the indirect primary bases for this class. 1330 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; 1331 1332 /// viewInheritance - Renders and displays an inheritance diagram 1333 /// for this C++ class and all of its base classes (transitively) using 1334 /// GraphViz. 1335 void viewInheritance(ASTContext& Context) const; 1336 1337 /// MergeAccess - Calculates the access of a decl that is reached 1338 /// along a path. 1339 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 1340 AccessSpecifier DeclAccess) { 1341 assert(DeclAccess != AS_none); 1342 if (DeclAccess == AS_private) return AS_none; 1343 return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 1344 } 1345 1346 /// \brief Indicates that the definition of this class is now complete. 1347 virtual void completeDefinition(); 1348 1349 /// \brief Indicates that the definition of this class is now complete, 1350 /// and provides a final overrider map to help determine 1351 /// 1352 /// \param FinalOverriders The final overrider map for this class, which can 1353 /// be provided as an optimization for abstract-class checking. If NULL, 1354 /// final overriders will be computed if they are needed to complete the 1355 /// definition. 1356 void completeDefinition(CXXFinalOverriderMap *FinalOverriders); 1357 1358 /// \brief Determine whether this class may end up being abstract, even though 1359 /// it is not yet known to be abstract. 1360 /// 1361 /// \returns true if this class is not known to be abstract but has any 1362 /// base classes that are abstract. In this case, \c completeDefinition() 1363 /// will need to compute final overriders to determine whether the class is 1364 /// actually abstract. 1365 bool mayBeAbstract() const; 1366 1367 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1368 static bool classofKind(Kind K) { 1369 return K >= firstCXXRecord && K <= lastCXXRecord; 1370 } 1371 static bool classof(const CXXRecordDecl *D) { return true; } 1372 static bool classof(const ClassTemplateSpecializationDecl *D) { 1373 return true; 1374 } 1375 1376 friend class ASTDeclReader; 1377 friend class ASTDeclWriter; 1378 friend class ASTReader; 1379 friend class ASTWriter; 1380}; 1381 1382/// CXXMethodDecl - Represents a static or instance method of a 1383/// struct/union/class. 1384class CXXMethodDecl : public FunctionDecl { 1385 virtual void anchor(); 1386protected: 1387 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc, 1388 const DeclarationNameInfo &NameInfo, 1389 QualType T, TypeSourceInfo *TInfo, 1390 bool isStatic, StorageClass SCAsWritten, bool isInline, 1391 bool isConstexpr, SourceLocation EndLocation) 1392 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo, 1393 (isStatic ? SC_Static : SC_None), 1394 SCAsWritten, isInline, isConstexpr) { 1395 if (EndLocation.isValid()) 1396 setRangeEnd(EndLocation); 1397 } 1398 1399public: 1400 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1401 SourceLocation StartLoc, 1402 const DeclarationNameInfo &NameInfo, 1403 QualType T, TypeSourceInfo *TInfo, 1404 bool isStatic, 1405 StorageClass SCAsWritten, 1406 bool isInline, 1407 bool isConstexpr, 1408 SourceLocation EndLocation); 1409 1410 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1411 1412 bool isStatic() const { return getStorageClass() == SC_Static; } 1413 bool isInstance() const { return !isStatic(); } 1414 1415 bool isVirtual() const { 1416 CXXMethodDecl *CD = 1417 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 1418 1419 if (CD->isVirtualAsWritten()) 1420 return true; 1421 1422 return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 1423 } 1424 1425 /// \brief Determine whether this is a usual deallocation function 1426 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 1427 /// delete or delete[] operator with a particular signature. 1428 bool isUsualDeallocationFunction() const; 1429 1430 /// \brief Determine whether this is a copy-assignment operator, regardless 1431 /// of whether it was declared implicitly or explicitly. 1432 bool isCopyAssignmentOperator() const; 1433 1434 /// \brief Determine whether this is a move assignment operator. 1435 bool isMoveAssignmentOperator() const; 1436 1437 const CXXMethodDecl *getCanonicalDecl() const { 1438 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1439 } 1440 CXXMethodDecl *getCanonicalDecl() { 1441 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1442 } 1443 1444 /// isUserProvided - True if it is either an implicit constructor or 1445 /// if it was defaulted or deleted on first declaration. 1446 bool isUserProvided() const { 1447 return !(isDeleted() || getCanonicalDecl()->isDefaulted()); 1448 } 1449 1450 /// 1451 void addOverriddenMethod(const CXXMethodDecl *MD); 1452 1453 typedef const CXXMethodDecl ** method_iterator; 1454 1455 method_iterator begin_overridden_methods() const; 1456 method_iterator end_overridden_methods() const; 1457 unsigned size_overridden_methods() const; 1458 1459 /// getParent - Returns the parent of this method declaration, which 1460 /// is the class in which this method is defined. 1461 const CXXRecordDecl *getParent() const { 1462 return cast<CXXRecordDecl>(FunctionDecl::getParent()); 1463 } 1464 1465 /// getParent - Returns the parent of this method declaration, which 1466 /// is the class in which this method is defined. 1467 CXXRecordDecl *getParent() { 1468 return const_cast<CXXRecordDecl *>( 1469 cast<CXXRecordDecl>(FunctionDecl::getParent())); 1470 } 1471 1472 /// getThisType - Returns the type of 'this' pointer. 1473 /// Should only be called for instance methods. 1474 QualType getThisType(ASTContext &C) const; 1475 1476 unsigned getTypeQualifiers() const { 1477 return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 1478 } 1479 1480 /// \brief Retrieve the ref-qualifier associated with this method. 1481 /// 1482 /// In the following example, \c f() has an lvalue ref-qualifier, \c g() 1483 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. 1484 /// \code 1485 /// struct X { 1486 /// void f() &; 1487 /// void g() &&; 1488 /// void h(); 1489 /// }; 1490 /// \endcode 1491 RefQualifierKind getRefQualifier() const { 1492 return getType()->getAs<FunctionProtoType>()->getRefQualifier(); 1493 } 1494 1495 bool hasInlineBody() const; 1496 1497 // Implement isa/cast/dyncast/etc. 1498 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1499 static bool classof(const CXXMethodDecl *D) { return true; } 1500 static bool classofKind(Kind K) { 1501 return K >= firstCXXMethod && K <= lastCXXMethod; 1502 } 1503}; 1504 1505/// CXXCtorInitializer - Represents a C++ base or member 1506/// initializer, which is part of a constructor initializer that 1507/// initializes one non-static member variable or one base class. For 1508/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 1509/// initializers: 1510/// 1511/// @code 1512/// class A { }; 1513/// class B : public A { 1514/// float f; 1515/// public: 1516/// B(A& a) : A(a), f(3.14159) { } 1517/// }; 1518/// @endcode 1519class CXXCtorInitializer { 1520 /// \brief Either the base class name/delegating constructor type (stored as 1521 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field 1522 /// (IndirectFieldDecl*) being initialized. 1523 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> 1524 Initializee; 1525 1526 /// \brief The source location for the field name or, for a base initializer 1527 /// pack expansion, the location of the ellipsis. In the case of a delegating 1528 /// constructor, it will still include the type's source location as the 1529 /// Initializee points to the CXXConstructorDecl (to allow loop detection). 1530 SourceLocation MemberOrEllipsisLocation; 1531 1532 /// \brief The argument used to initialize the base or member, which may 1533 /// end up constructing an object (when multiple arguments are involved). 1534 /// If 0, this is a field initializer, and the in-class member initializer 1535 /// will be used. 1536 Stmt *Init; 1537 1538 /// LParenLoc - Location of the left paren of the ctor-initializer. 1539 SourceLocation LParenLoc; 1540 1541 /// RParenLoc - Location of the right paren of the ctor-initializer. 1542 SourceLocation RParenLoc; 1543 1544 /// \brief If the initializee is a type, whether that type makes this 1545 /// a delegating initialization. 1546 bool IsDelegating : 1; 1547 1548 /// IsVirtual - If the initializer is a base initializer, this keeps track 1549 /// of whether the base is virtual or not. 1550 bool IsVirtual : 1; 1551 1552 /// IsWritten - Whether or not the initializer is explicitly written 1553 /// in the sources. 1554 bool IsWritten : 1; 1555 1556 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this 1557 /// number keeps track of the textual order of this initializer in the 1558 /// original sources, counting from 0; otherwise, if IsWritten is false, 1559 /// it stores the number of array index variables stored after this 1560 /// object in memory. 1561 unsigned SourceOrderOrNumArrayIndices : 13; 1562 1563 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1564 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1565 SourceLocation R, VarDecl **Indices, unsigned NumIndices); 1566 1567public: 1568 /// CXXCtorInitializer - Creates a new base-class initializer. 1569 explicit 1570 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, 1571 SourceLocation L, Expr *Init, SourceLocation R, 1572 SourceLocation EllipsisLoc); 1573 1574 /// CXXCtorInitializer - Creates a new member initializer. 1575 explicit 1576 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 1577 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1578 SourceLocation R); 1579 1580 /// CXXCtorInitializer - Creates a new anonymous field initializer. 1581 explicit 1582 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, 1583 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 1584 SourceLocation R); 1585 1586 /// CXXCtorInitializer - Creates a new delegating Initializer. 1587 explicit 1588 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, 1589 SourceLocation L, Expr *Init, SourceLocation R); 1590 1591 /// \brief Creates a new member initializer that optionally contains 1592 /// array indices used to describe an elementwise initialization. 1593 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member, 1594 SourceLocation MemberLoc, SourceLocation L, 1595 Expr *Init, SourceLocation R, 1596 VarDecl **Indices, unsigned NumIndices); 1597 1598 /// isBaseInitializer - Returns true when this initializer is 1599 /// initializing a base class. 1600 bool isBaseInitializer() const { 1601 return Initializee.is<TypeSourceInfo*>() && !IsDelegating; 1602 } 1603 1604 /// isMemberInitializer - Returns true when this initializer is 1605 /// initializing a non-static data member. 1606 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } 1607 1608 bool isAnyMemberInitializer() const { 1609 return isMemberInitializer() || isIndirectMemberInitializer(); 1610 } 1611 1612 bool isIndirectMemberInitializer() const { 1613 return Initializee.is<IndirectFieldDecl*>(); 1614 } 1615 1616 /// isInClassMemberInitializer - Returns true when this initializer is an 1617 /// implicit ctor initializer generated for a field with an initializer 1618 /// defined on the member declaration. 1619 bool isInClassMemberInitializer() const { 1620 return !Init; 1621 } 1622 1623 /// isDelegatingInitializer - Returns true when this initializer is creating 1624 /// a delegating constructor. 1625 bool isDelegatingInitializer() const { 1626 return Initializee.is<TypeSourceInfo*>() && IsDelegating; 1627 } 1628 1629 /// \brief Determine whether this initializer is a pack expansion. 1630 bool isPackExpansion() const { 1631 return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); 1632 } 1633 1634 // \brief For a pack expansion, returns the location of the ellipsis. 1635 SourceLocation getEllipsisLoc() const { 1636 assert(isPackExpansion() && "Initializer is not a pack expansion"); 1637 return MemberOrEllipsisLocation; 1638 } 1639 1640 /// If this is a base class initializer, returns the type of the 1641 /// base class with location information. Otherwise, returns an NULL 1642 /// type location. 1643 TypeLoc getBaseClassLoc() const; 1644 1645 /// If this is a base class initializer, returns the type of the base class. 1646 /// Otherwise, returns NULL. 1647 const Type *getBaseClass() const; 1648 1649 /// Returns whether the base is virtual or not. 1650 bool isBaseVirtual() const { 1651 assert(isBaseInitializer() && "Must call this on base initializer!"); 1652 1653 return IsVirtual; 1654 } 1655 1656 /// \brief Returns the declarator information for a base class or delegating 1657 /// initializer. 1658 TypeSourceInfo *getTypeSourceInfo() const { 1659 return Initializee.dyn_cast<TypeSourceInfo *>(); 1660 } 1661 1662 /// getMember - If this is a member initializer, returns the 1663 /// declaration of the non-static data member being 1664 /// initialized. Otherwise, returns NULL. 1665 FieldDecl *getMember() const { 1666 if (isMemberInitializer()) 1667 return Initializee.get<FieldDecl*>(); 1668 return 0; 1669 } 1670 FieldDecl *getAnyMember() const { 1671 if (isMemberInitializer()) 1672 return Initializee.get<FieldDecl*>(); 1673 if (isIndirectMemberInitializer()) 1674 return Initializee.get<IndirectFieldDecl*>()->getAnonField(); 1675 return 0; 1676 } 1677 1678 IndirectFieldDecl *getIndirectMember() const { 1679 if (isIndirectMemberInitializer()) 1680 return Initializee.get<IndirectFieldDecl*>(); 1681 return 0; 1682 } 1683 1684 SourceLocation getMemberLocation() const { 1685 return MemberOrEllipsisLocation; 1686 } 1687 1688 /// \brief Determine the source location of the initializer. 1689 SourceLocation getSourceLocation() const; 1690 1691 /// \brief Determine the source range covering the entire initializer. 1692 SourceRange getSourceRange() const; 1693 1694 /// isWritten - Returns true if this initializer is explicitly written 1695 /// in the source code. 1696 bool isWritten() const { return IsWritten; } 1697 1698 /// \brief Return the source position of the initializer, counting from 0. 1699 /// If the initializer was implicit, -1 is returned. 1700 int getSourceOrder() const { 1701 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1; 1702 } 1703 1704 /// \brief Set the source order of this initializer. This method can only 1705 /// be called once for each initializer; it cannot be called on an 1706 /// initializer having a positive number of (implicit) array indices. 1707 void setSourceOrder(int pos) { 1708 assert(!IsWritten && 1709 "calling twice setSourceOrder() on the same initializer"); 1710 assert(SourceOrderOrNumArrayIndices == 0 && 1711 "setSourceOrder() used when there are implicit array indices"); 1712 assert(pos >= 0 && 1713 "setSourceOrder() used to make an initializer implicit"); 1714 IsWritten = true; 1715 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos); 1716 } 1717 1718 SourceLocation getLParenLoc() const { return LParenLoc; } 1719 SourceLocation getRParenLoc() const { return RParenLoc; } 1720 1721 /// \brief Determine the number of implicit array indices used while 1722 /// described an array member initialization. 1723 unsigned getNumArrayIndices() const { 1724 return IsWritten ? 0 : SourceOrderOrNumArrayIndices; 1725 } 1726 1727 /// \brief Retrieve a particular array index variable used to 1728 /// describe an array member initialization. 1729 VarDecl *getArrayIndex(unsigned I) { 1730 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1731 return reinterpret_cast<VarDecl **>(this + 1)[I]; 1732 } 1733 const VarDecl *getArrayIndex(unsigned I) const { 1734 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1735 return reinterpret_cast<const VarDecl * const *>(this + 1)[I]; 1736 } 1737 void setArrayIndex(unsigned I, VarDecl *Index) { 1738 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 1739 reinterpret_cast<VarDecl **>(this + 1)[I] = Index; 1740 } 1741 1742 /// \brief Get the initializer. This is 0 if this is an in-class initializer 1743 /// for a non-static data member which has not yet been parsed. 1744 Expr *getInit() const { 1745 if (!Init) 1746 return getAnyMember()->getInClassInitializer(); 1747 1748 return static_cast<Expr*>(Init); 1749 } 1750}; 1751 1752/// CXXConstructorDecl - Represents a C++ constructor within a 1753/// class. For example: 1754/// 1755/// @code 1756/// class X { 1757/// public: 1758/// explicit X(int); // represented by a CXXConstructorDecl. 1759/// }; 1760/// @endcode 1761class CXXConstructorDecl : public CXXMethodDecl { 1762 virtual void anchor(); 1763 /// IsExplicitSpecified - Whether this constructor declaration has the 1764 /// 'explicit' keyword specified. 1765 bool IsExplicitSpecified : 1; 1766 1767 /// ImplicitlyDefined - Whether this constructor was implicitly 1768 /// defined by the compiler. When false, the constructor was defined 1769 /// by the user. In C++03, this flag will have the same value as 1770 /// Implicit. In C++0x, however, a constructor that is 1771 /// explicitly defaulted (i.e., defined with " = default") will have 1772 /// @c !Implicit && ImplicitlyDefined. 1773 bool ImplicitlyDefined : 1; 1774 1775 /// Support for base and member initializers. 1776 /// CtorInitializers - The arguments used to initialize the base 1777 /// or member. 1778 CXXCtorInitializer **CtorInitializers; 1779 unsigned NumCtorInitializers; 1780 1781 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 1782 const DeclarationNameInfo &NameInfo, 1783 QualType T, TypeSourceInfo *TInfo, 1784 bool isExplicitSpecified, bool isInline, 1785 bool isImplicitlyDeclared, bool isConstexpr) 1786 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false, 1787 SC_None, isInline, isConstexpr, SourceLocation()), 1788 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false), 1789 CtorInitializers(0), NumCtorInitializers(0) { 1790 setImplicit(isImplicitlyDeclared); 1791 } 1792 1793public: 1794 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1795 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1796 SourceLocation StartLoc, 1797 const DeclarationNameInfo &NameInfo, 1798 QualType T, TypeSourceInfo *TInfo, 1799 bool isExplicit, 1800 bool isInline, bool isImplicitlyDeclared, 1801 bool isConstexpr); 1802 1803 /// isExplicitSpecified - Whether this constructor declaration has the 1804 /// 'explicit' keyword specified. 1805 bool isExplicitSpecified() const { return IsExplicitSpecified; } 1806 1807 /// isExplicit - Whether this constructor was marked "explicit" or not. 1808 bool isExplicit() const { 1809 return cast<CXXConstructorDecl>(getFirstDeclaration()) 1810 ->isExplicitSpecified(); 1811 } 1812 1813 /// isImplicitlyDefined - Whether this constructor was implicitly 1814 /// defined. If false, then this constructor was defined by the 1815 /// user. This operation can only be invoked if the constructor has 1816 /// already been defined. 1817 bool isImplicitlyDefined() const { 1818 assert(isThisDeclarationADefinition() && 1819 "Can only get the implicit-definition flag once the " 1820 "constructor has been defined"); 1821 return ImplicitlyDefined; 1822 } 1823 1824 /// setImplicitlyDefined - Set whether this constructor was 1825 /// implicitly defined or not. 1826 void setImplicitlyDefined(bool ID) { 1827 assert(isThisDeclarationADefinition() && 1828 "Can only set the implicit-definition flag once the constructor " 1829 "has been defined"); 1830 ImplicitlyDefined = ID; 1831 } 1832 1833 /// init_iterator - Iterates through the member/base initializer list. 1834 typedef CXXCtorInitializer **init_iterator; 1835 1836 /// init_const_iterator - Iterates through the memberbase initializer list. 1837 typedef CXXCtorInitializer * const * init_const_iterator; 1838 1839 /// init_begin() - Retrieve an iterator to the first initializer. 1840 init_iterator init_begin() { return CtorInitializers; } 1841 /// begin() - Retrieve an iterator to the first initializer. 1842 init_const_iterator init_begin() const { return CtorInitializers; } 1843 1844 /// init_end() - Retrieve an iterator past the last initializer. 1845 init_iterator init_end() { 1846 return CtorInitializers + NumCtorInitializers; 1847 } 1848 /// end() - Retrieve an iterator past the last initializer. 1849 init_const_iterator init_end() const { 1850 return CtorInitializers + NumCtorInitializers; 1851 } 1852 1853 typedef std::reverse_iterator<init_iterator> init_reverse_iterator; 1854 typedef std::reverse_iterator<init_const_iterator> 1855 init_const_reverse_iterator; 1856 1857 init_reverse_iterator init_rbegin() { 1858 return init_reverse_iterator(init_end()); 1859 } 1860 init_const_reverse_iterator init_rbegin() const { 1861 return init_const_reverse_iterator(init_end()); 1862 } 1863 1864 init_reverse_iterator init_rend() { 1865 return init_reverse_iterator(init_begin()); 1866 } 1867 init_const_reverse_iterator init_rend() const { 1868 return init_const_reverse_iterator(init_begin()); 1869 } 1870 1871 /// getNumArgs - Determine the number of arguments used to 1872 /// initialize the member or base. 1873 unsigned getNumCtorInitializers() const { 1874 return NumCtorInitializers; 1875 } 1876 1877 void setNumCtorInitializers(unsigned numCtorInitializers) { 1878 NumCtorInitializers = numCtorInitializers; 1879 } 1880 1881 void setCtorInitializers(CXXCtorInitializer ** initializers) { 1882 CtorInitializers = initializers; 1883 } 1884 1885 /// isDelegatingConstructor - Whether this constructor is a 1886 /// delegating constructor 1887 bool isDelegatingConstructor() const { 1888 return (getNumCtorInitializers() == 1) && 1889 CtorInitializers[0]->isDelegatingInitializer(); 1890 } 1891 1892 /// getTargetConstructor - When this constructor delegates to 1893 /// another, retrieve the target 1894 CXXConstructorDecl *getTargetConstructor() const; 1895 1896 /// isDefaultConstructor - Whether this constructor is a default 1897 /// constructor (C++ [class.ctor]p5), which can be used to 1898 /// default-initialize a class of this type. 1899 bool isDefaultConstructor() const; 1900 1901 /// isCopyConstructor - Whether this constructor is a copy 1902 /// constructor (C++ [class.copy]p2, which can be used to copy the 1903 /// class. @p TypeQuals will be set to the qualifiers on the 1904 /// argument type. For example, @p TypeQuals would be set to @c 1905 /// QualType::Const for the following copy constructor: 1906 /// 1907 /// @code 1908 /// class X { 1909 /// public: 1910 /// X(const X&); 1911 /// }; 1912 /// @endcode 1913 bool isCopyConstructor(unsigned &TypeQuals) const; 1914 1915 /// isCopyConstructor - Whether this constructor is a copy 1916 /// constructor (C++ [class.copy]p2, which can be used to copy the 1917 /// class. 1918 bool isCopyConstructor() const { 1919 unsigned TypeQuals = 0; 1920 return isCopyConstructor(TypeQuals); 1921 } 1922 1923 /// \brief Determine whether this constructor is a move constructor 1924 /// (C++0x [class.copy]p3), which can be used to move values of the class. 1925 /// 1926 /// \param TypeQuals If this constructor is a move constructor, will be set 1927 /// to the type qualifiers on the referent of the first parameter's type. 1928 bool isMoveConstructor(unsigned &TypeQuals) const; 1929 1930 /// \brief Determine whether this constructor is a move constructor 1931 /// (C++0x [class.copy]p3), which can be used to move values of the class. 1932 bool isMoveConstructor() const { 1933 unsigned TypeQuals = 0; 1934 return isMoveConstructor(TypeQuals); 1935 } 1936 1937 /// \brief Determine whether this is a copy or move constructor. 1938 /// 1939 /// \param TypeQuals Will be set to the type qualifiers on the reference 1940 /// parameter, if in fact this is a copy or move constructor. 1941 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; 1942 1943 /// \brief Determine whether this a copy or move constructor. 1944 bool isCopyOrMoveConstructor() const { 1945 unsigned Quals; 1946 return isCopyOrMoveConstructor(Quals); 1947 } 1948 1949 /// isConvertingConstructor - Whether this constructor is a 1950 /// converting constructor (C++ [class.conv.ctor]), which can be 1951 /// used for user-defined conversions. 1952 bool isConvertingConstructor(bool AllowExplicit) const; 1953 1954 /// \brief Determine whether this is a member template specialization that 1955 /// would copy the object to itself. Such constructors are never used to copy 1956 /// an object. 1957 bool isSpecializationCopyingObject() const; 1958 1959 /// \brief Get the constructor that this inheriting constructor is based on. 1960 const CXXConstructorDecl *getInheritedConstructor() const; 1961 1962 /// \brief Set the constructor that this inheriting constructor is based on. 1963 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor); 1964 1965 const CXXConstructorDecl *getCanonicalDecl() const { 1966 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 1967 } 1968 CXXConstructorDecl *getCanonicalDecl() { 1969 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 1970 } 1971 1972 // Implement isa/cast/dyncast/etc. 1973 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1974 static bool classof(const CXXConstructorDecl *D) { return true; } 1975 static bool classofKind(Kind K) { return K == CXXConstructor; } 1976 1977 friend class ASTDeclReader; 1978 friend class ASTDeclWriter; 1979}; 1980 1981/// CXXDestructorDecl - Represents a C++ destructor within a 1982/// class. For example: 1983/// 1984/// @code 1985/// class X { 1986/// public: 1987/// ~X(); // represented by a CXXDestructorDecl. 1988/// }; 1989/// @endcode 1990class CXXDestructorDecl : public CXXMethodDecl { 1991 virtual void anchor(); 1992 /// ImplicitlyDefined - Whether this destructor was implicitly 1993 /// defined by the compiler. When false, the destructor was defined 1994 /// by the user. In C++03, this flag will have the same value as 1995 /// Implicit. In C++0x, however, a destructor that is 1996 /// explicitly defaulted (i.e., defined with " = default") will have 1997 /// @c !Implicit && ImplicitlyDefined. 1998 bool ImplicitlyDefined : 1; 1999 2000 FunctionDecl *OperatorDelete; 2001 2002 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 2003 const DeclarationNameInfo &NameInfo, 2004 QualType T, TypeSourceInfo *TInfo, 2005 bool isInline, bool isImplicitlyDeclared) 2006 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false, 2007 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()), 2008 ImplicitlyDefined(false), OperatorDelete(0) { 2009 setImplicit(isImplicitlyDeclared); 2010 } 2011 2012public: 2013 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 2014 SourceLocation StartLoc, 2015 const DeclarationNameInfo &NameInfo, 2016 QualType T, TypeSourceInfo* TInfo, 2017 bool isInline, 2018 bool isImplicitlyDeclared); 2019 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); 2020 2021 /// isImplicitlyDefined - Whether this destructor was implicitly 2022 /// defined. If false, then this destructor was defined by the 2023 /// user. This operation can only be invoked if the destructor has 2024 /// already been defined. 2025 bool isImplicitlyDefined() const { 2026 assert(isThisDeclarationADefinition() && 2027 "Can only get the implicit-definition flag once the destructor has " 2028 "been defined"); 2029 return ImplicitlyDefined; 2030 } 2031 2032 /// setImplicitlyDefined - Set whether this destructor was 2033 /// implicitly defined or not. 2034 void setImplicitlyDefined(bool ID) { 2035 assert(isThisDeclarationADefinition() && 2036 "Can only set the implicit-definition flag once the destructor has " 2037 "been defined"); 2038 ImplicitlyDefined = ID; 2039 } 2040 2041 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 2042 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 2043 2044 // Implement isa/cast/dyncast/etc. 2045 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2046 static bool classof(const CXXDestructorDecl *D) { return true; } 2047 static bool classofKind(Kind K) { return K == CXXDestructor; } 2048 2049 friend class ASTDeclReader; 2050 friend class ASTDeclWriter; 2051}; 2052 2053/// CXXConversionDecl - Represents a C++ conversion function within a 2054/// class. For example: 2055/// 2056/// @code 2057/// class X { 2058/// public: 2059/// operator bool(); 2060/// }; 2061/// @endcode 2062class CXXConversionDecl : public CXXMethodDecl { 2063 virtual void anchor(); 2064 /// IsExplicitSpecified - Whether this conversion function declaration is 2065 /// marked "explicit", meaning that it can only be applied when the user 2066 /// explicitly wrote a cast. This is a C++0x feature. 2067 bool IsExplicitSpecified : 1; 2068 2069 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 2070 const DeclarationNameInfo &NameInfo, 2071 QualType T, TypeSourceInfo *TInfo, 2072 bool isInline, bool isExplicitSpecified, 2073 bool isConstexpr, SourceLocation EndLocation) 2074 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false, 2075 SC_None, isInline, isConstexpr, EndLocation), 2076 IsExplicitSpecified(isExplicitSpecified) { } 2077 2078public: 2079 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 2080 SourceLocation StartLoc, 2081 const DeclarationNameInfo &NameInfo, 2082 QualType T, TypeSourceInfo *TInfo, 2083 bool isInline, bool isExplicit, 2084 bool isConstexpr, 2085 SourceLocation EndLocation); 2086 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2087 2088 /// IsExplicitSpecified - Whether this conversion function declaration is 2089 /// marked "explicit", meaning that it can only be applied when the user 2090 /// explicitly wrote a cast. This is a C++0x feature. 2091 bool isExplicitSpecified() const { return IsExplicitSpecified; } 2092 2093 /// isExplicit - Whether this is an explicit conversion operator 2094 /// (C++0x only). Explicit conversion operators are only considered 2095 /// when the user has explicitly written a cast. 2096 bool isExplicit() const { 2097 return cast<CXXConversionDecl>(getFirstDeclaration()) 2098 ->isExplicitSpecified(); 2099 } 2100 2101 /// getConversionType - Returns the type that this conversion 2102 /// function is converting to. 2103 QualType getConversionType() const { 2104 return getType()->getAs<FunctionType>()->getResultType(); 2105 } 2106 2107 // Implement isa/cast/dyncast/etc. 2108 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2109 static bool classof(const CXXConversionDecl *D) { return true; } 2110 static bool classofKind(Kind K) { return K == CXXConversion; } 2111 2112 friend class ASTDeclReader; 2113 friend class ASTDeclWriter; 2114}; 2115 2116/// LinkageSpecDecl - This represents a linkage specification. For example: 2117/// extern "C" void foo(); 2118/// 2119class LinkageSpecDecl : public Decl, public DeclContext { 2120 virtual void anchor(); 2121public: 2122 /// LanguageIDs - Used to represent the language in a linkage 2123 /// specification. The values are part of the serialization abi for 2124 /// ASTs and cannot be changed without altering that abi. To help 2125 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 2126 /// from the dwarf standard. 2127 enum LanguageIDs { 2128 lang_c = /* DW_LANG_C */ 0x0002, 2129 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 2130 }; 2131private: 2132 /// Language - The language for this linkage specification. 2133 LanguageIDs Language; 2134 /// ExternLoc - The source location for the extern keyword. 2135 SourceLocation ExternLoc; 2136 /// RBraceLoc - The source location for the right brace (if valid). 2137 SourceLocation RBraceLoc; 2138 2139 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, 2140 SourceLocation LangLoc, LanguageIDs lang, 2141 SourceLocation RBLoc) 2142 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), 2143 Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { } 2144 2145public: 2146 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 2147 SourceLocation ExternLoc, 2148 SourceLocation LangLoc, LanguageIDs Lang, 2149 SourceLocation RBraceLoc = SourceLocation()); 2150 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2151 2152 /// \brief Return the language specified by this linkage specification. 2153 LanguageIDs getLanguage() const { return Language; } 2154 /// \brief Set the language specified by this linkage specification. 2155 void setLanguage(LanguageIDs L) { Language = L; } 2156 2157 /// \brief Determines whether this linkage specification had braces in 2158 /// its syntactic form. 2159 bool hasBraces() const { return RBraceLoc.isValid(); } 2160 2161 SourceLocation getExternLoc() const { return ExternLoc; } 2162 SourceLocation getRBraceLoc() const { return RBraceLoc; } 2163 void setExternLoc(SourceLocation L) { ExternLoc = L; } 2164 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 2165 2166 SourceLocation getLocEnd() const { 2167 if (hasBraces()) 2168 return getRBraceLoc(); 2169 // No braces: get the end location of the (only) declaration in context 2170 // (if present). 2171 return decls_empty() ? getLocation() : decls_begin()->getLocEnd(); 2172 } 2173 2174 SourceRange getSourceRange() const { 2175 return SourceRange(ExternLoc, getLocEnd()); 2176 } 2177 2178 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2179 static bool classof(const LinkageSpecDecl *D) { return true; } 2180 static bool classofKind(Kind K) { return K == LinkageSpec; } 2181 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 2182 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 2183 } 2184 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 2185 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 2186 } 2187}; 2188 2189/// UsingDirectiveDecl - Represents C++ using-directive. For example: 2190/// 2191/// using namespace std; 2192/// 2193// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 2194// artificial names for all using-directives in order to store 2195// them in DeclContext effectively. 2196class UsingDirectiveDecl : public NamedDecl { 2197 virtual void anchor(); 2198 /// \brief The location of the "using" keyword. 2199 SourceLocation UsingLoc; 2200 2201 /// SourceLocation - Location of 'namespace' token. 2202 SourceLocation NamespaceLoc; 2203 2204 /// \brief The nested-name-specifier that precedes the namespace. 2205 NestedNameSpecifierLoc QualifierLoc; 2206 2207 /// NominatedNamespace - Namespace nominated by using-directive. 2208 NamedDecl *NominatedNamespace; 2209 2210 /// Enclosing context containing both using-directive and nominated 2211 /// namespace. 2212 DeclContext *CommonAncestor; 2213 2214 /// getUsingDirectiveName - Returns special DeclarationName used by 2215 /// using-directives. This is only used by DeclContext for storing 2216 /// UsingDirectiveDecls in its lookup structure. 2217 static DeclarationName getName() { 2218 return DeclarationName::getUsingDirectiveName(); 2219 } 2220 2221 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, 2222 SourceLocation NamespcLoc, 2223 NestedNameSpecifierLoc QualifierLoc, 2224 SourceLocation IdentLoc, 2225 NamedDecl *Nominated, 2226 DeclContext *CommonAncestor) 2227 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), 2228 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), 2229 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { } 2230 2231public: 2232 /// \brief Retrieve the nested-name-specifier that qualifies the 2233 /// name of the namespace, with source-location information. 2234 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2235 2236 /// \brief Retrieve the nested-name-specifier that qualifies the 2237 /// name of the namespace. 2238 NestedNameSpecifier *getQualifier() const { 2239 return QualifierLoc.getNestedNameSpecifier(); 2240 } 2241 2242 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 2243 const NamedDecl *getNominatedNamespaceAsWritten() const { 2244 return NominatedNamespace; 2245 } 2246 2247 /// getNominatedNamespace - Returns namespace nominated by using-directive. 2248 NamespaceDecl *getNominatedNamespace(); 2249 2250 const NamespaceDecl *getNominatedNamespace() const { 2251 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 2252 } 2253 2254 /// \brief Returns the common ancestor context of this using-directive and 2255 /// its nominated namespace. 2256 DeclContext *getCommonAncestor() { return CommonAncestor; } 2257 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 2258 2259 /// \brief Return the location of the "using" keyword. 2260 SourceLocation getUsingLoc() const { return UsingLoc; } 2261 2262 // FIXME: Could omit 'Key' in name. 2263 /// getNamespaceKeyLocation - Returns location of namespace keyword. 2264 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 2265 2266 /// getIdentLocation - Returns location of identifier. 2267 SourceLocation getIdentLocation() const { return getLocation(); } 2268 2269 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 2270 SourceLocation UsingLoc, 2271 SourceLocation NamespaceLoc, 2272 NestedNameSpecifierLoc QualifierLoc, 2273 SourceLocation IdentLoc, 2274 NamedDecl *Nominated, 2275 DeclContext *CommonAncestor); 2276 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2277 2278 SourceRange getSourceRange() const { 2279 return SourceRange(UsingLoc, getLocation()); 2280 } 2281 2282 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2283 static bool classof(const UsingDirectiveDecl *D) { return true; } 2284 static bool classofKind(Kind K) { return K == UsingDirective; } 2285 2286 // Friend for getUsingDirectiveName. 2287 friend class DeclContext; 2288 2289 friend class ASTDeclReader; 2290}; 2291 2292/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 2293/// 2294/// @code 2295/// namespace Foo = Bar; 2296/// @endcode 2297class NamespaceAliasDecl : public NamedDecl { 2298 virtual void anchor(); 2299 2300 /// \brief The location of the "namespace" keyword. 2301 SourceLocation NamespaceLoc; 2302 2303 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc. 2304 SourceLocation IdentLoc; 2305 2306 /// \brief The nested-name-specifier that precedes the namespace. 2307 NestedNameSpecifierLoc QualifierLoc; 2308 2309 /// Namespace - The Decl that this alias points to. Can either be a 2310 /// NamespaceDecl or a NamespaceAliasDecl. 2311 NamedDecl *Namespace; 2312 2313 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc, 2314 SourceLocation AliasLoc, IdentifierInfo *Alias, 2315 NestedNameSpecifierLoc QualifierLoc, 2316 SourceLocation IdentLoc, NamedDecl *Namespace) 2317 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), 2318 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), 2319 QualifierLoc(QualifierLoc), Namespace(Namespace) { } 2320 2321 friend class ASTDeclReader; 2322 2323public: 2324 /// \brief Retrieve the nested-name-specifier that qualifies the 2325 /// name of the namespace, with source-location information. 2326 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2327 2328 /// \brief Retrieve the nested-name-specifier that qualifies the 2329 /// name of the namespace. 2330 NestedNameSpecifier *getQualifier() const { 2331 return QualifierLoc.getNestedNameSpecifier(); 2332 } 2333 2334 /// \brief Retrieve the namespace declaration aliased by this directive. 2335 NamespaceDecl *getNamespace() { 2336 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 2337 return AD->getNamespace(); 2338 2339 return cast<NamespaceDecl>(Namespace); 2340 } 2341 2342 const NamespaceDecl *getNamespace() const { 2343 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 2344 } 2345 2346 /// Returns the location of the alias name, i.e. 'foo' in 2347 /// "namespace foo = ns::bar;". 2348 SourceLocation getAliasLoc() const { return getLocation(); } 2349 2350 /// Returns the location of the 'namespace' keyword. 2351 SourceLocation getNamespaceLoc() const { return NamespaceLoc; } 2352 2353 /// Returns the location of the identifier in the named namespace. 2354 SourceLocation getTargetNameLoc() const { return IdentLoc; } 2355 2356 /// \brief Retrieve the namespace that this alias refers to, which 2357 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 2358 NamedDecl *getAliasedNamespace() const { return Namespace; } 2359 2360 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 2361 SourceLocation NamespaceLoc, 2362 SourceLocation AliasLoc, 2363 IdentifierInfo *Alias, 2364 NestedNameSpecifierLoc QualifierLoc, 2365 SourceLocation IdentLoc, 2366 NamedDecl *Namespace); 2367 2368 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2369 2370 virtual SourceRange getSourceRange() const { 2371 return SourceRange(NamespaceLoc, IdentLoc); 2372 } 2373 2374 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2375 static bool classof(const NamespaceAliasDecl *D) { return true; } 2376 static bool classofKind(Kind K) { return K == NamespaceAlias; } 2377}; 2378 2379/// UsingShadowDecl - Represents a shadow declaration introduced into 2380/// a scope by a (resolved) using declaration. For example, 2381/// 2382/// namespace A { 2383/// void foo(); 2384/// } 2385/// namespace B { 2386/// using A::foo(); // <- a UsingDecl 2387/// // Also creates a UsingShadowDecl for A::foo in B 2388/// } 2389/// 2390class UsingShadowDecl : public NamedDecl { 2391 virtual void anchor(); 2392 2393 /// The referenced declaration. 2394 NamedDecl *Underlying; 2395 2396 /// \brief The using declaration which introduced this decl or the next using 2397 /// shadow declaration contained in the aforementioned using declaration. 2398 NamedDecl *UsingOrNextShadow; 2399 friend class UsingDecl; 2400 2401 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 2402 NamedDecl *Target) 2403 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()), 2404 Underlying(Target), 2405 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) { 2406 if (Target) { 2407 setDeclName(Target->getDeclName()); 2408 IdentifierNamespace = Target->getIdentifierNamespace(); 2409 } 2410 setImplicit(); 2411 } 2412 2413public: 2414 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 2415 SourceLocation Loc, UsingDecl *Using, 2416 NamedDecl *Target) { 2417 return new (C) UsingShadowDecl(DC, Loc, Using, Target); 2418 } 2419 2420 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2421 2422 /// \brief Gets the underlying declaration which has been brought into the 2423 /// local scope. 2424 NamedDecl *getTargetDecl() const { return Underlying; } 2425 2426 /// \brief Sets the underlying declaration which has been brought into the 2427 /// local scope. 2428 void setTargetDecl(NamedDecl* ND) { 2429 assert(ND && "Target decl is null!"); 2430 Underlying = ND; 2431 IdentifierNamespace = ND->getIdentifierNamespace(); 2432 } 2433 2434 /// \brief Gets the using declaration to which this declaration is tied. 2435 UsingDecl *getUsingDecl() const; 2436 2437 /// \brief The next using shadow declaration contained in the shadow decl 2438 /// chain of the using declaration which introduced this decl. 2439 UsingShadowDecl *getNextUsingShadowDecl() const { 2440 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); 2441 } 2442 2443 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2444 static bool classof(const UsingShadowDecl *D) { return true; } 2445 static bool classofKind(Kind K) { return K == Decl::UsingShadow; } 2446 2447 friend class ASTDeclReader; 2448 friend class ASTDeclWriter; 2449}; 2450 2451/// UsingDecl - Represents a C++ using-declaration. For example: 2452/// using someNameSpace::someIdentifier; 2453class UsingDecl : public NamedDecl { 2454 virtual void anchor(); 2455 2456 /// \brief The source location of the "using" location itself. 2457 SourceLocation UsingLocation; 2458 2459 /// \brief The nested-name-specifier that precedes the name. 2460 NestedNameSpecifierLoc QualifierLoc; 2461 2462 /// DNLoc - Provides source/type location info for the 2463 /// declaration name embedded in the ValueDecl base class. 2464 DeclarationNameLoc DNLoc; 2465 2466 /// \brief The first shadow declaration of the shadow decl chain associated 2467 /// with this using declaration. 2468 UsingShadowDecl *FirstUsingShadow; 2469 2470 // \brief Has 'typename' keyword. 2471 bool IsTypeName; 2472 2473 UsingDecl(DeclContext *DC, SourceLocation UL, 2474 NestedNameSpecifierLoc QualifierLoc, 2475 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg) 2476 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), 2477 UsingLocation(UL), QualifierLoc(QualifierLoc), 2478 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg) { 2479 } 2480 2481public: 2482 /// \brief Returns the source location of the "using" keyword. 2483 SourceLocation getUsingLocation() const { return UsingLocation; } 2484 2485 /// \brief Set the source location of the 'using' keyword. 2486 void setUsingLocation(SourceLocation L) { UsingLocation = L; } 2487 2488 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2489 /// with source-location information. 2490 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2491 2492 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2493 NestedNameSpecifier *getQualifier() const { 2494 return QualifierLoc.getNestedNameSpecifier(); 2495 } 2496 2497 DeclarationNameInfo getNameInfo() const { 2498 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2499 } 2500 2501 /// \brief Return true if the using declaration has 'typename'. 2502 bool isTypeName() const { return IsTypeName; } 2503 2504 /// \brief Sets whether the using declaration has 'typename'. 2505 void setTypeName(bool TN) { IsTypeName = TN; } 2506 2507 /// \brief Iterates through the using shadow declarations assosiated with 2508 /// this using declaration. 2509 class shadow_iterator { 2510 /// \brief The current using shadow declaration. 2511 UsingShadowDecl *Current; 2512 2513 public: 2514 typedef UsingShadowDecl* value_type; 2515 typedef UsingShadowDecl* reference; 2516 typedef UsingShadowDecl* pointer; 2517 typedef std::forward_iterator_tag iterator_category; 2518 typedef std::ptrdiff_t difference_type; 2519 2520 shadow_iterator() : Current(0) { } 2521 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { } 2522 2523 reference operator*() const { return Current; } 2524 pointer operator->() const { return Current; } 2525 2526 shadow_iterator& operator++() { 2527 Current = Current->getNextUsingShadowDecl(); 2528 return *this; 2529 } 2530 2531 shadow_iterator operator++(int) { 2532 shadow_iterator tmp(*this); 2533 ++(*this); 2534 return tmp; 2535 } 2536 2537 friend bool operator==(shadow_iterator x, shadow_iterator y) { 2538 return x.Current == y.Current; 2539 } 2540 friend bool operator!=(shadow_iterator x, shadow_iterator y) { 2541 return x.Current != y.Current; 2542 } 2543 }; 2544 2545 shadow_iterator shadow_begin() const { 2546 return shadow_iterator(FirstUsingShadow); 2547 } 2548 shadow_iterator shadow_end() const { return shadow_iterator(); } 2549 2550 /// \brief Return the number of shadowed declarations associated with this 2551 /// using declaration. 2552 unsigned shadow_size() const { 2553 return std::distance(shadow_begin(), shadow_end()); 2554 } 2555 2556 void addShadowDecl(UsingShadowDecl *S); 2557 void removeShadowDecl(UsingShadowDecl *S); 2558 2559 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 2560 SourceLocation UsingL, 2561 NestedNameSpecifierLoc QualifierLoc, 2562 const DeclarationNameInfo &NameInfo, 2563 bool IsTypeNameArg); 2564 2565 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2566 2567 SourceRange getSourceRange() const { 2568 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 2569 } 2570 2571 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2572 static bool classof(const UsingDecl *D) { return true; } 2573 static bool classofKind(Kind K) { return K == Using; } 2574 2575 friend class ASTDeclReader; 2576 friend class ASTDeclWriter; 2577}; 2578 2579/// UnresolvedUsingValueDecl - Represents a dependent using 2580/// declaration which was not marked with 'typename'. Unlike 2581/// non-dependent using declarations, these *only* bring through 2582/// non-types; otherwise they would break two-phase lookup. 2583/// 2584/// template <class T> class A : public Base<T> { 2585/// using Base<T>::foo; 2586/// }; 2587class UnresolvedUsingValueDecl : public ValueDecl { 2588 virtual void anchor(); 2589 2590 /// \brief The source location of the 'using' keyword 2591 SourceLocation UsingLocation; 2592 2593 /// \brief The nested-name-specifier that precedes the name. 2594 NestedNameSpecifierLoc QualifierLoc; 2595 2596 /// DNLoc - Provides source/type location info for the 2597 /// declaration name embedded in the ValueDecl base class. 2598 DeclarationNameLoc DNLoc; 2599 2600 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 2601 SourceLocation UsingLoc, 2602 NestedNameSpecifierLoc QualifierLoc, 2603 const DeclarationNameInfo &NameInfo) 2604 : ValueDecl(UnresolvedUsingValue, DC, 2605 NameInfo.getLoc(), NameInfo.getName(), Ty), 2606 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc), 2607 DNLoc(NameInfo.getInfo()) 2608 { } 2609 2610public: 2611 /// \brief Returns the source location of the 'using' keyword. 2612 SourceLocation getUsingLoc() const { return UsingLocation; } 2613 2614 /// \brief Set the source location of the 'using' keyword. 2615 void setUsingLoc(SourceLocation L) { UsingLocation = L; } 2616 2617 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2618 /// with source-location information. 2619 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2620 2621 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2622 NestedNameSpecifier *getQualifier() const { 2623 return QualifierLoc.getNestedNameSpecifier(); 2624 } 2625 2626 DeclarationNameInfo getNameInfo() const { 2627 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 2628 } 2629 2630 static UnresolvedUsingValueDecl * 2631 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2632 NestedNameSpecifierLoc QualifierLoc, 2633 const DeclarationNameInfo &NameInfo); 2634 2635 static UnresolvedUsingValueDecl * 2636 CreateDeserialized(ASTContext &C, unsigned ID); 2637 2638 SourceRange getSourceRange() const { 2639 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 2640 } 2641 2642 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2643 static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 2644 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } 2645 2646 friend class ASTDeclReader; 2647 friend class ASTDeclWriter; 2648}; 2649 2650/// UnresolvedUsingTypenameDecl - Represents a dependent using 2651/// declaration which was marked with 'typename'. 2652/// 2653/// template <class T> class A : public Base<T> { 2654/// using typename Base<T>::foo; 2655/// }; 2656/// 2657/// The type associated with a unresolved using typename decl is 2658/// currently always a typename type. 2659class UnresolvedUsingTypenameDecl : public TypeDecl { 2660 virtual void anchor(); 2661 2662 /// \brief The source location of the 'using' keyword 2663 SourceLocation UsingLocation; 2664 2665 /// \brief The source location of the 'typename' keyword 2666 SourceLocation TypenameLocation; 2667 2668 /// \brief The nested-name-specifier that precedes the name. 2669 NestedNameSpecifierLoc QualifierLoc; 2670 2671 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 2672 SourceLocation TypenameLoc, 2673 NestedNameSpecifierLoc QualifierLoc, 2674 SourceLocation TargetNameLoc, 2675 IdentifierInfo *TargetName) 2676 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, 2677 UsingLoc), 2678 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { } 2679 2680 friend class ASTDeclReader; 2681 2682public: 2683 /// \brief Returns the source location of the 'using' keyword. 2684 SourceLocation getUsingLoc() const { return getLocStart(); } 2685 2686 /// \brief Returns the source location of the 'typename' keyword. 2687 SourceLocation getTypenameLoc() const { return TypenameLocation; } 2688 2689 /// \brief Retrieve the nested-name-specifier that qualifies the name, 2690 /// with source-location information. 2691 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2692 2693 /// \brief Retrieve the nested-name-specifier that qualifies the name. 2694 NestedNameSpecifier *getQualifier() const { 2695 return QualifierLoc.getNestedNameSpecifier(); 2696 } 2697 2698 static UnresolvedUsingTypenameDecl * 2699 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 2700 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, 2701 SourceLocation TargetNameLoc, DeclarationName TargetName); 2702 2703 static UnresolvedUsingTypenameDecl * 2704 CreateDeserialized(ASTContext &C, unsigned ID); 2705 2706 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2707 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 2708 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } 2709}; 2710 2711/// StaticAssertDecl - Represents a C++0x static_assert declaration. 2712class StaticAssertDecl : public Decl { 2713 virtual void anchor(); 2714 Expr *AssertExpr; 2715 StringLiteral *Message; 2716 SourceLocation RParenLoc; 2717 2718 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, 2719 Expr *assertexpr, StringLiteral *message, 2720 SourceLocation RParenLoc) 2721 : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr), 2722 Message(message), RParenLoc(RParenLoc) { } 2723 2724public: 2725 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 2726 SourceLocation StaticAssertLoc, 2727 Expr *AssertExpr, StringLiteral *Message, 2728 SourceLocation RParenLoc); 2729 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2730 2731 Expr *getAssertExpr() { return AssertExpr; } 2732 const Expr *getAssertExpr() const { return AssertExpr; } 2733 2734 StringLiteral *getMessage() { return Message; } 2735 const StringLiteral *getMessage() const { return Message; } 2736 2737 SourceLocation getRParenLoc() const { return RParenLoc; } 2738 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2739 2740 SourceRange getSourceRange() const { 2741 return SourceRange(getLocation(), getRParenLoc()); 2742 } 2743 2744 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2745 static bool classof(StaticAssertDecl *D) { return true; } 2746 static bool classofKind(Kind K) { return K == StaticAssert; } 2747 2748 friend class ASTDeclReader; 2749}; 2750 2751/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 2752/// into a diagnostic with <<. 2753const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 2754 AccessSpecifier AS); 2755 2756} // end namespace clang 2757 2758#endif 2759