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/Attr.h"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/LambdaCapture.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/PointerIntPair.h"
26 #include "llvm/Support/Compiler.h"
30 class ClassTemplateDecl;
31 class ClassTemplateSpecializationDecl;
34 class CXXConstructorDecl;
35 class CXXConversionDecl;
36 class CXXDestructorDecl;
39 class CXXMemberLookupCriteria;
40 class CXXFinalOverriderMap;
41 class CXXIndirectPrimaryBaseSet;
46 /// \brief Represents any kind of function declaration, whether it is a
47 /// concrete function or a function template.
48 class AnyFunctionDecl {
51 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
54 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
55 AnyFunctionDecl(FunctionTemplateDecl *FTD);
57 /// \brief Implicily converts any function or function template into a
58 /// named declaration.
59 operator NamedDecl *() const { return Function; }
61 /// \brief Retrieve the underlying function or function template.
62 NamedDecl *get() const { return Function; }
64 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
65 return AnyFunctionDecl(ND);
69 } // end namespace clang
72 // Provide PointerLikeTypeTraits for non-cvr pointers.
74 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
76 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
79 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
80 return ::clang::AnyFunctionDecl::getFromNamedDecl(
81 static_cast< ::clang::NamedDecl*>(P));
84 enum { NumLowBitsAvailable = 2 };
87 } // end namespace llvm
91 /// \brief Represents an access specifier followed by colon ':'.
93 /// An objects of this class represents sugar for the syntactic occurrence
94 /// of an access specifier followed by a colon in the list of member
95 /// specifiers of a C++ class definition.
97 /// Note that they do not represent other uses of access specifiers,
98 /// such as those occurring in a list of base specifiers.
99 /// Also note that this class has nothing to do with so-called
100 /// "access declarations" (C++98 11.3 [class.access.dcl]).
101 class AccessSpecDecl : public Decl {
102 virtual void anchor();
103 /// \brief The location of the ':'.
104 SourceLocation ColonLoc;
106 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
107 SourceLocation ASLoc, SourceLocation ColonLoc)
108 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
111 AccessSpecDecl(EmptyShell Empty)
112 : Decl(AccessSpec, Empty) { }
114 /// \brief The location of the access specifier.
115 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
116 /// \brief Sets the location of the access specifier.
117 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
119 /// \brief The location of the colon following the access specifier.
120 SourceLocation getColonLoc() const { return ColonLoc; }
121 /// \brief Sets the location of the colon.
122 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
124 SourceRange getSourceRange() const override LLVM_READONLY {
125 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
128 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
129 DeclContext *DC, SourceLocation ASLoc,
130 SourceLocation ColonLoc) {
131 return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
133 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
135 // Implement isa/cast/dyncast/etc.
136 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
137 static bool classofKind(Kind K) { return K == AccessSpec; }
141 /// \brief Represents a base class of a C++ class.
143 /// Each CXXBaseSpecifier represents a single, direct base class (or
144 /// struct) of a C++ class (or struct). It specifies the type of that
145 /// base class, whether it is a virtual or non-virtual base, and what
146 /// level of access (public, protected, private) is used for the
147 /// derivation. For example:
152 /// class C : public virtual A, protected B { };
155 /// In this code, C will have two CXXBaseSpecifiers, one for "public
156 /// virtual A" and the other for "protected B".
157 class CXXBaseSpecifier {
158 /// \brief The source code range that covers the full base
159 /// specifier, including the "virtual" (if present) and access
160 /// specifier (if present).
163 /// \brief The source location of the ellipsis, if this is a pack
165 SourceLocation EllipsisLoc;
167 /// \brief Whether this is a virtual base class or not.
170 /// \brief Whether this is the base of a class (true) or of a struct (false).
172 /// This determines the mapping from the access specifier as written in the
173 /// source code to the access specifier used for semantic analysis.
174 bool BaseOfClass : 1;
176 /// \brief Access specifier as written in the source code (may be AS_none).
178 /// The actual type of data stored here is an AccessSpecifier, but we use
179 /// "unsigned" here to work around a VC++ bug.
182 /// \brief Whether the class contains a using declaration
183 /// to inherit the named class's constructors.
184 bool InheritConstructors : 1;
186 /// \brief The type of the base class.
188 /// This will be a class or struct (or a typedef of such). The source code
189 /// range does not include the \c virtual or the access specifier.
190 TypeSourceInfo *BaseTypeInfo;
193 CXXBaseSpecifier() { }
195 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
196 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
197 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
198 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
200 /// \brief Retrieves the source range that contains the entire base specifier.
201 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
202 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
203 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
205 /// \brief Determines whether the base class is a virtual base class (or not).
206 bool isVirtual() const { return Virtual; }
208 /// \brief Determine whether this base class is a base of a class declared
209 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
210 bool isBaseOfClass() const { return BaseOfClass; }
212 /// \brief Determine whether this base specifier is a pack expansion.
213 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
215 /// \brief Determine whether this base class's constructors get inherited.
216 bool getInheritConstructors() const { return InheritConstructors; }
218 /// \brief Set that this base class's constructors should be inherited.
219 void setInheritConstructors(bool Inherit = true) {
220 InheritConstructors = Inherit;
223 /// \brief For a pack expansion, determine the location of the ellipsis.
224 SourceLocation getEllipsisLoc() const {
228 /// \brief Returns the access specifier for this base specifier.
230 /// This is the actual base specifier as used for semantic analysis, so
231 /// the result can never be AS_none. To retrieve the access specifier as
232 /// written in the source code, use getAccessSpecifierAsWritten().
233 AccessSpecifier getAccessSpecifier() const {
234 if ((AccessSpecifier)Access == AS_none)
235 return BaseOfClass? AS_private : AS_public;
237 return (AccessSpecifier)Access;
240 /// \brief Retrieves the access specifier as written in the source code
241 /// (which may mean that no access specifier was explicitly written).
243 /// Use getAccessSpecifier() to retrieve the access specifier for use in
244 /// semantic analysis.
245 AccessSpecifier getAccessSpecifierAsWritten() const {
246 return (AccessSpecifier)Access;
249 /// \brief Retrieves the type of the base class.
251 /// This type will always be an unqualified class type.
252 QualType getType() const {
253 return BaseTypeInfo->getType().getUnqualifiedType();
256 /// \brief Retrieves the type and source location of the base class.
257 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
260 /// \brief A lazy pointer to the definition data for a declaration.
261 /// FIXME: This is a little CXXRecordDecl-specific that the moment.
262 template<typename Decl, typename T> class LazyDefinitionDataPtr {
263 llvm::PointerUnion<T *, Decl *> DataOrCanonicalDecl;
265 LazyDefinitionDataPtr update() {
266 if (Decl *Canon = DataOrCanonicalDecl.template dyn_cast<Decl*>()) {
267 if (Canon->isCanonicalDecl())
268 Canon->getMostRecentDecl();
270 // Declaration isn't canonical any more;
271 // update it and perform path compression.
272 *this = Canon->getPreviousDecl()->DefinitionData.update();
278 LazyDefinitionDataPtr(Decl *Canon) : DataOrCanonicalDecl(Canon) {}
279 LazyDefinitionDataPtr(T *Data) : DataOrCanonicalDecl(Data) {}
280 T *getNotUpdated() { return DataOrCanonicalDecl.template dyn_cast<T*>(); }
281 T *get() { return update().getNotUpdated(); }
284 /// \brief Represents a C++ struct/union/class.
285 class CXXRecordDecl : public RecordDecl {
287 friend void TagDecl::startDefinition();
289 /// Values used in DefinitionData fields to represent special members.
290 enum SpecialMemberFlags {
291 SMF_DefaultConstructor = 0x1,
292 SMF_CopyConstructor = 0x2,
293 SMF_MoveConstructor = 0x4,
294 SMF_CopyAssignment = 0x8,
295 SMF_MoveAssignment = 0x10,
296 SMF_Destructor = 0x20,
300 struct DefinitionData {
301 DefinitionData(CXXRecordDecl *D);
303 /// \brief True if this class has any user-declared constructors.
304 bool UserDeclaredConstructor : 1;
306 /// \brief The user-declared special members which this class has.
307 unsigned UserDeclaredSpecialMembers : 6;
309 /// \brief True when this class is an aggregate.
312 /// \brief True when this class is a POD-type.
313 bool PlainOldData : 1;
315 /// true when this class is empty for traits purposes,
316 /// i.e. has no data members other than 0-width bit-fields, has no
317 /// virtual function/base, and doesn't inherit from a non-empty
318 /// class. Doesn't take union-ness into account.
321 /// \brief True when this class is polymorphic, i.e., has at
322 /// least one virtual member or derives from a polymorphic class.
323 bool Polymorphic : 1;
325 /// \brief True when this class is abstract, i.e., has at least
326 /// one pure virtual function, (that can come from a base class).
329 /// \brief True when this class has standard layout.
331 /// C++11 [class]p7. A standard-layout class is a class that:
332 /// * has no non-static data members of type non-standard-layout class (or
333 /// array of such types) or reference,
334 /// * has no virtual functions (10.3) and no virtual base classes (10.1),
335 /// * has the same access control (Clause 11) for all non-static data
337 /// * has no non-standard-layout base classes,
338 /// * either has no non-static data members in the most derived class and at
339 /// most one base class with non-static data members, or has no base
340 /// classes with non-static data members, and
341 /// * has no base classes of the same type as the first non-static data
343 bool IsStandardLayout : 1;
345 /// \brief True when there are no non-empty base classes.
347 /// This is a helper bit of state used to implement IsStandardLayout more
349 bool HasNoNonEmptyBases : 1;
351 /// \brief True when there are private non-static data members.
352 bool HasPrivateFields : 1;
354 /// \brief True when there are protected non-static data members.
355 bool HasProtectedFields : 1;
357 /// \brief True when there are private non-static data members.
358 bool HasPublicFields : 1;
360 /// \brief True if this class (or any subobject) has mutable fields.
361 bool HasMutableFields : 1;
363 /// \brief True if this class (or any nested anonymous struct or union)
364 /// has variant members.
365 bool HasVariantMembers : 1;
367 /// \brief True if there no non-field members declared by the user.
368 bool HasOnlyCMembers : 1;
370 /// \brief True if any field has an in-class initializer, including those
371 /// within anonymous unions or structs.
372 bool HasInClassInitializer : 1;
374 /// \brief True if any field is of reference type, and does not have an
375 /// in-class initializer.
377 /// In this case, value-initialization of this class is illegal in C++98
378 /// even if the class has a trivial default constructor.
379 bool HasUninitializedReferenceMember : 1;
381 /// \brief These flags are \c true if a defaulted corresponding special
382 /// member can't be fully analyzed without performing overload resolution.
384 bool NeedOverloadResolutionForMoveConstructor : 1;
385 bool NeedOverloadResolutionForMoveAssignment : 1;
386 bool NeedOverloadResolutionForDestructor : 1;
389 /// \brief These flags are \c true if an implicit defaulted corresponding
390 /// special member would be defined as deleted.
392 bool DefaultedMoveConstructorIsDeleted : 1;
393 bool DefaultedMoveAssignmentIsDeleted : 1;
394 bool DefaultedDestructorIsDeleted : 1;
397 /// \brief The trivial special members which this class has, per
398 /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
399 /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
401 /// This excludes any user-declared but not user-provided special members
402 /// which have been declared but not yet defined.
403 unsigned HasTrivialSpecialMembers : 6;
405 /// \brief The declared special members of this class which are known to be
408 /// This excludes any user-declared but not user-provided special members
409 /// which have been declared but not yet defined, and any implicit special
410 /// members which have not yet been declared.
411 unsigned DeclaredNonTrivialSpecialMembers : 6;
413 /// \brief True when this class has a destructor with no semantic effect.
414 bool HasIrrelevantDestructor : 1;
416 /// \brief True when this class has at least one user-declared constexpr
417 /// constructor which is neither the copy nor move constructor.
418 bool HasConstexprNonCopyMoveConstructor : 1;
420 /// \brief True if a defaulted default constructor for this class would
422 bool DefaultedDefaultConstructorIsConstexpr : 1;
424 /// \brief True if this class has a constexpr default constructor.
426 /// This is true for either a user-declared constexpr default constructor
427 /// or an implicitly declared constexpr default constructor.
428 bool HasConstexprDefaultConstructor : 1;
430 /// \brief True when this class contains at least one non-static data
431 /// member or base class of non-literal or volatile type.
432 bool HasNonLiteralTypeFieldsOrBases : 1;
434 /// \brief True when visible conversion functions are already computed
435 /// and are available.
436 bool ComputedVisibleConversions : 1;
438 /// \brief Whether we have a C++11 user-provided default constructor (not
439 /// explicitly deleted or defaulted).
440 bool UserProvidedDefaultConstructor : 1;
442 /// \brief The special members which have been declared for this class,
443 /// either by the user or implicitly.
444 unsigned DeclaredSpecialMembers : 6;
446 /// \brief Whether an implicit copy constructor would have a const-qualified
448 bool ImplicitCopyConstructorHasConstParam : 1;
450 /// \brief Whether an implicit copy assignment operator would have a
451 /// const-qualified parameter.
452 bool ImplicitCopyAssignmentHasConstParam : 1;
454 /// \brief Whether any declared copy constructor has a const-qualified
456 bool HasDeclaredCopyConstructorWithConstParam : 1;
458 /// \brief Whether any declared copy assignment operator has either a
459 /// const-qualified reference parameter or a non-reference parameter.
460 bool HasDeclaredCopyAssignmentWithConstParam : 1;
462 /// \brief Whether this class describes a C++ lambda.
465 /// \brief Whether we are currently parsing base specifiers.
466 bool IsParsingBaseSpecifiers : 1;
468 /// \brief The number of base class specifiers in Bases.
471 /// \brief The number of virtual base class specifiers in VBases.
474 /// \brief Base classes of this class.
476 /// FIXME: This is wasted space for a union.
477 LazyCXXBaseSpecifiersPtr Bases;
479 /// \brief direct and indirect virtual base classes of this class.
480 LazyCXXBaseSpecifiersPtr VBases;
482 /// \brief The conversion functions of this C++ class (but not its
483 /// inherited conversion functions).
485 /// Each of the entries in this overload set is a CXXConversionDecl.
486 LazyASTUnresolvedSet Conversions;
488 /// \brief The conversion functions of this C++ class and all those
489 /// inherited conversion functions that are visible in this class.
491 /// Each of the entries in this overload set is a CXXConversionDecl or a
492 /// FunctionTemplateDecl.
493 LazyASTUnresolvedSet VisibleConversions;
495 /// \brief The declaration which defines this record.
496 CXXRecordDecl *Definition;
498 /// \brief The first friend declaration in this class, or null if there
501 /// This is actually currently stored in reverse order.
502 LazyDeclPtr FirstFriend;
504 /// \brief Retrieve the set of direct base classes.
505 CXXBaseSpecifier *getBases() const {
506 if (!Bases.isOffset())
507 return Bases.get(nullptr);
508 return getBasesSlowCase();
511 /// \brief Retrieve the set of virtual base classes.
512 CXXBaseSpecifier *getVBases() const {
513 if (!VBases.isOffset())
514 return VBases.get(nullptr);
515 return getVBasesSlowCase();
519 CXXBaseSpecifier *getBasesSlowCase() const;
520 CXXBaseSpecifier *getVBasesSlowCase() const;
523 typedef LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>
525 friend class LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>;
527 mutable DefinitionDataPtr DefinitionData;
529 /// \brief Describes a C++ closure type (generated by a lambda expression).
530 struct LambdaDefinitionData : public DefinitionData {
531 typedef LambdaCapture Capture;
533 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
534 bool Dependent, bool IsGeneric,
535 LambdaCaptureDefault CaptureDefault)
536 : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
537 CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
538 ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
543 /// \brief Whether this lambda is known to be dependent, even if its
544 /// context isn't dependent.
546 /// A lambda with a non-dependent context can be dependent if it occurs
547 /// within the default argument of a function template, because the
548 /// lambda will have been created with the enclosing context as its
549 /// declaration context, rather than function. This is an unfortunate
550 /// artifact of having to parse the default arguments before.
551 unsigned Dependent : 1;
553 /// \brief Whether this lambda is a generic lambda.
554 unsigned IsGenericLambda : 1;
556 /// \brief The Default Capture.
557 unsigned CaptureDefault : 2;
559 /// \brief The number of captures in this lambda is limited 2^NumCaptures.
560 unsigned NumCaptures : 15;
562 /// \brief The number of explicit captures in this lambda.
563 unsigned NumExplicitCaptures : 13;
565 /// \brief The number used to indicate this lambda expression for name
566 /// mangling in the Itanium C++ ABI.
567 unsigned ManglingNumber;
569 /// \brief The declaration that provides context for this lambda, if the
570 /// actual DeclContext does not suffice. This is used for lambdas that
571 /// occur within default arguments of function parameters within the class
572 /// or within a data member initializer.
575 /// \brief The list of captures, both explicit and implicit, for this
579 /// \brief The type of the call method.
580 TypeSourceInfo *MethodTyInfo;
584 struct DefinitionData &data() const {
585 auto *DD = DefinitionData.get();
586 assert(DD && "queried property of class with no definition");
590 struct LambdaDefinitionData &getLambdaData() const {
591 // No update required: a merged definition cannot change any lambda
593 auto *DD = DefinitionData.getNotUpdated();
594 assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
595 return static_cast<LambdaDefinitionData&>(*DD);
598 /// \brief The template or declaration that this declaration
599 /// describes or was instantiated from, respectively.
601 /// For non-templates, this value will be null. For record
602 /// declarations that describe a class template, this will be a
603 /// pointer to a ClassTemplateDecl. For member
604 /// classes of class template specializations, this will be the
605 /// MemberSpecializationInfo referring to the member class that was
606 /// instantiated or specialized.
607 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
608 TemplateOrInstantiation;
610 friend class DeclContext;
611 friend class LambdaExpr;
613 /// \brief Called from setBases and addedMember to notify the class that a
614 /// direct or virtual base class or a member of class type has been added.
615 void addedClassSubobject(CXXRecordDecl *Base);
617 /// \brief Notify the class that member has been added.
619 /// This routine helps maintain information about the class based on which
620 /// members have been added. It will be invoked by DeclContext::addDecl()
621 /// whenever a member is added to this record.
622 void addedMember(Decl *D);
624 void markedVirtualFunctionPure();
625 friend void FunctionDecl::setPure(bool);
627 friend class ASTNodeImporter;
629 /// \brief Get the head of our list of friend declarations, possibly
630 /// deserializing the friends from an external AST source.
631 FriendDecl *getFirstFriend() const;
634 CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
635 SourceLocation StartLoc, SourceLocation IdLoc,
636 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
639 /// \brief Iterator that traverses the base classes of a class.
640 typedef CXXBaseSpecifier* base_class_iterator;
642 /// \brief Iterator that traverses the base classes of a class.
643 typedef const CXXBaseSpecifier* base_class_const_iterator;
645 CXXRecordDecl *getCanonicalDecl() override {
646 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
648 virtual const CXXRecordDecl *getCanonicalDecl() const {
649 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
652 CXXRecordDecl *getPreviousDecl() {
653 return cast_or_null<CXXRecordDecl>(
654 static_cast<RecordDecl *>(this)->getPreviousDecl());
656 const CXXRecordDecl *getPreviousDecl() const {
657 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
660 CXXRecordDecl *getMostRecentDecl() {
661 return cast<CXXRecordDecl>(
662 static_cast<RecordDecl *>(this)->getMostRecentDecl());
665 const CXXRecordDecl *getMostRecentDecl() const {
666 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
669 CXXRecordDecl *getDefinition() const {
670 auto *DD = DefinitionData.get();
671 return DD ? DD->Definition : nullptr;
674 bool hasDefinition() const { return DefinitionData.get(); }
676 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
677 SourceLocation StartLoc, SourceLocation IdLoc,
679 CXXRecordDecl *PrevDecl = nullptr,
680 bool DelayTypeCreation = false);
681 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
682 TypeSourceInfo *Info, SourceLocation Loc,
683 bool DependentLambda, bool IsGeneric,
684 LambdaCaptureDefault CaptureDefault);
685 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
687 bool isDynamicClass() const {
688 return data().Polymorphic || data().NumVBases != 0;
691 void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
693 bool isParsingBaseSpecifiers() const {
694 return data().IsParsingBaseSpecifiers;
697 /// \brief Sets the base classes of this struct or class.
698 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
700 /// \brief Retrieves the number of base classes of this class.
701 unsigned getNumBases() const { return data().NumBases; }
703 typedef llvm::iterator_range<base_class_iterator> base_class_range;
704 typedef llvm::iterator_range<base_class_const_iterator>
705 base_class_const_range;
707 base_class_range bases() {
708 return base_class_range(bases_begin(), bases_end());
710 base_class_const_range bases() const {
711 return base_class_const_range(bases_begin(), bases_end());
714 base_class_iterator bases_begin() { return data().getBases(); }
715 base_class_const_iterator bases_begin() const { return data().getBases(); }
716 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
717 base_class_const_iterator bases_end() const {
718 return bases_begin() + data().NumBases;
721 /// \brief Retrieves the number of virtual base classes of this class.
722 unsigned getNumVBases() const { return data().NumVBases; }
724 base_class_range vbases() {
725 return base_class_range(vbases_begin(), vbases_end());
727 base_class_const_range vbases() const {
728 return base_class_const_range(vbases_begin(), vbases_end());
731 base_class_iterator vbases_begin() { return data().getVBases(); }
732 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
733 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
734 base_class_const_iterator vbases_end() const {
735 return vbases_begin() + data().NumVBases;
738 /// \brief Determine whether this class has any dependent base classes which
739 /// are not the current instantiation.
740 bool hasAnyDependentBases() const;
742 /// Iterator access to method members. The method iterator visits
743 /// all method members of the class, including non-instance methods,
744 /// special methods, etc.
745 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
746 typedef llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>
749 method_range methods() const {
750 return method_range(method_begin(), method_end());
753 /// \brief Method begin iterator. Iterates in the order the methods
755 method_iterator method_begin() const {
756 return method_iterator(decls_begin());
758 /// \brief Method past-the-end iterator.
759 method_iterator method_end() const {
760 return method_iterator(decls_end());
763 /// Iterator access to constructor members.
764 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
765 typedef llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>
768 ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
770 ctor_iterator ctor_begin() const {
771 return ctor_iterator(decls_begin());
773 ctor_iterator ctor_end() const {
774 return ctor_iterator(decls_end());
777 /// An iterator over friend declarations. All of these are defined
779 class friend_iterator;
780 typedef llvm::iterator_range<friend_iterator> friend_range;
782 friend_range friends() const;
783 friend_iterator friend_begin() const;
784 friend_iterator friend_end() const;
785 void pushFriendDecl(FriendDecl *FD);
787 /// Determines whether this record has any friends.
788 bool hasFriends() const {
789 return data().FirstFriend.isValid();
792 /// \brief \c true if we know for sure that this class has a single,
793 /// accessible, unambiguous move constructor that is not deleted.
794 bool hasSimpleMoveConstructor() const {
795 return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
796 !data().DefaultedMoveConstructorIsDeleted;
798 /// \brief \c true if we know for sure that this class has a single,
799 /// accessible, unambiguous move assignment operator that is not deleted.
800 bool hasSimpleMoveAssignment() const {
801 return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
802 !data().DefaultedMoveAssignmentIsDeleted;
804 /// \brief \c true if we know for sure that this class has an accessible
805 /// destructor that is not deleted.
806 bool hasSimpleDestructor() const {
807 return !hasUserDeclaredDestructor() &&
808 !data().DefaultedDestructorIsDeleted;
811 /// \brief Determine whether this class has any default constructors.
812 bool hasDefaultConstructor() const {
813 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
814 needsImplicitDefaultConstructor();
817 /// \brief Determine if we need to declare a default constructor for
820 /// This value is used for lazy creation of default constructors.
821 bool needsImplicitDefaultConstructor() const {
822 return !data().UserDeclaredConstructor &&
823 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
826 /// \brief Determine whether this class has any user-declared constructors.
828 /// When true, a default constructor will not be implicitly declared.
829 bool hasUserDeclaredConstructor() const {
830 return data().UserDeclaredConstructor;
833 /// \brief Whether this class has a user-provided default constructor
835 bool hasUserProvidedDefaultConstructor() const {
836 return data().UserProvidedDefaultConstructor;
839 /// \brief Determine whether this class has a user-declared copy constructor.
841 /// When false, a copy constructor will be implicitly declared.
842 bool hasUserDeclaredCopyConstructor() const {
843 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
846 /// \brief Determine whether this class needs an implicit copy
847 /// constructor to be lazily declared.
848 bool needsImplicitCopyConstructor() const {
849 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
852 /// \brief Determine whether we need to eagerly declare a defaulted copy
853 /// constructor for this class.
854 bool needsOverloadResolutionForCopyConstructor() const {
855 return data().HasMutableFields;
858 /// \brief Determine whether an implicit copy constructor for this type
859 /// would have a parameter with a const-qualified reference type.
860 bool implicitCopyConstructorHasConstParam() const {
861 return data().ImplicitCopyConstructorHasConstParam;
864 /// \brief Determine whether this class has a copy constructor with
865 /// a parameter type which is a reference to a const-qualified type.
866 bool hasCopyConstructorWithConstParam() const {
867 return data().HasDeclaredCopyConstructorWithConstParam ||
868 (needsImplicitCopyConstructor() &&
869 implicitCopyConstructorHasConstParam());
872 /// \brief Whether this class has a user-declared move constructor or
873 /// assignment operator.
875 /// When false, a move constructor and assignment operator may be
876 /// implicitly declared.
877 bool hasUserDeclaredMoveOperation() const {
878 return data().UserDeclaredSpecialMembers &
879 (SMF_MoveConstructor | SMF_MoveAssignment);
882 /// \brief Determine whether this class has had a move constructor
883 /// declared by the user.
884 bool hasUserDeclaredMoveConstructor() const {
885 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
888 /// \brief Determine whether this class has a move constructor.
889 bool hasMoveConstructor() const {
890 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
891 needsImplicitMoveConstructor();
894 /// \brief Set that we attempted to declare an implicitly move
895 /// constructor, but overload resolution failed so we deleted it.
896 void setImplicitMoveConstructorIsDeleted() {
897 assert((data().DefaultedMoveConstructorIsDeleted ||
898 needsOverloadResolutionForMoveConstructor()) &&
899 "move constructor should not be deleted");
900 data().DefaultedMoveConstructorIsDeleted = true;
903 /// \brief Determine whether this class should get an implicit move
904 /// constructor or if any existing special member function inhibits this.
905 bool needsImplicitMoveConstructor() const {
906 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
907 !hasUserDeclaredCopyConstructor() &&
908 !hasUserDeclaredCopyAssignment() &&
909 !hasUserDeclaredMoveAssignment() &&
910 !hasUserDeclaredDestructor();
913 /// \brief Determine whether we need to eagerly declare a defaulted move
914 /// constructor for this class.
915 bool needsOverloadResolutionForMoveConstructor() const {
916 return data().NeedOverloadResolutionForMoveConstructor;
919 /// \brief Determine whether this class has a user-declared copy assignment
922 /// When false, a copy assigment operator will be implicitly declared.
923 bool hasUserDeclaredCopyAssignment() const {
924 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
927 /// \brief Determine whether this class needs an implicit copy
928 /// assignment operator to be lazily declared.
929 bool needsImplicitCopyAssignment() const {
930 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
933 /// \brief Determine whether we need to eagerly declare a defaulted copy
934 /// assignment operator for this class.
935 bool needsOverloadResolutionForCopyAssignment() const {
936 return data().HasMutableFields;
939 /// \brief Determine whether an implicit copy assignment operator for this
940 /// type would have a parameter with a const-qualified reference type.
941 bool implicitCopyAssignmentHasConstParam() const {
942 return data().ImplicitCopyAssignmentHasConstParam;
945 /// \brief Determine whether this class has a copy assignment operator with
946 /// a parameter type which is a reference to a const-qualified type or is not
948 bool hasCopyAssignmentWithConstParam() const {
949 return data().HasDeclaredCopyAssignmentWithConstParam ||
950 (needsImplicitCopyAssignment() &&
951 implicitCopyAssignmentHasConstParam());
954 /// \brief Determine whether this class has had a move assignment
955 /// declared by the user.
956 bool hasUserDeclaredMoveAssignment() const {
957 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
960 /// \brief Determine whether this class has a move assignment operator.
961 bool hasMoveAssignment() const {
962 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
963 needsImplicitMoveAssignment();
966 /// \brief Set that we attempted to declare an implicit move assignment
967 /// operator, but overload resolution failed so we deleted it.
968 void setImplicitMoveAssignmentIsDeleted() {
969 assert((data().DefaultedMoveAssignmentIsDeleted ||
970 needsOverloadResolutionForMoveAssignment()) &&
971 "move assignment should not be deleted");
972 data().DefaultedMoveAssignmentIsDeleted = true;
975 /// \brief Determine whether this class should get an implicit move
976 /// assignment operator or if any existing special member function inhibits
978 bool needsImplicitMoveAssignment() const {
979 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
980 !hasUserDeclaredCopyConstructor() &&
981 !hasUserDeclaredCopyAssignment() &&
982 !hasUserDeclaredMoveConstructor() &&
983 !hasUserDeclaredDestructor();
986 /// \brief Determine whether we need to eagerly declare a move assignment
987 /// operator for this class.
988 bool needsOverloadResolutionForMoveAssignment() const {
989 return data().NeedOverloadResolutionForMoveAssignment;
992 /// \brief Determine whether this class has a user-declared destructor.
994 /// When false, a destructor will be implicitly declared.
995 bool hasUserDeclaredDestructor() const {
996 return data().UserDeclaredSpecialMembers & SMF_Destructor;
999 /// \brief Determine whether this class needs an implicit destructor to
1000 /// be lazily declared.
1001 bool needsImplicitDestructor() const {
1002 return !(data().DeclaredSpecialMembers & SMF_Destructor);
1005 /// \brief Determine whether we need to eagerly declare a destructor for this
1007 bool needsOverloadResolutionForDestructor() const {
1008 return data().NeedOverloadResolutionForDestructor;
1011 /// \brief Determine whether this class describes a lambda function object.
1012 bool isLambda() const {
1013 // An update record can't turn a non-lambda into a lambda.
1014 auto *DD = DefinitionData.getNotUpdated();
1015 return DD && DD->IsLambda;
1018 /// \brief Determine whether this class describes a generic
1019 /// lambda function object (i.e. function call operator is
1021 bool isGenericLambda() const;
1023 /// \brief Retrieve the lambda call operator of the closure type
1024 /// if this is a closure type.
1025 CXXMethodDecl *getLambdaCallOperator() const;
1027 /// \brief Retrieve the lambda static invoker, the address of which
1028 /// is returned by the conversion operator, and the body of which
1029 /// is forwarded to the lambda call operator.
1030 CXXMethodDecl *getLambdaStaticInvoker() const;
1032 /// \brief Retrieve the generic lambda's template parameter list.
1033 /// Returns null if the class does not represent a lambda or a generic
1035 TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1037 LambdaCaptureDefault getLambdaCaptureDefault() const {
1039 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1042 /// \brief For a closure type, retrieve the mapping from captured
1043 /// variables and \c this to the non-static data members that store the
1044 /// values or references of the captures.
1046 /// \param Captures Will be populated with the mapping from captured
1047 /// variables to the corresponding fields.
1049 /// \param ThisCapture Will be set to the field declaration for the
1050 /// \c this capture.
1052 /// \note No entries will be added for init-captures, as they do not capture
1054 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1055 FieldDecl *&ThisCapture) const;
1057 typedef const LambdaCapture *capture_const_iterator;
1058 typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
1060 capture_const_range captures() const {
1061 return capture_const_range(captures_begin(), captures_end());
1063 capture_const_iterator captures_begin() const {
1064 return isLambda() ? getLambdaData().Captures : nullptr;
1066 capture_const_iterator captures_end() const {
1067 return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1071 typedef UnresolvedSetIterator conversion_iterator;
1072 conversion_iterator conversion_begin() const {
1073 return data().Conversions.get(getASTContext()).begin();
1075 conversion_iterator conversion_end() const {
1076 return data().Conversions.get(getASTContext()).end();
1079 /// Removes a conversion function from this class. The conversion
1080 /// function must currently be a member of this class. Furthermore,
1081 /// this class must currently be in the process of being defined.
1082 void removeConversion(const NamedDecl *Old);
1084 /// \brief Get all conversion functions visible in current class,
1085 /// including conversion function templates.
1086 std::pair<conversion_iterator, conversion_iterator>
1087 getVisibleConversionFunctions();
1089 /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1090 /// which is a class with no user-declared constructors, no private
1091 /// or protected non-static data members, no base classes, and no virtual
1092 /// functions (C++ [dcl.init.aggr]p1).
1093 bool isAggregate() const { return data().Aggregate; }
1095 /// \brief Whether this class has any in-class initializers
1096 /// for non-static data members (including those in anonymous unions or
1098 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1100 /// \brief Whether this class or any of its subobjects has any members of
1101 /// reference type which would make value-initialization ill-formed.
1103 /// Per C++03 [dcl.init]p5:
1104 /// - if T is a non-union class type without a user-declared constructor,
1105 /// then every non-static data member and base-class component of T is
1106 /// value-initialized [...] A program that calls for [...]
1107 /// value-initialization of an entity of reference type is ill-formed.
1108 bool hasUninitializedReferenceMember() const {
1109 return !isUnion() && !hasUserDeclaredConstructor() &&
1110 data().HasUninitializedReferenceMember;
1113 /// \brief Whether this class is a POD-type (C++ [class]p4)
1115 /// For purposes of this function a class is POD if it is an aggregate
1116 /// that has no non-static non-POD data members, no reference data
1117 /// members, no user-defined copy assignment operator and no
1118 /// user-defined destructor.
1120 /// Note that this is the C++ TR1 definition of POD.
1121 bool isPOD() const { return data().PlainOldData; }
1123 /// \brief True if this class is C-like, without C++-specific features, e.g.
1124 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1125 bool isCLike() const;
1127 /// \brief Determine whether this is an empty class in the sense of
1128 /// (C++11 [meta.unary.prop]).
1130 /// A non-union class is empty iff it has a virtual function, virtual base,
1131 /// data member (other than 0-width bit-field) or inherits from a non-empty
1134 /// \note This does NOT include a check for union-ness.
1135 bool isEmpty() const { return data().Empty; }
1137 /// Whether this class is polymorphic (C++ [class.virtual]),
1138 /// which means that the class contains or inherits a virtual function.
1139 bool isPolymorphic() const { return data().Polymorphic; }
1141 /// \brief Determine whether this class has a pure virtual function.
1143 /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1144 /// a pure virtual function or inherits a pure virtual function that is
1146 bool isAbstract() const { return data().Abstract; }
1148 /// \brief Determine whether this class has standard layout per
1150 bool isStandardLayout() const { return data().IsStandardLayout; }
1152 /// \brief Determine whether this class, or any of its class subobjects,
1153 /// contains a mutable field.
1154 bool hasMutableFields() const { return data().HasMutableFields; }
1156 /// \brief Determine whether this class has any variant members.
1157 bool hasVariantMembers() const { return data().HasVariantMembers; }
1159 /// \brief Determine whether this class has a trivial default constructor
1160 /// (C++11 [class.ctor]p5).
1161 bool hasTrivialDefaultConstructor() const {
1162 return hasDefaultConstructor() &&
1163 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1166 /// \brief Determine whether this class has a non-trivial default constructor
1167 /// (C++11 [class.ctor]p5).
1168 bool hasNonTrivialDefaultConstructor() const {
1169 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1170 (needsImplicitDefaultConstructor() &&
1171 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1174 /// \brief Determine whether this class has at least one constexpr constructor
1175 /// other than the copy or move constructors.
1176 bool hasConstexprNonCopyMoveConstructor() const {
1177 return data().HasConstexprNonCopyMoveConstructor ||
1178 (needsImplicitDefaultConstructor() &&
1179 defaultedDefaultConstructorIsConstexpr());
1182 /// \brief Determine whether a defaulted default constructor for this class
1183 /// would be constexpr.
1184 bool defaultedDefaultConstructorIsConstexpr() const {
1185 return data().DefaultedDefaultConstructorIsConstexpr &&
1186 (!isUnion() || hasInClassInitializer() || !hasVariantMembers());
1189 /// \brief Determine whether this class has a constexpr default constructor.
1190 bool hasConstexprDefaultConstructor() const {
1191 return data().HasConstexprDefaultConstructor ||
1192 (needsImplicitDefaultConstructor() &&
1193 defaultedDefaultConstructorIsConstexpr());
1196 /// \brief Determine whether this class has a trivial copy constructor
1197 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1198 bool hasTrivialCopyConstructor() const {
1199 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1202 /// \brief Determine whether this class has a non-trivial copy constructor
1203 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1204 bool hasNonTrivialCopyConstructor() const {
1205 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1206 !hasTrivialCopyConstructor();
1209 /// \brief Determine whether this class has a trivial move constructor
1210 /// (C++11 [class.copy]p12)
1211 bool hasTrivialMoveConstructor() const {
1212 return hasMoveConstructor() &&
1213 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1216 /// \brief Determine whether this class has a non-trivial move constructor
1217 /// (C++11 [class.copy]p12)
1218 bool hasNonTrivialMoveConstructor() const {
1219 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1220 (needsImplicitMoveConstructor() &&
1221 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1224 /// \brief Determine whether this class has a trivial copy assignment operator
1225 /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1226 bool hasTrivialCopyAssignment() const {
1227 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1230 /// \brief Determine whether this class has a non-trivial copy assignment
1231 /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1232 bool hasNonTrivialCopyAssignment() const {
1233 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1234 !hasTrivialCopyAssignment();
1237 /// \brief Determine whether this class has a trivial move assignment operator
1238 /// (C++11 [class.copy]p25)
1239 bool hasTrivialMoveAssignment() const {
1240 return hasMoveAssignment() &&
1241 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1244 /// \brief Determine whether this class has a non-trivial move assignment
1245 /// operator (C++11 [class.copy]p25)
1246 bool hasNonTrivialMoveAssignment() const {
1247 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1248 (needsImplicitMoveAssignment() &&
1249 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1252 /// \brief Determine whether this class has a trivial destructor
1253 /// (C++ [class.dtor]p3)
1254 bool hasTrivialDestructor() const {
1255 return data().HasTrivialSpecialMembers & SMF_Destructor;
1258 /// \brief Determine whether this class has a non-trivial destructor
1259 /// (C++ [class.dtor]p3)
1260 bool hasNonTrivialDestructor() const {
1261 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1264 /// \brief Determine whether this class has a destructor which has no
1265 /// semantic effect.
1267 /// Any such destructor will be trivial, public, defaulted and not deleted,
1268 /// and will call only irrelevant destructors.
1269 bool hasIrrelevantDestructor() const {
1270 return data().HasIrrelevantDestructor;
1273 /// \brief Determine whether this class has a non-literal or/ volatile type
1274 /// non-static data member or base class.
1275 bool hasNonLiteralTypeFieldsOrBases() const {
1276 return data().HasNonLiteralTypeFieldsOrBases;
1279 /// \brief Determine whether this class is considered trivially copyable per
1280 /// (C++11 [class]p6).
1281 bool isTriviallyCopyable() const;
1283 /// \brief Determine whether this class is considered trivial.
1285 /// C++11 [class]p6:
1286 /// "A trivial class is a class that has a trivial default constructor and
1287 /// is trivially copiable."
1288 bool isTrivial() const {
1289 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1292 /// \brief Determine whether this class is a literal type.
1294 /// C++11 [basic.types]p10:
1295 /// A class type that has all the following properties:
1296 /// - it has a trivial destructor
1297 /// - every constructor call and full-expression in the
1298 /// brace-or-equal-intializers for non-static data members (if any) is
1299 /// a constant expression.
1300 /// - it is an aggregate type or has at least one constexpr constructor
1301 /// or constructor template that is not a copy or move constructor, and
1302 /// - all of its non-static data members and base classes are of literal
1305 /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1306 /// treating types with trivial default constructors as literal types.
1307 bool isLiteral() const {
1308 return hasTrivialDestructor() &&
1309 (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1310 hasTrivialDefaultConstructor()) &&
1311 !hasNonLiteralTypeFieldsOrBases();
1314 /// \brief If this record is an instantiation of a member class,
1315 /// retrieves the member class from which it was instantiated.
1317 /// This routine will return non-null for (non-templated) member
1318 /// classes of class templates. For example, given:
1321 /// template<typename T>
1327 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1328 /// whose parent is the class template specialization X<int>. For
1329 /// this declaration, getInstantiatedFromMemberClass() will return
1330 /// the CXXRecordDecl X<T>::A. When a complete definition of
1331 /// X<int>::A is required, it will be instantiated from the
1332 /// declaration returned by getInstantiatedFromMemberClass().
1333 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1335 /// \brief If this class is an instantiation of a member class of a
1336 /// class template specialization, retrieves the member specialization
1338 MemberSpecializationInfo *getMemberSpecializationInfo() const {
1339 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1342 /// \brief Specify that this record is an instantiation of the
1343 /// member class \p RD.
1344 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1345 TemplateSpecializationKind TSK);
1347 /// \brief Retrieves the class template that is described by this
1348 /// class declaration.
1350 /// Every class template is represented as a ClassTemplateDecl and a
1351 /// CXXRecordDecl. The former contains template properties (such as
1352 /// the template parameter lists) while the latter contains the
1353 /// actual description of the template's
1354 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1355 /// CXXRecordDecl that from a ClassTemplateDecl, while
1356 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1357 /// a CXXRecordDecl.
1358 ClassTemplateDecl *getDescribedClassTemplate() const {
1359 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1362 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1363 TemplateOrInstantiation = Template;
1366 /// \brief Determine whether this particular class is a specialization or
1367 /// instantiation of a class template or member class of a class template,
1368 /// and how it was instantiated or specialized.
1369 TemplateSpecializationKind getTemplateSpecializationKind() const;
1371 /// \brief Set the kind of specialization or template instantiation this is.
1372 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1374 /// \brief Returns the destructor decl for this class.
1375 CXXDestructorDecl *getDestructor() const;
1377 /// \brief If the class is a local class [class.local], returns
1378 /// the enclosing function declaration.
1379 const FunctionDecl *isLocalClass() const {
1380 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1381 return RD->isLocalClass();
1383 return dyn_cast<FunctionDecl>(getDeclContext());
1386 FunctionDecl *isLocalClass() {
1387 return const_cast<FunctionDecl*>(
1388 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1391 /// \brief Determine whether this dependent class is a current instantiation,
1392 /// when viewed from within the given context.
1393 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1395 /// \brief Determine whether this class is derived from the class \p Base.
1397 /// This routine only determines whether this class is derived from \p Base,
1398 /// but does not account for factors that may make a Derived -> Base class
1399 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1400 /// base class subobjects.
1402 /// \param Base the base class we are searching for.
1404 /// \returns true if this class is derived from Base, false otherwise.
1405 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1407 /// \brief Determine whether this class is derived from the type \p Base.
1409 /// This routine only determines whether this class is derived from \p Base,
1410 /// but does not account for factors that may make a Derived -> Base class
1411 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1412 /// base class subobjects.
1414 /// \param Base the base class we are searching for.
1416 /// \param Paths will contain the paths taken from the current class to the
1417 /// given \p Base class.
1419 /// \returns true if this class is derived from \p Base, false otherwise.
1421 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1422 /// tangling input and output in \p Paths
1423 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1425 /// \brief Determine whether this class is virtually derived from
1426 /// the class \p Base.
1428 /// This routine only determines whether this class is virtually
1429 /// derived from \p Base, but does not account for factors that may
1430 /// make a Derived -> Base class ill-formed, such as
1431 /// private/protected inheritance or multiple, ambiguous base class
1434 /// \param Base the base class we are searching for.
1436 /// \returns true if this class is virtually derived from Base,
1437 /// false otherwise.
1438 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1440 /// \brief Determine whether this class is provably not derived from
1441 /// the type \p Base.
1442 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1444 /// \brief Function type used by forallBases() as a callback.
1446 /// \param BaseDefinition the definition of the base class
1448 /// \returns true if this base matched the search criteria
1449 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1452 /// \brief Determines if the given callback holds for all the direct
1453 /// or indirect base classes of this type.
1455 /// The class itself does not count as a base class. This routine
1456 /// returns false if the class has non-computable base classes.
1458 /// \param BaseMatches Callback invoked for each (direct or indirect) base
1459 /// class of this type, or if \p AllowShortCircuit is true then until a call
1462 /// \param UserData Passed as the second argument of every call to
1465 /// \param AllowShortCircuit if false, forces the callback to be called
1466 /// for every base class, even if a dependent or non-matching base was
1468 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1469 bool AllowShortCircuit = true) const;
1471 /// \brief Function type used by lookupInBases() to determine whether a
1472 /// specific base class subobject matches the lookup criteria.
1474 /// \param Specifier the base-class specifier that describes the inheritance
1475 /// from the base class we are trying to match.
1477 /// \param Path the current path, from the most-derived class down to the
1478 /// base named by the \p Specifier.
1480 /// \param UserData a single pointer to user-specified data, provided to
1481 /// lookupInBases().
1483 /// \returns true if this base matched the search criteria, false otherwise.
1484 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1488 /// \brief Look for entities within the base classes of this C++ class,
1489 /// transitively searching all base class subobjects.
1491 /// This routine uses the callback function \p BaseMatches to find base
1492 /// classes meeting some search criteria, walking all base class subobjects
1493 /// and populating the given \p Paths structure with the paths through the
1494 /// inheritance hierarchy that resulted in a match. On a successful search,
1495 /// the \p Paths structure can be queried to retrieve the matching paths and
1496 /// to determine if there were any ambiguities.
1498 /// \param BaseMatches callback function used to determine whether a given
1499 /// base matches the user-defined search criteria.
1501 /// \param UserData user data pointer that will be provided to \p BaseMatches.
1503 /// \param Paths used to record the paths from this class to its base class
1504 /// subobjects that match the search criteria.
1506 /// \returns true if there exists any path from this class to a base class
1507 /// subobject that matches the search criteria.
1508 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1509 CXXBasePaths &Paths) const;
1511 /// \brief Base-class lookup callback that determines whether the given
1512 /// base class specifier refers to a specific class declaration.
1514 /// This callback can be used with \c lookupInBases() to determine whether
1515 /// a given derived class has is a base class subobject of a particular type.
1516 /// The user data pointer should refer to the canonical CXXRecordDecl of the
1517 /// base class that we are searching for.
1518 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1519 CXXBasePath &Path, void *BaseRecord);
1521 /// \brief Base-class lookup callback that determines whether the
1522 /// given base class specifier refers to a specific class
1523 /// declaration and describes virtual derivation.
1525 /// This callback can be used with \c lookupInBases() to determine
1526 /// whether a given derived class has is a virtual base class
1527 /// subobject of a particular type. The user data pointer should
1528 /// refer to the canonical CXXRecordDecl of the base class that we
1529 /// are searching for.
1530 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1531 CXXBasePath &Path, void *BaseRecord);
1533 /// \brief Base-class lookup callback that determines whether there exists
1534 /// a tag with the given name.
1536 /// This callback can be used with \c lookupInBases() to find tag members
1537 /// of the given name within a C++ class hierarchy. The user data pointer
1538 /// is an opaque \c DeclarationName pointer.
1539 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1540 CXXBasePath &Path, void *Name);
1542 /// \brief Base-class lookup callback that determines whether there exists
1543 /// a member with the given name.
1545 /// This callback can be used with \c lookupInBases() to find members
1546 /// of the given name within a C++ class hierarchy. The user data pointer
1547 /// is an opaque \c DeclarationName pointer.
1548 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1549 CXXBasePath &Path, void *Name);
1551 /// \brief Base-class lookup callback that determines whether there exists
1552 /// a member with the given name that can be used in a nested-name-specifier.
1554 /// This callback can be used with \c lookupInBases() to find membes of
1555 /// the given name within a C++ class hierarchy that can occur within
1556 /// nested-name-specifiers.
1557 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1561 /// \brief Retrieve the final overriders for each virtual member
1562 /// function in the class hierarchy where this class is the
1563 /// most-derived class in the class hierarchy.
1564 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1566 /// \brief Get the indirect primary bases for this class.
1567 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1569 /// Renders and displays an inheritance diagram
1570 /// for this C++ class and all of its base classes (transitively) using
1572 void viewInheritance(ASTContext& Context) const;
1574 /// \brief Calculates the access of a decl that is reached
1576 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1577 AccessSpecifier DeclAccess) {
1578 assert(DeclAccess != AS_none);
1579 if (DeclAccess == AS_private) return AS_none;
1580 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1583 /// \brief Indicates that the declaration of a defaulted or deleted special
1584 /// member function is now complete.
1585 void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1587 /// \brief Indicates that the definition of this class is now complete.
1588 void completeDefinition() override;
1590 /// \brief Indicates that the definition of this class is now complete,
1591 /// and provides a final overrider map to help determine
1593 /// \param FinalOverriders The final overrider map for this class, which can
1594 /// be provided as an optimization for abstract-class checking. If NULL,
1595 /// final overriders will be computed if they are needed to complete the
1597 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1599 /// \brief Determine whether this class may end up being abstract, even though
1600 /// it is not yet known to be abstract.
1602 /// \returns true if this class is not known to be abstract but has any
1603 /// base classes that are abstract. In this case, \c completeDefinition()
1604 /// will need to compute final overriders to determine whether the class is
1605 /// actually abstract.
1606 bool mayBeAbstract() const;
1608 /// \brief If this is the closure type of a lambda expression, retrieve the
1609 /// number to be used for name mangling in the Itanium C++ ABI.
1611 /// Zero indicates that this closure type has internal linkage, so the
1612 /// mangling number does not matter, while a non-zero value indicates which
1613 /// lambda expression this is in this particular context.
1614 unsigned getLambdaManglingNumber() const {
1615 assert(isLambda() && "Not a lambda closure type!");
1616 return getLambdaData().ManglingNumber;
1619 /// \brief Retrieve the declaration that provides additional context for a
1620 /// lambda, when the normal declaration context is not specific enough.
1622 /// Certain contexts (default arguments of in-class function parameters and
1623 /// the initializers of data members) have separate name mangling rules for
1624 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1625 /// the declaration in which the lambda occurs, e.g., the function parameter
1626 /// or the non-static data member. Otherwise, it returns NULL to imply that
1627 /// the declaration context suffices.
1628 Decl *getLambdaContextDecl() const {
1629 assert(isLambda() && "Not a lambda closure type!");
1630 return getLambdaData().ContextDecl;
1633 /// \brief Set the mangling number and context declaration for a lambda
1635 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1636 getLambdaData().ManglingNumber = ManglingNumber;
1637 getLambdaData().ContextDecl = ContextDecl;
1640 /// \brief Returns the inheritance model used for this record.
1641 MSInheritanceAttr::Spelling getMSInheritanceModel() const;
1642 /// \brief Calculate what the inheritance model would be for this class.
1643 MSInheritanceAttr::Spelling calculateInheritanceModel() const;
1645 /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1646 /// member pointer if we can guarantee that zero is not a valid field offset,
1647 /// or if the member pointer has multiple fields. Polymorphic classes have a
1648 /// vfptr at offset zero, so we can use zero for null. If there are multiple
1649 /// fields, we can use zero even if it is a valid field offset because
1650 /// null-ness testing will check the other fields.
1651 bool nullFieldOffsetIsZero() const {
1652 return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1653 getMSInheritanceModel()) ||
1654 (hasDefinition() && isPolymorphic());
1657 /// \brief Controls when vtordisps will be emitted if this record is used as a
1659 MSVtorDispAttr::Mode getMSVtorDispMode() const;
1661 /// \brief Determine whether this lambda expression was known to be dependent
1662 /// at the time it was created, even if its context does not appear to be
1665 /// This flag is a workaround for an issue with parsing, where default
1666 /// arguments are parsed before their enclosing function declarations have
1667 /// been created. This means that any lambda expressions within those
1668 /// default arguments will have as their DeclContext the context enclosing
1669 /// the function declaration, which may be non-dependent even when the
1670 /// function declaration itself is dependent. This flag indicates when we
1671 /// know that the lambda is dependent despite that.
1672 bool isDependentLambda() const {
1673 return isLambda() && getLambdaData().Dependent;
1676 TypeSourceInfo *getLambdaTypeInfo() const {
1677 return getLambdaData().MethodTyInfo;
1680 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1681 static bool classofKind(Kind K) {
1682 return K >= firstCXXRecord && K <= lastCXXRecord;
1685 friend class ASTDeclReader;
1686 friend class ASTDeclWriter;
1687 friend class ASTReader;
1688 friend class ASTWriter;
1691 /// \brief Represents a static or instance method of a struct/union/class.
1693 /// In the terminology of the C++ Standard, these are the (static and
1694 /// non-static) member functions, whether virtual or not.
1695 class CXXMethodDecl : public FunctionDecl {
1696 void anchor() override;
1698 CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1699 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1700 QualType T, TypeSourceInfo *TInfo,
1701 StorageClass SC, bool isInline,
1702 bool isConstexpr, SourceLocation EndLocation)
1703 : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
1704 SC, isInline, isConstexpr) {
1705 if (EndLocation.isValid())
1706 setRangeEnd(EndLocation);
1710 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1711 SourceLocation StartLoc,
1712 const DeclarationNameInfo &NameInfo,
1713 QualType T, TypeSourceInfo *TInfo,
1717 SourceLocation EndLocation);
1719 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1721 bool isStatic() const;
1722 bool isInstance() const { return !isStatic(); }
1724 /// Returns true if the given operator is implicitly static in a record
1726 static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1728 // Any allocation function for a class T is a static member
1729 // (even if not explicitly declared static).
1730 // [class.free]p6 Any deallocation function for a class X is a static member
1731 // (even if not explicitly declared static).
1732 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1733 OOK == OO_Array_Delete;
1736 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1737 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1739 bool isVirtual() const {
1741 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1743 // Member function is virtual if it is marked explicitly so, or if it is
1744 // declared in __interface -- then it is automatically pure virtual.
1745 if (CD->isVirtualAsWritten() || CD->isPure())
1748 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1751 /// \brief Determine whether this is a usual deallocation function
1752 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1753 /// delete or delete[] operator with a particular signature.
1754 bool isUsualDeallocationFunction() const;
1756 /// \brief Determine whether this is a copy-assignment operator, regardless
1757 /// of whether it was declared implicitly or explicitly.
1758 bool isCopyAssignmentOperator() const;
1760 /// \brief Determine whether this is a move assignment operator.
1761 bool isMoveAssignmentOperator() const;
1763 CXXMethodDecl *getCanonicalDecl() override {
1764 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1766 const CXXMethodDecl *getCanonicalDecl() const override {
1767 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1770 CXXMethodDecl *getMostRecentDecl() {
1771 return cast<CXXMethodDecl>(
1772 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
1774 const CXXMethodDecl *getMostRecentDecl() const {
1775 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
1778 /// True if this method is user-declared and was not
1779 /// deleted or defaulted on its first declaration.
1780 bool isUserProvided() const {
1781 return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1785 void addOverriddenMethod(const CXXMethodDecl *MD);
1787 typedef const CXXMethodDecl *const* method_iterator;
1789 method_iterator begin_overridden_methods() const;
1790 method_iterator end_overridden_methods() const;
1791 unsigned size_overridden_methods() const;
1793 /// Returns the parent of this method declaration, which
1794 /// is the class in which this method is defined.
1795 const CXXRecordDecl *getParent() const {
1796 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1799 /// Returns the parent of this method declaration, which
1800 /// is the class in which this method is defined.
1801 CXXRecordDecl *getParent() {
1802 return const_cast<CXXRecordDecl *>(
1803 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1806 /// \brief Returns the type of the \c this pointer.
1808 /// Should only be called for instance (i.e., non-static) methods.
1809 QualType getThisType(ASTContext &C) const;
1811 unsigned getTypeQualifiers() const {
1812 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1815 /// \brief Retrieve the ref-qualifier associated with this method.
1817 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1818 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1826 RefQualifierKind getRefQualifier() const {
1827 return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1830 bool hasInlineBody() const;
1832 /// \brief Determine whether this is a lambda closure type's static member
1833 /// function that is used for the result of the lambda's conversion to
1834 /// function pointer (for a lambda with no captures).
1836 /// The function itself, if used, will have a placeholder body that will be
1837 /// supplied by IR generation to either forward to the function call operator
1838 /// or clone the function call operator.
1839 bool isLambdaStaticInvoker() const;
1841 /// \brief Find the method in \p RD that corresponds to this one.
1843 /// Find if \p RD or one of the classes it inherits from override this method.
1844 /// If so, return it. \p RD is assumed to be a subclass of the class defining
1845 /// this method (or be the class itself), unless \p MayBeBase is set to true.
1847 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1848 bool MayBeBase = false);
1850 const CXXMethodDecl *
1851 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1852 bool MayBeBase = false) const {
1853 return const_cast<CXXMethodDecl *>(this)
1854 ->getCorrespondingMethodInClass(RD, MayBeBase);
1857 // Implement isa/cast/dyncast/etc.
1858 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1859 static bool classofKind(Kind K) {
1860 return K >= firstCXXMethod && K <= lastCXXMethod;
1864 /// \brief Represents a C++ base or member initializer.
1866 /// This is part of a constructor initializer that
1867 /// initializes one non-static member variable or one base class. For
1868 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1873 /// class B : public A {
1876 /// B(A& a) : A(a), f(3.14159) { }
1879 class CXXCtorInitializer {
1880 /// \brief Either the base class name/delegating constructor type (stored as
1881 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1882 /// (IndirectFieldDecl*) being initialized.
1883 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1886 /// \brief The source location for the field name or, for a base initializer
1887 /// pack expansion, the location of the ellipsis.
1889 /// In the case of a delegating
1890 /// constructor, it will still include the type's source location as the
1891 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1892 SourceLocation MemberOrEllipsisLocation;
1894 /// \brief The argument used to initialize the base or member, which may
1895 /// end up constructing an object (when multiple arguments are involved).
1898 /// \brief Location of the left paren of the ctor-initializer.
1899 SourceLocation LParenLoc;
1901 /// \brief Location of the right paren of the ctor-initializer.
1902 SourceLocation RParenLoc;
1904 /// \brief If the initializee is a type, whether that type makes this
1905 /// a delegating initialization.
1906 bool IsDelegating : 1;
1908 /// \brief If the initializer is a base initializer, this keeps track
1909 /// of whether the base is virtual or not.
1912 /// \brief Whether or not the initializer is explicitly written
1916 /// If IsWritten is true, then this number keeps track of the textual order
1917 /// of this initializer in the original sources, counting from 0; otherwise,
1918 /// it stores the number of array index variables stored after this object
1920 unsigned SourceOrderOrNumArrayIndices : 13;
1922 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1923 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1924 SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1927 /// \brief Creates a new base-class initializer.
1929 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1930 SourceLocation L, Expr *Init, SourceLocation R,
1931 SourceLocation EllipsisLoc);
1933 /// \brief Creates a new member initializer.
1935 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1936 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1939 /// \brief Creates a new anonymous field initializer.
1941 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1942 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1945 /// \brief Creates a new delegating initializer.
1947 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1948 SourceLocation L, Expr *Init, SourceLocation R);
1950 /// \brief Creates a new member initializer that optionally contains
1951 /// array indices used to describe an elementwise initialization.
1952 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1953 SourceLocation MemberLoc, SourceLocation L,
1954 Expr *Init, SourceLocation R,
1955 VarDecl **Indices, unsigned NumIndices);
1957 /// \brief Determine whether this initializer is initializing a base class.
1958 bool isBaseInitializer() const {
1959 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1962 /// \brief Determine whether this initializer is initializing a non-static
1964 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1966 bool isAnyMemberInitializer() const {
1967 return isMemberInitializer() || isIndirectMemberInitializer();
1970 bool isIndirectMemberInitializer() const {
1971 return Initializee.is<IndirectFieldDecl*>();
1974 /// \brief Determine whether this initializer is an implicit initializer
1975 /// generated for a field with an initializer defined on the member
1978 /// In-class member initializers (also known as "non-static data member
1979 /// initializations", NSDMIs) were introduced in C++11.
1980 bool isInClassMemberInitializer() const {
1981 return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
1984 /// \brief Determine whether this initializer is creating a delegating
1986 bool isDelegatingInitializer() const {
1987 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1990 /// \brief Determine whether this initializer is a pack expansion.
1991 bool isPackExpansion() const {
1992 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1995 // \brief For a pack expansion, returns the location of the ellipsis.
1996 SourceLocation getEllipsisLoc() const {
1997 assert(isPackExpansion() && "Initializer is not a pack expansion");
1998 return MemberOrEllipsisLocation;
2001 /// If this is a base class initializer, returns the type of the
2002 /// base class with location information. Otherwise, returns an NULL
2004 TypeLoc getBaseClassLoc() const;
2006 /// If this is a base class initializer, returns the type of the base class.
2007 /// Otherwise, returns null.
2008 const Type *getBaseClass() const;
2010 /// Returns whether the base is virtual or not.
2011 bool isBaseVirtual() const {
2012 assert(isBaseInitializer() && "Must call this on base initializer!");
2017 /// \brief Returns the declarator information for a base class or delegating
2019 TypeSourceInfo *getTypeSourceInfo() const {
2020 return Initializee.dyn_cast<TypeSourceInfo *>();
2023 /// \brief If this is a member initializer, returns the declaration of the
2024 /// non-static data member being initialized. Otherwise, returns null.
2025 FieldDecl *getMember() const {
2026 if (isMemberInitializer())
2027 return Initializee.get<FieldDecl*>();
2030 FieldDecl *getAnyMember() const {
2031 if (isMemberInitializer())
2032 return Initializee.get<FieldDecl*>();
2033 if (isIndirectMemberInitializer())
2034 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2038 IndirectFieldDecl *getIndirectMember() const {
2039 if (isIndirectMemberInitializer())
2040 return Initializee.get<IndirectFieldDecl*>();
2044 SourceLocation getMemberLocation() const {
2045 return MemberOrEllipsisLocation;
2048 /// \brief Determine the source location of the initializer.
2049 SourceLocation getSourceLocation() const;
2051 /// \brief Determine the source range covering the entire initializer.
2052 SourceRange getSourceRange() const LLVM_READONLY;
2054 /// \brief Determine whether this initializer is explicitly written
2055 /// in the source code.
2056 bool isWritten() const { return IsWritten; }
2058 /// \brief Return the source position of the initializer, counting from 0.
2059 /// If the initializer was implicit, -1 is returned.
2060 int getSourceOrder() const {
2061 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
2064 /// \brief Set the source order of this initializer.
2066 /// This can only be called once for each initializer; it cannot be called
2067 /// on an initializer having a positive number of (implicit) array indices.
2069 /// This assumes that the initialzier was written in the source code, and
2070 /// ensures that isWritten() returns true.
2071 void setSourceOrder(int pos) {
2072 assert(!IsWritten &&
2073 "calling twice setSourceOrder() on the same initializer");
2074 assert(SourceOrderOrNumArrayIndices == 0 &&
2075 "setSourceOrder() used when there are implicit array indices");
2077 "setSourceOrder() used to make an initializer implicit");
2079 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
2082 SourceLocation getLParenLoc() const { return LParenLoc; }
2083 SourceLocation getRParenLoc() const { return RParenLoc; }
2085 /// \brief Determine the number of implicit array indices used while
2086 /// described an array member initialization.
2087 unsigned getNumArrayIndices() const {
2088 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
2091 /// \brief Retrieve a particular array index variable used to
2092 /// describe an array member initialization.
2093 VarDecl *getArrayIndex(unsigned I) {
2094 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2095 return reinterpret_cast<VarDecl **>(this + 1)[I];
2097 const VarDecl *getArrayIndex(unsigned I) const {
2098 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2099 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
2101 void setArrayIndex(unsigned I, VarDecl *Index) {
2102 assert(I < getNumArrayIndices() && "Out of bounds member array index");
2103 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
2105 ArrayRef<VarDecl *> getArrayIndexes() {
2106 assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
2107 return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
2108 getNumArrayIndices());
2111 /// \brief Get the initializer.
2112 Expr *getInit() const { return static_cast<Expr*>(Init); }
2115 /// \brief Represents a C++ constructor within a class.
2122 /// explicit X(int); // represented by a CXXConstructorDecl.
2125 class CXXConstructorDecl : public CXXMethodDecl {
2126 void anchor() override;
2127 /// \brief Whether this constructor declaration has the \c explicit keyword
2129 bool IsExplicitSpecified : 1;
2131 /// \name Support for base and member initializers.
2133 /// \brief The arguments used to initialize the base or member.
2134 CXXCtorInitializer **CtorInitializers;
2135 unsigned NumCtorInitializers;
2138 CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2139 const DeclarationNameInfo &NameInfo,
2140 QualType T, TypeSourceInfo *TInfo,
2141 bool isExplicitSpecified, bool isInline,
2142 bool isImplicitlyDeclared, bool isConstexpr)
2143 : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2144 SC_None, isInline, isConstexpr, SourceLocation()),
2145 IsExplicitSpecified(isExplicitSpecified), CtorInitializers(nullptr),
2146 NumCtorInitializers(0) {
2147 setImplicit(isImplicitlyDeclared);
2151 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2152 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2153 SourceLocation StartLoc,
2154 const DeclarationNameInfo &NameInfo,
2155 QualType T, TypeSourceInfo *TInfo,
2157 bool isInline, bool isImplicitlyDeclared,
2160 /// \brief Determine whether this constructor declaration has the
2161 /// \c explicit keyword specified.
2162 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2164 /// \brief Determine whether this constructor was marked "explicit" or not.
2165 bool isExplicit() const {
2166 return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
2169 /// \brief Iterates through the member/base initializer list.
2170 typedef CXXCtorInitializer **init_iterator;
2172 /// \brief Iterates through the member/base initializer list.
2173 typedef CXXCtorInitializer * const * init_const_iterator;
2175 typedef llvm::iterator_range<init_iterator> init_range;
2176 typedef llvm::iterator_range<init_const_iterator> init_const_range;
2178 init_range inits() { return init_range(init_begin(), init_end()); }
2179 init_const_range inits() const {
2180 return init_const_range(init_begin(), init_end());
2183 /// \brief Retrieve an iterator to the first initializer.
2184 init_iterator init_begin() { return CtorInitializers; }
2185 /// \brief Retrieve an iterator to the first initializer.
2186 init_const_iterator init_begin() const { return CtorInitializers; }
2188 /// \brief Retrieve an iterator past the last initializer.
2189 init_iterator init_end() {
2190 return CtorInitializers + NumCtorInitializers;
2192 /// \brief Retrieve an iterator past the last initializer.
2193 init_const_iterator init_end() const {
2194 return CtorInitializers + NumCtorInitializers;
2197 typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2198 typedef std::reverse_iterator<init_const_iterator>
2199 init_const_reverse_iterator;
2201 init_reverse_iterator init_rbegin() {
2202 return init_reverse_iterator(init_end());
2204 init_const_reverse_iterator init_rbegin() const {
2205 return init_const_reverse_iterator(init_end());
2208 init_reverse_iterator init_rend() {
2209 return init_reverse_iterator(init_begin());
2211 init_const_reverse_iterator init_rend() const {
2212 return init_const_reverse_iterator(init_begin());
2215 /// \brief Determine the number of arguments used to initialize the member
2217 unsigned getNumCtorInitializers() const {
2218 return NumCtorInitializers;
2221 void setNumCtorInitializers(unsigned numCtorInitializers) {
2222 NumCtorInitializers = numCtorInitializers;
2225 void setCtorInitializers(CXXCtorInitializer ** initializers) {
2226 CtorInitializers = initializers;
2229 /// \brief Determine whether this constructor is a delegating constructor.
2230 bool isDelegatingConstructor() const {
2231 return (getNumCtorInitializers() == 1) &&
2232 CtorInitializers[0]->isDelegatingInitializer();
2235 /// \brief When this constructor delegates to another, retrieve the target.
2236 CXXConstructorDecl *getTargetConstructor() const;
2238 /// Whether this constructor is a default
2239 /// constructor (C++ [class.ctor]p5), which can be used to
2240 /// default-initialize a class of this type.
2241 bool isDefaultConstructor() const;
2243 /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2244 /// which can be used to copy the class.
2246 /// \p TypeQuals will be set to the qualifiers on the
2247 /// argument type. For example, \p TypeQuals would be set to \c
2248 /// Qualifiers::Const for the following copy constructor:
2256 bool isCopyConstructor(unsigned &TypeQuals) const;
2258 /// Whether this constructor is a copy
2259 /// constructor (C++ [class.copy]p2, which can be used to copy the
2261 bool isCopyConstructor() const {
2262 unsigned TypeQuals = 0;
2263 return isCopyConstructor(TypeQuals);
2266 /// \brief Determine whether this constructor is a move constructor
2267 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2269 /// \param TypeQuals If this constructor is a move constructor, will be set
2270 /// to the type qualifiers on the referent of the first parameter's type.
2271 bool isMoveConstructor(unsigned &TypeQuals) const;
2273 /// \brief Determine whether this constructor is a move constructor
2274 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2275 bool isMoveConstructor() const {
2276 unsigned TypeQuals = 0;
2277 return isMoveConstructor(TypeQuals);
2280 /// \brief Determine whether this is a copy or move constructor.
2282 /// \param TypeQuals Will be set to the type qualifiers on the reference
2283 /// parameter, if in fact this is a copy or move constructor.
2284 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2286 /// \brief Determine whether this a copy or move constructor.
2287 bool isCopyOrMoveConstructor() const {
2289 return isCopyOrMoveConstructor(Quals);
2292 /// Whether this constructor is a
2293 /// converting constructor (C++ [class.conv.ctor]), which can be
2294 /// used for user-defined conversions.
2295 bool isConvertingConstructor(bool AllowExplicit) const;
2297 /// \brief Determine whether this is a member template specialization that
2298 /// would copy the object to itself. Such constructors are never used to copy
2300 bool isSpecializationCopyingObject() const;
2302 /// \brief Get the constructor that this inheriting constructor is based on.
2303 const CXXConstructorDecl *getInheritedConstructor() const;
2305 /// \brief Set the constructor that this inheriting constructor is based on.
2306 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2308 const CXXConstructorDecl *getCanonicalDecl() const override {
2309 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2311 CXXConstructorDecl *getCanonicalDecl() override {
2312 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2315 // Implement isa/cast/dyncast/etc.
2316 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2317 static bool classofKind(Kind K) { return K == CXXConstructor; }
2319 friend class ASTDeclReader;
2320 friend class ASTDeclWriter;
2323 /// \brief Represents a C++ destructor within a class.
2330 /// ~X(); // represented by a CXXDestructorDecl.
2333 class CXXDestructorDecl : public CXXMethodDecl {
2334 void anchor() override;
2336 FunctionDecl *OperatorDelete;
2338 CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2339 const DeclarationNameInfo &NameInfo,
2340 QualType T, TypeSourceInfo *TInfo,
2341 bool isInline, bool isImplicitlyDeclared)
2342 : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2343 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2344 OperatorDelete(nullptr) {
2345 setImplicit(isImplicitlyDeclared);
2349 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2350 SourceLocation StartLoc,
2351 const DeclarationNameInfo &NameInfo,
2352 QualType T, TypeSourceInfo* TInfo,
2354 bool isImplicitlyDeclared);
2355 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2357 void setOperatorDelete(FunctionDecl *OD) {
2358 cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete = OD;
2360 const FunctionDecl *getOperatorDelete() const {
2361 return cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete;
2364 // Implement isa/cast/dyncast/etc.
2365 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2366 static bool classofKind(Kind K) { return K == CXXDestructor; }
2368 friend class ASTDeclReader;
2369 friend class ASTDeclWriter;
2372 /// \brief Represents a C++ conversion function within a class.
2379 /// operator bool();
2382 class CXXConversionDecl : public CXXMethodDecl {
2383 void anchor() override;
2384 /// Whether this conversion function declaration is marked
2385 /// "explicit", meaning that it can only be applied when the user
2386 /// explicitly wrote a cast. This is a C++0x feature.
2387 bool IsExplicitSpecified : 1;
2389 CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2390 const DeclarationNameInfo &NameInfo,
2391 QualType T, TypeSourceInfo *TInfo,
2392 bool isInline, bool isExplicitSpecified,
2393 bool isConstexpr, SourceLocation EndLocation)
2394 : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2395 SC_None, isInline, isConstexpr, EndLocation),
2396 IsExplicitSpecified(isExplicitSpecified) { }
2399 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2400 SourceLocation StartLoc,
2401 const DeclarationNameInfo &NameInfo,
2402 QualType T, TypeSourceInfo *TInfo,
2403 bool isInline, bool isExplicit,
2405 SourceLocation EndLocation);
2406 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2408 /// Whether this conversion function declaration is marked
2409 /// "explicit", meaning that it can only be used for direct initialization
2410 /// (including explitly written casts). This is a C++11 feature.
2411 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2413 /// \brief Whether this is an explicit conversion operator (C++11 and later).
2415 /// Explicit conversion operators are only considered for direct
2416 /// initialization, e.g., when the user has explicitly written a cast.
2417 bool isExplicit() const {
2418 return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
2421 /// \brief Returns the type that this conversion function is converting to.
2422 QualType getConversionType() const {
2423 return getType()->getAs<FunctionType>()->getReturnType();
2426 /// \brief Determine whether this conversion function is a conversion from
2427 /// a lambda closure type to a block pointer.
2428 bool isLambdaToBlockPointerConversion() const;
2430 // Implement isa/cast/dyncast/etc.
2431 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2432 static bool classofKind(Kind K) { return K == CXXConversion; }
2434 friend class ASTDeclReader;
2435 friend class ASTDeclWriter;
2438 /// \brief Represents a linkage specification.
2442 /// extern "C" void foo();
2444 class LinkageSpecDecl : public Decl, public DeclContext {
2445 virtual void anchor();
2447 /// \brief Represents the language in a linkage specification.
2449 /// The values are part of the serialization ABI for
2450 /// ASTs and cannot be changed without altering that ABI. To help
2451 /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2452 /// from the dwarf standard.
2454 lang_c = /* DW_LANG_C */ 0x0002,
2455 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2458 /// \brief The language for this linkage specification.
2459 unsigned Language : 3;
2460 /// \brief True if this linkage spec has braces.
2462 /// This is needed so that hasBraces() returns the correct result while the
2463 /// linkage spec body is being parsed. Once RBraceLoc has been set this is
2464 /// not used, so it doesn't need to be serialized.
2465 unsigned HasBraces : 1;
2466 /// \brief The source location for the extern keyword.
2467 SourceLocation ExternLoc;
2468 /// \brief The source location for the right brace (if valid).
2469 SourceLocation RBraceLoc;
2471 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2472 SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2473 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2474 Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2475 RBraceLoc(SourceLocation()) { }
2478 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2479 SourceLocation ExternLoc,
2480 SourceLocation LangLoc, LanguageIDs Lang,
2482 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2484 /// \brief Return the language specified by this linkage specification.
2485 LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2486 /// \brief Set the language specified by this linkage specification.
2487 void setLanguage(LanguageIDs L) { Language = L; }
2489 /// \brief Determines whether this linkage specification had braces in
2490 /// its syntactic form.
2491 bool hasBraces() const {
2492 assert(!RBraceLoc.isValid() || HasBraces);
2496 SourceLocation getExternLoc() const { return ExternLoc; }
2497 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2498 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2499 void setRBraceLoc(SourceLocation L) {
2501 HasBraces = RBraceLoc.isValid();
2504 SourceLocation getLocEnd() const LLVM_READONLY {
2506 return getRBraceLoc();
2507 // No braces: get the end location of the (only) declaration in context
2509 return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2512 SourceRange getSourceRange() const override LLVM_READONLY {
2513 return SourceRange(ExternLoc, getLocEnd());
2516 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2517 static bool classofKind(Kind K) { return K == LinkageSpec; }
2518 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2519 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2521 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2522 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2526 /// \brief Represents C++ using-directive.
2530 /// using namespace std;
2533 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2534 /// artificial names for all using-directives in order to store
2535 /// them in DeclContext effectively.
2536 class UsingDirectiveDecl : public NamedDecl {
2537 void anchor() override;
2538 /// \brief The location of the \c using keyword.
2539 SourceLocation UsingLoc;
2541 /// \brief The location of the \c namespace keyword.
2542 SourceLocation NamespaceLoc;
2544 /// \brief The nested-name-specifier that precedes the namespace.
2545 NestedNameSpecifierLoc QualifierLoc;
2547 /// \brief The namespace nominated by this using-directive.
2548 NamedDecl *NominatedNamespace;
2550 /// Enclosing context containing both using-directive and nominated
2552 DeclContext *CommonAncestor;
2554 /// \brief Returns special DeclarationName used by using-directives.
2556 /// This is only used by DeclContext for storing UsingDirectiveDecls in
2557 /// its lookup structure.
2558 static DeclarationName getName() {
2559 return DeclarationName::getUsingDirectiveName();
2562 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2563 SourceLocation NamespcLoc,
2564 NestedNameSpecifierLoc QualifierLoc,
2565 SourceLocation IdentLoc,
2566 NamedDecl *Nominated,
2567 DeclContext *CommonAncestor)
2568 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2569 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2570 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2573 /// \brief Retrieve the nested-name-specifier that qualifies the
2574 /// name of the namespace, with source-location information.
2575 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2577 /// \brief Retrieve the nested-name-specifier that qualifies the
2578 /// name of the namespace.
2579 NestedNameSpecifier *getQualifier() const {
2580 return QualifierLoc.getNestedNameSpecifier();
2583 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2584 const NamedDecl *getNominatedNamespaceAsWritten() const {
2585 return NominatedNamespace;
2588 /// \brief Returns the namespace nominated by this using-directive.
2589 NamespaceDecl *getNominatedNamespace();
2591 const NamespaceDecl *getNominatedNamespace() const {
2592 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2595 /// \brief Returns the common ancestor context of this using-directive and
2596 /// its nominated namespace.
2597 DeclContext *getCommonAncestor() { return CommonAncestor; }
2598 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2600 /// \brief Return the location of the \c using keyword.
2601 SourceLocation getUsingLoc() const { return UsingLoc; }
2603 // FIXME: Could omit 'Key' in name.
2604 /// \brief Returns the location of the \c namespace keyword.
2605 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2607 /// \brief Returns the location of this using declaration's identifier.
2608 SourceLocation getIdentLocation() const { return getLocation(); }
2610 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2611 SourceLocation UsingLoc,
2612 SourceLocation NamespaceLoc,
2613 NestedNameSpecifierLoc QualifierLoc,
2614 SourceLocation IdentLoc,
2615 NamedDecl *Nominated,
2616 DeclContext *CommonAncestor);
2617 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2619 SourceRange getSourceRange() const override LLVM_READONLY {
2620 return SourceRange(UsingLoc, getLocation());
2623 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2624 static bool classofKind(Kind K) { return K == UsingDirective; }
2626 // Friend for getUsingDirectiveName.
2627 friend class DeclContext;
2629 friend class ASTDeclReader;
2632 /// \brief Represents a C++ namespace alias.
2637 /// namespace Foo = Bar;
2639 class NamespaceAliasDecl : public NamedDecl {
2640 void anchor() override;
2642 /// \brief The location of the \c namespace keyword.
2643 SourceLocation NamespaceLoc;
2645 /// \brief The location of the namespace's identifier.
2647 /// This is accessed by TargetNameLoc.
2648 SourceLocation IdentLoc;
2650 /// \brief The nested-name-specifier that precedes the namespace.
2651 NestedNameSpecifierLoc QualifierLoc;
2653 /// \brief The Decl that this alias points to, either a NamespaceDecl or
2654 /// a NamespaceAliasDecl.
2655 NamedDecl *Namespace;
2657 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2658 SourceLocation AliasLoc, IdentifierInfo *Alias,
2659 NestedNameSpecifierLoc QualifierLoc,
2660 SourceLocation IdentLoc, NamedDecl *Namespace)
2661 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2662 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2663 QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2665 friend class ASTDeclReader;
2668 /// \brief Retrieve the nested-name-specifier that qualifies the
2669 /// name of the namespace, with source-location information.
2670 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2672 /// \brief Retrieve the nested-name-specifier that qualifies the
2673 /// name of the namespace.
2674 NestedNameSpecifier *getQualifier() const {
2675 return QualifierLoc.getNestedNameSpecifier();
2678 /// \brief Retrieve the namespace declaration aliased by this directive.
2679 NamespaceDecl *getNamespace() {
2680 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2681 return AD->getNamespace();
2683 return cast<NamespaceDecl>(Namespace);
2686 const NamespaceDecl *getNamespace() const {
2687 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2690 /// Returns the location of the alias name, i.e. 'foo' in
2691 /// "namespace foo = ns::bar;".
2692 SourceLocation getAliasLoc() const { return getLocation(); }
2694 /// Returns the location of the \c namespace keyword.
2695 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2697 /// Returns the location of the identifier in the named namespace.
2698 SourceLocation getTargetNameLoc() const { return IdentLoc; }
2700 /// \brief Retrieve the namespace that this alias refers to, which
2701 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2702 NamedDecl *getAliasedNamespace() const { return Namespace; }
2704 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2705 SourceLocation NamespaceLoc,
2706 SourceLocation AliasLoc,
2707 IdentifierInfo *Alias,
2708 NestedNameSpecifierLoc QualifierLoc,
2709 SourceLocation IdentLoc,
2710 NamedDecl *Namespace);
2712 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2714 SourceRange getSourceRange() const override LLVM_READONLY {
2715 return SourceRange(NamespaceLoc, IdentLoc);
2718 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2719 static bool classofKind(Kind K) { return K == NamespaceAlias; }
2722 /// \brief Represents a shadow declaration introduced into a scope by a
2723 /// (resolved) using declaration.
2731 /// using A::foo; // <- a UsingDecl
2732 /// // Also creates a UsingShadowDecl for A::foo() in B
2735 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
2736 void anchor() override;
2738 /// The referenced declaration.
2739 NamedDecl *Underlying;
2741 /// \brief The using declaration which introduced this decl or the next using
2742 /// shadow declaration contained in the aforementioned using declaration.
2743 NamedDecl *UsingOrNextShadow;
2744 friend class UsingDecl;
2746 UsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
2747 UsingDecl *Using, NamedDecl *Target)
2748 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2749 redeclarable_base(C), Underlying(Target),
2750 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2752 setDeclName(Target->getDeclName());
2753 IdentifierNamespace = Target->getIdentifierNamespace();
2758 typedef Redeclarable<UsingShadowDecl> redeclarable_base;
2759 UsingShadowDecl *getNextRedeclarationImpl() override {
2760 return getNextRedeclaration();
2762 UsingShadowDecl *getPreviousDeclImpl() override {
2763 return getPreviousDecl();
2765 UsingShadowDecl *getMostRecentDeclImpl() override {
2766 return getMostRecentDecl();
2770 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2771 SourceLocation Loc, UsingDecl *Using,
2772 NamedDecl *Target) {
2773 return new (C, DC) UsingShadowDecl(C, DC, Loc, Using, Target);
2776 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2778 typedef redeclarable_base::redecl_range redecl_range;
2779 typedef redeclarable_base::redecl_iterator redecl_iterator;
2780 using redeclarable_base::redecls_begin;
2781 using redeclarable_base::redecls_end;
2782 using redeclarable_base::redecls;
2783 using redeclarable_base::getPreviousDecl;
2784 using redeclarable_base::getMostRecentDecl;
2786 UsingShadowDecl *getCanonicalDecl() override {
2787 return getFirstDecl();
2789 const UsingShadowDecl *getCanonicalDecl() const {
2790 return getFirstDecl();
2793 /// \brief Gets the underlying declaration which has been brought into the
2795 NamedDecl *getTargetDecl() const { return Underlying; }
2797 /// \brief Sets the underlying declaration which has been brought into the
2799 void setTargetDecl(NamedDecl* ND) {
2800 assert(ND && "Target decl is null!");
2802 IdentifierNamespace = ND->getIdentifierNamespace();
2805 /// \brief Gets the using declaration to which this declaration is tied.
2806 UsingDecl *getUsingDecl() const;
2808 /// \brief The next using shadow declaration contained in the shadow decl
2809 /// chain of the using declaration which introduced this decl.
2810 UsingShadowDecl *getNextUsingShadowDecl() const {
2811 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2814 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2815 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2817 friend class ASTDeclReader;
2818 friend class ASTDeclWriter;
2821 /// \brief Represents a C++ using-declaration.
2825 /// using someNameSpace::someIdentifier;
2827 class UsingDecl : public NamedDecl {
2828 void anchor() override;
2830 /// \brief The source location of the 'using' keyword itself.
2831 SourceLocation UsingLocation;
2833 /// \brief The nested-name-specifier that precedes the name.
2834 NestedNameSpecifierLoc QualifierLoc;
2836 /// \brief Provides source/type location info for the declaration name
2837 /// embedded in the ValueDecl base class.
2838 DeclarationNameLoc DNLoc;
2840 /// \brief The first shadow declaration of the shadow decl chain associated
2841 /// with this using declaration.
2843 /// The bool member of the pair store whether this decl has the \c typename
2845 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2847 UsingDecl(DeclContext *DC, SourceLocation UL,
2848 NestedNameSpecifierLoc QualifierLoc,
2849 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
2850 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2851 UsingLocation(UL), QualifierLoc(QualifierLoc),
2852 DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
2856 /// \brief Return the source location of the 'using' keyword.
2857 SourceLocation getUsingLoc() const { return UsingLocation; }
2859 /// \brief Set the source location of the 'using' keyword.
2860 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2862 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2863 /// with source-location information.
2864 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2866 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2867 NestedNameSpecifier *getQualifier() const {
2868 return QualifierLoc.getNestedNameSpecifier();
2871 DeclarationNameInfo getNameInfo() const {
2872 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2875 /// \brief Return true if it is a C++03 access declaration (no 'using').
2876 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2878 /// \brief Return true if the using declaration has 'typename'.
2879 bool hasTypename() const { return FirstUsingShadow.getInt(); }
2881 /// \brief Sets whether the using declaration has 'typename'.
2882 void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
2884 /// \brief Iterates through the using shadow declarations associated with
2885 /// this using declaration.
2886 class shadow_iterator {
2887 /// \brief The current using shadow declaration.
2888 UsingShadowDecl *Current;
2891 typedef UsingShadowDecl* value_type;
2892 typedef UsingShadowDecl* reference;
2893 typedef UsingShadowDecl* pointer;
2894 typedef std::forward_iterator_tag iterator_category;
2895 typedef std::ptrdiff_t difference_type;
2897 shadow_iterator() : Current(nullptr) { }
2898 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2900 reference operator*() const { return Current; }
2901 pointer operator->() const { return Current; }
2903 shadow_iterator& operator++() {
2904 Current = Current->getNextUsingShadowDecl();
2908 shadow_iterator operator++(int) {
2909 shadow_iterator tmp(*this);
2914 friend bool operator==(shadow_iterator x, shadow_iterator y) {
2915 return x.Current == y.Current;
2917 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2918 return x.Current != y.Current;
2922 typedef llvm::iterator_range<shadow_iterator> shadow_range;
2924 shadow_range shadows() const {
2925 return shadow_range(shadow_begin(), shadow_end());
2927 shadow_iterator shadow_begin() const {
2928 return shadow_iterator(FirstUsingShadow.getPointer());
2930 shadow_iterator shadow_end() const { return shadow_iterator(); }
2932 /// \brief Return the number of shadowed declarations associated with this
2933 /// using declaration.
2934 unsigned shadow_size() const {
2935 return std::distance(shadow_begin(), shadow_end());
2938 void addShadowDecl(UsingShadowDecl *S);
2939 void removeShadowDecl(UsingShadowDecl *S);
2941 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2942 SourceLocation UsingL,
2943 NestedNameSpecifierLoc QualifierLoc,
2944 const DeclarationNameInfo &NameInfo,
2945 bool HasTypenameKeyword);
2947 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2949 SourceRange getSourceRange() const override LLVM_READONLY;
2951 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2952 static bool classofKind(Kind K) { return K == Using; }
2954 friend class ASTDeclReader;
2955 friend class ASTDeclWriter;
2958 /// \brief Represents a dependent using declaration which was not marked with
2961 /// Unlike non-dependent using declarations, these *only* bring through
2962 /// non-types; otherwise they would break two-phase lookup.
2965 /// template \<class T> class A : public Base<T> {
2966 /// using Base<T>::foo;
2969 class UnresolvedUsingValueDecl : public ValueDecl {
2970 void anchor() override;
2972 /// \brief The source location of the 'using' keyword
2973 SourceLocation UsingLocation;
2975 /// \brief The nested-name-specifier that precedes the name.
2976 NestedNameSpecifierLoc QualifierLoc;
2978 /// \brief Provides source/type location info for the declaration name
2979 /// embedded in the ValueDecl base class.
2980 DeclarationNameLoc DNLoc;
2982 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2983 SourceLocation UsingLoc,
2984 NestedNameSpecifierLoc QualifierLoc,
2985 const DeclarationNameInfo &NameInfo)
2986 : ValueDecl(UnresolvedUsingValue, DC,
2987 NameInfo.getLoc(), NameInfo.getName(), Ty),
2988 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2989 DNLoc(NameInfo.getInfo())
2993 /// \brief Returns the source location of the 'using' keyword.
2994 SourceLocation getUsingLoc() const { return UsingLocation; }
2996 /// \brief Set the source location of the 'using' keyword.
2997 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2999 /// \brief Return true if it is a C++03 access declaration (no 'using').
3000 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3002 /// \brief Retrieve the nested-name-specifier that qualifies the name,
3003 /// with source-location information.
3004 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3006 /// \brief Retrieve the nested-name-specifier that qualifies the name.
3007 NestedNameSpecifier *getQualifier() const {
3008 return QualifierLoc.getNestedNameSpecifier();
3011 DeclarationNameInfo getNameInfo() const {
3012 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3015 static UnresolvedUsingValueDecl *
3016 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3017 NestedNameSpecifierLoc QualifierLoc,
3018 const DeclarationNameInfo &NameInfo);
3020 static UnresolvedUsingValueDecl *
3021 CreateDeserialized(ASTContext &C, unsigned ID);
3023 SourceRange getSourceRange() const override LLVM_READONLY;
3025 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3026 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3028 friend class ASTDeclReader;
3029 friend class ASTDeclWriter;
3032 /// \brief Represents a dependent using declaration which was marked with
3036 /// template \<class T> class A : public Base<T> {
3037 /// using typename Base<T>::foo;
3041 /// The type associated with an unresolved using typename decl is
3042 /// currently always a typename type.
3043 class UnresolvedUsingTypenameDecl : public TypeDecl {
3044 void anchor() override;
3046 /// \brief The source location of the 'typename' keyword
3047 SourceLocation TypenameLocation;
3049 /// \brief The nested-name-specifier that precedes the name.
3050 NestedNameSpecifierLoc QualifierLoc;
3052 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3053 SourceLocation TypenameLoc,
3054 NestedNameSpecifierLoc QualifierLoc,
3055 SourceLocation TargetNameLoc,
3056 IdentifierInfo *TargetName)
3057 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3059 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
3061 friend class ASTDeclReader;
3064 /// \brief Returns the source location of the 'using' keyword.
3065 SourceLocation getUsingLoc() const { return getLocStart(); }
3067 /// \brief Returns the source location of the 'typename' keyword.
3068 SourceLocation getTypenameLoc() const { return TypenameLocation; }
3070 /// \brief Retrieve the nested-name-specifier that qualifies the name,
3071 /// with source-location information.
3072 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3074 /// \brief Retrieve the nested-name-specifier that qualifies the name.
3075 NestedNameSpecifier *getQualifier() const {
3076 return QualifierLoc.getNestedNameSpecifier();
3079 static UnresolvedUsingTypenameDecl *
3080 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3081 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3082 SourceLocation TargetNameLoc, DeclarationName TargetName);
3084 static UnresolvedUsingTypenameDecl *
3085 CreateDeserialized(ASTContext &C, unsigned ID);
3087 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3088 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3091 /// \brief Represents a C++11 static_assert declaration.
3092 class StaticAssertDecl : public Decl {
3093 virtual void anchor();
3094 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3095 StringLiteral *Message;
3096 SourceLocation RParenLoc;
3098 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3099 Expr *AssertExpr, StringLiteral *Message,
3100 SourceLocation RParenLoc, bool Failed)
3101 : Decl(StaticAssert, DC, StaticAssertLoc),
3102 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3103 RParenLoc(RParenLoc) { }
3106 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3107 SourceLocation StaticAssertLoc,
3108 Expr *AssertExpr, StringLiteral *Message,
3109 SourceLocation RParenLoc, bool Failed);
3110 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3112 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3113 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3115 StringLiteral *getMessage() { return Message; }
3116 const StringLiteral *getMessage() const { return Message; }
3118 bool isFailed() const { return AssertExprAndFailed.getInt(); }
3120 SourceLocation getRParenLoc() const { return RParenLoc; }
3122 SourceRange getSourceRange() const override LLVM_READONLY {
3123 return SourceRange(getLocation(), getRParenLoc());
3126 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3127 static bool classofKind(Kind K) { return K == StaticAssert; }
3129 friend class ASTDeclReader;
3132 /// An instance of this class represents the declaration of a property
3133 /// member. This is a Microsoft extension to C++, first introduced in
3134 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3135 /// and Managed C++.
3137 /// A property must always be a non-static class member.
3139 /// A property member superficially resembles a non-static data
3140 /// member, except preceded by a property attribute:
3141 /// __declspec(property(get=GetX, put=PutX)) int x;
3142 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3144 /// A reference to a property is always an lvalue. If the lvalue
3145 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3146 /// required, and that member is called with no arguments.
3147 /// If the lvalue is assigned into, then a setter name is required,
3148 /// and that member is called with one argument, the value assigned.
3149 /// Both operations are potentially overloaded. Compound assignments
3150 /// are permitted, as are the increment and decrement operators.
3152 /// The getter and putter methods are permitted to be overloaded,
3153 /// although their return and parameter types are subject to certain
3154 /// restrictions according to the type of the property.
3156 /// A property declared using an incomplete array type may
3157 /// additionally be subscripted, adding extra parameters to the getter
3158 /// and putter methods.
3159 class MSPropertyDecl : public DeclaratorDecl {
3160 IdentifierInfo *GetterId, *SetterId;
3162 MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3163 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3164 IdentifierInfo *Getter, IdentifierInfo *Setter)
3165 : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3166 GetterId(Getter), SetterId(Setter) {}
3169 static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3170 SourceLocation L, DeclarationName N, QualType T,
3171 TypeSourceInfo *TInfo, SourceLocation StartL,
3172 IdentifierInfo *Getter, IdentifierInfo *Setter);
3173 static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3175 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3177 bool hasGetter() const { return GetterId != nullptr; }
3178 IdentifierInfo* getGetterId() const { return GetterId; }
3179 bool hasSetter() const { return SetterId != nullptr; }
3180 IdentifierInfo* getSetterId() const { return SetterId; }
3182 friend class ASTDeclReader;
3185 /// Insertion operator for diagnostics. This allows sending an AccessSpecifier
3186 /// into a diagnostic with <<.
3187 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3188 AccessSpecifier AS);
3190 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3191 AccessSpecifier AS);
3193 } // end namespace clang