DeclCXX.h revision 5346278f81930e7fd0545bbbb2fc217c6921b109
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. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_DECLCXX_H 15#define LLVM_CLANG_AST_DECLCXX_H 16 17#include "clang/AST/Expr.h" 18#include "clang/AST/Decl.h" 19#include "llvm/ADT/SmallVector.h" 20 21namespace clang { 22 23class ClassTemplateDecl; 24class CXXRecordDecl; 25class CXXConstructorDecl; 26class CXXDestructorDecl; 27class CXXConversionDecl; 28class CXXMethodDecl; 29class ClassTemplateSpecializationDecl; 30 31/// \brief Represents any kind of function declaration, whether it is a 32/// concrete function or a function template. 33class AnyFunctionDecl { 34 NamedDecl *Function; 35 36 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 37 38public: 39 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 40 AnyFunctionDecl(FunctionTemplateDecl *FTD); 41 42 /// \brief Implicily converts any function or function template into a 43 /// named declaration. 44 operator NamedDecl *() const { return Function; } 45 46 /// \brief Retrieve the underlying function or function template. 47 NamedDecl *get() const { return Function; } 48 49 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 50 return AnyFunctionDecl(ND); 51 } 52}; 53 54} // end namespace clang 55 56namespace llvm { 57 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 58 /// AnyFunctionDecl to any function or function template declaration. 59 template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 60 typedef ::clang::NamedDecl* SimpleType; 61 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 62 return Val; 63 } 64 }; 65 template<> struct simplify_type< ::clang::AnyFunctionDecl> 66 : public simplify_type<const ::clang::AnyFunctionDecl> {}; 67 68 // Provide PointerLikeTypeTraits for non-cvr pointers. 69 template<> 70 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 71 public: 72 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 73 return F.get(); 74 } 75 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 76 return ::clang::AnyFunctionDecl::getFromNamedDecl( 77 static_cast< ::clang::NamedDecl*>(P)); 78 } 79 80 enum { NumLowBitsAvailable = 2 }; 81 }; 82 83} // end namespace llvm 84 85namespace clang { 86 87/// OverloadedFunctionDecl - An instance of this class represents a 88/// set of overloaded functions. All of the functions have the same 89/// name and occur within the same scope. 90/// 91/// An OverloadedFunctionDecl has no ownership over the FunctionDecl 92/// nodes it contains. Rather, the FunctionDecls are owned by the 93/// enclosing scope (which also owns the OverloadedFunctionDecl 94/// node). OverloadedFunctionDecl is used primarily to store a set of 95/// overloaded functions for name lookup. 96class OverloadedFunctionDecl : public NamedDecl { 97protected: 98 OverloadedFunctionDecl(DeclContext *DC, DeclarationName N) 99 : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { } 100 101 /// Functions - the set of overloaded functions contained in this 102 /// overload set. 103 llvm::SmallVector<AnyFunctionDecl, 4> Functions; 104 105 // FIXME: This should go away when we stop using 106 // OverloadedFunctionDecl to store conversions in CXXRecordDecl. 107 friend class CXXRecordDecl; 108 109public: 110 typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator; 111 typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator 112 function_const_iterator; 113 114 static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC, 115 DeclarationName N); 116 117 /// \brief Add a new overloaded function or function template to the set 118 /// of overloaded function templates. 119 void addOverload(AnyFunctionDecl F); 120 121 function_iterator function_begin() { return Functions.begin(); } 122 function_iterator function_end() { return Functions.end(); } 123 function_const_iterator function_begin() const { return Functions.begin(); } 124 function_const_iterator function_end() const { return Functions.end(); } 125 126 /// \brief Returns the number of overloaded functions stored in 127 /// this set. 128 unsigned size() const { return Functions.size(); } 129 130 // Implement isa/cast/dyncast/etc. 131 static bool classof(const Decl *D) { 132 return D->getKind() == OverloadedFunction; 133 } 134 static bool classof(const OverloadedFunctionDecl *D) { return true; } 135}; 136 137/// \brief Provides uniform iteration syntax for an overload set, function, 138/// or function template. 139class OverloadIterator { 140 /// \brief An overloaded function set, function declaration, or 141 /// function template declaration. 142 NamedDecl *D; 143 144 /// \brief If the declaration is an overloaded function set, this is the 145 /// iterator pointing to the current position within that overloaded 146 /// function set. 147 OverloadedFunctionDecl::function_iterator Iter; 148 149public: 150 typedef AnyFunctionDecl value_type; 151 typedef value_type reference; 152 typedef NamedDecl *pointer; 153 typedef int difference_type; 154 typedef std::forward_iterator_tag iterator_category; 155 156 OverloadIterator() : D(0) { } 157 158 OverloadIterator(FunctionDecl *FD) : D(FD) { } 159 OverloadIterator(FunctionTemplateDecl *FTD) 160 : D(reinterpret_cast<NamedDecl*>(FTD)) { } 161 OverloadIterator(OverloadedFunctionDecl *Ovl) 162 : D(Ovl), Iter(Ovl->function_begin()) { } 163 164 OverloadIterator(NamedDecl *ND); 165 166 reference operator*() const; 167 168 pointer operator->() const { return (**this).get(); } 169 170 OverloadIterator &operator++(); 171 172 OverloadIterator operator++(int) { 173 OverloadIterator Temp(*this); 174 ++(*this); 175 return Temp; 176 } 177 178 bool Equals(const OverloadIterator &Other) const; 179}; 180 181inline bool operator==(const OverloadIterator &X, const OverloadIterator &Y) { 182 return X.Equals(Y); 183} 184 185inline bool operator!=(const OverloadIterator &X, const OverloadIterator &Y) { 186 return !(X == Y); 187} 188 189/// CXXBaseSpecifier - A base class of a C++ class. 190/// 191/// Each CXXBaseSpecifier represents a single, direct base class (or 192/// struct) of a C++ class (or struct). It specifies the type of that 193/// base class, whether it is a virtual or non-virtual base, and what 194/// level of access (public, protected, private) is used for the 195/// derivation. For example: 196/// 197/// @code 198/// class A { }; 199/// class B { }; 200/// class C : public virtual A, protected B { }; 201/// @endcode 202/// 203/// In this code, C will have two CXXBaseSpecifiers, one for "public 204/// virtual A" and the other for "protected B". 205class CXXBaseSpecifier { 206 /// Range - The source code range that covers the full base 207 /// specifier, including the "virtual" (if present) and access 208 /// specifier (if present). 209 SourceRange Range; 210 211 /// Virtual - Whether this is a virtual base class or not. 212 bool Virtual : 1; 213 214 /// BaseOfClass - Whether this is the base of a class (true) or of a 215 /// struct (false). This determines the mapping from the access 216 /// specifier as written in the source code to the access specifier 217 /// used for semantic analysis. 218 bool BaseOfClass : 1; 219 220 /// Access - Access specifier as written in the source code (which 221 /// may be AS_none). The actual type of data stored here is an 222 /// AccessSpecifier, but we use "unsigned" here to work around a 223 /// VC++ bug. 224 unsigned Access : 2; 225 226 /// BaseType - The type of the base class. This will be a class or 227 /// struct (or a typedef of such). 228 QualType BaseType; 229 230public: 231 CXXBaseSpecifier() { } 232 233 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 234 : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 235 236 /// getSourceRange - Retrieves the source range that contains the 237 /// entire base specifier. 238 SourceRange getSourceRange() const { return Range; } 239 240 /// isVirtual - Determines whether the base class is a virtual base 241 /// class (or not). 242 bool isVirtual() const { return Virtual; } 243 244 /// getAccessSpecifier - Returns the access specifier for this base 245 /// specifier. This is the actual base specifier as used for 246 /// semantic analysis, so the result can never be AS_none. To 247 /// retrieve the access specifier as written in the source code, use 248 /// getAccessSpecifierAsWritten(). 249 AccessSpecifier getAccessSpecifier() const { 250 if ((AccessSpecifier)Access == AS_none) 251 return BaseOfClass? AS_private : AS_public; 252 else 253 return (AccessSpecifier)Access; 254 } 255 256 /// getAccessSpecifierAsWritten - Retrieves the access specifier as 257 /// written in the source code (which may mean that no access 258 /// specifier was explicitly written). Use getAccessSpecifier() to 259 /// retrieve the access specifier for use in semantic analysis. 260 AccessSpecifier getAccessSpecifierAsWritten() const { 261 return (AccessSpecifier)Access; 262 } 263 264 /// getType - Retrieves the type of the base class. This type will 265 /// always be an unqualified class type. 266 QualType getType() const { return BaseType; } 267}; 268 269/// CXXRecordDecl - Represents a C++ struct/union/class. 270/// FIXME: This class will disappear once we've properly taught RecordDecl 271/// to deal with C++-specific things. 272class CXXRecordDecl : public RecordDecl { 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, i.e. has no 296 /// data members other than 0-width bit-fields, has no virtual function/base, 297 /// and doesn't inherit from a non-empty class. Doesn't take union-ness into 298 /// account. 299 bool Empty : 1; 300 301 /// Polymorphic - True when this class is polymorphic, i.e. has at least one 302 /// 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 one 306 /// 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 /// HasTrivialCopyConstructor - True when this class has a trivial copy 320 /// constructor. 321 /// 322 /// C++ [class.copy]p6. A copy constructor for class X is trivial 323 /// if it is implicitly declared and if 324 /// * class X has no virtual functions and no virtual base classes, and 325 /// * each direct base class of X has a trivial copy constructor, and 326 /// * for all the nonstatic data members of X that are of class type (or 327 /// array thereof), each such class type has a trivial copy constructor; 328 /// otherwise the copy constructor is non-trivial. 329 bool HasTrivialCopyConstructor : 1; 330 331 /// HasTrivialCopyAssignment - True when this class has a trivial copy 332 /// assignment operator. 333 /// 334 /// C++ [class.copy]p11. A copy assignment operator for class X is 335 /// trivial if it is implicitly declared and if 336 /// * class X has no virtual functions and no virtual base classes, and 337 /// * each direct base class of X has a trivial copy assignment operator, and 338 /// * for all the nonstatic data members of X that are of class type (or 339 /// array thereof), each such class type has a trivial copy assignment 340 /// operator; 341 /// otherwise the copy assignment operator is non-trivial. 342 bool HasTrivialCopyAssignment : 1; 343 344 /// HasTrivialDestructor - True when this class has a trivial destructor. 345 /// 346 /// C++ [class.dtor]p3. A destructor is trivial if it is an 347 /// implicitly-declared destructor and if: 348 /// * all of the direct base classes of its class have trivial destructors 349 /// and 350 /// * for all of the non-static data members of its class that are of class 351 /// type (or array thereof), each such class has a trivial destructor. 352 bool HasTrivialDestructor : 1; 353 354 /// Bases - Base classes of this class. 355 /// FIXME: This is wasted space for a union. 356 CXXBaseSpecifier *Bases; 357 358 /// NumBases - The number of base class specifiers in Bases. 359 unsigned NumBases; 360 361 /// VBases - direct and indirect virtual base classes of this class. 362 CXXBaseSpecifier *VBases; 363 364 /// NumVBases - The number of virtual base class specifiers in VBases. 365 unsigned NumVBases; 366 367 /// Conversions - Overload set containing the conversion functions 368 /// of this C++ class (but not its inherited conversion 369 /// functions). Each of the entries in this overload set is a 370 /// CXXConversionDecl. 371 OverloadedFunctionDecl Conversions; 372 373 /// VisibleConversions - Overload set containing the conversion functions 374 /// of this C++ class and all those inherited conversion functions that 375 /// are visible in this class. Each of the entries in this overload set is 376 /// a CXXConversionDecl or a FunctionTemplateDecl. 377 OverloadedFunctionDecl VisibleConversions; 378 379 /// \brief The template or declaration that this declaration 380 /// describes or was instantiated from, respectively. 381 /// 382 /// For non-templates, this value will be NULL. For record 383 /// declarations that describe a class template, this will be a 384 /// pointer to a ClassTemplateDecl. For member 385 /// classes of class template specializations, this will be the 386 /// RecordDecl from which the member class was instantiated. 387 llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*> 388 TemplateOrInstantiation; 389 390protected: 391 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 392 SourceLocation L, IdentifierInfo *Id, 393 CXXRecordDecl *PrevDecl, 394 SourceLocation TKL = SourceLocation()); 395 396 ~CXXRecordDecl(); 397 398public: 399 /// base_class_iterator - Iterator that traverses the base classes 400 /// of a class. 401 typedef CXXBaseSpecifier* base_class_iterator; 402 403 /// base_class_const_iterator - Iterator that traverses the base 404 /// classes of a class. 405 typedef const CXXBaseSpecifier* base_class_const_iterator; 406 407 /// reverse_base_class_iterator = Iterator that traverses the base classes 408 /// of a class in reverse order. 409 typedef std::reverse_iterator<base_class_iterator> 410 reverse_base_class_iterator; 411 412 /// reverse_base_class_iterator = Iterator that traverses the base classes 413 /// of a class in reverse order. 414 typedef std::reverse_iterator<base_class_const_iterator> 415 reverse_base_class_const_iterator; 416 417 virtual CXXRecordDecl *getCanonicalDecl() { 418 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 419 } 420 421 static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 422 SourceLocation L, IdentifierInfo *Id, 423 SourceLocation TKL = SourceLocation(), 424 CXXRecordDecl* PrevDecl=0, 425 bool DelayTypeCreation = false); 426 427 virtual void Destroy(ASTContext& C); 428 429 bool isDynamicClass() const { 430 return Polymorphic || NumVBases!=0; 431 } 432 433 /// setBases - Sets the base classes of this struct or class. 434 void setBases(ASTContext &C, 435 CXXBaseSpecifier const * const *Bases, unsigned NumBases); 436 437 /// getNumBases - Retrieves the number of base classes of this 438 /// class. 439 unsigned getNumBases() const { return NumBases; } 440 441 base_class_iterator bases_begin() { return Bases; } 442 base_class_const_iterator bases_begin() const { return Bases; } 443 base_class_iterator bases_end() { return Bases + NumBases; } 444 base_class_const_iterator bases_end() const { return Bases + NumBases; } 445 reverse_base_class_iterator bases_rbegin() { 446 return reverse_base_class_iterator(bases_end()); 447 } 448 reverse_base_class_const_iterator bases_rbegin() const { 449 return reverse_base_class_const_iterator(bases_end()); 450 } 451 reverse_base_class_iterator bases_rend() { 452 return reverse_base_class_iterator(bases_begin()); 453 } 454 reverse_base_class_const_iterator bases_rend() const { 455 return reverse_base_class_const_iterator(bases_begin()); 456 } 457 458 /// getNumVBases - Retrieves the number of virtual base classes of this 459 /// class. 460 unsigned getNumVBases() const { return NumVBases; } 461 462 base_class_iterator vbases_begin() { return VBases; } 463 base_class_const_iterator vbases_begin() const { return VBases; } 464 base_class_iterator vbases_end() { return VBases + NumVBases; } 465 base_class_const_iterator vbases_end() const { return VBases + NumVBases; } 466 reverse_base_class_iterator vbases_rbegin() { 467 return reverse_base_class_iterator(vbases_end()); 468 } 469 reverse_base_class_const_iterator vbases_rbegin() const { 470 return reverse_base_class_const_iterator(vbases_end()); 471 } 472 reverse_base_class_iterator vbases_rend() { 473 return reverse_base_class_iterator(vbases_begin()); 474 } 475 reverse_base_class_const_iterator vbases_rend() const { 476 return reverse_base_class_const_iterator(vbases_begin()); 477 } 478 479 /// Iterator access to method members. The method iterator visits 480 /// all method members of the class, including non-instance methods, 481 /// special methods, etc. 482 typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 483 484 /// method_begin - Method begin iterator. Iterates in the order the methods 485 /// were declared. 486 method_iterator method_begin() const { 487 return method_iterator(decls_begin()); 488 } 489 /// method_end - Method end iterator. 490 method_iterator method_end() const { 491 return method_iterator(decls_end()); 492 } 493 494 /// Iterator access to constructor members. 495 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 496 497 ctor_iterator ctor_begin() const { 498 return ctor_iterator(decls_begin()); 499 } 500 ctor_iterator ctor_end() const { 501 return ctor_iterator(decls_end()); 502 } 503 504 /// hasConstCopyConstructor - Determines whether this class has a 505 /// copy constructor that accepts a const-qualified argument. 506 bool hasConstCopyConstructor(ASTContext &Context) const; 507 508 /// getCopyConstructor - Returns the copy constructor for this class 509 CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 510 unsigned TypeQuals) const; 511 512 /// hasConstCopyAssignment - Determines whether this class has a 513 /// copy assignment operator that accepts a const-qualified argument. 514 /// It returns its decl in MD if found. 515 bool hasConstCopyAssignment(ASTContext &Context, 516 const CXXMethodDecl *&MD) const; 517 518 /// addedConstructor - Notify the class that another constructor has 519 /// been added. This routine helps maintain information about the 520 /// class based on which constructors have been added. 521 void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 522 523 /// hasUserDeclaredConstructor - Whether this class has any 524 /// user-declared constructors. When true, a default constructor 525 /// will not be implicitly declared. 526 bool hasUserDeclaredConstructor() const { 527 assert((isDefinition() || 528 cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 529 "Incomplete record decl!"); 530 return UserDeclaredConstructor; 531 } 532 533 /// hasUserDeclaredCopyConstructor - Whether this class has a 534 /// user-declared copy constructor. When false, a copy constructor 535 /// will be implicitly declared. 536 bool hasUserDeclaredCopyConstructor() const { 537 return UserDeclaredCopyConstructor; 538 } 539 540 /// addedAssignmentOperator - Notify the class that another assignment 541 /// operator has been added. This routine helps maintain information about the 542 /// class based on which operators have been added. 543 void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 544 545 /// hasUserDeclaredCopyAssignment - Whether this class has a 546 /// user-declared copy assignment operator. When false, a copy 547 /// assigment operator will be implicitly declared. 548 bool hasUserDeclaredCopyAssignment() const { 549 return UserDeclaredCopyAssignment; 550 } 551 552 /// hasUserDeclaredDestructor - Whether this class has a 553 /// user-declared destructor. When false, a destructor will be 554 /// implicitly declared. 555 bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 556 557 /// setUserDeclaredDestructor - Set whether this class has a 558 /// user-declared destructor. If not set by the time the class is 559 /// fully defined, a destructor will be implicitly declared. 560 void setUserDeclaredDestructor(bool UCD) { 561 UserDeclaredDestructor = UCD; 562 } 563 564 /// getConversions - Retrieve the overload set containing all of the 565 /// conversion functions in this class. 566 OverloadedFunctionDecl *getConversionFunctions() { 567 assert((this->isDefinition() || 568 cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 569 "getConversionFunctions() called on incomplete type"); 570 return &Conversions; 571 } 572 const OverloadedFunctionDecl *getConversionFunctions() const { 573 assert((this->isDefinition() || 574 cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 575 "getConversionFunctions() called on incomplete type"); 576 return &Conversions; 577 } 578 579 /// getVisibleConversionFunctions - get all conversion functions visible 580 /// in current class; including conversion function templates. 581 OverloadedFunctionDecl *getVisibleConversionFunctions(ASTContext &Context, 582 CXXRecordDecl *RD); 583 /// addVisibleConversionFunction - Add a new conversion function to the 584 /// list of visible conversion functions. 585 void addVisibleConversionFunction(ASTContext &Context, 586 CXXConversionDecl *ConvDecl); 587 588 /// \brief Add a new conversion function template to the list of visible 589 /// conversion functions. 590 void addVisibleConversionFunction(ASTContext &Context, 591 FunctionTemplateDecl *ConvDecl); 592 593 /// addConversionFunction - Add a new conversion function to the 594 /// list of conversion functions. 595 void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl); 596 597 /// \brief Add a new conversion function template to the list of conversion 598 /// functions. 599 void addConversionFunction(ASTContext &Context, 600 FunctionTemplateDecl *ConvDecl); 601 602 /// isAggregate - Whether this class is an aggregate (C++ 603 /// [dcl.init.aggr]), which is a class with no user-declared 604 /// constructors, no private or protected non-static data members, 605 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 606 bool isAggregate() const { return Aggregate; } 607 608 /// setAggregate - Set whether this class is an aggregate (C++ 609 /// [dcl.init.aggr]). 610 void setAggregate(bool Agg) { Aggregate = Agg; } 611 612 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 613 /// that is an aggregate that has no non-static non-POD data members, no 614 /// reference data members, no user-defined copy assignment operator and no 615 /// user-defined destructor. 616 bool isPOD() const { return PlainOldData; } 617 618 /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 619 void setPOD(bool POD) { PlainOldData = POD; } 620 621 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 622 /// means it has a virtual function, virtual base, data member (other than 623 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 624 /// a check for union-ness. 625 bool isEmpty() const { return Empty; } 626 627 /// Set whether this class is empty (C++0x [meta.unary.prop]) 628 void setEmpty(bool Emp) { Empty = Emp; } 629 630 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 631 /// which means that the class contains or inherits a virtual function. 632 bool isPolymorphic() const { return Polymorphic; } 633 634 /// setPolymorphic - Set whether this class is polymorphic (C++ 635 /// [class.virtual]). 636 void setPolymorphic(bool Poly) { Polymorphic = Poly; } 637 638 /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 639 /// which means that the class contains or inherits a pure virtual function. 640 bool isAbstract() const { return Abstract; } 641 642 /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 643 void setAbstract(bool Abs) { Abstract = Abs; } 644 645 // hasTrivialConstructor - Whether this class has a trivial constructor 646 // (C++ [class.ctor]p5) 647 bool hasTrivialConstructor() const { return HasTrivialConstructor; } 648 649 // setHasTrivialConstructor - Set whether this class has a trivial constructor 650 // (C++ [class.ctor]p5) 651 void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 652 653 // hasTrivialCopyConstructor - Whether this class has a trivial copy 654 // constructor (C++ [class.copy]p6) 655 bool hasTrivialCopyConstructor() const { return HasTrivialCopyConstructor; } 656 657 // setHasTrivialCopyConstructor - Set whether this class has a trivial 658 // copy constructor (C++ [class.copy]p6) 659 void setHasTrivialCopyConstructor(bool TC) { HasTrivialCopyConstructor = TC; } 660 661 // hasTrivialCopyAssignment - Whether this class has a trivial copy 662 // assignment operator (C++ [class.copy]p11) 663 bool hasTrivialCopyAssignment() const { return HasTrivialCopyAssignment; } 664 665 // setHasTrivialCopyAssignment - Set whether this class has a 666 // trivial copy assignment operator (C++ [class.copy]p11) 667 void setHasTrivialCopyAssignment(bool TC) { HasTrivialCopyAssignment = TC; } 668 669 // hasTrivialDestructor - Whether this class has a trivial destructor 670 // (C++ [class.dtor]p3) 671 bool hasTrivialDestructor() const { return HasTrivialDestructor; } 672 673 // setHasTrivialDestructor - Set whether this class has a trivial destructor 674 // (C++ [class.dtor]p3) 675 void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 676 677 /// \brief If this record is an instantiation of a member class, 678 /// retrieves the member class from which it was instantiated. 679 /// 680 /// This routine will return non-NULL for (non-templated) member 681 /// classes of class templates. For example, given: 682 /// 683 /// \code 684 /// template<typename T> 685 /// struct X { 686 /// struct A { }; 687 /// }; 688 /// \endcode 689 /// 690 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 691 /// whose parent is the class template specialization X<int>. For 692 /// this declaration, getInstantiatedFromMemberClass() will return 693 /// the CXXRecordDecl X<T>::A. When a complete definition of 694 /// X<int>::A is required, it will be instantiated from the 695 /// declaration returned by getInstantiatedFromMemberClass(). 696 CXXRecordDecl *getInstantiatedFromMemberClass() const { 697 return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>(); 698 } 699 700 /// \brief Specify that this record is an instantiation of the 701 /// member class RD. 702 void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 703 TemplateOrInstantiation = RD; 704 } 705 706 /// \brief Retrieves the class template that is described by this 707 /// class declaration. 708 /// 709 /// Every class template is represented as a ClassTemplateDecl and a 710 /// CXXRecordDecl. The former contains template properties (such as 711 /// the template parameter lists) while the latter contains the 712 /// actual description of the template's 713 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 714 /// CXXRecordDecl that from a ClassTemplateDecl, while 715 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 716 /// a CXXRecordDecl. 717 ClassTemplateDecl *getDescribedClassTemplate() const { 718 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 719 } 720 721 void setDescribedClassTemplate(ClassTemplateDecl *Template) { 722 TemplateOrInstantiation = Template; 723 } 724 725 /// getDefaultConstructor - Returns the default constructor for this class 726 CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 727 728 /// getDestructor - Returns the destructor decl for this class. 729 const CXXDestructorDecl *getDestructor(ASTContext &Context); 730 731 /// isLocalClass - If the class is a local class [class.local], returns 732 /// the enclosing function declaration. 733 const FunctionDecl *isLocalClass() const { 734 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 735 return RD->isLocalClass(); 736 737 return dyn_cast<FunctionDecl>(getDeclContext()); 738 } 739 740 /// viewInheritance - Renders and displays an inheritance diagram 741 /// for this C++ class and all of its base classes (transitively) using 742 /// GraphViz. 743 void viewInheritance(ASTContext& Context) const; 744 745 static bool classof(const Decl *D) { 746 return D->getKind() == CXXRecord || 747 D->getKind() == ClassTemplateSpecialization || 748 D->getKind() == ClassTemplatePartialSpecialization; 749 } 750 static bool classof(const CXXRecordDecl *D) { return true; } 751 static bool classof(const ClassTemplateSpecializationDecl *D) { 752 return true; 753 } 754}; 755 756/// CXXMethodDecl - Represents a static or instance method of a 757/// struct/union/class. 758class CXXMethodDecl : public FunctionDecl { 759protected: 760 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 761 DeclarationName N, QualType T, DeclaratorInfo *DInfo, 762 bool isStatic, bool isInline) 763 : FunctionDecl(DK, RD, L, N, T, DInfo, (isStatic ? Static : None), 764 isInline) {} 765 766public: 767 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 768 SourceLocation L, DeclarationName N, 769 QualType T, DeclaratorInfo *DInfo, 770 bool isStatic = false, 771 bool isInline = false); 772 773 bool isStatic() const { return getStorageClass() == Static; } 774 bool isInstance() const { return !isStatic(); } 775 776 bool isVirtual() const { 777 return isVirtualAsWritten() || 778 (begin_overridden_methods() != end_overridden_methods()); 779 } 780 781 /// 782 void addOverriddenMethod(const CXXMethodDecl *MD); 783 784 typedef const CXXMethodDecl ** method_iterator; 785 786 method_iterator begin_overridden_methods() const; 787 method_iterator end_overridden_methods() const; 788 789 /// getParent - Returns the parent of this method declaration, which 790 /// is the class in which this method is defined. 791 const CXXRecordDecl *getParent() const { 792 return cast<CXXRecordDecl>(FunctionDecl::getParent()); 793 } 794 795 /// getParent - Returns the parent of this method declaration, which 796 /// is the class in which this method is defined. 797 CXXRecordDecl *getParent() { 798 return const_cast<CXXRecordDecl *>( 799 cast<CXXRecordDecl>(FunctionDecl::getParent())); 800 } 801 802 /// getThisType - Returns the type of 'this' pointer. 803 /// Should only be called for instance methods. 804 QualType getThisType(ASTContext &C) const; 805 806 unsigned getTypeQualifiers() const { 807 return getType()->getAsFunctionProtoType()->getTypeQuals(); 808 } 809 810 // Implement isa/cast/dyncast/etc. 811 static bool classof(const Decl *D) { 812 return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 813 } 814 static bool classof(const CXXMethodDecl *D) { return true; } 815}; 816 817/// CXXBaseOrMemberInitializer - Represents a C++ base or member 818/// initializer, which is part of a constructor initializer that 819/// initializes one non-static member variable or one base class. For 820/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 821/// initializers: 822/// 823/// @code 824/// class A { }; 825/// class B : public A { 826/// float f; 827/// public: 828/// B(A& a) : A(a), f(3.14159) { } 829/// }; 830/// @endcode 831class CXXBaseOrMemberInitializer { 832 /// BaseOrMember - This points to the entity being initialized, 833 /// which is either a base class (a Type) or a non-static data 834 /// member. When the low bit is 1, it's a base 835 /// class; when the low bit is 0, it's a member. 836 uintptr_t BaseOrMember; 837 838 /// Args - The arguments used to initialize the base or member. 839 Stmt **Args; 840 unsigned NumArgs; 841 842 /// \brief Stores either the constructor to call to initialize this base or 843 /// member (a CXXConstructorDecl pointer), or stores the anonymous union of 844 /// which the initialized value is a member. 845 /// 846 /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's 847 /// anonymous union data member, this field holds the FieldDecl for the 848 /// member of the anonymous union being initialized. 849 /// @code 850 /// struct X { 851 /// X() : au_i1(123) {} 852 /// union { 853 /// int au_i1; 854 /// float au_f1; 855 /// }; 856 /// }; 857 /// @endcode 858 /// In above example, BaseOrMember holds the field decl. for anonymous union 859 /// and AnonUnionMember holds field decl for au_i1. 860 llvm::PointerUnion<CXXConstructorDecl *, FieldDecl *> CtorOrAnonUnion; 861 862 /// IdLoc - Location of the id in ctor-initializer list. 863 SourceLocation IdLoc; 864 865 /// RParenLoc - Location of the right paren of the ctor-initializer. 866 SourceLocation RParenLoc; 867 868public: 869 /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 870 explicit 871 CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, 872 CXXConstructorDecl *C, 873 SourceLocation L, SourceLocation R); 874 875 /// CXXBaseOrMemberInitializer - Creates a new member initializer. 876 explicit 877 CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, 878 CXXConstructorDecl *C, 879 SourceLocation L, SourceLocation R); 880 881 /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer. 882 ~CXXBaseOrMemberInitializer(); 883 884 /// arg_iterator - Iterates through the member initialization 885 /// arguments. 886 typedef ExprIterator arg_iterator; 887 888 /// arg_const_iterator - Iterates through the member initialization 889 /// arguments. 890 typedef ConstExprIterator const_arg_iterator; 891 892 /// getBaseOrMember - get the generic 'member' representing either the field 893 /// or a base class. 894 void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); } 895 896 /// isBaseInitializer - Returns true when this initializer is 897 /// initializing a base class. 898 bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; } 899 900 /// isMemberInitializer - Returns true when this initializer is 901 /// initializing a non-static data member. 902 bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; } 903 904 /// getBaseClass - If this is a base class initializer, returns the 905 /// type used to specify the initializer. The resulting type will be 906 /// a class type or a typedef of a class type. If this is not a base 907 /// class initializer, returns NULL. 908 Type *getBaseClass() { 909 if (isBaseInitializer()) 910 return reinterpret_cast<Type*>(BaseOrMember & ~0x01); 911 else 912 return 0; 913 } 914 915 /// getBaseClass - If this is a base class initializer, returns the 916 /// type used to specify the initializer. The resulting type will be 917 /// a class type or a typedef of a class type. If this is not a base 918 /// class initializer, returns NULL. 919 const Type *getBaseClass() const { 920 if (isBaseInitializer()) 921 return reinterpret_cast<const Type*>(BaseOrMember & ~0x01); 922 else 923 return 0; 924 } 925 926 /// getMember - If this is a member initializer, returns the 927 /// declaration of the non-static data member being 928 /// initialized. Otherwise, returns NULL. 929 FieldDecl *getMember() { 930 if (isMemberInitializer()) 931 return reinterpret_cast<FieldDecl *>(BaseOrMember); 932 else 933 return 0; 934 } 935 936 void setMember(FieldDecl * anonUnionField) { 937 BaseOrMember = reinterpret_cast<uintptr_t>(anonUnionField); 938 } 939 940 FieldDecl *getAnonUnionMember() const { 941 return CtorOrAnonUnion.dyn_cast<FieldDecl *>(); 942 } 943 void setAnonUnionMember(FieldDecl *anonMember) { 944 CtorOrAnonUnion = anonMember; 945 } 946 947 const CXXConstructorDecl *getConstructor() const { 948 return CtorOrAnonUnion.dyn_cast<CXXConstructorDecl *>(); 949 } 950 951 SourceLocation getSourceLocation() const { return IdLoc; } 952 SourceLocation getRParenLoc() const { return RParenLoc; } 953 954 /// arg_begin() - Retrieve an iterator to the first initializer argument. 955 arg_iterator arg_begin() { return Args; } 956 /// arg_begin() - Retrieve an iterator to the first initializer argument. 957 const_arg_iterator const_arg_begin() const { return Args; } 958 959 /// arg_end() - Retrieve an iterator past the last initializer argument. 960 arg_iterator arg_end() { return Args + NumArgs; } 961 /// arg_end() - Retrieve an iterator past the last initializer argument. 962 const_arg_iterator const_arg_end() const { return Args + NumArgs; } 963 964 /// getNumArgs - Determine the number of arguments used to 965 /// initialize the member or base. 966 unsigned getNumArgs() const { return NumArgs; } 967}; 968 969/// CXXConstructorDecl - Represents a C++ constructor within a 970/// class. For example: 971/// 972/// @code 973/// class X { 974/// public: 975/// explicit X(int); // represented by a CXXConstructorDecl. 976/// }; 977/// @endcode 978class CXXConstructorDecl : public CXXMethodDecl { 979 /// Explicit - Whether this constructor is explicit. 980 bool Explicit : 1; 981 982 /// ImplicitlyDefined - Whether this constructor was implicitly 983 /// defined by the compiler. When false, the constructor was defined 984 /// by the user. In C++03, this flag will have the same value as 985 /// Implicit. In C++0x, however, a constructor that is 986 /// explicitly defaulted (i.e., defined with " = default") will have 987 /// @c !Implicit && ImplicitlyDefined. 988 bool ImplicitlyDefined : 1; 989 990 /// Support for base and member initializers. 991 /// BaseOrMemberInitializers - The arguments used to initialize the base 992 /// or member. 993 CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 994 unsigned NumBaseOrMemberInitializers; 995 996 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 997 DeclarationName N, QualType T, DeclaratorInfo *DInfo, 998 bool isExplicit, bool isInline, bool isImplicitlyDeclared) 999 : CXXMethodDecl(CXXConstructor, RD, L, N, T, DInfo, false, isInline), 1000 Explicit(isExplicit), ImplicitlyDefined(false), 1001 BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 1002 setImplicit(isImplicitlyDeclared); 1003 } 1004 virtual void Destroy(ASTContext& C); 1005 1006public: 1007 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1008 SourceLocation L, DeclarationName N, 1009 QualType T, DeclaratorInfo *DInfo, 1010 bool isExplicit, 1011 bool isInline, bool isImplicitlyDeclared); 1012 1013 /// isExplicit - Whether this constructor was marked "explicit" or not. 1014 bool isExplicit() const { return Explicit; } 1015 1016 /// isImplicitlyDefined - Whether this constructor was implicitly 1017 /// defined. If false, then this constructor was defined by the 1018 /// user. This operation can only be invoked if the constructor has 1019 /// already been defined. 1020 bool isImplicitlyDefined(ASTContext &C) const { 1021 assert(isThisDeclarationADefinition() && 1022 "Can only get the implicit-definition flag once the " 1023 "constructor has been defined"); 1024 return ImplicitlyDefined; 1025 } 1026 1027 /// setImplicitlyDefined - Set whether this constructor was 1028 /// implicitly defined or not. 1029 void setImplicitlyDefined(bool ID) { 1030 assert(isThisDeclarationADefinition() && 1031 "Can only set the implicit-definition flag once the constructor " 1032 "has been defined"); 1033 ImplicitlyDefined = ID; 1034 } 1035 1036 /// init_iterator - Iterates through the member/base initializer list. 1037 typedef CXXBaseOrMemberInitializer **init_iterator; 1038 1039 /// init_const_iterator - Iterates through the memberbase initializer list. 1040 typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 1041 1042 /// init_begin() - Retrieve an iterator to the first initializer. 1043 init_iterator init_begin() { return BaseOrMemberInitializers; } 1044 /// begin() - Retrieve an iterator to the first initializer. 1045 init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 1046 1047 /// init_end() - Retrieve an iterator past the last initializer. 1048 init_iterator init_end() { 1049 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1050 } 1051 /// end() - Retrieve an iterator past the last initializer. 1052 init_const_iterator init_end() const { 1053 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1054 } 1055 1056 /// getNumArgs - Determine the number of arguments used to 1057 /// initialize the member or base. 1058 unsigned getNumBaseOrMemberInitializers() const { 1059 return NumBaseOrMemberInitializers; 1060 } 1061 1062 void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) { 1063 NumBaseOrMemberInitializers = numBaseOrMemberInitializers; 1064 } 1065 1066 void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) { 1067 BaseOrMemberInitializers = initializers; 1068 } 1069 /// isDefaultConstructor - Whether this constructor is a default 1070 /// constructor (C++ [class.ctor]p5), which can be used to 1071 /// default-initialize a class of this type. 1072 bool isDefaultConstructor() const; 1073 1074 /// isCopyConstructor - Whether this constructor is a copy 1075 /// constructor (C++ [class.copy]p2, which can be used to copy the 1076 /// class. @p TypeQuals will be set to the qualifiers on the 1077 /// argument type. For example, @p TypeQuals would be set to @c 1078 /// QualType::Const for the following copy constructor: 1079 /// 1080 /// @code 1081 /// class X { 1082 /// public: 1083 /// X(const X&); 1084 /// }; 1085 /// @endcode 1086 bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 1087 1088 /// isCopyConstructor - Whether this constructor is a copy 1089 /// constructor (C++ [class.copy]p2, which can be used to copy the 1090 /// class. 1091 bool isCopyConstructor(ASTContext &Context) const { 1092 unsigned TypeQuals = 0; 1093 return isCopyConstructor(Context, TypeQuals); 1094 } 1095 1096 /// isConvertingConstructor - Whether this constructor is a 1097 /// converting constructor (C++ [class.conv.ctor]), which can be 1098 /// used for user-defined conversions. 1099 bool isConvertingConstructor(bool AllowExplicit) const; 1100 1101 // Implement isa/cast/dyncast/etc. 1102 static bool classof(const Decl *D) { 1103 return D->getKind() == CXXConstructor; 1104 } 1105 static bool classof(const CXXConstructorDecl *D) { return true; } 1106}; 1107 1108/// CXXDestructorDecl - Represents a C++ destructor within a 1109/// class. For example: 1110/// 1111/// @code 1112/// class X { 1113/// public: 1114/// ~X(); // represented by a CXXDestructorDecl. 1115/// }; 1116/// @endcode 1117class CXXDestructorDecl : public CXXMethodDecl { 1118public: 1119 enum KindOfObjectToDestroy { 1120 VBASE = 0x1, 1121 DRCTNONVBASE = 0x2, 1122 ANYBASE = 0x3 1123 }; 1124private: 1125 /// ImplicitlyDefined - Whether this destructor was implicitly 1126 /// defined by the compiler. When false, the destructor was defined 1127 /// by the user. In C++03, this flag will have the same value as 1128 /// Implicit. In C++0x, however, a destructor that is 1129 /// explicitly defaulted (i.e., defined with " = default") will have 1130 /// @c !Implicit && ImplicitlyDefined. 1131 bool ImplicitlyDefined : 1; 1132 1133 /// Support for base and member destruction. 1134 /// BaseOrMemberDestructions - The arguments used to destruct the base 1135 /// or member. Each uintptr_t value represents one of base classes (either 1136 /// virtual or direct non-virtual base), or non-static data member 1137 /// to be destroyed. The low two bits encode the kind of object 1138 /// being destroyed. 1139 uintptr_t *BaseOrMemberDestructions; 1140 unsigned NumBaseOrMemberDestructions; 1141 1142 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 1143 DeclarationName N, QualType T, 1144 bool isInline, bool isImplicitlyDeclared) 1145 : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*DInfo=*/0, false, isInline), 1146 ImplicitlyDefined(false), 1147 BaseOrMemberDestructions(0), NumBaseOrMemberDestructions(0) { 1148 setImplicit(isImplicitlyDeclared); 1149 } 1150 virtual void Destroy(ASTContext& C); 1151 1152public: 1153 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1154 SourceLocation L, DeclarationName N, 1155 QualType T, bool isInline, 1156 bool isImplicitlyDeclared); 1157 1158 /// isImplicitlyDefined - Whether this destructor was implicitly 1159 /// defined. If false, then this destructor was defined by the 1160 /// user. This operation can only be invoked if the destructor has 1161 /// already been defined. 1162 bool isImplicitlyDefined() const { 1163 assert(isThisDeclarationADefinition() && 1164 "Can only get the implicit-definition flag once the destructor has been defined"); 1165 return ImplicitlyDefined; 1166 } 1167 1168 /// setImplicitlyDefined - Set whether this destructor was 1169 /// implicitly defined or not. 1170 void setImplicitlyDefined(bool ID) { 1171 assert(isThisDeclarationADefinition() && 1172 "Can only set the implicit-definition flag once the destructor has been defined"); 1173 ImplicitlyDefined = ID; 1174 } 1175 1176 /// destr_iterator - Iterates through the member/base destruction list. 1177 1178 /// destr_const_iterator - Iterates through the member/base destruction list. 1179 typedef uintptr_t const destr_const_iterator; 1180 1181 /// destr_begin() - Retrieve an iterator to the first destructed member/base. 1182 uintptr_t* destr_begin() { 1183 return BaseOrMemberDestructions; 1184 } 1185 /// destr_begin() - Retrieve an iterator to the first destructed member/base. 1186 uintptr_t* destr_begin() const { 1187 return BaseOrMemberDestructions; 1188 } 1189 1190 /// destr_end() - Retrieve an iterator past the last destructed member/base. 1191 uintptr_t* destr_end() { 1192 return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 1193 } 1194 /// destr_end() - Retrieve an iterator past the last destructed member/base. 1195 uintptr_t* destr_end() const { 1196 return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 1197 } 1198 1199 /// getNumBaseOrMemberDestructions - Number of base and non-static members 1200 /// to destroy. 1201 unsigned getNumBaseOrMemberDestructions() const { 1202 return NumBaseOrMemberDestructions; 1203 } 1204 1205 /// setNumBaseOrMemberDestructions - Set number of base and non-static members 1206 /// to destroy. 1207 void setNumBaseOrMemberDestructions(unsigned numBaseOrMemberDestructions) { 1208 NumBaseOrMemberDestructions = numBaseOrMemberDestructions; 1209 } 1210 1211 /// getBaseOrMemberToDestroy - get the generic 'member' representing either 1212 /// the field or a base class. 1213 uintptr_t* getBaseOrMemberToDestroy() const { 1214 return BaseOrMemberDestructions; 1215 } 1216 1217 /// setBaseOrMemberToDestroy - set the generic 'member' representing either 1218 /// the field or a base class. 1219 void setBaseOrMemberDestructions(uintptr_t* baseOrMemberDestructions) { 1220 BaseOrMemberDestructions = baseOrMemberDestructions; 1221 } 1222 1223 /// isVbaseToDestroy - returns true, if object is virtual base. 1224 bool isVbaseToDestroy(uintptr_t Vbase) const { 1225 return (Vbase & VBASE) != 0; 1226 } 1227 /// isDirectNonVBaseToDestroy - returns true, if object is direct non-virtual 1228 /// base. 1229 bool isDirectNonVBaseToDestroy(uintptr_t DrctNonVbase) const { 1230 return (DrctNonVbase & DRCTNONVBASE) != 0; 1231 } 1232 /// isAnyBaseToDestroy - returns true, if object is any base (virtual or 1233 /// direct non-virtual) 1234 bool isAnyBaseToDestroy(uintptr_t AnyBase) const { 1235 return (AnyBase & ANYBASE) != 0; 1236 } 1237 /// isMemberToDestroy - returns true if object is a non-static data member. 1238 bool isMemberToDestroy(uintptr_t Member) const { 1239 return (Member & ANYBASE) == 0; 1240 } 1241 /// getAnyBaseClassToDestroy - Get the type for the given base class object. 1242 Type *getAnyBaseClassToDestroy(uintptr_t Base) const { 1243 if (isAnyBaseToDestroy(Base)) 1244 return reinterpret_cast<Type*>(Base & ~0x03); 1245 return 0; 1246 } 1247 /// getMemberToDestroy - Get the member for the given object. 1248 FieldDecl *getMemberToDestroy(uintptr_t Member) const { 1249 if (isMemberToDestroy(Member)) 1250 return reinterpret_cast<FieldDecl *>(Member); 1251 return 0; 1252 } 1253 /// getVbaseClassToDestroy - Get the virtual base. 1254 Type *getVbaseClassToDestroy(uintptr_t Vbase) const { 1255 if (isVbaseToDestroy(Vbase)) 1256 return reinterpret_cast<Type*>(Vbase & ~0x01); 1257 return 0; 1258 } 1259 /// getDirectNonVBaseClassToDestroy - Get the virtual base. 1260 Type *getDirectNonVBaseClassToDestroy(uintptr_t Base) const { 1261 if (isDirectNonVBaseToDestroy(Base)) 1262 return reinterpret_cast<Type*>(Base & ~0x02); 1263 return 0; 1264 } 1265 1266 // Implement isa/cast/dyncast/etc. 1267 static bool classof(const Decl *D) { 1268 return D->getKind() == CXXDestructor; 1269 } 1270 static bool classof(const CXXDestructorDecl *D) { return true; } 1271}; 1272 1273/// CXXConversionDecl - Represents a C++ conversion function within a 1274/// class. For example: 1275/// 1276/// @code 1277/// class X { 1278/// public: 1279/// operator bool(); 1280/// }; 1281/// @endcode 1282class CXXConversionDecl : public CXXMethodDecl { 1283 /// Explicit - Whether this conversion function is marked 1284 /// "explicit", meaning that it can only be applied when the user 1285 /// explicitly wrote a cast. This is a C++0x feature. 1286 bool Explicit : 1; 1287 1288 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1289 DeclarationName N, QualType T, DeclaratorInfo *DInfo, 1290 bool isInline, bool isExplicit) 1291 : CXXMethodDecl(CXXConversion, RD, L, N, T, DInfo, false, isInline), 1292 Explicit(isExplicit) { } 1293 1294public: 1295 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1296 SourceLocation L, DeclarationName N, 1297 QualType T, DeclaratorInfo *DInfo, 1298 bool isInline, bool isExplicit); 1299 1300 /// isExplicit - Whether this is an explicit conversion operator 1301 /// (C++0x only). Explicit conversion operators are only considered 1302 /// when the user has explicitly written a cast. 1303 bool isExplicit() const { return Explicit; } 1304 1305 /// getConversionType - Returns the type that this conversion 1306 /// function is converting to. 1307 QualType getConversionType() const { 1308 return getType()->getAsFunctionType()->getResultType(); 1309 } 1310 1311 // Implement isa/cast/dyncast/etc. 1312 static bool classof(const Decl *D) { 1313 return D->getKind() == CXXConversion; 1314 } 1315 static bool classof(const CXXConversionDecl *D) { return true; } 1316}; 1317 1318/// FriendDecl - Represents the declaration of a friend entity, 1319/// which can be a function, a type, or a templated function or type. 1320// For example: 1321/// 1322/// @code 1323/// template <typename T> class A { 1324/// friend int foo(T); 1325/// friend class B; 1326/// friend T; // only in C++0x 1327/// template <typename U> friend class C; 1328/// template <typename U> friend A& operator+=(A&, const U&) { ... } 1329/// }; 1330/// @endcode 1331/// 1332/// The semantic context of a friend decl is its declaring class. 1333class FriendDecl : public Decl { 1334public: 1335 typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 1336 1337private: 1338 // The declaration that's a friend of this class. 1339 FriendUnion Friend; 1340 1341 // Location of the 'friend' specifier. 1342 SourceLocation FriendLoc; 1343 1344 FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend, 1345 SourceLocation FriendL) 1346 : Decl(Decl::Friend, DC, L), 1347 Friend(Friend), 1348 FriendLoc(FriendL) { 1349 } 1350 1351public: 1352 static FriendDecl *Create(ASTContext &C, DeclContext *DC, 1353 SourceLocation L, FriendUnion Friend_, 1354 SourceLocation FriendL); 1355 1356 /// If this friend declaration names an (untemplated but 1357 /// possibly dependent) type, return the type; otherwise 1358 /// return null. This is used only for C++0x's unelaborated 1359 /// friend type declarations. 1360 Type *getFriendType() const { 1361 return Friend.dyn_cast<Type*>(); 1362 } 1363 1364 /// If this friend declaration doesn't name an unelaborated 1365 /// type, return the inner declaration. 1366 NamedDecl *getFriendDecl() const { 1367 return Friend.dyn_cast<NamedDecl*>(); 1368 } 1369 1370 /// Retrieves the location of the 'friend' keyword. 1371 SourceLocation getFriendLoc() const { 1372 return FriendLoc; 1373 } 1374 1375 // Implement isa/cast/dyncast/etc. 1376 static bool classof(const Decl *D) { 1377 return D->getKind() == Decl::Friend; 1378 } 1379 static bool classof(const FriendDecl *D) { return true; } 1380}; 1381 1382/// LinkageSpecDecl - This represents a linkage specification. For example: 1383/// extern "C" void foo(); 1384/// 1385class LinkageSpecDecl : public Decl, public DeclContext { 1386public: 1387 /// LanguageIDs - Used to represent the language in a linkage 1388 /// specification. The values are part of the serialization abi for 1389 /// ASTs and cannot be changed without altering that abi. To help 1390 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1391 /// from the dwarf standard. 1392 enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 1393 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 1394private: 1395 /// Language - The language for this linkage specification. 1396 LanguageIDs Language; 1397 1398 /// HadBraces - Whether this linkage specification had curly braces or not. 1399 bool HadBraces : 1; 1400 1401 LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1402 bool Braces) 1403 : Decl(LinkageSpec, DC, L), 1404 DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1405 1406public: 1407 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1408 SourceLocation L, LanguageIDs Lang, 1409 bool Braces); 1410 1411 LanguageIDs getLanguage() const { return Language; } 1412 1413 /// hasBraces - Determines whether this linkage specification had 1414 /// braces in its syntactic form. 1415 bool hasBraces() const { return HadBraces; } 1416 1417 static bool classof(const Decl *D) { 1418 return D->getKind() == LinkageSpec; 1419 } 1420 static bool classof(const LinkageSpecDecl *D) { return true; } 1421 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1422 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1423 } 1424 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1425 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1426 } 1427}; 1428 1429/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1430/// 1431/// using namespace std; 1432/// 1433// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1434// artificial name, for all using-directives in order to store 1435// them in DeclContext effectively. 1436class UsingDirectiveDecl : public NamedDecl { 1437 1438 /// SourceLocation - Location of 'namespace' token. 1439 SourceLocation NamespaceLoc; 1440 1441 /// \brief The source range that covers the nested-name-specifier 1442 /// preceding the namespace name. 1443 SourceRange QualifierRange; 1444 1445 /// \brief The nested-name-specifier that precedes the namespace 1446 /// name, if any. 1447 NestedNameSpecifier *Qualifier; 1448 1449 /// IdentLoc - Location of nominated namespace-name identifier. 1450 // FIXME: We don't store location of scope specifier. 1451 SourceLocation IdentLoc; 1452 1453 /// NominatedNamespace - Namespace nominated by using-directive. 1454 NamespaceDecl *NominatedNamespace; 1455 1456 /// Enclosing context containing both using-directive and nomintated 1457 /// namespace. 1458 DeclContext *CommonAncestor; 1459 1460 /// getUsingDirectiveName - Returns special DeclarationName used by 1461 /// using-directives. This is only used by DeclContext for storing 1462 /// UsingDirectiveDecls in its lookup structure. 1463 static DeclarationName getName() { 1464 return DeclarationName::getUsingDirectiveName(); 1465 } 1466 1467 UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1468 SourceLocation NamespcLoc, 1469 SourceRange QualifierRange, 1470 NestedNameSpecifier *Qualifier, 1471 SourceLocation IdentLoc, 1472 NamespaceDecl *Nominated, 1473 DeclContext *CommonAncestor) 1474 : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1475 NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1476 Qualifier(Qualifier), IdentLoc(IdentLoc), 1477 NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0), 1478 CommonAncestor(CommonAncestor) { 1479 } 1480 1481public: 1482 /// \brief Retrieve the source range of the nested-name-specifier 1483 /// that qualifiers the namespace name. 1484 SourceRange getQualifierRange() const { return QualifierRange; } 1485 1486 /// \brief Retrieve the nested-name-specifier that qualifies the 1487 /// name of the namespace. 1488 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1489 1490 /// getNominatedNamespace - Returns namespace nominated by using-directive. 1491 NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; } 1492 1493 const NamespaceDecl *getNominatedNamespace() const { 1494 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1495 } 1496 1497 /// getCommonAncestor - returns common ancestor context of using-directive, 1498 /// and nominated by it namespace. 1499 DeclContext *getCommonAncestor() { return CommonAncestor; } 1500 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1501 1502 /// getNamespaceKeyLocation - Returns location of namespace keyword. 1503 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1504 1505 /// getIdentLocation - Returns location of identifier. 1506 SourceLocation getIdentLocation() const { return IdentLoc; } 1507 1508 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1509 SourceLocation L, 1510 SourceLocation NamespaceLoc, 1511 SourceRange QualifierRange, 1512 NestedNameSpecifier *Qualifier, 1513 SourceLocation IdentLoc, 1514 NamespaceDecl *Nominated, 1515 DeclContext *CommonAncestor); 1516 1517 static bool classof(const Decl *D) { 1518 return D->getKind() == Decl::UsingDirective; 1519 } 1520 static bool classof(const UsingDirectiveDecl *D) { return true; } 1521 1522 // Friend for getUsingDirectiveName. 1523 friend class DeclContext; 1524}; 1525 1526/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1527/// 1528/// @code 1529/// namespace Foo = Bar; 1530/// @endcode 1531class NamespaceAliasDecl : public NamedDecl { 1532 SourceLocation AliasLoc; 1533 1534 /// \brief The source range that covers the nested-name-specifier 1535 /// preceding the namespace name. 1536 SourceRange QualifierRange; 1537 1538 /// \brief The nested-name-specifier that precedes the namespace 1539 /// name, if any. 1540 NestedNameSpecifier *Qualifier; 1541 1542 /// IdentLoc - Location of namespace identifier. 1543 SourceLocation IdentLoc; 1544 1545 /// Namespace - The Decl that this alias points to. Can either be a 1546 /// NamespaceDecl or a NamespaceAliasDecl. 1547 NamedDecl *Namespace; 1548 1549 NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1550 SourceLocation AliasLoc, IdentifierInfo *Alias, 1551 SourceRange QualifierRange, 1552 NestedNameSpecifier *Qualifier, 1553 SourceLocation IdentLoc, NamedDecl *Namespace) 1554 : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1555 QualifierRange(QualifierRange), Qualifier(Qualifier), 1556 IdentLoc(IdentLoc), Namespace(Namespace) { } 1557 1558public: 1559 /// \brief Retrieve the source range of the nested-name-specifier 1560 /// that qualifiers the namespace name. 1561 SourceRange getQualifierRange() const { return QualifierRange; } 1562 1563 /// \brief Retrieve the nested-name-specifier that qualifies the 1564 /// name of the namespace. 1565 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1566 1567 NamespaceDecl *getNamespace() { 1568 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1569 return AD->getNamespace(); 1570 1571 return cast<NamespaceDecl>(Namespace); 1572 } 1573 1574 const NamespaceDecl *getNamespace() const { 1575 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1576 } 1577 1578 /// \brief Retrieve the namespace that this alias refers to, which 1579 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1580 NamedDecl *getAliasedNamespace() const { return Namespace; } 1581 1582 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1583 SourceLocation L, SourceLocation AliasLoc, 1584 IdentifierInfo *Alias, 1585 SourceRange QualifierRange, 1586 NestedNameSpecifier *Qualifier, 1587 SourceLocation IdentLoc, 1588 NamedDecl *Namespace); 1589 1590 static bool classof(const Decl *D) { 1591 return D->getKind() == Decl::NamespaceAlias; 1592 } 1593 static bool classof(const NamespaceAliasDecl *D) { return true; } 1594}; 1595 1596/// UsingDecl - Represents a C++ using-declaration. For example: 1597/// using someNameSpace::someIdentifier; 1598class UsingDecl : public NamedDecl { 1599 /// \brief The source range that covers the nested-name-specifier 1600 /// preceding the declaration name. 1601 SourceRange NestedNameRange; 1602 1603 /// \brief The source location of the target declaration name. 1604 SourceLocation TargetNameLocation; 1605 1606 /// \brief The source location of the "using" location itself. 1607 SourceLocation UsingLocation; 1608 1609 /// \brief Target declaration. 1610 NamedDecl* TargetDecl; 1611 1612 /// \brief Target nested name specifier. 1613 NestedNameSpecifier* TargetNestedNameDecl; 1614 1615 // \brief Has 'typename' keyword. 1616 bool IsTypeName; 1617 1618 UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1619 SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target, 1620 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) 1621 : NamedDecl(Decl::Using, DC, L, Target->getDeclName()), 1622 NestedNameRange(NNR), TargetNameLocation(TargetNL), 1623 UsingLocation(UL), TargetDecl(Target), 1624 TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { 1625 this->IdentifierNamespace = TargetDecl->getIdentifierNamespace(); 1626 } 1627 1628public: 1629 /// \brief Returns the source range that covers the nested-name-specifier 1630 /// preceding the namespace name. 1631 SourceRange getNestedNameRange() { return NestedNameRange; } 1632 1633 /// \brief Returns the source location of the target declaration name. 1634 SourceLocation getTargetNameLocation() { return TargetNameLocation; } 1635 1636 /// \brief Returns the source location of the "using" location itself. 1637 SourceLocation getUsingLocation() { return UsingLocation; } 1638 1639 /// \brief getTargetDecl - Returns target specified by using-decl. 1640 NamedDecl *getTargetDecl() { return TargetDecl; } 1641 const NamedDecl *getTargetDecl() const { return TargetDecl; } 1642 1643 /// \brief Get target nested name declaration. 1644 NestedNameSpecifier* getTargetNestedNameDecl() { 1645 return TargetNestedNameDecl; 1646 } 1647 1648 /// isTypeName - Return true if using decl has 'typename'. 1649 bool isTypeName() const { return IsTypeName; } 1650 1651 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1652 SourceLocation L, SourceRange NNR, SourceLocation TargetNL, 1653 SourceLocation UL, NamedDecl* Target, 1654 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg); 1655 1656 static bool classof(const Decl *D) { 1657 return D->getKind() == Decl::Using; 1658 } 1659 static bool classof(const UsingDecl *D) { return true; } 1660}; 1661 1662/// UnresolvedUsingDecl - Represents a using declaration whose name can not 1663/// yet be resolved. 1664class UnresolvedUsingDecl : public NamedDecl { 1665 /// \brief The source range that covers the nested-name-specifier 1666 /// preceding the declaration name. 1667 SourceRange TargetNestedNameRange; 1668 1669 /// \brief The source location of the target declaration name. 1670 SourceLocation TargetNameLocation; 1671 1672 NestedNameSpecifier *TargetNestedNameSpecifier; 1673 1674 DeclarationName TargetName; 1675 1676 // \brief Has 'typename' keyword. 1677 bool IsTypeName; 1678 1679 UnresolvedUsingDecl(DeclContext *DC, SourceLocation UsingLoc, 1680 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1681 SourceLocation TargetNameLoc, DeclarationName TargetName, 1682 bool IsTypeNameArg) 1683 : NamedDecl(Decl::UnresolvedUsing, DC, UsingLoc, TargetName), 1684 TargetNestedNameRange(TargetNNR), TargetNameLocation(TargetNameLoc), 1685 TargetNestedNameSpecifier(TargetNNS), TargetName(TargetName), 1686 IsTypeName(IsTypeNameArg) { } 1687 1688public: 1689 /// \brief Returns the source range that covers the nested-name-specifier 1690 /// preceding the namespace name. 1691 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1692 1693 /// \brief Get target nested name declaration. 1694 NestedNameSpecifier* getTargetNestedNameSpecifier() { 1695 return TargetNestedNameSpecifier; 1696 } 1697 1698 /// \brief Returns the source location of the target declaration name. 1699 SourceLocation getTargetNameLocation() const { return TargetNameLocation; } 1700 1701 /// \brief Returns the source location of the target declaration name. 1702 DeclarationName getTargetName() const { return TargetName; } 1703 1704 bool isTypeName() const { return IsTypeName; } 1705 1706 static UnresolvedUsingDecl *Create(ASTContext &C, DeclContext *DC, 1707 SourceLocation UsingLoc, 1708 SourceRange TargetNNR, 1709 NestedNameSpecifier *TargetNNS, 1710 SourceLocation TargetNameLoc, 1711 DeclarationName TargetName, 1712 bool IsTypeNameArg); 1713 1714 static bool classof(const Decl *D) { 1715 return D->getKind() == Decl::UnresolvedUsing; 1716 } 1717 static bool classof(const UnresolvedUsingDecl *D) { return true; } 1718}; 1719 1720/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1721class StaticAssertDecl : public Decl { 1722 Expr *AssertExpr; 1723 StringLiteral *Message; 1724 1725 StaticAssertDecl(DeclContext *DC, SourceLocation L, 1726 Expr *assertexpr, StringLiteral *message) 1727 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1728 1729public: 1730 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1731 SourceLocation L, Expr *AssertExpr, 1732 StringLiteral *Message); 1733 1734 Expr *getAssertExpr() { return AssertExpr; } 1735 const Expr *getAssertExpr() const { return AssertExpr; } 1736 1737 StringLiteral *getMessage() { return Message; } 1738 const StringLiteral *getMessage() const { return Message; } 1739 1740 virtual ~StaticAssertDecl(); 1741 virtual void Destroy(ASTContext& C); 1742 1743 static bool classof(const Decl *D) { 1744 return D->getKind() == Decl::StaticAssert; 1745 } 1746 static bool classof(StaticAssertDecl *D) { return true; } 1747}; 1748 1749/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1750/// into a diagnostic with <<. 1751const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1752 AccessSpecifier AS); 1753 1754} // end namespace clang 1755 1756#endif 1757