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