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