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 /// HasTrivialConstructor - True when this class has a trivial constructor.
311 /// C++ [class.ctor]p5. A constructor is trivial if it is an
312 /// implicitly-declared default constructor and if:
313 /// * its class has no virtual functions and no virtual base classes, and
314 /// * all the direct base classes of its class have trivial constructors, and
315 /// * for all the nonstatic data members of its class that are of class type
316 /// (or array thereof), each such class has a trivial constructor.
317 bool HasTrivialConstructor
: 1;
319 /// HasTrivialCopyConstructor - True when this class has a trivial copy
322 /// C++ [class.copy]p6. A copy constructor for class X is trivial
323 /// if it is implicitly declared and if
324 /// * class X has no virtual functions and no virtual base classes, and
325 /// * each direct base class of X has a trivial copy constructor, and
326 /// * for all the nonstatic data members of X that are of class type (or
327 /// array thereof), each such class type has a trivial copy constructor;
328 /// otherwise the copy constructor is non-trivial.
329 bool HasTrivialCopyConstructor
: 1;
331 /// HasTrivialCopyAssignment - True when this class has a trivial copy
332 /// assignment operator.
334 /// C++ [class.copy]p11. A copy assignment operator for class X is
335 /// trivial if it is implicitly declared and if
336 /// * class X has no virtual functions and no virtual base classes, and
337 /// * each direct base class of X has a trivial copy assignment operator, and
338 /// * for all the nonstatic data members of X that are of class type (or
339 /// array thereof), each such class type has a trivial copy assignment
341 /// otherwise the copy assignment operator is non-trivial.
342 bool HasTrivialCopyAssignment
: 1;
344 /// HasTrivialDestructor - True when this class has a trivial destructor.
346 /// C++ [class.dtor]p3. A destructor is trivial if it is an
347 /// implicitly-declared destructor and if:
348 /// * all of the direct base classes of its class have trivial destructors
350 /// * for all of the non-static data members of its class that are of class
351 /// type (or array thereof), each such class has a trivial destructor.
352 bool HasTrivialDestructor
: 1;
354 /// ComputedVisibleConversions - True when visible conversion functions are
355 /// already computed and are available.
356 bool ComputedVisibleConversions
: 1;
358 /// \brief Whether we have already declared the default constructor or
359 /// do not need to have one declared.
360 bool DeclaredDefaultConstructor
: 1;
362 /// \brief Whether we have already declared the copy constructor.
363 bool DeclaredCopyConstructor
: 1;
365 /// \brief Whether we have already declared the copy-assignment operator.
366 bool DeclaredCopyAssignment
: 1;
368 /// \brief Whether we have already declared a destructor within the class.
369 bool DeclaredDestructor
: 1;
371 /// NumBases - The number of base class specifiers in Bases.
374 /// NumVBases - The number of virtual base class specifiers in VBases.
377 /// Bases - Base classes of this class.
378 /// FIXME: This is wasted space for a union.
379 LazyCXXBaseSpecifiersPtr Bases
;
381 /// VBases - direct and indirect virtual base classes of this class.
382 LazyCXXBaseSpecifiersPtr VBases
;
384 /// Conversions - Overload set containing the conversion functions
385 /// of this C++ class (but not its inherited conversion
386 /// functions). Each of the entries in this overload set is a
387 /// CXXConversionDecl.
388 UnresolvedSet
<4> Conversions
;
390 /// VisibleConversions - Overload set containing the conversion
391 /// functions of this C++ class and all those inherited conversion
392 /// functions that are visible in this class. Each of the entries
393 /// in this overload set is a CXXConversionDecl or a
394 /// FunctionTemplateDecl.
395 UnresolvedSet
<4> VisibleConversions
;
397 /// Definition - The declaration which defines this record.
398 CXXRecordDecl
*Definition
;
400 /// FirstFriend - The first friend declaration in this class, or
401 /// null if there aren't any. This is actually currently stored
402 /// in reverse order.
403 FriendDecl
*FirstFriend
;
405 /// \brief Retrieve the set of direct base classes.
406 CXXBaseSpecifier
*getBases() const {
407 return Bases
.get(Definition
->getASTContext().getExternalSource());
410 /// \brief Retrieve the set of virtual base classes.
411 CXXBaseSpecifier
*getVBases() const {
412 return VBases
.get(Definition
->getASTContext().getExternalSource());
416 struct DefinitionData
&data() {
417 assert(DefinitionData
&& "queried property of class with no definition");
418 return *DefinitionData
;
421 const struct DefinitionData
&data() const {
422 assert(DefinitionData
&& "queried property of class with no definition");
423 return *DefinitionData
;
426 /// \brief The template or declaration that this declaration
427 /// describes or was instantiated from, respectively.
429 /// For non-templates, this value will be NULL. For record
430 /// declarations that describe a class template, this will be a
431 /// pointer to a ClassTemplateDecl. For member
432 /// classes of class template specializations, this will be the
433 /// MemberSpecializationInfo referring to the member class that was
434 /// instantiated or specialized.
435 llvm::PointerUnion
<ClassTemplateDecl
*, MemberSpecializationInfo
*>
436 TemplateOrInstantiation
;
438 friend class DeclContext
;
440 /// \brief Notify the class that member has been added.
442 /// This routine helps maintain information about the class based on which
443 /// members have been added. It will be invoked by DeclContext::addDecl()
444 /// whenever a member is added to this record.
445 void addedMember(Decl
*D
);
447 void markedVirtualFunctionPure();
448 friend void FunctionDecl::setPure(bool);
451 CXXRecordDecl(Kind K
, TagKind TK
, DeclContext
*DC
,
452 SourceLocation L
, IdentifierInfo
*Id
,
453 CXXRecordDecl
*PrevDecl
,
454 SourceLocation TKL
= SourceLocation());
457 /// base_class_iterator - Iterator that traverses the base classes
459 typedef CXXBaseSpecifier
* base_class_iterator
;
461 /// base_class_const_iterator - Iterator that traverses the base
462 /// classes of a class.
463 typedef const CXXBaseSpecifier
* base_class_const_iterator
;
465 /// reverse_base_class_iterator = Iterator that traverses the base classes
466 /// of a class in reverse order.
467 typedef std::reverse_iterator
<base_class_iterator
>
468 reverse_base_class_iterator
;
470 /// reverse_base_class_iterator = Iterator that traverses the base classes
471 /// of a class in reverse order.
472 typedef std::reverse_iterator
<base_class_const_iterator
>
473 reverse_base_class_const_iterator
;
475 CXXRecordDecl
*getCanonicalDecl() {
476 return cast
<CXXRecordDecl
>(RecordDecl::getCanonicalDecl());
478 const CXXRecordDecl
*getCanonicalDecl() const {
479 return cast
<CXXRecordDecl
>(RecordDecl::getCanonicalDecl());
482 const CXXRecordDecl
*getPreviousDeclaration() const {
483 return cast_or_null
<CXXRecordDecl
>(RecordDecl::getPreviousDeclaration());
485 CXXRecordDecl
*getPreviousDeclaration() {
486 return cast_or_null
<CXXRecordDecl
>(RecordDecl::getPreviousDeclaration());
489 CXXRecordDecl
*getDefinition() const {
490 if (!DefinitionData
) return 0;
491 return data().Definition
;
494 bool hasDefinition() const { return DefinitionData
!= 0; }
496 static CXXRecordDecl
*Create(const ASTContext
&C
, TagKind TK
, DeclContext
*DC
,
497 SourceLocation L
, IdentifierInfo
*Id
,
498 SourceLocation TKL
= SourceLocation(),
499 CXXRecordDecl
* PrevDecl
=0,
500 bool DelayTypeCreation
= false);
501 static CXXRecordDecl
*Create(const ASTContext
&C
, EmptyShell Empty
);
503 bool isDynamicClass() const {
504 return data().Polymorphic
|| data().NumVBases
!= 0;
507 /// setBases - Sets the base classes of this struct or class.
508 void setBases(CXXBaseSpecifier
const * const *Bases
, unsigned NumBases
);
510 /// getNumBases - Retrieves the number of base classes of this
512 unsigned getNumBases() const { return data().NumBases
; }
514 base_class_iterator
bases_begin() { return data().getBases(); }
515 base_class_const_iterator
bases_begin() const { return data().getBases(); }
516 base_class_iterator
bases_end() { return bases_begin() + data().NumBases
; }
517 base_class_const_iterator
bases_end() const {
518 return bases_begin() + data().NumBases
;
520 reverse_base_class_iterator
bases_rbegin() {
521 return reverse_base_class_iterator(bases_end());
523 reverse_base_class_const_iterator
bases_rbegin() const {
524 return reverse_base_class_const_iterator(bases_end());
526 reverse_base_class_iterator
bases_rend() {
527 return reverse_base_class_iterator(bases_begin());
529 reverse_base_class_const_iterator
bases_rend() const {
530 return reverse_base_class_const_iterator(bases_begin());
533 /// getNumVBases - Retrieves the number of virtual base classes of this
535 unsigned getNumVBases() const { return data().NumVBases
; }
537 base_class_iterator
vbases_begin() { return data().getVBases(); }
538 base_class_const_iterator
vbases_begin() const { return data().getVBases(); }
539 base_class_iterator
vbases_end() { return vbases_begin() + data().NumVBases
; }
540 base_class_const_iterator
vbases_end() const {
541 return vbases_begin() + data().NumVBases
;
543 reverse_base_class_iterator
vbases_rbegin() {
544 return reverse_base_class_iterator(vbases_end());
546 reverse_base_class_const_iterator
vbases_rbegin() const {
547 return reverse_base_class_const_iterator(vbases_end());
549 reverse_base_class_iterator
vbases_rend() {
550 return reverse_base_class_iterator(vbases_begin());
552 reverse_base_class_const_iterator
vbases_rend() const {
553 return reverse_base_class_const_iterator(vbases_begin());
556 /// \brief Determine whether this class has any dependent base classes.
557 bool hasAnyDependentBases() const;
559 /// Iterator access to method members. The method iterator visits
560 /// all method members of the class, including non-instance methods,
561 /// special methods, etc.
562 typedef specific_decl_iterator
<CXXMethodDecl
> method_iterator
;
564 /// method_begin - Method begin iterator. Iterates in the order the methods
566 method_iterator
method_begin() const {
567 return method_iterator(decls_begin());
569 /// method_end - Method end iterator.
570 method_iterator
method_end() const {
571 return method_iterator(decls_end());
574 /// Iterator access to constructor members.
575 typedef specific_decl_iterator
<CXXConstructorDecl
> ctor_iterator
;
577 ctor_iterator
ctor_begin() const {
578 return ctor_iterator(decls_begin());
580 ctor_iterator
ctor_end() const {
581 return ctor_iterator(decls_end());
584 /// An iterator over friend declarations. All of these are defined
586 class friend_iterator
;
587 friend_iterator
friend_begin() const;
588 friend_iterator
friend_end() const;
589 void pushFriendDecl(FriendDecl
*FD
);
591 /// Determines whether this record has any friends.
592 bool hasFriends() const {
593 return data().FirstFriend
!= 0;
596 /// \brief Determine whether this class has had its default constructor
597 /// declared implicitly or does not need one declared implicitly.
599 /// This value is used for lazy creation of default constructors.
600 bool hasDeclaredDefaultConstructor() const {
601 return data().DeclaredDefaultConstructor
;
604 /// hasConstCopyConstructor - Determines whether this class has a
605 /// copy constructor that accepts a const-qualified argument.
606 bool hasConstCopyConstructor(const ASTContext
&Context
) const;
608 /// getCopyConstructor - Returns the copy constructor for this class
609 CXXConstructorDecl
*getCopyConstructor(const ASTContext
&Context
,
610 unsigned TypeQuals
) const;
612 /// \brief Retrieve the copy-assignment operator for this class, if available.
614 /// This routine attempts to find the copy-assignment operator for this
615 /// class, using a simplistic form of overload resolution.
617 /// \param ArgIsConst Whether the argument to the copy-assignment operator
618 /// is const-qualified.
620 /// \returns The copy-assignment operator that can be invoked, or NULL if
621 /// a unique copy-assignment operator could not be found.
622 CXXMethodDecl
*getCopyAssignmentOperator(bool ArgIsConst
) const;
624 /// hasUserDeclaredConstructor - Whether this class has any
625 /// user-declared constructors. When true, a default constructor
626 /// will not be implicitly declared.
627 bool hasUserDeclaredConstructor() const {
628 return data().UserDeclaredConstructor
;
631 /// hasUserDeclaredCopyConstructor - Whether this class has a
632 /// user-declared copy constructor. When false, a copy constructor
633 /// will be implicitly declared.
634 bool hasUserDeclaredCopyConstructor() const {
635 return data().UserDeclaredCopyConstructor
;
638 /// \brief Determine whether this class has had its copy constructor
639 /// declared, either via the user or via an implicit declaration.
641 /// This value is used for lazy creation of copy constructors.
642 bool hasDeclaredCopyConstructor() const {
643 return data().DeclaredCopyConstructor
;
646 /// hasUserDeclaredCopyAssignment - Whether this class has a
647 /// user-declared copy assignment operator. When false, a copy
648 /// assigment operator will be implicitly declared.
649 bool hasUserDeclaredCopyAssignment() const {
650 return data().UserDeclaredCopyAssignment
;
653 /// \brief Determine whether this class has had its copy assignment operator
654 /// declared, either via the user or via an implicit declaration.
656 /// This value is used for lazy creation of copy assignment operators.
657 bool hasDeclaredCopyAssignment() const {
658 return data().DeclaredCopyAssignment
;
661 /// hasUserDeclaredDestructor - Whether this class has a
662 /// user-declared destructor. When false, a destructor will be
663 /// implicitly declared.
664 bool hasUserDeclaredDestructor() const {
665 return data().UserDeclaredDestructor
;
668 /// \brief Determine whether this class has had its destructor declared,
669 /// either via the user or via an implicit declaration.
671 /// This value is used for lazy creation of destructors.
672 bool hasDeclaredDestructor() const { return data().DeclaredDestructor
; }
674 /// getConversions - Retrieve the overload set containing all of the
675 /// conversion functions in this class.
676 UnresolvedSetImpl
*getConversionFunctions() {
677 return &data().Conversions
;
679 const UnresolvedSetImpl
*getConversionFunctions() const {
680 return &data().Conversions
;
683 typedef UnresolvedSetImpl::iterator conversion_iterator
;
684 conversion_iterator
conversion_begin() const {
685 return getConversionFunctions()->begin();
687 conversion_iterator
conversion_end() const {
688 return getConversionFunctions()->end();
691 /// Removes a conversion function from this class. The conversion
692 /// function must currently be a member of this class. Furthermore,
693 /// this class must currently be in the process of being defined.
694 void removeConversion(const NamedDecl
*Old
);
696 /// getVisibleConversionFunctions - get all conversion functions visible
697 /// in current class; including conversion function templates.
698 const UnresolvedSetImpl
*getVisibleConversionFunctions();
700 /// isAggregate - Whether this class is an aggregate (C++
701 /// [dcl.init.aggr]), which is a class with no user-declared
702 /// constructors, no private or protected non-static data members,
703 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
704 bool isAggregate() const { return data().Aggregate
; }
706 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
707 /// that is an aggregate that has no non-static non-POD data members, no
708 /// reference data members, no user-defined copy assignment operator and no
709 /// user-defined destructor.
710 bool isPOD() const { return data().PlainOldData
; }
712 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
713 /// means it has a virtual function, virtual base, data member (other than
714 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
715 /// a check for union-ness.
716 bool isEmpty() const { return data().Empty
; }
718 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
719 /// which means that the class contains or inherits a virtual function.
720 bool isPolymorphic() const { return data().Polymorphic
; }
722 /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
723 /// which means that the class contains or inherits a pure virtual function.
724 bool isAbstract() const { return data().Abstract
; }
726 // hasTrivialConstructor - Whether this class has a trivial constructor
727 // (C++ [class.ctor]p5)
728 bool hasTrivialConstructor() const { return data().HasTrivialConstructor
; }
730 // hasTrivialCopyConstructor - Whether this class has a trivial copy
731 // constructor (C++ [class.copy]p6)
732 bool hasTrivialCopyConstructor() const {
733 return data().HasTrivialCopyConstructor
;
736 // hasTrivialCopyAssignment - Whether this class has a trivial copy
737 // assignment operator (C++ [class.copy]p11)
738 bool hasTrivialCopyAssignment() const {
739 return data().HasTrivialCopyAssignment
;
742 // hasTrivialDestructor - Whether this class has a trivial destructor
743 // (C++ [class.dtor]p3)
744 bool hasTrivialDestructor() const { return data().HasTrivialDestructor
; }
746 /// \brief If this record is an instantiation of a member class,
747 /// retrieves the member class from which it was instantiated.
749 /// This routine will return non-NULL for (non-templated) member
750 /// classes of class templates. For example, given:
753 /// template<typename T>
759 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
760 /// whose parent is the class template specialization X<int>. For
761 /// this declaration, getInstantiatedFromMemberClass() will return
762 /// the CXXRecordDecl X<T>::A. When a complete definition of
763 /// X<int>::A is required, it will be instantiated from the
764 /// declaration returned by getInstantiatedFromMemberClass().
765 CXXRecordDecl
*getInstantiatedFromMemberClass() const;
767 /// \brief If this class is an instantiation of a member class of a
768 /// class template specialization, retrieves the member specialization
770 MemberSpecializationInfo
*getMemberSpecializationInfo() const;
772 /// \brief Specify that this record is an instantiation of the
774 void setInstantiationOfMemberClass(CXXRecordDecl
*RD
,
775 TemplateSpecializationKind TSK
);
777 /// \brief Retrieves the class template that is described by this
778 /// class declaration.
780 /// Every class template is represented as a ClassTemplateDecl and a
781 /// CXXRecordDecl. The former contains template properties (such as
782 /// the template parameter lists) while the latter contains the
783 /// actual description of the template's
784 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
785 /// CXXRecordDecl that from a ClassTemplateDecl, while
786 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
788 ClassTemplateDecl
*getDescribedClassTemplate() const {
789 return TemplateOrInstantiation
.dyn_cast
<ClassTemplateDecl
*>();
792 void setDescribedClassTemplate(ClassTemplateDecl
*Template
) {
793 TemplateOrInstantiation
= Template
;
796 /// \brief Determine whether this particular class is a specialization or
797 /// instantiation of a class template or member class of a class template,
798 /// and how it was instantiated or specialized.
799 TemplateSpecializationKind
getTemplateSpecializationKind() const;
801 /// \brief Set the kind of specialization or template instantiation this is.
802 void setTemplateSpecializationKind(TemplateSpecializationKind TSK
);
804 /// getDestructor - Returns the destructor decl for this class.
805 CXXDestructorDecl
*getDestructor() const;
807 /// isLocalClass - If the class is a local class [class.local], returns
808 /// the enclosing function declaration.
809 const FunctionDecl
*isLocalClass() const {
810 if (const CXXRecordDecl
*RD
= dyn_cast
<CXXRecordDecl
>(getDeclContext()))
811 return RD
->isLocalClass();
813 return dyn_cast
<FunctionDecl
>(getDeclContext());
816 /// \brief Determine whether this class is derived from the class \p Base.
818 /// This routine only determines whether this class is derived from \p Base,
819 /// but does not account for factors that may make a Derived -> Base class
820 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
821 /// base class subobjects.
823 /// \param Base the base class we are searching for.
825 /// \returns true if this class is derived from Base, false otherwise.
826 bool isDerivedFrom(const CXXRecordDecl
*Base
) const;
828 /// \brief Determine whether this class is derived from the type \p Base.
830 /// This routine only determines whether this class is derived from \p Base,
831 /// but does not account for factors that may make a Derived -> Base class
832 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
833 /// base class subobjects.
835 /// \param Base the base class we are searching for.
837 /// \param Paths will contain the paths taken from the current class to the
838 /// given \p Base class.
840 /// \returns true if this class is derived from Base, false otherwise.
842 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
843 /// tangling input and output in \p Paths
844 bool isDerivedFrom(const CXXRecordDecl
*Base
, CXXBasePaths
&Paths
) const;
846 /// \brief Determine whether this class is virtually derived from
847 /// the class \p Base.
849 /// This routine only determines whether this class is virtually
850 /// derived from \p Base, but does not account for factors that may
851 /// make a Derived -> Base class ill-formed, such as
852 /// private/protected inheritance or multiple, ambiguous base class
855 /// \param Base the base class we are searching for.
857 /// \returns true if this class is virtually derived from Base,
859 bool isVirtuallyDerivedFrom(CXXRecordDecl
*Base
) const;
861 /// \brief Determine whether this class is provably not derived from
862 /// the type \p Base.
863 bool isProvablyNotDerivedFrom(const CXXRecordDecl
*Base
) const;
865 /// \brief Function type used by forallBases() as a callback.
867 /// \param Base the definition of the base class
869 /// \returns true if this base matched the search criteria
870 typedef bool ForallBasesCallback(const CXXRecordDecl
*BaseDefinition
,
873 /// \brief Determines if the given callback holds for all the direct
874 /// or indirect base classes of this type.
876 /// The class itself does not count as a base class. This routine
877 /// returns false if the class has non-computable base classes.
879 /// \param AllowShortCircuit if false, forces the callback to be called
880 /// for every base class, even if a dependent or non-matching base was
882 bool forallBases(ForallBasesCallback
*BaseMatches
, void *UserData
,
883 bool AllowShortCircuit
= true) const;
885 /// \brief Function type used by lookupInBases() to determine whether a
886 /// specific base class subobject matches the lookup criteria.
888 /// \param Specifier the base-class specifier that describes the inheritance
889 /// from the base class we are trying to match.
891 /// \param Path the current path, from the most-derived class down to the
892 /// base named by the \p Specifier.
894 /// \param UserData a single pointer to user-specified data, provided to
897 /// \returns true if this base matched the search criteria, false otherwise.
898 typedef bool BaseMatchesCallback(const CXXBaseSpecifier
*Specifier
,
902 /// \brief Look for entities within the base classes of this C++ class,
903 /// transitively searching all base class subobjects.
905 /// This routine uses the callback function \p BaseMatches to find base
906 /// classes meeting some search criteria, walking all base class subobjects
907 /// and populating the given \p Paths structure with the paths through the
908 /// inheritance hierarchy that resulted in a match. On a successful search,
909 /// the \p Paths structure can be queried to retrieve the matching paths and
910 /// to determine if there were any ambiguities.
912 /// \param BaseMatches callback function used to determine whether a given
913 /// base matches the user-defined search criteria.
915 /// \param UserData user data pointer that will be provided to \p BaseMatches.
917 /// \param Paths used to record the paths from this class to its base class
918 /// subobjects that match the search criteria.
920 /// \returns true if there exists any path from this class to a base class
921 /// subobject that matches the search criteria.
922 bool lookupInBases(BaseMatchesCallback
*BaseMatches
, void *UserData
,
923 CXXBasePaths
&Paths
) const;
925 /// \brief Base-class lookup callback that determines whether the given
926 /// base class specifier refers to a specific class declaration.
928 /// This callback can be used with \c lookupInBases() to determine whether
929 /// a given derived class has is a base class subobject of a particular type.
930 /// The user data pointer should refer to the canonical CXXRecordDecl of the
931 /// base class that we are searching for.
932 static bool FindBaseClass(const CXXBaseSpecifier
*Specifier
,
933 CXXBasePath
&Path
, void *BaseRecord
);
935 /// \brief Base-class lookup callback that determines whether the
936 /// given base class specifier refers to a specific class
937 /// declaration and describes virtual derivation.
939 /// This callback can be used with \c lookupInBases() to determine
940 /// whether a given derived class has is a virtual base class
941 /// subobject of a particular type. The user data pointer should
942 /// refer to the canonical CXXRecordDecl of the base class that we
943 /// are searching for.
944 static bool FindVirtualBaseClass(const CXXBaseSpecifier
*Specifier
,
945 CXXBasePath
&Path
, void *BaseRecord
);
947 /// \brief Base-class lookup callback that determines whether there exists
948 /// a tag with the given name.
950 /// This callback can be used with \c lookupInBases() to find tag members
951 /// of the given name within a C++ class hierarchy. The user data pointer
952 /// is an opaque \c DeclarationName pointer.
953 static bool FindTagMember(const CXXBaseSpecifier
*Specifier
,
954 CXXBasePath
&Path
, void *Name
);
956 /// \brief Base-class lookup callback that determines whether there exists
957 /// a member with the given name.
959 /// This callback can be used with \c lookupInBases() to find members
960 /// of the given name within a C++ class hierarchy. The user data pointer
961 /// is an opaque \c DeclarationName pointer.
962 static bool FindOrdinaryMember(const CXXBaseSpecifier
*Specifier
,
963 CXXBasePath
&Path
, void *Name
);
965 /// \brief Base-class lookup callback that determines whether there exists
966 /// a member with the given name that can be used in a nested-name-specifier.
968 /// This callback can be used with \c lookupInBases() to find membes of
969 /// the given name within a C++ class hierarchy that can occur within
970 /// nested-name-specifiers.
971 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier
*Specifier
,
975 /// \brief Retrieve the final overriders for each virtual member
976 /// function in the class hierarchy where this class is the
977 /// most-derived class in the class hierarchy.
978 void getFinalOverriders(CXXFinalOverriderMap
&FinaOverriders
) const;
980 /// \brief Get the indirect primary bases for this class.
981 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet
& Bases
) const;
983 /// viewInheritance - Renders and displays an inheritance diagram
984 /// for this C++ class and all of its base classes (transitively) using
986 void viewInheritance(ASTContext
& Context
) const;
988 /// MergeAccess - Calculates the access of a decl that is reached
990 static AccessSpecifier
MergeAccess(AccessSpecifier PathAccess
,
991 AccessSpecifier DeclAccess
) {
992 assert(DeclAccess
!= AS_none
);
993 if (DeclAccess
== AS_private
) return AS_none
;
994 return (PathAccess
> DeclAccess
? PathAccess
: DeclAccess
);
997 /// \brief Indicates that the definition of this class is now complete.
998 virtual void completeDefinition();
1000 /// \brief Indicates that the definition of this class is now complete,
1001 /// and provides a final overrider map to help determine
1003 /// \param FinalOverriders The final overrider map for this class, which can
1004 /// be provided as an optimization for abstract-class checking. If NULL,
1005 /// final overriders will be computed if they are needed to complete the
1007 void completeDefinition(CXXFinalOverriderMap
*FinalOverriders
);
1009 /// \brief Determine whether this class may end up being abstract, even though
1010 /// it is not yet known to be abstract.
1012 /// \returns true if this class is not known to be abstract but has any
1013 /// base classes that are abstract. In this case, \c completeDefinition()
1014 /// will need to compute final overriders to determine whether the class is
1015 /// actually abstract.
1016 bool mayBeAbstract() const;
1018 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1019 static bool classofKind(Kind K
) {
1020 return K
>= firstCXXRecord
&& K
<= lastCXXRecord
;
1022 static bool classof(const CXXRecordDecl
*D
) { return true; }
1023 static bool classof(const ClassTemplateSpecializationDecl
*D
) {
1027 friend class ASTDeclReader
;
1028 friend class ASTDeclWriter
;
1029 friend class ASTReader
;
1030 friend class ASTWriter
;
1033 /// CXXMethodDecl - Represents a static or instance method of a
1034 /// struct/union/class.
1035 class CXXMethodDecl
: public FunctionDecl
{
1037 CXXMethodDecl(Kind DK
, CXXRecordDecl
*RD
,
1038 const DeclarationNameInfo
&NameInfo
,
1039 QualType T
, TypeSourceInfo
*TInfo
,
1040 bool isStatic
, StorageClass SCAsWritten
, bool isInline
)
1041 : FunctionDecl(DK
, RD
, NameInfo
, T
, TInfo
, (isStatic
? SC_Static
: SC_None
),
1042 SCAsWritten
, isInline
) {}
1045 static CXXMethodDecl
*Create(ASTContext
&C
, CXXRecordDecl
*RD
,
1046 const DeclarationNameInfo
&NameInfo
,
1047 QualType T
, TypeSourceInfo
*TInfo
,
1048 bool isStatic
= false,
1049 StorageClass SCAsWritten
= SC_None
,
1050 bool isInline
= false);
1052 bool isStatic() const { return getStorageClass() == SC_Static
; }
1053 bool isInstance() const { return !isStatic(); }
1055 bool isVirtual() const {
1057 cast
<CXXMethodDecl
>(const_cast<CXXMethodDecl
*>(this)->getCanonicalDecl());
1059 if (CD
->isVirtualAsWritten())
1062 return (CD
->begin_overridden_methods() != CD
->end_overridden_methods());
1065 /// \brief Determine whether this is a usual deallocation function
1066 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1067 /// delete or delete[] operator with a particular signature.
1068 bool isUsualDeallocationFunction() const;
1070 /// \brief Determine whether this is a copy-assignment operator, regardless
1071 /// of whether it was declared implicitly or explicitly.
1072 bool isCopyAssignmentOperator() const;
1074 const CXXMethodDecl
*getCanonicalDecl() const {
1075 return cast
<CXXMethodDecl
>(FunctionDecl::getCanonicalDecl());
1077 CXXMethodDecl
*getCanonicalDecl() {
1078 return cast
<CXXMethodDecl
>(FunctionDecl::getCanonicalDecl());
1082 void addOverriddenMethod(const CXXMethodDecl
*MD
);
1084 typedef const CXXMethodDecl
** method_iterator
;
1086 method_iterator
begin_overridden_methods() const;
1087 method_iterator
end_overridden_methods() const;
1088 unsigned size_overridden_methods() const;
1090 /// getParent - Returns the parent of this method declaration, which
1091 /// is the class in which this method is defined.
1092 const CXXRecordDecl
*getParent() const {
1093 return cast
<CXXRecordDecl
>(FunctionDecl::getParent());
1096 /// getParent - Returns the parent of this method declaration, which
1097 /// is the class in which this method is defined.
1098 CXXRecordDecl
*getParent() {
1099 return const_cast<CXXRecordDecl
*>(
1100 cast
<CXXRecordDecl
>(FunctionDecl::getParent()));
1103 /// getThisType - Returns the type of 'this' pointer.
1104 /// Should only be called for instance methods.
1105 QualType
getThisType(ASTContext
&C
) const;
1107 unsigned getTypeQualifiers() const {
1108 return getType()->getAs
<FunctionProtoType
>()->getTypeQuals();
1111 /// \brief Retrieve the ref-qualifier associated with this method.
1113 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1114 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1121 RefQualifierKind
getRefQualifier() const {
1122 return getType()->getAs
<FunctionProtoType
>()->getRefQualifier();
1125 bool hasInlineBody() const;
1127 // Implement isa/cast/dyncast/etc.
1128 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1129 static bool classof(const CXXMethodDecl
*D
) { return true; }
1130 static bool classofKind(Kind K
) {
1131 return K
>= firstCXXMethod
&& K
<= lastCXXMethod
;
1135 /// CXXCtorInitializer - Represents a C++ base or member
1136 /// initializer, which is part of a constructor initializer that
1137 /// initializes one non-static member variable or one base class. For
1138 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1143 /// class B : public A {
1146 /// B(A& a) : A(a), f(3.14159) { }
1149 class CXXCtorInitializer
{
1150 /// \brief Either the base class name (stored as a TypeSourceInfo*), an normal
1151 /// field (FieldDecl) or an anonymous field (IndirectFieldDecl*) being
1153 llvm::PointerUnion3
<TypeSourceInfo
*, FieldDecl
*, IndirectFieldDecl
*>
1156 /// \brief The source location for the field name or, for a base initializer
1157 /// pack expansion, the location of the ellipsis.
1158 SourceLocation MemberOrEllipsisLocation
;
1160 /// \brief The argument used to initialize the base or member, which may
1161 /// end up constructing an object (when multiple arguments are involved).
1164 /// LParenLoc - Location of the left paren of the ctor-initializer.
1165 SourceLocation LParenLoc
;
1167 /// RParenLoc - Location of the right paren of the ctor-initializer.
1168 SourceLocation RParenLoc
;
1170 /// IsVirtual - If the initializer is a base initializer, this keeps track
1171 /// of whether the base is virtual or not.
1174 /// IsWritten - Whether or not the initializer is explicitly written
1178 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1179 /// number keeps track of the textual order of this initializer in the
1180 /// original sources, counting from 0; otherwise, if IsWritten is false,
1181 /// it stores the number of array index variables stored after this
1182 /// object in memory.
1183 unsigned SourceOrderOrNumArrayIndices
: 14;
1185 CXXCtorInitializer(ASTContext
&Context
, FieldDecl
*Member
,
1186 SourceLocation MemberLoc
, SourceLocation L
, Expr
*Init
,
1187 SourceLocation R
, VarDecl
**Indices
, unsigned NumIndices
);
1190 /// CXXCtorInitializer - Creates a new base-class initializer.
1192 CXXCtorInitializer(ASTContext
&Context
, TypeSourceInfo
*TInfo
, bool IsVirtual
,
1193 SourceLocation L
, Expr
*Init
, SourceLocation R
,
1194 SourceLocation EllipsisLoc
);
1196 /// CXXCtorInitializer - Creates a new member initializer.
1198 CXXCtorInitializer(ASTContext
&Context
, FieldDecl
*Member
,
1199 SourceLocation MemberLoc
, SourceLocation L
, Expr
*Init
,
1203 CXXCtorInitializer(ASTContext
&Context
, IndirectFieldDecl
*Member
,
1204 SourceLocation MemberLoc
, SourceLocation L
, Expr
*Init
,
1207 /// \brief Creates a new member initializer that optionally contains
1208 /// array indices used to describe an elementwise initialization.
1209 static CXXCtorInitializer
*Create(ASTContext
&Context
, FieldDecl
*Member
,
1210 SourceLocation MemberLoc
, SourceLocation L
,
1211 Expr
*Init
, SourceLocation R
,
1212 VarDecl
**Indices
, unsigned NumIndices
);
1214 /// isBaseInitializer - Returns true when this initializer is
1215 /// initializing a base class.
1216 bool isBaseInitializer() const { return Initializee
.is
<TypeSourceInfo
*>(); }
1218 /// isMemberInitializer - Returns true when this initializer is
1219 /// initializing a non-static data member.
1220 bool isMemberInitializer() const { return Initializee
.is
<FieldDecl
*>(); }
1222 bool isAnyMemberInitializer() const {
1223 return isMemberInitializer() || isIndirectMemberInitializer();
1226 bool isIndirectMemberInitializer() const {
1227 return Initializee
.is
<IndirectFieldDecl
*>();
1230 /// \brief Determine whether this initializer is a pack expansion.
1231 bool isPackExpansion() const {
1232 return isBaseInitializer() && MemberOrEllipsisLocation
.isValid();
1235 // \brief For a pack expansion, returns the location of the ellipsis.
1236 SourceLocation
getEllipsisLoc() const {
1237 assert(isPackExpansion() && "Initializer is not a pack expansion");
1238 return MemberOrEllipsisLocation
;
1241 /// If this is a base class initializer, returns the type of the
1242 /// base class with location information. Otherwise, returns an NULL
1244 TypeLoc
getBaseClassLoc() const;
1246 /// If this is a base class initializer, returns the type of the base class.
1247 /// Otherwise, returns NULL.
1248 const Type
*getBaseClass() const;
1250 /// Returns whether the base is virtual or not.
1251 bool isBaseVirtual() const {
1252 assert(isBaseInitializer() && "Must call this on base initializer!");
1257 /// \brief Returns the declarator information for a base class initializer.
1258 TypeSourceInfo
*getBaseClassInfo() const {
1259 return Initializee
.dyn_cast
<TypeSourceInfo
*>();
1262 /// getMember - If this is a member initializer, returns the
1263 /// declaration of the non-static data member being
1264 /// initialized. Otherwise, returns NULL.
1265 FieldDecl
*getMember() const {
1266 if (isMemberInitializer())
1267 return Initializee
.get
<FieldDecl
*>();
1271 FieldDecl
*getAnyMember() const {
1272 if (isMemberInitializer())
1273 return Initializee
.get
<FieldDecl
*>();
1274 else if (isIndirectMemberInitializer())
1275 return Initializee
.get
<IndirectFieldDecl
*>()->getAnonField();
1280 IndirectFieldDecl
*getIndirectMember() const {
1281 if (isIndirectMemberInitializer())
1282 return Initializee
.get
<IndirectFieldDecl
*>();
1287 SourceLocation
getMemberLocation() const {
1288 return MemberOrEllipsisLocation
;
1291 /// \brief Determine the source location of the initializer.
1292 SourceLocation
getSourceLocation() const;
1294 /// \brief Determine the source range covering the entire initializer.
1295 SourceRange
getSourceRange() const;
1297 /// isWritten - Returns true if this initializer is explicitly written
1298 /// in the source code.
1299 bool isWritten() const { return IsWritten
; }
1301 /// \brief Return the source position of the initializer, counting from 0.
1302 /// If the initializer was implicit, -1 is returned.
1303 int getSourceOrder() const {
1304 return IsWritten
? static_cast<int>(SourceOrderOrNumArrayIndices
) : -1;
1307 /// \brief Set the source order of this initializer. This method can only
1308 /// be called once for each initializer; it cannot be called on an
1309 /// initializer having a positive number of (implicit) array indices.
1310 void setSourceOrder(int pos
) {
1311 assert(!IsWritten
&&
1312 "calling twice setSourceOrder() on the same initializer");
1313 assert(SourceOrderOrNumArrayIndices
== 0 &&
1314 "setSourceOrder() used when there are implicit array indices");
1316 "setSourceOrder() used to make an initializer implicit");
1318 SourceOrderOrNumArrayIndices
= static_cast<unsigned>(pos
);
1321 SourceLocation
getLParenLoc() const { return LParenLoc
; }
1322 SourceLocation
getRParenLoc() const { return RParenLoc
; }
1324 /// \brief Determine the number of implicit array indices used while
1325 /// described an array member initialization.
1326 unsigned getNumArrayIndices() const {
1327 return IsWritten
? 0 : SourceOrderOrNumArrayIndices
;
1330 /// \brief Retrieve a particular array index variable used to
1331 /// describe an array member initialization.
1332 VarDecl
*getArrayIndex(unsigned I
) {
1333 assert(I
< getNumArrayIndices() && "Out of bounds member array index");
1334 return reinterpret_cast<VarDecl
**>(this + 1)[I
];
1336 const VarDecl
*getArrayIndex(unsigned I
) const {
1337 assert(I
< getNumArrayIndices() && "Out of bounds member array index");
1338 return reinterpret_cast<const VarDecl
* const *>(this + 1)[I
];
1340 void setArrayIndex(unsigned I
, VarDecl
*Index
) {
1341 assert(I
< getNumArrayIndices() && "Out of bounds member array index");
1342 reinterpret_cast<VarDecl
**>(this + 1)[I
] = Index
;
1345 Expr
*getInit() const { return static_cast<Expr
*>(Init
); }
1348 /// CXXConstructorDecl - Represents a C++ constructor within a
1349 /// class. For example:
1354 /// explicit X(int); // represented by a CXXConstructorDecl.
1357 class CXXConstructorDecl
: public CXXMethodDecl
{
1358 /// IsExplicitSpecified - Whether this constructor declaration has the
1359 /// 'explicit' keyword specified.
1360 bool IsExplicitSpecified
: 1;
1362 /// ImplicitlyDefined - Whether this constructor was implicitly
1363 /// defined by the compiler. When false, the constructor was defined
1364 /// by the user. In C++03, this flag will have the same value as
1365 /// Implicit. In C++0x, however, a constructor that is
1366 /// explicitly defaulted (i.e., defined with " = default") will have
1367 /// @c !Implicit && ImplicitlyDefined.
1368 bool ImplicitlyDefined
: 1;
1370 /// Support for base and member initializers.
1371 /// CtorInitializers - The arguments used to initialize the base
1373 CXXCtorInitializer
**CtorInitializers
;
1374 unsigned NumCtorInitializers
;
1376 CXXConstructorDecl(CXXRecordDecl
*RD
, const DeclarationNameInfo
&NameInfo
,
1377 QualType T
, TypeSourceInfo
*TInfo
,
1378 bool isExplicitSpecified
, bool isInline
,
1379 bool isImplicitlyDeclared
)
1380 : CXXMethodDecl(CXXConstructor
, RD
, NameInfo
, T
, TInfo
, false,
1382 IsExplicitSpecified(isExplicitSpecified
), ImplicitlyDefined(false),
1383 CtorInitializers(0), NumCtorInitializers(0) {
1384 setImplicit(isImplicitlyDeclared
);
1388 static CXXConstructorDecl
*Create(ASTContext
&C
, EmptyShell Empty
);
1389 static CXXConstructorDecl
*Create(ASTContext
&C
, CXXRecordDecl
*RD
,
1390 const DeclarationNameInfo
&NameInfo
,
1391 QualType T
, TypeSourceInfo
*TInfo
,
1393 bool isInline
, bool isImplicitlyDeclared
);
1395 /// isExplicitSpecified - Whether this constructor declaration has the
1396 /// 'explicit' keyword specified.
1397 bool isExplicitSpecified() const { return IsExplicitSpecified
; }
1399 /// isExplicit - Whether this constructor was marked "explicit" or not.
1400 bool isExplicit() const {
1401 return cast
<CXXConstructorDecl
>(getFirstDeclaration())
1402 ->isExplicitSpecified();
1405 /// isImplicitlyDefined - Whether this constructor was implicitly
1406 /// defined. If false, then this constructor was defined by the
1407 /// user. This operation can only be invoked if the constructor has
1408 /// already been defined.
1409 bool isImplicitlyDefined() const {
1410 assert(isThisDeclarationADefinition() &&
1411 "Can only get the implicit-definition flag once the "
1412 "constructor has been defined");
1413 return ImplicitlyDefined
;
1416 /// setImplicitlyDefined - Set whether this constructor was
1417 /// implicitly defined or not.
1418 void setImplicitlyDefined(bool ID
) {
1419 assert(isThisDeclarationADefinition() &&
1420 "Can only set the implicit-definition flag once the constructor "
1421 "has been defined");
1422 ImplicitlyDefined
= ID
;
1425 /// init_iterator - Iterates through the member/base initializer list.
1426 typedef CXXCtorInitializer
**init_iterator
;
1428 /// init_const_iterator - Iterates through the memberbase initializer list.
1429 typedef CXXCtorInitializer
* const * init_const_iterator
;
1431 /// init_begin() - Retrieve an iterator to the first initializer.
1432 init_iterator
init_begin() { return CtorInitializers
; }
1433 /// begin() - Retrieve an iterator to the first initializer.
1434 init_const_iterator
init_begin() const { return CtorInitializers
; }
1436 /// init_end() - Retrieve an iterator past the last initializer.
1437 init_iterator
init_end() {
1438 return CtorInitializers
+ NumCtorInitializers
;
1440 /// end() - Retrieve an iterator past the last initializer.
1441 init_const_iterator
init_end() const {
1442 return CtorInitializers
+ NumCtorInitializers
;
1445 typedef std::reverse_iterator
<init_iterator
> init_reverse_iterator
;
1446 typedef std::reverse_iterator
<init_const_iterator
> init_const_reverse_iterator
;
1448 init_reverse_iterator
init_rbegin() {
1449 return init_reverse_iterator(init_end());
1451 init_const_reverse_iterator
init_rbegin() const {
1452 return init_const_reverse_iterator(init_end());
1455 init_reverse_iterator
init_rend() {
1456 return init_reverse_iterator(init_begin());
1458 init_const_reverse_iterator
init_rend() const {
1459 return init_const_reverse_iterator(init_begin());
1462 /// getNumArgs - Determine the number of arguments used to
1463 /// initialize the member or base.
1464 unsigned getNumCtorInitializers() const {
1465 return NumCtorInitializers
;
1468 void setNumCtorInitializers(unsigned numCtorInitializers
) {
1469 NumCtorInitializers
= numCtorInitializers
;
1472 void setCtorInitializers(CXXCtorInitializer
** initializers
) {
1473 CtorInitializers
= initializers
;
1475 /// isDefaultConstructor - Whether this constructor is a default
1476 /// constructor (C++ [class.ctor]p5), which can be used to
1477 /// default-initialize a class of this type.
1478 bool isDefaultConstructor() const;
1480 /// isCopyConstructor - Whether this constructor is a copy
1481 /// constructor (C++ [class.copy]p2, which can be used to copy the
1482 /// class. @p TypeQuals will be set to the qualifiers on the
1483 /// argument type. For example, @p TypeQuals would be set to @c
1484 /// QualType::Const for the following copy constructor:
1492 bool isCopyConstructor(unsigned &TypeQuals
) const;
1494 /// isCopyConstructor - Whether this constructor is a copy
1495 /// constructor (C++ [class.copy]p2, which can be used to copy the
1497 bool isCopyConstructor() const {
1498 unsigned TypeQuals
= 0;
1499 return isCopyConstructor(TypeQuals
);
1502 /// \brief Determine whether this constructor is a move constructor
1503 /// (C++0x [class.copy]p3), which can be used to move values of the class.
1505 /// \param TypeQuals If this constructor is a move constructor, will be set
1506 /// to the type qualifiers on the referent of the first parameter's type.
1507 bool isMoveConstructor(unsigned &TypeQuals
) const;
1509 /// \brief Determine whether this constructor is a move constructor
1510 /// (C++0x [class.copy]p3), which can be used to move values of the class.
1511 bool isMoveConstructor() const;
1513 /// \brief Determine whether this is a copy or move constructor.
1515 /// \param TypeQuals Will be set to the type qualifiers on the reference
1516 /// parameter, if in fact this is a copy or move constructor.
1517 bool isCopyOrMoveConstructor(unsigned &TypeQuals
) const;
1519 /// \brief Determine whether this a copy or move constructor.
1520 bool isCopyOrMoveConstructor() const {
1522 return isCopyOrMoveConstructor(Quals
);
1525 /// isConvertingConstructor - Whether this constructor is a
1526 /// converting constructor (C++ [class.conv.ctor]), which can be
1527 /// used for user-defined conversions.
1528 bool isConvertingConstructor(bool AllowExplicit
) const;
1530 /// \brief Determine whether this is a member template specialization that
1531 /// would copy the object to itself. Such constructors are never used to copy
1533 bool isSpecializationCopyingObject() const;
1535 /// \brief Get the constructor that this inheriting constructor is based on.
1536 const CXXConstructorDecl
*getInheritedConstructor() const;
1538 /// \brief Set the constructor that this inheriting constructor is based on.
1539 void setInheritedConstructor(const CXXConstructorDecl
*BaseCtor
);
1541 // Implement isa/cast/dyncast/etc.
1542 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1543 static bool classof(const CXXConstructorDecl
*D
) { return true; }
1544 static bool classofKind(Kind K
) { return K
== CXXConstructor
; }
1546 friend class ASTDeclReader
;
1547 friend class ASTDeclWriter
;
1550 /// CXXDestructorDecl - Represents a C++ destructor within a
1551 /// class. For example:
1556 /// ~X(); // represented by a CXXDestructorDecl.
1559 class CXXDestructorDecl
: public CXXMethodDecl
{
1560 /// ImplicitlyDefined - Whether this destructor was implicitly
1561 /// defined by the compiler. When false, the destructor was defined
1562 /// by the user. In C++03, this flag will have the same value as
1563 /// Implicit. In C++0x, however, a destructor that is
1564 /// explicitly defaulted (i.e., defined with " = default") will have
1565 /// @c !Implicit && ImplicitlyDefined.
1566 bool ImplicitlyDefined
: 1;
1568 FunctionDecl
*OperatorDelete
;
1570 CXXDestructorDecl(CXXRecordDecl
*RD
, const DeclarationNameInfo
&NameInfo
,
1571 QualType T
, TypeSourceInfo
*TInfo
,
1572 bool isInline
, bool isImplicitlyDeclared
)
1573 : CXXMethodDecl(CXXDestructor
, RD
, NameInfo
, T
, TInfo
, false,
1575 ImplicitlyDefined(false), OperatorDelete(0) {
1576 setImplicit(isImplicitlyDeclared
);
1580 static CXXDestructorDecl
*Create(ASTContext
& C
, EmptyShell Empty
);
1581 static CXXDestructorDecl
*Create(ASTContext
&C
, CXXRecordDecl
*RD
,
1582 const DeclarationNameInfo
&NameInfo
,
1583 QualType T
, TypeSourceInfo
* TInfo
,
1585 bool isImplicitlyDeclared
);
1587 /// isImplicitlyDefined - Whether this destructor was implicitly
1588 /// defined. If false, then this destructor was defined by the
1589 /// user. This operation can only be invoked if the destructor has
1590 /// already been defined.
1591 bool isImplicitlyDefined() const {
1592 assert(isThisDeclarationADefinition() &&
1593 "Can only get the implicit-definition flag once the destructor has been defined");
1594 return ImplicitlyDefined
;
1597 /// setImplicitlyDefined - Set whether this destructor was
1598 /// implicitly defined or not.
1599 void setImplicitlyDefined(bool ID
) {
1600 assert(isThisDeclarationADefinition() &&
1601 "Can only set the implicit-definition flag once the destructor has been defined");
1602 ImplicitlyDefined
= ID
;
1605 void setOperatorDelete(FunctionDecl
*OD
) { OperatorDelete
= OD
; }
1606 const FunctionDecl
*getOperatorDelete() const { return OperatorDelete
; }
1608 // Implement isa/cast/dyncast/etc.
1609 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1610 static bool classof(const CXXDestructorDecl
*D
) { return true; }
1611 static bool classofKind(Kind K
) { return K
== CXXDestructor
; }
1613 friend class ASTDeclReader
;
1614 friend class ASTDeclWriter
;
1617 /// CXXConversionDecl - Represents a C++ conversion function within a
1618 /// class. For example:
1623 /// operator bool();
1626 class CXXConversionDecl
: public CXXMethodDecl
{
1627 /// IsExplicitSpecified - Whether this conversion function declaration is
1628 /// marked "explicit", meaning that it can only be applied when the user
1629 /// explicitly wrote a cast. This is a C++0x feature.
1630 bool IsExplicitSpecified
: 1;
1632 CXXConversionDecl(CXXRecordDecl
*RD
, const DeclarationNameInfo
&NameInfo
,
1633 QualType T
, TypeSourceInfo
*TInfo
,
1634 bool isInline
, bool isExplicitSpecified
)
1635 : CXXMethodDecl(CXXConversion
, RD
, NameInfo
, T
, TInfo
, false,
1637 IsExplicitSpecified(isExplicitSpecified
) { }
1640 static CXXConversionDecl
*Create(ASTContext
&C
, EmptyShell Empty
);
1641 static CXXConversionDecl
*Create(ASTContext
&C
, CXXRecordDecl
*RD
,
1642 const DeclarationNameInfo
&NameInfo
,
1643 QualType T
, TypeSourceInfo
*TInfo
,
1644 bool isInline
, bool isExplicit
);
1646 /// IsExplicitSpecified - Whether this conversion function declaration is
1647 /// marked "explicit", meaning that it can only be applied when the user
1648 /// explicitly wrote a cast. This is a C++0x feature.
1649 bool isExplicitSpecified() const { return IsExplicitSpecified
; }
1651 /// isExplicit - Whether this is an explicit conversion operator
1652 /// (C++0x only). Explicit conversion operators are only considered
1653 /// when the user has explicitly written a cast.
1654 bool isExplicit() const {
1655 return cast
<CXXConversionDecl
>(getFirstDeclaration())
1656 ->isExplicitSpecified();
1659 /// getConversionType - Returns the type that this conversion
1660 /// function is converting to.
1661 QualType
getConversionType() const {
1662 return getType()->getAs
<FunctionType
>()->getResultType();
1665 // Implement isa/cast/dyncast/etc.
1666 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1667 static bool classof(const CXXConversionDecl
*D
) { return true; }
1668 static bool classofKind(Kind K
) { return K
== CXXConversion
; }
1670 friend class ASTDeclReader
;
1671 friend class ASTDeclWriter
;
1674 /// LinkageSpecDecl - This represents a linkage specification. For example:
1675 /// extern "C" void foo();
1677 class LinkageSpecDecl
: public Decl
, public DeclContext
{
1679 /// LanguageIDs - Used to represent the language in a linkage
1680 /// specification. The values are part of the serialization abi for
1681 /// ASTs and cannot be changed without altering that abi. To help
1682 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1683 /// from the dwarf standard.
1685 lang_c
= /* DW_LANG_C */ 0x0002,
1686 lang_cxx
= /* DW_LANG_C_plus_plus */ 0x0004
1689 /// Language - The language for this linkage specification.
1690 LanguageIDs Language
;
1692 /// HadBraces - Whether this linkage specification had curly braces or not.
1695 LinkageSpecDecl(DeclContext
*DC
, SourceLocation L
, LanguageIDs lang
,
1697 : Decl(LinkageSpec
, DC
, L
),
1698 DeclContext(LinkageSpec
), Language(lang
), HadBraces(Braces
) { }
1701 static LinkageSpecDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
1702 SourceLocation L
, LanguageIDs Lang
,
1705 /// \brief Return the language specified by this linkage specification.
1706 LanguageIDs
getLanguage() const { return Language
; }
1708 /// \brief Set the language specified by this linkage specification.
1709 void setLanguage(LanguageIDs L
) { Language
= L
; }
1711 /// \brief Determines whether this linkage specification had braces in
1712 /// its syntactic form.
1713 bool hasBraces() const { return HadBraces
; }
1715 /// \brief Set whether this linkage specification has braces in its
1717 void setHasBraces(bool B
) { HadBraces
= B
; }
1719 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1720 static bool classof(const LinkageSpecDecl
*D
) { return true; }
1721 static bool classofKind(Kind K
) { return K
== LinkageSpec
; }
1722 static DeclContext
*castToDeclContext(const LinkageSpecDecl
*D
) {
1723 return static_cast<DeclContext
*>(const_cast<LinkageSpecDecl
*>(D
));
1725 static LinkageSpecDecl
*castFromDeclContext(const DeclContext
*DC
) {
1726 return static_cast<LinkageSpecDecl
*>(const_cast<DeclContext
*>(DC
));
1730 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
1732 /// using namespace std;
1734 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1735 // artificial name, for all using-directives in order to store
1736 // them in DeclContext effectively.
1737 class UsingDirectiveDecl
: public NamedDecl
{
1738 /// \brief The location of the "using" keyword.
1739 SourceLocation UsingLoc
;
1741 /// SourceLocation - Location of 'namespace' token.
1742 SourceLocation NamespaceLoc
;
1744 /// \brief The source range that covers the nested-name-specifier
1745 /// preceding the namespace name.
1746 SourceRange QualifierRange
;
1748 /// \brief The nested-name-specifier that precedes the namespace
1750 NestedNameSpecifier
*Qualifier
;
1752 /// NominatedNamespace - Namespace nominated by using-directive.
1753 NamedDecl
*NominatedNamespace
;
1755 /// Enclosing context containing both using-directive and nominated
1757 DeclContext
*CommonAncestor
;
1759 /// getUsingDirectiveName - Returns special DeclarationName used by
1760 /// using-directives. This is only used by DeclContext for storing
1761 /// UsingDirectiveDecls in its lookup structure.
1762 static DeclarationName
getName() {
1763 return DeclarationName::getUsingDirectiveName();
1766 UsingDirectiveDecl(DeclContext
*DC
, SourceLocation UsingLoc
,
1767 SourceLocation NamespcLoc
,
1768 SourceRange QualifierRange
,
1769 NestedNameSpecifier
*Qualifier
,
1770 SourceLocation IdentLoc
,
1771 NamedDecl
*Nominated
,
1772 DeclContext
*CommonAncestor
)
1773 : NamedDecl(UsingDirective
, DC
, IdentLoc
, getName()), UsingLoc(UsingLoc
),
1774 NamespaceLoc(NamespcLoc
), QualifierRange(QualifierRange
),
1775 Qualifier(Qualifier
), NominatedNamespace(Nominated
),
1776 CommonAncestor(CommonAncestor
) {
1780 /// \brief Retrieve the source range of the nested-name-specifier
1781 /// that qualifies the namespace name.
1782 SourceRange
getQualifierRange() const { return QualifierRange
; }
1784 /// \brief Retrieve the nested-name-specifier that qualifies the
1785 /// name of the namespace.
1786 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
1788 NamedDecl
*getNominatedNamespaceAsWritten() { return NominatedNamespace
; }
1789 const NamedDecl
*getNominatedNamespaceAsWritten() const {
1790 return NominatedNamespace
;
1793 /// getNominatedNamespace - Returns namespace nominated by using-directive.
1794 NamespaceDecl
*getNominatedNamespace();
1796 const NamespaceDecl
*getNominatedNamespace() const {
1797 return const_cast<UsingDirectiveDecl
*>(this)->getNominatedNamespace();
1800 /// \brief Returns the common ancestor context of this using-directive and
1801 /// its nominated namespace.
1802 DeclContext
*getCommonAncestor() { return CommonAncestor
; }
1803 const DeclContext
*getCommonAncestor() const { return CommonAncestor
; }
1805 /// \brief Return the location of the "using" keyword.
1806 SourceLocation
getUsingLoc() const { return UsingLoc
; }
1808 // FIXME: Could omit 'Key' in name.
1809 /// getNamespaceKeyLocation - Returns location of namespace keyword.
1810 SourceLocation
getNamespaceKeyLocation() const { return NamespaceLoc
; }
1812 /// getIdentLocation - Returns location of identifier.
1813 SourceLocation
getIdentLocation() const { return getLocation(); }
1815 static UsingDirectiveDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
1816 SourceLocation UsingLoc
,
1817 SourceLocation NamespaceLoc
,
1818 SourceRange QualifierRange
,
1819 NestedNameSpecifier
*Qualifier
,
1820 SourceLocation IdentLoc
,
1821 NamedDecl
*Nominated
,
1822 DeclContext
*CommonAncestor
);
1824 SourceRange
getSourceRange() const {
1825 return SourceRange(UsingLoc
, getLocation());
1828 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1829 static bool classof(const UsingDirectiveDecl
*D
) { return true; }
1830 static bool classofKind(Kind K
) { return K
== UsingDirective
; }
1832 // Friend for getUsingDirectiveName.
1833 friend class DeclContext
;
1835 friend class ASTDeclReader
;
1838 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1841 /// namespace Foo = Bar;
1843 class NamespaceAliasDecl
: public NamedDecl
{
1844 /// \brief The location of the "namespace" keyword.
1845 SourceLocation NamespaceLoc
;
1847 /// \brief The source range that covers the nested-name-specifier
1848 /// preceding the namespace name.
1849 SourceRange QualifierRange
;
1851 /// \brief The nested-name-specifier that precedes the namespace
1853 NestedNameSpecifier
*Qualifier
;
1855 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
1856 SourceLocation IdentLoc
;
1858 /// Namespace - The Decl that this alias points to. Can either be a
1859 /// NamespaceDecl or a NamespaceAliasDecl.
1860 NamedDecl
*Namespace
;
1862 NamespaceAliasDecl(DeclContext
*DC
, SourceLocation NamespaceLoc
,
1863 SourceLocation AliasLoc
, IdentifierInfo
*Alias
,
1864 SourceRange QualifierRange
,
1865 NestedNameSpecifier
*Qualifier
,
1866 SourceLocation IdentLoc
, NamedDecl
*Namespace
)
1867 : NamedDecl(NamespaceAlias
, DC
, AliasLoc
, Alias
),
1868 NamespaceLoc(NamespaceLoc
), QualifierRange(QualifierRange
),
1869 Qualifier(Qualifier
), IdentLoc(IdentLoc
), Namespace(Namespace
) { }
1871 friend class ASTDeclReader
;
1874 /// \brief Retrieve the source range of the nested-name-specifier
1875 /// that qualifiers the namespace name.
1876 SourceRange
getQualifierRange() const { return QualifierRange
; }
1878 /// \brief Set the source range of the nested-name-specifier that qualifies
1879 /// the namespace name.
1880 void setQualifierRange(SourceRange R
) { QualifierRange
= R
; }
1882 /// \brief Retrieve the nested-name-specifier that qualifies the
1883 /// name of the namespace.
1884 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
1886 /// \brief Set the nested-name-specifier that qualifies the name of the
1888 void setQualifier(NestedNameSpecifier
*NNS
) { Qualifier
= NNS
; }
1890 /// \brief Retrieve the namespace declaration aliased by this directive.
1891 NamespaceDecl
*getNamespace() {
1892 if (NamespaceAliasDecl
*AD
= dyn_cast
<NamespaceAliasDecl
>(Namespace
))
1893 return AD
->getNamespace();
1895 return cast
<NamespaceDecl
>(Namespace
);
1898 const NamespaceDecl
*getNamespace() const {
1899 return const_cast<NamespaceAliasDecl
*>(this)->getNamespace();
1902 /// Returns the location of the alias name, i.e. 'foo' in
1903 /// "namespace foo = ns::bar;".
1904 SourceLocation
getAliasLoc() const { return getLocation(); }
1906 /// Returns the location of the 'namespace' keyword.
1907 SourceLocation
getNamespaceLoc() const { return NamespaceLoc
; }
1909 /// Returns the location of the identifier in the named namespace.
1910 SourceLocation
getTargetNameLoc() const { return IdentLoc
; }
1912 /// \brief Retrieve the namespace that this alias refers to, which
1913 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1914 NamedDecl
*getAliasedNamespace() const { return Namespace
; }
1916 static NamespaceAliasDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
1917 SourceLocation NamespaceLoc
,
1918 SourceLocation AliasLoc
,
1919 IdentifierInfo
*Alias
,
1920 SourceRange QualifierRange
,
1921 NestedNameSpecifier
*Qualifier
,
1922 SourceLocation IdentLoc
,
1923 NamedDecl
*Namespace
);
1925 virtual SourceRange
getSourceRange() const {
1926 return SourceRange(NamespaceLoc
, IdentLoc
);
1929 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1930 static bool classof(const NamespaceAliasDecl
*D
) { return true; }
1931 static bool classofKind(Kind K
) { return K
== NamespaceAlias
; }
1934 /// UsingShadowDecl - Represents a shadow declaration introduced into
1935 /// a scope by a (resolved) using declaration. For example,
1941 /// using A::foo(); // <- a UsingDecl
1942 /// // Also creates a UsingShadowDecl for A::foo in B
1945 class UsingShadowDecl
: public NamedDecl
{
1946 /// The referenced declaration.
1947 NamedDecl
*Underlying
;
1949 /// \brief The using declaration which introduced this decl or the next using
1950 /// shadow declaration contained in the aforementioned using declaration.
1951 NamedDecl
*UsingOrNextShadow
;
1952 friend class UsingDecl
;
1954 UsingShadowDecl(DeclContext
*DC
, SourceLocation Loc
, UsingDecl
*Using
,
1956 : NamedDecl(UsingShadow
, DC
, Loc
, DeclarationName()),
1958 UsingOrNextShadow(reinterpret_cast<NamedDecl
*>(Using
)) {
1960 setDeclName(Target
->getDeclName());
1961 IdentifierNamespace
= Target
->getIdentifierNamespace();
1967 static UsingShadowDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
1968 SourceLocation Loc
, UsingDecl
*Using
,
1969 NamedDecl
*Target
) {
1970 return new (C
) UsingShadowDecl(DC
, Loc
, Using
, Target
);
1973 /// \brief Gets the underlying declaration which has been brought into the
1975 NamedDecl
*getTargetDecl() const { return Underlying
; }
1977 /// \brief Sets the underlying declaration which has been brought into the
1979 void setTargetDecl(NamedDecl
* ND
) {
1980 assert(ND
&& "Target decl is null!");
1982 IdentifierNamespace
= ND
->getIdentifierNamespace();
1985 /// \brief Gets the using declaration to which this declaration is tied.
1986 UsingDecl
*getUsingDecl() const;
1988 /// \brief The next using shadow declaration contained in the shadow decl
1989 /// chain of the using declaration which introduced this decl.
1990 UsingShadowDecl
*getNextUsingShadowDecl() const {
1991 return dyn_cast_or_null
<UsingShadowDecl
>(UsingOrNextShadow
);
1994 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
1995 static bool classof(const UsingShadowDecl
*D
) { return true; }
1996 static bool classofKind(Kind K
) { return K
== Decl::UsingShadow
; }
1998 friend class ASTDeclReader
;
1999 friend class ASTDeclWriter
;
2002 /// UsingDecl - Represents a C++ using-declaration. For example:
2003 /// using someNameSpace::someIdentifier;
2004 class UsingDecl
: public NamedDecl
{
2005 /// \brief The source range that covers the nested-name-specifier
2006 /// preceding the declaration name.
2007 SourceRange NestedNameRange
;
2009 /// \brief The source location of the "using" location itself.
2010 SourceLocation UsingLocation
;
2012 /// \brief Target nested name specifier.
2013 NestedNameSpecifier
* TargetNestedName
;
2015 /// DNLoc - Provides source/type location info for the
2016 /// declaration name embedded in the ValueDecl base class.
2017 DeclarationNameLoc DNLoc
;
2019 /// \brief The first shadow declaration of the shadow decl chain associated
2020 /// with this using declaration.
2021 UsingShadowDecl
*FirstUsingShadow
;
2023 // \brief Has 'typename' keyword.
2026 UsingDecl(DeclContext
*DC
, SourceRange NNR
,
2027 SourceLocation UL
, NestedNameSpecifier
* TargetNNS
,
2028 const DeclarationNameInfo
&NameInfo
, bool IsTypeNameArg
)
2029 : NamedDecl(Using
, DC
, NameInfo
.getLoc(), NameInfo
.getName()),
2030 NestedNameRange(NNR
), UsingLocation(UL
), TargetNestedName(TargetNNS
),
2031 DNLoc(NameInfo
.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg
) {
2035 /// \brief Returns the source range that covers the nested-name-specifier
2036 /// preceding the namespace name.
2037 SourceRange
getNestedNameRange() const { return NestedNameRange
; }
2039 /// \brief Set the source range of the nested-name-specifier.
2040 void setNestedNameRange(SourceRange R
) { NestedNameRange
= R
; }
2042 // FIXME: Naming is inconsistent with other get*Loc functions.
2043 /// \brief Returns the source location of the "using" keyword.
2044 SourceLocation
getUsingLocation() const { return UsingLocation
; }
2046 /// \brief Set the source location of the 'using' keyword.
2047 void setUsingLocation(SourceLocation L
) { UsingLocation
= L
; }
2049 /// \brief Get the target nested name declaration.
2050 NestedNameSpecifier
* getTargetNestedNameDecl() const {
2051 return TargetNestedName
;
2054 /// \brief Set the target nested name declaration.
2055 void setTargetNestedNameDecl(NestedNameSpecifier
*NNS
) {
2056 TargetNestedName
= NNS
;
2059 DeclarationNameInfo
getNameInfo() const {
2060 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc
);
2063 /// \brief Return true if the using declaration has 'typename'.
2064 bool isTypeName() const { return IsTypeName
; }
2066 /// \brief Sets whether the using declaration has 'typename'.
2067 void setTypeName(bool TN
) { IsTypeName
= TN
; }
2069 /// \brief Iterates through the using shadow declarations assosiated with
2070 /// this using declaration.
2071 class shadow_iterator
{
2072 /// \brief The current using shadow declaration.
2073 UsingShadowDecl
*Current
;
2076 typedef UsingShadowDecl
* value_type
;
2077 typedef UsingShadowDecl
* reference
;
2078 typedef UsingShadowDecl
* pointer
;
2079 typedef std::forward_iterator_tag iterator_category
;
2080 typedef std::ptrdiff_t difference_type
;
2082 shadow_iterator() : Current(0) { }
2083 explicit shadow_iterator(UsingShadowDecl
*C
) : Current(C
) { }
2085 reference
operator*() const { return Current
; }
2086 pointer
operator->() const { return Current
; }
2088 shadow_iterator
& operator++() {
2089 Current
= Current
->getNextUsingShadowDecl();
2093 shadow_iterator
operator++(int) {
2094 shadow_iterator
tmp(*this);
2099 friend bool operator==(shadow_iterator x
, shadow_iterator y
) {
2100 return x
.Current
== y
.Current
;
2102 friend bool operator!=(shadow_iterator x
, shadow_iterator y
) {
2103 return x
.Current
!= y
.Current
;
2107 shadow_iterator
shadow_begin() const {
2108 return shadow_iterator(FirstUsingShadow
);
2110 shadow_iterator
shadow_end() const { return shadow_iterator(); }
2112 /// \brief Return the number of shadowed declarations associated with this
2113 /// using declaration.
2114 unsigned shadow_size() const {
2115 return std::distance(shadow_begin(), shadow_end());
2118 void addShadowDecl(UsingShadowDecl
*S
);
2119 void removeShadowDecl(UsingShadowDecl
*S
);
2121 static UsingDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
2122 SourceRange NNR
, SourceLocation UsingL
,
2123 NestedNameSpecifier
* TargetNNS
,
2124 const DeclarationNameInfo
&NameInfo
,
2125 bool IsTypeNameArg
);
2127 SourceRange
getSourceRange() const {
2128 return SourceRange(UsingLocation
, getNameInfo().getEndLoc());
2131 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
2132 static bool classof(const UsingDecl
*D
) { return true; }
2133 static bool classofKind(Kind K
) { return K
== Using
; }
2135 friend class ASTDeclReader
;
2136 friend class ASTDeclWriter
;
2139 /// UnresolvedUsingValueDecl - Represents a dependent using
2140 /// declaration which was not marked with 'typename'. Unlike
2141 /// non-dependent using declarations, these *only* bring through
2142 /// non-types; otherwise they would break two-phase lookup.
2144 /// template <class T> class A : public Base<T> {
2145 /// using Base<T>::foo;
2147 class UnresolvedUsingValueDecl
: public ValueDecl
{
2148 /// \brief The source range that covers the nested-name-specifier
2149 /// preceding the declaration name.
2150 SourceRange TargetNestedNameRange
;
2152 /// \brief The source location of the 'using' keyword
2153 SourceLocation UsingLocation
;
2155 NestedNameSpecifier
*TargetNestedNameSpecifier
;
2157 /// DNLoc - Provides source/type location info for the
2158 /// declaration name embedded in the ValueDecl base class.
2159 DeclarationNameLoc DNLoc
;
2161 UnresolvedUsingValueDecl(DeclContext
*DC
, QualType Ty
,
2162 SourceLocation UsingLoc
, SourceRange TargetNNR
,
2163 NestedNameSpecifier
*TargetNNS
,
2164 const DeclarationNameInfo
&NameInfo
)
2165 : ValueDecl(UnresolvedUsingValue
, DC
,
2166 NameInfo
.getLoc(), NameInfo
.getName(), Ty
),
2167 TargetNestedNameRange(TargetNNR
), UsingLocation(UsingLoc
),
2168 TargetNestedNameSpecifier(TargetNNS
), DNLoc(NameInfo
.getInfo())
2172 /// \brief Returns the source range that covers the nested-name-specifier
2173 /// preceding the namespace name.
2174 SourceRange
getTargetNestedNameRange() const { return TargetNestedNameRange
; }
2176 /// \brief Set the source range coverting the nested-name-specifier preceding
2177 /// the namespace name.
2178 void setTargetNestedNameRange(SourceRange R
) { TargetNestedNameRange
= R
; }
2180 /// \brief Get target nested name declaration.
2181 NestedNameSpecifier
* getTargetNestedNameSpecifier() const {
2182 return TargetNestedNameSpecifier
;
2185 /// \brief Set the nested name declaration.
2186 void setTargetNestedNameSpecifier(NestedNameSpecifier
* NNS
) {
2187 TargetNestedNameSpecifier
= NNS
;
2190 /// \brief Returns the source location of the 'using' keyword.
2191 SourceLocation
getUsingLoc() const { return UsingLocation
; }
2193 /// \brief Set the source location of the 'using' keyword.
2194 void setUsingLoc(SourceLocation L
) { UsingLocation
= L
; }
2196 DeclarationNameInfo
getNameInfo() const {
2197 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc
);
2200 static UnresolvedUsingValueDecl
*
2201 Create(ASTContext
&C
, DeclContext
*DC
, SourceLocation UsingLoc
,
2202 SourceRange TargetNNR
, NestedNameSpecifier
*TargetNNS
,
2203 const DeclarationNameInfo
&NameInfo
);
2205 SourceRange
getSourceRange() const {
2206 return SourceRange(UsingLocation
, getNameInfo().getEndLoc());
2209 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
2210 static bool classof(const UnresolvedUsingValueDecl
*D
) { return true; }
2211 static bool classofKind(Kind K
) { return K
== UnresolvedUsingValue
; }
2213 friend class ASTDeclReader
;
2214 friend class ASTDeclWriter
;
2217 /// UnresolvedUsingTypenameDecl - Represents a dependent using
2218 /// declaration which was marked with 'typename'.
2220 /// template <class T> class A : public Base<T> {
2221 /// using typename Base<T>::foo;
2224 /// The type associated with a unresolved using typename decl is
2225 /// currently always a typename type.
2226 class UnresolvedUsingTypenameDecl
: public TypeDecl
{
2227 /// \brief The source range that covers the nested-name-specifier
2228 /// preceding the declaration name.
2229 SourceRange TargetNestedNameRange
;
2231 /// \brief The source location of the 'using' keyword
2232 SourceLocation UsingLocation
;
2234 /// \brief The source location of the 'typename' keyword
2235 SourceLocation TypenameLocation
;
2237 NestedNameSpecifier
*TargetNestedNameSpecifier
;
2239 UnresolvedUsingTypenameDecl(DeclContext
*DC
, SourceLocation UsingLoc
,
2240 SourceLocation TypenameLoc
,
2241 SourceRange TargetNNR
, NestedNameSpecifier
*TargetNNS
,
2242 SourceLocation TargetNameLoc
, IdentifierInfo
*TargetName
)
2243 : TypeDecl(UnresolvedUsingTypename
, DC
, TargetNameLoc
, TargetName
),
2244 TargetNestedNameRange(TargetNNR
), UsingLocation(UsingLoc
),
2245 TypenameLocation(TypenameLoc
), TargetNestedNameSpecifier(TargetNNS
)
2248 friend class ASTDeclReader
;
2251 /// \brief Returns the source range that covers the nested-name-specifier
2252 /// preceding the namespace name.
2253 SourceRange
getTargetNestedNameRange() const { return TargetNestedNameRange
; }
2255 /// \brief Get target nested name declaration.
2256 NestedNameSpecifier
* getTargetNestedNameSpecifier() {
2257 return TargetNestedNameSpecifier
;
2260 /// \brief Returns the source location of the 'using' keyword.
2261 SourceLocation
getUsingLoc() const { return UsingLocation
; }
2263 /// \brief Returns the source location of the 'typename' keyword.
2264 SourceLocation
getTypenameLoc() const { return TypenameLocation
; }
2266 static UnresolvedUsingTypenameDecl
*
2267 Create(ASTContext
&C
, DeclContext
*DC
, SourceLocation UsingLoc
,
2268 SourceLocation TypenameLoc
,
2269 SourceRange TargetNNR
, NestedNameSpecifier
*TargetNNS
,
2270 SourceLocation TargetNameLoc
, DeclarationName TargetName
);
2272 SourceRange
getSourceRange() const {
2273 return SourceRange(UsingLocation
, getLocation());
2276 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
2277 static bool classof(const UnresolvedUsingTypenameDecl
*D
) { return true; }
2278 static bool classofKind(Kind K
) { return K
== UnresolvedUsingTypename
; }
2281 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
2282 class StaticAssertDecl
: public Decl
{
2284 StringLiteral
*Message
;
2286 StaticAssertDecl(DeclContext
*DC
, SourceLocation L
,
2287 Expr
*assertexpr
, StringLiteral
*message
)
2288 : Decl(StaticAssert
, DC
, L
), AssertExpr(assertexpr
), Message(message
) { }
2291 static StaticAssertDecl
*Create(ASTContext
&C
, DeclContext
*DC
,
2292 SourceLocation L
, Expr
*AssertExpr
,
2293 StringLiteral
*Message
);
2295 Expr
*getAssertExpr() { return AssertExpr
; }
2296 const Expr
*getAssertExpr() const { return AssertExpr
; }
2298 StringLiteral
*getMessage() { return Message
; }
2299 const StringLiteral
*getMessage() const { return Message
; }
2301 static bool classof(const Decl
*D
) { return classofKind(D
->getKind()); }
2302 static bool classof(StaticAssertDecl
*D
) { return true; }
2303 static bool classofKind(Kind K
) { return K
== StaticAssert
; }
2305 friend class ASTDeclReader
;
2308 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
2309 /// into a diagnostic with <<.
2310 const DiagnosticBuilder
&operator<<(const DiagnosticBuilder
&DB
,
2311 AccessSpecifier AS
);
2313 } // end namespace clang