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