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