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