DeclCXX.h revision 223017
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/SmallVector.h" 23#include "llvm/ADT/SmallPtrSet.h" 24 25namespace clang { 26 27class ClassTemplateDecl; 28class ClassTemplateSpecializationDecl; 29class CXXBasePath; 30class CXXBasePaths; 31class CXXConstructorDecl; 32class CXXConversionDecl; 33class CXXDestructorDecl; 34class CXXMethodDecl; 35class CXXRecordDecl; 36class CXXMemberLookupCriteria; 37class CXXFinalOverriderMap; 38class CXXIndirectPrimaryBaseSet; 39class FriendDecl; 40 41/// \brief Represents any kind of function declaration, whether it is a 42/// concrete function or a function template. 43class AnyFunctionDecl { 44 NamedDecl *Function; 45 46 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 47 48public: 49 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 50 AnyFunctionDecl(FunctionTemplateDecl *FTD); 51 52 /// \brief Implicily converts any function or function template into a 53 /// named declaration. 54 operator NamedDecl *() const { return Function; } 55 56 /// \brief Retrieve the underlying function or function template. 57 NamedDecl *get() const { return Function; } 58 59 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 60 return AnyFunctionDecl(ND); 61 } 62}; 63 64} // end namespace clang 65 66namespace llvm { 67 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 68 /// AnyFunctionDecl to any function or function template declaration. 69 template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 70 typedef ::clang::NamedDecl* SimpleType; 71 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 72 return Val; 73 } 74 }; 75 template<> struct simplify_type< ::clang::AnyFunctionDecl> 76 : public simplify_type<const ::clang::AnyFunctionDecl> {}; 77 78 // Provide PointerLikeTypeTraits for non-cvr pointers. 79 template<> 80 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 81 public: 82 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 83 return F.get(); 84 } 85 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 86 return ::clang::AnyFunctionDecl::getFromNamedDecl( 87 static_cast< ::clang::NamedDecl*>(P)); 88 } 89 90 enum { NumLowBitsAvailable = 2 }; 91 }; 92 93} // end namespace llvm 94 95namespace clang { 96 97/// AccessSpecDecl - An access specifier followed by colon ':'. 98/// 99/// An objects of this class represents sugar for the syntactic occurrence 100/// of an access specifier followed by a colon in the list of member 101/// specifiers of a C++ class definition. 102/// 103/// Note that they do not represent other uses of access specifiers, 104/// such as those occurring in a list of base specifiers. 105/// Also note that this class has nothing to do with so-called 106/// "access declarations" (C++98 11.3 [class.access.dcl]). 107class AccessSpecDecl : public Decl { 108 /// ColonLoc - The location of the ':'. 109 SourceLocation ColonLoc; 110 111 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, 112 SourceLocation ASLoc, SourceLocation ColonLoc) 113 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { 114 setAccess(AS); 115 } 116 AccessSpecDecl(EmptyShell Empty) 117 : Decl(AccessSpec, Empty) { } 118public: 119 /// getAccessSpecifierLoc - The location of the access specifier. 120 SourceLocation getAccessSpecifierLoc() const { return getLocation(); } 121 /// setAccessSpecifierLoc - Sets the location of the access specifier. 122 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } 123 124 /// getColonLoc - The location of the colon following the access specifier. 125 SourceLocation getColonLoc() const { return ColonLoc; } 126 /// setColonLoc - Sets the location of the colon. 127 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } 128 129 SourceRange getSourceRange() const { 130 return SourceRange(getAccessSpecifierLoc(), getColonLoc()); 131 } 132 133 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, 134 DeclContext *DC, SourceLocation ASLoc, 135 SourceLocation ColonLoc) { 136 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); 137 } 138 static AccessSpecDecl *Create(ASTContext &C, EmptyShell Empty) { 139 return new (C) AccessSpecDecl(Empty); 140 } 141 142 // Implement isa/cast/dyncast/etc. 143 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 144 static bool classof(const AccessSpecDecl *D) { return true; } 145 static bool classofKind(Kind K) { return K == AccessSpec; } 146}; 147 148 149/// CXXBaseSpecifier - A base class of a C++ class. 150/// 151/// Each CXXBaseSpecifier represents a single, direct base class (or 152/// struct) of a C++ class (or struct). It specifies the type of that 153/// base class, whether it is a virtual or non-virtual base, and what 154/// level of access (public, protected, private) is used for the 155/// derivation. For example: 156/// 157/// @code 158/// class A { }; 159/// class B { }; 160/// class C : public virtual A, protected B { }; 161/// @endcode 162/// 163/// In this code, C will have two CXXBaseSpecifiers, one for "public 164/// virtual A" and the other for "protected B". 165class CXXBaseSpecifier { 166 /// Range - The source code range that covers the full base 167 /// specifier, including the "virtual" (if present) and access 168 /// specifier (if present). 169 SourceRange Range; 170 171 /// \brief The source location of the ellipsis, if this is a pack 172 /// expansion. 173 SourceLocation EllipsisLoc; 174 175 /// Virtual - Whether this is a virtual base class or not. 176 bool Virtual : 1; 177 178 /// BaseOfClass - Whether this is the base of a class (true) or of a 179 /// struct (false). This determines the mapping from the access 180 /// specifier as written in the source code to the access specifier 181 /// used for semantic analysis. 182 bool BaseOfClass : 1; 183 184 /// Access - Access specifier as written in the source code (which 185 /// may be AS_none). The actual type of data stored here is an 186 /// AccessSpecifier, but we use "unsigned" here to work around a 187 /// VC++ bug. 188 unsigned Access : 2; 189 190 /// InheritConstructors - Whether the class contains a using declaration 191 /// to inherit the named class's constructors. 192 bool InheritConstructors : 1; 193 194 /// BaseTypeInfo - The type of the base class. This will be a class or struct 195 /// (or a typedef of such). The source code range does not include the 196 /// "virtual" or access specifier. 197 TypeSourceInfo *BaseTypeInfo; 198 199public: 200 CXXBaseSpecifier() { } 201 202 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, 203 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) 204 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), 205 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { } 206 207 /// getSourceRange - Retrieves the source range that contains the 208 /// entire base specifier. 209 SourceRange getSourceRange() const { return Range; } 210 211 /// isVirtual - Determines whether the base class is a virtual base 212 /// class (or not). 213 bool isVirtual() const { return Virtual; } 214 215 /// \brief Determine whether this base class is a base of a class declared 216 /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 217 bool isBaseOfClass() const { return BaseOfClass; } 218 219 /// \brief Determine whether this base specifier is a pack expansion. 220 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 221 222 /// \brief Determine whether this base class's constructors get inherited. 223 bool getInheritConstructors() const { return InheritConstructors; } 224 225 /// \brief Set that this base class's constructors should be inherited. 226 void setInheritConstructors(bool Inherit = true) { 227 InheritConstructors = Inherit; 228 } 229 230 /// \brief For a pack expansion, determine the location of the ellipsis. 231 SourceLocation getEllipsisLoc() const { 232 return EllipsisLoc; 233 } 234 235 /// getAccessSpecifier - Returns the access specifier for this base 236 /// specifier. This is the actual base specifier as used for 237 /// semantic analysis, so the result can never be AS_none. To 238 /// retrieve the access specifier as written in the source code, use 239 /// getAccessSpecifierAsWritten(). 240 AccessSpecifier getAccessSpecifier() const { 241 if ((AccessSpecifier)Access == AS_none) 242 return BaseOfClass? AS_private : AS_public; 243 else 244 return (AccessSpecifier)Access; 245 } 246 247 /// getAccessSpecifierAsWritten - Retrieves the access specifier as 248 /// written in the source code (which may mean that no access 249 /// specifier was explicitly written). Use getAccessSpecifier() to 250 /// retrieve the access specifier for use in semantic analysis. 251 AccessSpecifier getAccessSpecifierAsWritten() const { 252 return (AccessSpecifier)Access; 253 } 254 255 /// getType - Retrieves the type of the base class. This type will 256 /// always be an unqualified class type. 257 QualType getType() const { return BaseTypeInfo->getType(); } 258 259 /// getTypeLoc - Retrieves the type and source location of the base class. 260 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } 261}; 262 263/// CXXRecordDecl - Represents a C++ struct/union/class. 264/// FIXME: This class will disappear once we've properly taught RecordDecl 265/// to deal with C++-specific things. 266class CXXRecordDecl : public RecordDecl { 267 268 friend void TagDecl::startDefinition(); 269 270 struct DefinitionData { 271 DefinitionData(CXXRecordDecl *D); 272 273 /// UserDeclaredConstructor - True when this class has a 274 /// user-declared constructor. 275 bool UserDeclaredConstructor : 1; 276 277 /// UserDeclaredCopyConstructor - True when this class has a 278 /// user-declared copy constructor. 279 bool UserDeclaredCopyConstructor : 1; 280 281 /// UserDeclareMoveConstructor - True when this class has a 282 /// user-declared move constructor. 283 bool UserDeclaredMoveConstructor : 1; 284 285 /// UserDeclaredCopyAssignment - True when this class has a 286 /// user-declared copy assignment operator. 287 bool UserDeclaredCopyAssignment : 1; 288 289 /// UserDeclareMoveAssignment - True when this class has a 290 /// user-declared move assignment. 291 bool UserDeclaredMoveAssignment : 1; 292 293 /// UserDeclaredDestructor - True when this class has a 294 /// user-declared destructor. 295 bool UserDeclaredDestructor : 1; 296 297 /// Aggregate - True when this class is an aggregate. 298 bool Aggregate : 1; 299 300 /// PlainOldData - True when this class is a POD-type. 301 bool PlainOldData : 1; 302 303 /// Empty - true when this class is empty for traits purposes, 304 /// i.e. has no data members other than 0-width bit-fields, has no 305 /// virtual function/base, and doesn't inherit from a non-empty 306 /// class. Doesn't take union-ness into account. 307 bool Empty : 1; 308 309 /// Polymorphic - True when this class is polymorphic, i.e. has at 310 /// least one virtual member or derives from a polymorphic class. 311 bool Polymorphic : 1; 312 313 /// Abstract - True when this class is abstract, i.e. has at least 314 /// one pure virtual function, (that can come from a base class). 315 bool Abstract : 1; 316 317 /// IsStandardLayout - True when this class has standard layout. 318 /// 319 /// C++0x [class]p7. A standard-layout class is a class that: 320 /// * has no non-static data members of type non-standard-layout class (or 321 /// array of such types) or reference, 322 /// * has no virtual functions (10.3) and no virtual base classes (10.1), 323 /// * has the same access control (Clause 11) for all non-static data members 324 /// * has no non-standard-layout base classes, 325 /// * either has no non-static data members in the most derived class and at 326 /// most one base class with non-static data members, or has no base 327 /// classes with non-static data members, and 328 /// * has no base classes of the same type as the first non-static data 329 /// member. 330 bool IsStandardLayout : 1; 331 332 /// HasNoNonEmptyBases - True when there are no non-empty base classes. 333 /// 334 /// This is a helper bit of state used to implement IsStandardLayout more 335 /// efficiently. 336 bool HasNoNonEmptyBases : 1; 337 338 /// HasPrivateFields - True when there are private non-static data members. 339 bool HasPrivateFields : 1; 340 341 /// HasProtectedFields - True when there are protected non-static data 342 /// members. 343 bool HasProtectedFields : 1; 344 345 /// HasPublicFields - True when there are private non-static data members. 346 bool HasPublicFields : 1; 347 348 /// \brief True if this class (or any subobject) has mutable fields. 349 bool HasMutableFields : 1; 350 351 /// HasTrivialDefaultConstructor - True when, if this class has a default 352 /// constructor, this default constructor is trivial. 353 /// 354 /// C++0x [class.ctor]p5 355 /// A default constructor is trivial if it is not user-provided and if 356 /// -- its class has no virtual functions and no virtual base classes, 357 /// and 358 /// -- no non-static data member of its class has a 359 /// brace-or-equal-initializer, and 360 /// -- all the direct base classes of its class have trivial 361 /// default constructors, and 362 /// -- for all the nonstatic data members of its class that are of class 363 /// type (or array thereof), each such class has a trivial 364 /// default constructor. 365 bool HasTrivialDefaultConstructor : 1; 366 367 /// HasConstExprNonCopyMoveConstructor - True when this class has at least 368 /// one constexpr constructor which is neither the copy nor move 369 /// constructor. 370 bool HasConstExprNonCopyMoveConstructor : 1; 371 372 /// HasTrivialCopyConstructor - True when this class has a trivial copy 373 /// constructor. 374 /// 375 /// C++0x [class.copy]p13: 376 /// A copy/move constructor for class X is trivial if it is neither 377 /// user-provided and if 378 /// -- class X has no virtual functions and no virtual base classes, and 379 /// -- the constructor selected to copy/move each direct base class 380 /// subobject is trivial, and 381 /// -- for each non-static data member of X that is of class type (or an 382 /// array thereof), the constructor selected to copy/move that member 383 /// is trivial; 384 /// otherwise the copy/move constructor is non-trivial. 385 bool HasTrivialCopyConstructor : 1; 386 387 /// HasTrivialMoveConstructor - True when this class has a trivial move 388 /// constructor. 389 /// 390 /// C++0x [class.copy]p13: 391 /// A copy/move constructor for class X is trivial if it is neither 392 /// user-provided and if 393 /// -- class X has no virtual functions and no virtual base classes, and 394 /// -- the constructor selected to copy/move each direct base class 395 /// subobject is trivial, and 396 /// -- for each non-static data member of X that is of class type (or an 397 /// array thereof), the constructor selected to copy/move that member 398 /// is trivial; 399 /// otherwise the copy/move constructor is non-trivial. 400 bool HasTrivialMoveConstructor : 1; 401 402 /// HasTrivialCopyAssignment - True when this class has a trivial copy 403 /// assignment operator. 404 /// 405 /// C++0x [class.copy]p27: 406 /// A copy/move assignment operator for class X is trivial if it is 407 /// neither user-provided nor deleted and if 408 /// -- class X has no virtual functions and no virtual base classes, and 409 /// -- the assignment operator selected to copy/move each direct base 410 /// class subobject is trivial, and 411 /// -- for each non-static data member of X that is of class type (or an 412 /// array thereof), the assignment operator selected to copy/move 413 /// that member is trivial; 414 /// otherwise the copy/move assignment operator is non-trivial. 415 bool HasTrivialCopyAssignment : 1; 416 417 /// HasTrivialMoveAssignment - True when this class has a trivial move 418 /// assignment operator. 419 /// 420 /// C++0x [class.copy]p27: 421 /// A copy/move assignment operator for class X is trivial if it is 422 /// neither user-provided nor deleted and if 423 /// -- class X has no virtual functions and no virtual base classes, and 424 /// -- the assignment operator selected to copy/move each direct base 425 /// class subobject is trivial, and 426 /// -- for each non-static data member of X that is of class type (or an 427 /// array thereof), the assignment operator selected to copy/move 428 /// that member is trivial; 429 /// otherwise the copy/move assignment operator is non-trivial. 430 bool HasTrivialMoveAssignment : 1; 431 432 /// HasTrivialDestructor - True when this class has a trivial destructor. 433 /// 434 /// C++ [class.dtor]p3. A destructor is trivial if it is an 435 /// implicitly-declared destructor and if: 436 /// * all of the direct base classes of its class have trivial destructors 437 /// and 438 /// * for all of the non-static data members of its class that are of class 439 /// type (or array thereof), each such class has a trivial destructor. 440 bool HasTrivialDestructor : 1; 441 442 /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least 443 /// one non-static data member or base class of non literal type. 444 bool HasNonLiteralTypeFieldsOrBases : 1; 445 446 /// ComputedVisibleConversions - True when visible conversion functions are 447 /// already computed and are available. 448 bool ComputedVisibleConversions : 1; 449 450 /// \brief Whether we have a C++0x user-provided default constructor (not 451 /// explicitly deleted or defaulted). 452 bool UserProvidedDefaultConstructor : 1; 453 454 /// \brief Whether we have already declared the default constructor. 455 bool DeclaredDefaultConstructor : 1; 456 457 /// \brief Whether we have already declared the copy constructor. 458 bool DeclaredCopyConstructor : 1; 459 460 /// \brief Whether we have already declared the move constructor. 461 bool DeclaredMoveConstructor : 1; 462 463 /// \brief Whether we have already declared the copy-assignment operator. 464 bool DeclaredCopyAssignment : 1; 465 466 /// \brief Whether we have already declared the move-assignment operator. 467 bool DeclaredMoveAssignment : 1; 468 469 /// \brief Whether we have already declared a destructor within the class. 470 bool DeclaredDestructor : 1; 471 472 /// NumBases - The number of base class specifiers in Bases. 473 unsigned NumBases; 474 475 /// NumVBases - The number of virtual base class specifiers in VBases. 476 unsigned NumVBases; 477 478 /// Bases - Base classes of this class. 479 /// FIXME: This is wasted space for a union. 480 LazyCXXBaseSpecifiersPtr Bases; 481 482 /// VBases - direct and indirect virtual base classes of this class. 483 LazyCXXBaseSpecifiersPtr VBases; 484 485 /// Conversions - Overload set containing the conversion functions 486 /// of this C++ class (but not its inherited conversion 487 /// functions). Each of the entries in this overload set is a 488 /// CXXConversionDecl. 489 UnresolvedSet<4> Conversions; 490 491 /// VisibleConversions - Overload set containing the conversion 492 /// functions of this C++ class and all those inherited conversion 493 /// functions that are visible in this class. Each of the entries 494 /// in this overload set is a CXXConversionDecl or a 495 /// FunctionTemplateDecl. 496 UnresolvedSet<4> VisibleConversions; 497 498 /// Definition - The declaration which defines this record. 499 CXXRecordDecl *Definition; 500 501 /// FirstFriend - The first friend declaration in this class, or 502 /// null if there aren't any. This is actually currently stored 503 /// in reverse order. 504 FriendDecl *FirstFriend; 505 506 /// \brief Retrieve the set of direct base classes. 507 CXXBaseSpecifier *getBases() const { 508 return Bases.get(Definition->getASTContext().getExternalSource()); 509 } 510 511 /// \brief Retrieve the set of virtual base classes. 512 CXXBaseSpecifier *getVBases() const { 513 return VBases.get(Definition->getASTContext().getExternalSource()); 514 } 515 } *DefinitionData; 516 517 struct DefinitionData &data() { 518 assert(DefinitionData && "queried property of class with no definition"); 519 return *DefinitionData; 520 } 521 522 const struct DefinitionData &data() const { 523 assert(DefinitionData && "queried property of class with no definition"); 524 return *DefinitionData; 525 } 526 527 /// \brief The template or declaration that this declaration 528 /// describes or was instantiated from, respectively. 529 /// 530 /// For non-templates, this value will be NULL. For record 531 /// declarations that describe a class template, this will be a 532 /// pointer to a ClassTemplateDecl. For member 533 /// classes of class template specializations, this will be the 534 /// MemberSpecializationInfo referring to the member class that was 535 /// instantiated or specialized. 536 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 537 TemplateOrInstantiation; 538 539 friend class DeclContext; 540 541 /// \brief Notify the class that member has been added. 542 /// 543 /// This routine helps maintain information about the class based on which 544 /// members have been added. It will be invoked by DeclContext::addDecl() 545 /// whenever a member is added to this record. 546 void addedMember(Decl *D); 547 548 void markedVirtualFunctionPure(); 549 friend void FunctionDecl::setPure(bool); 550 551protected: 552 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 553 SourceLocation StartLoc, SourceLocation IdLoc, 554 IdentifierInfo *Id, CXXRecordDecl *PrevDecl); 555 556public: 557 /// base_class_iterator - Iterator that traverses the base classes 558 /// of a class. 559 typedef CXXBaseSpecifier* base_class_iterator; 560 561 /// base_class_const_iterator - Iterator that traverses the base 562 /// classes of a class. 563 typedef const CXXBaseSpecifier* base_class_const_iterator; 564 565 /// reverse_base_class_iterator = Iterator that traverses the base classes 566 /// of a class in reverse order. 567 typedef std::reverse_iterator<base_class_iterator> 568 reverse_base_class_iterator; 569 570 /// reverse_base_class_iterator = Iterator that traverses the base classes 571 /// of a class in reverse order. 572 typedef std::reverse_iterator<base_class_const_iterator> 573 reverse_base_class_const_iterator; 574 575 virtual CXXRecordDecl *getCanonicalDecl() { 576 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 577 } 578 virtual const CXXRecordDecl *getCanonicalDecl() const { 579 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 580 } 581 582 const CXXRecordDecl *getPreviousDeclaration() const { 583 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 584 } 585 CXXRecordDecl *getPreviousDeclaration() { 586 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration()); 587 } 588 589 CXXRecordDecl *getDefinition() const { 590 if (!DefinitionData) return 0; 591 return data().Definition; 592 } 593 594 bool hasDefinition() const { return DefinitionData != 0; } 595 596 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 597 SourceLocation StartLoc, SourceLocation IdLoc, 598 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0, 599 bool DelayTypeCreation = false); 600 static CXXRecordDecl *Create(const ASTContext &C, EmptyShell Empty); 601 602 bool isDynamicClass() const { 603 return data().Polymorphic || data().NumVBases != 0; 604 } 605 606 /// setBases - Sets the base classes of this struct or class. 607 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 608 609 /// getNumBases - Retrieves the number of base classes of this 610 /// class. 611 unsigned getNumBases() const { return data().NumBases; } 612 613 base_class_iterator bases_begin() { return data().getBases(); } 614 base_class_const_iterator bases_begin() const { return data().getBases(); } 615 base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 616 base_class_const_iterator bases_end() const { 617 return bases_begin() + data().NumBases; 618 } 619 reverse_base_class_iterator bases_rbegin() { 620 return reverse_base_class_iterator(bases_end()); 621 } 622 reverse_base_class_const_iterator bases_rbegin() const { 623 return reverse_base_class_const_iterator(bases_end()); 624 } 625 reverse_base_class_iterator bases_rend() { 626 return reverse_base_class_iterator(bases_begin()); 627 } 628 reverse_base_class_const_iterator bases_rend() const { 629 return reverse_base_class_const_iterator(bases_begin()); 630 } 631 632 /// getNumVBases - Retrieves the number of virtual base classes of this 633 /// class. 634 unsigned getNumVBases() const { return data().NumVBases; } 635 636 base_class_iterator vbases_begin() { return data().getVBases(); } 637 base_class_const_iterator vbases_begin() const { return data().getVBases(); } 638 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 639 base_class_const_iterator vbases_end() const { 640 return vbases_begin() + data().NumVBases; 641 } 642 reverse_base_class_iterator vbases_rbegin() { 643 return reverse_base_class_iterator(vbases_end()); 644 } 645 reverse_base_class_const_iterator vbases_rbegin() const { 646 return reverse_base_class_const_iterator(vbases_end()); 647 } 648 reverse_base_class_iterator vbases_rend() { 649 return reverse_base_class_iterator(vbases_begin()); 650 } 651 reverse_base_class_const_iterator vbases_rend() const { 652 return reverse_base_class_const_iterator(vbases_begin()); 653 } 654 655 /// \brief Determine whether this class has any dependent base classes. 656 bool hasAnyDependentBases() const; 657 658 /// Iterator access to method members. The method iterator visits 659 /// all method members of the class, including non-instance methods, 660 /// special methods, etc. 661 typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 662 663 /// method_begin - Method begin iterator. Iterates in the order the methods 664 /// were declared. 665 method_iterator method_begin() const { 666 return method_iterator(decls_begin()); 667 } 668 /// method_end - Method end iterator. 669 method_iterator method_end() const { 670 return method_iterator(decls_end()); 671 } 672 673 /// Iterator access to constructor members. 674 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 675 676 ctor_iterator ctor_begin() const { 677 return ctor_iterator(decls_begin()); 678 } 679 ctor_iterator ctor_end() const { 680 return ctor_iterator(decls_end()); 681 } 682 683 /// An iterator over friend declarations. All of these are defined 684 /// in DeclFriend.h. 685 class friend_iterator; 686 friend_iterator friend_begin() const; 687 friend_iterator friend_end() const; 688 void pushFriendDecl(FriendDecl *FD); 689 690 /// Determines whether this record has any friends. 691 bool hasFriends() const { 692 return data().FirstFriend != 0; 693 } 694 695 /// \brief Determine if we need to declare a default constructor for 696 /// this class. 697 /// 698 /// This value is used for lazy creation of default constructors. 699 bool needsImplicitDefaultConstructor() const { 700 return !data().UserDeclaredConstructor && 701 !data().DeclaredDefaultConstructor; 702 } 703 704 /// hasDeclaredDefaultConstructor - Whether this class's default constructor 705 /// has been declared (either explicitly or implicitly). 706 bool hasDeclaredDefaultConstructor() const { 707 return data().DeclaredDefaultConstructor; 708 } 709 710 /// hasConstCopyConstructor - Determines whether this class has a 711 /// copy constructor that accepts a const-qualified argument. 712 bool hasConstCopyConstructor() const; 713 714 /// getCopyConstructor - Returns the copy constructor for this class 715 CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const; 716 717 /// getMoveConstructor - Returns the move constructor for this class 718 CXXConstructorDecl *getMoveConstructor() const; 719 720 /// \brief Retrieve the copy-assignment operator for this class, if available. 721 /// 722 /// This routine attempts to find the copy-assignment operator for this 723 /// class, using a simplistic form of overload resolution. 724 /// 725 /// \param ArgIsConst Whether the argument to the copy-assignment operator 726 /// is const-qualified. 727 /// 728 /// \returns The copy-assignment operator that can be invoked, or NULL if 729 /// a unique copy-assignment operator could not be found. 730 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const; 731 732 /// getMoveAssignmentOperator - Returns the move assignment operator for this 733 /// class 734 CXXMethodDecl *getMoveAssignmentOperator() const; 735 736 /// hasUserDeclaredConstructor - Whether this class has any 737 /// user-declared constructors. When true, a default constructor 738 /// will not be implicitly declared. 739 bool hasUserDeclaredConstructor() const { 740 return data().UserDeclaredConstructor; 741 } 742 743 /// hasUserProvidedDefaultconstructor - Whether this class has a 744 /// user-provided default constructor per C++0x. 745 bool hasUserProvidedDefaultConstructor() const { 746 return data().UserProvidedDefaultConstructor; 747 } 748 749 /// hasUserDeclaredCopyConstructor - Whether this class has a 750 /// user-declared copy constructor. When false, a copy constructor 751 /// will be implicitly declared. 752 bool hasUserDeclaredCopyConstructor() const { 753 return data().UserDeclaredCopyConstructor; 754 } 755 756 /// \brief Determine whether this class has had its copy constructor 757 /// declared, either via the user or via an implicit declaration. 758 /// 759 /// This value is used for lazy creation of copy constructors. 760 bool hasDeclaredCopyConstructor() const { 761 return data().DeclaredCopyConstructor; 762 } 763 764 /// hasUserDeclaredMoveOperation - Whether this class has a user- 765 /// declared move constructor or assignment operator. When false, a 766 /// move constructor and assignment operator may be implicitly declared. 767 bool hasUserDeclaredMoveOperation() const { 768 return data().UserDeclaredMoveConstructor || 769 data().UserDeclaredMoveAssignment; 770 } 771 772 /// \brief Determine whether this class has had a move constructor 773 /// declared by the user. 774 bool hasUserDeclaredMoveConstructor() const { 775 return data().UserDeclaredMoveConstructor; 776 } 777 778 /// \brief Determine whether this class has had a move constructor 779 /// declared. 780 bool hasDeclaredMoveConstructor() const { 781 return data().DeclaredMoveConstructor; 782 } 783 784 /// hasUserDeclaredCopyAssignment - Whether this class has a 785 /// user-declared copy assignment operator. When false, a copy 786 /// assigment operator will be implicitly declared. 787 bool hasUserDeclaredCopyAssignment() const { 788 return data().UserDeclaredCopyAssignment; 789 } 790 791 /// \brief Determine whether this class has had its copy assignment operator 792 /// declared, either via the user or via an implicit declaration. 793 /// 794 /// This value is used for lazy creation of copy assignment operators. 795 bool hasDeclaredCopyAssignment() const { 796 return data().DeclaredCopyAssignment; 797 } 798 799 /// \brief Determine whether this class has had a move assignment 800 /// declared by the user. 801 bool hasUserDeclaredMoveAssignment() const { 802 return data().UserDeclaredMoveAssignment; 803 } 804 805 /// hasDeclaredMoveAssignment - Whether this class has a 806 /// declared move assignment operator. 807 bool hasDeclaredMoveAssignment() const { 808 return data().DeclaredMoveAssignment; 809 } 810 811 /// hasUserDeclaredDestructor - Whether this class has a 812 /// user-declared destructor. When false, a destructor will be 813 /// implicitly declared. 814 bool hasUserDeclaredDestructor() const { 815 return data().UserDeclaredDestructor; 816 } 817 818 /// \brief Determine whether this class has had its destructor declared, 819 /// either via the user or via an implicit declaration. 820 /// 821 /// This value is used for lazy creation of destructors. 822 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; } 823 824 /// getConversions - Retrieve the overload set containing all of the 825 /// conversion functions in this class. 826 UnresolvedSetImpl *getConversionFunctions() { 827 return &data().Conversions; 828 } 829 const UnresolvedSetImpl *getConversionFunctions() const { 830 return &data().Conversions; 831 } 832 833 typedef UnresolvedSetImpl::iterator conversion_iterator; 834 conversion_iterator conversion_begin() const { 835 return getConversionFunctions()->begin(); 836 } 837 conversion_iterator conversion_end() const { 838 return getConversionFunctions()->end(); 839 } 840 841 /// Removes a conversion function from this class. The conversion 842 /// function must currently be a member of this class. Furthermore, 843 /// this class must currently be in the process of being defined. 844 void removeConversion(const NamedDecl *Old); 845 846 /// getVisibleConversionFunctions - get all conversion functions visible 847 /// in current class; including conversion function templates. 848 const UnresolvedSetImpl *getVisibleConversionFunctions(); 849 850 /// isAggregate - Whether this class is an aggregate (C++ 851 /// [dcl.init.aggr]), which is a class with no user-declared 852 /// constructors, no private or protected non-static data members, 853 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 854 bool isAggregate() const { return data().Aggregate; } 855 856 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 857 /// that is an aggregate that has no non-static non-POD data members, no 858 /// reference data members, no user-defined copy assignment operator and no 859 /// user-defined destructor. 860 bool isPOD() const { return data().PlainOldData; } 861 862 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 863 /// means it has a virtual function, virtual base, data member (other than 864 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 865 /// a check for union-ness. 866 bool isEmpty() const { return data().Empty; } 867 868 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 869 /// which means that the class contains or inherits a virtual function. 870 bool isPolymorphic() const { return data().Polymorphic; } 871 872 /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 873 /// which means that the class contains or inherits a pure virtual function. 874 bool isAbstract() const { return data().Abstract; } 875 876 /// isStandardLayout - Whether this class has standard layout 877 /// (C++ [class]p7) 878 bool isStandardLayout() const { return data().IsStandardLayout; } 879 880 /// \brief Whether this class, or any of its class subobjects, contains a 881 /// mutable field. 882 bool hasMutableFields() const { return data().HasMutableFields; } 883 884 // hasTrivialDefaultConstructor - Whether this class has a trivial default 885 // constructor 886 // (C++0x [class.ctor]p5) 887 bool hasTrivialDefaultConstructor() const { 888 return data().HasTrivialDefaultConstructor && 889 (!data().UserDeclaredConstructor || 890 data().DeclaredDefaultConstructor); 891 } 892 893 // hasConstExprNonCopyMoveConstructor - Whether this class has at least one 894 // constexpr constructor other than the copy or move constructors 895 bool hasConstExprNonCopyMoveConstructor() const { 896 return data().HasConstExprNonCopyMoveConstructor; 897 } 898 899 // hasTrivialCopyConstructor - Whether this class has a trivial copy 900 // constructor (C++ [class.copy]p6, C++0x [class.copy]p13) 901 bool hasTrivialCopyConstructor() const { 902 return data().HasTrivialCopyConstructor; 903 } 904 905 // hasTrivialMoveConstructor - Whether this class has a trivial move 906 // constructor (C++0x [class.copy]p13) 907 bool hasTrivialMoveConstructor() const { 908 return data().HasTrivialMoveConstructor; 909 } 910 911 // hasTrivialCopyAssignment - Whether this class has a trivial copy 912 // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27) 913 bool hasTrivialCopyAssignment() const { 914 return data().HasTrivialCopyAssignment; 915 } 916 917 // hasTrivialMoveAssignment - Whether this class has a trivial move 918 // assignment operator (C++0x [class.copy]p27) 919 bool hasTrivialMoveAssignment() const { 920 return data().HasTrivialMoveAssignment; 921 } 922 923 // hasTrivialDestructor - Whether this class has a trivial destructor 924 // (C++ [class.dtor]p3) 925 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; } 926 927 // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal type 928 // non-static data member or base class. 929 bool hasNonLiteralTypeFieldsOrBases() const { 930 return data().HasNonLiteralTypeFieldsOrBases; 931 } 932 933 // isTriviallyCopyable - Whether this class is considered trivially copyable 934 // (C++0x [class]p6). 935 bool isTriviallyCopyable() const; 936 937 // isTrivial - Whether this class is considered trivial 938 // 939 // C++0x [class]p6 940 // A trivial class is a class that has a trivial default constructor and 941 // is trivially copiable. 942 bool isTrivial() const { 943 return isTriviallyCopyable() && hasTrivialDefaultConstructor(); 944 } 945 946 /// \brief If this record is an instantiation of a member class, 947 /// retrieves the member class from which it was instantiated. 948 /// 949 /// This routine will return non-NULL for (non-templated) member 950 /// classes of class templates. For example, given: 951 /// 952 /// \code 953 /// template<typename T> 954 /// struct X { 955 /// struct A { }; 956 /// }; 957 /// \endcode 958 /// 959 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 960 /// whose parent is the class template specialization X<int>. For 961 /// this declaration, getInstantiatedFromMemberClass() will return 962 /// the CXXRecordDecl X<T>::A. When a complete definition of 963 /// X<int>::A is required, it will be instantiated from the 964 /// declaration returned by getInstantiatedFromMemberClass(). 965 CXXRecordDecl *getInstantiatedFromMemberClass() const; 966 967 /// \brief If this class is an instantiation of a member class of a 968 /// class template specialization, retrieves the member specialization 969 /// information. 970 MemberSpecializationInfo *getMemberSpecializationInfo() const; 971 972 /// \brief Specify that this record is an instantiation of the 973 /// member class RD. 974 void setInstantiationOfMemberClass(CXXRecordDecl *RD, 975 TemplateSpecializationKind TSK); 976 977 /// \brief Retrieves the class template that is described by this 978 /// class declaration. 979 /// 980 /// Every class template is represented as a ClassTemplateDecl and a 981 /// CXXRecordDecl. The former contains template properties (such as 982 /// the template parameter lists) while the latter contains the 983 /// actual description of the template's 984 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 985 /// CXXRecordDecl that from a ClassTemplateDecl, while 986 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 987 /// a CXXRecordDecl. 988 ClassTemplateDecl *getDescribedClassTemplate() const { 989 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 990 } 991 992 void setDescribedClassTemplate(ClassTemplateDecl *Template) { 993 TemplateOrInstantiation = Template; 994 } 995 996 /// \brief Determine whether this particular class is a specialization or 997 /// instantiation of a class template or member class of a class template, 998 /// and how it was instantiated or specialized. 999 TemplateSpecializationKind getTemplateSpecializationKind() const; 1000 1001 /// \brief Set the kind of specialization or template instantiation this is. 1002 void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 1003 1004 /// getDestructor - Returns the destructor decl for this class. 1005 CXXDestructorDecl *getDestructor() const; 1006 1007 /// isLocalClass - If the class is a local class [class.local], returns 1008 /// the enclosing function declaration. 1009 const FunctionDecl *isLocalClass() const { 1010 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 1011 return RD->isLocalClass(); 1012 1013 return dyn_cast<FunctionDecl>(getDeclContext()); 1014 } 1015 1016 /// \brief Determine whether this class is derived from the class \p Base. 1017 /// 1018 /// This routine only determines whether this class is derived from \p Base, 1019 /// but does not account for factors that may make a Derived -> Base class 1020 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1021 /// base class subobjects. 1022 /// 1023 /// \param Base the base class we are searching for. 1024 /// 1025 /// \returns true if this class is derived from Base, false otherwise. 1026 bool isDerivedFrom(const CXXRecordDecl *Base) const; 1027 1028 /// \brief Determine whether this class is derived from the type \p Base. 1029 /// 1030 /// This routine only determines whether this class is derived from \p Base, 1031 /// but does not account for factors that may make a Derived -> Base class 1032 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 1033 /// base class subobjects. 1034 /// 1035 /// \param Base the base class we are searching for. 1036 /// 1037 /// \param Paths will contain the paths taken from the current class to the 1038 /// given \p Base class. 1039 /// 1040 /// \returns true if this class is derived from Base, false otherwise. 1041 /// 1042 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 1043 /// tangling input and output in \p Paths 1044 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; 1045 1046 /// \brief Determine whether this class is virtually derived from 1047 /// the class \p Base. 1048 /// 1049 /// This routine only determines whether this class is virtually 1050 /// derived from \p Base, but does not account for factors that may 1051 /// make a Derived -> Base class ill-formed, such as 1052 /// private/protected inheritance or multiple, ambiguous base class 1053 /// subobjects. 1054 /// 1055 /// \param Base the base class we are searching for. 1056 /// 1057 /// \returns true if this class is virtually derived from Base, 1058 /// false otherwise. 1059 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; 1060 1061 /// \brief Determine whether this class is provably not derived from 1062 /// the type \p Base. 1063 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 1064 1065 /// \brief Function type used by forallBases() as a callback. 1066 /// 1067 /// \param Base the definition of the base class 1068 /// 1069 /// \returns true if this base matched the search criteria 1070 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 1071 void *UserData); 1072 1073 /// \brief Determines if the given callback holds for all the direct 1074 /// or indirect base classes of this type. 1075 /// 1076 /// The class itself does not count as a base class. This routine 1077 /// returns false if the class has non-computable base classes. 1078 /// 1079 /// \param AllowShortCircuit if false, forces the callback to be called 1080 /// for every base class, even if a dependent or non-matching base was 1081 /// found. 1082 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 1083 bool AllowShortCircuit = true) const; 1084 1085 /// \brief Function type used by lookupInBases() to determine whether a 1086 /// specific base class subobject matches the lookup criteria. 1087 /// 1088 /// \param Specifier the base-class specifier that describes the inheritance 1089 /// from the base class we are trying to match. 1090 /// 1091 /// \param Path the current path, from the most-derived class down to the 1092 /// base named by the \p Specifier. 1093 /// 1094 /// \param UserData a single pointer to user-specified data, provided to 1095 /// lookupInBases(). 1096 /// 1097 /// \returns true if this base matched the search criteria, false otherwise. 1098 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 1099 CXXBasePath &Path, 1100 void *UserData); 1101 1102 /// \brief Look for entities within the base classes of this C++ class, 1103 /// transitively searching all base class subobjects. 1104 /// 1105 /// This routine uses the callback function \p BaseMatches to find base 1106 /// classes meeting some search criteria, walking all base class subobjects 1107 /// and populating the given \p Paths structure with the paths through the 1108 /// inheritance hierarchy that resulted in a match. On a successful search, 1109 /// the \p Paths structure can be queried to retrieve the matching paths and 1110 /// to determine if there were any ambiguities. 1111 /// 1112 /// \param BaseMatches callback function used to determine whether a given 1113 /// base matches the user-defined search criteria. 1114 /// 1115 /// \param UserData user data pointer that will be provided to \p BaseMatches. 1116 /// 1117 /// \param Paths used to record the paths from this class to its base class 1118 /// subobjects that match the search criteria. 1119 /// 1120 /// \returns true if there exists any path from this class to a base class 1121 /// subobject that matches the search criteria. 1122 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 1123 CXXBasePaths &Paths) const; 1124 1125 /// \brief Base-class lookup callback that determines whether the given 1126 /// base class specifier refers to a specific class declaration. 1127 /// 1128 /// This callback can be used with \c lookupInBases() to determine whether 1129 /// a given derived class has is a base class subobject of a particular type. 1130 /// The user data pointer should refer to the canonical CXXRecordDecl of the 1131 /// base class that we are searching for. 1132 static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 1133 CXXBasePath &Path, void *BaseRecord); 1134 1135 /// \brief Base-class lookup callback that determines whether the 1136 /// given base class specifier refers to a specific class 1137 /// declaration and describes virtual derivation. 1138 /// 1139 /// This callback can be used with \c lookupInBases() to determine 1140 /// whether a given derived class has is a virtual base class 1141 /// subobject of a particular type. The user data pointer should 1142 /// refer to the canonical CXXRecordDecl of the base class that we 1143 /// are searching for. 1144 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 1145 CXXBasePath &Path, void *BaseRecord); 1146 1147 /// \brief Base-class lookup callback that determines whether there exists 1148 /// a tag with the given name. 1149 /// 1150 /// This callback can be used with \c lookupInBases() to find tag members 1151 /// of the given name within a C++ class hierarchy. The user data pointer 1152 /// is an opaque \c DeclarationName pointer. 1153 static bool FindTagMember(const CXXBaseSpecifier *Specifier, 1154 CXXBasePath &Path, void *Name); 1155 1156 /// \brief Base-class lookup callback that determines whether there exists 1157 /// a member with the given name. 1158 /// 1159 /// This callback can be used with \c lookupInBases() to find members 1160 /// of the given name within a C++ class hierarchy. The user data pointer 1161 /// is an opaque \c DeclarationName pointer. 1162 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 1163 CXXBasePath &Path, void *Name); 1164 1165 /// \brief Base-class lookup callback that determines whether there exists 1166 /// a member with the given name that can be used in a nested-name-specifier. 1167 /// 1168 /// This callback can be used with \c lookupInBases() to find membes of 1169 /// the given name within a C++ class hierarchy that can occur within 1170 /// nested-name-specifiers. 1171 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 1172 CXXBasePath &Path, 1173 void *UserData); 1174 1175 /// \brief Retrieve the final overriders for each virtual member 1176 /// function in the class hierarchy where this class is the 1177 /// most-derived class in the class hierarchy. 1178 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 1179 1180 /// \brief Get the indirect primary bases for this class. 1181 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; 1182 1183 /// viewInheritance - Renders and displays an inheritance diagram 1184 /// for this C++ class and all of its base classes (transitively) using 1185 /// GraphViz. 1186 void viewInheritance(ASTContext& Context) const; 1187 1188 /// MergeAccess - Calculates the access of a decl that is reached 1189 /// along a path. 1190 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 1191 AccessSpecifier DeclAccess) { 1192 assert(DeclAccess != AS_none); 1193 if (DeclAccess == AS_private) return AS_none; 1194 return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 1195 } 1196 1197 /// \brief Indicates that the definition of this class is now complete. 1198 virtual void completeDefinition(); 1199 1200 /// \brief Indicates that the definition of this class is now complete, 1201 /// and provides a final overrider map to help determine 1202 /// 1203 /// \param FinalOverriders The final overrider map for this class, which can 1204 /// be provided as an optimization for abstract-class checking. If NULL, 1205 /// final overriders will be computed if they are needed to complete the 1206 /// definition. 1207 void completeDefinition(CXXFinalOverriderMap *FinalOverriders); 1208 1209 /// \brief Determine whether this class may end up being abstract, even though 1210 /// it is not yet known to be abstract. 1211 /// 1212 /// \returns true if this class is not known to be abstract but has any 1213 /// base classes that are abstract. In this case, \c completeDefinition() 1214 /// will need to compute final overriders to determine whether the class is 1215 /// actually abstract. 1216 bool mayBeAbstract() const; 1217 1218 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1219 static bool classofKind(Kind K) { 1220 return K >= firstCXXRecord && K <= lastCXXRecord; 1221 } 1222 static bool classof(const CXXRecordDecl *D) { return true; } 1223 static bool classof(const ClassTemplateSpecializationDecl *D) { 1224 return true; 1225 } 1226 1227 friend class ASTDeclReader; 1228 friend class ASTDeclWriter; 1229 friend class ASTReader; 1230 friend class ASTWriter; 1231}; 1232 1233/// CXXMethodDecl - Represents a static or instance method of a 1234/// struct/union/class. 1235class CXXMethodDecl : public FunctionDecl { 1236protected: 1237 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc, 1238 const DeclarationNameInfo &NameInfo, 1239 QualType T, TypeSourceInfo *TInfo, 1240 bool isStatic, StorageClass SCAsWritten, bool isInline, 1241 SourceLocation EndLocation) 1242 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo, 1243 (isStatic ? SC_Static : SC_None), 1244 SCAsWritten, isInline) { 1245 if (EndLocation.isValid()) 1246 setRangeEnd(EndLocation); 1247 } 1248 1249public: 1250 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1251 SourceLocation StartLoc, 1252 const DeclarationNameInfo &NameInfo, 1253 QualType T, TypeSourceInfo *TInfo, 1254 bool isStatic, 1255 StorageClass SCAsWritten, 1256 bool isInline, 1257 SourceLocation EndLocation); 1258 1259 bool isStatic() const { return getStorageClass() == SC_Static; } 1260 bool isInstance() const { return !isStatic(); } 1261 1262 bool isVirtual() const { 1263 CXXMethodDecl *CD = 1264 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 1265 1266 if (CD->isVirtualAsWritten()) 1267 return true; 1268 1269 return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 1270 } 1271 1272 /// \brief Determine whether this is a usual deallocation function 1273 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 1274 /// delete or delete[] operator with a particular signature. 1275 bool isUsualDeallocationFunction() const; 1276 1277 /// \brief Determine whether this is a copy-assignment operator, regardless 1278 /// of whether it was declared implicitly or explicitly. 1279 bool isCopyAssignmentOperator() const; 1280 1281 /// \brief Determine whether this is a move assignment operator. 1282 bool isMoveAssignmentOperator() const; 1283 1284 const CXXMethodDecl *getCanonicalDecl() const { 1285 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1286 } 1287 CXXMethodDecl *getCanonicalDecl() { 1288 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 1289 } 1290 1291 /// isUserProvided - True if it is either an implicit constructor or 1292 /// if it was defaulted or deleted on first declaration. 1293 bool isUserProvided() const { 1294 return !(isDeleted() || getCanonicalDecl()->isDefaulted()); 1295 } 1296 1297 /// 1298 void addOverriddenMethod(const CXXMethodDecl *MD); 1299 1300 typedef const CXXMethodDecl ** method_iterator; 1301 1302 method_iterator begin_overridden_methods() const; 1303 method_iterator end_overridden_methods() const; 1304 unsigned size_overridden_methods() const; 1305 1306 /// getParent - Returns the parent of this method declaration, which 1307 /// is the class in which this method is defined. 1308 const CXXRecordDecl *getParent() const { 1309 return cast<CXXRecordDecl>(FunctionDecl::getParent()); 1310 } 1311 1312 /// getParent - Returns the parent of this method declaration, which 1313 /// is the class in which this method is defined. 1314 CXXRecordDecl *getParent() { 1315 return const_cast<CXXRecordDecl *>( 1316 cast<CXXRecordDecl>(FunctionDecl::getParent())); 1317 } 1318 1319 /// getThisType - Returns the type of 'this' pointer. 1320 /// Should only be called for instance methods. 1321 QualType getThisType(ASTContext &C) const; 1322 1323 unsigned getTypeQualifiers() const { 1324 return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 1325 } 1326 1327 /// \brief Retrieve the ref-qualifier associated with this method. 1328 /// 1329 /// In the following example, \c f() has an lvalue ref-qualifier, \c g() 1330 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. 1331 /// \code 1332 /// struct X { 1333 /// void f() &; 1334 /// void g() &&; 1335 /// void h(); 1336 /// }; 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