DeclCXX.h revision e7184df728bb339633d88c774b5097dd9318cc8a
1402e2422266b331d25374a90339711ed332952c0Christian Williams//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 2329db3eb85b10c4d4cbce8fbbc488af3481ea2f4Christian Williams// 313e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass// The LLVM Compiler Infrastructure 413e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass// 513e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass// This file is distributed under the University of Illinois Open Source 613e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass// License. See LICENSE.TXT for details. 713e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass// 813e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass//===----------------------------------------------------------------------===// 9cd21db2bb21da8047bf5485bb356de3ff5a5b494Christian Williams// 10cd21db2bb21da8047bf5485bb356de3ff5a5b494Christian Williams// This file defines the C++ Decl subclasses. 11cd21db2bb21da8047bf5485bb356de3ff5a5b494Christian Williams// 1213e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass//===----------------------------------------------------------------------===// 1313e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass 1413e343bf0b12d99043d3cdced94e86fb284e48d4Erich Douglass#ifndef LLVM_CLANG_AST_DECLCXX_H 15329db3eb85b10c4d4cbce8fbbc488af3481ea2f4Christian Williams#define LLVM_CLANG_AST_DECLCXX_H 16329db3eb85b10c4d4cbce8fbbc488af3481ea2f4Christian Williams 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 // Implement isa/cast/dyncast/etc. 874 static bool classof(const Decl *D) { 875 return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 876 } 877 static bool classof(const CXXMethodDecl *D) { return true; } 878}; 879 880/// CXXBaseOrMemberInitializer - Represents a C++ base or member 881/// initializer, which is part of a constructor initializer that 882/// initializes one non-static member variable or one base class. For 883/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 884/// initializers: 885/// 886/// @code 887/// class A { }; 888/// class B : public A { 889/// float f; 890/// public: 891/// B(A& a) : A(a), f(3.14159) { } 892/// }; 893/// @endcode 894class CXXBaseOrMemberInitializer { 895 /// \brief Either the base class name (stored as a DeclaratorInfo*) or the 896 /// field being initialized. 897 llvm::PointerUnion<DeclaratorInfo *, FieldDecl *> BaseOrMember; 898 899 /// \brief The source location for the field name. 900 SourceLocation MemberLocation; 901 902 /// Args - The arguments used to initialize the base or member. 903 Stmt **Args; 904 unsigned NumArgs; 905 906 /// \brief Stores either the constructor to call to initialize this base or 907 /// member (a CXXConstructorDecl pointer), or stores the anonymous union of 908 /// which the initialized value is a member. 909 /// 910 /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's 911 /// anonymous union data member, this field holds the FieldDecl for the 912 /// member of the anonymous union being initialized. 913 /// @code 914 /// struct X { 915 /// X() : au_i1(123) {} 916 /// union { 917 /// int au_i1; 918 /// float au_f1; 919 /// }; 920 /// }; 921 /// @endcode 922 /// In above example, BaseOrMember holds the field decl. for anonymous union 923 /// and AnonUnionMember holds field decl for au_i1. 924 llvm::PointerUnion<CXXConstructorDecl *, FieldDecl *> CtorOrAnonUnion; 925 926 /// LParenLoc - Location of the left paren of the ctor-initializer. 927 SourceLocation LParenLoc; 928 929 /// RParenLoc - Location of the right paren of the ctor-initializer. 930 SourceLocation RParenLoc; 931 932public: 933 /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 934 explicit 935 CXXBaseOrMemberInitializer(ASTContext &Context, 936 DeclaratorInfo *DInfo, CXXConstructorDecl *C, 937 SourceLocation L, 938 Expr **Args, unsigned NumArgs, 939 SourceLocation R); 940 941 /// CXXBaseOrMemberInitializer - Creates a new member initializer. 942 explicit 943 CXXBaseOrMemberInitializer(ASTContext &Context, 944 FieldDecl *Member, SourceLocation MemberLoc, 945 CXXConstructorDecl *C, SourceLocation L, 946 Expr **Args, unsigned NumArgs, 947 SourceLocation R); 948 949 /// \brief Destroy the base or member initializer. 950 void Destroy(ASTContext &Context); 951 952 /// arg_iterator - Iterates through the member initialization 953 /// arguments. 954 typedef ExprIterator arg_iterator; 955 956 /// arg_const_iterator - Iterates through the member initialization 957 /// arguments. 958 typedef ConstExprIterator const_arg_iterator; 959 960 /// isBaseInitializer - Returns true when this initializer is 961 /// initializing a base class. 962 bool isBaseInitializer() const { return BaseOrMember.is<DeclaratorInfo*>(); } 963 964 /// isMemberInitializer - Returns true when this initializer is 965 /// initializing a non-static data member. 966 bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); } 967 968 /// If this is a base class initializer, returns the type of the 969 /// base class with location information. Otherwise, returns an NULL 970 /// type location. 971 TypeLoc getBaseClassLoc() const; 972 973 /// If this is a base class initializer, returns the type of the base class. 974 /// Otherwise, returns NULL. 975 const Type *getBaseClass() const; 976 Type *getBaseClass(); 977 978 /// \brief Returns the declarator information for a base class initializer. 979 DeclaratorInfo *getBaseClassInfo() const { 980 return BaseOrMember.dyn_cast<DeclaratorInfo *>(); 981 } 982 983 /// getMember - If this is a member initializer, returns the 984 /// declaration of the non-static data member being 985 /// initialized. Otherwise, returns NULL. 986 FieldDecl *getMember() { 987 if (isMemberInitializer()) 988 return BaseOrMember.get<FieldDecl*>(); 989 else 990 return 0; 991 } 992 993 SourceLocation getMemberLocation() const { 994 return MemberLocation; 995 } 996 997 void setMember(FieldDecl *Member) { 998 assert(isMemberInitializer()); 999 BaseOrMember = Member; 1000 } 1001 1002 /// \brief Determine the source location of the initializer. 1003 SourceLocation getSourceLocation() const; 1004 1005 /// \brief Determine the source range covering the entire initializer. 1006 SourceRange getSourceRange() const; 1007 1008 FieldDecl *getAnonUnionMember() const { 1009 return CtorOrAnonUnion.dyn_cast<FieldDecl *>(); 1010 } 1011 void setAnonUnionMember(FieldDecl *anonMember) { 1012 CtorOrAnonUnion = anonMember; 1013 } 1014 1015 const CXXConstructorDecl *getConstructor() const { 1016 return CtorOrAnonUnion.dyn_cast<CXXConstructorDecl *>(); 1017 } 1018 1019 SourceLocation getLParenLoc() const { return LParenLoc; } 1020 SourceLocation getRParenLoc() const { return RParenLoc; } 1021 1022 /// arg_begin() - Retrieve an iterator to the first initializer argument. 1023 arg_iterator arg_begin() { return Args; } 1024 /// arg_begin() - Retrieve an iterator to the first initializer argument. 1025 const_arg_iterator const_arg_begin() const { return Args; } 1026 1027 /// arg_end() - Retrieve an iterator past the last initializer argument. 1028 arg_iterator arg_end() { return Args + NumArgs; } 1029 /// arg_end() - Retrieve an iterator past the last initializer argument. 1030 const_arg_iterator const_arg_end() const { return Args + NumArgs; } 1031 1032 /// getNumArgs - Determine the number of arguments used to 1033 /// initialize the member or base. 1034 unsigned getNumArgs() const { return NumArgs; } 1035}; 1036 1037/// CXXConstructorDecl - Represents a C++ constructor within a 1038/// class. For example: 1039/// 1040/// @code 1041/// class X { 1042/// public: 1043/// explicit X(int); // represented by a CXXConstructorDecl. 1044/// }; 1045/// @endcode 1046class CXXConstructorDecl : public CXXMethodDecl { 1047 /// Explicit - Whether this constructor is explicit. 1048 bool Explicit : 1; 1049 1050 /// ImplicitlyDefined - Whether this constructor was implicitly 1051 /// defined by the compiler. When false, the constructor was defined 1052 /// by the user. In C++03, this flag will have the same value as 1053 /// Implicit. In C++0x, however, a constructor that is 1054 /// explicitly defaulted (i.e., defined with " = default") will have 1055 /// @c !Implicit && ImplicitlyDefined. 1056 bool ImplicitlyDefined : 1; 1057 1058 /// Support for base and member initializers. 1059 /// BaseOrMemberInitializers - The arguments used to initialize the base 1060 /// or member. 1061 CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 1062 unsigned NumBaseOrMemberInitializers; 1063 1064 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 1065 DeclarationName N, QualType T, DeclaratorInfo *DInfo, 1066 bool isExplicit, bool isInline, bool isImplicitlyDeclared) 1067 : CXXMethodDecl(CXXConstructor, RD, L, N, T, DInfo, false, isInline), 1068 Explicit(isExplicit), ImplicitlyDefined(false), 1069 BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 1070 setImplicit(isImplicitlyDeclared); 1071 } 1072 virtual void Destroy(ASTContext& C); 1073 1074public: 1075 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1076 SourceLocation L, DeclarationName N, 1077 QualType T, DeclaratorInfo *DInfo, 1078 bool isExplicit, 1079 bool isInline, bool isImplicitlyDeclared); 1080 1081 /// isExplicit - Whether this constructor was marked "explicit" or not. 1082 bool isExplicit() const { return Explicit; } 1083 1084 /// isImplicitlyDefined - Whether this constructor was implicitly 1085 /// defined. If false, then this constructor was defined by the 1086 /// user. This operation can only be invoked if the constructor has 1087 /// already been defined. 1088 bool isImplicitlyDefined(ASTContext &C) const { 1089 assert(isThisDeclarationADefinition() && 1090 "Can only get the implicit-definition flag once the " 1091 "constructor has been defined"); 1092 return ImplicitlyDefined; 1093 } 1094 1095 /// setImplicitlyDefined - Set whether this constructor was 1096 /// implicitly defined or not. 1097 void setImplicitlyDefined(bool ID) { 1098 assert(isThisDeclarationADefinition() && 1099 "Can only set the implicit-definition flag once the constructor " 1100 "has been defined"); 1101 ImplicitlyDefined = ID; 1102 } 1103 1104 /// init_iterator - Iterates through the member/base initializer list. 1105 typedef CXXBaseOrMemberInitializer **init_iterator; 1106 1107 /// init_const_iterator - Iterates through the memberbase initializer list. 1108 typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 1109 1110 /// init_begin() - Retrieve an iterator to the first initializer. 1111 init_iterator init_begin() { return BaseOrMemberInitializers; } 1112 /// begin() - Retrieve an iterator to the first initializer. 1113 init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 1114 1115 /// init_end() - Retrieve an iterator past the last initializer. 1116 init_iterator init_end() { 1117 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1118 } 1119 /// end() - Retrieve an iterator past the last initializer. 1120 init_const_iterator init_end() const { 1121 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 1122 } 1123 1124 /// getNumArgs - Determine the number of arguments used to 1125 /// initialize the member or base. 1126 unsigned getNumBaseOrMemberInitializers() const { 1127 return NumBaseOrMemberInitializers; 1128 } 1129 1130 void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) { 1131 NumBaseOrMemberInitializers = numBaseOrMemberInitializers; 1132 } 1133 1134 void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) { 1135 BaseOrMemberInitializers = initializers; 1136 } 1137 /// isDefaultConstructor - Whether this constructor is a default 1138 /// constructor (C++ [class.ctor]p5), which can be used to 1139 /// default-initialize a class of this type. 1140 bool isDefaultConstructor() const; 1141 1142 /// isCopyConstructor - Whether this constructor is a copy 1143 /// constructor (C++ [class.copy]p2, which can be used to copy the 1144 /// class. @p TypeQuals will be set to the qualifiers on the 1145 /// argument type. For example, @p TypeQuals would be set to @c 1146 /// QualType::Const for the following copy constructor: 1147 /// 1148 /// @code 1149 /// class X { 1150 /// public: 1151 /// X(const X&); 1152 /// }; 1153 /// @endcode 1154 bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 1155 1156 /// isCopyConstructor - Whether this constructor is a copy 1157 /// constructor (C++ [class.copy]p2, which can be used to copy the 1158 /// class. 1159 bool isCopyConstructor(ASTContext &Context) const { 1160 unsigned TypeQuals = 0; 1161 return isCopyConstructor(Context, TypeQuals); 1162 } 1163 1164 /// isConvertingConstructor - Whether this constructor is a 1165 /// converting constructor (C++ [class.conv.ctor]), which can be 1166 /// used for user-defined conversions. 1167 bool isConvertingConstructor(bool AllowExplicit) const; 1168 1169 /// \brief Determine whether this is a member template specialization that 1170 /// looks like a copy constructor. Such constructors are never used to copy 1171 /// an object. 1172 bool isCopyConstructorLikeSpecialization() const; 1173 1174 // Implement isa/cast/dyncast/etc. 1175 static bool classof(const Decl *D) { 1176 return D->getKind() == CXXConstructor; 1177 } 1178 static bool classof(const CXXConstructorDecl *D) { return true; } 1179}; 1180 1181/// CXXDestructorDecl - Represents a C++ destructor within a 1182/// class. For example: 1183/// 1184/// @code 1185/// class X { 1186/// public: 1187/// ~X(); // represented by a CXXDestructorDecl. 1188/// }; 1189/// @endcode 1190class CXXDestructorDecl : public CXXMethodDecl { 1191 /// ImplicitlyDefined - Whether this destructor was implicitly 1192 /// defined by the compiler. When false, the destructor was defined 1193 /// by the user. In C++03, this flag will have the same value as 1194 /// Implicit. In C++0x, however, a destructor that is 1195 /// explicitly defaulted (i.e., defined with " = default") will have 1196 /// @c !Implicit && ImplicitlyDefined. 1197 bool ImplicitlyDefined : 1; 1198 1199 FunctionDecl *OperatorDelete; 1200 1201 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 1202 DeclarationName N, QualType T, 1203 bool isInline, bool isImplicitlyDeclared) 1204 : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*DInfo=*/0, false, isInline), 1205 ImplicitlyDefined(false), OperatorDelete(0) { 1206 setImplicit(isImplicitlyDeclared); 1207 } 1208 1209public: 1210 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1211 SourceLocation L, DeclarationName N, 1212 QualType T, bool isInline, 1213 bool isImplicitlyDeclared); 1214 1215 /// isImplicitlyDefined - Whether this destructor was implicitly 1216 /// defined. If false, then this destructor was defined by the 1217 /// user. This operation can only be invoked if the destructor has 1218 /// already been defined. 1219 bool isImplicitlyDefined() const { 1220 assert(isThisDeclarationADefinition() && 1221 "Can only get the implicit-definition flag once the destructor has been defined"); 1222 return ImplicitlyDefined; 1223 } 1224 1225 /// setImplicitlyDefined - Set whether this destructor was 1226 /// implicitly defined or not. 1227 void setImplicitlyDefined(bool ID) { 1228 assert(isThisDeclarationADefinition() && 1229 "Can only set the implicit-definition flag once the destructor has been defined"); 1230 ImplicitlyDefined = ID; 1231 } 1232 1233 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 1234 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1235 1236 // Implement isa/cast/dyncast/etc. 1237 static bool classof(const Decl *D) { 1238 return D->getKind() == CXXDestructor; 1239 } 1240 static bool classof(const CXXDestructorDecl *D) { return true; } 1241}; 1242 1243/// CXXConversionDecl - Represents a C++ conversion function within a 1244/// class. For example: 1245/// 1246/// @code 1247/// class X { 1248/// public: 1249/// operator bool(); 1250/// }; 1251/// @endcode 1252class CXXConversionDecl : public CXXMethodDecl { 1253 /// Explicit - Whether this conversion function is marked 1254 /// "explicit", meaning that it can only be applied when the user 1255 /// explicitly wrote a cast. This is a C++0x feature. 1256 bool Explicit : 1; 1257 1258 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1259 DeclarationName N, QualType T, DeclaratorInfo *DInfo, 1260 bool isInline, bool isExplicit) 1261 : CXXMethodDecl(CXXConversion, RD, L, N, T, DInfo, false, isInline), 1262 Explicit(isExplicit) { } 1263 1264public: 1265 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1266 SourceLocation L, DeclarationName N, 1267 QualType T, DeclaratorInfo *DInfo, 1268 bool isInline, bool isExplicit); 1269 1270 /// isExplicit - Whether this is an explicit conversion operator 1271 /// (C++0x only). Explicit conversion operators are only considered 1272 /// when the user has explicitly written a cast. 1273 bool isExplicit() const { return Explicit; } 1274 1275 /// getConversionType - Returns the type that this conversion 1276 /// function is converting to. 1277 QualType getConversionType() const { 1278 return getType()->getAs<FunctionType>()->getResultType(); 1279 } 1280 1281 // Implement isa/cast/dyncast/etc. 1282 static bool classof(const Decl *D) { 1283 return D->getKind() == CXXConversion; 1284 } 1285 static bool classof(const CXXConversionDecl *D) { return true; } 1286}; 1287 1288/// FriendDecl - Represents the declaration of a friend entity, 1289/// which can be a function, a type, or a templated function or type. 1290// For example: 1291/// 1292/// @code 1293/// template <typename T> class A { 1294/// friend int foo(T); 1295/// friend class B; 1296/// friend T; // only in C++0x 1297/// template <typename U> friend class C; 1298/// template <typename U> friend A& operator+=(A&, const U&) { ... } 1299/// }; 1300/// @endcode 1301/// 1302/// The semantic context of a friend decl is its declaring class. 1303class FriendDecl : public Decl { 1304public: 1305 typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 1306 1307private: 1308 // The declaration that's a friend of this class. 1309 FriendUnion Friend; 1310 1311 // Location of the 'friend' specifier. 1312 SourceLocation FriendLoc; 1313 1314 FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend, 1315 SourceLocation FriendL) 1316 : Decl(Decl::Friend, DC, L), 1317 Friend(Friend), 1318 FriendLoc(FriendL) { 1319 } 1320 1321public: 1322 static FriendDecl *Create(ASTContext &C, DeclContext *DC, 1323 SourceLocation L, FriendUnion Friend_, 1324 SourceLocation FriendL); 1325 1326 /// If this friend declaration names an (untemplated but 1327 /// possibly dependent) type, return the type; otherwise 1328 /// return null. This is used only for C++0x's unelaborated 1329 /// friend type declarations. 1330 Type *getFriendType() const { 1331 return Friend.dyn_cast<Type*>(); 1332 } 1333 1334 /// If this friend declaration doesn't name an unelaborated 1335 /// type, return the inner declaration. 1336 NamedDecl *getFriendDecl() const { 1337 return Friend.dyn_cast<NamedDecl*>(); 1338 } 1339 1340 /// Retrieves the location of the 'friend' keyword. 1341 SourceLocation getFriendLoc() const { 1342 return FriendLoc; 1343 } 1344 1345 // Implement isa/cast/dyncast/etc. 1346 static bool classof(const Decl *D) { 1347 return D->getKind() == Decl::Friend; 1348 } 1349 static bool classof(const FriendDecl *D) { return true; } 1350}; 1351 1352/// LinkageSpecDecl - This represents a linkage specification. For example: 1353/// extern "C" void foo(); 1354/// 1355class LinkageSpecDecl : public Decl, public DeclContext { 1356public: 1357 /// LanguageIDs - Used to represent the language in a linkage 1358 /// specification. The values are part of the serialization abi for 1359 /// ASTs and cannot be changed without altering that abi. To help 1360 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1361 /// from the dwarf standard. 1362 enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 1363 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 1364private: 1365 /// Language - The language for this linkage specification. 1366 LanguageIDs Language; 1367 1368 /// HadBraces - Whether this linkage specification had curly braces or not. 1369 bool HadBraces : 1; 1370 1371 LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1372 bool Braces) 1373 : Decl(LinkageSpec, DC, L), 1374 DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1375 1376public: 1377 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1378 SourceLocation L, LanguageIDs Lang, 1379 bool Braces); 1380 1381 LanguageIDs getLanguage() const { return Language; } 1382 1383 /// hasBraces - Determines whether this linkage specification had 1384 /// braces in its syntactic form. 1385 bool hasBraces() const { return HadBraces; } 1386 1387 static bool classof(const Decl *D) { 1388 return D->getKind() == LinkageSpec; 1389 } 1390 static bool classof(const LinkageSpecDecl *D) { return true; } 1391 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1392 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1393 } 1394 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1395 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1396 } 1397}; 1398 1399/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1400/// 1401/// using namespace std; 1402/// 1403// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1404// artificial name, for all using-directives in order to store 1405// them in DeclContext effectively. 1406class UsingDirectiveDecl : public NamedDecl { 1407 1408 /// SourceLocation - Location of 'namespace' token. 1409 SourceLocation NamespaceLoc; 1410 1411 /// \brief The source range that covers the nested-name-specifier 1412 /// preceding the namespace name. 1413 SourceRange QualifierRange; 1414 1415 /// \brief The nested-name-specifier that precedes the namespace 1416 /// name, if any. 1417 NestedNameSpecifier *Qualifier; 1418 1419 /// IdentLoc - Location of nominated namespace-name identifier. 1420 // FIXME: We don't store location of scope specifier. 1421 SourceLocation IdentLoc; 1422 1423 /// NominatedNamespace - Namespace nominated by using-directive. 1424 NamedDecl *NominatedNamespace; 1425 1426 /// Enclosing context containing both using-directive and nominated 1427 /// namespace. 1428 DeclContext *CommonAncestor; 1429 1430 /// getUsingDirectiveName - Returns special DeclarationName used by 1431 /// using-directives. This is only used by DeclContext for storing 1432 /// UsingDirectiveDecls in its lookup structure. 1433 static DeclarationName getName() { 1434 return DeclarationName::getUsingDirectiveName(); 1435 } 1436 1437 UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1438 SourceLocation NamespcLoc, 1439 SourceRange QualifierRange, 1440 NestedNameSpecifier *Qualifier, 1441 SourceLocation IdentLoc, 1442 NamedDecl *Nominated, 1443 DeclContext *CommonAncestor) 1444 : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1445 NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1446 Qualifier(Qualifier), IdentLoc(IdentLoc), 1447 NominatedNamespace(Nominated), 1448 CommonAncestor(CommonAncestor) { 1449 } 1450 1451public: 1452 /// \brief Retrieve the source range of the nested-name-specifier 1453 /// that qualifiers the namespace name. 1454 SourceRange getQualifierRange() const { return QualifierRange; } 1455 1456 /// \brief Retrieve the nested-name-specifier that qualifies the 1457 /// name of the namespace. 1458 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1459 1460 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 1461 const NamedDecl *getNominatedNamespaceAsWritten() const { 1462 return NominatedNamespace; 1463 } 1464 1465 /// getNominatedNamespace - Returns namespace nominated by using-directive. 1466 NamespaceDecl *getNominatedNamespace(); 1467 1468 const NamespaceDecl *getNominatedNamespace() const { 1469 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1470 } 1471 1472 /// getCommonAncestor - returns common ancestor context of using-directive, 1473 /// and nominated by it namespace. 1474 DeclContext *getCommonAncestor() { return CommonAncestor; } 1475 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1476 1477 /// getNamespaceKeyLocation - Returns location of namespace keyword. 1478 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1479 1480 /// getIdentLocation - Returns location of identifier. 1481 SourceLocation getIdentLocation() const { return IdentLoc; } 1482 1483 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1484 SourceLocation L, 1485 SourceLocation NamespaceLoc, 1486 SourceRange QualifierRange, 1487 NestedNameSpecifier *Qualifier, 1488 SourceLocation IdentLoc, 1489 NamedDecl *Nominated, 1490 DeclContext *CommonAncestor); 1491 1492 static bool classof(const Decl *D) { 1493 return D->getKind() == Decl::UsingDirective; 1494 } 1495 static bool classof(const UsingDirectiveDecl *D) { return true; } 1496 1497 // Friend for getUsingDirectiveName. 1498 friend class DeclContext; 1499}; 1500 1501/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1502/// 1503/// @code 1504/// namespace Foo = Bar; 1505/// @endcode 1506class NamespaceAliasDecl : public NamedDecl { 1507 SourceLocation AliasLoc; 1508 1509 /// \brief The source range that covers the nested-name-specifier 1510 /// preceding the namespace name. 1511 SourceRange QualifierRange; 1512 1513 /// \brief The nested-name-specifier that precedes the namespace 1514 /// name, if any. 1515 NestedNameSpecifier *Qualifier; 1516 1517 /// IdentLoc - Location of namespace identifier. 1518 SourceLocation IdentLoc; 1519 1520 /// Namespace - The Decl that this alias points to. Can either be a 1521 /// NamespaceDecl or a NamespaceAliasDecl. 1522 NamedDecl *Namespace; 1523 1524 NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1525 SourceLocation AliasLoc, IdentifierInfo *Alias, 1526 SourceRange QualifierRange, 1527 NestedNameSpecifier *Qualifier, 1528 SourceLocation IdentLoc, NamedDecl *Namespace) 1529 : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1530 QualifierRange(QualifierRange), Qualifier(Qualifier), 1531 IdentLoc(IdentLoc), Namespace(Namespace) { } 1532 1533public: 1534 /// \brief Retrieve the source range of the nested-name-specifier 1535 /// that qualifiers the namespace name. 1536 SourceRange getQualifierRange() const { return QualifierRange; } 1537 1538 /// \brief Retrieve the nested-name-specifier that qualifies the 1539 /// name of the namespace. 1540 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1541 1542 NamespaceDecl *getNamespace() { 1543 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1544 return AD->getNamespace(); 1545 1546 return cast<NamespaceDecl>(Namespace); 1547 } 1548 1549 const NamespaceDecl *getNamespace() const { 1550 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1551 } 1552 1553 /// \brief Retrieve the namespace that this alias refers to, which 1554 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1555 NamedDecl *getAliasedNamespace() const { return Namespace; } 1556 1557 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1558 SourceLocation L, SourceLocation AliasLoc, 1559 IdentifierInfo *Alias, 1560 SourceRange QualifierRange, 1561 NestedNameSpecifier *Qualifier, 1562 SourceLocation IdentLoc, 1563 NamedDecl *Namespace); 1564 1565 static bool classof(const Decl *D) { 1566 return D->getKind() == Decl::NamespaceAlias; 1567 } 1568 static bool classof(const NamespaceAliasDecl *D) { return true; } 1569}; 1570 1571/// UsingShadowDecl - Represents a shadow declaration introduced into 1572/// a scope by a (resolved) using declaration. For example, 1573/// 1574/// namespace A { 1575/// void foo(); 1576/// } 1577/// namespace B { 1578/// using A::foo(); // <- a UsingDecl 1579/// // Also creates a UsingShadowDecl for A::foo in B 1580/// } 1581/// 1582class UsingShadowDecl : public NamedDecl { 1583 /// The referenced declaration. 1584 NamedDecl *Underlying; 1585 1586 /// The using declaration which introduced this decl. 1587 UsingDecl *Using; 1588 1589 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 1590 NamedDecl *Target) 1591 : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()), 1592 Underlying(Target), Using(Using) { 1593 IdentifierNamespace = Target->getIdentifierNamespace(); 1594 setImplicit(); 1595 } 1596 1597public: 1598 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 1599 SourceLocation Loc, UsingDecl *Using, 1600 NamedDecl *Target) { 1601 return new (C) UsingShadowDecl(DC, Loc, Using, Target); 1602 } 1603 1604 /// Gets the underlying declaration which has been brought into the 1605 /// local scope. 1606 NamedDecl *getTargetDecl() const { 1607 return Underlying; 1608 } 1609 1610 /// Gets the using declaration to which this declaration is tied. 1611 UsingDecl *getUsingDecl() const { 1612 return Using; 1613 } 1614 1615 static bool classof(const Decl *D) { 1616 return D->getKind() == Decl::UsingShadow; 1617 } 1618 static bool classof(const UsingShadowDecl *D) { return true; } 1619}; 1620 1621/// UsingDecl - Represents a C++ using-declaration. For example: 1622/// using someNameSpace::someIdentifier; 1623class UsingDecl : public NamedDecl { 1624 /// \brief The source range that covers the nested-name-specifier 1625 /// preceding the declaration name. 1626 SourceRange NestedNameRange; 1627 1628 /// \brief The source location of the "using" location itself. 1629 SourceLocation UsingLocation; 1630 1631 /// \brief Target nested name specifier. 1632 NestedNameSpecifier* TargetNestedName; 1633 1634 /// \brief The collection of shadow declarations associated with 1635 /// this using declaration. This set can change as a class is 1636 /// processed. 1637 llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows; 1638 1639 // \brief Has 'typename' keyword. 1640 bool IsTypeName; 1641 1642 UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1643 SourceLocation UL, NestedNameSpecifier* TargetNNS, 1644 DeclarationName Name, bool IsTypeNameArg) 1645 : NamedDecl(Decl::Using, DC, L, Name), 1646 NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS), 1647 IsTypeName(IsTypeNameArg) { 1648 } 1649 1650public: 1651 /// \brief Returns the source range that covers the nested-name-specifier 1652 /// preceding the namespace name. 1653 SourceRange getNestedNameRange() { return NestedNameRange; } 1654 1655 /// \brief Returns the source location of the "using" location itself. 1656 SourceLocation getUsingLocation() { return UsingLocation; } 1657 1658 /// \brief Get target nested name declaration. 1659 NestedNameSpecifier* getTargetNestedNameDecl() { 1660 return TargetNestedName; 1661 } 1662 1663 /// isTypeName - Return true if using decl has 'typename'. 1664 bool isTypeName() const { return IsTypeName; } 1665 1666 typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator; 1667 shadow_iterator shadow_begin() const { return Shadows.begin(); } 1668 shadow_iterator shadow_end() const { return Shadows.end(); } 1669 1670 void addShadowDecl(UsingShadowDecl *S) { 1671 assert(S->getUsingDecl() == this); 1672 if (!Shadows.insert(S)) { 1673 assert(false && "declaration already in set"); 1674 } 1675 } 1676 void removeShadowDecl(UsingShadowDecl *S) { 1677 assert(S->getUsingDecl() == this); 1678 if (!Shadows.erase(S)) { 1679 assert(false && "declaration not in set"); 1680 } 1681 } 1682 1683 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1684 SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL, 1685 NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg); 1686 1687 static bool classof(const Decl *D) { 1688 return D->getKind() == Decl::Using; 1689 } 1690 static bool classof(const UsingDecl *D) { return true; } 1691}; 1692 1693/// UnresolvedUsingValueDecl - Represents a dependent using 1694/// declaration which was not marked with 'typename'. Unlike 1695/// non-dependent using declarations, these *only* bring through 1696/// non-types; otherwise they would break two-phase lookup. 1697/// 1698/// template <class T> class A : public Base<T> { 1699/// using Base<T>::foo; 1700/// }; 1701class UnresolvedUsingValueDecl : public ValueDecl { 1702 /// \brief The source range that covers the nested-name-specifier 1703 /// preceding the declaration name. 1704 SourceRange TargetNestedNameRange; 1705 1706 /// \brief The source location of the 'using' keyword 1707 SourceLocation UsingLocation; 1708 1709 NestedNameSpecifier *TargetNestedNameSpecifier; 1710 1711 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 1712 SourceLocation UsingLoc, SourceRange TargetNNR, 1713 NestedNameSpecifier *TargetNNS, 1714 SourceLocation TargetNameLoc, 1715 DeclarationName TargetName) 1716 : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), 1717 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1718 TargetNestedNameSpecifier(TargetNNS) 1719 { } 1720 1721public: 1722 /// \brief Returns the source range that covers the nested-name-specifier 1723 /// preceding the namespace name. 1724 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1725 1726 /// \brief Get target nested name declaration. 1727 NestedNameSpecifier* getTargetNestedNameSpecifier() { 1728 return TargetNestedNameSpecifier; 1729 } 1730 1731 /// \brief Returns the source location of the 'using' keyword. 1732 SourceLocation getUsingLoc() const { return UsingLocation; } 1733 1734 static UnresolvedUsingValueDecl * 1735 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1736 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1737 SourceLocation TargetNameLoc, DeclarationName TargetName); 1738 1739 static bool classof(const Decl *D) { 1740 return D->getKind() == Decl::UnresolvedUsingValue; 1741 } 1742 static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 1743}; 1744 1745/// UnresolvedUsingTypenameDecl - Represents a dependent using 1746/// declaration which was marked with 'typename'. 1747/// 1748/// template <class T> class A : public Base<T> { 1749/// using typename Base<T>::foo; 1750/// }; 1751/// 1752/// The type associated with a unresolved using typename decl is 1753/// currently always a typename type. 1754class UnresolvedUsingTypenameDecl : public TypeDecl { 1755 /// \brief The source range that covers the nested-name-specifier 1756 /// preceding the declaration name. 1757 SourceRange TargetNestedNameRange; 1758 1759 /// \brief The source location of the 'using' keyword 1760 SourceLocation UsingLocation; 1761 1762 /// \brief The source location of the 'typename' keyword 1763 SourceLocation TypenameLocation; 1764 1765 NestedNameSpecifier *TargetNestedNameSpecifier; 1766 1767 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 1768 SourceLocation TypenameLoc, 1769 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1770 SourceLocation TargetNameLoc, IdentifierInfo *TargetName) 1771 : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), 1772 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), 1773 TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS) 1774 { } 1775 1776public: 1777 /// \brief Returns the source range that covers the nested-name-specifier 1778 /// preceding the namespace name. 1779 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; } 1780 1781 /// \brief Get target nested name declaration. 1782 NestedNameSpecifier* getTargetNestedNameSpecifier() { 1783 return TargetNestedNameSpecifier; 1784 } 1785 1786 /// \brief Returns the source location of the 'using' keyword. 1787 SourceLocation getUsingLoc() const { return UsingLocation; } 1788 1789 /// \brief Returns the source location of the 'typename' keyword. 1790 SourceLocation getTypenameLoc() const { return TypenameLocation; } 1791 1792 static UnresolvedUsingTypenameDecl * 1793 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 1794 SourceLocation TypenameLoc, 1795 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, 1796 SourceLocation TargetNameLoc, DeclarationName TargetName); 1797 1798 static bool classof(const Decl *D) { 1799 return D->getKind() == Decl::UnresolvedUsingTypename; 1800 } 1801 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 1802}; 1803 1804/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1805class StaticAssertDecl : public Decl { 1806 Expr *AssertExpr; 1807 StringLiteral *Message; 1808 1809 StaticAssertDecl(DeclContext *DC, SourceLocation L, 1810 Expr *assertexpr, StringLiteral *message) 1811 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1812 1813public: 1814 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1815 SourceLocation L, Expr *AssertExpr, 1816 StringLiteral *Message); 1817 1818 Expr *getAssertExpr() { return AssertExpr; } 1819 const Expr *getAssertExpr() const { return AssertExpr; } 1820 1821 StringLiteral *getMessage() { return Message; } 1822 const StringLiteral *getMessage() const { return Message; } 1823 1824 virtual ~StaticAssertDecl(); 1825 virtual void Destroy(ASTContext& C); 1826 1827 static bool classof(const Decl *D) { 1828 return D->getKind() == Decl::StaticAssert; 1829 } 1830 static bool classof(StaticAssertDecl *D) { return true; } 1831}; 1832 1833/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1834/// into a diagnostic with <<. 1835const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1836 AccessSpecifier AS); 1837 1838} // end namespace clang 1839 1840#endif 1841