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