DeclCXX.h revision 393612e6c7727f1fee50039254d9f434364cc0b2
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/Decl.h" 18#include "llvm/ADT/SmallVector.h" 19 20namespace clang { 21 22class ClassTemplateDecl; 23class CXXRecordDecl; 24class CXXConstructorDecl; 25class CXXDestructorDecl; 26class CXXConversionDecl; 27class CXXMethodDecl; 28class ClassTemplateSpecializationDecl; 29 30/// \brief Represents any kind of function declaration, whether it is a 31/// concrete function or a function template. 32class AnyFunctionDecl { 33 NamedDecl *Function; 34 35 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 36 37public: 38 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 39 AnyFunctionDecl(FunctionTemplateDecl *FTD); 40 41 /// \brief Implicily converts any function or function template into a 42 /// named declaration. 43 operator NamedDecl *() const { return Function; } 44 45 /// \brief Retrieve the underlying function or function template. 46 NamedDecl *get() const { return Function; } 47 48 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 49 return AnyFunctionDecl(ND); 50 } 51}; 52 53} // end namespace clang 54 55namespace llvm { 56 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 57 /// AnyFunctionDecl to any function or function template declaration. 58 template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 59 typedef ::clang::NamedDecl* SimpleType; 60 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 61 return Val; 62 } 63 }; 64 template<> struct simplify_type< ::clang::AnyFunctionDecl> 65 : public simplify_type<const ::clang::AnyFunctionDecl> {}; 66 67 // Provide PointerLikeTypeTraits for non-cvr pointers. 68 template<> 69 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 70 public: 71 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 72 return F.get(); 73 } 74 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 75 return ::clang::AnyFunctionDecl::getFromNamedDecl( 76 static_cast< ::clang::NamedDecl*>(P)); 77 } 78 79 enum { NumLowBitsAvailable = 2 }; 80 }; 81 82} // end namespace llvm 83 84namespace clang { 85 86/// OverloadedFunctionDecl - An instance of this class represents a 87/// set of overloaded functions. All of the functions have the same 88/// name and occur within the same scope. 89/// 90/// An OverloadedFunctionDecl has no ownership over the FunctionDecl 91/// nodes it contains. Rather, the FunctionDecls are owned by the 92/// enclosing scope (which also owns the OverloadedFunctionDecl 93/// node). OverloadedFunctionDecl is used primarily to store a set of 94/// overloaded functions for name lookup. 95class OverloadedFunctionDecl : public NamedDecl { 96protected: 97 OverloadedFunctionDecl(DeclContext *DC, DeclarationName N) 98 : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { } 99 100 /// Functions - the set of overloaded functions contained in this 101 /// overload set. 102 llvm::SmallVector<AnyFunctionDecl, 4> Functions; 103 104 // FIXME: This should go away when we stop using 105 // OverloadedFunctionDecl to store conversions in CXXRecordDecl. 106 friend class CXXRecordDecl; 107 108public: 109 typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator; 110 typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator 111 function_const_iterator; 112 113 static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC, 114 DeclarationName N); 115 116 /// \brief Add a new overloaded function or function template to the set 117 /// of overloaded function templates. 118 void addOverload(AnyFunctionDecl F); 119 120 function_iterator function_begin() { return Functions.begin(); } 121 function_iterator function_end() { return Functions.end(); } 122 function_const_iterator function_begin() const { return Functions.begin(); } 123 function_const_iterator function_end() const { return Functions.end(); } 124 125 /// \brief Returns the number of overloaded functions stored in 126 /// this set. 127 unsigned size() const { return Functions.size(); } 128 129 // Implement isa/cast/dyncast/etc. 130 static bool classof(const Decl *D) { 131 return D->getKind() == OverloadedFunction; 132 } 133 static bool classof(const OverloadedFunctionDecl *D) { return true; } 134}; 135 136/// \brief Provides uniform iteration syntax for an overload set, function, 137/// or function template. 138class OverloadIterator { 139 /// \brief An overloaded function set, function declaration, or 140 /// function template declaration. 141 NamedDecl *D; 142 143 /// \brief If the declaration is an overloaded function set, this is the 144 /// iterator pointing to the current position within that overloaded 145 /// function set. 146 OverloadedFunctionDecl::function_iterator Iter; 147 148public: 149 typedef AnyFunctionDecl value_type; 150 typedef value_type reference; 151 typedef NamedDecl *pointer; 152 typedef int difference_type; 153 typedef std::forward_iterator_tag iterator_category; 154 155 OverloadIterator() : D(0) { } 156 157 OverloadIterator(FunctionDecl *FD) : D(FD) { } 158 OverloadIterator(FunctionTemplateDecl *FTD) 159 : D(reinterpret_cast<NamedDecl*>(FTD)) { } 160 OverloadIterator(OverloadedFunctionDecl *Ovl) 161 : D(Ovl), Iter(Ovl->function_begin()) { } 162 163 reference operator*() const; 164 165 pointer operator->() const { return (**this).get(); } 166 167 OverloadIterator &operator++(); 168 169 OverloadIterator operator++(int) { 170 OverloadIterator Temp(*this); 171 ++(*this); 172 return Temp; 173 } 174 175 bool Equals(const OverloadIterator &Other) const; 176}; 177 178inline bool operator==(const OverloadIterator &X, const OverloadIterator &Y) { 179 return X.Equals(Y); 180} 181 182inline bool operator!=(const OverloadIterator &X, const OverloadIterator &Y) { 183 return !(X == Y); 184} 185 186/// CXXBaseSpecifier - A base class of a C++ class. 187/// 188/// Each CXXBaseSpecifier represents a single, direct base class (or 189/// struct) of a C++ class (or struct). It specifies the type of that 190/// base class, whether it is a virtual or non-virtual base, and what 191/// level of access (public, protected, private) is used for the 192/// derivation. For example: 193/// 194/// @code 195/// class A { }; 196/// class B { }; 197/// class C : public virtual A, protected B { }; 198/// @endcode 199/// 200/// In this code, C will have two CXXBaseSpecifiers, one for "public 201/// virtual A" and the other for "protected B". 202class CXXBaseSpecifier { 203 /// Range - The source code range that covers the full base 204 /// specifier, including the "virtual" (if present) and access 205 /// specifier (if present). 206 SourceRange Range; 207 208 /// Virtual - Whether this is a virtual base class or not. 209 bool Virtual : 1; 210 211 /// BaseOfClass - Whether this is the base of a class (true) or of a 212 /// struct (false). This determines the mapping from the access 213 /// specifier as written in the source code to the access specifier 214 /// used for semantic analysis. 215 bool BaseOfClass : 1; 216 217 /// Access - Access specifier as written in the source code (which 218 /// may be AS_none). The actual type of data stored here is an 219 /// AccessSpecifier, but we use "unsigned" here to work around a 220 /// VC++ bug. 221 unsigned Access : 2; 222 223 /// BaseType - The type of the base class. This will be a class or 224 /// struct (or a typedef of such). 225 QualType BaseType; 226 227public: 228 CXXBaseSpecifier() { } 229 230 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T) 231 : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { } 232 233 /// getSourceRange - Retrieves the source range that contains the 234 /// entire base specifier. 235 SourceRange getSourceRange() const { return Range; } 236 237 /// isVirtual - Determines whether the base class is a virtual base 238 /// class (or not). 239 bool isVirtual() const { return Virtual; } 240 241 /// getAccessSpecifier - Returns the access specifier for this base 242 /// specifier. This is the actual base specifier as used for 243 /// semantic analysis, so the result can never be AS_none. To 244 /// retrieve the access specifier as written in the source code, use 245 /// getAccessSpecifierAsWritten(). 246 AccessSpecifier getAccessSpecifier() const { 247 if ((AccessSpecifier)Access == AS_none) 248 return BaseOfClass? AS_private : AS_public; 249 else 250 return (AccessSpecifier)Access; 251 } 252 253 /// getAccessSpecifierAsWritten - Retrieves the access specifier as 254 /// written in the source code (which may mean that no access 255 /// specifier was explicitly written). Use getAccessSpecifier() to 256 /// retrieve the access specifier for use in semantic analysis. 257 AccessSpecifier getAccessSpecifierAsWritten() const { 258 return (AccessSpecifier)Access; 259 } 260 261 /// getType - Retrieves the type of the base class. This type will 262 /// always be an unqualified class type. 263 QualType getType() const { return BaseType; } 264}; 265 266/// CXXRecordDecl - Represents a C++ struct/union/class. 267/// FIXME: This class will disappear once we've properly taught RecordDecl 268/// to deal with C++-specific things. 269class CXXRecordDecl : public RecordDecl { 270 /// UserDeclaredConstructor - True when this class has a 271 /// user-declared constructor. 272 bool UserDeclaredConstructor : 1; 273 274 /// UserDeclaredCopyConstructor - True when this class has a 275 /// user-declared copy constructor. 276 bool UserDeclaredCopyConstructor : 1; 277 278 /// UserDeclaredCopyAssignment - True when this class has a 279 /// user-declared copy assignment operator. 280 bool UserDeclaredCopyAssignment : 1; 281 282 /// UserDeclaredDestructor - True when this class has a 283 /// user-declared destructor. 284 bool UserDeclaredDestructor : 1; 285 286 /// Aggregate - True when this class is an aggregate. 287 bool Aggregate : 1; 288 289 /// PlainOldData - True when this class is a POD-type. 290 bool PlainOldData : 1; 291 292 /// Polymorphic - True when this class is polymorphic, i.e. has at least one 293 /// virtual member or derives from a polymorphic class. 294 bool Polymorphic : 1; 295 296 /// Abstract - True when this class is abstract, i.e. has at least one 297 /// pure virtual function, (that can come from a base class). 298 bool Abstract : 1; 299 300 /// HasTrivialConstructor - True when this class has a trivial constructor 301 bool HasTrivialConstructor : 1; 302 303 /// HasTrivialDestructor - True when this class has a trivial destructor 304 bool HasTrivialDestructor : 1; 305 306 /// Bases - Base classes of this class. 307 /// FIXME: This is wasted space for a union. 308 CXXBaseSpecifier *Bases; 309 310 /// NumBases - The number of base class specifiers in Bases. 311 unsigned NumBases; 312 313 /// VBases - direct and indirect virtual base classes of this class. 314 CXXBaseSpecifier *VBases; 315 316 /// NumVBases - The number of virtual base class specifiers in VBases. 317 unsigned NumVBases; 318 319 /// Conversions - Overload set containing the conversion functions 320 /// of this C++ class (but not its inherited conversion 321 /// functions). Each of the entries in this overload set is a 322 /// CXXConversionDecl. 323 OverloadedFunctionDecl Conversions; 324 325 /// \brief The template or declaration that this declaration 326 /// describes or was instantiated from, respectively. 327 /// 328 /// For non-templates, this value will be NULL. For record 329 /// declarations that describe a class template, this will be a 330 /// pointer to a ClassTemplateDecl. For member 331 /// classes of class template specializations, this will be the 332 /// RecordDecl from which the member class was instantiated. 333 llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*> 334 TemplateOrInstantiation; 335 336protected: 337 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 338 SourceLocation L, IdentifierInfo *Id, 339 SourceLocation TKL = SourceLocation()); 340 341 ~CXXRecordDecl(); 342 343public: 344 /// base_class_iterator - Iterator that traverses the base classes 345 /// of a clas. 346 typedef CXXBaseSpecifier* base_class_iterator; 347 348 /// base_class_const_iterator - Iterator that traverses the base 349 /// classes of a clas. 350 typedef const CXXBaseSpecifier* base_class_const_iterator; 351 352 static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, 353 SourceLocation L, IdentifierInfo *Id, 354 SourceLocation TKL = SourceLocation(), 355 CXXRecordDecl* PrevDecl=0, 356 bool DelayTypeCreation = false); 357 358 virtual void Destroy(ASTContext& C); 359 360 /// setBases - Sets the base classes of this struct or class. 361 void setBases(ASTContext &C, 362 CXXBaseSpecifier const * const *Bases, unsigned NumBases); 363 364 /// getNumBases - Retrieves the number of base classes of this 365 /// class. 366 unsigned getNumBases() const { return NumBases; } 367 368 base_class_iterator bases_begin() { return Bases; } 369 base_class_const_iterator bases_begin() const { return Bases; } 370 base_class_iterator bases_end() { return Bases + NumBases; } 371 base_class_const_iterator bases_end() const { return Bases + NumBases; } 372 373 /// getNumVBases - Retrieves the number of virtual base classes of this 374 /// class. 375 unsigned getNumVBases() const { return NumVBases; } 376 377 base_class_iterator vbases_begin() { return VBases; } 378 base_class_const_iterator vbases_begin() const { return VBases; } 379 base_class_iterator vbases_end() { return VBases + NumVBases; } 380 base_class_const_iterator vbases_end() const { return VBases + NumVBases; } 381 382 /// hasConstCopyConstructor - Determines whether this class has a 383 /// copy constructor that accepts a const-qualified argument. 384 bool hasConstCopyConstructor(ASTContext &Context) const; 385 386 /// getCopyConstructor - Returns the copy constructor for this class 387 CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 388 unsigned TypeQuals) const; 389 390 /// hasConstCopyAssignment - Determines whether this class has a 391 /// copy assignment operator that accepts a const-qualified argument. 392 bool hasConstCopyAssignment(ASTContext &Context) const; 393 394 /// addedConstructor - Notify the class that another constructor has 395 /// been added. This routine helps maintain information about the 396 /// class based on which constructors have been added. 397 void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl); 398 399 /// hasUserDeclaredConstructor - Whether this class has any 400 /// user-declared constructors. When true, a default constructor 401 /// will not be implicitly declared. 402 bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; } 403 404 /// hasUserDeclaredCopyConstructor - Whether this class has a 405 /// user-declared copy constructor. When false, a copy constructor 406 /// will be implicitly declared. 407 bool hasUserDeclaredCopyConstructor() const { 408 return UserDeclaredCopyConstructor; 409 } 410 411 /// addedAssignmentOperator - Notify the class that another assignment 412 /// operator has been added. This routine helps maintain information about the 413 /// class based on which operators have been added. 414 void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl); 415 416 /// hasUserDeclaredCopyAssignment - Whether this class has a 417 /// user-declared copy assignment operator. When false, a copy 418 /// assigment operator will be implicitly declared. 419 bool hasUserDeclaredCopyAssignment() const { 420 return UserDeclaredCopyAssignment; 421 } 422 423 /// hasUserDeclaredDestructor - Whether this class has a 424 /// user-declared destructor. When false, a destructor will be 425 /// implicitly declared. 426 bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; } 427 428 /// setUserDeclaredDestructor - Set whether this class has a 429 /// user-declared destructor. If not set by the time the class is 430 /// fully defined, a destructor will be implicitly declared. 431 void setUserDeclaredDestructor(bool UCD) { 432 UserDeclaredDestructor = UCD; 433 } 434 435 /// getConversions - Retrieve the overload set containing all of the 436 /// conversion functions in this class. 437 OverloadedFunctionDecl *getConversionFunctions() { 438 return &Conversions; 439 } 440 const OverloadedFunctionDecl *getConversionFunctions() const { 441 return &Conversions; 442 } 443 444 /// addConversionFunction - Add a new conversion function to the 445 /// list of conversion functions. 446 void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl); 447 448 /// isAggregate - Whether this class is an aggregate (C++ 449 /// [dcl.init.aggr]), which is a class with no user-declared 450 /// constructors, no private or protected non-static data members, 451 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 452 bool isAggregate() const { return Aggregate; } 453 454 /// setAggregate - Set whether this class is an aggregate (C++ 455 /// [dcl.init.aggr]). 456 void setAggregate(bool Agg) { Aggregate = Agg; } 457 458 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 459 /// that is an aggregate that has no non-static non-POD data members, no 460 /// reference data members, no user-defined copy assignment operator and no 461 /// user-defined destructor. 462 bool isPOD() const { return PlainOldData; } 463 464 /// setPOD - Set whether this class is a POD-type (C++ [class]p4). 465 void setPOD(bool POD) { PlainOldData = POD; } 466 467 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 468 /// which means that the class contains or inherits a virtual function. 469 bool isPolymorphic() const { return Polymorphic; } 470 471 /// setPolymorphic - Set whether this class is polymorphic (C++ 472 /// [class.virtual]). 473 void setPolymorphic(bool Poly) { Polymorphic = Poly; } 474 475 /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 476 /// which means that the class contains or inherits a pure virtual function. 477 bool isAbstract() const { return Abstract; } 478 479 /// setAbstract - Set whether this class is abstract (C++ [class.abstract]) 480 void setAbstract(bool Abs) { Abstract = Abs; } 481 482 // hasTrivialConstructor - Whether this class has a trivial constructor 483 // (C++ [class.ctor]p5) 484 bool hasTrivialConstructor() const { return HasTrivialConstructor; } 485 486 // setHasTrivialConstructor - Set whether this class has a trivial constructor 487 // (C++ [class.ctor]p5) 488 void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; } 489 490 // hasTrivialDestructor - Whether this class has a trivial destructor 491 // (C++ [class.dtor]p3) 492 bool hasTrivialDestructor() const { return HasTrivialDestructor; } 493 494 // setHasTrivialDestructor - Set whether this class has a trivial destructor 495 // (C++ [class.dtor]p3) 496 void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; } 497 498 /// \brief If this record is an instantiation of a member class, 499 /// retrieves the member class from which it was instantiated. 500 /// 501 /// This routine will return non-NULL for (non-templated) member 502 /// classes of class templates. For example, given: 503 /// 504 /// \code 505 /// template<typename T> 506 /// struct X { 507 /// struct A { }; 508 /// }; 509 /// \endcode 510 /// 511 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 512 /// whose parent is the class template specialization X<int>. For 513 /// this declaration, getInstantiatedFromMemberClass() will return 514 /// the CXXRecordDecl X<T>::A. When a complete definition of 515 /// X<int>::A is required, it will be instantiated from the 516 /// declaration returned by getInstantiatedFromMemberClass(). 517 CXXRecordDecl *getInstantiatedFromMemberClass() const { 518 return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>(); 519 } 520 521 /// \brief Specify that this record is an instantiation of the 522 /// member class RD. 523 void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 524 TemplateOrInstantiation = RD; 525 } 526 527 /// \brief Retrieves the class template that is described by this 528 /// class declaration. 529 /// 530 /// Every class template is represented as a ClassTemplateDecl and a 531 /// CXXRecordDecl. The former contains template properties (such as 532 /// the template parameter lists) while the latter contains the 533 /// actual description of the template's 534 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 535 /// CXXRecordDecl that from a ClassTemplateDecl, while 536 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 537 /// a CXXRecordDecl. 538 ClassTemplateDecl *getDescribedClassTemplate() const { 539 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 540 } 541 542 void setDescribedClassTemplate(ClassTemplateDecl *Template) { 543 TemplateOrInstantiation = Template; 544 } 545 546 /// getDefaultConstructor - Returns the default constructor for this class 547 CXXConstructorDecl *getDefaultConstructor(ASTContext &Context); 548 549 /// getDestructor - Returns the destructor decl for this class. 550 const CXXDestructorDecl *getDestructor(ASTContext &Context); 551 552 /// isLocalClass - If the class is a local class [class.local], returns 553 /// the enclosing function declaration. 554 const FunctionDecl *isLocalClass() const { 555 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 556 return RD->isLocalClass(); 557 558 return dyn_cast<FunctionDecl>(getDeclContext()); 559 } 560 561 /// viewInheritance - Renders and displays an inheritance diagram 562 /// for this C++ class and all of its base classes (transitively) using 563 /// GraphViz. 564 void viewInheritance(ASTContext& Context) const; 565 566 static bool classof(const Decl *D) { 567 return D->getKind() == CXXRecord || 568 D->getKind() == ClassTemplateSpecialization || 569 D->getKind() == ClassTemplatePartialSpecialization; 570 } 571 static bool classof(const CXXRecordDecl *D) { return true; } 572 static bool classof(const ClassTemplateSpecializationDecl *D) { 573 return true; 574 } 575}; 576 577/// CXXMethodDecl - Represents a static or instance method of a 578/// struct/union/class. 579class CXXMethodDecl : public FunctionDecl { 580protected: 581 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L, 582 DeclarationName N, QualType T, 583 bool isStatic, bool isInline) 584 : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None), 585 isInline) {} 586 587public: 588 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 589 SourceLocation L, DeclarationName N, 590 QualType T, bool isStatic = false, 591 bool isInline = false); 592 593 bool isStatic() const { return getStorageClass() == Static; } 594 bool isInstance() const { return !isStatic(); } 595 596 bool isVirtual() const { 597 return isVirtualAsWritten() || 598 (begin_overridden_methods() != end_overridden_methods()); 599 } 600 601 /// 602 void addOverriddenMethod(const CXXMethodDecl *MD); 603 604 typedef const CXXMethodDecl ** method_iterator; 605 606 method_iterator begin_overridden_methods() const; 607 method_iterator end_overridden_methods() const; 608 609 /// getParent - Returns the parent of this method declaration, which 610 /// is the class in which this method is defined. 611 const CXXRecordDecl *getParent() const { 612 return cast<CXXRecordDecl>(FunctionDecl::getParent()); 613 } 614 615 /// getParent - Returns the parent of this method declaration, which 616 /// is the class in which this method is defined. 617 CXXRecordDecl *getParent() { 618 return const_cast<CXXRecordDecl *>( 619 cast<CXXRecordDecl>(FunctionDecl::getParent())); 620 } 621 622 /// getThisType - Returns the type of 'this' pointer. 623 /// Should only be called for instance methods. 624 QualType getThisType(ASTContext &C) const; 625 626 unsigned getTypeQualifiers() const { 627 return getType()->getAsFunctionProtoType()->getTypeQuals(); 628 } 629 630 // Implement isa/cast/dyncast/etc. 631 static bool classof(const Decl *D) { 632 return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion; 633 } 634 static bool classof(const CXXMethodDecl *D) { return true; } 635}; 636 637/// CXXBaseOrMemberInitializer - Represents a C++ base or member 638/// initializer, which is part of a constructor initializer that 639/// initializes one non-static member variable or one base class. For 640/// example, in the following, both 'A(a)' and 'f(3.14159)' are member 641/// initializers: 642/// 643/// @code 644/// class A { }; 645/// class B : public A { 646/// float f; 647/// public: 648/// B(A& a) : A(a), f(3.14159) { } 649/// }; 650/// @endcode 651class CXXBaseOrMemberInitializer { 652 /// BaseOrMember - This points to the entity being initialized, 653 /// which is either a base class (a Type) or a non-static data 654 /// member. When the low bit is 1, it's a base 655 /// class; when the low bit is 0, it's a member. 656 uintptr_t BaseOrMember; 657 658 /// Args - The arguments used to initialize the base or member. 659 Expr **Args; 660 unsigned NumArgs; 661 662 /// IdLoc - Location of the id in ctor-initializer list. 663 SourceLocation IdLoc; 664 665public: 666 /// CXXBaseOrMemberInitializer - Creates a new base-class initializer. 667 explicit 668 CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, 669 SourceLocation L); 670 671 /// CXXBaseOrMemberInitializer - Creates a new member initializer. 672 explicit 673 CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, 674 SourceLocation L); 675 676 /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer. 677 ~CXXBaseOrMemberInitializer(); 678 679 /// arg_iterator - Iterates through the member initialization 680 /// arguments. 681 typedef Expr **arg_iterator; 682 683 /// arg_const_iterator - Iterates through the member initialization 684 /// arguments. 685 typedef Expr * const * arg_const_iterator; 686 687 /// getBaseOrMember - get the generic 'member' representing either the field 688 /// or a base class. 689 void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); } 690 691 /// isBaseInitializer - Returns true when this initializer is 692 /// initializing a base class. 693 bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; } 694 695 /// isMemberInitializer - Returns true when this initializer is 696 /// initializing a non-static data member. 697 bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; } 698 699 /// getBaseClass - If this is a base class initializer, returns the 700 /// type used to specify the initializer. The resulting type will be 701 /// a class type or a typedef of a class type. If this is not a base 702 /// class initializer, returns NULL. 703 Type *getBaseClass() { 704 if (isBaseInitializer()) 705 return reinterpret_cast<Type*>(BaseOrMember & ~0x01); 706 else 707 return 0; 708 } 709 710 /// getBaseClass - If this is a base class initializer, returns the 711 /// type used to specify the initializer. The resulting type will be 712 /// a class type or a typedef of a class type. If this is not a base 713 /// class initializer, returns NULL. 714 const Type *getBaseClass() const { 715 if (isBaseInitializer()) 716 return reinterpret_cast<const Type*>(BaseOrMember & ~0x01); 717 else 718 return 0; 719 } 720 721 /// getMember - If this is a member initializer, returns the 722 /// declaration of the non-static data member being 723 /// initialized. Otherwise, returns NULL. 724 FieldDecl *getMember() { 725 if (isMemberInitializer()) 726 return reinterpret_cast<FieldDecl *>(BaseOrMember); 727 else 728 return 0; 729 } 730 731 SourceLocation getSourceLocation() const { return IdLoc; } 732 733 /// begin() - Retrieve an iterator to the first initializer argument. 734 arg_iterator begin() { return Args; } 735 /// begin() - Retrieve an iterator to the first initializer argument. 736 arg_const_iterator begin() const { return Args; } 737 738 /// end() - Retrieve an iterator past the last initializer argument. 739 arg_iterator end() { return Args + NumArgs; } 740 /// end() - Retrieve an iterator past the last initializer argument. 741 arg_const_iterator end() const { return Args + NumArgs; } 742 743 /// getNumArgs - Determine the number of arguments used to 744 /// initialize the member or base. 745 unsigned getNumArgs() const { return NumArgs; } 746}; 747 748/// CXXConstructorDecl - Represents a C++ constructor within a 749/// class. For example: 750/// 751/// @code 752/// class X { 753/// public: 754/// explicit X(int); // represented by a CXXConstructorDecl. 755/// }; 756/// @endcode 757class CXXConstructorDecl : public CXXMethodDecl { 758 /// Explicit - Whether this constructor is explicit. 759 bool Explicit : 1; 760 761 /// ImplicitlyDefined - Whether this constructor was implicitly 762 /// defined by the compiler. When false, the constructor was defined 763 /// by the user. In C++03, this flag will have the same value as 764 /// Implicit. In C++0x, however, a constructor that is 765 /// explicitly defaulted (i.e., defined with " = default") will have 766 /// @c !Implicit && ImplicitlyDefined. 767 bool ImplicitlyDefined : 1; 768 769 /// Support for base and member initializers. 770 /// BaseOrMemberInitializers - The arguments used to initialize the base 771 /// or member. 772 CXXBaseOrMemberInitializer **BaseOrMemberInitializers; 773 unsigned NumBaseOrMemberInitializers; 774 775 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, 776 DeclarationName N, QualType T, 777 bool isExplicit, bool isInline, bool isImplicitlyDeclared) 778 : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline), 779 Explicit(isExplicit), ImplicitlyDefined(false), 780 BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 781 setImplicit(isImplicitlyDeclared); 782 } 783 virtual void Destroy(ASTContext& C); 784 785public: 786 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 787 SourceLocation L, DeclarationName N, 788 QualType T, bool isExplicit, 789 bool isInline, bool isImplicitlyDeclared); 790 791 /// isExplicit - Whether this constructor was marked "explicit" or not. 792 bool isExplicit() const { return Explicit; } 793 794 /// isImplicitlyDefined - Whether this constructor was implicitly 795 /// defined. If false, then this constructor was defined by the 796 /// user. This operation can only be invoked if the constructor has 797 /// already been defined. 798 bool isImplicitlyDefined(ASTContext &C) const { 799 assert(isThisDeclarationADefinition() && 800 "Can only get the implicit-definition flag once the " 801 "constructor has been defined"); 802 return ImplicitlyDefined; 803 } 804 805 /// setImplicitlyDefined - Set whether this constructor was 806 /// implicitly defined or not. 807 void setImplicitlyDefined(bool ID) { 808 assert(isThisDeclarationADefinition() && 809 "Can only set the implicit-definition flag once the constructor " 810 "has been defined"); 811 ImplicitlyDefined = ID; 812 } 813 814 /// init_iterator - Iterates through the member/base initializer list. 815 typedef CXXBaseOrMemberInitializer **init_iterator; 816 817 /// init_const_iterator - Iterates through the memberbase initializer list. 818 typedef CXXBaseOrMemberInitializer * const * init_const_iterator; 819 820 /// init_begin() - Retrieve an iterator to the first initializer. 821 init_iterator init_begin() { return BaseOrMemberInitializers; } 822 /// begin() - Retrieve an iterator to the first initializer. 823 init_const_iterator init_begin() const { return BaseOrMemberInitializers; } 824 825 /// init_end() - Retrieve an iterator past the last initializer. 826 init_iterator init_end() { 827 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 828 } 829 /// end() - Retrieve an iterator past the last initializer. 830 init_const_iterator init_end() const { 831 return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 832 } 833 834 /// getNumArgs - Determine the number of arguments used to 835 /// initialize the member or base. 836 unsigned getNumBaseOrMemberInitializers() const { 837 return NumBaseOrMemberInitializers; 838 } 839 840 void setBaseOrMemberInitializers(ASTContext &C, 841 CXXBaseOrMemberInitializer **Initializers, 842 unsigned NumInitializers); 843 844 /// isDefaultConstructor - Whether this constructor is a default 845 /// constructor (C++ [class.ctor]p5), which can be used to 846 /// default-initialize a class of this type. 847 bool isDefaultConstructor() const; 848 849 /// isCopyConstructor - Whether this constructor is a copy 850 /// constructor (C++ [class.copy]p2, which can be used to copy the 851 /// class. @p TypeQuals will be set to the qualifiers on the 852 /// argument type. For example, @p TypeQuals would be set to @c 853 /// QualType::Const for the following copy constructor: 854 /// 855 /// @code 856 /// class X { 857 /// public: 858 /// X(const X&); 859 /// }; 860 /// @endcode 861 bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const; 862 863 /// isCopyConstructor - Whether this constructor is a copy 864 /// constructor (C++ [class.copy]p2, which can be used to copy the 865 /// class. 866 bool isCopyConstructor(ASTContext &Context) const { 867 unsigned TypeQuals = 0; 868 return isCopyConstructor(Context, TypeQuals); 869 } 870 871 /// isConvertingConstructor - Whether this constructor is a 872 /// converting constructor (C++ [class.conv.ctor]), which can be 873 /// used for user-defined conversions. 874 bool isConvertingConstructor() const; 875 876 // Implement isa/cast/dyncast/etc. 877 static bool classof(const Decl *D) { 878 return D->getKind() == CXXConstructor; 879 } 880 static bool classof(const CXXConstructorDecl *D) { return true; } 881}; 882 883/// CXXDestructorDecl - Represents a C++ destructor within a 884/// class. For example: 885/// 886/// @code 887/// class X { 888/// public: 889/// ~X(); // represented by a CXXDestructorDecl. 890/// }; 891/// @endcode 892class CXXDestructorDecl : public CXXMethodDecl { 893 /// ImplicitlyDefined - Whether this destructor was implicitly 894 /// defined by the compiler. When false, the destructor was defined 895 /// by the user. In C++03, this flag will have the same value as 896 /// Implicit. In C++0x, however, a destructor that is 897 /// explicitly defaulted (i.e., defined with " = default") will have 898 /// @c !Implicit && ImplicitlyDefined. 899 bool ImplicitlyDefined : 1; 900 901 /// Support for base and member destruction. 902 /// BaseOrMemberDestructions - The arguments used to destruct the base 903 /// or member. 904 uintptr_t *BaseOrMemberDestructions; 905 unsigned NumBaseOrMemberDestructions; 906 907 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L, 908 DeclarationName N, QualType T, 909 bool isInline, bool isImplicitlyDeclared) 910 : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline), 911 ImplicitlyDefined(false), 912 BaseOrMemberDestructions(0), NumBaseOrMemberDestructions(0) { 913 setImplicit(isImplicitlyDeclared); 914 } 915 virtual void Destroy(ASTContext& C); 916 917public: 918 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 919 SourceLocation L, DeclarationName N, 920 QualType T, bool isInline, 921 bool isImplicitlyDeclared); 922 923 /// isImplicitlyDefined - Whether this destructor was implicitly 924 /// defined. If false, then this destructor was defined by the 925 /// user. This operation can only be invoked if the destructor has 926 /// already been defined. 927 bool isImplicitlyDefined() const { 928 assert(isThisDeclarationADefinition() && 929 "Can only get the implicit-definition flag once the destructor has been defined"); 930 return ImplicitlyDefined; 931 } 932 933 /// setImplicitlyDefined - Set whether this destructor was 934 /// implicitly defined or not. 935 void setImplicitlyDefined(bool ID) { 936 assert(isThisDeclarationADefinition() && 937 "Can only set the implicit-definition flag once the destructor has been defined"); 938 ImplicitlyDefined = ID; 939 } 940 941 /// destr_iterator - Iterates through the member/base destruction list. 942 943 /// destr_const_iterator - Iterates through the member/base destruction list. 944 typedef uintptr_t const destr_const_iterator; 945 946 /// destr_begin() - Retrieve an iterator to the first destructed member/base. 947 uintptr_t* destr_begin() { 948 return BaseOrMemberDestructions; 949 } 950 /// destr_begin() - Retrieve an iterator to the first destructed member/base. 951 uintptr_t* destr_begin() const { 952 return BaseOrMemberDestructions; 953 } 954 955 /// destr_end() - Retrieve an iterator past the last destructed member/base. 956 uintptr_t* destr_end() { 957 return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 958 } 959 /// destr_end() - Retrieve an iterator past the last destructed member/base. 960 uintptr_t* destr_end() const { 961 return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 962 } 963 964 /// getNumBaseOrMemberDestructions - Number of base and non-static members 965 /// to destroy. 966 unsigned getNumBaseOrMemberDestructions() const { 967 return NumBaseOrMemberDestructions; 968 } 969 970 /// getBaseOrMember - get the generic 'member' representing either the field 971 /// or a base class. 972 uintptr_t* getBaseOrMemberToDestroy() const { 973 return BaseOrMemberDestructions; 974 } 975 976 /// isVbaseToDestroy - returns true, if object is virtual base. 977 bool isVbaseToDestroy(uintptr_t Vbase) const { 978 return (Vbase & 0x1) != 0; 979 } 980 /// isDirectNonVBaseToDestroy - returns true, if object is direct non-virtual 981 /// base. 982 bool isDirectNonVBaseToDestroy(uintptr_t DrctNonVbase) const { 983 return (DrctNonVbase & 0x2) != 0; 984 } 985 /// isAnyBaseToDestroy - returns true, if object is any base (virtual or 986 /// direct non-virtual) 987 bool isAnyBaseToDestroy(uintptr_t AnyBase) const { 988 return (AnyBase & 0x3) != 0; 989 } 990 /// isMemberToDestroy - returns true if object is a non-static data member. 991 bool isMemberToDestroy(uintptr_t Member) const { 992 return (Member & 0x3) == 0; 993 } 994 /// getAnyBaseClassToDestroy - Get the type for the given base class object. 995 Type *getAnyBaseClassToDestroy(uintptr_t Base) const { 996 if (isAnyBaseToDestroy(Base)) 997 return reinterpret_cast<Type*>(Base & ~0x03); 998 return 0; 999 } 1000 /// getMemberToDestroy - Get the member for the given object. 1001 FieldDecl *getMemberToDestroy(uintptr_t Member) { 1002 if (isMemberToDestroy(Member)) 1003 return reinterpret_cast<FieldDecl *>(Member); 1004 return 0; 1005 } 1006 /// getVbaseClassToDestroy - Get the virtual base. 1007 Type *getVbaseClassToDestroy(uintptr_t Vbase) const { 1008 if (isVbaseToDestroy(Vbase)) 1009 return reinterpret_cast<Type*>(Vbase & ~0x01); 1010 return 0; 1011 } 1012 /// getDirectNonVBaseClassToDestroy - Get the virtual base. 1013 Type *getDirectNonVBaseClassToDestroy(uintptr_t Base) const { 1014 if (isDirectNonVBaseToDestroy(Base)) 1015 return reinterpret_cast<Type*>(Base & ~0x02); 1016 return 0; 1017 } 1018 1019 /// computeBaseOrMembersToDestroy - Compute information in current 1020 /// destructor decl's AST of bases and non-static data members which will be 1021 /// implicitly destroyed. We are storing the destruction in the order that 1022 /// they should occur (which is the reverse of construction order). 1023 void computeBaseOrMembersToDestroy(ASTContext &C); 1024 1025 // Implement isa/cast/dyncast/etc. 1026 static bool classof(const Decl *D) { 1027 return D->getKind() == CXXDestructor; 1028 } 1029 static bool classof(const CXXDestructorDecl *D) { return true; } 1030}; 1031 1032/// CXXConversionDecl - Represents a C++ conversion function within a 1033/// class. For example: 1034/// 1035/// @code 1036/// class X { 1037/// public: 1038/// operator bool(); 1039/// }; 1040/// @endcode 1041class CXXConversionDecl : public CXXMethodDecl { 1042 /// Explicit - Whether this conversion function is marked 1043 /// "explicit", meaning that it can only be applied when the user 1044 /// explicitly wrote a cast. This is a C++0x feature. 1045 bool Explicit : 1; 1046 1047 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L, 1048 DeclarationName N, QualType T, 1049 bool isInline, bool isExplicit) 1050 : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline), 1051 Explicit(isExplicit) { } 1052 1053public: 1054 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 1055 SourceLocation L, DeclarationName N, 1056 QualType T, bool isInline, 1057 bool isExplicit); 1058 1059 /// isExplicit - Whether this is an explicit conversion operator 1060 /// (C++0x only). Explicit conversion operators are only considered 1061 /// when the user has explicitly written a cast. 1062 bool isExplicit() const { return Explicit; } 1063 1064 /// getConversionType - Returns the type that this conversion 1065 /// function is converting to. 1066 QualType getConversionType() const { 1067 return getType()->getAsFunctionType()->getResultType(); 1068 } 1069 1070 // Implement isa/cast/dyncast/etc. 1071 static bool classof(const Decl *D) { 1072 return D->getKind() == CXXConversion; 1073 } 1074 static bool classof(const CXXConversionDecl *D) { return true; } 1075}; 1076 1077/// LinkageSpecDecl - This represents a linkage specification. For example: 1078/// extern "C" void foo(); 1079/// 1080class LinkageSpecDecl : public Decl, public DeclContext { 1081public: 1082 /// LanguageIDs - Used to represent the language in a linkage 1083 /// specification. The values are part of the serialization abi for 1084 /// ASTs and cannot be changed without altering that abi. To help 1085 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 1086 /// from the dwarf standard. 1087 enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002, 1088 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 }; 1089private: 1090 /// Language - The language for this linkage specification. 1091 LanguageIDs Language; 1092 1093 /// HadBraces - Whether this linkage specification had curly braces or not. 1094 bool HadBraces : 1; 1095 1096 LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 1097 bool Braces) 1098 : Decl(LinkageSpec, DC, L), 1099 DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { } 1100 1101public: 1102 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 1103 SourceLocation L, LanguageIDs Lang, 1104 bool Braces); 1105 1106 LanguageIDs getLanguage() const { return Language; } 1107 1108 /// hasBraces - Determines whether this linkage specification had 1109 /// braces in its syntactic form. 1110 bool hasBraces() const { return HadBraces; } 1111 1112 static bool classof(const Decl *D) { 1113 return D->getKind() == LinkageSpec; 1114 } 1115 static bool classof(const LinkageSpecDecl *D) { return true; } 1116 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 1117 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 1118 } 1119 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 1120 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 1121 } 1122}; 1123 1124/// UsingDirectiveDecl - Represents C++ using-directive. For example: 1125/// 1126/// using namespace std; 1127/// 1128// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 1129// artificial name, for all using-directives in order to store 1130// them in DeclContext effectively. 1131class UsingDirectiveDecl : public NamedDecl { 1132 1133 /// SourceLocation - Location of 'namespace' token. 1134 SourceLocation NamespaceLoc; 1135 1136 /// \brief The source range that covers the nested-name-specifier 1137 /// preceding the namespace name. 1138 SourceRange QualifierRange; 1139 1140 /// \brief The nested-name-specifier that precedes the namespace 1141 /// name, if any. 1142 NestedNameSpecifier *Qualifier; 1143 1144 /// IdentLoc - Location of nominated namespace-name identifier. 1145 // FIXME: We don't store location of scope specifier. 1146 SourceLocation IdentLoc; 1147 1148 /// NominatedNamespace - Namespace nominated by using-directive. 1149 NamespaceDecl *NominatedNamespace; 1150 1151 /// Enclosing context containing both using-directive and nomintated 1152 /// namespace. 1153 DeclContext *CommonAncestor; 1154 1155 /// getUsingDirectiveName - Returns special DeclarationName used by 1156 /// using-directives. This is only used by DeclContext for storing 1157 /// UsingDirectiveDecls in its lookup structure. 1158 static DeclarationName getName() { 1159 return DeclarationName::getUsingDirectiveName(); 1160 } 1161 1162 UsingDirectiveDecl(DeclContext *DC, SourceLocation L, 1163 SourceLocation NamespcLoc, 1164 SourceRange QualifierRange, 1165 NestedNameSpecifier *Qualifier, 1166 SourceLocation IdentLoc, 1167 NamespaceDecl *Nominated, 1168 DeclContext *CommonAncestor) 1169 : NamedDecl(Decl::UsingDirective, DC, L, getName()), 1170 NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 1171 Qualifier(Qualifier), IdentLoc(IdentLoc), 1172 NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0), 1173 CommonAncestor(CommonAncestor) { 1174 } 1175 1176public: 1177 /// \brief Retrieve the source range of the nested-name-specifier 1178 /// that qualifiers the namespace name. 1179 SourceRange getQualifierRange() const { return QualifierRange; } 1180 1181 /// \brief Retrieve the nested-name-specifier that qualifies the 1182 /// name of the namespace. 1183 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1184 1185 /// getNominatedNamespace - Returns namespace nominated by using-directive. 1186 NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; } 1187 1188 const NamespaceDecl *getNominatedNamespace() const { 1189 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 1190 } 1191 1192 /// getCommonAncestor - returns common ancestor context of using-directive, 1193 /// and nominated by it namespace. 1194 DeclContext *getCommonAncestor() { return CommonAncestor; } 1195 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 1196 1197 /// getNamespaceKeyLocation - Returns location of namespace keyword. 1198 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 1199 1200 /// getIdentLocation - Returns location of identifier. 1201 SourceLocation getIdentLocation() const { return IdentLoc; } 1202 1203 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 1204 SourceLocation L, 1205 SourceLocation NamespaceLoc, 1206 SourceRange QualifierRange, 1207 NestedNameSpecifier *Qualifier, 1208 SourceLocation IdentLoc, 1209 NamespaceDecl *Nominated, 1210 DeclContext *CommonAncestor); 1211 1212 static bool classof(const Decl *D) { 1213 return D->getKind() == Decl::UsingDirective; 1214 } 1215 static bool classof(const UsingDirectiveDecl *D) { return true; } 1216 1217 // Friend for getUsingDirectiveName. 1218 friend class DeclContext; 1219}; 1220 1221/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 1222/// 1223/// @code 1224/// namespace Foo = Bar; 1225/// @endcode 1226class NamespaceAliasDecl : public NamedDecl { 1227 SourceLocation AliasLoc; 1228 1229 /// \brief The source range that covers the nested-name-specifier 1230 /// preceding the namespace name. 1231 SourceRange QualifierRange; 1232 1233 /// \brief The nested-name-specifier that precedes the namespace 1234 /// name, if any. 1235 NestedNameSpecifier *Qualifier; 1236 1237 /// IdentLoc - Location of namespace identifier. 1238 SourceLocation IdentLoc; 1239 1240 /// Namespace - The Decl that this alias points to. Can either be a 1241 /// NamespaceDecl or a NamespaceAliasDecl. 1242 NamedDecl *Namespace; 1243 1244 NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 1245 SourceLocation AliasLoc, IdentifierInfo *Alias, 1246 SourceRange QualifierRange, 1247 NestedNameSpecifier *Qualifier, 1248 SourceLocation IdentLoc, NamedDecl *Namespace) 1249 : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 1250 QualifierRange(QualifierRange), Qualifier(Qualifier), 1251 IdentLoc(IdentLoc), Namespace(Namespace) { } 1252 1253public: 1254 /// \brief Retrieve the source range of the nested-name-specifier 1255 /// that qualifiers the namespace name. 1256 SourceRange getQualifierRange() const { return QualifierRange; } 1257 1258 /// \brief Retrieve the nested-name-specifier that qualifies the 1259 /// name of the namespace. 1260 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1261 1262 NamespaceDecl *getNamespace() { 1263 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 1264 return AD->getNamespace(); 1265 1266 return cast<NamespaceDecl>(Namespace); 1267 } 1268 1269 const NamespaceDecl *getNamespace() const { 1270 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 1271 } 1272 1273 /// \brief Retrieve the namespace that this alias refers to, which 1274 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 1275 NamedDecl *getAliasedNamespace() const { return Namespace; } 1276 1277 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 1278 SourceLocation L, SourceLocation AliasLoc, 1279 IdentifierInfo *Alias, 1280 SourceRange QualifierRange, 1281 NestedNameSpecifier *Qualifier, 1282 SourceLocation IdentLoc, 1283 NamedDecl *Namespace); 1284 1285 static bool classof(const Decl *D) { 1286 return D->getKind() == Decl::NamespaceAlias; 1287 } 1288 static bool classof(const NamespaceAliasDecl *D) { return true; } 1289}; 1290 1291/// UsingDecl - Represents a C++ using-declaration. For example: 1292/// using someNameSpace::someIdentifier; 1293class UsingDecl : public NamedDecl { 1294 1295 /// \brief The source range that covers the nested-name-specifier 1296 /// preceding the declaration name. 1297 SourceRange NestedNameRange; 1298 /// \brief The source location of the target declaration name. 1299 SourceLocation TargetNameLocation; 1300 /// \brief The source location of the "using" location itself. 1301 SourceLocation UsingLocation; 1302 /// \brief Target declaration. 1303 NamedDecl* TargetDecl; 1304 /// \brief Target declaration. 1305 NestedNameSpecifier* TargetNestedNameDecl; 1306 1307 // Had 'typename' keyword. 1308 bool IsTypeName; 1309 1310 UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, 1311 SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target, 1312 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) 1313 : NamedDecl(Decl::Using, DC, L, Target->getDeclName()), 1314 NestedNameRange(NNR), TargetNameLocation(TargetNL), 1315 UsingLocation(UL), TargetDecl(Target), 1316 TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { 1317 this->IdentifierNamespace = TargetDecl->getIdentifierNamespace(); 1318 } 1319 1320public: 1321 /// \brief Returns the source range that covers the nested-name-specifier 1322 /// preceding the namespace name. 1323 SourceRange getNestedNameRange() { return NestedNameRange; } 1324 1325 /// \brief Returns the source location of the target declaration name. 1326 SourceLocation getTargetNameLocation() { return TargetNameLocation; } 1327 1328 /// \brief Returns the source location of the "using" location itself. 1329 SourceLocation getUsingLocation() { return UsingLocation; } 1330 1331 /// \brief getTargetDecl - Returns target specified by using-decl. 1332 NamedDecl *getTargetDecl() { return TargetDecl; } 1333 const NamedDecl *getTargetDecl() const { return TargetDecl; } 1334 1335 /// \brief Get target nested name declaration. 1336 NestedNameSpecifier* getTargetNestedNameDecl() { 1337 return TargetNestedNameDecl; 1338 } 1339 1340 /// isTypeName - Return true if using decl had 'typename'. 1341 bool isTypeName() const { return IsTypeName; } 1342 1343 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 1344 SourceLocation L, SourceRange NNR, SourceLocation TargetNL, 1345 SourceLocation UL, NamedDecl* Target, 1346 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg); 1347 1348 static bool classof(const Decl *D) { 1349 return D->getKind() == Decl::Using; 1350 } 1351 static bool classof(const UsingDecl *D) { return true; } 1352}; 1353 1354/// StaticAssertDecl - Represents a C++0x static_assert declaration. 1355class StaticAssertDecl : public Decl { 1356 Expr *AssertExpr; 1357 StringLiteral *Message; 1358 1359 StaticAssertDecl(DeclContext *DC, SourceLocation L, 1360 Expr *assertexpr, StringLiteral *message) 1361 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } 1362 1363public: 1364 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 1365 SourceLocation L, Expr *AssertExpr, 1366 StringLiteral *Message); 1367 1368 Expr *getAssertExpr() { return AssertExpr; } 1369 const Expr *getAssertExpr() const { return AssertExpr; } 1370 1371 StringLiteral *getMessage() { return Message; } 1372 const StringLiteral *getMessage() const { return Message; } 1373 1374 virtual ~StaticAssertDecl(); 1375 virtual void Destroy(ASTContext& C); 1376 1377 static bool classof(const Decl *D) { 1378 return D->getKind() == Decl::StaticAssert; 1379 } 1380 static bool classof(StaticAssertDecl *D) { return true; } 1381}; 1382 1383/// Insertion operator for diagnostics. This allows sending AccessSpecifier's 1384/// into a diagnostic with <<. 1385const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1386 AccessSpecifier AS); 1387 1388} // end namespace clang 1389 1390#endif 1391