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