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