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