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