1 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the C++ Decl subclasses, other than those for
11 // templates (in DeclTemplate.h) and friends (in DeclFriend.h).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_DECLCXX_H
16 #define LLVM_CLANG_AST_DECLCXX_H
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/TypeLoc.h"
22 #include "clang/AST/UnresolvedSet.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/PointerIntPair.h"
25 #include "llvm/ADT/SmallPtrSet.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 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
73 /// AnyFunctionDecl to any function or function template declaration.
74 template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
75 typedef ::clang::NamedDecl* SimpleType;
76 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
80 template<> struct simplify_type< ::clang::AnyFunctionDecl>
81 : public simplify_type<const ::clang::AnyFunctionDecl> {};
83 // Provide PointerLikeTypeTraits for non-cvr pointers.
85 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
87 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
90 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
91 return ::clang::AnyFunctionDecl::getFromNamedDecl(
92 static_cast< ::clang::NamedDecl*>(P));
95 enum { NumLowBitsAvailable = 2 };
98 } // end namespace llvm
102 /// @brief Represents an access specifier followed by colon ':'.
104 /// An objects of this class represents sugar for the syntactic occurrence
105 /// of an access specifier followed by a colon in the list of member
106 /// specifiers of a C++ class definition.
108 /// Note that they do not represent other uses of access specifiers,
109 /// such as those occurring in a list of base specifiers.
110 /// Also note that this class has nothing to do with so-called
111 /// "access declarations" (C++98 11.3 [class.access.dcl]).
112 class AccessSpecDecl : public Decl {
113 virtual void anchor();
114 /// \brief The location of the ':'.
115 SourceLocation ColonLoc;
117 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
118 SourceLocation ASLoc, SourceLocation ColonLoc)
119 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
122 AccessSpecDecl(EmptyShell Empty)
123 : Decl(AccessSpec, Empty) { }
125 /// \brief The location of the access specifier.
126 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
127 /// \brief Sets the location of the access specifier.
128 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
130 /// \brief The location of the colon following the access specifier.
131 SourceLocation getColonLoc() const { return ColonLoc; }
132 /// \brief Sets the location of the colon.
133 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
135 SourceRange getSourceRange() const LLVM_READONLY {
136 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
139 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
140 DeclContext *DC, SourceLocation ASLoc,
141 SourceLocation ColonLoc) {
142 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
144 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
146 // Implement isa/cast/dyncast/etc.
147 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
148 static bool classofKind(Kind K) { return K == AccessSpec; }
152 /// \brief Represents a base class of a C++ class.
154 /// Each CXXBaseSpecifier represents a single, direct base class (or
155 /// struct) of a C++ class (or struct). It specifies the type of that
156 /// base class, whether it is a virtual or non-virtual base, and what
157 /// level of access (public, protected, private) is used for the
158 /// derivation. For example:
163 /// class C : public virtual A, protected B { };
166 /// In this code, C will have two CXXBaseSpecifiers, one for "public
167 /// virtual A" and the other for "protected B".
168 class CXXBaseSpecifier {
169 /// Range - The source code range that covers the full base
170 /// specifier, including the "virtual" (if present) and access
171 /// specifier (if present).
174 /// \brief The source location of the ellipsis, if this is a pack
176 SourceLocation EllipsisLoc;
178 /// \brief Whether this is a virtual base class or not.
181 /// BaseOfClass - Whether this is the base of a class (true) or of a
182 /// struct (false). This determines the mapping from the access
183 /// specifier as written in the source code to the access specifier
184 /// used for semantic analysis.
185 bool BaseOfClass : 1;
187 /// Access - Access specifier as written in the source code (which
188 /// may be AS_none). The actual type of data stored here is an
189 /// AccessSpecifier, but we use "unsigned" here to work around a
193 /// InheritConstructors - Whether the class contains a using declaration
194 /// to inherit the named class's constructors.
195 bool InheritConstructors : 1;
197 /// BaseTypeInfo - The type of the base class. This will be a class or struct
198 /// (or a typedef of such). The source code range does not include the
199 /// "virtual" or access specifier.
200 TypeSourceInfo *BaseTypeInfo;
203 CXXBaseSpecifier() { }
205 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
206 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
207 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
208 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
210 /// getSourceRange - Retrieves the source range that contains the
211 /// entire base specifier.
212 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
213 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
214 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
216 /// isVirtual - Determines whether the base class is a virtual base
218 bool isVirtual() const { return Virtual; }
220 /// \brief Determine whether this base class is a base of a class declared
221 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
222 bool isBaseOfClass() const { return BaseOfClass; }
224 /// \brief Determine whether this base specifier is a pack expansion.
225 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
227 /// \brief Determine whether this base class's constructors get inherited.
228 bool getInheritConstructors() const { return InheritConstructors; }
230 /// \brief Set that this base class's constructors should be inherited.
231 void setInheritConstructors(bool Inherit = true) {
232 InheritConstructors = Inherit;
235 /// \brief For a pack expansion, determine the location of the ellipsis.
236 SourceLocation getEllipsisLoc() const {
240 /// getAccessSpecifier - Returns the access specifier for this base
241 /// specifier. This is the actual base specifier as used for
242 /// semantic analysis, so the result can never be AS_none. To
243 /// retrieve the access specifier as written in the source code, use
244 /// getAccessSpecifierAsWritten().
245 AccessSpecifier getAccessSpecifier() const {
246 if ((AccessSpecifier)Access == AS_none)
247 return BaseOfClass? AS_private : AS_public;
249 return (AccessSpecifier)Access;
252 /// getAccessSpecifierAsWritten - Retrieves the access specifier as
253 /// written in the source code (which may mean that no access
254 /// specifier was explicitly written). Use getAccessSpecifier() to
255 /// retrieve the access specifier for use in semantic analysis.
256 AccessSpecifier getAccessSpecifierAsWritten() const {
257 return (AccessSpecifier)Access;
260 /// getType - Retrieves the type of the base class. This type will
261 /// always be an unqualified class type.
262 QualType getType() const { return BaseTypeInfo->getType(); }
264 /// getTypeLoc - Retrieves the type and source location of the base class.
265 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
268 /// CXXRecordDecl - Represents a C++ struct/union/class.
269 /// FIXME: This class will disappear once we've properly taught RecordDecl
270 /// to deal with C++-specific things.
271 class CXXRecordDecl : public RecordDecl {
273 friend void TagDecl::startDefinition();
275 struct DefinitionData {
276 DefinitionData(CXXRecordDecl *D);
278 /// UserDeclaredConstructor - True when this class has a
279 /// user-declared constructor.
280 bool UserDeclaredConstructor : 1;
282 /// UserDeclaredCopyConstructor - True when this class has a
283 /// user-declared copy constructor.
284 bool UserDeclaredCopyConstructor : 1;
286 /// UserDeclareMoveConstructor - True when this class has a
287 /// user-declared move constructor.
288 bool UserDeclaredMoveConstructor : 1;
290 /// UserDeclaredCopyAssignment - True when this class has a
291 /// user-declared copy assignment operator.
292 bool UserDeclaredCopyAssignment : 1;
294 /// UserDeclareMoveAssignment - True when this class has a
295 /// user-declared move assignment.
296 bool UserDeclaredMoveAssignment : 1;
298 /// UserDeclaredDestructor - True when this class has a
299 /// user-declared destructor.
300 bool UserDeclaredDestructor : 1;
302 /// Aggregate - True when this class is an aggregate.
305 /// PlainOldData - True when this class is a POD-type.
306 bool PlainOldData : 1;
308 /// Empty - true when this class is empty for traits purposes,
309 /// i.e. has no data members other than 0-width bit-fields, has no
310 /// virtual function/base, and doesn't inherit from a non-empty
311 /// class. Doesn't take union-ness into account.
314 /// Polymorphic - True when this class is polymorphic, i.e. has at
315 /// least one virtual member or derives from a polymorphic class.
316 bool Polymorphic : 1;
318 /// Abstract - True when this class is abstract, i.e. has at least
319 /// one pure virtual function, (that can come from a base class).
322 /// IsStandardLayout - True when this class has standard layout.
324 /// C++0x [class]p7. A standard-layout class is a class that:
325 /// * has no non-static data members of type non-standard-layout class (or
326 /// array of such types) or reference,
327 /// * has no virtual functions (10.3) and no virtual base classes (10.1),
328 /// * has the same access control (Clause 11) for all non-static data
330 /// * has no non-standard-layout base classes,
331 /// * either has no non-static data members in the most derived class and at
332 /// most one base class with non-static data members, or has no base
333 /// classes with non-static data members, and
334 /// * has no base classes of the same type as the first non-static data
336 bool IsStandardLayout : 1;
338 /// HasNoNonEmptyBases - True when there are no non-empty base classes.
340 /// This is a helper bit of state used to implement IsStandardLayout more
342 bool HasNoNonEmptyBases : 1;
344 /// HasPrivateFields - True when there are private non-static data members.
345 bool HasPrivateFields : 1;
347 /// HasProtectedFields - True when there are protected non-static data
349 bool HasProtectedFields : 1;
351 /// HasPublicFields - True when there are private non-static data members.
352 bool HasPublicFields : 1;
354 /// \brief True if this class (or any subobject) has mutable fields.
355 bool HasMutableFields : 1;
357 /// \brief True if there no non-field members declared by the user.
358 bool HasOnlyCMembers : 1;
360 /// \brief True if any field has an in-class initializer.
361 bool HasInClassInitializer : 1;
363 /// HasTrivialDefaultConstructor - True when, if this class has a default
364 /// constructor, this default constructor is trivial.
366 /// C++0x [class.ctor]p5
367 /// A default constructor is trivial if it is not user-provided and if
368 /// -- its class has no virtual functions and no virtual base classes,
370 /// -- no non-static data member of its class has a
371 /// brace-or-equal-initializer, and
372 /// -- all the direct base classes of its class have trivial
373 /// default constructors, and
374 /// -- for all the nonstatic data members of its class that are of class
375 /// type (or array thereof), each such class has a trivial
376 /// default constructor.
377 bool HasTrivialDefaultConstructor : 1;
379 /// HasConstexprNonCopyMoveConstructor - True when this class has at least
380 /// one user-declared constexpr constructor which is neither the copy nor
381 /// move constructor.
382 bool HasConstexprNonCopyMoveConstructor : 1;
384 /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default
385 /// constructor for this class would be constexpr.
386 bool DefaultedDefaultConstructorIsConstexpr : 1;
388 /// HasConstexprDefaultConstructor - True if this class has a constexpr
389 /// default constructor (either user-declared or implicitly declared).
390 bool HasConstexprDefaultConstructor : 1;
392 /// HasTrivialCopyConstructor - True when this class has a trivial copy
395 /// C++0x [class.copy]p13:
396 /// A copy/move constructor for class X is trivial if it is neither
397 /// user-provided and if
398 /// -- class X has no virtual functions and no virtual base classes, and
399 /// -- the constructor selected to copy/move each direct base class
400 /// subobject is trivial, and
401 /// -- for each non-static data member of X that is of class type (or an
402 /// array thereof), the constructor selected to copy/move that member
404 /// otherwise the copy/move constructor is non-trivial.
405 bool HasTrivialCopyConstructor : 1;
407 /// HasTrivialMoveConstructor - True when this class has a trivial move
410 /// C++0x [class.copy]p13:
411 /// A copy/move constructor for class X is trivial if it is neither
412 /// user-provided and if
413 /// -- class X has no virtual functions and no virtual base classes, and
414 /// -- the constructor selected to copy/move each direct base class
415 /// subobject is trivial, and
416 /// -- for each non-static data member of X that is of class type (or an
417 /// array thereof), the constructor selected to copy/move that member
419 /// otherwise the copy/move constructor is non-trivial.
420 bool HasTrivialMoveConstructor : 1;
422 /// HasTrivialCopyAssignment - True when this class has a trivial copy
423 /// assignment operator.
425 /// C++0x [class.copy]p27:
426 /// A copy/move assignment operator for class X is trivial if it is
427 /// neither user-provided nor deleted and if
428 /// -- class X has no virtual functions and no virtual base classes, and
429 /// -- the assignment operator selected to copy/move each direct base
430 /// class subobject is trivial, and
431 /// -- for each non-static data member of X that is of class type (or an
432 /// array thereof), the assignment operator selected to copy/move
433 /// that member is trivial;
434 /// otherwise the copy/move assignment operator is non-trivial.
435 bool HasTrivialCopyAssignment : 1;
437 /// HasTrivialMoveAssignment - True when this class has a trivial move
438 /// assignment operator.
440 /// C++0x [class.copy]p27:
441 /// A copy/move assignment operator for class X is trivial if it is
442 /// neither user-provided nor deleted and if
443 /// -- class X has no virtual functions and no virtual base classes, and
444 /// -- the assignment operator selected to copy/move each direct base
445 /// class subobject is trivial, and
446 /// -- for each non-static data member of X that is of class type (or an
447 /// array thereof), the assignment operator selected to copy/move
448 /// that member is trivial;
449 /// otherwise the copy/move assignment operator is non-trivial.
450 bool HasTrivialMoveAssignment : 1;
452 /// HasTrivialDestructor - True when this class has a trivial destructor.
454 /// C++ [class.dtor]p3. A destructor is trivial if it is an
455 /// implicitly-declared destructor and if:
456 /// * all of the direct base classes of its class have trivial destructors
458 /// * for all of the non-static data members of its class that are of class
459 /// type (or array thereof), each such class has a trivial destructor.
460 bool HasTrivialDestructor : 1;
462 /// HasIrrelevantDestructor - True when this class has a destructor with no
464 bool HasIrrelevantDestructor : 1;
466 /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
467 /// one non-static data member or base class of non-literal or volatile
469 bool HasNonLiteralTypeFieldsOrBases : 1;
471 /// ComputedVisibleConversions - True when visible conversion functions are
472 /// already computed and are available.
473 bool ComputedVisibleConversions : 1;
475 /// \brief Whether we have a C++0x user-provided default constructor (not
476 /// explicitly deleted or defaulted).
477 bool UserProvidedDefaultConstructor : 1;
479 /// \brief Whether we have already declared the default constructor.
480 bool DeclaredDefaultConstructor : 1;
482 /// \brief Whether we have already declared the copy constructor.
483 bool DeclaredCopyConstructor : 1;
485 /// \brief Whether we have already declared the move constructor.
486 bool DeclaredMoveConstructor : 1;
488 /// \brief Whether we have already declared the copy-assignment operator.
489 bool DeclaredCopyAssignment : 1;
491 /// \brief Whether we have already declared the move-assignment operator.
492 bool DeclaredMoveAssignment : 1;
494 /// \brief Whether we have already declared a destructor within the class.
495 bool DeclaredDestructor : 1;
497 /// \brief Whether an implicit move constructor was attempted to be declared
498 /// but would have been deleted.
499 bool FailedImplicitMoveConstructor : 1;
501 /// \brief Whether an implicit move assignment operator was attempted to be
502 /// declared but would have been deleted.
503 bool FailedImplicitMoveAssignment : 1;
505 /// \brief Whether this class describes a C++ lambda.
508 /// NumBases - The number of base class specifiers in Bases.
511 /// NumVBases - The number of virtual base class specifiers in VBases.
514 /// Bases - Base classes of this class.
515 /// FIXME: This is wasted space for a union.
516 LazyCXXBaseSpecifiersPtr Bases;
518 /// VBases - direct and indirect virtual base classes of this class.
519 LazyCXXBaseSpecifiersPtr VBases;
521 /// Conversions - Overload set containing the conversion functions
522 /// of this C++ class (but not its inherited conversion
523 /// functions). Each of the entries in this overload set is a
524 /// CXXConversionDecl.
525 UnresolvedSet<4> Conversions;
527 /// VisibleConversions - Overload set containing the conversion
528 /// functions of this C++ class and all those inherited conversion
529 /// functions that are visible in this class. Each of the entries
530 /// in this overload set is a CXXConversionDecl or a
531 /// FunctionTemplateDecl.
532 UnresolvedSet<4> VisibleConversions;
534 /// Definition - The declaration which defines this record.
535 CXXRecordDecl *Definition;
537 /// FirstFriend - The first friend declaration in this class, or
538 /// null if there aren't any. This is actually currently stored
539 /// in reverse order.
540 FriendDecl *FirstFriend;
542 /// \brief Retrieve the set of direct base classes.
543 CXXBaseSpecifier *getBases() const {
544 if (!Bases.isOffset())
546 return getBasesSlowCase();
549 /// \brief Retrieve the set of virtual base classes.
550 CXXBaseSpecifier *getVBases() const {
551 if (!VBases.isOffset())
552 return VBases.get(0);
553 return getVBasesSlowCase();
557 CXXBaseSpecifier *getBasesSlowCase() const;
558 CXXBaseSpecifier *getVBasesSlowCase() const;
561 /// \brief Describes a C++ closure type (generated by a lambda expression).
562 struct LambdaDefinitionData : public DefinitionData {
563 typedef LambdaExpr::Capture Capture;
565 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent)
566 : DefinitionData(D), Dependent(Dependent), NumCaptures(0),
567 NumExplicitCaptures(0), ManglingNumber(0), ContextDecl(0), Captures(0),
573 /// \brief Whether this lambda is known to be dependent, even if its
574 /// context isn't dependent.
576 /// A lambda with a non-dependent context can be dependent if it occurs
577 /// within the default argument of a function template, because the
578 /// lambda will have been created with the enclosing context as its
579 /// declaration context, rather than function. This is an unfortunate
580 /// artifact of having to parse the default arguments before
581 unsigned Dependent : 1;
583 /// \brief The number of captures in this lambda.
584 unsigned NumCaptures : 16;
586 /// \brief The number of explicit captures in this lambda.
587 unsigned NumExplicitCaptures : 15;
589 /// \brief The number used to indicate this lambda expression for name
590 /// mangling in the Itanium C++ ABI.
591 unsigned ManglingNumber;
593 /// \brief The declaration that provides context for this lambda, if the
594 /// actual DeclContext does not suffice. This is used for lambdas that
595 /// occur within default arguments of function parameters within the class
596 /// or within a data member initializer.
599 /// \brief The list of captures, both explicit and implicit, for this
603 /// \brief The type of the call method.
604 TypeSourceInfo *MethodTyInfo;
607 struct DefinitionData &data() {
608 assert(DefinitionData && "queried property of class with no definition");
609 return *DefinitionData;
612 const struct DefinitionData &data() const {
613 assert(DefinitionData && "queried property of class with no definition");
614 return *DefinitionData;
617 struct LambdaDefinitionData &getLambdaData() const {
618 assert(DefinitionData && "queried property of lambda with no definition");
619 assert(DefinitionData->IsLambda &&
620 "queried lambda property of non-lambda class");
621 return static_cast<LambdaDefinitionData &>(*DefinitionData);
624 /// \brief The template or declaration that this declaration
625 /// describes or was instantiated from, respectively.
627 /// For non-templates, this value will be NULL. For record
628 /// declarations that describe a class template, this will be a
629 /// pointer to a ClassTemplateDecl. For member
630 /// classes of class template specializations, this will be the
631 /// MemberSpecializationInfo referring to the member class that was
632 /// instantiated or specialized.
633 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
634 TemplateOrInstantiation;
636 friend class DeclContext;
637 friend class LambdaExpr;
639 /// \brief Notify the class that member has been added.
641 /// This routine helps maintain information about the class based on which
642 /// members have been added. It will be invoked by DeclContext::addDecl()
643 /// whenever a member is added to this record.
644 void addedMember(Decl *D);
646 void markedVirtualFunctionPure();
647 friend void FunctionDecl::setPure(bool);
649 void markedConstructorConstexpr(CXXConstructorDecl *CD);
650 friend void FunctionDecl::setConstexpr(bool);
652 friend class ASTNodeImporter;
655 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
656 SourceLocation StartLoc, SourceLocation IdLoc,
657 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
660 /// base_class_iterator - Iterator that traverses the base classes
662 typedef CXXBaseSpecifier* base_class_iterator;
664 /// base_class_const_iterator - Iterator that traverses the base
665 /// classes of a class.
666 typedef const CXXBaseSpecifier* base_class_const_iterator;
668 /// reverse_base_class_iterator = Iterator that traverses the base classes
669 /// of a class in reverse order.
670 typedef std::reverse_iterator<base_class_iterator>
671 reverse_base_class_iterator;
673 /// reverse_base_class_iterator = Iterator that traverses the base classes
674 /// of a class in reverse order.
675 typedef std::reverse_iterator<base_class_const_iterator>
676 reverse_base_class_const_iterator;
678 virtual CXXRecordDecl *getCanonicalDecl() {
679 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
681 virtual const CXXRecordDecl *getCanonicalDecl() const {
682 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
685 const CXXRecordDecl *getPreviousDecl() const {
686 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
688 CXXRecordDecl *getPreviousDecl() {
689 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
692 const CXXRecordDecl *getMostRecentDecl() const {
693 return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
695 CXXRecordDecl *getMostRecentDecl() {
696 return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
699 CXXRecordDecl *getDefinition() const {
700 if (!DefinitionData) return 0;
701 return data().Definition;
704 bool hasDefinition() const { return DefinitionData != 0; }
706 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
707 SourceLocation StartLoc, SourceLocation IdLoc,
708 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
709 bool DelayTypeCreation = false);
710 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
711 TypeSourceInfo *Info, SourceLocation Loc,
712 bool DependentLambda);
713 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
715 bool isDynamicClass() const {
716 return data().Polymorphic || data().NumVBases != 0;
719 /// setBases - Sets the base classes of this struct or class.
720 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
722 /// getNumBases - Retrieves the number of base classes of this
724 unsigned getNumBases() const { return data().NumBases; }
726 base_class_iterator bases_begin() { return data().getBases(); }
727 base_class_const_iterator bases_begin() const { return data().getBases(); }
728 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
729 base_class_const_iterator bases_end() const {
730 return bases_begin() + data().NumBases;
732 reverse_base_class_iterator bases_rbegin() {
733 return reverse_base_class_iterator(bases_end());
735 reverse_base_class_const_iterator bases_rbegin() const {
736 return reverse_base_class_const_iterator(bases_end());
738 reverse_base_class_iterator bases_rend() {
739 return reverse_base_class_iterator(bases_begin());
741 reverse_base_class_const_iterator bases_rend() const {
742 return reverse_base_class_const_iterator(bases_begin());
745 /// getNumVBases - Retrieves the number of virtual base classes of this
747 unsigned getNumVBases() const { return data().NumVBases; }
749 base_class_iterator vbases_begin() { return data().getVBases(); }
750 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
751 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
752 base_class_const_iterator vbases_end() const {
753 return vbases_begin() + data().NumVBases;
755 reverse_base_class_iterator vbases_rbegin() {
756 return reverse_base_class_iterator(vbases_end());
758 reverse_base_class_const_iterator vbases_rbegin() const {
759 return reverse_base_class_const_iterator(vbases_end());
761 reverse_base_class_iterator vbases_rend() {
762 return reverse_base_class_iterator(vbases_begin());
764 reverse_base_class_const_iterator vbases_rend() const {
765 return reverse_base_class_const_iterator(vbases_begin());
768 /// \brief Determine whether this class has any dependent base classes.
769 bool hasAnyDependentBases() const;
771 /// Iterator access to method members. The method iterator visits
772 /// all method members of the class, including non-instance methods,
773 /// special methods, etc.
774 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
776 /// method_begin - Method begin iterator. Iterates in the order the methods
778 method_iterator method_begin() const {
779 return method_iterator(decls_begin());
781 /// method_end - Method end iterator.
782 method_iterator method_end() const {
783 return method_iterator(decls_end());
786 /// Iterator access to constructor members.
787 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
789 ctor_iterator ctor_begin() const {
790 return ctor_iterator(decls_begin());
792 ctor_iterator ctor_end() const {
793 return ctor_iterator(decls_end());
796 /// An iterator over friend declarations. All of these are defined
798 class friend_iterator;
799 friend_iterator friend_begin() const;
800 friend_iterator friend_end() const;
801 void pushFriendDecl(FriendDecl *FD);
803 /// Determines whether this record has any friends.
804 bool hasFriends() const {
805 return data().FirstFriend != 0;
808 /// \brief Determine if we need to declare a default constructor for
811 /// This value is used for lazy creation of default constructors.
812 bool needsImplicitDefaultConstructor() const {
813 return !data().UserDeclaredConstructor &&
814 !data().DeclaredDefaultConstructor;
817 /// hasDeclaredDefaultConstructor - Whether this class's default constructor
818 /// has been declared (either explicitly or implicitly).
819 bool hasDeclaredDefaultConstructor() const {
820 return data().DeclaredDefaultConstructor;
823 /// hasConstCopyConstructor - Determines whether this class has a
824 /// copy constructor that accepts a const-qualified argument.
825 bool hasConstCopyConstructor() const;
827 /// getCopyConstructor - Returns the copy constructor for this class
828 CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const;
830 /// getMoveConstructor - Returns the move constructor for this class
831 CXXConstructorDecl *getMoveConstructor() const;
833 /// \brief Retrieve the copy-assignment operator for this class, if available.
835 /// This routine attempts to find the copy-assignment operator for this
836 /// class, using a simplistic form of overload resolution.
838 /// \param ArgIsConst Whether the argument to the copy-assignment operator
839 /// is const-qualified.
841 /// \returns The copy-assignment operator that can be invoked, or NULL if
842 /// a unique copy-assignment operator could not be found.
843 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
845 /// getMoveAssignmentOperator - Returns the move assignment operator for this
847 CXXMethodDecl *getMoveAssignmentOperator() const;
849 /// hasUserDeclaredConstructor - Whether this class has any
850 /// user-declared constructors. When true, a default constructor
851 /// will not be implicitly declared.
852 bool hasUserDeclaredConstructor() const {
853 return data().UserDeclaredConstructor;
856 /// hasUserProvidedDefaultconstructor - Whether this class has a
857 /// user-provided default constructor per C++0x.
858 bool hasUserProvidedDefaultConstructor() const {
859 return data().UserProvidedDefaultConstructor;
862 /// hasUserDeclaredCopyConstructor - Whether this class has a
863 /// user-declared copy constructor. When false, a copy constructor
864 /// will be implicitly declared.
865 bool hasUserDeclaredCopyConstructor() const {
866 return data().UserDeclaredCopyConstructor;
869 /// \brief Determine whether this class has had its copy constructor
870 /// declared, either via the user or via an implicit declaration.
872 /// This value is used for lazy creation of copy constructors.
873 bool hasDeclaredCopyConstructor() const {
874 return data().DeclaredCopyConstructor;
877 /// hasUserDeclaredMoveOperation - Whether this class has a user-
878 /// declared move constructor or assignment operator. When false, a
879 /// move constructor and assignment operator may be implicitly declared.
880 bool hasUserDeclaredMoveOperation() const {
881 return data().UserDeclaredMoveConstructor ||
882 data().UserDeclaredMoveAssignment;
885 /// \brief Determine whether this class has had a move constructor
886 /// declared by the user.
887 bool hasUserDeclaredMoveConstructor() const {
888 return data().UserDeclaredMoveConstructor;
891 /// \brief Determine whether this class has had a move constructor
893 bool hasDeclaredMoveConstructor() const {
894 return data().DeclaredMoveConstructor;
897 /// \brief Determine whether implicit move constructor generation for this
898 /// class has failed before.
899 bool hasFailedImplicitMoveConstructor() const {
900 return data().FailedImplicitMoveConstructor;
903 /// \brief Set whether implicit move constructor generation for this class
904 /// has failed before.
905 void setFailedImplicitMoveConstructor(bool Failed = true) {
906 data().FailedImplicitMoveConstructor = Failed;
909 /// \brief Determine whether this class should get an implicit move
910 /// constructor or if any existing special member function inhibits this.
912 /// Covers all bullets of C++0x [class.copy]p9 except the last, that the
913 /// constructor wouldn't be deleted, which is only looked up from a cached
915 bool needsImplicitMoveConstructor() const {
916 return !hasFailedImplicitMoveConstructor() &&
917 !hasDeclaredMoveConstructor() &&
918 !hasUserDeclaredCopyConstructor() &&
919 !hasUserDeclaredCopyAssignment() &&
920 !hasUserDeclaredMoveAssignment() &&
921 !hasUserDeclaredDestructor();
924 /// hasUserDeclaredCopyAssignment - Whether this class has a
925 /// user-declared copy assignment operator. When false, a copy
926 /// assigment operator will be implicitly declared.
927 bool hasUserDeclaredCopyAssignment() const {
928 return data().UserDeclaredCopyAssignment;
931 /// \brief Determine whether this class has had its copy assignment operator
932 /// declared, either via the user or via an implicit declaration.
934 /// This value is used for lazy creation of copy assignment operators.
935 bool hasDeclaredCopyAssignment() const {
936 return data().DeclaredCopyAssignment;
939 /// \brief Determine whether this class has had a move assignment
940 /// declared by the user.
941 bool hasUserDeclaredMoveAssignment() const {
942 return data().UserDeclaredMoveAssignment;
945 /// hasDeclaredMoveAssignment - Whether this class has a
946 /// declared move assignment operator.
947 bool hasDeclaredMoveAssignment() const {
948 return data().DeclaredMoveAssignment;
951 /// \brief Determine whether implicit move assignment generation for this
952 /// class has failed before.
953 bool hasFailedImplicitMoveAssignment() const {
954 return data().FailedImplicitMoveAssignment;
957 /// \brief Set whether implicit move assignment generation for this class
958 /// has failed before.
959 void setFailedImplicitMoveAssignment(bool Failed = true) {
960 data().FailedImplicitMoveAssignment = Failed;
963 /// \brief Determine whether this class should get an implicit move
964 /// assignment operator or if any existing special member function inhibits
967 /// Covers all bullets of C++0x [class.copy]p20 except the last, that the
968 /// constructor wouldn't be deleted.
969 bool needsImplicitMoveAssignment() const {
970 return !hasFailedImplicitMoveAssignment() &&
971 !hasDeclaredMoveAssignment() &&
972 !hasUserDeclaredCopyConstructor() &&
973 !hasUserDeclaredCopyAssignment() &&
974 !hasUserDeclaredMoveConstructor() &&
975 !hasUserDeclaredDestructor();
978 /// hasUserDeclaredDestructor - Whether this class has a
979 /// user-declared destructor. When false, a destructor will be
980 /// implicitly declared.
981 bool hasUserDeclaredDestructor() const {
982 return data().UserDeclaredDestructor;
985 /// \brief Determine whether this class has had its destructor declared,
986 /// either via the user or via an implicit declaration.
988 /// This value is used for lazy creation of destructors.
989 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
991 /// \brief Determine whether this class describes a lambda function object.
992 bool isLambda() const { return hasDefinition() && data().IsLambda; }
994 /// \brief For a closure type, retrieve the mapping from captured
995 /// variables and this to the non-static data members that store the
996 /// values or references of the captures.
998 /// \param Captures Will be populated with the mapping from captured
999 /// variables to the corresponding fields.
1001 /// \param ThisCapture Will be set to the field declaration for the
1003 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1004 FieldDecl *&ThisCapture) const;
1006 typedef const LambdaExpr::Capture* capture_const_iterator;
1007 capture_const_iterator captures_begin() const {
1008 return isLambda() ? getLambdaData().Captures : NULL;
1010 capture_const_iterator captures_end() const {
1011 return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
1014 /// getConversions - Retrieve the overload set containing all of the
1015 /// conversion functions in this class.
1016 UnresolvedSetImpl *getConversionFunctions() {
1017 return &data().Conversions;
1019 const UnresolvedSetImpl *getConversionFunctions() const {
1020 return &data().Conversions;
1023 typedef UnresolvedSetImpl::iterator conversion_iterator;
1024 conversion_iterator conversion_begin() const {
1025 return getConversionFunctions()->begin();
1027 conversion_iterator conversion_end() const {
1028 return getConversionFunctions()->end();
1031 /// Removes a conversion function from this class. The conversion
1032 /// function must currently be a member of this class. Furthermore,
1033 /// this class must currently be in the process of being defined.
1034 void removeConversion(const NamedDecl *Old);
1036 /// getVisibleConversionFunctions - get all conversion functions visible
1037 /// in current class; including conversion function templates.
1038 const UnresolvedSetImpl *getVisibleConversionFunctions();
1040 /// isAggregate - Whether this class is an aggregate (C++
1041 /// [dcl.init.aggr]), which is a class with no user-declared
1042 /// constructors, no private or protected non-static data members,
1043 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
1044 bool isAggregate() const { return data().Aggregate; }
1046 /// hasInClassInitializer - Whether this class has any in-class initializers
1047 /// for non-static data members.
1048 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1050 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
1051 /// that is an aggregate that has no non-static non-POD data members, no
1052 /// reference data members, no user-defined copy assignment operator and no
1053 /// user-defined destructor.
1054 bool isPOD() const { return data().PlainOldData; }
1056 /// \brief True if this class is C-like, without C++-specific features, e.g.
1057 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1058 bool isCLike() const;
1060 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
1061 /// means it has a virtual function, virtual base, data member (other than
1062 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
1063 /// a check for union-ness.
1064 bool isEmpty() const { return data().Empty; }
1066 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
1067 /// which means that the class contains or inherits a virtual function.
1068 bool isPolymorphic() const { return data().Polymorphic; }
1070 /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
1071 /// which means that the class contains or inherits a pure virtual function.
1072 bool isAbstract() const { return data().Abstract; }
1074 /// isStandardLayout - Whether this class has standard layout
1076 bool isStandardLayout() const { return data().IsStandardLayout; }
1078 /// \brief Whether this class, or any of its class subobjects, contains a
1080 bool hasMutableFields() const { return data().HasMutableFields; }
1082 /// hasTrivialDefaultConstructor - Whether this class has a trivial default
1083 /// constructor (C++11 [class.ctor]p5).
1084 bool hasTrivialDefaultConstructor() const {
1085 return data().HasTrivialDefaultConstructor &&
1086 (!data().UserDeclaredConstructor ||
1087 data().DeclaredDefaultConstructor);
1090 /// hasConstexprNonCopyMoveConstructor - Whether this class has at least one
1091 /// constexpr constructor other than the copy or move constructors.
1092 bool hasConstexprNonCopyMoveConstructor() const {
1093 return data().HasConstexprNonCopyMoveConstructor ||
1094 (!hasUserDeclaredConstructor() &&
1095 defaultedDefaultConstructorIsConstexpr());
1098 /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default
1099 /// constructor for this class would be constexpr.
1100 bool defaultedDefaultConstructorIsConstexpr() const {
1101 return data().DefaultedDefaultConstructorIsConstexpr &&
1102 (!isUnion() || hasInClassInitializer());
1105 /// hasConstexprDefaultConstructor - Whether this class has a constexpr
1106 /// default constructor.
1107 bool hasConstexprDefaultConstructor() const {
1108 return data().HasConstexprDefaultConstructor ||
1109 (!data().UserDeclaredConstructor &&
1110 defaultedDefaultConstructorIsConstexpr());
1113 // hasTrivialCopyConstructor - Whether this class has a trivial copy
1114 // constructor (C++ [class.copy]p6, C++0x [class.copy]p13)
1115 bool hasTrivialCopyConstructor() const {
1116 return data().HasTrivialCopyConstructor;
1119 // hasTrivialMoveConstructor - Whether this class has a trivial move
1120 // constructor (C++0x [class.copy]p13)
1121 bool hasTrivialMoveConstructor() const {
1122 return data().HasTrivialMoveConstructor;
1125 // hasTrivialCopyAssignment - Whether this class has a trivial copy
1126 // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27)
1127 bool hasTrivialCopyAssignment() const {
1128 return data().HasTrivialCopyAssignment;
1131 // hasTrivialMoveAssignment - Whether this class has a trivial move
1132 // assignment operator (C++0x [class.copy]p27)
1133 bool hasTrivialMoveAssignment() const {
1134 return data().HasTrivialMoveAssignment;
1137 // hasTrivialDestructor - Whether this class has a trivial destructor
1138 // (C++ [class.dtor]p3)
1139 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
1141 // hasIrrelevantDestructor - Whether this class has a destructor which has no
1142 // semantic effect. Any such destructor will be trivial, public, defaulted
1143 // and not deleted, and will call only irrelevant destructors.
1144 bool hasIrrelevantDestructor() const {
1145 return data().HasIrrelevantDestructor;
1148 // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or
1149 // volatile type non-static data member or base class.
1150 bool hasNonLiteralTypeFieldsOrBases() const {
1151 return data().HasNonLiteralTypeFieldsOrBases;
1154 // isTriviallyCopyable - Whether this class is considered trivially copyable
1155 // (C++0x [class]p6).
1156 bool isTriviallyCopyable() const;
1158 // isTrivial - Whether this class is considered trivial
1161 // A trivial class is a class that has a trivial default constructor and
1162 // is trivially copiable.
1163 bool isTrivial() const {
1164 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1167 // isLiteral - Whether this class is a literal type.
1169 // C++11 [basic.types]p10
1170 // A class type that has all the following properties:
1171 // -- it has a trivial destructor
1172 // -- every constructor call and full-expression in the
1173 // brace-or-equal-intializers for non-static data members (if any) is
1174 // a constant expression.
1175 // -- it is an aggregate type or has at least one constexpr constructor or
1176 // constructor template that is not a copy or move constructor, and
1177 // -- all of its non-static data members and base classes are of literal
1180 // We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1181 // treating types with trivial default constructors as literal types.
1182 bool isLiteral() const {
1183 return hasTrivialDestructor() &&
1184 (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1185 hasTrivialDefaultConstructor()) &&
1186 !hasNonLiteralTypeFieldsOrBases();
1189 /// \brief If this record is an instantiation of a member class,
1190 /// retrieves the member class from which it was instantiated.
1192 /// This routine will return non-NULL for (non-templated) member
1193 /// classes of class templates. For example, given:
1196 /// template<typename T>
1202 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1203 /// whose parent is the class template specialization X<int>. For
1204 /// this declaration, getInstantiatedFromMemberClass() will return
1205 /// the CXXRecordDecl X<T>::A. When a complete definition of
1206 /// X<int>::A is required, it will be instantiated from the
1207 /// declaration returned by getInstantiatedFromMemberClass().
1208 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1210 /// \brief If this class is an instantiation of a member class of a
1211 /// class template specialization, retrieves the member specialization
1213 MemberSpecializationInfo *getMemberSpecializationInfo() const;
1215 /// \brief Specify that this record is an instantiation of the
1216 /// member class RD.
1217 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1218 TemplateSpecializationKind TSK);
1220 /// \brief Retrieves the class template that is described by this
1221 /// class declaration.
1223 /// Every class template is represented as a ClassTemplateDecl and a
1224 /// CXXRecordDecl. The former contains template properties (such as
1225 /// the template parameter lists) while the latter contains the
1226 /// actual description of the template's
1227 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1228 /// CXXRecordDecl that from a ClassTemplateDecl, while
1229 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1230 /// a CXXRecordDecl.
1231 ClassTemplateDecl *getDescribedClassTemplate() const {
1232 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1235 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1236 TemplateOrInstantiation = Template;
1239 /// \brief Determine whether this particular class is a specialization or
1240 /// instantiation of a class template or member class of a class template,
1241 /// and how it was instantiated or specialized.
1242 TemplateSpecializationKind getTemplateSpecializationKind() const;
1244 /// \brief Set the kind of specialization or template instantiation this is.
1245 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1247 /// getDestructor - Returns the destructor decl for this class.
1248 CXXDestructorDecl *getDestructor() const;
1250 /// isLocalClass - If the class is a local class [class.local], returns
1251 /// the enclosing function declaration.
1252 const FunctionDecl *isLocalClass() const {
1253 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1254 return RD->isLocalClass();
1256 return dyn_cast<FunctionDecl>(getDeclContext());
1259 /// \brief Determine whether this class is derived from the class \p Base.
1261 /// This routine only determines whether this class is derived from \p Base,
1262 /// but does not account for factors that may make a Derived -> Base class
1263 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1264 /// base class subobjects.
1266 /// \param Base the base class we are searching for.
1268 /// \returns true if this class is derived from Base, false otherwise.
1269 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1271 /// \brief Determine whether this class is derived from the type \p Base.
1273 /// This routine only determines whether this class is derived from \p Base,
1274 /// but does not account for factors that may make a Derived -> Base class
1275 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1276 /// base class subobjects.
1278 /// \param Base the base class we are searching for.
1280 /// \param Paths will contain the paths taken from the current class to the
1281 /// given \p Base class.
1283 /// \returns true if this class is derived from Base, false otherwise.
1285 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1286 /// tangling input and output in \p Paths
1287 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1289 /// \brief Determine whether this class is virtually derived from
1290 /// the class \p Base.
1292 /// This routine only determines whether this class is virtually
1293 /// derived from \p Base, but does not account for factors that may
1294 /// make a Derived -> Base class ill-formed, such as
1295 /// private/protected inheritance or multiple, ambiguous base class
1298 /// \param Base the base class we are searching for.
1300 /// \returns true if this class is virtually derived from Base,
1301 /// false otherwise.
1302 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1304 /// \brief Determine whether this class is provably not derived from
1305 /// the type \p Base.
1306 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1308 /// \brief Function type used by forallBases() as a callback.
1310 /// \param BaseDefinition the definition of the base class
1312 /// \returns true if this base matched the search criteria
1313 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1316 /// \brief Determines if the given callback holds for all the direct
1317 /// or indirect base classes of this type.
1319 /// The class itself does not count as a base class. This routine
1320 /// returns false if the class has non-computable base classes.
1322 /// \param AllowShortCircuit if false, forces the callback to be called
1323 /// for every base class, even if a dependent or non-matching base was
1325 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1326 bool AllowShortCircuit = true) const;
1328 /// \brief Function type used by lookupInBases() to determine whether a
1329 /// specific base class subobject matches the lookup criteria.
1331 /// \param Specifier the base-class specifier that describes the inheritance
1332 /// from the base class we are trying to match.
1334 /// \param Path the current path, from the most-derived class down to the
1335 /// base named by the \p Specifier.
1337 /// \param UserData a single pointer to user-specified data, provided to
1338 /// lookupInBases().
1340 /// \returns true if this base matched the search criteria, false otherwise.
1341 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1345 /// \brief Look for entities within the base classes of this C++ class,
1346 /// transitively searching all base class subobjects.
1348 /// This routine uses the callback function \p BaseMatches to find base
1349 /// classes meeting some search criteria, walking all base class subobjects
1350 /// and populating the given \p Paths structure with the paths through the
1351 /// inheritance hierarchy that resulted in a match. On a successful search,
1352 /// the \p Paths structure can be queried to retrieve the matching paths and
1353 /// to determine if there were any ambiguities.
1355 /// \param BaseMatches callback function used to determine whether a given
1356 /// base matches the user-defined search criteria.
1358 /// \param UserData user data pointer that will be provided to \p BaseMatches.
1360 /// \param Paths used to record the paths from this class to its base class
1361 /// subobjects that match the search criteria.
1363 /// \returns true if there exists any path from this class to a base class
1364 /// subobject that matches the search criteria.
1365 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1366 CXXBasePaths &Paths) const;
1368 /// \brief Base-class lookup callback that determines whether the given
1369 /// base class specifier refers to a specific class declaration.
1371 /// This callback can be used with \c lookupInBases() to determine whether
1372 /// a given derived class has is a base class subobject of a particular type.
1373 /// The user data pointer should refer to the canonical CXXRecordDecl of the
1374 /// base class that we are searching for.
1375 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1376 CXXBasePath &Path, void *BaseRecord);
1378 /// \brief Base-class lookup callback that determines whether the
1379 /// given base class specifier refers to a specific class
1380 /// declaration and describes virtual derivation.
1382 /// This callback can be used with \c lookupInBases() to determine
1383 /// whether a given derived class has is a virtual base class
1384 /// subobject of a particular type. The user data pointer should
1385 /// refer to the canonical CXXRecordDecl of the base class that we
1386 /// are searching for.
1387 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1388 CXXBasePath &Path, void *BaseRecord);
1390 /// \brief Base-class lookup callback that determines whether there exists
1391 /// a tag with the given name.
1393 /// This callback can be used with \c lookupInBases() to find tag members
1394 /// of the given name within a C++ class hierarchy. The user data pointer
1395 /// is an opaque \c DeclarationName pointer.
1396 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1397 CXXBasePath &Path, void *Name);
1399 /// \brief Base-class lookup callback that determines whether there exists
1400 /// a member with the given name.
1402 /// This callback can be used with \c lookupInBases() to find members
1403 /// of the given name within a C++ class hierarchy. The user data pointer
1404 /// is an opaque \c DeclarationName pointer.
1405 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1406 CXXBasePath &Path, void *Name);
1408 /// \brief Base-class lookup callback that determines whether there exists
1409 /// a member with the given name that can be used in a nested-name-specifier.
1411 /// This callback can be used with \c lookupInBases() to find membes of
1412 /// the given name within a C++ class hierarchy that can occur within
1413 /// nested-name-specifiers.
1414 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1418 /// \brief Retrieve the final overriders for each virtual member
1419 /// function in the class hierarchy where this class is the
1420 /// most-derived class in the class hierarchy.
1421 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1423 /// \brief Get the indirect primary bases for this class.
1424 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1426 /// viewInheritance - Renders and displays an inheritance diagram
1427 /// for this C++ class and all of its base classes (transitively) using
1429 void viewInheritance(ASTContext& Context) const;
1431 /// MergeAccess - Calculates the access of a decl that is reached
1433 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1434 AccessSpecifier DeclAccess) {
1435 assert(DeclAccess != AS_none);
1436 if (DeclAccess == AS_private) return AS_none;
1437 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1440 /// \brief Indicates that the definition of this class is now complete.
1441 virtual void completeDefinition();
1443 /// \brief Indicates that the definition of this class is now complete,
1444 /// and provides a final overrider map to help determine
1446 /// \param FinalOverriders The final overrider map for this class, which can
1447 /// be provided as an optimization for abstract-class checking. If NULL,
1448 /// final overriders will be computed if they are needed to complete the
1450 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1452 /// \brief Determine whether this class may end up being abstract, even though
1453 /// it is not yet known to be abstract.
1455 /// \returns true if this class is not known to be abstract but has any
1456 /// base classes that are abstract. In this case, \c completeDefinition()
1457 /// will need to compute final overriders to determine whether the class is
1458 /// actually abstract.
1459 bool mayBeAbstract() const;
1461 /// \brief If this is the closure type of a lambda expression, retrieve the
1462 /// number to be used for name mangling in the Itanium C++ ABI.
1464 /// Zero indicates that this closure type has internal linkage, so the
1465 /// mangling number does not matter, while a non-zero value indicates which
1466 /// lambda expression this is in this particular context.
1467 unsigned getLambdaManglingNumber() const {
1468 assert(isLambda() && "Not a lambda closure type!");
1469 return getLambdaData().ManglingNumber;
1472 /// \brief Retrieve the declaration that provides additional context for a
1473 /// lambda, when the normal declaration context is not specific enough.
1475 /// Certain contexts (default arguments of in-class function parameters and
1476 /// the initializers of data members) have separate name mangling rules for
1477 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1478 /// the declaration in which the lambda occurs, e.g., the function parameter
1479 /// or the non-static data member. Otherwise, it returns NULL to imply that
1480 /// the declaration context suffices.
1481 Decl *getLambdaContextDecl() const {
1482 assert(isLambda() && "Not a lambda closure type!");
1483 return getLambdaData().ContextDecl;
1486 /// \brief Set the mangling number and context declaration for a lambda
1488 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1489 getLambdaData().ManglingNumber = ManglingNumber;
1490 getLambdaData().ContextDecl = ContextDecl;
1493 /// \brief Determine whether this lambda expression was known to be dependent
1494 /// at the time it was created, even if its context does not appear to be
1497 /// This flag is a workaround for an issue with parsing, where default
1498 /// arguments are parsed before their enclosing function declarations have
1499 /// been created. This means that any lambda expressions within those
1500 /// default arguments will have as their DeclContext the context enclosing
1501 /// the function declaration, which may be non-dependent even when the
1502 /// function declaration itself is dependent. This flag indicates when we
1503 /// know that the lambda is dependent despite that.
1504 bool isDependentLambda() const {
1505 return isLambda() && getLambdaData().Dependent;
1508 TypeSourceInfo *getLambdaTypeInfo() const {
1509 return getLambdaData().MethodTyInfo;
1512 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1513 static bool classofKind(Kind K) {
1514 return K >= firstCXXRecord && K <= lastCXXRecord;
1517 friend class ASTDeclReader;
1518 friend class ASTDeclWriter;
1519 friend class ASTReader;
1520 friend class ASTWriter;
1523 /// CXXMethodDecl - Represents a static or instance method of a
1524 /// struct/union/class.
1525 class CXXMethodDecl : public FunctionDecl {
1526 virtual void anchor();
1528 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1529 const DeclarationNameInfo &NameInfo,
1530 QualType T, TypeSourceInfo *TInfo,
1531 bool isStatic, StorageClass SCAsWritten, bool isInline,
1532 bool isConstexpr, SourceLocation EndLocation)
1533 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1534 (isStatic ? SC_Static : SC_None),
1535 SCAsWritten, isInline, isConstexpr) {
1536 if (EndLocation.isValid())
1537 setRangeEnd(EndLocation);
1541 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1542 SourceLocation StartLoc,
1543 const DeclarationNameInfo &NameInfo,
1544 QualType T, TypeSourceInfo *TInfo,
1546 StorageClass SCAsWritten,
1549 SourceLocation EndLocation);
1551 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1553 bool isStatic() const { return getStorageClass() == SC_Static; }
1554 bool isInstance() const { return !isStatic(); }
1556 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1557 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1559 bool isVirtual() const {
1561 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1563 // Methods declared in interfaces are automatically (pure) virtual.
1564 if (CD->isVirtualAsWritten() ||
1565 (CD->getParent()->isInterface() && CD->isUserProvided()))
1568 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1571 /// \brief Determine whether this is a usual deallocation function
1572 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1573 /// delete or delete[] operator with a particular signature.
1574 bool isUsualDeallocationFunction() const;
1576 /// \brief Determine whether this is a copy-assignment operator, regardless
1577 /// of whether it was declared implicitly or explicitly.
1578 bool isCopyAssignmentOperator() const;
1580 /// \brief Determine whether this is a move assignment operator.
1581 bool isMoveAssignmentOperator() const;
1583 const CXXMethodDecl *getCanonicalDecl() const {
1584 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1586 CXXMethodDecl *getCanonicalDecl() {
1587 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1590 /// isUserProvided - True if this method is user-declared and was not
1591 /// deleted or defaulted on its first declaration.
1592 bool isUserProvided() const {
1593 return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1597 void addOverriddenMethod(const CXXMethodDecl *MD);
1599 typedef const CXXMethodDecl *const* method_iterator;
1601 method_iterator begin_overridden_methods() const;
1602 method_iterator end_overridden_methods() const;
1603 unsigned size_overridden_methods() const;
1605 /// getParent - Returns the parent of this method declaration, which
1606 /// is the class in which this method is defined.
1607 const CXXRecordDecl *getParent() const {
1608 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1611 /// getParent - Returns the parent of this method declaration, which
1612 /// is the class in which this method is defined.
1613 CXXRecordDecl *getParent() {
1614 return const_cast<CXXRecordDecl *>(
1615 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1618 /// getThisType - Returns the type of 'this' pointer.
1619 /// Should only be called for instance methods.
1620 QualType getThisType(ASTContext &C) const;
1622 unsigned getTypeQualifiers() const {
1623 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1626 /// \brief Retrieve the ref-qualifier associated with this method.
1628 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1629 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1637 RefQualifierKind getRefQualifier() const {
1638 return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1641 bool hasInlineBody() const;
1643 /// \brief Determine whether this is a lambda closure type's static member
1644 /// function that is used for the result of the lambda's conversion to
1645 /// function pointer (for a lambda with no captures).
1647 /// The function itself, if used, will have a placeholder body that will be
1648 /// supplied by IR generation to either forward to the function call operator
1649 /// or clone the function call operator.
1650 bool isLambdaStaticInvoker() const;
1652 /// \brief Find the method in RD that corresponds to this one.
1654 /// Find if RD or one of the classes it inherits from override this method.
1655 /// If so, return it. RD is assumed to be a subclass of the class defining
1656 /// this method (or be the class itself), unless MayBeBase is set to true.
1658 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1659 bool MayBeBase = false);
1661 const CXXMethodDecl *
1662 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1663 bool MayBeBase = false) const {
1664 return const_cast<CXXMethodDecl *>(this)
1665 ->getCorrespondingMethodInClass(RD, MayBeBase);
1668 // Implement isa/cast/dyncast/etc.
1669 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1670 static bool classofKind(Kind K) {
1671 return K >= firstCXXMethod && K <= lastCXXMethod;
1675 /// CXXCtorInitializer - Represents a C++ base or member
1676 /// initializer, which is part of a constructor initializer that
1677 /// initializes one non-static member variable or one base class. For
1678 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1683 /// class B : public A {
1686 /// B(A& a) : A(a), f(3.14159) { }
1689 class CXXCtorInitializer {
1690 /// \brief Either the base class name/delegating constructor type (stored as
1691 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1692 /// (IndirectFieldDecl*) being initialized.
1693 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1696 /// \brief The source location for the field name or, for a base initializer
1697 /// pack expansion, the location of the ellipsis. In the case of a delegating
1698 /// constructor, it will still include the type's source location as the
1699 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1700 SourceLocation MemberOrEllipsisLocation;
1702 /// \brief The argument used to initialize the base or member, which may
1703 /// end up constructing an object (when multiple arguments are involved).
1704 /// If 0, this is a field initializer, and the in-class member initializer
1708 /// LParenLoc - Location of the left paren of the ctor-initializer.
1709 SourceLocation LParenLoc;
1711 /// RParenLoc - Location of the right paren of the ctor-initializer.
1712 SourceLocation RParenLoc;
1714 /// \brief If the initializee is a type, whether that type makes this
1715 /// a delegating initialization.
1716 bool IsDelegating : 1;
1718 /// IsVirtual - If the initializer is a base initializer, this keeps track
1719 /// of whether the base is virtual or not.
1722 /// IsWritten - Whether or not the initializer is explicitly written
1726 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1727 /// number keeps track of the textual order of this initializer in the
1728 /// original sources, counting from 0; otherwise, if IsWritten is false,
1729 /// it stores the number of array index variables stored after this
1730 /// object in memory.
1731 unsigned SourceOrderOrNumArrayIndices : 13;
1733 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1734 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1735 SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1738 /// CXXCtorInitializer - Creates a new base-class initializer.
1740 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1741 SourceLocation L, Expr *Init, SourceLocation R,
1742 SourceLocation EllipsisLoc);
1744 /// CXXCtorInitializer - Creates a new member initializer.
1746 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1747 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1750 /// CXXCtorInitializer - Creates a new anonymous field initializer.
1752 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1753 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1756 /// CXXCtorInitializer - Creates a new delegating Initializer.
1758 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1759 SourceLocation L, Expr *Init, SourceLocation R);
1761 /// \brief Creates a new member initializer that optionally contains
1762 /// array indices used to describe an elementwise initialization.
1763 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1764 SourceLocation MemberLoc, SourceLocation L,
1765 Expr *Init, SourceLocation R,
1766 VarDecl **Indices, unsigned NumIndices);
1768 /// isBaseInitializer - Returns true when this initializer is
1769 /// initializing a base class.
1770 bool isBaseInitializer() const {
1771 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1774 /// isMemberInitializer - Returns true when this initializer is
1775 /// initializing a non-static data member.
1776 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1778 bool isAnyMemberInitializer() const {
1779 return isMemberInitializer() || isIndirectMemberInitializer();
1782 bool isIndirectMemberInitializer() const {
1783 return Initializee.is<IndirectFieldDecl*>();
1786 /// isInClassMemberInitializer - Returns true when this initializer is an
1787 /// implicit ctor initializer generated for a field with an initializer
1788 /// defined on the member declaration.
1789 bool isInClassMemberInitializer() const {
1793 /// isDelegatingInitializer - Returns true when this initializer is creating
1794 /// a delegating constructor.
1795 bool isDelegatingInitializer() const {
1796 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1799 /// \brief Determine whether this initializer is a pack expansion.
1800 bool isPackExpansion() const {
1801 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1804 // \brief For a pack expansion, returns the location of the ellipsis.
1805 SourceLocation getEllipsisLoc() const {
1806 assert(isPackExpansion() && "Initializer is not a pack expansion");
1807 return MemberOrEllipsisLocation;
1810 /// If this is a base class initializer, returns the type of the
1811 /// base class with location information. Otherwise, returns an NULL
1813 TypeLoc getBaseClassLoc() const;
1815 /// If this is a base class initializer, returns the type of the base class.
1816 /// Otherwise, returns NULL.
1817 const Type *getBaseClass() const;
1819 /// Returns whether the base is virtual or not.
1820 bool isBaseVirtual() const {
1821 assert(isBaseInitializer() && "Must call this on base initializer!");
1826 /// \brief Returns the declarator information for a base class or delegating
1828 TypeSourceInfo *getTypeSourceInfo() const {
1829 return Initializee.dyn_cast<TypeSourceInfo *>();
1832 /// getMember - If this is a member initializer, returns the
1833 /// declaration of the non-static data member being
1834 /// initialized. Otherwise, returns NULL.
1835 FieldDecl *getMember() const {
1836 if (isMemberInitializer())
1837 return Initializee.get<FieldDecl*>();
1840 FieldDecl *getAnyMember() const {
1841 if (isMemberInitializer())
1842 return Initializee.get<FieldDecl*>();
1843 if (isIndirectMemberInitializer())
1844 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1848 IndirectFieldDecl *getIndirectMember() const {
1849 if (isIndirectMemberInitializer())
1850 return Initializee.get<IndirectFieldDecl*>();
1854 SourceLocation getMemberLocation() const {
1855 return MemberOrEllipsisLocation;
1858 /// \brief Determine the source location of the initializer.
1859 SourceLocation getSourceLocation() const;
1861 /// \brief Determine the source range covering the entire initializer.
1862 SourceRange getSourceRange() const LLVM_READONLY;
1864 /// isWritten - Returns true if this initializer is explicitly written
1865 /// in the source code.
1866 bool isWritten() const { return IsWritten; }
1868 /// \brief Return the source position of the initializer, counting from 0.
1869 /// If the initializer was implicit, -1 is returned.
1870 int getSourceOrder() const {
1871 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1874 /// \brief Set the source order of this initializer. This method can only
1875 /// be called once for each initializer; it cannot be called on an
1876 /// initializer having a positive number of (implicit) array indices.
1877 void setSourceOrder(int pos) {
1878 assert(!IsWritten &&
1879 "calling twice setSourceOrder() on the same initializer");
1880 assert(SourceOrderOrNumArrayIndices == 0 &&
1881 "setSourceOrder() used when there are implicit array indices");
1883 "setSourceOrder() used to make an initializer implicit");
1885 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1888 SourceLocation getLParenLoc() const { return LParenLoc; }
1889 SourceLocation getRParenLoc() const { return RParenLoc; }
1891 /// \brief Determine the number of implicit array indices used while
1892 /// described an array member initialization.
1893 unsigned getNumArrayIndices() const {
1894 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1897 /// \brief Retrieve a particular array index variable used to
1898 /// describe an array member initialization.
1899 VarDecl *getArrayIndex(unsigned I) {
1900 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1901 return reinterpret_cast<VarDecl **>(this + 1)[I];
1903 const VarDecl *getArrayIndex(unsigned I) const {
1904 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1905 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1907 void setArrayIndex(unsigned I, VarDecl *Index) {
1908 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1909 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1911 ArrayRef<VarDecl *> getArrayIndexes() {
1912 assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
1913 return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
1914 getNumArrayIndices());
1917 /// \brief Get the initializer. This is 0 if this is an in-class initializer
1918 /// for a non-static data member which has not yet been parsed.
1919 Expr *getInit() const {
1921 return getAnyMember()->getInClassInitializer();
1923 return static_cast<Expr*>(Init);
1927 /// CXXConstructorDecl - Represents a C++ constructor within a
1928 /// class. For example:
1933 /// explicit X(int); // represented by a CXXConstructorDecl.
1936 class CXXConstructorDecl : public CXXMethodDecl {
1937 virtual void anchor();
1938 /// IsExplicitSpecified - Whether this constructor declaration has the
1939 /// 'explicit' keyword specified.
1940 bool IsExplicitSpecified : 1;
1942 /// ImplicitlyDefined - Whether this constructor was implicitly
1943 /// defined by the compiler. When false, the constructor was defined
1944 /// by the user. In C++03, this flag will have the same value as
1945 /// Implicit. In C++0x, however, a constructor that is
1946 /// explicitly defaulted (i.e., defined with " = default") will have
1947 /// @c !Implicit && ImplicitlyDefined.
1948 bool ImplicitlyDefined : 1;
1950 /// Support for base and member initializers.
1951 /// CtorInitializers - The arguments used to initialize the base
1953 CXXCtorInitializer **CtorInitializers;
1954 unsigned NumCtorInitializers;
1956 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1957 const DeclarationNameInfo &NameInfo,
1958 QualType T, TypeSourceInfo *TInfo,
1959 bool isExplicitSpecified, bool isInline,
1960 bool isImplicitlyDeclared, bool isConstexpr)
1961 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
1962 SC_None, isInline, isConstexpr, SourceLocation()),
1963 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1964 CtorInitializers(0), NumCtorInitializers(0) {
1965 setImplicit(isImplicitlyDeclared);
1969 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1970 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1971 SourceLocation StartLoc,
1972 const DeclarationNameInfo &NameInfo,
1973 QualType T, TypeSourceInfo *TInfo,
1975 bool isInline, bool isImplicitlyDeclared,
1978 /// isExplicitSpecified - Whether this constructor declaration has the
1979 /// 'explicit' keyword specified.
1980 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1982 /// isExplicit - Whether this constructor was marked "explicit" or not.
1983 bool isExplicit() const {
1984 return cast<CXXConstructorDecl>(getFirstDeclaration())
1985 ->isExplicitSpecified();
1988 /// isImplicitlyDefined - Whether this constructor was implicitly
1989 /// defined. If false, then this constructor was defined by the
1990 /// user. This operation can only be invoked if the constructor has
1991 /// already been defined.
1992 bool isImplicitlyDefined() const {
1993 assert(isThisDeclarationADefinition() &&
1994 "Can only get the implicit-definition flag once the "
1995 "constructor has been defined");
1996 return ImplicitlyDefined;
1999 /// setImplicitlyDefined - Set whether this constructor was
2000 /// implicitly defined or not.
2001 void setImplicitlyDefined(bool ID) {
2002 assert(isThisDeclarationADefinition() &&
2003 "Can only set the implicit-definition flag once the constructor "
2004 "has been defined");
2005 ImplicitlyDefined = ID;
2008 /// init_iterator - Iterates through the member/base initializer list.
2009 typedef CXXCtorInitializer **init_iterator;
2011 /// init_const_iterator - Iterates through the memberbase initializer list.
2012 typedef CXXCtorInitializer * const * init_const_iterator;
2014 /// init_begin() - Retrieve an iterator to the first initializer.
2015 init_iterator init_begin() { return CtorInitializers; }
2016 /// begin() - Retrieve an iterator to the first initializer.
2017 init_const_iterator init_begin() const { return CtorInitializers; }
2019 /// init_end() - Retrieve an iterator past the last initializer.
2020 init_iterator init_end() {
2021 return CtorInitializers + NumCtorInitializers;
2023 /// end() - Retrieve an iterator past the last initializer.
2024 init_const_iterator init_end() const {
2025 return CtorInitializers + NumCtorInitializers;
2028 typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2029 typedef std::reverse_iterator<init_const_iterator>
2030 init_const_reverse_iterator;
2032 init_reverse_iterator init_rbegin() {
2033 return init_reverse_iterator(init_end());
2035 init_const_reverse_iterator init_rbegin() const {
2036 return init_const_reverse_iterator(init_end());
2039 init_reverse_iterator init_rend() {
2040 return init_reverse_iterator(init_begin());
2042 init_const_reverse_iterator init_rend() const {
2043 return init_const_reverse_iterator(init_begin());
2046 /// getNumArgs - Determine the number of arguments used to
2047 /// initialize the member or base.
2048 unsigned getNumCtorInitializers() const {
2049 return NumCtorInitializers;
2052 void setNumCtorInitializers(unsigned numCtorInitializers) {
2053 NumCtorInitializers = numCtorInitializers;
2056 void setCtorInitializers(CXXCtorInitializer ** initializers) {
2057 CtorInitializers = initializers;
2060 /// isDelegatingConstructor - Whether this constructor is a
2061 /// delegating constructor
2062 bool isDelegatingConstructor() const {
2063 return (getNumCtorInitializers() == 1) &&
2064 CtorInitializers[0]->isDelegatingInitializer();
2067 /// getTargetConstructor - When this constructor delegates to
2068 /// another, retrieve the target
2069 CXXConstructorDecl *getTargetConstructor() const;
2071 /// isDefaultConstructor - Whether this constructor is a default
2072 /// constructor (C++ [class.ctor]p5), which can be used to
2073 /// default-initialize a class of this type.
2074 bool isDefaultConstructor() const;
2076 /// isCopyConstructor - Whether this constructor is a copy
2077 /// constructor (C++ [class.copy]p2, which can be used to copy the
2078 /// class. @p TypeQuals will be set to the qualifiers on the
2079 /// argument type. For example, @p TypeQuals would be set to @c
2080 /// QualType::Const for the following copy constructor:
2088 bool isCopyConstructor(unsigned &TypeQuals) const;
2090 /// isCopyConstructor - Whether this constructor is a copy
2091 /// constructor (C++ [class.copy]p2, which can be used to copy the
2093 bool isCopyConstructor() const {
2094 unsigned TypeQuals = 0;
2095 return isCopyConstructor(TypeQuals);
2098 /// \brief Determine whether this constructor is a move constructor
2099 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2101 /// \param TypeQuals If this constructor is a move constructor, will be set
2102 /// to the type qualifiers on the referent of the first parameter's type.
2103 bool isMoveConstructor(unsigned &TypeQuals) const;
2105 /// \brief Determine whether this constructor is a move constructor
2106 /// (C++0x [class.copy]p3), which can be used to move values of the class.
2107 bool isMoveConstructor() const {
2108 unsigned TypeQuals = 0;
2109 return isMoveConstructor(TypeQuals);
2112 /// \brief Determine whether this is a copy or move constructor.
2114 /// \param TypeQuals Will be set to the type qualifiers on the reference
2115 /// parameter, if in fact this is a copy or move constructor.
2116 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2118 /// \brief Determine whether this a copy or move constructor.
2119 bool isCopyOrMoveConstructor() const {
2121 return isCopyOrMoveConstructor(Quals);
2124 /// isConvertingConstructor - Whether this constructor is a
2125 /// converting constructor (C++ [class.conv.ctor]), which can be
2126 /// used for user-defined conversions.
2127 bool isConvertingConstructor(bool AllowExplicit) const;
2129 /// \brief Determine whether this is a member template specialization that
2130 /// would copy the object to itself. Such constructors are never used to copy
2132 bool isSpecializationCopyingObject() const;
2134 /// \brief Get the constructor that this inheriting constructor is based on.
2135 const CXXConstructorDecl *getInheritedConstructor() const;
2137 /// \brief Set the constructor that this inheriting constructor is based on.
2138 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2140 const CXXConstructorDecl *getCanonicalDecl() const {
2141 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2143 CXXConstructorDecl *getCanonicalDecl() {
2144 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2147 // Implement isa/cast/dyncast/etc.
2148 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2149 static bool classofKind(Kind K) { return K == CXXConstructor; }
2151 friend class ASTDeclReader;
2152 friend class ASTDeclWriter;
2155 /// CXXDestructorDecl - Represents a C++ destructor within a
2156 /// class. For example:
2161 /// ~X(); // represented by a CXXDestructorDecl.
2164 class CXXDestructorDecl : public CXXMethodDecl {
2165 virtual void anchor();
2166 /// ImplicitlyDefined - Whether this destructor was implicitly
2167 /// defined by the compiler. When false, the destructor was defined
2168 /// by the user. In C++03, this flag will have the same value as
2169 /// Implicit. In C++0x, however, a destructor that is
2170 /// explicitly defaulted (i.e., defined with " = default") will have
2171 /// @c !Implicit && ImplicitlyDefined.
2172 bool ImplicitlyDefined : 1;
2174 FunctionDecl *OperatorDelete;
2176 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2177 const DeclarationNameInfo &NameInfo,
2178 QualType T, TypeSourceInfo *TInfo,
2179 bool isInline, bool isImplicitlyDeclared)
2180 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
2181 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2182 ImplicitlyDefined(false), OperatorDelete(0) {
2183 setImplicit(isImplicitlyDeclared);
2187 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2188 SourceLocation StartLoc,
2189 const DeclarationNameInfo &NameInfo,
2190 QualType T, TypeSourceInfo* TInfo,
2192 bool isImplicitlyDeclared);
2193 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2195 /// isImplicitlyDefined - Whether this destructor was implicitly
2196 /// defined. If false, then this destructor was defined by the
2197 /// user. This operation can only be invoked if the destructor has
2198 /// already been defined.
2199 bool isImplicitlyDefined() const {
2200 assert(isThisDeclarationADefinition() &&
2201 "Can only get the implicit-definition flag once the destructor has "
2203 return ImplicitlyDefined;
2206 /// setImplicitlyDefined - Set whether this destructor was
2207 /// implicitly defined or not.
2208 void setImplicitlyDefined(bool ID) {
2209 assert(isThisDeclarationADefinition() &&
2210 "Can only set the implicit-definition flag once the destructor has "
2212 ImplicitlyDefined = ID;
2215 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2216 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2218 // Implement isa/cast/dyncast/etc.
2219 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2220 static bool classofKind(Kind K) { return K == CXXDestructor; }
2222 friend class ASTDeclReader;
2223 friend class ASTDeclWriter;
2226 /// CXXConversionDecl - Represents a C++ conversion function within a
2227 /// class. For example:
2232 /// operator bool();
2235 class CXXConversionDecl : public CXXMethodDecl {
2236 virtual void anchor();
2237 /// IsExplicitSpecified - Whether this conversion function declaration is
2238 /// marked "explicit", meaning that it can only be applied when the user
2239 /// explicitly wrote a cast. This is a C++0x feature.
2240 bool IsExplicitSpecified : 1;
2242 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2243 const DeclarationNameInfo &NameInfo,
2244 QualType T, TypeSourceInfo *TInfo,
2245 bool isInline, bool isExplicitSpecified,
2246 bool isConstexpr, SourceLocation EndLocation)
2247 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
2248 SC_None, isInline, isConstexpr, EndLocation),
2249 IsExplicitSpecified(isExplicitSpecified) { }
2252 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2253 SourceLocation StartLoc,
2254 const DeclarationNameInfo &NameInfo,
2255 QualType T, TypeSourceInfo *TInfo,
2256 bool isInline, bool isExplicit,
2258 SourceLocation EndLocation);
2259 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2261 /// IsExplicitSpecified - Whether this conversion function declaration is
2262 /// marked "explicit", meaning that it can only be applied when the user
2263 /// explicitly wrote a cast. This is a C++0x feature.
2264 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2266 /// isExplicit - Whether this is an explicit conversion operator
2267 /// (C++0x only). Explicit conversion operators are only considered
2268 /// when the user has explicitly written a cast.
2269 bool isExplicit() const {
2270 return cast<CXXConversionDecl>(getFirstDeclaration())
2271 ->isExplicitSpecified();
2274 /// getConversionType - Returns the type that this conversion
2275 /// function is converting to.
2276 QualType getConversionType() const {
2277 return getType()->getAs<FunctionType>()->getResultType();
2280 /// \brief Determine whether this conversion function is a conversion from
2281 /// a lambda closure type to a block pointer.
2282 bool isLambdaToBlockPointerConversion() const;
2284 // Implement isa/cast/dyncast/etc.
2285 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2286 static bool classofKind(Kind K) { return K == CXXConversion; }
2288 friend class ASTDeclReader;
2289 friend class ASTDeclWriter;
2292 /// LinkageSpecDecl - This represents a linkage specification. For example:
2293 /// extern "C" void foo();
2295 class LinkageSpecDecl : public Decl, public DeclContext {
2296 virtual void anchor();
2298 /// LanguageIDs - Used to represent the language in a linkage
2299 /// specification. The values are part of the serialization abi for
2300 /// ASTs and cannot be changed without altering that abi. To help
2301 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
2302 /// from the dwarf standard.
2304 lang_c = /* DW_LANG_C */ 0x0002,
2305 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2308 /// Language - The language for this linkage specification.
2309 LanguageIDs Language;
2310 /// ExternLoc - The source location for the extern keyword.
2311 SourceLocation ExternLoc;
2312 /// RBraceLoc - The source location for the right brace (if valid).
2313 SourceLocation RBraceLoc;
2315 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2316 SourceLocation LangLoc, LanguageIDs lang,
2317 SourceLocation RBLoc)
2318 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2319 Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
2322 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2323 SourceLocation ExternLoc,
2324 SourceLocation LangLoc, LanguageIDs Lang,
2325 SourceLocation RBraceLoc = SourceLocation());
2326 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2328 /// \brief Return the language specified by this linkage specification.
2329 LanguageIDs getLanguage() const { return Language; }
2330 /// \brief Set the language specified by this linkage specification.
2331 void setLanguage(LanguageIDs L) { Language = L; }
2333 /// \brief Determines whether this linkage specification had braces in
2334 /// its syntactic form.
2335 bool hasBraces() const { return RBraceLoc.isValid(); }
2337 SourceLocation getExternLoc() const { return ExternLoc; }
2338 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2339 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2340 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2342 SourceLocation getLocEnd() const LLVM_READONLY {
2344 return getRBraceLoc();
2345 // No braces: get the end location of the (only) declaration in context
2347 return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2350 SourceRange getSourceRange() const LLVM_READONLY {
2351 return SourceRange(ExternLoc, getLocEnd());
2354 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2355 static bool classofKind(Kind K) { return K == LinkageSpec; }
2356 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2357 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2359 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2360 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2364 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
2366 /// using namespace std;
2368 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2369 // artificial names for all using-directives in order to store
2370 // them in DeclContext effectively.
2371 class UsingDirectiveDecl : public NamedDecl {
2372 virtual void anchor();
2373 /// \brief The location of the "using" keyword.
2374 SourceLocation UsingLoc;
2376 /// SourceLocation - Location of 'namespace' token.
2377 SourceLocation NamespaceLoc;
2379 /// \brief The nested-name-specifier that precedes the namespace.
2380 NestedNameSpecifierLoc QualifierLoc;
2382 /// NominatedNamespace - Namespace nominated by using-directive.
2383 NamedDecl *NominatedNamespace;
2385 /// Enclosing context containing both using-directive and nominated
2387 DeclContext *CommonAncestor;
2389 /// getUsingDirectiveName - Returns special DeclarationName used by
2390 /// using-directives. This is only used by DeclContext for storing
2391 /// UsingDirectiveDecls in its lookup structure.
2392 static DeclarationName getName() {
2393 return DeclarationName::getUsingDirectiveName();
2396 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2397 SourceLocation NamespcLoc,
2398 NestedNameSpecifierLoc QualifierLoc,
2399 SourceLocation IdentLoc,
2400 NamedDecl *Nominated,
2401 DeclContext *CommonAncestor)
2402 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2403 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2404 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2407 /// \brief Retrieve the nested-name-specifier that qualifies the
2408 /// name of the namespace, with source-location information.
2409 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2411 /// \brief Retrieve the nested-name-specifier that qualifies the
2412 /// name of the namespace.
2413 NestedNameSpecifier *getQualifier() const {
2414 return QualifierLoc.getNestedNameSpecifier();
2417 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2418 const NamedDecl *getNominatedNamespaceAsWritten() const {
2419 return NominatedNamespace;
2422 /// getNominatedNamespace - Returns namespace nominated by using-directive.
2423 NamespaceDecl *getNominatedNamespace();
2425 const NamespaceDecl *getNominatedNamespace() const {
2426 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2429 /// \brief Returns the common ancestor context of this using-directive and
2430 /// its nominated namespace.
2431 DeclContext *getCommonAncestor() { return CommonAncestor; }
2432 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2434 /// \brief Return the location of the "using" keyword.
2435 SourceLocation getUsingLoc() const { return UsingLoc; }
2437 // FIXME: Could omit 'Key' in name.
2438 /// getNamespaceKeyLocation - Returns location of namespace keyword.
2439 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2441 /// getIdentLocation - Returns location of identifier.
2442 SourceLocation getIdentLocation() const { return getLocation(); }
2444 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2445 SourceLocation UsingLoc,
2446 SourceLocation NamespaceLoc,
2447 NestedNameSpecifierLoc QualifierLoc,
2448 SourceLocation IdentLoc,
2449 NamedDecl *Nominated,
2450 DeclContext *CommonAncestor);
2451 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2453 SourceRange getSourceRange() const LLVM_READONLY {
2454 return SourceRange(UsingLoc, getLocation());
2457 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2458 static bool classofKind(Kind K) { return K == UsingDirective; }
2460 // Friend for getUsingDirectiveName.
2461 friend class DeclContext;
2463 friend class ASTDeclReader;
2466 /// \brief Represents a C++ namespace alias.
2471 /// namespace Foo = Bar;
2473 class NamespaceAliasDecl : public NamedDecl {
2474 virtual void anchor();
2476 /// \brief The location of the "namespace" keyword.
2477 SourceLocation NamespaceLoc;
2479 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2480 SourceLocation IdentLoc;
2482 /// \brief The nested-name-specifier that precedes the namespace.
2483 NestedNameSpecifierLoc QualifierLoc;
2485 /// Namespace - The Decl that this alias points to. Can either be a
2486 /// NamespaceDecl or a NamespaceAliasDecl.
2487 NamedDecl *Namespace;
2489 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2490 SourceLocation AliasLoc, IdentifierInfo *Alias,
2491 NestedNameSpecifierLoc QualifierLoc,
2492 SourceLocation IdentLoc, NamedDecl *Namespace)
2493 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2494 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2495 QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2497 friend class ASTDeclReader;
2500 /// \brief Retrieve the nested-name-specifier that qualifies the
2501 /// name of the namespace, with source-location information.
2502 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2504 /// \brief Retrieve the nested-name-specifier that qualifies the
2505 /// name of the namespace.
2506 NestedNameSpecifier *getQualifier() const {
2507 return QualifierLoc.getNestedNameSpecifier();
2510 /// \brief Retrieve the namespace declaration aliased by this directive.
2511 NamespaceDecl *getNamespace() {
2512 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2513 return AD->getNamespace();
2515 return cast<NamespaceDecl>(Namespace);
2518 const NamespaceDecl *getNamespace() const {
2519 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2522 /// Returns the location of the alias name, i.e. 'foo' in
2523 /// "namespace foo = ns::bar;".
2524 SourceLocation getAliasLoc() const { return getLocation(); }
2526 /// Returns the location of the 'namespace' keyword.
2527 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2529 /// Returns the location of the identifier in the named namespace.
2530 SourceLocation getTargetNameLoc() const { return IdentLoc; }
2532 /// \brief Retrieve the namespace that this alias refers to, which
2533 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2534 NamedDecl *getAliasedNamespace() const { return Namespace; }
2536 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2537 SourceLocation NamespaceLoc,
2538 SourceLocation AliasLoc,
2539 IdentifierInfo *Alias,
2540 NestedNameSpecifierLoc QualifierLoc,
2541 SourceLocation IdentLoc,
2542 NamedDecl *Namespace);
2544 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2546 virtual SourceRange getSourceRange() const LLVM_READONLY {
2547 return SourceRange(NamespaceLoc, IdentLoc);
2550 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2551 static bool classofKind(Kind K) { return K == NamespaceAlias; }
2554 /// \brief Represents a shadow declaration introduced into a scope by a
2555 /// (resolved) using declaration.
2563 /// using A::foo; // <- a UsingDecl
2564 /// // Also creates a UsingShadowDecl for A::foo() in B
2567 class UsingShadowDecl : public NamedDecl {
2568 virtual void anchor();
2570 /// The referenced declaration.
2571 NamedDecl *Underlying;
2573 /// \brief The using declaration which introduced this decl or the next using
2574 /// shadow declaration contained in the aforementioned using declaration.
2575 NamedDecl *UsingOrNextShadow;
2576 friend class UsingDecl;
2578 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2580 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2582 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2584 setDeclName(Target->getDeclName());
2585 IdentifierNamespace = Target->getIdentifierNamespace();
2591 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2592 SourceLocation Loc, UsingDecl *Using,
2593 NamedDecl *Target) {
2594 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2597 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2599 /// \brief Gets the underlying declaration which has been brought into the
2601 NamedDecl *getTargetDecl() const { return Underlying; }
2603 /// \brief Sets the underlying declaration which has been brought into the
2605 void setTargetDecl(NamedDecl* ND) {
2606 assert(ND && "Target decl is null!");
2608 IdentifierNamespace = ND->getIdentifierNamespace();
2611 /// \brief Gets the using declaration to which this declaration is tied.
2612 UsingDecl *getUsingDecl() const;
2614 /// \brief The next using shadow declaration contained in the shadow decl
2615 /// chain of the using declaration which introduced this decl.
2616 UsingShadowDecl *getNextUsingShadowDecl() const {
2617 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2620 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2621 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2623 friend class ASTDeclReader;
2624 friend class ASTDeclWriter;
2627 /// \brief Represents a C++ using-declaration.
2631 /// using someNameSpace::someIdentifier;
2633 class UsingDecl : public NamedDecl {
2634 virtual void anchor();
2636 /// \brief The source location of the "using" location itself.
2637 SourceLocation UsingLocation;
2639 /// \brief The nested-name-specifier that precedes the name.
2640 NestedNameSpecifierLoc QualifierLoc;
2642 /// DNLoc - Provides source/type location info for the
2643 /// declaration name embedded in the ValueDecl base class.
2644 DeclarationNameLoc DNLoc;
2646 /// \brief The first shadow declaration of the shadow decl chain associated
2647 /// with this using declaration.
2649 /// The bool member of the pair store whether this decl has the \c typename
2651 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2653 UsingDecl(DeclContext *DC, SourceLocation UL,
2654 NestedNameSpecifierLoc QualifierLoc,
2655 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2656 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2657 UsingLocation(UL), QualifierLoc(QualifierLoc),
2658 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) {
2662 /// \brief Returns the source location of the "using" keyword.
2663 SourceLocation getUsingLocation() const { return UsingLocation; }
2665 /// \brief Set the source location of the 'using' keyword.
2666 void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2668 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2669 /// with source-location information.
2670 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2672 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2673 NestedNameSpecifier *getQualifier() const {
2674 return QualifierLoc.getNestedNameSpecifier();
2677 DeclarationNameInfo getNameInfo() const {
2678 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2681 /// \brief Return true if the using declaration has 'typename'.
2682 bool isTypeName() const { return FirstUsingShadow.getInt(); }
2684 /// \brief Sets whether the using declaration has 'typename'.
2685 void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); }
2687 /// \brief Iterates through the using shadow declarations assosiated with
2688 /// this using declaration.
2689 class shadow_iterator {
2690 /// \brief The current using shadow declaration.
2691 UsingShadowDecl *Current;
2694 typedef UsingShadowDecl* value_type;
2695 typedef UsingShadowDecl* reference;
2696 typedef UsingShadowDecl* pointer;
2697 typedef std::forward_iterator_tag iterator_category;
2698 typedef std::ptrdiff_t difference_type;
2700 shadow_iterator() : Current(0) { }
2701 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2703 reference operator*() const { return Current; }
2704 pointer operator->() const { return Current; }
2706 shadow_iterator& operator++() {
2707 Current = Current->getNextUsingShadowDecl();
2711 shadow_iterator operator++(int) {
2712 shadow_iterator tmp(*this);
2717 friend bool operator==(shadow_iterator x, shadow_iterator y) {
2718 return x.Current == y.Current;
2720 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2721 return x.Current != y.Current;
2725 shadow_iterator shadow_begin() const {
2726 return shadow_iterator(FirstUsingShadow.getPointer());
2728 shadow_iterator shadow_end() const { return shadow_iterator(); }
2730 /// \brief Return the number of shadowed declarations associated with this
2731 /// using declaration.
2732 unsigned shadow_size() const {
2733 return std::distance(shadow_begin(), shadow_end());
2736 void addShadowDecl(UsingShadowDecl *S);
2737 void removeShadowDecl(UsingShadowDecl *S);
2739 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2740 SourceLocation UsingL,
2741 NestedNameSpecifierLoc QualifierLoc,
2742 const DeclarationNameInfo &NameInfo,
2743 bool IsTypeNameArg);
2745 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2747 SourceRange getSourceRange() const LLVM_READONLY {
2748 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2751 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2752 static bool classofKind(Kind K) { return K == Using; }
2754 friend class ASTDeclReader;
2755 friend class ASTDeclWriter;
2758 /// \brief Represents a dependent using declaration which was not marked with
2761 /// Unlike non-dependent using declarations, these *only* bring through
2762 /// non-types; otherwise they would break two-phase lookup.
2765 /// template \<class T> class A : public Base<T> {
2766 /// using Base<T>::foo;
2769 class UnresolvedUsingValueDecl : public ValueDecl {
2770 virtual void anchor();
2772 /// \brief The source location of the 'using' keyword
2773 SourceLocation UsingLocation;
2775 /// \brief The nested-name-specifier that precedes the name.
2776 NestedNameSpecifierLoc QualifierLoc;
2778 /// DNLoc - Provides source/type location info for the
2779 /// declaration name embedded in the ValueDecl base class.
2780 DeclarationNameLoc DNLoc;
2782 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2783 SourceLocation UsingLoc,
2784 NestedNameSpecifierLoc QualifierLoc,
2785 const DeclarationNameInfo &NameInfo)
2786 : ValueDecl(UnresolvedUsingValue, DC,
2787 NameInfo.getLoc(), NameInfo.getName(), Ty),
2788 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2789 DNLoc(NameInfo.getInfo())
2793 /// \brief Returns the source location of the 'using' keyword.
2794 SourceLocation getUsingLoc() const { return UsingLocation; }
2796 /// \brief Set the source location of the 'using' keyword.
2797 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2799 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2800 /// with source-location information.
2801 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2803 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2804 NestedNameSpecifier *getQualifier() const {
2805 return QualifierLoc.getNestedNameSpecifier();
2808 DeclarationNameInfo getNameInfo() const {
2809 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2812 static UnresolvedUsingValueDecl *
2813 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2814 NestedNameSpecifierLoc QualifierLoc,
2815 const DeclarationNameInfo &NameInfo);
2817 static UnresolvedUsingValueDecl *
2818 CreateDeserialized(ASTContext &C, unsigned ID);
2820 SourceRange getSourceRange() const LLVM_READONLY {
2821 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2824 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2825 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2827 friend class ASTDeclReader;
2828 friend class ASTDeclWriter;
2831 /// @brief Represents a dependent using declaration which was marked with
2835 /// template \<class T> class A : public Base<T> {
2836 /// using typename Base<T>::foo;
2840 /// The type associated with an unresolved using typename decl is
2841 /// currently always a typename type.
2842 class UnresolvedUsingTypenameDecl : public TypeDecl {
2843 virtual void anchor();
2845 /// \brief The source location of the 'using' keyword
2846 SourceLocation UsingLocation;
2848 /// \brief The source location of the 'typename' keyword
2849 SourceLocation TypenameLocation;
2851 /// \brief The nested-name-specifier that precedes the name.
2852 NestedNameSpecifierLoc QualifierLoc;
2854 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2855 SourceLocation TypenameLoc,
2856 NestedNameSpecifierLoc QualifierLoc,
2857 SourceLocation TargetNameLoc,
2858 IdentifierInfo *TargetName)
2859 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2861 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2863 friend class ASTDeclReader;
2866 /// \brief Returns the source location of the 'using' keyword.
2867 SourceLocation getUsingLoc() const { return getLocStart(); }
2869 /// \brief Returns the source location of the 'typename' keyword.
2870 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2872 /// \brief Retrieve the nested-name-specifier that qualifies the name,
2873 /// with source-location information.
2874 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2876 /// \brief Retrieve the nested-name-specifier that qualifies the name.
2877 NestedNameSpecifier *getQualifier() const {
2878 return QualifierLoc.getNestedNameSpecifier();
2881 static UnresolvedUsingTypenameDecl *
2882 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2883 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2884 SourceLocation TargetNameLoc, DeclarationName TargetName);
2886 static UnresolvedUsingTypenameDecl *
2887 CreateDeserialized(ASTContext &C, unsigned ID);
2889 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2890 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2893 /// \brief Represents a C++11 static_assert declaration.
2894 class StaticAssertDecl : public Decl {
2895 virtual void anchor();
2896 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
2897 StringLiteral *Message;
2898 SourceLocation RParenLoc;
2900 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2901 Expr *AssertExpr, StringLiteral *Message,
2902 SourceLocation RParenLoc, bool Failed)
2903 : Decl(StaticAssert, DC, StaticAssertLoc),
2904 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
2905 RParenLoc(RParenLoc) { }
2908 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2909 SourceLocation StaticAssertLoc,
2910 Expr *AssertExpr, StringLiteral *Message,
2911 SourceLocation RParenLoc, bool Failed);
2912 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2914 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
2915 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
2917 StringLiteral *getMessage() { return Message; }
2918 const StringLiteral *getMessage() const { return Message; }
2920 bool isFailed() const { return AssertExprAndFailed.getInt(); }
2922 SourceLocation getRParenLoc() const { return RParenLoc; }
2924 SourceRange getSourceRange() const LLVM_READONLY {
2925 return SourceRange(getLocation(), getRParenLoc());
2928 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2929 static bool classofKind(Kind K) { return K == StaticAssert; }
2931 friend class ASTDeclReader;
2934 /// Insertion operator for diagnostics. This allows sending an AccessSpecifier
2935 /// into a diagnostic with <<.
2936 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2937 AccessSpecifier AS);
2939 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
2940 AccessSpecifier AS);
2942 } // end namespace clang