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