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