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