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