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