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 //===----------------------------------------------------------------------===//
11 /// \brief Defines the C++ Decl subclasses, other than those for templates
12 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_DECLCXX_H
17 #define LLVM_CLANG_AST_DECLCXX_H
19 #include "clang/AST/ASTUnresolvedSet.h"
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/TypeLoc.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/PointerIntPair.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/Support/Compiler.h"
31 class ClassTemplateDecl;
32 class ClassTemplateSpecializationDecl;
35 class CXXConstructorDecl;
36 class CXXConversionDecl;
37 class CXXDestructorDecl;
40 class CXXMemberLookupCriteria;
41 class CXXFinalOverriderMap;
42 class CXXIndirectPrimaryBaseSet;
47 /// \brief Represents any kind of function declaration, whether it is a
48 /// concrete function or a function template.
49 class AnyFunctionDecl {
52 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
55 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
56 AnyFunctionDecl(FunctionTemplateDecl *FTD);
58 /// \brief Implicily converts any function or function template into a
59 /// named declaration.
60 operator NamedDecl *() const { return Function; }
62 /// \brief Retrieve the underlying function or function template.
63 NamedDecl *get() const { return Function; }
65 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
66 return AnyFunctionDecl(ND);
70 } // end namespace clang
73 // Provide PointerLikeTypeTraits for non-cvr pointers.
75 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
77 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
80 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
81 return ::clang::AnyFunctionDecl::getFromNamedDecl(
82 static_cast< ::clang::NamedDecl*>(P));
85 enum { NumLowBitsAvailable = 2 };
88 } // end namespace llvm
92 /// \brief Represents an access specifier followed by colon ':'.
94 /// An objects of this class represents sugar for the syntactic occurrence
95 /// of an access specifier followed by a colon in the list of member
96 /// specifiers of a C++ class definition.
98 /// Note that they do not represent other uses of access specifiers,
99 /// such as those occurring in a list of base specifiers.
100 /// Also note that this class has nothing to do with so-called
101 /// "access declarations" (C++98 11.3 [class.access.dcl]).
102 class AccessSpecDecl : public Decl {
103 virtual void anchor();
104 /// \brief The location of the ':'.
105 SourceLocation ColonLoc;
107 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
108 SourceLocation ASLoc, SourceLocation ColonLoc)
109 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
112 AccessSpecDecl(EmptyShell Empty)
113 : Decl(AccessSpec, Empty) { }
115 /// \brief The location of the access specifier.
116 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
117 /// \brief Sets the location of the access specifier.
118 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
120 /// \brief The location of the colon following the access specifier.
121 SourceLocation getColonLoc() const { return ColonLoc; }
122 /// \brief Sets the location of the colon.
123 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
125 SourceRange getSourceRange() const LLVM_READONLY {
126 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
129 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
130 DeclContext *DC, SourceLocation ASLoc,
131 SourceLocation ColonLoc) {
132 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
134 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
136 // Implement isa/cast/dyncast/etc.
137 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
138 static bool classofKind(Kind K) { return K == AccessSpec; }
142 /// \brief Represents a base class of a C++ class.
144 /// Each CXXBaseSpecifier represents a single, direct base class (or
145 /// struct) of a C++ class (or struct). It specifies the type of that
146 /// base class, whether it is a virtual or non-virtual base, and what
147 /// level of access (public, protected, private) is used for the
148 /// derivation. For example:
153 /// class C : public virtual A, protected B { };
156 /// In this code, C will have two CXXBaseSpecifiers, one for "public
157 /// virtual A" and the other for "protected B".
158 class CXXBaseSpecifier {
159 /// \brief The source code range that covers the full base
160 /// specifier, including the "virtual" (if present) and access
161 /// specifier (if present).
164 /// \brief The source location of the ellipsis, if this is a pack
166 SourceLocation EllipsisLoc;
168 /// \brief Whether this is a virtual base class or not.
171 /// \brief Whether this is the base of a class (true) or of a struct (false).
173 /// This determines the mapping from the access specifier as written in the
174 /// source code to the access specifier used for semantic analysis.
175 bool BaseOfClass : 1;
177 /// \brief Access specifier as written in the source code (may be AS_none).
179 /// The actual type of data stored here is an AccessSpecifier, but we use
180 /// "unsigned" here to work around a VC++ bug.
183 /// \brief Whether the class contains a using declaration
184 /// to inherit the named class's constructors.
185 bool InheritConstructors : 1;
187 /// \brief The type of the base class.
189 /// This will be a class or struct (or a typedef of such). The source code
190 /// range does not include the \c virtual or the access specifier.
191 TypeSourceInfo *BaseTypeInfo;
194 CXXBaseSpecifier() { }
196 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
197 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
198 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
199 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
201 /// \brief Retrieves the source range that contains the entire base specifier.
202 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
203 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
204 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
206 /// \brief Determines whether the base class is a virtual base class (or not).
207 bool isVirtual() const { return Virtual; }
209 /// \brief Determine whether this base class is a base of a class declared
210 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
211 bool isBaseOfClass() const { return BaseOfClass; }
213 /// \brief Determine whether this base specifier is a pack expansion.
214 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
216 /// \brief Determine whether this base class's constructors get inherited.
217 bool getInheritConstructors() const { return InheritConstructors; }
219 /// \brief Set that this base class's constructors should be inherited.
220 void setInheritConstructors(bool Inherit = true) {
221 InheritConstructors = Inherit;
224 /// \brief For a pack expansion, determine the location of the ellipsis.
225 SourceLocation getEllipsisLoc() const {
229 /// \brief Returns the access specifier for this base specifier.
231 /// This is the actual base specifier as used for semantic analysis, so
232 /// the result can never be AS_none. To retrieve the access specifier as
233 /// written in the source code, use getAccessSpecifierAsWritten().
234 AccessSpecifier getAccessSpecifier() const {
235 if ((AccessSpecifier)Access == AS_none)
236 return BaseOfClass? AS_private : AS_public;
238 return (AccessSpecifier)Access;
241 /// \brief Retrieves the access specifier as written in the source code
242 /// (which may mean that no access specifier was explicitly written).
244 /// Use getAccessSpecifier() to retrieve the access specifier for use in
245 /// semantic analysis.
246 AccessSpecifier getAccessSpecifierAsWritten() const {
247 return (AccessSpecifier)Access;
250 /// \brief Retrieves the type of the base class.
252 /// This type will always be an unqualified class type.
253 QualType getType() const {
254 return BaseTypeInfo->getType().getUnqualifiedType();
257 /// \brief Retrieves the type and source location of the base class.
258 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
261 /// The inheritance model to use for member pointers of a given CXXRecordDecl.
262 enum MSInheritanceModel {
264 MSIM_SinglePolymorphic,
266 MSIM_MultiplePolymorphic,
271 /// \brief Represents a C++ struct/union/class.
273 /// FIXME: This class will disappear once we've properly taught RecordDecl
274 /// to deal with C++-specific things.
275 class CXXRecordDecl : public RecordDecl {
277 friend void TagDecl::startDefinition();
279 /// Values used in DefinitionData fields to represent special members.
280 enum SpecialMemberFlags {
281 SMF_DefaultConstructor = 0x1,
282 SMF_CopyConstructor = 0x2,
283 SMF_MoveConstructor = 0x4,
284 SMF_CopyAssignment = 0x8,
285 SMF_MoveAssignment = 0x10,
286 SMF_Destructor = 0x20,
290 struct DefinitionData {
291 DefinitionData(CXXRecordDecl *D);
293 /// \brief True if this class has any user-declared constructors.
294 bool UserDeclaredConstructor : 1;
296 /// \brief The user-declared special members which this class has.
297 unsigned UserDeclaredSpecialMembers : 6;
299 /// \brief True when this class is an aggregate.
302 /// \brief True when this class is a POD-type.
303 bool PlainOldData : 1;
305 /// true when this class is empty for traits purposes,
306 /// i.e. has no data members other than 0-width bit-fields, has no
307 /// virtual function/base, and doesn't inherit from a non-empty
308 /// class. Doesn't take union-ness into account.
311 /// \brief True when this class is polymorphic, i.e., has at
312 /// least one virtual member or derives from a polymorphic class.
313 bool Polymorphic : 1;
315 /// \brief True when this class is abstract, i.e., has at least
316 /// one pure virtual function, (that can come from a base class).
319 /// \brief True when this class has standard layout.
321 /// C++11 [class]p7. A standard-layout class is a class that:
322 /// * has no non-static data members of type non-standard-layout class (or
323 /// array of such types) or reference,
324 /// * has no virtual functions (10.3) and no virtual base classes (10.1),
325 /// * has the same access control (Clause 11) for all non-static data
327 /// * has no non-standard-layout base classes,
328 /// * either has no non-static data members in the most derived class and at
329 /// most one base class with non-static data members, or has no base
330 /// classes with non-static data members, and
331 /// * has no base classes of the same type as the first non-static data
333 bool IsStandardLayout : 1;
335 /// \brief True when there are no non-empty base classes.
337 /// This is a helper bit of state used to implement IsStandardLayout more
339 bool HasNoNonEmptyBases : 1;
341 /// \brief True when there are private non-static data members.
342 bool HasPrivateFields : 1;
344 /// \brief True when there are protected non-static data members.
345 bool HasProtectedFields : 1;
347 /// \brief True when there are private non-static data members.
348 bool HasPublicFields : 1;
350 /// \brief True if this class (or any subobject) has mutable fields.
351 bool HasMutableFields : 1;
353 /// \brief True if there no non-field members declared by the user.
354 bool HasOnlyCMembers : 1;
356 /// \brief True if any field has an in-class initializer.
357 bool HasInClassInitializer : 1;
359 /// \brief True if any field is of reference type, and does not have an
360 /// in-class initializer.
362 /// In this case, value-initialization of this class is illegal in C++98
363 /// even if the class has a trivial default constructor.
364 bool HasUninitializedReferenceMember : 1;
366 /// \brief These flags are \c true if a defaulted corresponding special
367 /// member can't be fully analyzed without performing overload resolution.
369 bool NeedOverloadResolutionForMoveConstructor : 1;
370 bool NeedOverloadResolutionForMoveAssignment : 1;
371 bool NeedOverloadResolutionForDestructor : 1;
374 /// \brief These flags are \c true if an implicit defaulted corresponding
375 /// special member would be defined as deleted.
377 bool DefaultedMoveConstructorIsDeleted : 1;
378 bool DefaultedMoveAssignmentIsDeleted : 1;
379 bool DefaultedDestructorIsDeleted : 1;
382 /// \brief The trivial special members which this class has, per
383 /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
384 /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
386 /// This excludes any user-declared but not user-provided special members
387 /// which have been declared but not yet defined.
388 unsigned HasTrivialSpecialMembers : 6;
390 /// \brief The declared special members of this class which are known to be
393 /// This excludes any user-declared but not user-provided special members
394 /// which have been declared but not yet defined, and any implicit special
395 /// members which have not yet been declared.
396 unsigned DeclaredNonTrivialSpecialMembers : 6;
398 /// \brief True when this class has a destructor with no semantic effect.
399 bool HasIrrelevantDestructor : 1;
401 /// \brief True when this class has at least one user-declared constexpr
402 /// constructor which is neither the copy nor move constructor.
403 bool HasConstexprNonCopyMoveConstructor : 1;
405 /// \brief True if a defaulted default constructor for this class would
407 bool DefaultedDefaultConstructorIsConstexpr : 1;
409 /// \brief True if this class has a constexpr default constructor.
411 /// This is true for either a user-declared constexpr default constructor
412 /// or an implicitly declared constexpr default constructor..
413 bool HasConstexprDefaultConstructor : 1;
415 /// \brief True when this class contains at least one non-static data
416 /// member or base class of non-literal or volatile type.
417 bool HasNonLiteralTypeFieldsOrBases : 1;
419 /// \brief True when visible conversion functions are already computed
420 /// and are available.
421 bool ComputedVisibleConversions : 1;
423 /// \brief Whether we have a C++11 user-provided default constructor (not
424 /// explicitly deleted or defaulted).
425 bool UserProvidedDefaultConstructor : 1;
427 /// \brief The special members which have been declared for this class,
428 /// either by the user or implicitly.
429 unsigned DeclaredSpecialMembers : 6;
431 /// \brief Whether an implicit copy constructor would have a const-qualified
433 bool ImplicitCopyConstructorHasConstParam : 1;
435 /// \brief Whether an implicit copy assignment operator would have a
436 /// const-qualified parameter.
437 bool ImplicitCopyAssignmentHasConstParam : 1;
439 /// \brief Whether any declared copy constructor has a const-qualified
441 bool HasDeclaredCopyConstructorWithConstParam : 1;
443 /// \brief Whether any declared copy assignment operator has either a
444 /// const-qualified reference parameter or a non-reference parameter.
445 bool HasDeclaredCopyAssignmentWithConstParam : 1;
447 /// \brief Whether this class describes a C++ lambda.
450 /// \brief The number of base class specifiers in Bases.
453 /// \brief The number of virtual base class specifiers in VBases.
456 /// \brief Base classes of this class.
458 /// FIXME: This is wasted space for a union.
459 LazyCXXBaseSpecifiersPtr Bases;
461 /// \brief direct and indirect virtual base classes of this class.
462 LazyCXXBaseSpecifiersPtr VBases;
464 /// \brief The conversion functions of this C++ class (but not its
465 /// inherited conversion functions).
467 /// Each of the entries in this overload set is a CXXConversionDecl.
468 LazyASTUnresolvedSet Conversions;
470 /// \brief The conversion functions of this C++ class and all those
471 /// inherited conversion functions that are visible in this class.
473 /// Each of the entries in this overload set is a CXXConversionDecl or a
474 /// FunctionTemplateDecl.
475 LazyASTUnresolvedSet VisibleConversions;
477 /// \brief The declaration which defines this record.
478 CXXRecordDecl *Definition;
480 /// \brief The first friend declaration in this class, or null if there
483 /// This is actually currently stored in reverse order.
484 LazyDeclPtr FirstFriend;
486 /// \brief Retrieve the set of direct base classes.
487 CXXBaseSpecifier *getBases() const {
488 if (!Bases.isOffset())
490 return getBasesSlowCase();
493 /// \brief Retrieve the set of virtual base classes.
494 CXXBaseSpecifier *getVBases() const {
495 if (!VBases.isOffset())
496 return VBases.get(0);
497 return getVBasesSlowCase();
501 CXXBaseSpecifier *getBasesSlowCase() const;
502 CXXBaseSpecifier *getVBasesSlowCase() const;
505 /// \brief Describes a C++ closure type (generated by a lambda expression).
506 struct LambdaDefinitionData : public DefinitionData {
507 typedef LambdaExpr::Capture Capture;
509 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
510 bool Dependent, bool IsGeneric,
511 LambdaCaptureDefault CaptureDefault)
512 : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
513 CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
514 ManglingNumber(0), ContextDecl(0), Captures(0), MethodTyInfo(Info)
519 /// \brief Whether this lambda is known to be dependent, even if its
520 /// context isn't dependent.
522 /// A lambda with a non-dependent context can be dependent if it occurs
523 /// within the default argument of a function template, because the
524 /// lambda will have been created with the enclosing context as its
525 /// declaration context, rather than function. This is an unfortunate
526 /// artifact of having to parse the default arguments before.
527 unsigned Dependent : 1;
529 /// \brief Whether this lambda is a generic lambda.
530 unsigned IsGenericLambda : 1;
532 /// \brief The Default Capture.
533 unsigned CaptureDefault : 2;
535 /// \brief The number of captures in this lambda is limited 2^NumCaptures.
536 unsigned NumCaptures : 15;
538 /// \brief The number of explicit captures in this lambda.
539 unsigned NumExplicitCaptures : 13;
541 /// \brief The number used to indicate this lambda expression for name
542 /// mangling in the Itanium C++ ABI.
543 unsigned ManglingNumber;
545 /// \brief The declaration that provides context for this lambda, if the
546 /// actual DeclContext does not suffice. This is used for lambdas that
547 /// occur within default arguments of function parameters within the class
548 /// or within a data member initializer.
551 /// \brief The list of captures, both explicit and implicit, for this
555 /// \brief The type of the call method.
556 TypeSourceInfo *MethodTyInfo;
560 struct DefinitionData &data() {
561 assert(DefinitionData && "queried property of class with no definition");
562 return *DefinitionData;
565 const struct DefinitionData &data() const {
566 assert(DefinitionData && "queried property of class with no definition");
567 return *DefinitionData;
570 struct LambdaDefinitionData &getLambdaData() const {
571 assert(DefinitionData && "queried property of lambda with no definition");
572 assert(DefinitionData->IsLambda &&
573 "queried lambda property of non-lambda class");
574 return static_cast<LambdaDefinitionData &>(*DefinitionData);
577 /// \brief The template or declaration that this declaration
578 /// describes or was instantiated from, respectively.
580 /// For non-templates, this value will be null. For record
581 /// declarations that describe a class template, this will be a
582 /// pointer to a ClassTemplateDecl. For member
583 /// classes of class template specializations, this will be the
584 /// MemberSpecializationInfo referring to the member class that was
585 /// instantiated or specialized.
586 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
587 TemplateOrInstantiation;
589 friend class DeclContext;
590 friend class LambdaExpr;
592 /// \brief Called from setBases and addedMember to notify the class that a
593 /// direct or virtual base class or a member of class type has been added.
594 void addedClassSubobject(CXXRecordDecl *Base);
596 /// \brief Notify the class that member has been added.
598 /// This routine helps maintain information about the class based on which
599 /// members have been added. It will be invoked by DeclContext::addDecl()
600 /// whenever a member is added to this record.
601 void addedMember(Decl *D);
603 void markedVirtualFunctionPure();
604 friend void FunctionDecl::setPure(bool);
606 friend class ASTNodeImporter;
608 /// \brief Get the head of our list of friend declarations, possibly
609 /// deserializing the friends from an external AST source.
610 FriendDecl *getFirstFriend() const;
613 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
614 SourceLocation StartLoc, SourceLocation IdLoc,
615 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
618 /// \brief Iterator that traverses the base classes of a class.
619 typedef CXXBaseSpecifier* base_class_iterator;
621 /// \brief Iterator that traverses the base classes of a class.
622 typedef const CXXBaseSpecifier* base_class_const_iterator;
624 /// \brief Iterator that traverses the base classes of a class in reverse
626 typedef std::reverse_iterator<base_class_iterator>
627 reverse_base_class_iterator;
629 /// \brief Iterator that traverses the base classes of a class in reverse
631 typedef std::reverse_iterator<base_class_const_iterator>
632 reverse_base_class_const_iterator;
634 virtual CXXRecordDecl *getCanonicalDecl() {
635 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
637 virtual const CXXRecordDecl *getCanonicalDecl() const {
638 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
641 CXXRecordDecl *getPreviousDecl() {
642 return cast_or_null<CXXRecordDecl>(
643 static_cast<RecordDecl *>(this)->getPreviousDecl());
645 const CXXRecordDecl *getPreviousDecl() const {
646 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
649 CXXRecordDecl *getMostRecentDecl() {
650 return cast<CXXRecordDecl>(
651 static_cast<RecordDecl *>(this)->getMostRecentDecl());
654 const CXXRecordDecl *getMostRecentDecl() const {
655 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
658 CXXRecordDecl *getDefinition() const {
659 if (!DefinitionData) return 0;
660 return data().Definition;
663 bool hasDefinition() const { return DefinitionData != 0; }
665 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
666 SourceLocation StartLoc, SourceLocation IdLoc,
667 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
668 bool DelayTypeCreation = false);
669 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
670 TypeSourceInfo *Info, SourceLocation Loc,
671 bool DependentLambda, bool IsGeneric,
672 LambdaCaptureDefault CaptureDefault);
673 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
675 bool isDynamicClass() const {
676 return data().Polymorphic || data().NumVBases != 0;
679 /// \brief Sets the base classes of this struct or class.
680 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
682 /// \brief Retrieves the number of base classes of this class.
683 unsigned getNumBases() const { return data().NumBases; }
685 base_class_iterator bases_begin() { return data().getBases(); }
686 base_class_const_iterator bases_begin() const { return data().getBases(); }
687 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
688 base_class_const_iterator bases_end() const {
689 return bases_begin() + data().NumBases;
691 reverse_base_class_iterator bases_rbegin() {
692 return reverse_base_class_iterator(bases_end());
694 reverse_base_class_const_iterator bases_rbegin() const {
695 return reverse_base_class_const_iterator(bases_end());
697 reverse_base_class_iterator bases_rend() {
698 return reverse_base_class_iterator(bases_begin());
700 reverse_base_class_const_iterator bases_rend() const {
701 return reverse_base_class_const_iterator(bases_begin());
704 /// \brief Retrieves the number of virtual base classes of this class.
705 unsigned getNumVBases() const { return data().NumVBases; }
707 base_class_iterator vbases_begin() { return data().getVBases(); }
708 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
709 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
710 base_class_const_iterator vbases_end() const {
711 return vbases_begin() + data().NumVBases;
713 reverse_base_class_iterator vbases_rbegin() {
714 return reverse_base_class_iterator(vbases_end());
716 reverse_base_class_const_iterator vbases_rbegin() const {
717 return reverse_base_class_const_iterator(vbases_end());
719 reverse_base_class_iterator vbases_rend() {
720 return reverse_base_class_iterator(vbases_begin());
722 reverse_base_class_const_iterator vbases_rend() const {
723 return reverse_base_class_const_iterator(vbases_begin());
726 /// \brief Determine whether this class has any dependent base classes which
727 /// are not the current instantiation.
728 bool hasAnyDependentBases() const;
730 /// Iterator access to method members. The method iterator visits
731 /// all method members of the class, including non-instance methods,
732 /// special methods, etc.
733 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
735 /// \brief Method begin iterator. Iterates in the order the methods
737 method_iterator method_begin() const {
738 return method_iterator(decls_begin());
740 /// \brief Method past-the-end iterator.
741 method_iterator method_end() const {
742 return method_iterator(decls_end());
745 /// Iterator access to constructor members.
746 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
748 ctor_iterator ctor_begin() const {
749 return ctor_iterator(decls_begin());
751 ctor_iterator ctor_end() const {
752 return ctor_iterator(decls_end());
755 /// An iterator over friend declarations. All of these are defined
757 class friend_iterator;
758 friend_iterator friend_begin() const;
759 friend_iterator friend_end() const;
760 void pushFriendDecl(FriendDecl *FD);
762 /// Determines whether this record has any friends.
763 bool hasFriends() const {
764 return data().FirstFriend.isValid();
767 /// \brief \c true if we know for sure that this class has a single,
768 /// accessible, unambiguous move constructor that is not deleted.
769 bool hasSimpleMoveConstructor() const {
770 return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
771 !data().DefaultedMoveConstructorIsDeleted;
773 /// \brief \c true if we know for sure that this class has a single,
774 /// accessible, unambiguous move assignment operator that is not deleted.
775 bool hasSimpleMoveAssignment() const {
776 return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
777 !data().DefaultedMoveAssignmentIsDeleted;
779 /// \brief \c true if we know for sure that this class has an accessible
780 /// destructor that is not deleted.
781 bool hasSimpleDestructor() const {
782 return !hasUserDeclaredDestructor() &&
783 !data().DefaultedDestructorIsDeleted;
786 /// \brief Determine whether this class has any default constructors.
787 bool hasDefaultConstructor() const {
788 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
789 needsImplicitDefaultConstructor();
792 /// \brief Determine if we need to declare a default constructor for
795 /// This value is used for lazy creation of default constructors.
796 bool needsImplicitDefaultConstructor() const {
797 return !data().UserDeclaredConstructor &&
798 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
801 /// \brief Determine whether this class has any user-declared constructors.
803 /// When true, a default constructor will not be implicitly declared.
804 bool hasUserDeclaredConstructor() const {
805 return data().UserDeclaredConstructor;
808 /// \brief Whether this class has a user-provided default constructor
810 bool hasUserProvidedDefaultConstructor() const {
811 return data().UserProvidedDefaultConstructor;
814 /// \brief Determine whether this class has a user-declared copy constructor.
816 /// When false, a copy constructor will be implicitly declared.
817 bool hasUserDeclaredCopyConstructor() const {
818 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
821 /// \brief Determine whether this class needs an implicit copy
822 /// constructor to be lazily declared.
823 bool needsImplicitCopyConstructor() const {
824 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
827 /// \brief Determine whether we need to eagerly declare a defaulted copy
828 /// constructor for this class.
829 bool needsOverloadResolutionForCopyConstructor() const {
830 return data().HasMutableFields;
833 /// \brief Determine whether an implicit copy constructor for this type
834 /// would have a parameter with a const-qualified reference type.
835 bool implicitCopyConstructorHasConstParam() const {
836 return data().ImplicitCopyConstructorHasConstParam;
839 /// \brief Determine whether this class has a copy constructor with
840 /// a parameter type which is a reference to a const-qualified type.
841 bool hasCopyConstructorWithConstParam() const {
842 return data().HasDeclaredCopyConstructorWithConstParam ||
843 (needsImplicitCopyConstructor() &&
844 implicitCopyConstructorHasConstParam());
847 /// \brief Whether this class has a user-declared move constructor or
848 /// assignment operator.
850 /// When false, a move constructor and assignment operator may be
851 /// implicitly declared.
852 bool hasUserDeclaredMoveOperation() const {
853 return data().UserDeclaredSpecialMembers &
854 (SMF_MoveConstructor | SMF_MoveAssignment);
857 /// \brief Determine whether this class has had a move constructor
858 /// declared by the user.
859 bool hasUserDeclaredMoveConstructor() const {
860 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
863 /// \brief Determine whether this class has a move constructor.
864 bool hasMoveConstructor() const {
865 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
866 needsImplicitMoveConstructor();
869 /// \brief Set that we attempted to declare an implicitly move
870 /// constructor, but overload resolution failed so we deleted it.
871 void setImplicitMoveConstructorIsDeleted() {
872 assert((data().DefaultedMoveConstructorIsDeleted ||
873 needsOverloadResolutionForMoveConstructor()) &&
874 "move constructor should not be deleted");
875 data().DefaultedMoveConstructorIsDeleted = true;
878 /// \brief Determine whether this class should get an implicit move
879 /// constructor or if any existing special member function inhibits this.
880 bool needsImplicitMoveConstructor() const {
881 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
882 !hasUserDeclaredCopyConstructor() &&
883 !hasUserDeclaredCopyAssignment() &&
884 !hasUserDeclaredMoveAssignment() &&
885 !hasUserDeclaredDestructor();
888 /// \brief Determine whether we need to eagerly declare a defaulted move
889 /// constructor for this class.
890 bool needsOverloadResolutionForMoveConstructor() const {
891 return data().NeedOverloadResolutionForMoveConstructor;
894 /// \brief Determine whether this class has a user-declared copy assignment
897 /// When false, a copy assigment operator will be implicitly declared.
898 bool hasUserDeclaredCopyAssignment() const {
899 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
902 /// \brief Determine whether this class needs an implicit copy
903 /// assignment operator to be lazily declared.
904 bool needsImplicitCopyAssignment() const {
905 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
908 /// \brief Determine whether we need to eagerly declare a defaulted copy
909 /// assignment operator for this class.
910 bool needsOverloadResolutionForCopyAssignment() const {
911 return data().HasMutableFields;
914 /// \brief Determine whether an implicit copy assignment operator for this
915 /// type would have a parameter with a const-qualified reference type.
916 bool implicitCopyAssignmentHasConstParam() const {
917 return data().ImplicitCopyAssignmentHasConstParam;
920 /// \brief Determine whether this class has a copy assignment operator with
921 /// a parameter type which is a reference to a const-qualified type or is not
923 bool hasCopyAssignmentWithConstParam() const {
924 return data().HasDeclaredCopyAssignmentWithConstParam ||
925 (needsImplicitCopyAssignment() &&
926 implicitCopyAssignmentHasConstParam());
929 /// \brief Determine whether this class has had a move assignment
930 /// declared by the user.
931 bool hasUserDeclaredMoveAssignment() const {
932 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
935 /// \brief Determine whether this class has a move assignment operator.
936 bool hasMoveAssignment() const {
937 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
938 needsImplicitMoveAssignment();
941 /// \brief Set that we attempted to declare an implicit move assignment
942 /// operator, but overload resolution failed so we deleted it.
943 void setImplicitMoveAssignmentIsDeleted() {
944 assert((data().DefaultedMoveAssignmentIsDeleted ||
945 needsOverloadResolutionForMoveAssignment()) &&
946 "move assignment should not be deleted");
947 data().DefaultedMoveAssignmentIsDeleted = true;
950 /// \brief Determine whether this class should get an implicit move
951 /// assignment operator or if any existing special member function inhibits
953 bool needsImplicitMoveAssignment() const {
954 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
955 !hasUserDeclaredCopyConstructor() &&
956 !hasUserDeclaredCopyAssignment() &&
957 !hasUserDeclaredMoveConstructor() &&
958 !hasUserDeclaredDestructor();
961 /// \brief Determine whether we need to eagerly declare a move assignment
962 /// operator for this class.
963 bool needsOverloadResolutionForMoveAssignment() const {
964 return data().NeedOverloadResolutionForMoveAssignment;
967 /// \brief Determine whether this class has a user-declared destructor.
969 /// When false, a destructor will be implicitly declared.
970 bool hasUserDeclaredDestructor() const {
971 return data().UserDeclaredSpecialMembers & SMF_Destructor;
974 /// \brief Determine whether this class needs an implicit destructor to
975 /// be lazily declared.
976 bool needsImplicitDestructor() const {
977 return !(data().DeclaredSpecialMembers & SMF_Destructor);
980 /// \brief Determine whether we need to eagerly declare a destructor for this
982 bool needsOverloadResolutionForDestructor() const {
983 return data().NeedOverloadResolutionForDestructor;
986 /// \brief Determine whether this class describes a lambda function object.
987 bool isLambda() const { return hasDefinition() && data().IsLambda; }
989 /// \brief Determine whether this class describes a generic
990 /// lambda function object (i.e. function call operator is
992 bool isGenericLambda() const;
994 /// \brief Retrieve the lambda call operator of the closure type
995 /// if this is a closure type.
996 CXXMethodDecl *getLambdaCallOperator() const;
998 /// \brief Retrieve the lambda static invoker, the address of which
999 /// is returned by the conversion operator, and the body of which
1000 /// is forwarded to the lambda call operator.
1001 CXXMethodDecl *getLambdaStaticInvoker() const;
1003 /// \brief Retrieve the generic lambda's template parameter list.
1004 /// Returns null if the class does not represent a lambda or a generic
1006 TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1008 LambdaCaptureDefault getLambdaCaptureDefault() const {
1010 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1013 /// \brief For a closure type, retrieve the mapping from captured
1014 /// variables and \c this to the non-static data members that store the
1015 /// values or references of the captures.
1017 /// \param Captures Will be populated with the mapping from captured
1018 /// variables to the corresponding fields.
1020 /// \param ThisCapture Will be set to the field declaration for the
1021 /// \c this capture.
1023 /// \note No entries will be added for init-captures, as they do not capture
1025 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1026 FieldDecl *&ThisCapture) const;
1028 typedef const LambdaExpr::Capture* capture_const_iterator;
1029 capture_const_iterator captures_begin() const {
1030 return isLambda() ? getLambdaData().Captures : NULL;
1032 capture_const_iterator captures_end() const {
1033 return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
1036 typedef UnresolvedSetIterator conversion_iterator;
1037 conversion_iterator conversion_begin() const {
1038 return data().Conversions.get(getASTContext()).begin();
1040 conversion_iterator conversion_end() const {
1041 return data().Conversions.get(getASTContext()).end();
1044 /// Removes a conversion function from this class. The conversion
1045 /// function must currently be a member of this class. Furthermore,
1046 /// this class must currently be in the process of being defined.
1047 void removeConversion(const NamedDecl *Old);
1049 /// \brief Get all conversion functions visible in current class,
1050 /// including conversion function templates.
1051 std::pair<conversion_iterator, conversion_iterator>
1052 getVisibleConversionFunctions();
1054 /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1055 /// which is a class with no user-declared constructors, no private
1056 /// or protected non-static data members, no base classes, and no virtual
1057 /// functions (C++ [dcl.init.aggr]p1).
1058 bool isAggregate() const { return data().Aggregate; }
1060 /// \brief Whether this class has any in-class initializers
1061 /// for non-static data members.
1062 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1064 /// \brief Whether this class or any of its subobjects has any members of
1065 /// reference type which would make value-initialization ill-formed.
1067 /// Per C++03 [dcl.init]p5:
1068 /// - if T is a non-union class type without a user-declared constructor,
1069 /// then every non-static data member and base-class component of T is
1070 /// value-initialized [...] A program that calls for [...]
1071 /// value-initialization of an entity of reference type is ill-formed.
1072 bool hasUninitializedReferenceMember() const {
1073 return !isUnion() && !hasUserDeclaredConstructor() &&
1074 data().HasUninitializedReferenceMember;
1077 /// \brief Whether this class is a POD-type (C++ [class]p4)
1079 /// For purposes of this function a class is POD if it is an aggregate
1080 /// that has no non-static non-POD data members, no reference data
1081 /// members, no user-defined copy assignment operator and no
1082 /// user-defined destructor.
1084 /// Note that this is the C++ TR1 definition of POD.
1085 bool isPOD() const { return data().PlainOldData; }
1087 /// \brief True if this class is C-like, without C++-specific features, e.g.
1088 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1089 bool isCLike() const;
1091 /// \brief Determine whether this is an empty class in the sense of
1092 /// (C++11 [meta.unary.prop]).
1094 /// A non-union class is empty iff it has a virtual function, virtual base,
1095 /// data member (other than 0-width bit-field) or inherits from a non-empty
1098 /// \note This does NOT include a check for union-ness.
1099 bool isEmpty() const { return data().Empty; }
1101 /// Whether this class is polymorphic (C++ [class.virtual]),
1102 /// which means that the class contains or inherits a virtual function.
1103 bool isPolymorphic() const { return data().Polymorphic; }
1105 /// \brief Determine whether this class has a pure virtual function.
1107 /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1108 /// a pure virtual function or inherits a pure virtual function that is
1110 bool isAbstract() const { return data().Abstract; }
1112 /// \brief Determine whether this class has standard layout per
1114 bool isStandardLayout() const { return data().IsStandardLayout; }
1116 /// \brief Determine whether this class, or any of its class subobjects,
1117 /// contains a mutable field.
1118 bool hasMutableFields() const { return data().HasMutableFields; }
1120 /// \brief Determine whether this class has a trivial default constructor
1121 /// (C++11 [class.ctor]p5).
1122 bool hasTrivialDefaultConstructor() const {
1123 return hasDefaultConstructor() &&
1124 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1127 /// \brief Determine whether this class has a non-trivial default constructor
1128 /// (C++11 [class.ctor]p5).
1129 bool hasNonTrivialDefaultConstructor() const {
1130 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1131 (needsImplicitDefaultConstructor() &&
1132 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1135 /// \brief Determine whether this class has at least one constexpr constructor
1136 /// other than the copy or move constructors.
1137 bool hasConstexprNonCopyMoveConstructor() const {
1138 return data().HasConstexprNonCopyMoveConstructor ||
1139 (needsImplicitDefaultConstructor() &&
1140 defaultedDefaultConstructorIsConstexpr());
1143 /// \brief Determine whether a defaulted default constructor for this class
1144 /// would be constexpr.
1145 bool defaultedDefaultConstructorIsConstexpr() const {
1146 return data().DefaultedDefaultConstructorIsConstexpr &&
1147 (!isUnion() || hasInClassInitializer());
1150 /// \brief Determine whether this class has a constexpr default constructor.
1151 bool hasConstexprDefaultConstructor() const {
1152 return data().HasConstexprDefaultConstructor ||
1153 (needsImplicitDefaultConstructor() &&
1154 defaultedDefaultConstructorIsConstexpr());
1157 /// \brief Determine whether this class has a trivial copy constructor
1158 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1159 bool hasTrivialCopyConstructor() const {
1160 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1163 /// \brief Determine whether this class has a non-trivial copy constructor
1164 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1165 bool hasNonTrivialCopyConstructor() const {
1166 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1167 !hasTrivialCopyConstructor();
1170 /// \brief Determine whether this class has a trivial move constructor
1171 /// (C++11 [class.copy]p12)
1172 bool hasTrivialMoveConstructor() const {
1173 return hasMoveConstructor() &&
1174 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1177 /// \brief Determine whether this class has a non-trivial move constructor
1178 /// (C++11 [class.copy]p12)
1179 bool hasNonTrivialMoveConstructor() const {
1180 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1181 (needsImplicitMoveConstructor() &&
1182 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1185 /// \brief Determine whether this class has a trivial copy assignment operator
1186 /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1187 bool hasTrivialCopyAssignment() const {
1188 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1191 /// \brief Determine whether this class has a non-trivial copy assignment
1192 /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1193 bool hasNonTrivialCopyAssignment() const {
1194 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1195 !hasTrivialCopyAssignment();
1198 /// \brief Determine whether this class has a trivial move assignment operator
1199 /// (C++11 [class.copy]p25)
1200 bool hasTrivialMoveAssignment() const {
1201 return hasMoveAssignment() &&
1202 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1205 /// \brief Determine whether this class has a non-trivial move assignment
1206 /// operator (C++11 [class.copy]p25)
1207 bool hasNonTrivialMoveAssignment() const {
1208 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1209 (needsImplicitMoveAssignment() &&
1210 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1213 /// \brief Determine whether this class has a trivial destructor
1214 /// (C++ [class.dtor]p3)
1215 bool hasTrivialDestructor() const {
1216 return data().HasTrivialSpecialMembers & SMF_Destructor;
1219 /// \brief Determine whether this class has a non-trivial destructor
1220 /// (C++ [class.dtor]p3)
1221 bool hasNonTrivialDestructor() const {
1222 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1225 /// \brief Determine whether this class has a destructor which has no
1226 /// semantic effect.
1228 /// Any such destructor will be trivial, public, defaulted and not deleted,
1229 /// and will call only irrelevant destructors.
1230 bool hasIrrelevantDestructor() const {
1231 return data().HasIrrelevantDestructor;
1234 /// \brief Determine whether this class has a non-literal or/ volatile type
1235 /// non-static data member or base class.
1236 bool hasNonLiteralTypeFieldsOrBases() const {
1237 return data().HasNonLiteralTypeFieldsOrBases;
1240 /// \brief Determine whether this class is considered trivially copyable per
1241 /// (C++11 [class]p6).
1242 bool isTriviallyCopyable() const;
1244 /// \brief Determine whether this class is considered trivial.
1246 /// C++11 [class]p6:
1247 /// "A trivial class is a class that has a trivial default constructor and
1248 /// is trivially copiable."
1249 bool isTrivial() const {
1250 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1253 /// \brief Determine whether this class is a literal type.
1255 /// C++11 [basic.types]p10:
1256 /// A class type that has all the following properties:
1257 /// - it has a trivial destructor
1258 /// - every constructor call and full-expression in the
1259 /// brace-or-equal-intializers for non-static data members (if any) is
1260 /// a constant expression.
1261 /// - it is an aggregate type or has at least one constexpr constructor
1262 /// or constructor template that is not a copy or move constructor, and
1263 /// - all of its non-static data members and base classes are of literal
1266 /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1267 /// treating types with trivial default constructors as literal types.
1268 bool isLiteral() const {
1269 return hasTrivialDestructor() &&
1270 (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1271 hasTrivialDefaultConstructor()) &&
1272 !hasNonLiteralTypeFieldsOrBases();
1275 /// \brief If this record is an instantiation of a member class,
1276 /// retrieves the member class from which it was instantiated.
1278 /// This routine will return non-null for (non-templated) member
1279 /// classes of class templates. For example, given:
1282 /// template<typename T>
1288 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1289 /// whose parent is the class template specialization X<int>. For
1290 /// this declaration, getInstantiatedFromMemberClass() will return
1291 /// the CXXRecordDecl X<T>::A. When a complete definition of
1292 /// X<int>::A is required, it will be instantiated from the
1293 /// declaration returned by getInstantiatedFromMemberClass().
1294 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1296 /// \brief If this class is an instantiation of a member class of a
1297 /// class template specialization, retrieves the member specialization
1299 MemberSpecializationInfo *getMemberSpecializationInfo() const {
1300 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1303 /// \brief Specify that this record is an instantiation of the
1304 /// member class \p RD.
1305 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1306 TemplateSpecializationKind TSK);
1308 /// \brief Retrieves the class template that is described by this
1309 /// class declaration.
1311 /// Every class template is represented as a ClassTemplateDecl and a
1312 /// CXXRecordDecl. The former contains template properties (such as
1313 /// the template parameter lists) while the latter contains the
1314 /// actual description of the template's
1315 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1316 /// CXXRecordDecl that from a ClassTemplateDecl, while
1317 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1318 /// a CXXRecordDecl.
1319 ClassTemplateDecl *getDescribedClassTemplate() const {
1320 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1323 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1324 TemplateOrInstantiation = Template;
1327 /// \brief Determine whether this particular class is a specialization or
1328 /// instantiation of a class template or member class of a class template,
1329 /// and how it was instantiated or specialized.
1330 TemplateSpecializationKind getTemplateSpecializationKind() const;
1332 /// \brief Set the kind of specialization or template instantiation this is.
1333 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1335 /// \brief Returns the destructor decl for this class.
1336 CXXDestructorDecl *getDestructor() const;
1338 /// \brief If the class is a local class [class.local], returns
1339 /// the enclosing function declaration.
1340 const FunctionDecl *isLocalClass() const {
1341 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1342 return RD->isLocalClass();
1344 return dyn_cast<FunctionDecl>(getDeclContext());
1347 FunctionDecl *isLocalClass() {
1348 return const_cast<FunctionDecl*>(
1349 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1352 /// \brief Determine whether this dependent class is a current instantiation,
1353 /// when viewed from within the given context.
1354 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1356 /// \brief Determine whether this class is derived from the class \p Base.
1358 /// This routine only determines whether this class is derived from \p Base,
1359 /// but does not account for factors that may make a Derived -> Base class
1360 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1361 /// base class subobjects.
1363 /// \param Base the base class we are searching for.
1365 /// \returns true if this class is derived from Base, false otherwise.
1366 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1368 /// \brief Determine whether this class is derived from the type \p Base.
1370 /// This routine only determines whether this class is derived from \p Base,
1371 /// but does not account for factors that may make a Derived -> Base class
1372 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1373 /// base class subobjects.
1375 /// \param Base the base class we are searching for.
1377 /// \param Paths will contain the paths taken from the current class to the
1378 /// given \p Base class.
1380 /// \returns true if this class is derived from \p Base, false otherwise.
1382 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1383 /// tangling input and output in \p Paths
1384 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1386 /// \brief Determine whether this class is virtually derived from
1387 /// the class \p Base.
1389 /// This routine only determines whether this class is virtually
1390 /// derived from \p Base, but does not account for factors that may
1391 /// make a Derived -> Base class ill-formed, such as
1392 /// private/protected inheritance or multiple, ambiguous base class
1395 /// \param Base the base class we are searching for.
1397 /// \returns true if this class is virtually derived from Base,
1398 /// false otherwise.
1399 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1401 /// \brief Determine whether this class is provably not derived from
1402 /// the type \p Base.
1403 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1405 /// \brief Function type used by forallBases() as a callback.
1407 /// \param BaseDefinition the definition of the base class
1409 /// \returns true if this base matched the search criteria
1410 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1413 /// \brief Determines if the given callback holds for all the direct
1414 /// or indirect base classes of this type.
1416 /// The class itself does not count as a base class. This routine
1417 /// returns false if the class has non-computable base classes.
1419 /// \param BaseMatches Callback invoked for each (direct or indirect) base
1420 /// class of this type, or if \p AllowShortCircuit is true then until a call
1423 /// \param UserData Passed as the second argument of every call to
1426 /// \param AllowShortCircuit if false, forces the callback to be called
1427 /// for every base class, even if a dependent or non-matching base was
1429 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1430 bool AllowShortCircuit = true) const;
1432 /// \brief Function type used by lookupInBases() to determine whether a
1433 /// specific base class subobject matches the lookup criteria.
1435 /// \param Specifier the base-class specifier that describes the inheritance
1436 /// from the base class we are trying to match.
1438 /// \param Path the current path, from the most-derived class down to the
1439 /// base named by the \p Specifier.
1441 /// \param UserData a single pointer to user-specified data, provided to
1442 /// lookupInBases().
1444 /// \returns true if this base matched the search criteria, false otherwise.
1445 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1449 /// \brief Look for entities within the base classes of this C++ class,
1450 /// transitively searching all base class subobjects.
1452 /// This routine uses the callback function \p BaseMatches to find base
1453 /// classes meeting some search criteria, walking all base class subobjects
1454 /// and populating the given \p Paths structure with the paths through the
1455 /// inheritance hierarchy that resulted in a match. On a successful search,
1456 /// the \p Paths structure can be queried to retrieve the matching paths and
1457 /// to determine if there were any ambiguities.
1459 /// \param BaseMatches callback function used to determine whether a given
1460 /// base matches the user-defined search criteria.
1462 /// \param UserData user data pointer that will be provided to \p BaseMatches.
1464 /// \param Paths used to record the paths from this class to its base class
1465 /// subobjects that match the search criteria.
1467 /// \returns true if there exists any path from this class to a base class
1468 /// subobject that matches the search criteria.
1469 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1470 CXXBasePaths &Paths) const;
1472 /// \brief Base-class lookup callback that determines whether the given
1473 /// base class specifier refers to a specific class declaration.
1475 /// This callback can be used with \c lookupInBases() to determine whether
1476 /// a given derived class has is a base class subobject of a particular type.
1477 /// The user data pointer should refer to the canonical CXXRecordDecl of the
1478 /// base class that we are searching for.
1479 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1480 CXXBasePath &Path, void *BaseRecord);
1482 /// \brief Base-class lookup callback that determines whether the
1483 /// given base class specifier refers to a specific class
1484 /// declaration and describes virtual derivation.
1486 /// This callback can be used with \c lookupInBases() to determine
1487 /// whether a given derived class has is a virtual base class
1488 /// subobject of a particular type. The user data pointer should
1489 /// refer to the canonical CXXRecordDecl of the base class that we
1490 /// are searching for.
1491 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1492 CXXBasePath &Path, void *BaseRecord);
1494 /// \brief Base-class lookup callback that determines whether there exists
1495 /// a tag with the given name.
1497 /// This callback can be used with \c lookupInBases() to find tag members
1498 /// of the given name within a C++ class hierarchy. The user data pointer
1499 /// is an opaque \c DeclarationName pointer.
1500 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1501 CXXBasePath &Path, void *Name);
1503 /// \brief Base-class lookup callback that determines whether there exists
1504 /// a member with the given name.
1506 /// This callback can be used with \c lookupInBases() to find members
1507 /// of the given name within a C++ class hierarchy. The user data pointer
1508 /// is an opaque \c DeclarationName pointer.
1509 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1510 CXXBasePath &Path, void *Name);
1512 /// \brief Base-class lookup callback that determines whether there exists
1513 /// a member with the given name that can be used in a nested-name-specifier.
1515 /// This callback can be used with \c lookupInBases() to find membes of
1516 /// the given name within a C++ class hierarchy that can occur within
1517 /// nested-name-specifiers.
1518 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1522 /// \brief Retrieve the final overriders for each virtual member
1523 /// function in the class hierarchy where this class is the
1524 /// most-derived class in the class hierarchy.
1525 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1527 /// \brief Get the indirect primary bases for this class.
1528 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1530 /// Renders and displays an inheritance diagram
1531 /// for this C++ class and all of its base classes (transitively) using
1533 void viewInheritance(ASTContext& Context) const;
1535 /// \brief Calculates the access of a decl that is reached
1537 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1538 AccessSpecifier DeclAccess) {
1539 assert(DeclAccess != AS_none);
1540 if (DeclAccess == AS_private) return AS_none;
1541 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1544 /// \brief Indicates that the declaration of a defaulted or deleted special
1545 /// member function is now complete.
1546 void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1548 /// \brief Indicates that the definition of this class is now complete.
1549 virtual void completeDefinition();
1551 /// \brief Indicates that the definition of this class is now complete,
1552 /// and provides a final overrider map to help determine
1554 /// \param FinalOverriders The final overrider map for this class, which can
1555 /// be provided as an optimization for abstract-class checking. If NULL,
1556 /// final overriders will be computed if they are needed to complete the
1558 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1560 /// \brief Determine whether this class may end up being abstract, even though
1561 /// it is not yet known to be abstract.
1563 /// \returns true if this class is not known to be abstract but has any
1564 /// base classes that are abstract. In this case, \c completeDefinition()
1565 /// will need to compute final overriders to determine whether the class is
1566 /// actually abstract.
1567 bool mayBeAbstract() const;
1569 /// \brief If this is the closure type of a lambda expression, retrieve the
1570 /// number to be used for name mangling in the Itanium C++ ABI.
1572 /// Zero indicates that this closure type has internal linkage, so the
1573 /// mangling number does not matter, while a non-zero value indicates which
1574 /// lambda expression this is in this particular context.
1575 unsigned getLambdaManglingNumber() const {
1576 assert(isLambda() && "Not a lambda closure type!");
1577 return getLambdaData().ManglingNumber;
1580 /// \brief Retrieve the declaration that provides additional context for a
1581 /// lambda, when the normal declaration context is not specific enough.
1583 /// Certain contexts (default arguments of in-class function parameters and
1584 /// the initializers of data members) have separate name mangling rules for
1585 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1586 /// the declaration in which the lambda occurs, e.g., the function parameter
1587 /// or the non-static data member. Otherwise, it returns NULL to imply that
1588 /// the declaration context suffices.
1589 Decl *getLambdaContextDecl() const {
1590 assert(isLambda() && "Not a lambda closure type!");
1591 return getLambdaData().ContextDecl;
1594 /// \brief Set the mangling number and context declaration for a lambda
1596 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1597 getLambdaData().ManglingNumber = ManglingNumber;
1598 getLambdaData().ContextDecl = ContextDecl;
1601 /// \brief Returns the inheritance model used for this record.
1602 MSInheritanceModel getMSInheritanceModel() const;
1604 /// \brief Determine whether this lambda expression was known to be dependent
1605 /// at the time it was created, even if its context does not appear to be
1608 /// This flag is a workaround for an issue with parsing, where default
1609 /// arguments are parsed before their enclosing function declarations have
1610 /// been created. This means that any lambda expressions within those
1611 /// default arguments will have as their DeclContext the context enclosing
1612 /// the function declaration, which may be non-dependent even when the
1613 /// function declaration itself is dependent. This flag indicates when we
1614 /// know that the lambda is dependent despite that.
1615 bool isDependentLambda() const {
1616 return isLambda() && getLambdaData().Dependent;
1619 TypeSourceInfo *getLambdaTypeInfo() const {
1620 return getLambdaData().MethodTyInfo;
1623 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1624 static bool classofKind(Kind K) {
1625 return K >= firstCXXRecord && K <= lastCXXRecord;
1628 friend class ASTDeclReader;
1629 friend class ASTDeclWriter;
1630 friend class ASTReader;
1631 friend class ASTWriter;
1634 /// \brief Represents a static or instance method of a struct/union/class.
1636 /// In the terminology of the C++ Standard, these are the (static and
1637 /// non-static) member functions, whether virtual or not.
1638 class CXXMethodDecl : public FunctionDecl {
1639 virtual void anchor();
1641 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1642 const DeclarationNameInfo &NameInfo,
1643 QualType T, TypeSourceInfo *TInfo,
1644 StorageClass SC, bool isInline,
1645 bool isConstexpr, SourceLocation EndLocation)
1646 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1647 SC, isInline, isConstexpr) {
1648 if (EndLocation.isValid())
1649 setRangeEnd(EndLocation);
1653 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1654 SourceLocation StartLoc,
1655 const DeclarationNameInfo &NameInfo,
1656 QualType T, TypeSourceInfo *TInfo,
1660 SourceLocation EndLocation);
1662 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1664 bool isStatic() const;
1665 bool isInstance() const { return !isStatic(); }
1667 /// Returns true if the given operator is implicitly static in a record
1669 static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1671 // Any allocation function for a class T is a static member
1672 // (even if not explicitly declared static).
1673 // [class.free]p6 Any deallocation function for a class X is a static member
1674 // (even if not explicitly declared static).
1675 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1676 OOK == OO_Array_Delete;
1679 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1680 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1682 bool isVirtual() const {
1684 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1686 // Methods declared in interfaces are automatically (pure) virtual.
1687 if (CD->isVirtualAsWritten() ||
1688 (CD->getParent()->isInterface() && CD->isUserProvided()))
1691 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1694 /// \brief Determine whether this is a usual deallocation function
1695 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1696 /// delete or delete[] operator with a particular signature.
1697 bool isUsualDeallocationFunction() const;
1699 /// \brief Determine whether this is a copy-assignment operator, regardless
1700 /// of whether it was declared implicitly or explicitly.
1701 bool isCopyAssignmentOperator() const;
1703 /// \brief Determine whether this is a move assignment operator.
1704 bool isMoveAssignmentOperator() const;
1706 CXXMethodDecl *getCanonicalDecl() {
1707 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1709 const CXXMethodDecl *getCanonicalDecl() const {
1710 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1713 CXXMethodDecl *getMostRecentDecl() {
1714 return cast<CXXMethodDecl>(
1715 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
1717 const CXXMethodDecl *getMostRecentDecl() const {
1718 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
1721 /// True if this method is user-declared and was not
1722 /// deleted or defaulted on its first declaration.
1723 bool isUserProvided() const {
1724 return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1728 void addOverriddenMethod(const CXXMethodDecl *MD);
1730 typedef const CXXMethodDecl *const* method_iterator;
1732 method_iterator begin_overridden_methods() const;
1733 method_iterator end_overridden_methods() const;
1734 unsigned size_overridden_methods() const;
1736 /// Returns the parent of this method declaration, which
1737 /// is the class in which this method is defined.
1738 const CXXRecordDecl *getParent() const {
1739 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1742 /// Returns the parent of this method declaration, which
1743 /// is the class in which this method is defined.
1744 CXXRecordDecl *getParent() {
1745 return const_cast<CXXRecordDecl *>(
1746 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1749 /// \brief Returns the type of the \c this pointer.
1751 /// Should only be called for instance (i.e., non-static) methods.
1752 QualType getThisType(ASTContext &C) const;
1754 unsigned getTypeQualifiers() const {
1755 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1758 /// \brief Retrieve the ref-qualifier associated with this method.
1760 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1761 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1769 RefQualifierKind getRefQualifier() const {
1770 return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1773 bool hasInlineBody() const;
1775 /// \brief Determine whether this is a lambda closure type's static member
1776 /// function that is used for the result of the lambda's conversion to
1777 /// function pointer (for a lambda with no captures).
1779 /// The function itself, if used, will have a placeholder body that will be
1780 /// supplied by IR generation to either forward to the function call operator
1781 /// or clone the function call operator.
1782 bool isLambdaStaticInvoker() const;
1784 /// \brief Find the method in \p RD that corresponds to this one.
1786 /// Find if \p RD or one of the classes it inherits from override this method.
1787 /// If so, return it. \p RD is assumed to be a subclass of the class defining
1788 /// this method (or be the class itself), unless \p MayBeBase is set to true.
1790 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1791 bool MayBeBase = false);
1793 const CXXMethodDecl *
1794 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1795 bool MayBeBase = false) const {
1796 return const_cast<CXXMethodDecl *>(this)
1797 ->getCorrespondingMethodInClass(RD, MayBeBase);
1800 // Implement isa/cast/dyncast/etc.
1801 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1802 static bool classofKind(Kind K) {
1803 return K >= firstCXXMethod && K <= lastCXXMethod;
1807 /// \brief Represents a C++ base or member initializer.
1809 /// This is part of a constructor initializer that
1810 /// initializes one non-static member variable or one base class. For
1811 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1816 /// class B : public A {
1819 /// B(A& a) : A(a), f(3.14159) { }
1822 class CXXCtorInitializer {
1823 /// \brief Either the base class name/delegating constructor type (stored as
1824 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1825 /// (IndirectFieldDecl*) being initialized.
1826 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1829 /// \brief The source location for the field name or, for a base initializer
1830 /// pack expansion, the location of the ellipsis.
1832 /// In the case of a delegating
1833 /// constructor, it will still include the type's source location as the
1834 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1835 SourceLocation MemberOrEllipsisLocation;
1837 /// \brief The argument used to initialize the base or member, which may
1838 /// end up constructing an object (when multiple arguments are involved).
1841 /// \brief Location of the left paren of the ctor-initializer.
1842 SourceLocation LParenLoc;
1844 /// \brief Location of the right paren of the ctor-initializer.
1845 SourceLocation RParenLoc;
1847 /// \brief If the initializee is a type, whether that type makes this
1848 /// a delegating initialization.
1849 bool IsDelegating : 1;
1851 /// \brief If the initializer is a base initializer, this keeps track
1852 /// of whether the base is virtual or not.
1855 /// \brief Whether or not the initializer is explicitly written
1859 /// If IsWritten is true, then this number keeps track of the textual order
1860 /// of this initializer in the original sources, counting from 0; otherwise,
1861 /// it stores the number of array index variables stored after this object
1863 unsigned SourceOrderOrNumArrayIndices : 13;
1865 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1866 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1867 SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1870 /// \brief Creates a new base-class initializer.
1872 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1873 SourceLocation L, Expr *Init, SourceLocation R,
1874 SourceLocation EllipsisLoc);
1876 /// \brief Creates a new member initializer.
1878 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1879 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1882 /// \brief Creates a new anonymous field initializer.
1884 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1885 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1888 /// \brief Creates a new delegating initializer.
1890 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1891 SourceLocation L, Expr *Init, SourceLocation R);
1893 /// \brief Creates a new member initializer that optionally contains
1894 /// array indices used to describe an elementwise initialization.
1895 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1896 SourceLocation MemberLoc, SourceLocation L,
1897 Expr *Init, SourceLocation R,
1898 VarDecl **Indices, unsigned NumIndices);
1900 /// \brief Determine whether this initializer is initializing a base class.
1901 bool isBaseInitializer() const {
1902 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1905 /// \brief Determine whether this initializer is initializing a non-static
1907 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1909 bool isAnyMemberInitializer() const {
1910 return isMemberInitializer() || isIndirectMemberInitializer();
1913 bool isIndirectMemberInitializer() const {
1914 return Initializee.is<IndirectFieldDecl*>();
1917 /// \brief Determine whether this initializer is an implicit initializer
1918 /// generated for a field with an initializer defined on the member
1921 /// In-class member initializers (also known as "non-static data member
1922 /// initializations", NSDMIs) were introduced in C++11.
1923 bool isInClassMemberInitializer() const {
1924 return isa<CXXDefaultInitExpr>(Init);
1927 /// \brief Determine whether this initializer is creating a delegating
1929 bool isDelegatingInitializer() const {
1930 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1933 /// \brief Determine whether this initializer is a pack expansion.
1934 bool isPackExpansion() const {
1935 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1938 // \brief For a pack expansion, returns the location of the ellipsis.
1939 SourceLocation getEllipsisLoc() const {
1940 assert(isPackExpansion() && "Initializer is not a pack expansion");
1941 return MemberOrEllipsisLocation;
1944 /// If this is a base class initializer, returns the type of the
1945 /// base class with location information. Otherwise, returns an NULL
1947 TypeLoc getBaseClassLoc() const;
1949 /// If this is a base class initializer, returns the type of the base class.
1950 /// Otherwise, returns null.
1951 const Type *getBaseClass() const;
1953 /// Returns whether the base is virtual or not.
1954 bool isBaseVirtual() const {
1955 assert(isBaseInitializer() && "Must call this on base initializer!");
1960 /// \brief Returns the declarator information for a base class or delegating
1962 TypeSourceInfo *getTypeSourceInfo() const {
1963 return Initializee.dyn_cast<TypeSourceInfo *>();
1966 /// \brief If this is a member initializer, returns the declaration of the
1967 /// non-static data member being initialized. Otherwise, returns null.
1968 FieldDecl *getMember() const {
1969 if (isMemberInitializer())
1970 return Initializee.get<FieldDecl*>();
1973 FieldDecl *getAnyMember() const {
1974 if (isMemberInitializer())
1975 return Initializee.get<FieldDecl*>();
1976 if (isIndirectMemberInitializer())
1977 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1981 IndirectFieldDecl *getIndirectMember() const {
1982 if (isIndirectMemberInitializer())
1983 return Initializee.get<IndirectFieldDecl*>();
1987 SourceLocation getMemberLocation() const {
1988 return MemberOrEllipsisLocation;
1991 /// \brief Determine the source location of the initializer.
1992 SourceLocation getSourceLocation() const;
1994 /// \brief Determine the source range covering the entire initializer.
1995 SourceRange getSourceRange() const LLVM_READONLY;
1997 /// \brief Determine whether this initializer is explicitly written
1998 /// in the source code.
1999 bool isWritten() const { return IsWritten; }
2001 /// \brief Return the source position of the initializer, counting from 0.
2002 /// If the initializer was implicit, -1 is returned.
2003 int getSourceOrder() const {
2004 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
2007 /// \brief Set the source order of this initializer.
2009 /// This can only be called once for each initializer; it cannot be called
2010 /// on an initializer having a positive number of (implicit) array indices.
2012 /// This assumes that the initialzier was written in the source code, and
2013 /// ensures that isWritten() returns true.
2014 void setSourceOrder(int pos) {
2015 assert(!IsWritten &&
2016 "calling twice setSourceOrder() on the same initializer");
2017 assert(SourceOrderOrNumArrayIndices == 0 &&
2018 "setSourceOrder() used when there are implicit array indices");
2020 "setSourceOrder() used to make an initializer implicit");
2022 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
2025 SourceLocation getLParenLoc() const { return LParenLoc; }
2026 SourceLocation getRParenLoc() const { return RParenLoc; }
2028 /// \brief Determine the number of implicit array indices used while
2029 /// described an array member initialization.
2030 unsigned getNumArrayIndices() const {
2031 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
2034 /// \brief Retrieve a particular array index variable used to
2035 /// describe an array member initialization.
2036 VarDecl *getArrayIndex(unsigned I) {
2037 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2038 return reinterpret_cast<VarDecl **>(this + 1)[I];
2040 const VarDecl *getArrayIndex(unsigned I) const {
2041 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2042 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
2044 void setArrayIndex(unsigned I, VarDecl *Index) {
2045 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2046 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
2048 ArrayRef<VarDecl *> getArrayIndexes() {
2049 assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
2050 return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
2051 getNumArrayIndices());
2054 /// \brief Get the initializer.
2055 Expr *getInit() const { return static_cast<Expr*>(Init); }
2058 /// \brief Represents a C++ constructor within a class.
2065 /// explicit X(int); // represented by a CXXConstructorDecl.
2068 class CXXConstructorDecl : public CXXMethodDecl {
2069 virtual void anchor();
2070 /// \brief Whether this constructor declaration has the \c explicit keyword
2072 bool IsExplicitSpecified : 1;
2074 /// \name Support for base and member initializers.
2076 /// \brief The arguments used to initialize the base or member.
2077 CXXCtorInitializer **CtorInitializers;
2078 unsigned NumCtorInitializers;
2081 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2082 const DeclarationNameInfo &NameInfo,
2083 QualType T, TypeSourceInfo *TInfo,
2084 bool isExplicitSpecified, bool isInline,
2085 bool isImplicitlyDeclared, bool isConstexpr)
2086 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo,
2087 SC_None, isInline, isConstexpr, SourceLocation()),
2088 IsExplicitSpecified(isExplicitSpecified), CtorInitializers(0),
2089 NumCtorInitializers(0) {
2090 setImplicit(isImplicitlyDeclared);
2094 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2095 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2096 SourceLocation StartLoc,
2097 const DeclarationNameInfo &NameInfo,
2098 QualType T, TypeSourceInfo *TInfo,
2100 bool isInline, bool isImplicitlyDeclared,
2103 /// \brief Determine whether this constructor declaration has the
2104 /// \c explicit keyword specified.
2105 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2107 /// \brief Determine whether this constructor was marked "explicit" or not.
2108 bool isExplicit() const {
2109 return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
2112 /// \brief Iterates through the member/base initializer list.
2113 typedef CXXCtorInitializer **init_iterator;
2115 /// \brief Iterates through the member/base initializer list.
2116 typedef CXXCtorInitializer * const * init_const_iterator;
2118 /// \brief Retrieve an iterator to the first initializer.
2119 init_iterator init_begin() { return CtorInitializers; }
2120 /// \brief Retrieve an iterator to the first initializer.
2121 init_const_iterator init_begin() const { return CtorInitializers; }
2123 /// \brief Retrieve an iterator past the last initializer.
2124 init_iterator init_end() {
2125 return CtorInitializers + NumCtorInitializers;
2127 /// \brief Retrieve an iterator past the last initializer.
2128 init_const_iterator init_end() const {
2129 return CtorInitializers + NumCtorInitializers;
2132 typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2133 typedef std::reverse_iterator<init_const_iterator>
2134 init_const_reverse_iterator;
2136 init_reverse_iterator init_rbegin() {
2137 return init_reverse_iterator(init_end());
2139 init_const_reverse_iterator init_rbegin() const {
2140 return init_const_reverse_iterator(init_end());
2143 init_reverse_iterator init_rend() {
2144 return init_reverse_iterator(init_begin());
2146 init_const_reverse_iterator init_rend() const {
2147 return init_const_reverse_iterator(init_begin());
2150 /// \brief Determine the number of arguments used to initialize the member
2152 unsigned getNumCtorInitializers() const {
2153 return NumCtorInitializers;
2156 void setNumCtorInitializers(unsigned numCtorInitializers) {
2157 NumCtorInitializers = numCtorInitializers;
2160 void setCtorInitializers(CXXCtorInitializer ** initializers) {
2161 CtorInitializers = initializers;
2164 /// \brief Determine whether this constructor is a delegating constructor.
2165 bool isDelegatingConstructor() const {
2166 return (getNumCtorInitializers() == 1) &&
2167 CtorInitializers[0]->isDelegatingInitializer();
2170 /// \brief When this constructor delegates to another, retrieve the target.
2171 CXXConstructorDecl *getTargetConstructor() const;
2173 /// Whether this constructor is a default
2174 /// constructor (C++ [class.ctor]p5), which can be used to
2175 /// default-initialize a class of this type.
2176 bool isDefaultConstructor() const;
2178 /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2179 /// which can be used to copy the class.
2181 /// \p TypeQuals will be set to the qualifiers on the
2182 /// argument type. For example, \p TypeQuals would be set to \c
2183 /// Qualifiers::Const for the following copy constructor:
2191 bool isCopyConstructor(unsigned &TypeQuals) const;
2193 /// Whether this constructor is a copy
2194 /// constructor (C++ [class.copy]p2, which can be used to copy the
2196 bool isCopyConstructor() const {
2197 unsigned TypeQuals = 0;
2198 return isCopyConstructor(TypeQuals);
2201 /// \brief Determine whether this constructor is a move constructor
2202 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2204 /// \param TypeQuals If this constructor is a move constructor, will be set
2205 /// to the type qualifiers on the referent of the first parameter's type.
2206 bool isMoveConstructor(unsigned &TypeQuals) const;
2208 /// \brief Determine whether this constructor is a move constructor
2209 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2210 bool isMoveConstructor() const {
2211 unsigned TypeQuals = 0;
2212 return isMoveConstructor(TypeQuals);
2215 /// \brief Determine whether this is a copy or move constructor.
2217 /// \param TypeQuals Will be set to the type qualifiers on the reference
2218 /// parameter, if in fact this is a copy or move constructor.
2219 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2221 /// \brief Determine whether this a copy or move constructor.
2222 bool isCopyOrMoveConstructor() const {
2224 return isCopyOrMoveConstructor(Quals);
2227 /// Whether this constructor is a
2228 /// converting constructor (C++ [class.conv.ctor]), which can be
2229 /// used for user-defined conversions.
2230 bool isConvertingConstructor(bool AllowExplicit) const;
2232 /// \brief Determine whether this is a member template specialization that
2233 /// would copy the object to itself. Such constructors are never used to copy
2235 bool isSpecializationCopyingObject() const;
2237 /// \brief Get the constructor that this inheriting constructor is based on.
2238 const CXXConstructorDecl *getInheritedConstructor() const;
2240 /// \brief Set the constructor that this inheriting constructor is based on.
2241 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2243 const CXXConstructorDecl *getCanonicalDecl() const {
2244 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2246 CXXConstructorDecl *getCanonicalDecl() {
2247 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2250 // Implement isa/cast/dyncast/etc.
2251 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2252 static bool classofKind(Kind K) { return K == CXXConstructor; }
2254 friend class ASTDeclReader;
2255 friend class ASTDeclWriter;
2258 /// \brief Represents a C++ destructor within a class.
2265 /// ~X(); // represented by a CXXDestructorDecl.
2268 class CXXDestructorDecl : public CXXMethodDecl {
2269 virtual void anchor();
2271 FunctionDecl *OperatorDelete;
2273 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2274 const DeclarationNameInfo &NameInfo,
2275 QualType T, TypeSourceInfo *TInfo,
2276 bool isInline, bool isImplicitlyDeclared)
2277 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo,
2278 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2280 setImplicit(isImplicitlyDeclared);
2284 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2285 SourceLocation StartLoc,
2286 const DeclarationNameInfo &NameInfo,
2287 QualType T, TypeSourceInfo* TInfo,
2289 bool isImplicitlyDeclared);
2290 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2292 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2293 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2295 // Implement isa/cast/dyncast/etc.
2296 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2297 static bool classofKind(Kind K) { return K == CXXDestructor; }
2299 friend class ASTDeclReader;
2300 friend class ASTDeclWriter;
2303 /// \brief Represents a C++ conversion function within a class.
2310 /// operator bool();
2313 class CXXConversionDecl : public CXXMethodDecl {
2314 virtual void anchor();
2315 /// Whether this conversion function declaration is marked
2316 /// "explicit", meaning that it can only be applied when the user
2317 /// explicitly wrote a cast. This is a C++0x feature.
2318 bool IsExplicitSpecified : 1;
2320 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2321 const DeclarationNameInfo &NameInfo,
2322 QualType T, TypeSourceInfo *TInfo,
2323 bool isInline, bool isExplicitSpecified,
2324 bool isConstexpr, SourceLocation EndLocation)
2325 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo,
2326 SC_None, isInline, isConstexpr, EndLocation),
2327 IsExplicitSpecified(isExplicitSpecified) { }
2330 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2331 SourceLocation StartLoc,
2332 const DeclarationNameInfo &NameInfo,
2333 QualType T, TypeSourceInfo *TInfo,
2334 bool isInline, bool isExplicit,
2336 SourceLocation EndLocation);
2337 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2339 /// Whether this conversion function declaration is marked
2340 /// "explicit", meaning that it can only be used for direct initialization
2341 /// (including explitly written casts). This is a C++11 feature.
2342 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2344 /// \brief Whether this is an explicit conversion operator (C++11 and later).
2346 /// Explicit conversion operators are only considered for direct
2347 /// initialization, e.g., when the user has explicitly written a cast.
2348 bool isExplicit() const {
2349 return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
2352 /// \brief Returns the type that this conversion function is converting to.
2353 QualType getConversionType() const {
2354 return getType()->getAs<FunctionType>()->getResultType();
2357 /// \brief Determine whether this conversion function is a conversion from
2358 /// a lambda closure type to a block pointer.
2359 bool isLambdaToBlockPointerConversion() const;
2361 // Implement isa/cast/dyncast/etc.
2362 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2363 static bool classofKind(Kind K) { return K == CXXConversion; }
2365 friend class ASTDeclReader;
2366 friend class ASTDeclWriter;
2369 /// \brief Represents a linkage specification.
2373 /// extern "C" void foo();
2375 class LinkageSpecDecl : public Decl, public DeclContext {
2376 virtual void anchor();
2378 /// \brief Represents the language in a linkage specification.
2380 /// The values are part of the serialization ABI for
2381 /// ASTs and cannot be changed without altering that ABI. To help
2382 /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2383 /// from the dwarf standard.
2385 lang_c = /* DW_LANG_C */ 0x0002,
2386 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2389 /// \brief The language for this linkage specification.
2390 unsigned Language : 3;
2391 /// \brief True if this linkage spec has braces.
2393 /// This is needed so that hasBraces() returns the correct result while the
2394 /// linkage spec body is being parsed. Once RBraceLoc has been set this is
2395 /// not used, so it doesn't need to be serialized.
2396 unsigned HasBraces : 1;
2397 /// \brief The source location for the extern keyword.
2398 SourceLocation ExternLoc;
2399 /// \brief The source location for the right brace (if valid).
2400 SourceLocation RBraceLoc;
2402 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2403 SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2404 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2405 Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2406 RBraceLoc(SourceLocation()) { }
2409 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2410 SourceLocation ExternLoc,
2411 SourceLocation LangLoc, LanguageIDs Lang,
2413 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2415 /// \brief Return the language specified by this linkage specification.
2416 LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2417 /// \brief Set the language specified by this linkage specification.
2418 void setLanguage(LanguageIDs L) { Language = L; }
2420 /// \brief Determines whether this linkage specification had braces in
2421 /// its syntactic form.
2422 bool hasBraces() const {
2423 assert(!RBraceLoc.isValid() || HasBraces);
2427 SourceLocation getExternLoc() const { return ExternLoc; }
2428 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2429 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2430 void setRBraceLoc(SourceLocation L) {
2432 HasBraces = RBraceLoc.isValid();
2435 SourceLocation getLocEnd() const LLVM_READONLY {
2437 return getRBraceLoc();
2438 // No braces: get the end location of the (only) declaration in context
2440 return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2443 SourceRange getSourceRange() const LLVM_READONLY {
2444 return SourceRange(ExternLoc, getLocEnd());
2447 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2448 static bool classofKind(Kind K) { return K == LinkageSpec; }
2449 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2450 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2452 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2453 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2457 /// \brief Represents C++ using-directive.
2461 /// using namespace std;
2464 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2465 /// artificial names for all using-directives in order to store
2466 /// them in DeclContext effectively.
2467 class UsingDirectiveDecl : public NamedDecl {
2468 virtual void anchor();
2469 /// \brief The location of the \c using keyword.
2470 SourceLocation UsingLoc;
2472 /// \brief The location of the \c namespace keyword.
2473 SourceLocation NamespaceLoc;
2475 /// \brief The nested-name-specifier that precedes the namespace.
2476 NestedNameSpecifierLoc QualifierLoc;
2478 /// \brief The namespace nominated by this using-directive.
2479 NamedDecl *NominatedNamespace;
2481 /// Enclosing context containing both using-directive and nominated
2483 DeclContext *CommonAncestor;
2485 /// \brief Returns special DeclarationName used by using-directives.
2487 /// This is only used by DeclContext for storing UsingDirectiveDecls in
2488 /// its lookup structure.
2489 static DeclarationName getName() {
2490 return DeclarationName::getUsingDirectiveName();
2493 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2494 SourceLocation NamespcLoc,
2495 NestedNameSpecifierLoc QualifierLoc,
2496 SourceLocation IdentLoc,
2497 NamedDecl *Nominated,
2498 DeclContext *CommonAncestor)
2499 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2500 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2501 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2504 /// \brief Retrieve the nested-name-specifier that qualifies the
2505 /// name of the namespace, with source-location information.
2506 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2508 /// \brief Retrieve the nested-name-specifier that qualifies the
2509 /// name of the namespace.
2510 NestedNameSpecifier *getQualifier() const {
2511 return QualifierLoc.getNestedNameSpecifier();
2514 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2515 const NamedDecl *getNominatedNamespaceAsWritten() const {
2516 return NominatedNamespace;
2519 /// \brief Returns the namespace nominated by this using-directive.
2520 NamespaceDecl *getNominatedNamespace();
2522 const NamespaceDecl *getNominatedNamespace() const {
2523 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2526 /// \brief Returns the common ancestor context of this using-directive and
2527 /// its nominated namespace.
2528 DeclContext *getCommonAncestor() { return CommonAncestor; }
2529 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2531 /// \brief Return the location of the \c using keyword.
2532 SourceLocation getUsingLoc() const { return UsingLoc; }
2534 // FIXME: Could omit 'Key' in name.
2535 /// \brief Returns the location of the \c namespace keyword.
2536 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2538 /// \brief Returns the location of this using declaration's identifier.
2539 SourceLocation getIdentLocation() const { return getLocation(); }
2541 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2542 SourceLocation UsingLoc,
2543 SourceLocation NamespaceLoc,
2544 NestedNameSpecifierLoc QualifierLoc,
2545 SourceLocation IdentLoc,
2546 NamedDecl *Nominated,
2547 DeclContext *CommonAncestor);
2548 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2550 SourceRange getSourceRange() const LLVM_READONLY {
2551 return SourceRange(UsingLoc, getLocation());
2554 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2555 static bool classofKind(Kind K) { return K == UsingDirective; }
2557 // Friend for getUsingDirectiveName.
2558 friend class DeclContext;
2560 friend class ASTDeclReader;
2563 /// \brief Represents a C++ namespace alias.
2568 /// namespace Foo = Bar;
2570 class NamespaceAliasDecl : public NamedDecl {
2571 virtual void anchor();
2573 /// \brief The location of the \c namespace keyword.
2574 SourceLocation NamespaceLoc;
2576 /// \brief The location of the namespace's identifier.
2578 /// This is accessed by TargetNameLoc.
2579 SourceLocation IdentLoc;
2581 /// \brief The nested-name-specifier that precedes the namespace.
2582 NestedNameSpecifierLoc QualifierLoc;
2584 /// \brief The Decl that this alias points to, either a NamespaceDecl or
2585 /// a NamespaceAliasDecl.
2586 NamedDecl *Namespace;
2588 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2589 SourceLocation AliasLoc, IdentifierInfo *Alias,
2590 NestedNameSpecifierLoc QualifierLoc,
2591 SourceLocation IdentLoc, NamedDecl *Namespace)
2592 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2593 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2594 QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2596 friend class ASTDeclReader;
2599 /// \brief Retrieve the nested-name-specifier that qualifies the
2600 /// name of the namespace, with source-location information.
2601 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2603 /// \brief Retrieve the nested-name-specifier that qualifies the
2604 /// name of the namespace.
2605 NestedNameSpecifier *getQualifier() const {
2606 return QualifierLoc.getNestedNameSpecifier();
2609 /// \brief Retrieve the namespace declaration aliased by this directive.
2610 NamespaceDecl *getNamespace() {
2611 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2612 return AD->getNamespace();
2614 return cast<NamespaceDecl>(Namespace);
2617 const NamespaceDecl *getNamespace() const {
2618 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2621 /// Returns the location of the alias name, i.e. 'foo' in
2622 /// "namespace foo = ns::bar;".
2623 SourceLocation getAliasLoc() const { return getLocation(); }
2625 /// Returns the location of the \c namespace keyword.
2626 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2628 /// Returns the location of the identifier in the named namespace.
2629 SourceLocation getTargetNameLoc() const { return IdentLoc; }
2631 /// \brief Retrieve the namespace that this alias refers to, which
2632 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2633 NamedDecl *getAliasedNamespace() const { return Namespace; }
2635 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2636 SourceLocation NamespaceLoc,
2637 SourceLocation AliasLoc,
2638 IdentifierInfo *Alias,
2639 NestedNameSpecifierLoc QualifierLoc,
2640 SourceLocation IdentLoc,
2641 NamedDecl *Namespace);
2643 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2645 virtual SourceRange getSourceRange() const LLVM_READONLY {
2646 return SourceRange(NamespaceLoc, IdentLoc);
2649 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2650 static bool classofKind(Kind K) { return K == NamespaceAlias; }
2653 /// \brief Represents a shadow declaration introduced into a scope by a
2654 /// (resolved) using declaration.
2662 /// using A::foo; // <- a UsingDecl
2663 /// // Also creates a UsingShadowDecl for A::foo() in B
2666 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
2667 virtual void anchor();
2669 /// The referenced declaration.
2670 NamedDecl *Underlying;
2672 /// \brief The using declaration which introduced this decl or the next using
2673 /// shadow declaration contained in the aforementioned using declaration.
2674 NamedDecl *UsingOrNextShadow;
2675 friend class UsingDecl;
2677 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2679 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2681 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2683 setDeclName(Target->getDeclName());
2684 IdentifierNamespace = Target->getIdentifierNamespace();
2689 typedef Redeclarable<UsingShadowDecl> redeclarable_base;
2690 virtual UsingShadowDecl *getNextRedeclaration() {
2691 return RedeclLink.getNext();
2693 virtual UsingShadowDecl *getPreviousDeclImpl() {
2694 return getPreviousDecl();
2696 virtual UsingShadowDecl *getMostRecentDeclImpl() {
2697 return getMostRecentDecl();
2701 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2702 SourceLocation Loc, UsingDecl *Using,
2703 NamedDecl *Target) {
2704 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2707 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2709 typedef redeclarable_base::redecl_iterator redecl_iterator;
2710 using redeclarable_base::redecls_begin;
2711 using redeclarable_base::redecls_end;
2712 using redeclarable_base::getPreviousDecl;
2713 using redeclarable_base::getMostRecentDecl;
2715 virtual UsingShadowDecl *getCanonicalDecl() {
2716 return getFirstDecl();
2718 virtual const UsingShadowDecl *getCanonicalDecl() const {
2719 return getFirstDecl();
2722 /// \brief Gets the underlying declaration which has been brought into the
2724 NamedDecl *getTargetDecl() const { return Underlying; }
2726 /// \brief Sets the underlying declaration which has been brought into the
2728 void setTargetDecl(NamedDecl* ND) {
2729 assert(ND && "Target decl is null!");
2731 IdentifierNamespace = ND->getIdentifierNamespace();
2734 /// \brief Gets the using declaration to which this declaration is tied.
2735 UsingDecl *getUsingDecl() const;
2737 /// \brief The next using shadow declaration contained in the shadow decl
2738 /// chain of the using declaration which introduced this decl.
2739 UsingShadowDecl *getNextUsingShadowDecl() const {
2740 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2743 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2744 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2746 friend class ASTDeclReader;
2747 friend class ASTDeclWriter;
2750 /// \brief Represents a C++ using-declaration.
2754 /// using someNameSpace::someIdentifier;
2756 class UsingDecl : public NamedDecl {
2757 virtual void anchor();
2759 /// \brief The source location of the 'using' keyword itself.
2760 SourceLocation UsingLocation;
2762 /// \brief The nested-name-specifier that precedes the name.
2763 NestedNameSpecifierLoc QualifierLoc;
2765 /// \brief Provides source/type location info for the declaration name
2766 /// embedded in the ValueDecl base class.
2767 DeclarationNameLoc DNLoc;
2769 /// \brief The first shadow declaration of the shadow decl chain associated
2770 /// with this using declaration.
2772 /// The bool member of the pair store whether this decl has the \c typename
2774 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2776 UsingDecl(DeclContext *DC, SourceLocation UL,
2777 NestedNameSpecifierLoc QualifierLoc,
2778 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
2779 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2780 UsingLocation(UL), QualifierLoc(QualifierLoc),
2781 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, HasTypenameKeyword) {
2785 /// \brief Return the source location of the 'using' keyword.
2786 SourceLocation getUsingLoc() const { return UsingLocation; }
2788 /// \brief Set the source location of the 'using' keyword.
2789 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2791 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2792 /// with source-location information.
2793 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2795 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2796 NestedNameSpecifier *getQualifier() const {
2797 return QualifierLoc.getNestedNameSpecifier();
2800 DeclarationNameInfo getNameInfo() const {
2801 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2804 /// \brief Return true if it is a C++03 access declaration (no 'using').
2805 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2807 /// \brief Return true if the using declaration has 'typename'.
2808 bool hasTypename() const { return FirstUsingShadow.getInt(); }
2810 /// \brief Sets whether the using declaration has 'typename'.
2811 void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
2813 /// \brief Iterates through the using shadow declarations associated with
2814 /// this using declaration.
2815 class shadow_iterator {
2816 /// \brief The current using shadow declaration.
2817 UsingShadowDecl *Current;
2820 typedef UsingShadowDecl* value_type;
2821 typedef UsingShadowDecl* reference;
2822 typedef UsingShadowDecl* pointer;
2823 typedef std::forward_iterator_tag iterator_category;
2824 typedef std::ptrdiff_t difference_type;
2826 shadow_iterator() : Current(0) { }
2827 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2829 reference operator*() const { return Current; }
2830 pointer operator->() const { return Current; }
2832 shadow_iterator& operator++() {
2833 Current = Current->getNextUsingShadowDecl();
2837 shadow_iterator operator++(int) {
2838 shadow_iterator tmp(*this);
2843 friend bool operator==(shadow_iterator x, shadow_iterator y) {
2844 return x.Current == y.Current;
2846 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2847 return x.Current != y.Current;
2851 shadow_iterator shadow_begin() const {
2852 return shadow_iterator(FirstUsingShadow.getPointer());
2854 shadow_iterator shadow_end() const { return shadow_iterator(); }
2856 /// \brief Return the number of shadowed declarations associated with this
2857 /// using declaration.
2858 unsigned shadow_size() const {
2859 return std::distance(shadow_begin(), shadow_end());
2862 void addShadowDecl(UsingShadowDecl *S);
2863 void removeShadowDecl(UsingShadowDecl *S);
2865 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2866 SourceLocation UsingL,
2867 NestedNameSpecifierLoc QualifierLoc,
2868 const DeclarationNameInfo &NameInfo,
2869 bool HasTypenameKeyword);
2871 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2873 SourceRange getSourceRange() const LLVM_READONLY;
2875 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2876 static bool classofKind(Kind K) { return K == Using; }
2878 friend class ASTDeclReader;
2879 friend class ASTDeclWriter;
2882 /// \brief Represents a dependent using declaration which was not marked with
2885 /// Unlike non-dependent using declarations, these *only* bring through
2886 /// non-types; otherwise they would break two-phase lookup.
2889 /// template \<class T> class A : public Base<T> {
2890 /// using Base<T>::foo;
2893 class UnresolvedUsingValueDecl : public ValueDecl {
2894 virtual void anchor();
2896 /// \brief The source location of the 'using' keyword
2897 SourceLocation UsingLocation;
2899 /// \brief The nested-name-specifier that precedes the name.
2900 NestedNameSpecifierLoc QualifierLoc;
2902 /// \brief Provides source/type location info for the declaration name
2903 /// embedded in the ValueDecl base class.
2904 DeclarationNameLoc DNLoc;
2906 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2907 SourceLocation UsingLoc,
2908 NestedNameSpecifierLoc QualifierLoc,
2909 const DeclarationNameInfo &NameInfo)
2910 : ValueDecl(UnresolvedUsingValue, DC,
2911 NameInfo.getLoc(), NameInfo.getName(), Ty),
2912 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2913 DNLoc(NameInfo.getInfo())
2917 /// \brief Returns the source location of the 'using' keyword.
2918 SourceLocation getUsingLoc() const { return UsingLocation; }
2920 /// \brief Set the source location of the 'using' keyword.
2921 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2923 /// \brief Return true if it is a C++03 access declaration (no 'using').
2924 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2926 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2927 /// with source-location information.
2928 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2930 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2931 NestedNameSpecifier *getQualifier() const {
2932 return QualifierLoc.getNestedNameSpecifier();
2935 DeclarationNameInfo getNameInfo() const {
2936 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2939 static UnresolvedUsingValueDecl *
2940 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2941 NestedNameSpecifierLoc QualifierLoc,
2942 const DeclarationNameInfo &NameInfo);
2944 static UnresolvedUsingValueDecl *
2945 CreateDeserialized(ASTContext &C, unsigned ID);
2947 SourceRange getSourceRange() const LLVM_READONLY;
2949 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2950 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2952 friend class ASTDeclReader;
2953 friend class ASTDeclWriter;
2956 /// \brief Represents a dependent using declaration which was marked with
2960 /// template \<class T> class A : public Base<T> {
2961 /// using typename Base<T>::foo;
2965 /// The type associated with an unresolved using typename decl is
2966 /// currently always a typename type.
2967 class UnresolvedUsingTypenameDecl : public TypeDecl {
2968 virtual void anchor();
2970 /// \brief The source location of the 'typename' keyword
2971 SourceLocation TypenameLocation;
2973 /// \brief The nested-name-specifier that precedes the name.
2974 NestedNameSpecifierLoc QualifierLoc;
2976 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2977 SourceLocation TypenameLoc,
2978 NestedNameSpecifierLoc QualifierLoc,
2979 SourceLocation TargetNameLoc,
2980 IdentifierInfo *TargetName)
2981 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2983 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2985 friend class ASTDeclReader;
2988 /// \brief Returns the source location of the 'using' keyword.
2989 SourceLocation getUsingLoc() const { return getLocStart(); }
2991 /// \brief Returns the source location of the 'typename' keyword.
2992 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2994 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2995 /// with source-location information.
2996 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2998 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2999 NestedNameSpecifier *getQualifier() const {
3000 return QualifierLoc.getNestedNameSpecifier();
3003 static UnresolvedUsingTypenameDecl *
3004 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3005 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3006 SourceLocation TargetNameLoc, DeclarationName TargetName);
3008 static UnresolvedUsingTypenameDecl *
3009 CreateDeserialized(ASTContext &C, unsigned ID);
3011 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3012 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3015 /// \brief Represents a C++11 static_assert declaration.
3016 class StaticAssertDecl : public Decl {
3017 virtual void anchor();
3018 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3019 StringLiteral *Message;
3020 SourceLocation RParenLoc;
3022 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3023 Expr *AssertExpr, StringLiteral *Message,
3024 SourceLocation RParenLoc, bool Failed)
3025 : Decl(StaticAssert, DC, StaticAssertLoc),
3026 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3027 RParenLoc(RParenLoc) { }
3030 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3031 SourceLocation StaticAssertLoc,
3032 Expr *AssertExpr, StringLiteral *Message,
3033 SourceLocation RParenLoc, bool Failed);
3034 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3036 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3037 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3039 StringLiteral *getMessage() { return Message; }
3040 const StringLiteral *getMessage() const { return Message; }
3042 bool isFailed() const { return AssertExprAndFailed.getInt(); }
3044 SourceLocation getRParenLoc() const { return RParenLoc; }
3046 SourceRange getSourceRange() const LLVM_READONLY {
3047 return SourceRange(getLocation(), getRParenLoc());
3050 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3051 static bool classofKind(Kind K) { return K == StaticAssert; }
3053 friend class ASTDeclReader;
3056 /// An instance of this class represents the declaration of a property
3057 /// member. This is a Microsoft extension to C++, first introduced in
3058 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3059 /// and Managed C++.
3061 /// A property must always be a non-static class member.
3063 /// A property member superficially resembles a non-static data
3064 /// member, except preceded by a property attribute:
3065 /// __declspec(property(get=GetX, put=PutX)) int x;
3066 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3068 /// A reference to a property is always an lvalue. If the lvalue
3069 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3070 /// required, and that member is called with no arguments.
3071 /// If the lvalue is assigned into, then a setter name is required,
3072 /// and that member is called with one argument, the value assigned.
3073 /// Both operations are potentially overloaded. Compound assignments
3074 /// are permitted, as are the increment and decrement operators.
3076 /// The getter and putter methods are permitted to be overloaded,
3077 /// although their return and parameter types are subject to certain
3078 /// restrictions according to the type of the property.
3080 /// A property declared using an incomplete array type may
3081 /// additionally be subscripted, adding extra parameters to the getter
3082 /// and putter methods.
3083 class MSPropertyDecl : public DeclaratorDecl {
3084 IdentifierInfo *GetterId, *SetterId;
3087 MSPropertyDecl(DeclContext *DC, SourceLocation L,
3088 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
3089 SourceLocation StartL, IdentifierInfo *Getter,
3090 IdentifierInfo *Setter):
3091 DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), GetterId(Getter),
3094 static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3096 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3098 bool hasGetter() const { return GetterId != NULL; }
3099 IdentifierInfo* getGetterId() const { return GetterId; }
3100 bool hasSetter() const { return SetterId != NULL; }
3101 IdentifierInfo* getSetterId() const { return SetterId; }
3103 friend class ASTDeclReader;
3106 /// Insertion operator for diagnostics. This allows sending an AccessSpecifier
3107 /// into a diagnostic with <<.
3108 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3109 AccessSpecifier AS);
3111 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3112 AccessSpecifier AS);
3114 } // end namespace clang