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