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