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