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