1 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the C++ Decl subclasses, other than those for
11 // templates (in DeclTemplate.h) and friends (in DeclFriend.h).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_DECLCXX_H
16 #define LLVM_CLANG_AST_DECLCXX_H
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/TypeLoc.h"
21 #include "clang/AST/UnresolvedSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/SmallPtrSet.h"
27 class ClassTemplateDecl;
28 class ClassTemplateSpecializationDecl;
31 class CXXConstructorDecl;
32 class CXXConversionDecl;
33 class CXXDestructorDecl;
36 class CXXMemberLookupCriteria;
37 class CXXFinalOverriderMap;
38 class CXXIndirectPrimaryBaseSet;
41 /// \brief Represents any kind of function declaration, whether it is a
42 /// concrete function or a function template.
43 class AnyFunctionDecl {
46 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
49 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
50 AnyFunctionDecl(FunctionTemplateDecl *FTD);
52 /// \brief Implicily converts any function or function template into a
53 /// named declaration.
54 operator NamedDecl *() const { return Function; }
56 /// \brief Retrieve the underlying function or function template.
57 NamedDecl *get() const { return Function; }
59 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
60 return AnyFunctionDecl(ND);
64 } // end namespace clang
67 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
68 /// AnyFunctionDecl to any function or function template declaration.
69 template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
70 typedef ::clang::NamedDecl* SimpleType;
71 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
75 template<> struct simplify_type< ::clang::AnyFunctionDecl>
76 : public simplify_type<const ::clang::AnyFunctionDecl> {};
78 // Provide PointerLikeTypeTraits for non-cvr pointers.
80 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
82 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
85 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
86 return ::clang::AnyFunctionDecl::getFromNamedDecl(
87 static_cast< ::clang::NamedDecl*>(P));
90 enum { NumLowBitsAvailable = 2 };
93 } // end namespace llvm
97 /// AccessSpecDecl - An access specifier followed by colon ':'.
99 /// An objects of this class represents sugar for the syntactic occurrence
100 /// of an access specifier followed by a colon in the list of member
101 /// specifiers of a C++ class definition.
103 /// Note that they do not represent other uses of access specifiers,
104 /// such as those occurring in a list of base specifiers.
105 /// Also note that this class has nothing to do with so-called
106 /// "access declarations" (C++98 11.3 [class.access.dcl]).
107 class AccessSpecDecl : public Decl {
108 /// ColonLoc - The location of the ':'.
109 SourceLocation ColonLoc;
111 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
112 SourceLocation ASLoc, SourceLocation ColonLoc)
113 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
116 AccessSpecDecl(EmptyShell Empty)
117 : Decl(AccessSpec, Empty) { }
119 /// getAccessSpecifierLoc - The location of the access specifier.
120 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
121 /// setAccessSpecifierLoc - Sets the location of the access specifier.
122 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
124 /// getColonLoc - The location of the colon following the access specifier.
125 SourceLocation getColonLoc() const { return ColonLoc; }
126 /// setColonLoc - Sets the location of the colon.
127 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
129 SourceRange getSourceRange() const {
130 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
133 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
134 DeclContext *DC, SourceLocation ASLoc,
135 SourceLocation ColonLoc) {
136 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
138 static AccessSpecDecl *Create(ASTContext &C, EmptyShell Empty) {
139 return new (C) AccessSpecDecl(Empty);
142 // Implement isa/cast/dyncast/etc.
143 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
144 static bool classof(const AccessSpecDecl *D) { return true; }
145 static bool classofKind(Kind K) { return K == AccessSpec; }
149 /// CXXBaseSpecifier - A base class of a C++ class.
151 /// Each CXXBaseSpecifier represents a single, direct base class (or
152 /// struct) of a C++ class (or struct). It specifies the type of that
153 /// base class, whether it is a virtual or non-virtual base, and what
154 /// level of access (public, protected, private) is used for the
155 /// derivation. For example:
160 /// class C : public virtual A, protected B { };
163 /// In this code, C will have two CXXBaseSpecifiers, one for "public
164 /// virtual A" and the other for "protected B".
165 class CXXBaseSpecifier {
166 /// Range - The source code range that covers the full base
167 /// specifier, including the "virtual" (if present) and access
168 /// specifier (if present).
171 /// \brief The source location of the ellipsis, if this is a pack
173 SourceLocation EllipsisLoc;
175 /// Virtual - Whether this is a virtual base class or not.
178 /// BaseOfClass - Whether this is the base of a class (true) or of a
179 /// struct (false). This determines the mapping from the access
180 /// specifier as written in the source code to the access specifier
181 /// used for semantic analysis.
182 bool BaseOfClass : 1;
184 /// Access - Access specifier as written in the source code (which
185 /// may be AS_none). The actual type of data stored here is an
186 /// AccessSpecifier, but we use "unsigned" here to work around a
190 /// InheritConstructors - Whether the class contains a using declaration
191 /// to inherit the named class's constructors.
192 bool InheritConstructors : 1;
194 /// BaseTypeInfo - The type of the base class. This will be a class or struct
195 /// (or a typedef of such). The source code range does not include the
196 /// "virtual" or access specifier.
197 TypeSourceInfo *BaseTypeInfo;
200 CXXBaseSpecifier() { }
202 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
203 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
204 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
205 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
207 /// getSourceRange - Retrieves the source range that contains the
208 /// entire base specifier.
209 SourceRange getSourceRange() const { return Range; }
211 /// isVirtual - Determines whether the base class is a virtual base
213 bool isVirtual() const { return Virtual; }
215 /// \brief Determine whether this base class is a base of a class declared
216 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
217 bool isBaseOfClass() const { return BaseOfClass; }
219 /// \brief Determine whether this base specifier is a pack expansion.
220 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
222 /// \brief Determine whether this base class's constructors get inherited.
223 bool getInheritConstructors() const { return InheritConstructors; }
225 /// \brief Set that this base class's constructors should be inherited.
226 void setInheritConstructors(bool Inherit = true) {
227 InheritConstructors = Inherit;
230 /// \brief For a pack expansion, determine the location of the ellipsis.
231 SourceLocation getEllipsisLoc() const {
235 /// getAccessSpecifier - Returns the access specifier for this base
236 /// specifier. This is the actual base specifier as used for
237 /// semantic analysis, so the result can never be AS_none. To
238 /// retrieve the access specifier as written in the source code, use
239 /// getAccessSpecifierAsWritten().
240 AccessSpecifier getAccessSpecifier() const {
241 if ((AccessSpecifier)Access == AS_none)
242 return BaseOfClass? AS_private : AS_public;
244 return (AccessSpecifier)Access;
247 /// getAccessSpecifierAsWritten - Retrieves the access specifier as
248 /// written in the source code (which may mean that no access
249 /// specifier was explicitly written). Use getAccessSpecifier() to
250 /// retrieve the access specifier for use in semantic analysis.
251 AccessSpecifier getAccessSpecifierAsWritten() const {
252 return (AccessSpecifier)Access;
255 /// getType - Retrieves the type of the base class. This type will
256 /// always be an unqualified class type.
257 QualType getType() const { return BaseTypeInfo->getType(); }
259 /// getTypeLoc - Retrieves the type and source location of the base class.
260 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
263 /// CXXRecordDecl - Represents a C++ struct/union/class.
264 /// FIXME: This class will disappear once we've properly taught RecordDecl
265 /// to deal with C++-specific things.
266 class CXXRecordDecl : public RecordDecl {
268 friend void TagDecl::startDefinition();
270 struct DefinitionData {
271 DefinitionData(CXXRecordDecl *D);
273 /// UserDeclaredConstructor - True when this class has a
274 /// user-declared constructor.
275 bool UserDeclaredConstructor : 1;
277 /// UserDeclaredCopyConstructor - True when this class has a
278 /// user-declared copy constructor.
279 bool UserDeclaredCopyConstructor : 1;
281 /// UserDeclaredCopyAssignment - True when this class has a
282 /// user-declared copy assignment operator.
283 bool UserDeclaredCopyAssignment : 1;
285 /// UserDeclaredDestructor - True when this class has a
286 /// user-declared destructor.
287 bool UserDeclaredDestructor : 1;
289 /// Aggregate - True when this class is an aggregate.
292 /// PlainOldData - True when this class is a POD-type.
293 bool PlainOldData : 1;
295 /// Empty - true when this class is empty for traits purposes,
296 /// i.e. has no data members other than 0-width bit-fields, has no
297 /// virtual function/base, and doesn't inherit from a non-empty
298 /// class. Doesn't take union-ness into account.
301 /// Polymorphic - True when this class is polymorphic, i.e. has at
302 /// least one virtual member or derives from a polymorphic class.
303 bool Polymorphic : 1;
305 /// Abstract - True when this class is abstract, i.e. has at least
306 /// one pure virtual function, (that can come from a base class).
309 /// IsStandardLayout - True when this class has standard layout.
311 /// C++0x [class]p7. A standard-layout class is a class that:
312 /// * has no non-static data members of type non-standard-layout class (or
313 /// array of such types) or reference,
314 /// * has no virtual functions (10.3) and no virtual base classes (10.1),
315 /// * has the same access control (Clause 11) for all non-static data members
316 /// * has no non-standard-layout base classes,
317 /// * either has no non-static data members in the most derived class and at
318 /// most one base class with non-static data members, or has no base
319 /// classes with non-static data members, and
320 /// * has no base classes of the same type as the first non-static data
322 bool IsStandardLayout : 1;
324 /// HasNoNonEmptyBases - True when there are no non-empty base classes.
326 /// This is a helper bit of state used to implement IsStandardLayout more
328 bool HasNoNonEmptyBases : 1;
330 /// HasPrivateFields - True when there are private non-static data members.
331 bool HasPrivateFields : 1;
333 /// HasProtectedFields - True when there are protected non-static data
335 bool HasProtectedFields : 1;
337 /// HasPublicFields - True when there are private non-static data members.
338 bool HasPublicFields : 1;
340 /// HasTrivialConstructor - True when this class has a trivial constructor.
342 /// C++ [class.ctor]p5. A constructor is trivial if it is an
343 /// implicitly-declared default constructor and if:
344 /// * its class has no virtual functions and no virtual base classes, and
345 /// * all the direct base classes of its class have trivial constructors, and
346 /// * for all the nonstatic data members of its class that are of class type
347 /// (or array thereof), each such class has a trivial constructor.
348 bool HasTrivialConstructor : 1;
350 /// HasConstExprNonCopyMoveConstructor - True when this class has at least
351 /// one constexpr constructor which is neither the copy nor move
353 bool HasConstExprNonCopyMoveConstructor : 1;
355 /// HasTrivialCopyConstructor - True when this class has a trivial copy
358 /// C++0x [class.copy]p13:
359 /// A copy/move constructor for class X is trivial if it is neither
360 /// user-provided nor deleted and if
361 /// -- class X has no virtual functions and no virtual base classes, and
362 /// -- the constructor selected to copy/move each direct base class
363 /// subobject is trivial, and
364 /// -- for each non-static data member of X that is of class type (or an
365 /// array thereof), the constructor selected to copy/move that member
367 /// otherwise the copy/move constructor is non-trivial.
368 bool HasTrivialCopyConstructor : 1;
370 /// HasTrivialMoveConstructor - True when this class has a trivial move
373 /// C++0x [class.copy]p13:
374 /// A copy/move constructor for class X is trivial if it is neither
375 /// user-provided nor deleted and if
376 /// -- class X has no virtual functions and no virtual base classes, and
377 /// -- the constructor selected to copy/move each direct base class
378 /// subobject is trivial, and
379 /// -- for each non-static data member of X that is of class type (or an
380 /// array thereof), the constructor selected to copy/move that member
382 /// otherwise the copy/move constructor is non-trivial.
383 bool HasTrivialMoveConstructor : 1;
385 /// HasTrivialCopyAssignment - True when this class has a trivial copy
386 /// assignment operator.
388 /// C++0x [class.copy]p27:
389 /// A copy/move assignment operator for class X is trivial if it is
390 /// neither user-provided nor deleted and if
391 /// -- class X has no virtual functions and no virtual base classes, and
392 /// -- the assignment operator selected to copy/move each direct base
393 /// class subobject is trivial, and
394 /// -- for each non-static data member of X that is of class type (or an
395 /// array thereof), the assignment operator selected to copy/move
396 /// that member is trivial;
397 /// otherwise the copy/move assignment operator is non-trivial.
398 bool HasTrivialCopyAssignment : 1;
400 /// HasTrivialMoveAssignment - True when this class has a trivial move
401 /// assignment operator.
403 /// C++0x [class.copy]p27:
404 /// A copy/move assignment operator for class X is trivial if it is
405 /// neither user-provided nor deleted and if
406 /// -- class X has no virtual functions and no virtual base classes, and
407 /// -- the assignment operator selected to copy/move each direct base
408 /// class subobject is trivial, and
409 /// -- for each non-static data member of X that is of class type (or an
410 /// array thereof), the assignment operator selected to copy/move
411 /// that member is trivial;
412 /// otherwise the copy/move assignment operator is non-trivial.
413 bool HasTrivialMoveAssignment : 1;
415 /// HasTrivialDestructor - True when this class has a trivial destructor.
417 /// C++ [class.dtor]p3. A destructor is trivial if it is an
418 /// implicitly-declared destructor and if:
419 /// * all of the direct base classes of its class have trivial destructors
421 /// * for all of the non-static data members of its class that are of class
422 /// type (or array thereof), each such class has a trivial destructor.
423 bool HasTrivialDestructor : 1;
425 /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
426 /// one non-static data member or base class of non literal type.
427 bool HasNonLiteralTypeFieldsOrBases : 1;
429 /// ComputedVisibleConversions - True when visible conversion functions are
430 /// already computed and are available.
431 bool ComputedVisibleConversions : 1;
433 /// \brief Whether we have already declared the default constructor or
434 /// do not need to have one declared.
435 bool DeclaredDefaultConstructor : 1;
437 /// \brief Whether we have already declared the copy constructor.
438 bool DeclaredCopyConstructor : 1;
440 /// \brief Whether we have already declared the copy-assignment operator.
441 bool DeclaredCopyAssignment : 1;
443 /// \brief Whether we have already declared a destructor within the class.
444 bool DeclaredDestructor : 1;
446 /// NumBases - The number of base class specifiers in Bases.
449 /// NumVBases - The number of virtual base class specifiers in VBases.
452 /// Bases - Base classes of this class.
453 /// FIXME: This is wasted space for a union.
454 LazyCXXBaseSpecifiersPtr Bases;
456 /// VBases - direct and indirect virtual base classes of this class.
457 LazyCXXBaseSpecifiersPtr VBases;
459 /// Conversions - Overload set containing the conversion functions
460 /// of this C++ class (but not its inherited conversion
461 /// functions). Each of the entries in this overload set is a
462 /// CXXConversionDecl.
463 UnresolvedSet<4> Conversions;
465 /// VisibleConversions - Overload set containing the conversion
466 /// functions of this C++ class and all those inherited conversion
467 /// functions that are visible in this class. Each of the entries
468 /// in this overload set is a CXXConversionDecl or a
469 /// FunctionTemplateDecl.
470 UnresolvedSet<4> VisibleConversions;
472 /// Definition - The declaration which defines this record.
473 CXXRecordDecl *Definition;
475 /// FirstFriend - The first friend declaration in this class, or
476 /// null if there aren't any. This is actually currently stored
477 /// in reverse order.
478 FriendDecl *FirstFriend;
480 /// \brief Retrieve the set of direct base classes.
481 CXXBaseSpecifier *getBases() const {
482 return Bases.get(Definition->getASTContext().getExternalSource());
485 /// \brief Retrieve the set of virtual base classes.
486 CXXBaseSpecifier *getVBases() const {
487 return VBases.get(Definition->getASTContext().getExternalSource());
491 struct DefinitionData &data() {
492 assert(DefinitionData && "queried property of class with no definition");
493 return *DefinitionData;
496 const struct DefinitionData &data() const {
497 assert(DefinitionData && "queried property of class with no definition");
498 return *DefinitionData;
501 /// \brief The template or declaration that this declaration
502 /// describes or was instantiated from, respectively.
504 /// For non-templates, this value will be NULL. For record
505 /// declarations that describe a class template, this will be a
506 /// pointer to a ClassTemplateDecl. For member
507 /// classes of class template specializations, this will be the
508 /// MemberSpecializationInfo referring to the member class that was
509 /// instantiated or specialized.
510 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
511 TemplateOrInstantiation;
513 friend class DeclContext;
515 /// \brief Notify the class that member has been added.
517 /// This routine helps maintain information about the class based on which
518 /// members have been added. It will be invoked by DeclContext::addDecl()
519 /// whenever a member is added to this record.
520 void addedMember(Decl *D);
522 void markedVirtualFunctionPure();
523 friend void FunctionDecl::setPure(bool);
526 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
527 SourceLocation StartLoc, SourceLocation IdLoc,
528 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
531 /// base_class_iterator - Iterator that traverses the base classes
533 typedef CXXBaseSpecifier* base_class_iterator;
535 /// base_class_const_iterator - Iterator that traverses the base
536 /// classes of a class.
537 typedef const CXXBaseSpecifier* base_class_const_iterator;
539 /// reverse_base_class_iterator = Iterator that traverses the base classes
540 /// of a class in reverse order.
541 typedef std::reverse_iterator<base_class_iterator>
542 reverse_base_class_iterator;
544 /// reverse_base_class_iterator = Iterator that traverses the base classes
545 /// of a class in reverse order.
546 typedef std::reverse_iterator<base_class_const_iterator>
547 reverse_base_class_const_iterator;
549 virtual CXXRecordDecl *getCanonicalDecl() {
550 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
552 virtual const CXXRecordDecl *getCanonicalDecl() const {
553 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
556 const CXXRecordDecl *getPreviousDeclaration() const {
557 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
559 CXXRecordDecl *getPreviousDeclaration() {
560 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
563 CXXRecordDecl *getDefinition() const {
564 if (!DefinitionData) return 0;
565 return data().Definition;
568 bool hasDefinition() const { return DefinitionData != 0; }
570 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
571 SourceLocation StartLoc, SourceLocation IdLoc,
572 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
573 bool DelayTypeCreation = false);
574 static CXXRecordDecl *Create(const ASTContext &C, EmptyShell Empty);
576 bool isDynamicClass() const {
577 return data().Polymorphic || data().NumVBases != 0;
580 /// setBases - Sets the base classes of this struct or class.
581 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
583 /// getNumBases - Retrieves the number of base classes of this
585 unsigned getNumBases() const { return data().NumBases; }
587 base_class_iterator bases_begin() { return data().getBases(); }
588 base_class_const_iterator bases_begin() const { return data().getBases(); }
589 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
590 base_class_const_iterator bases_end() const {
591 return bases_begin() + data().NumBases;
593 reverse_base_class_iterator bases_rbegin() {
594 return reverse_base_class_iterator(bases_end());
596 reverse_base_class_const_iterator bases_rbegin() const {
597 return reverse_base_class_const_iterator(bases_end());
599 reverse_base_class_iterator bases_rend() {
600 return reverse_base_class_iterator(bases_begin());
602 reverse_base_class_const_iterator bases_rend() const {
603 return reverse_base_class_const_iterator(bases_begin());
606 /// getNumVBases - Retrieves the number of virtual base classes of this
608 unsigned getNumVBases() const { return data().NumVBases; }
610 base_class_iterator vbases_begin() { return data().getVBases(); }
611 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
612 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
613 base_class_const_iterator vbases_end() const {
614 return vbases_begin() + data().NumVBases;
616 reverse_base_class_iterator vbases_rbegin() {
617 return reverse_base_class_iterator(vbases_end());
619 reverse_base_class_const_iterator vbases_rbegin() const {
620 return reverse_base_class_const_iterator(vbases_end());
622 reverse_base_class_iterator vbases_rend() {
623 return reverse_base_class_iterator(vbases_begin());
625 reverse_base_class_const_iterator vbases_rend() const {
626 return reverse_base_class_const_iterator(vbases_begin());
629 /// \brief Determine whether this class has any dependent base classes.
630 bool hasAnyDependentBases() const;
632 /// Iterator access to method members. The method iterator visits
633 /// all method members of the class, including non-instance methods,
634 /// special methods, etc.
635 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
637 /// method_begin - Method begin iterator. Iterates in the order the methods
639 method_iterator method_begin() const {
640 return method_iterator(decls_begin());
642 /// method_end - Method end iterator.
643 method_iterator method_end() const {
644 return method_iterator(decls_end());
647 /// Iterator access to constructor members.
648 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
650 ctor_iterator ctor_begin() const {
651 return ctor_iterator(decls_begin());
653 ctor_iterator ctor_end() const {
654 return ctor_iterator(decls_end());
657 /// An iterator over friend declarations. All of these are defined
659 class friend_iterator;
660 friend_iterator friend_begin() const;
661 friend_iterator friend_end() const;
662 void pushFriendDecl(FriendDecl *FD);
664 /// Determines whether this record has any friends.
665 bool hasFriends() const {
666 return data().FirstFriend != 0;
669 /// \brief Determine whether this class has had its default constructor
670 /// declared implicitly or does not need one declared implicitly.
672 /// This value is used for lazy creation of default constructors.
673 bool hasDeclaredDefaultConstructor() const {
674 return data().DeclaredDefaultConstructor;
677 /// hasConstCopyConstructor - Determines whether this class has a
678 /// copy constructor that accepts a const-qualified argument.
679 bool hasConstCopyConstructor(const ASTContext &Context) const;
681 /// getCopyConstructor - Returns the copy constructor for this class
682 CXXConstructorDecl *getCopyConstructor(const ASTContext &Context,
683 unsigned TypeQuals) const;
685 /// \brief Retrieve the copy-assignment operator for this class, if available.
687 /// This routine attempts to find the copy-assignment operator for this
688 /// class, using a simplistic form of overload resolution.
690 /// \param ArgIsConst Whether the argument to the copy-assignment operator
691 /// is const-qualified.
693 /// \returns The copy-assignment operator that can be invoked, or NULL if
694 /// a unique copy-assignment operator could not be found.
695 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
697 /// hasUserDeclaredConstructor - Whether this class has any
698 /// user-declared constructors. When true, a default constructor
699 /// will not be implicitly declared.
700 bool hasUserDeclaredConstructor() const {
701 return data().UserDeclaredConstructor;
704 /// hasUserDeclaredCopyConstructor - Whether this class has a
705 /// user-declared copy constructor. When false, a copy constructor
706 /// will be implicitly declared.
707 bool hasUserDeclaredCopyConstructor() const {
708 return data().UserDeclaredCopyConstructor;
711 /// \brief Determine whether this class has had its copy constructor
712 /// declared, either via the user or via an implicit declaration.
714 /// This value is used for lazy creation of copy constructors.
715 bool hasDeclaredCopyConstructor() const {
716 return data().DeclaredCopyConstructor;
719 /// hasUserDeclaredCopyAssignment - Whether this class has a
720 /// user-declared copy assignment operator. When false, a copy
721 /// assigment operator will be implicitly declared.
722 bool hasUserDeclaredCopyAssignment() const {
723 return data().UserDeclaredCopyAssignment;
726 /// \brief Determine whether this class has had its copy assignment operator
727 /// declared, either via the user or via an implicit declaration.
729 /// This value is used for lazy creation of copy assignment operators.
730 bool hasDeclaredCopyAssignment() const {
731 return data().DeclaredCopyAssignment;
734 /// hasUserDeclaredDestructor - Whether this class has a
735 /// user-declared destructor. When false, a destructor will be
736 /// implicitly declared.
737 bool hasUserDeclaredDestructor() const {
738 return data().UserDeclaredDestructor;
741 /// \brief Determine whether this class has had its destructor declared,
742 /// either via the user or via an implicit declaration.
744 /// This value is used for lazy creation of destructors.
745 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
747 /// getConversions - Retrieve the overload set containing all of the
748 /// conversion functions in this class.
749 UnresolvedSetImpl *getConversionFunctions() {
750 return &data().Conversions;
752 const UnresolvedSetImpl *getConversionFunctions() const {
753 return &data().Conversions;
756 typedef UnresolvedSetImpl::iterator conversion_iterator;
757 conversion_iterator conversion_begin() const {
758 return getConversionFunctions()->begin();
760 conversion_iterator conversion_end() const {
761 return getConversionFunctions()->end();
764 /// Removes a conversion function from this class. The conversion
765 /// function must currently be a member of this class. Furthermore,
766 /// this class must currently be in the process of being defined.
767 void removeConversion(const NamedDecl *Old);
769 /// getVisibleConversionFunctions - get all conversion functions visible
770 /// in current class; including conversion function templates.
771 const UnresolvedSetImpl *getVisibleConversionFunctions();
773 /// isAggregate - Whether this class is an aggregate (C++
774 /// [dcl.init.aggr]), which is a class with no user-declared
775 /// constructors, no private or protected non-static data members,
776 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
777 bool isAggregate() const { return data().Aggregate; }
779 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
780 /// that is an aggregate that has no non-static non-POD data members, no
781 /// reference data members, no user-defined copy assignment operator and no
782 /// user-defined destructor.
783 bool isPOD() const { return data().PlainOldData; }
785 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
786 /// means it has a virtual function, virtual base, data member (other than
787 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
788 /// a check for union-ness.
789 bool isEmpty() const { return data().Empty; }
791 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
792 /// which means that the class contains or inherits a virtual function.
793 bool isPolymorphic() const { return data().Polymorphic; }
795 /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
796 /// which means that the class contains or inherits a pure virtual function.
797 bool isAbstract() const { return data().Abstract; }
799 /// isStandardLayout - Whether this class has standard layout
801 bool isStandardLayout() const { return data().IsStandardLayout; }
803 // hasTrivialConstructor - Whether this class has a trivial constructor
804 // (C++ [class.ctor]p5)
805 bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
807 // hasConstExprNonCopyMoveConstructor - Whether this class has at least one
808 // constexpr constructor other than the copy or move constructors
809 bool hasConstExprNonCopyMoveConstructor() const {
810 return data().HasConstExprNonCopyMoveConstructor;
813 // hasTrivialCopyConstructor - Whether this class has a trivial copy
814 // constructor (C++ [class.copy]p6, C++0x [class.copy]p13)
815 bool hasTrivialCopyConstructor() const {
816 return data().HasTrivialCopyConstructor;
819 // hasTrivialMoveConstructor - Whether this class has a trivial move
820 // constructor (C++0x [class.copy]p13)
821 bool hasTrivialMoveConstructor() const {
822 return data().HasTrivialMoveConstructor;
825 // hasTrivialCopyAssignment - Whether this class has a trivial copy
826 // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27)
827 bool hasTrivialCopyAssignment() const {
828 return data().HasTrivialCopyAssignment;
831 // hasTrivialMoveAssignment - Whether this class has a trivial move
832 // assignment operator (C++0x [class.copy]p27)
833 bool hasTrivialMoveAssignment() const {
834 return data().HasTrivialMoveAssignment;
837 // hasTrivialDestructor - Whether this class has a trivial destructor
838 // (C++ [class.dtor]p3)
839 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
841 // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal type
842 // non-static data member or base class.
843 bool hasNonLiteralTypeFieldsOrBases() const {
844 return data().HasNonLiteralTypeFieldsOrBases;
847 // isTriviallyCopyable - Whether this class is considered trivially copyable
848 // (C++0x [class]p5).
849 bool isTriviallyCopyable() const;
851 /// \brief If this record is an instantiation of a member class,
852 /// retrieves the member class from which it was instantiated.
854 /// This routine will return non-NULL for (non-templated) member
855 /// classes of class templates. For example, given:
858 /// template<typename T>
864 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
865 /// whose parent is the class template specialization X<int>. For
866 /// this declaration, getInstantiatedFromMemberClass() will return
867 /// the CXXRecordDecl X<T>::A. When a complete definition of
868 /// X<int>::A is required, it will be instantiated from the
869 /// declaration returned by getInstantiatedFromMemberClass().
870 CXXRecordDecl *getInstantiatedFromMemberClass() const;
872 /// \brief If this class is an instantiation of a member class of a
873 /// class template specialization, retrieves the member specialization
875 MemberSpecializationInfo *getMemberSpecializationInfo() const;
877 /// \brief Specify that this record is an instantiation of the
879 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
880 TemplateSpecializationKind TSK);
882 /// \brief Retrieves the class template that is described by this
883 /// class declaration.
885 /// Every class template is represented as a ClassTemplateDecl and a
886 /// CXXRecordDecl. The former contains template properties (such as
887 /// the template parameter lists) while the latter contains the
888 /// actual description of the template's
889 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
890 /// CXXRecordDecl that from a ClassTemplateDecl, while
891 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
893 ClassTemplateDecl *getDescribedClassTemplate() const {
894 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
897 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
898 TemplateOrInstantiation = Template;
901 /// \brief Determine whether this particular class is a specialization or
902 /// instantiation of a class template or member class of a class template,
903 /// and how it was instantiated or specialized.
904 TemplateSpecializationKind getTemplateSpecializationKind() const;
906 /// \brief Set the kind of specialization or template instantiation this is.
907 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
909 /// getDestructor - Returns the destructor decl for this class.
910 CXXDestructorDecl *getDestructor() const;
912 /// isLocalClass - If the class is a local class [class.local], returns
913 /// the enclosing function declaration.
914 const FunctionDecl *isLocalClass() const {
915 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
916 return RD->isLocalClass();
918 return dyn_cast<FunctionDecl>(getDeclContext());
921 /// \brief Determine whether this class is derived from the class \p Base.
923 /// This routine only determines whether this class is derived from \p Base,
924 /// but does not account for factors that may make a Derived -> Base class
925 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
926 /// base class subobjects.
928 /// \param Base the base class we are searching for.
930 /// \returns true if this class is derived from Base, false otherwise.
931 bool isDerivedFrom(const CXXRecordDecl *Base) const;
933 /// \brief Determine whether this class is derived from the type \p Base.
935 /// This routine only determines whether this class is derived from \p Base,
936 /// but does not account for factors that may make a Derived -> Base class
937 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
938 /// base class subobjects.
940 /// \param Base the base class we are searching for.
942 /// \param Paths will contain the paths taken from the current class to the
943 /// given \p Base class.
945 /// \returns true if this class is derived from Base, false otherwise.
947 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
948 /// tangling input and output in \p Paths
949 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
951 /// \brief Determine whether this class is virtually derived from
952 /// the class \p Base.
954 /// This routine only determines whether this class is virtually
955 /// derived from \p Base, but does not account for factors that may
956 /// make a Derived -> Base class ill-formed, such as
957 /// private/protected inheritance or multiple, ambiguous base class
960 /// \param Base the base class we are searching for.
962 /// \returns true if this class is virtually derived from Base,
964 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
966 /// \brief Determine whether this class is provably not derived from
967 /// the type \p Base.
968 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
970 /// \brief Function type used by forallBases() as a callback.
972 /// \param Base the definition of the base class
974 /// \returns true if this base matched the search criteria
975 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
978 /// \brief Determines if the given callback holds for all the direct
979 /// or indirect base classes of this type.
981 /// The class itself does not count as a base class. This routine
982 /// returns false if the class has non-computable base classes.
984 /// \param AllowShortCircuit if false, forces the callback to be called
985 /// for every base class, even if a dependent or non-matching base was
987 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
988 bool AllowShortCircuit = true) const;
990 /// \brief Function type used by lookupInBases() to determine whether a
991 /// specific base class subobject matches the lookup criteria.
993 /// \param Specifier the base-class specifier that describes the inheritance
994 /// from the base class we are trying to match.
996 /// \param Path the current path, from the most-derived class down to the
997 /// base named by the \p Specifier.
999 /// \param UserData a single pointer to user-specified data, provided to
1000 /// lookupInBases().
1002 /// \returns true if this base matched the search criteria, false otherwise.
1003 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1007 /// \brief Look for entities within the base classes of this C++ class,
1008 /// transitively searching all base class subobjects.
1010 /// This routine uses the callback function \p BaseMatches to find base
1011 /// classes meeting some search criteria, walking all base class subobjects
1012 /// and populating the given \p Paths structure with the paths through the
1013 /// inheritance hierarchy that resulted in a match. On a successful search,
1014 /// the \p Paths structure can be queried to retrieve the matching paths and
1015 /// to determine if there were any ambiguities.
1017 /// \param BaseMatches callback function used to determine whether a given
1018 /// base matches the user-defined search criteria.
1020 /// \param UserData user data pointer that will be provided to \p BaseMatches.
1022 /// \param Paths used to record the paths from this class to its base class
1023 /// subobjects that match the search criteria.
1025 /// \returns true if there exists any path from this class to a base class
1026 /// subobject that matches the search criteria.
1027 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1028 CXXBasePaths &Paths) const;
1030 /// \brief Base-class lookup callback that determines whether the given
1031 /// base class specifier refers to a specific class declaration.
1033 /// This callback can be used with \c lookupInBases() to determine whether
1034 /// a given derived class has is a base class subobject of a particular type.
1035 /// The user data pointer should refer to the canonical CXXRecordDecl of the
1036 /// base class that we are searching for.
1037 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1038 CXXBasePath &Path, void *BaseRecord);
1040 /// \brief Base-class lookup callback that determines whether the
1041 /// given base class specifier refers to a specific class
1042 /// declaration and describes virtual derivation.
1044 /// This callback can be used with \c lookupInBases() to determine
1045 /// whether a given derived class has is a virtual base class
1046 /// subobject of a particular type. The user data pointer should
1047 /// refer to the canonical CXXRecordDecl of the base class that we
1048 /// are searching for.
1049 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1050 CXXBasePath &Path, void *BaseRecord);
1052 /// \brief Base-class lookup callback that determines whether there exists
1053 /// a tag with the given name.
1055 /// This callback can be used with \c lookupInBases() to find tag members
1056 /// of the given name within a C++ class hierarchy. The user data pointer
1057 /// is an opaque \c DeclarationName pointer.
1058 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1059 CXXBasePath &Path, void *Name);
1061 /// \brief Base-class lookup callback that determines whether there exists
1062 /// a member with the given name.
1064 /// This callback can be used with \c lookupInBases() to find members
1065 /// of the given name within a C++ class hierarchy. The user data pointer
1066 /// is an opaque \c DeclarationName pointer.
1067 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1068 CXXBasePath &Path, void *Name);
1070 /// \brief Base-class lookup callback that determines whether there exists
1071 /// a member with the given name that can be used in a nested-name-specifier.
1073 /// This callback can be used with \c lookupInBases() to find membes of
1074 /// the given name within a C++ class hierarchy that can occur within
1075 /// nested-name-specifiers.
1076 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1080 /// \brief Retrieve the final overriders for each virtual member
1081 /// function in the class hierarchy where this class is the
1082 /// most-derived class in the class hierarchy.
1083 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1085 /// \brief Get the indirect primary bases for this class.
1086 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1088 /// viewInheritance - Renders and displays an inheritance diagram
1089 /// for this C++ class and all of its base classes (transitively) using
1091 void viewInheritance(ASTContext& Context) const;
1093 /// MergeAccess - Calculates the access of a decl that is reached
1095 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1096 AccessSpecifier DeclAccess) {
1097 assert(DeclAccess != AS_none);
1098 if (DeclAccess == AS_private) return AS_none;
1099 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1102 /// \brief Indicates that the definition of this class is now complete.
1103 virtual void completeDefinition();
1105 /// \brief Indicates that the definition of this class is now complete,
1106 /// and provides a final overrider map to help determine
1108 /// \param FinalOverriders The final overrider map for this class, which can
1109 /// be provided as an optimization for abstract-class checking. If NULL,
1110 /// final overriders will be computed if they are needed to complete the
1112 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1114 /// \brief Determine whether this class may end up being abstract, even though
1115 /// it is not yet known to be abstract.
1117 /// \returns true if this class is not known to be abstract but has any
1118 /// base classes that are abstract. In this case, \c completeDefinition()
1119 /// will need to compute final overriders to determine whether the class is
1120 /// actually abstract.
1121 bool mayBeAbstract() const;
1123 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1124 static bool classofKind(Kind K) {
1125 return K >= firstCXXRecord && K <= lastCXXRecord;
1127 static bool classof(const CXXRecordDecl *D) { return true; }
1128 static bool classof(const ClassTemplateSpecializationDecl *D) {
1132 friend class ASTDeclReader;
1133 friend class ASTDeclWriter;
1134 friend class ASTReader;
1135 friend class ASTWriter;
1138 /// CXXMethodDecl - Represents a static or instance method of a
1139 /// struct/union/class.
1140 class CXXMethodDecl : public FunctionDecl {
1142 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1143 const DeclarationNameInfo &NameInfo,
1144 QualType T, TypeSourceInfo *TInfo,
1145 bool isStatic, StorageClass SCAsWritten, bool isInline,
1146 SourceLocation EndLocation)
1147 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1148 (isStatic ? SC_Static : SC_None),
1149 SCAsWritten, isInline) {
1150 if (EndLocation.isValid())
1151 setRangeEnd(EndLocation);
1155 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1156 SourceLocation StartLoc,
1157 const DeclarationNameInfo &NameInfo,
1158 QualType T, TypeSourceInfo *TInfo,
1160 StorageClass SCAsWritten,
1162 SourceLocation EndLocation);
1164 bool isStatic() const { return getStorageClass() == SC_Static; }
1165 bool isInstance() const { return !isStatic(); }
1167 bool isVirtual() const {
1169 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1171 if (CD->isVirtualAsWritten())
1174 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1177 /// \brief Determine whether this is a usual deallocation function
1178 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1179 /// delete or delete[] operator with a particular signature.
1180 bool isUsualDeallocationFunction() const;
1182 /// \brief Determine whether this is a copy-assignment operator, regardless
1183 /// of whether it was declared implicitly or explicitly.
1184 bool isCopyAssignmentOperator() const;
1186 const CXXMethodDecl *getCanonicalDecl() const {
1187 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1189 CXXMethodDecl *getCanonicalDecl() {
1190 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1194 void addOverriddenMethod(const CXXMethodDecl *MD);
1196 typedef const CXXMethodDecl ** method_iterator;
1198 method_iterator begin_overridden_methods() const;
1199 method_iterator end_overridden_methods() const;
1200 unsigned size_overridden_methods() const;
1202 /// getParent - Returns the parent of this method declaration, which
1203 /// is the class in which this method is defined.
1204 const CXXRecordDecl *getParent() const {
1205 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1208 /// getParent - Returns the parent of this method declaration, which
1209 /// is the class in which this method is defined.
1210 CXXRecordDecl *getParent() {
1211 return const_cast<CXXRecordDecl *>(
1212 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1215 /// getThisType - Returns the type of 'this' pointer.
1216 /// Should only be called for instance methods.
1217 QualType getThisType(ASTContext &C) const;
1219 unsigned getTypeQualifiers() const {
1220 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1223 /// \brief Retrieve the ref-qualifier associated with this method.
1225 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1226 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1233 RefQualifierKind getRefQualifier() const {
1234 return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1237 bool hasInlineBody() const;
1239 // Implement isa/cast/dyncast/etc.
1240 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1241 static bool classof(const CXXMethodDecl *D) { return true; }
1242 static bool classofKind(Kind K) {
1243 return K >= firstCXXMethod && K <= lastCXXMethod;
1247 /// CXXCtorInitializer - Represents a C++ base or member
1248 /// initializer, which is part of a constructor initializer that
1249 /// initializes one non-static member variable or one base class. For
1250 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1255 /// class B : public A {
1258 /// B(A& a) : A(a), f(3.14159) { }
1261 class CXXCtorInitializer {
1262 /// \brief Either the base class name (stored as a TypeSourceInfo*), an normal
1263 /// field (FieldDecl), anonymous field (IndirectFieldDecl*), or target
1264 /// constructor (CXXConstructorDecl*) being initialized.
1265 llvm::PointerUnion4<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *,
1266 CXXConstructorDecl *>
1269 /// \brief The source location for the field name or, for a base initializer
1270 /// pack expansion, the location of the ellipsis. In the case of a delegating
1271 /// constructor, it will still include the type's source location as the
1272 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1273 SourceLocation MemberOrEllipsisLocation;
1275 /// \brief The argument used to initialize the base or member, which may
1276 /// end up constructing an object (when multiple arguments are involved).
1279 /// LParenLoc - Location of the left paren of the ctor-initializer.
1280 SourceLocation LParenLoc;
1282 /// RParenLoc - Location of the right paren of the ctor-initializer.
1283 SourceLocation RParenLoc;
1285 /// IsVirtual - If the initializer is a base initializer, this keeps track
1286 /// of whether the base is virtual or not.
1289 /// IsWritten - Whether or not the initializer is explicitly written
1293 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1294 /// number keeps track of the textual order of this initializer in the
1295 /// original sources, counting from 0; otherwise, if IsWritten is false,
1296 /// it stores the number of array index variables stored after this
1297 /// object in memory.
1298 unsigned SourceOrderOrNumArrayIndices : 14;
1300 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1301 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1302 SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1305 /// CXXCtorInitializer - Creates a new base-class initializer.
1307 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1308 SourceLocation L, Expr *Init, SourceLocation R,
1309 SourceLocation EllipsisLoc);
1311 /// CXXCtorInitializer - Creates a new member initializer.
1313 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1314 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1317 /// CXXCtorInitializer - Creates a new anonymous field initializer.
1319 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1320 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1323 /// CXXCtorInitializer - Creates a new delegating Initializer.
1325 CXXCtorInitializer(ASTContext &Context, SourceLocation D, SourceLocation L,
1326 CXXConstructorDecl *Target, Expr *Init, SourceLocation R);
1328 /// \brief Creates a new member initializer that optionally contains
1329 /// array indices used to describe an elementwise initialization.
1330 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1331 SourceLocation MemberLoc, SourceLocation L,
1332 Expr *Init, SourceLocation R,
1333 VarDecl **Indices, unsigned NumIndices);
1335 /// isBaseInitializer - Returns true when this initializer is
1336 /// initializing a base class.
1337 bool isBaseInitializer() const { return Initializee.is<TypeSourceInfo*>(); }
1339 /// isMemberInitializer - Returns true when this initializer is
1340 /// initializing a non-static data member.
1341 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1343 bool isAnyMemberInitializer() const {
1344 return isMemberInitializer() || isIndirectMemberInitializer();
1347 bool isIndirectMemberInitializer() const {
1348 return Initializee.is<IndirectFieldDecl*>();
1351 /// isDelegatingInitializer - Returns true when this initializer is creating
1352 /// a delegating constructor.
1353 bool isDelegatingInitializer() const {
1354 return Initializee.is<CXXConstructorDecl *>();
1357 /// \brief Determine whether this initializer is a pack expansion.
1358 bool isPackExpansion() const {
1359 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1362 // \brief For a pack expansion, returns the location of the ellipsis.
1363 SourceLocation getEllipsisLoc() const {
1364 assert(isPackExpansion() && "Initializer is not a pack expansion");
1365 return MemberOrEllipsisLocation;
1368 /// If this is a base class initializer, returns the type of the
1369 /// base class with location information. Otherwise, returns an NULL
1371 TypeLoc getBaseClassLoc() const;
1373 /// If this is a base class initializer, returns the type of the base class.
1374 /// Otherwise, returns NULL.
1375 const Type *getBaseClass() const;
1377 /// Returns whether the base is virtual or not.
1378 bool isBaseVirtual() const {
1379 assert(isBaseInitializer() && "Must call this on base initializer!");
1384 /// \brief Returns the declarator information for a base class initializer.
1385 TypeSourceInfo *getBaseClassInfo() const {
1386 return Initializee.dyn_cast<TypeSourceInfo *>();
1389 /// getMember - If this is a member initializer, returns the
1390 /// declaration of the non-static data member being
1391 /// initialized. Otherwise, returns NULL.
1392 FieldDecl *getMember() const {
1393 if (isMemberInitializer())
1394 return Initializee.get<FieldDecl*>();
1398 FieldDecl *getAnyMember() const {
1399 if (isMemberInitializer())
1400 return Initializee.get<FieldDecl*>();
1401 else if (isIndirectMemberInitializer())
1402 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1407 IndirectFieldDecl *getIndirectMember() const {
1408 if (isIndirectMemberInitializer())
1409 return Initializee.get<IndirectFieldDecl*>();
1414 CXXConstructorDecl *getTargetConstructor() const {
1415 if (isDelegatingInitializer())
1416 return Initializee.get<CXXConstructorDecl*>();
1421 SourceLocation getMemberLocation() const {
1422 return MemberOrEllipsisLocation;
1425 /// \brief Determine the source location of the initializer.
1426 SourceLocation getSourceLocation() const;
1428 /// \brief Determine the source range covering the entire initializer.
1429 SourceRange getSourceRange() const;
1431 /// isWritten - Returns true if this initializer is explicitly written
1432 /// in the source code.
1433 bool isWritten() const { return IsWritten; }
1435 /// \brief Return the source position of the initializer, counting from 0.
1436 /// If the initializer was implicit, -1 is returned.
1437 int getSourceOrder() const {
1438 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1441 /// \brief Set the source order of this initializer. This method can only
1442 /// be called once for each initializer; it cannot be called on an
1443 /// initializer having a positive number of (implicit) array indices.
1444 void setSourceOrder(int pos) {
1445 assert(!IsWritten &&
1446 "calling twice setSourceOrder() on the same initializer");
1447 assert(SourceOrderOrNumArrayIndices == 0 &&
1448 "setSourceOrder() used when there are implicit array indices");
1450 "setSourceOrder() used to make an initializer implicit");
1452 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1455 SourceLocation getLParenLoc() const { return LParenLoc; }
1456 SourceLocation getRParenLoc() const { return RParenLoc; }
1458 /// \brief Determine the number of implicit array indices used while
1459 /// described an array member initialization.
1460 unsigned getNumArrayIndices() const {
1461 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1464 /// \brief Retrieve a particular array index variable used to
1465 /// describe an array member initialization.
1466 VarDecl *getArrayIndex(unsigned I) {
1467 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1468 return reinterpret_cast<VarDecl **>(this + 1)[I];
1470 const VarDecl *getArrayIndex(unsigned I) const {
1471 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1472 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1474 void setArrayIndex(unsigned I, VarDecl *Index) {
1475 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1476 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1479 Expr *getInit() const { return static_cast<Expr *>(Init); }
1482 /// CXXConstructorDecl - Represents a C++ constructor within a
1483 /// class. For example:
1488 /// explicit X(int); // represented by a CXXConstructorDecl.
1491 class CXXConstructorDecl : public CXXMethodDecl {
1492 /// IsExplicitSpecified - Whether this constructor declaration has the
1493 /// 'explicit' keyword specified.
1494 bool IsExplicitSpecified : 1;
1496 /// ImplicitlyDefined - Whether this constructor was implicitly
1497 /// defined by the compiler. When false, the constructor was defined
1498 /// by the user. In C++03, this flag will have the same value as
1499 /// Implicit. In C++0x, however, a constructor that is
1500 /// explicitly defaulted (i.e., defined with " = default") will have
1501 /// @c !Implicit && ImplicitlyDefined.
1502 bool ImplicitlyDefined : 1;
1504 /// Support for base and member initializers.
1505 /// CtorInitializers - The arguments used to initialize the base
1507 CXXCtorInitializer **CtorInitializers;
1508 unsigned NumCtorInitializers;
1510 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1511 const DeclarationNameInfo &NameInfo,
1512 QualType T, TypeSourceInfo *TInfo,
1513 bool isExplicitSpecified, bool isInline,
1514 bool isImplicitlyDeclared)
1515 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
1516 SC_None, isInline, SourceLocation()),
1517 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1518 CtorInitializers(0), NumCtorInitializers(0) {
1519 setImplicit(isImplicitlyDeclared);
1523 static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
1524 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1525 SourceLocation StartLoc,
1526 const DeclarationNameInfo &NameInfo,
1527 QualType T, TypeSourceInfo *TInfo,
1529 bool isInline, bool isImplicitlyDeclared);
1531 /// isExplicitSpecified - Whether this constructor declaration has the
1532 /// 'explicit' keyword specified.
1533 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1535 /// isExplicit - Whether this constructor was marked "explicit" or not.
1536 bool isExplicit() const {
1537 return cast<CXXConstructorDecl>(getFirstDeclaration())
1538 ->isExplicitSpecified();
1541 /// isImplicitlyDefined - Whether this constructor was implicitly
1542 /// defined. If false, then this constructor was defined by the
1543 /// user. This operation can only be invoked if the constructor has
1544 /// already been defined.
1545 bool isImplicitlyDefined() const {
1546 assert(isThisDeclarationADefinition() &&
1547 "Can only get the implicit-definition flag once the "
1548 "constructor has been defined");
1549 return ImplicitlyDefined;
1552 /// setImplicitlyDefined - Set whether this constructor was
1553 /// implicitly defined or not.
1554 void setImplicitlyDefined(bool ID) {
1555 assert(isThisDeclarationADefinition() &&
1556 "Can only set the implicit-definition flag once the constructor "
1557 "has been defined");
1558 ImplicitlyDefined = ID;
1561 /// init_iterator - Iterates through the member/base initializer list.
1562 typedef CXXCtorInitializer **init_iterator;
1564 /// init_const_iterator - Iterates through the memberbase initializer list.
1565 typedef CXXCtorInitializer * const * init_const_iterator;
1567 /// init_begin() - Retrieve an iterator to the first initializer.
1568 init_iterator init_begin() { return CtorInitializers; }
1569 /// begin() - Retrieve an iterator to the first initializer.
1570 init_const_iterator init_begin() const { return CtorInitializers; }
1572 /// init_end() - Retrieve an iterator past the last initializer.
1573 init_iterator init_end() {
1574 return CtorInitializers + NumCtorInitializers;
1576 /// end() - Retrieve an iterator past the last initializer.
1577 init_const_iterator init_end() const {
1578 return CtorInitializers + NumCtorInitializers;
1581 typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
1582 typedef std::reverse_iterator<init_const_iterator> init_const_reverse_iterator;
1584 init_reverse_iterator init_rbegin() {
1585 return init_reverse_iterator(init_end());
1587 init_const_reverse_iterator init_rbegin() const {
1588 return init_const_reverse_iterator(init_end());
1591 init_reverse_iterator init_rend() {
1592 return init_reverse_iterator(init_begin());
1594 init_const_reverse_iterator init_rend() const {
1595 return init_const_reverse_iterator(init_begin());
1598 /// getNumArgs - Determine the number of arguments used to
1599 /// initialize the member or base.
1600 unsigned getNumCtorInitializers() const {
1601 return NumCtorInitializers;
1604 void setNumCtorInitializers(unsigned numCtorInitializers) {
1605 NumCtorInitializers = numCtorInitializers;
1608 void setCtorInitializers(CXXCtorInitializer ** initializers) {
1609 CtorInitializers = initializers;
1612 /// isDelegatingConstructor - Whether this constructor is a
1613 /// delegating constructor
1614 bool isDelegatingConstructor() const {
1615 return (getNumCtorInitializers() == 1) &&
1616 CtorInitializers[0]->isDelegatingInitializer();
1619 /// getTargetConstructor - When this constructor delegates to
1620 /// another, retrieve the target
1621 CXXConstructorDecl *getTargetConstructor() const {
1622 if (isDelegatingConstructor())
1623 return CtorInitializers[0]->getTargetConstructor();
1628 /// isDefaultConstructor - Whether this constructor is a default
1629 /// constructor (C++ [class.ctor]p5), which can be used to
1630 /// default-initialize a class of this type.
1631 bool isDefaultConstructor() const;
1633 /// isCopyConstructor - Whether this constructor is a copy
1634 /// constructor (C++ [class.copy]p2, which can be used to copy the
1635 /// class. @p TypeQuals will be set to the qualifiers on the
1636 /// argument type. For example, @p TypeQuals would be set to @c
1637 /// QualType::Const for the following copy constructor:
1645 bool isCopyConstructor(unsigned &TypeQuals) const;
1647 /// isCopyConstructor - Whether this constructor is a copy
1648 /// constructor (C++ [class.copy]p2, which can be used to copy the
1650 bool isCopyConstructor() const {
1651 unsigned TypeQuals = 0;
1652 return isCopyConstructor(TypeQuals);
1655 /// \brief Determine whether this constructor is a move constructor
1656 /// (C++0x [class.copy]p3), which can be used to move values of the class.
1658 /// \param TypeQuals If this constructor is a move constructor, will be set
1659 /// to the type qualifiers on the referent of the first parameter's type.
1660 bool isMoveConstructor(unsigned &TypeQuals) const;
1662 /// \brief Determine whether this constructor is a move constructor
1663 /// (C++0x [class.copy]p3), which can be used to move values of the class.
1664 bool isMoveConstructor() const {
1665 unsigned TypeQuals = 0;
1666 return isMoveConstructor(TypeQuals);
1669 /// \brief Determine whether this is a copy or move constructor.
1671 /// \param TypeQuals Will be set to the type qualifiers on the reference
1672 /// parameter, if in fact this is a copy or move constructor.
1673 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
1675 /// \brief Determine whether this a copy or move constructor.
1676 bool isCopyOrMoveConstructor() const {
1678 return isCopyOrMoveConstructor(Quals);
1681 /// isConvertingConstructor - Whether this constructor is a
1682 /// converting constructor (C++ [class.conv.ctor]), which can be
1683 /// used for user-defined conversions.
1684 bool isConvertingConstructor(bool AllowExplicit) const;
1686 /// \brief Determine whether this is a member template specialization that
1687 /// would copy the object to itself. Such constructors are never used to copy
1689 bool isSpecializationCopyingObject() const;
1691 /// \brief Get the constructor that this inheriting constructor is based on.
1692 const CXXConstructorDecl *getInheritedConstructor() const;
1694 /// \brief Set the constructor that this inheriting constructor is based on.
1695 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
1697 // Implement isa/cast/dyncast/etc.
1698 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1699 static bool classof(const CXXConstructorDecl *D) { return true; }
1700 static bool classofKind(Kind K) { return K == CXXConstructor; }
1702 friend class ASTDeclReader;
1703 friend class ASTDeclWriter;
1706 /// CXXDestructorDecl - Represents a C++ destructor within a
1707 /// class. For example:
1712 /// ~X(); // represented by a CXXDestructorDecl.
1715 class CXXDestructorDecl : public CXXMethodDecl {
1716 /// ImplicitlyDefined - Whether this destructor was implicitly
1717 /// defined by the compiler. When false, the destructor was defined
1718 /// by the user. In C++03, this flag will have the same value as
1719 /// Implicit. In C++0x, however, a destructor that is
1720 /// explicitly defaulted (i.e., defined with " = default") will have
1721 /// @c !Implicit && ImplicitlyDefined.
1722 bool ImplicitlyDefined : 1;
1724 FunctionDecl *OperatorDelete;
1726 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1727 const DeclarationNameInfo &NameInfo,
1728 QualType T, TypeSourceInfo *TInfo,
1729 bool isInline, bool isImplicitlyDeclared)
1730 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
1731 SC_None, isInline, SourceLocation()),
1732 ImplicitlyDefined(false), OperatorDelete(0) {
1733 setImplicit(isImplicitlyDeclared);
1737 static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
1738 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1739 SourceLocation StartLoc,
1740 const DeclarationNameInfo &NameInfo,
1741 QualType T, TypeSourceInfo* TInfo,
1743 bool isImplicitlyDeclared);
1745 /// isImplicitlyDefined - Whether this destructor was implicitly
1746 /// defined. If false, then this destructor was defined by the
1747 /// user. This operation can only be invoked if the destructor has
1748 /// already been defined.
1749 bool isImplicitlyDefined() const {
1750 assert(isThisDeclarationADefinition() &&
1751 "Can only get the implicit-definition flag once the destructor has been defined");
1752 return ImplicitlyDefined;
1755 /// setImplicitlyDefined - Set whether this destructor was
1756 /// implicitly defined or not.
1757 void setImplicitlyDefined(bool ID) {
1758 assert(isThisDeclarationADefinition() &&
1759 "Can only set the implicit-definition flag once the destructor has been defined");
1760 ImplicitlyDefined = ID;
1763 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1764 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1766 // Implement isa/cast/dyncast/etc.
1767 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1768 static bool classof(const CXXDestructorDecl *D) { return true; }
1769 static bool classofKind(Kind K) { return K == CXXDestructor; }
1771 friend class ASTDeclReader;
1772 friend class ASTDeclWriter;
1775 /// CXXConversionDecl - Represents a C++ conversion function within a
1776 /// class. For example:
1781 /// operator bool();
1784 class CXXConversionDecl : public CXXMethodDecl {
1785 /// IsExplicitSpecified - Whether this conversion function declaration is
1786 /// marked "explicit", meaning that it can only be applied when the user
1787 /// explicitly wrote a cast. This is a C++0x feature.
1788 bool IsExplicitSpecified : 1;
1790 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1791 const DeclarationNameInfo &NameInfo,
1792 QualType T, TypeSourceInfo *TInfo,
1793 bool isInline, bool isExplicitSpecified,
1794 SourceLocation EndLocation)
1795 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
1796 SC_None, isInline, EndLocation),
1797 IsExplicitSpecified(isExplicitSpecified) { }
1800 static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
1801 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1802 SourceLocation StartLoc,
1803 const DeclarationNameInfo &NameInfo,
1804 QualType T, TypeSourceInfo *TInfo,
1805 bool isInline, bool isExplicit,
1806 SourceLocation EndLocation);
1808 /// IsExplicitSpecified - Whether this conversion function declaration is
1809 /// marked "explicit", meaning that it can only be applied when the user
1810 /// explicitly wrote a cast. This is a C++0x feature.
1811 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1813 /// isExplicit - Whether this is an explicit conversion operator
1814 /// (C++0x only). Explicit conversion operators are only considered
1815 /// when the user has explicitly written a cast.
1816 bool isExplicit() const {
1817 return cast<CXXConversionDecl>(getFirstDeclaration())
1818 ->isExplicitSpecified();
1821 /// getConversionType - Returns the type that this conversion
1822 /// function is converting to.
1823 QualType getConversionType() const {
1824 return getType()->getAs<FunctionType>()->getResultType();
1827 // Implement isa/cast/dyncast/etc.
1828 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1829 static bool classof(const CXXConversionDecl *D) { return true; }
1830 static bool classofKind(Kind K) { return K == CXXConversion; }
1832 friend class ASTDeclReader;
1833 friend class ASTDeclWriter;
1836 /// LinkageSpecDecl - This represents a linkage specification. For example:
1837 /// extern "C" void foo();
1839 class LinkageSpecDecl : public Decl, public DeclContext {
1841 /// LanguageIDs - Used to represent the language in a linkage
1842 /// specification. The values are part of the serialization abi for
1843 /// ASTs and cannot be changed without altering that abi. To help
1844 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1845 /// from the dwarf standard.
1847 lang_c = /* DW_LANG_C */ 0x0002,
1848 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
1851 /// Language - The language for this linkage specification.
1852 LanguageIDs Language;
1853 /// ExternLoc - The source location for the extern keyword.
1854 SourceLocation ExternLoc;
1855 /// RBraceLoc - The source location for the right brace (if valid).
1856 SourceLocation RBraceLoc;
1858 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
1859 SourceLocation LangLoc, LanguageIDs lang,
1860 SourceLocation RBLoc)
1861 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
1862 Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
1865 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1866 SourceLocation ExternLoc,
1867 SourceLocation LangLoc, LanguageIDs Lang,
1868 SourceLocation RBraceLoc = SourceLocation());
1870 /// \brief Return the language specified by this linkage specification.
1871 LanguageIDs getLanguage() const { return Language; }
1872 /// \brief Set the language specified by this linkage specification.
1873 void setLanguage(LanguageIDs L) { Language = L; }
1875 /// \brief Determines whether this linkage specification had braces in
1876 /// its syntactic form.
1877 bool hasBraces() const { return RBraceLoc.isValid(); }
1879 SourceLocation getExternLoc() const { return ExternLoc; }
1880 SourceLocation getRBraceLoc() const { return RBraceLoc; }
1881 void setExternLoc(SourceLocation L) { ExternLoc = L; }
1882 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
1884 SourceLocation getLocEnd() const {
1886 return getRBraceLoc();
1887 // No braces: get the end location of the (only) declaration in context
1889 return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
1892 SourceRange getSourceRange() const {
1893 return SourceRange(ExternLoc, getLocEnd());
1896 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1897 static bool classof(const LinkageSpecDecl *D) { return true; }
1898 static bool classofKind(Kind K) { return K == LinkageSpec; }
1899 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1900 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1902 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1903 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1907 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
1909 /// using namespace std;
1911 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1912 // artificial name, for all using-directives in order to store
1913 // them in DeclContext effectively.
1914 class UsingDirectiveDecl : public NamedDecl {
1915 /// \brief The location of the "using" keyword.
1916 SourceLocation UsingLoc;
1918 /// SourceLocation - Location of 'namespace' token.
1919 SourceLocation NamespaceLoc;
1921 /// \brief The nested-name-specifier that precedes the namespace.
1922 NestedNameSpecifierLoc QualifierLoc;
1924 /// NominatedNamespace - Namespace nominated by using-directive.
1925 NamedDecl *NominatedNamespace;
1927 /// Enclosing context containing both using-directive and nominated
1929 DeclContext *CommonAncestor;
1931 /// getUsingDirectiveName - Returns special DeclarationName used by
1932 /// using-directives. This is only used by DeclContext for storing
1933 /// UsingDirectiveDecls in its lookup structure.
1934 static DeclarationName getName() {
1935 return DeclarationName::getUsingDirectiveName();
1938 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
1939 SourceLocation NamespcLoc,
1940 NestedNameSpecifierLoc QualifierLoc,
1941 SourceLocation IdentLoc,
1942 NamedDecl *Nominated,
1943 DeclContext *CommonAncestor)
1944 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
1945 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
1946 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
1949 /// \brief Retrieve the nested-name-specifier that qualifies the
1950 /// name of the namespace, with source-location information.
1951 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1953 /// \brief Retrieve the nested-name-specifier that qualifies the
1954 /// name of the namespace.
1955 NestedNameSpecifier *getQualifier() const {
1956 return QualifierLoc.getNestedNameSpecifier();
1959 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1960 const NamedDecl *getNominatedNamespaceAsWritten() const {
1961 return NominatedNamespace;
1964 /// getNominatedNamespace - Returns namespace nominated by using-directive.
1965 NamespaceDecl *getNominatedNamespace();
1967 const NamespaceDecl *getNominatedNamespace() const {
1968 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1971 /// \brief Returns the common ancestor context of this using-directive and
1972 /// its nominated namespace.
1973 DeclContext *getCommonAncestor() { return CommonAncestor; }
1974 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1976 /// \brief Return the location of the "using" keyword.
1977 SourceLocation getUsingLoc() const { return UsingLoc; }
1979 // FIXME: Could omit 'Key' in name.
1980 /// getNamespaceKeyLocation - Returns location of namespace keyword.
1981 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1983 /// getIdentLocation - Returns location of identifier.
1984 SourceLocation getIdentLocation() const { return getLocation(); }
1986 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1987 SourceLocation UsingLoc,
1988 SourceLocation NamespaceLoc,
1989 NestedNameSpecifierLoc QualifierLoc,
1990 SourceLocation IdentLoc,
1991 NamedDecl *Nominated,
1992 DeclContext *CommonAncestor);
1994 SourceRange getSourceRange() const {
1995 return SourceRange(UsingLoc, getLocation());
1998 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1999 static bool classof(const UsingDirectiveDecl *D) { return true; }
2000 static bool classofKind(Kind K) { return K == UsingDirective; }
2002 // Friend for getUsingDirectiveName.
2003 friend class DeclContext;
2005 friend class ASTDeclReader;
2008 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
2011 /// namespace Foo = Bar;
2013 class NamespaceAliasDecl : public NamedDecl {
2014 /// \brief The location of the "namespace" keyword.
2015 SourceLocation NamespaceLoc;
2017 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2018 SourceLocation IdentLoc;
2020 /// \brief The nested-name-specifier that precedes the namespace.
2021 NestedNameSpecifierLoc QualifierLoc;
2023 /// Namespace - The Decl that this alias points to. Can either be a
2024 /// NamespaceDecl or a NamespaceAliasDecl.
2025 NamedDecl *Namespace;
2027 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2028 SourceLocation AliasLoc, IdentifierInfo *Alias,
2029 NestedNameSpecifierLoc QualifierLoc,
2030 SourceLocation IdentLoc, NamedDecl *Namespace)
2031 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2032 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2033 QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2035 friend class ASTDeclReader;
2038 /// \brief Retrieve the nested-name-specifier that qualifies the
2039 /// name of the namespace, with source-location information.
2040 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2042 /// \brief Retrieve the nested-name-specifier that qualifies the
2043 /// name of the namespace.
2044 NestedNameSpecifier *getQualifier() const {
2045 return QualifierLoc.getNestedNameSpecifier();
2048 /// \brief Retrieve the namespace declaration aliased by this directive.
2049 NamespaceDecl *getNamespace() {
2050 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2051 return AD->getNamespace();
2053 return cast<NamespaceDecl>(Namespace);
2056 const NamespaceDecl *getNamespace() const {
2057 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2060 /// Returns the location of the alias name, i.e. 'foo' in
2061 /// "namespace foo = ns::bar;".
2062 SourceLocation getAliasLoc() const { return getLocation(); }
2064 /// Returns the location of the 'namespace' keyword.
2065 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2067 /// Returns the location of the identifier in the named namespace.
2068 SourceLocation getTargetNameLoc() const { return IdentLoc; }
2070 /// \brief Retrieve the namespace that this alias refers to, which
2071 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2072 NamedDecl *getAliasedNamespace() const { return Namespace; }
2074 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2075 SourceLocation NamespaceLoc,
2076 SourceLocation AliasLoc,
2077 IdentifierInfo *Alias,
2078 NestedNameSpecifierLoc QualifierLoc,
2079 SourceLocation IdentLoc,
2080 NamedDecl *Namespace);
2082 virtual SourceRange getSourceRange() const {
2083 return SourceRange(NamespaceLoc, IdentLoc);
2086 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2087 static bool classof(const NamespaceAliasDecl *D) { return true; }
2088 static bool classofKind(Kind K) { return K == NamespaceAlias; }
2091 /// UsingShadowDecl - Represents a shadow declaration introduced into
2092 /// a scope by a (resolved) using declaration. For example,
2098 /// using A::foo(); // <- a UsingDecl
2099 /// // Also creates a UsingShadowDecl for A::foo in B
2102 class UsingShadowDecl : public NamedDecl {
2103 /// The referenced declaration.
2104 NamedDecl *Underlying;
2106 /// \brief The using declaration which introduced this decl or the next using
2107 /// shadow declaration contained in the aforementioned using declaration.
2108 NamedDecl *UsingOrNextShadow;
2109 friend class UsingDecl;
2111 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2113 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2115 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2117 setDeclName(Target->getDeclName());
2118 IdentifierNamespace = Target->getIdentifierNamespace();
2124 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2125 SourceLocation Loc, UsingDecl *Using,
2126 NamedDecl *Target) {
2127 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2130 /// \brief Gets the underlying declaration which has been brought into the
2132 NamedDecl *getTargetDecl() const { return Underlying; }
2134 /// \brief Sets the underlying declaration which has been brought into the
2136 void setTargetDecl(NamedDecl* ND) {
2137 assert(ND && "Target decl is null!");
2139 IdentifierNamespace = ND->getIdentifierNamespace();
2142 /// \brief Gets the using declaration to which this declaration is tied.
2143 UsingDecl *getUsingDecl() const;
2145 /// \brief The next using shadow declaration contained in the shadow decl
2146 /// chain of the using declaration which introduced this decl.
2147 UsingShadowDecl *getNextUsingShadowDecl() const {
2148 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2151 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2152 static bool classof(const UsingShadowDecl *D) { return true; }
2153 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2155 friend class ASTDeclReader;
2156 friend class ASTDeclWriter;
2159 /// UsingDecl - Represents a C++ using-declaration. For example:
2160 /// using someNameSpace::someIdentifier;
2161 class UsingDecl : public NamedDecl {
2162 /// \brief The source location of the "using" location itself.
2163 SourceLocation UsingLocation;
2165 /// \brief The nested-name-specifier that precedes the name.
2166 NestedNameSpecifierLoc QualifierLoc;
2168 /// DNLoc - Provides source/type location info for the
2169 /// declaration name embedded in the ValueDecl base class.
2170 DeclarationNameLoc DNLoc;
2172 /// \brief The first shadow declaration of the shadow decl chain associated
2173 /// with this using declaration.
2174 UsingShadowDecl *FirstUsingShadow;
2176 // \brief Has 'typename' keyword.
2179 UsingDecl(DeclContext *DC, SourceLocation UL,
2180 NestedNameSpecifierLoc QualifierLoc,
2181 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2182 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2183 UsingLocation(UL), QualifierLoc(QualifierLoc),
2184 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg) {
2188 /// \brief Returns the source location of the "using" keyword.
2189 SourceLocation getUsingLocation() const { return UsingLocation; }
2191 /// \brief Set the source location of the 'using' keyword.
2192 void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2194 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2195 /// with source-location information.
2196 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2198 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2199 NestedNameSpecifier *getQualifier() const {
2200 return QualifierLoc.getNestedNameSpecifier();
2203 DeclarationNameInfo getNameInfo() const {
2204 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2207 /// \brief Return true if the using declaration has 'typename'.
2208 bool isTypeName() const { return IsTypeName; }
2210 /// \brief Sets whether the using declaration has 'typename'.
2211 void setTypeName(bool TN) { IsTypeName = TN; }
2213 /// \brief Iterates through the using shadow declarations assosiated with
2214 /// this using declaration.
2215 class shadow_iterator {
2216 /// \brief The current using shadow declaration.
2217 UsingShadowDecl *Current;
2220 typedef UsingShadowDecl* value_type;
2221 typedef UsingShadowDecl* reference;
2222 typedef UsingShadowDecl* pointer;
2223 typedef std::forward_iterator_tag iterator_category;
2224 typedef std::ptrdiff_t difference_type;
2226 shadow_iterator() : Current(0) { }
2227 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2229 reference operator*() const { return Current; }
2230 pointer operator->() const { return Current; }
2232 shadow_iterator& operator++() {
2233 Current = Current->getNextUsingShadowDecl();
2237 shadow_iterator operator++(int) {
2238 shadow_iterator tmp(*this);
2243 friend bool operator==(shadow_iterator x, shadow_iterator y) {
2244 return x.Current == y.Current;
2246 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2247 return x.Current != y.Current;
2251 shadow_iterator shadow_begin() const {
2252 return shadow_iterator(FirstUsingShadow);
2254 shadow_iterator shadow_end() const { return shadow_iterator(); }
2256 /// \brief Return the number of shadowed declarations associated with this
2257 /// using declaration.
2258 unsigned shadow_size() const {
2259 return std::distance(shadow_begin(), shadow_end());
2262 void addShadowDecl(UsingShadowDecl *S);
2263 void removeShadowDecl(UsingShadowDecl *S);
2265 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2266 SourceLocation UsingL,
2267 NestedNameSpecifierLoc QualifierLoc,
2268 const DeclarationNameInfo &NameInfo,
2269 bool IsTypeNameArg);
2271 SourceRange getSourceRange() const {
2272 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2275 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2276 static bool classof(const UsingDecl *D) { return true; }
2277 static bool classofKind(Kind K) { return K == Using; }
2279 friend class ASTDeclReader;
2280 friend class ASTDeclWriter;
2283 /// UnresolvedUsingValueDecl - Represents a dependent using
2284 /// declaration which was not marked with 'typename'. Unlike
2285 /// non-dependent using declarations, these *only* bring through
2286 /// non-types; otherwise they would break two-phase lookup.
2288 /// template <class T> class A : public Base<T> {
2289 /// using Base<T>::foo;
2291 class UnresolvedUsingValueDecl : public ValueDecl {
2292 /// \brief The source location of the 'using' keyword
2293 SourceLocation UsingLocation;
2295 /// \brief The nested-name-specifier that precedes the name.
2296 NestedNameSpecifierLoc QualifierLoc;
2298 /// DNLoc - Provides source/type location info for the
2299 /// declaration name embedded in the ValueDecl base class.
2300 DeclarationNameLoc DNLoc;
2302 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2303 SourceLocation UsingLoc,
2304 NestedNameSpecifierLoc QualifierLoc,
2305 const DeclarationNameInfo &NameInfo)
2306 : ValueDecl(UnresolvedUsingValue, DC,
2307 NameInfo.getLoc(), NameInfo.getName(), Ty),
2308 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2309 DNLoc(NameInfo.getInfo())
2313 /// \brief Returns the source location of the 'using' keyword.
2314 SourceLocation getUsingLoc() const { return UsingLocation; }
2316 /// \brief Set the source location of the 'using' keyword.
2317 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2319 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2320 /// with source-location information.
2321 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2323 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2324 NestedNameSpecifier *getQualifier() const {
2325 return QualifierLoc.getNestedNameSpecifier();
2328 DeclarationNameInfo getNameInfo() const {
2329 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2332 static UnresolvedUsingValueDecl *
2333 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2334 NestedNameSpecifierLoc QualifierLoc,
2335 const DeclarationNameInfo &NameInfo);
2337 SourceRange getSourceRange() const {
2338 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2341 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2342 static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2343 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2345 friend class ASTDeclReader;
2346 friend class ASTDeclWriter;
2349 /// UnresolvedUsingTypenameDecl - Represents a dependent using
2350 /// declaration which was marked with 'typename'.
2352 /// template <class T> class A : public Base<T> {
2353 /// using typename Base<T>::foo;
2356 /// The type associated with a unresolved using typename decl is
2357 /// currently always a typename type.
2358 class UnresolvedUsingTypenameDecl : public TypeDecl {
2359 /// \brief The source location of the 'using' keyword
2360 SourceLocation UsingLocation;
2362 /// \brief The source location of the 'typename' keyword
2363 SourceLocation TypenameLocation;
2365 /// \brief The nested-name-specifier that precedes the name.
2366 NestedNameSpecifierLoc QualifierLoc;
2368 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2369 SourceLocation TypenameLoc,
2370 NestedNameSpecifierLoc QualifierLoc,
2371 SourceLocation TargetNameLoc,
2372 IdentifierInfo *TargetName)
2373 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2375 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2377 friend class ASTDeclReader;
2380 /// \brief Returns the source location of the 'using' keyword.
2381 SourceLocation getUsingLoc() const { return getLocStart(); }
2383 /// \brief Returns the source location of the 'typename' keyword.
2384 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2386 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2387 /// with source-location information.
2388 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2390 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2391 NestedNameSpecifier *getQualifier() const {
2392 return QualifierLoc.getNestedNameSpecifier();
2395 static UnresolvedUsingTypenameDecl *
2396 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2397 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2398 SourceLocation TargetNameLoc, DeclarationName TargetName);
2400 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2401 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2402 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2405 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
2406 class StaticAssertDecl : public Decl {
2408 StringLiteral *Message;
2409 SourceLocation RParenLoc;
2411 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2412 Expr *assertexpr, StringLiteral *message,
2413 SourceLocation RParenLoc)
2414 : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr),
2415 Message(message), RParenLoc(RParenLoc) { }
2418 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2419 SourceLocation StaticAssertLoc,
2420 Expr *AssertExpr, StringLiteral *Message,
2421 SourceLocation RParenLoc);
2423 Expr *getAssertExpr() { return AssertExpr; }
2424 const Expr *getAssertExpr() const { return AssertExpr; }
2426 StringLiteral *getMessage() { return Message; }
2427 const StringLiteral *getMessage() const { return Message; }
2429 SourceLocation getRParenLoc() const { return RParenLoc; }
2430 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2432 SourceRange getSourceRange() const {
2433 return SourceRange(getLocation(), getRParenLoc());
2436 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2437 static bool classof(StaticAssertDecl *D) { return true; }
2438 static bool classofKind(Kind K) { return K == StaticAssert; }
2440 friend class ASTDeclReader;
2443 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
2444 /// into a diagnostic with <<.
2445 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2446 AccessSpecifier AS);
2448 } // end namespace clang