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