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