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