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