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