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