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 virtual CXXRecordDecl *getCanonicalDecl() {
476 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
478 virtual 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 nested-name-specifier that precedes the namespace.
1745 NestedNameSpecifierLoc QualifierLoc;
1747 /// NominatedNamespace - Namespace nominated by using-directive.
1748 NamedDecl *NominatedNamespace;
1750 /// Enclosing context containing both using-directive and nominated
1752 DeclContext *CommonAncestor;
1754 /// getUsingDirectiveName - Returns special DeclarationName used by
1755 /// using-directives. This is only used by DeclContext for storing
1756 /// UsingDirectiveDecls in its lookup structure.
1757 static DeclarationName getName() {
1758 return DeclarationName::getUsingDirectiveName();
1761 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
1762 SourceLocation NamespcLoc,
1763 NestedNameSpecifierLoc QualifierLoc,
1764 SourceLocation IdentLoc,
1765 NamedDecl *Nominated,
1766 DeclContext *CommonAncestor)
1767 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
1768 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
1769 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
1772 /// \brief Retrieve the nested-name-specifier that qualifies the
1773 /// name of the namespace, with source-location information.
1774 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1776 /// \brief Retrieve the nested-name-specifier that qualifies the
1777 /// name of the namespace.
1778 NestedNameSpecifier *getQualifier() const {
1779 return QualifierLoc.getNestedNameSpecifier();
1782 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1783 const NamedDecl *getNominatedNamespaceAsWritten() const {
1784 return NominatedNamespace;
1787 /// getNominatedNamespace - Returns namespace nominated by using-directive.
1788 NamespaceDecl *getNominatedNamespace();
1790 const NamespaceDecl *getNominatedNamespace() const {
1791 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1794 /// \brief Returns the common ancestor context of this using-directive and
1795 /// its nominated namespace.
1796 DeclContext *getCommonAncestor() { return CommonAncestor; }
1797 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1799 /// \brief Return the location of the "using" keyword.
1800 SourceLocation getUsingLoc() const { return UsingLoc; }
1802 // FIXME: Could omit 'Key' in name.
1803 /// getNamespaceKeyLocation - Returns location of namespace keyword.
1804 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1806 /// getIdentLocation - Returns location of identifier.
1807 SourceLocation getIdentLocation() const { return getLocation(); }
1809 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1810 SourceLocation UsingLoc,
1811 SourceLocation NamespaceLoc,
1812 NestedNameSpecifierLoc QualifierLoc,
1813 SourceLocation IdentLoc,
1814 NamedDecl *Nominated,
1815 DeclContext *CommonAncestor);
1817 SourceRange getSourceRange() const {
1818 return SourceRange(UsingLoc, getLocation());
1821 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1822 static bool classof(const UsingDirectiveDecl *D) { return true; }
1823 static bool classofKind(Kind K) { return K == UsingDirective; }
1825 // Friend for getUsingDirectiveName.
1826 friend class DeclContext;
1828 friend class ASTDeclReader;
1831 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1834 /// namespace Foo = Bar;
1836 class NamespaceAliasDecl : public NamedDecl {
1837 /// \brief The location of the "namespace" keyword.
1838 SourceLocation NamespaceLoc;
1840 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
1841 SourceLocation IdentLoc;
1843 /// \brief The nested-name-specifier that precedes the namespace.
1844 NestedNameSpecifierLoc QualifierLoc;
1846 /// Namespace - The Decl that this alias points to. Can either be a
1847 /// NamespaceDecl or a NamespaceAliasDecl.
1848 NamedDecl *Namespace;
1850 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
1851 SourceLocation AliasLoc, IdentifierInfo *Alias,
1852 NestedNameSpecifierLoc QualifierLoc,
1853 SourceLocation IdentLoc, NamedDecl *Namespace)
1854 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
1855 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
1856 QualifierLoc(QualifierLoc), Namespace(Namespace) { }
1858 friend class ASTDeclReader;
1861 /// \brief Retrieve the nested-name-specifier that qualifies the
1862 /// name of the namespace, with source-location information.
1863 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1865 /// \brief Retrieve the nested-name-specifier that qualifies the
1866 /// name of the namespace.
1867 NestedNameSpecifier *getQualifier() const {
1868 return QualifierLoc.getNestedNameSpecifier();
1871 /// \brief Retrieve the namespace declaration aliased by this directive.
1872 NamespaceDecl *getNamespace() {
1873 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1874 return AD->getNamespace();
1876 return cast<NamespaceDecl>(Namespace);
1879 const NamespaceDecl *getNamespace() const {
1880 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1883 /// Returns the location of the alias name, i.e. 'foo' in
1884 /// "namespace foo = ns::bar;".
1885 SourceLocation getAliasLoc() const { return getLocation(); }
1887 /// Returns the location of the 'namespace' keyword.
1888 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
1890 /// Returns the location of the identifier in the named namespace.
1891 SourceLocation getTargetNameLoc() const { return IdentLoc; }
1893 /// \brief Retrieve the namespace that this alias refers to, which
1894 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1895 NamedDecl *getAliasedNamespace() const { return Namespace; }
1897 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1898 SourceLocation NamespaceLoc,
1899 SourceLocation AliasLoc,
1900 IdentifierInfo *Alias,
1901 NestedNameSpecifierLoc QualifierLoc,
1902 SourceLocation IdentLoc,
1903 NamedDecl *Namespace);
1905 virtual SourceRange getSourceRange() const {
1906 return SourceRange(NamespaceLoc, IdentLoc);
1909 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1910 static bool classof(const NamespaceAliasDecl *D) { return true; }
1911 static bool classofKind(Kind K) { return K == NamespaceAlias; }
1914 /// UsingShadowDecl - Represents a shadow declaration introduced into
1915 /// a scope by a (resolved) using declaration. For example,
1921 /// using A::foo(); // <- a UsingDecl
1922 /// // Also creates a UsingShadowDecl for A::foo in B
1925 class UsingShadowDecl : public NamedDecl {
1926 /// The referenced declaration.
1927 NamedDecl *Underlying;
1929 /// \brief The using declaration which introduced this decl or the next using
1930 /// shadow declaration contained in the aforementioned using declaration.
1931 NamedDecl *UsingOrNextShadow;
1932 friend class UsingDecl;
1934 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1936 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
1938 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
1940 setDeclName(Target->getDeclName());
1941 IdentifierNamespace = Target->getIdentifierNamespace();
1947 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1948 SourceLocation Loc, UsingDecl *Using,
1949 NamedDecl *Target) {
1950 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1953 /// \brief Gets the underlying declaration which has been brought into the
1955 NamedDecl *getTargetDecl() const { return Underlying; }
1957 /// \brief Sets the underlying declaration which has been brought into the
1959 void setTargetDecl(NamedDecl* ND) {
1960 assert(ND && "Target decl is null!");
1962 IdentifierNamespace = ND->getIdentifierNamespace();
1965 /// \brief Gets the using declaration to which this declaration is tied.
1966 UsingDecl *getUsingDecl() const;
1968 /// \brief The next using shadow declaration contained in the shadow decl
1969 /// chain of the using declaration which introduced this decl.
1970 UsingShadowDecl *getNextUsingShadowDecl() const {
1971 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
1974 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1975 static bool classof(const UsingShadowDecl *D) { return true; }
1976 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1978 friend class ASTDeclReader;
1979 friend class ASTDeclWriter;
1982 /// UsingDecl - Represents a C++ using-declaration. For example:
1983 /// using someNameSpace::someIdentifier;
1984 class UsingDecl : public NamedDecl {
1985 /// \brief The source location of the "using" location itself.
1986 SourceLocation UsingLocation;
1988 /// \brief The nested-name-specifier that precedes the name.
1989 NestedNameSpecifierLoc QualifierLoc;
1991 /// DNLoc - Provides source/type location info for the
1992 /// declaration name embedded in the ValueDecl base class.
1993 DeclarationNameLoc DNLoc;
1995 /// \brief The first shadow declaration of the shadow decl chain associated
1996 /// with this using declaration.
1997 UsingShadowDecl *FirstUsingShadow;
1999 // \brief Has 'typename' keyword.
2002 UsingDecl(DeclContext *DC, SourceLocation UL,
2003 NestedNameSpecifierLoc QualifierLoc,
2004 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2005 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2006 UsingLocation(UL), QualifierLoc(QualifierLoc),
2007 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg) {
2011 /// \brief Returns the source location of the "using" keyword.
2012 SourceLocation getUsingLocation() const { return UsingLocation; }
2014 /// \brief Set the source location of the 'using' keyword.
2015 void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2017 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2018 /// with source-location information.
2019 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2021 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2022 NestedNameSpecifier *getQualifier() const {
2023 return QualifierLoc.getNestedNameSpecifier();
2026 /// \brief Retrieve the source range of the nested-name-specifier
2027 /// that qualifies the name.
2028 SourceRange getQualifierRange() const {
2029 return QualifierLoc.getSourceRange();
2032 DeclarationNameInfo getNameInfo() const {
2033 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2036 /// \brief Return true if the using declaration has 'typename'.
2037 bool isTypeName() const { return IsTypeName; }
2039 /// \brief Sets whether the using declaration has 'typename'.
2040 void setTypeName(bool TN) { IsTypeName = TN; }
2042 /// \brief Iterates through the using shadow declarations assosiated with
2043 /// this using declaration.
2044 class shadow_iterator {
2045 /// \brief The current using shadow declaration.
2046 UsingShadowDecl *Current;
2049 typedef UsingShadowDecl* value_type;
2050 typedef UsingShadowDecl* reference;
2051 typedef UsingShadowDecl* pointer;
2052 typedef std::forward_iterator_tag iterator_category;
2053 typedef std::ptrdiff_t difference_type;
2055 shadow_iterator() : Current(0) { }
2056 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2058 reference operator*() const { return Current; }
2059 pointer operator->() const { return Current; }
2061 shadow_iterator& operator++() {
2062 Current = Current->getNextUsingShadowDecl();
2066 shadow_iterator operator++(int) {
2067 shadow_iterator tmp(*this);
2072 friend bool operator==(shadow_iterator x, shadow_iterator y) {
2073 return x.Current == y.Current;
2075 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2076 return x.Current != y.Current;
2080 shadow_iterator shadow_begin() const {
2081 return shadow_iterator(FirstUsingShadow);
2083 shadow_iterator shadow_end() const { return shadow_iterator(); }
2085 /// \brief Return the number of shadowed declarations associated with this
2086 /// using declaration.
2087 unsigned shadow_size() const {
2088 return std::distance(shadow_begin(), shadow_end());
2091 void addShadowDecl(UsingShadowDecl *S);
2092 void removeShadowDecl(UsingShadowDecl *S);
2094 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2095 SourceLocation UsingL,
2096 NestedNameSpecifierLoc QualifierLoc,
2097 const DeclarationNameInfo &NameInfo,
2098 bool IsTypeNameArg);
2100 SourceRange getSourceRange() const {
2101 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2104 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2105 static bool classof(const UsingDecl *D) { return true; }
2106 static bool classofKind(Kind K) { return K == Using; }
2108 friend class ASTDeclReader;
2109 friend class ASTDeclWriter;
2112 /// UnresolvedUsingValueDecl - Represents a dependent using
2113 /// declaration which was not marked with 'typename'. Unlike
2114 /// non-dependent using declarations, these *only* bring through
2115 /// non-types; otherwise they would break two-phase lookup.
2117 /// template <class T> class A : public Base<T> {
2118 /// using Base<T>::foo;
2120 class UnresolvedUsingValueDecl : public ValueDecl {
2121 /// \brief The source location of the 'using' keyword
2122 SourceLocation UsingLocation;
2124 /// \brief The nested-name-specifier that precedes the name.
2125 NestedNameSpecifierLoc QualifierLoc;
2127 /// DNLoc - Provides source/type location info for the
2128 /// declaration name embedded in the ValueDecl base class.
2129 DeclarationNameLoc DNLoc;
2131 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2132 SourceLocation UsingLoc,
2133 NestedNameSpecifierLoc QualifierLoc,
2134 const DeclarationNameInfo &NameInfo)
2135 : ValueDecl(UnresolvedUsingValue, DC,
2136 NameInfo.getLoc(), NameInfo.getName(), Ty),
2137 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2138 DNLoc(NameInfo.getInfo())
2142 /// \brief Returns the source location of the 'using' keyword.
2143 SourceLocation getUsingLoc() const { return UsingLocation; }
2145 /// \brief Set the source location of the 'using' keyword.
2146 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2148 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2149 /// with source-location information.
2150 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2152 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2153 NestedNameSpecifier *getQualifier() const {
2154 return QualifierLoc.getNestedNameSpecifier();
2157 /// \brief Retrieve the source range of the nested-name-specifier
2158 /// that qualifies the name.
2159 SourceRange getQualifierRange() const {
2160 return QualifierLoc.getSourceRange();
2163 DeclarationNameInfo getNameInfo() const {
2164 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2167 static UnresolvedUsingValueDecl *
2168 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2169 NestedNameSpecifierLoc QualifierLoc,
2170 const DeclarationNameInfo &NameInfo);
2172 SourceRange getSourceRange() const {
2173 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2176 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2177 static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2178 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2180 friend class ASTDeclReader;
2181 friend class ASTDeclWriter;
2184 /// UnresolvedUsingTypenameDecl - Represents a dependent using
2185 /// declaration which was marked with 'typename'.
2187 /// template <class T> class A : public Base<T> {
2188 /// using typename Base<T>::foo;
2191 /// The type associated with a unresolved using typename decl is
2192 /// currently always a typename type.
2193 class UnresolvedUsingTypenameDecl : public TypeDecl {
2194 /// \brief The source location of the 'using' keyword
2195 SourceLocation UsingLocation;
2197 /// \brief The source location of the 'typename' keyword
2198 SourceLocation TypenameLocation;
2200 /// \brief The nested-name-specifier that precedes the name.
2201 NestedNameSpecifierLoc QualifierLoc;
2203 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2204 SourceLocation TypenameLoc,
2205 NestedNameSpecifierLoc QualifierLoc,
2206 SourceLocation TargetNameLoc,
2207 IdentifierInfo *TargetName)
2208 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
2209 UsingLocation(UsingLoc), TypenameLocation(TypenameLoc),
2210 QualifierLoc(QualifierLoc) { }
2212 friend class ASTDeclReader;
2215 /// \brief Returns the source location of the 'using' keyword.
2216 SourceLocation getUsingLoc() const { return UsingLocation; }
2218 /// \brief Returns the source location of the 'typename' keyword.
2219 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2221 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2222 /// with source-location information.
2223 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2225 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2226 NestedNameSpecifier *getQualifier() const {
2227 return QualifierLoc.getNestedNameSpecifier();
2230 /// \brief Retrieve the source range of the nested-name-specifier
2231 /// that qualifies the name.
2232 SourceRange getQualifierRange() const {
2233 return QualifierLoc.getSourceRange();
2236 // FIXME: DeclarationNameInfo
2237 static UnresolvedUsingTypenameDecl *
2238 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2239 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2240 SourceLocation TargetNameLoc, DeclarationName TargetName);
2242 SourceRange getSourceRange() const {
2243 return SourceRange(UsingLocation, getLocation());
2246 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2247 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2248 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2251 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
2252 class StaticAssertDecl : public Decl {
2254 StringLiteral *Message;
2256 StaticAssertDecl(DeclContext *DC, SourceLocation L,
2257 Expr *assertexpr, StringLiteral *message)
2258 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
2261 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2262 SourceLocation L, Expr *AssertExpr,
2263 StringLiteral *Message);
2265 Expr *getAssertExpr() { return AssertExpr; }
2266 const Expr *getAssertExpr() const { return AssertExpr; }
2268 StringLiteral *getMessage() { return Message; }
2269 const StringLiteral *getMessage() const { return Message; }
2271 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2272 static bool classof(StaticAssertDecl *D) { return true; }
2273 static bool classofKind(Kind K) { return K == StaticAssert; }
2275 friend class ASTDeclReader;
2278 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
2279 /// into a diagnostic with <<.
2280 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2281 AccessSpecifier AS);
2283 } // end namespace clang