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