• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Defines the C++ Decl subclasses, other than those for templates
12 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_AST_DECLCXX_H
17 #define LLVM_CLANG_AST_DECLCXX_H
18 
19 #include "clang/AST/ASTUnresolvedSet.h"
20 #include "clang/AST/Attr.h"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/LambdaCapture.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/PointerIntPair.h"
26 #include "llvm/Support/Compiler.h"
27 
28 namespace clang {
29 
30 class ClassTemplateDecl;
31 class ClassTemplateSpecializationDecl;
32 class CXXBasePath;
33 class CXXBasePaths;
34 class CXXConstructorDecl;
35 class CXXConversionDecl;
36 class CXXDestructorDecl;
37 class CXXMethodDecl;
38 class CXXRecordDecl;
39 class CXXMemberLookupCriteria;
40 class CXXFinalOverriderMap;
41 class CXXIndirectPrimaryBaseSet;
42 class FriendDecl;
43 class LambdaExpr;
44 class UsingDecl;
45 
46 /// \brief Represents any kind of function declaration, whether it is a
47 /// concrete function or a function template.
48 class AnyFunctionDecl {
49   NamedDecl *Function;
50 
AnyFunctionDecl(NamedDecl * ND)51   AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
52 
53 public:
AnyFunctionDecl(FunctionDecl * FD)54   AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
55   AnyFunctionDecl(FunctionTemplateDecl *FTD);
56 
57   /// \brief Implicily converts any function or function template into a
58   /// named declaration.
59   operator NamedDecl *() const { return Function; }
60 
61   /// \brief Retrieve the underlying function or function template.
get()62   NamedDecl *get() const { return Function; }
63 
getFromNamedDecl(NamedDecl * ND)64   static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
65     return AnyFunctionDecl(ND);
66   }
67 };
68 
69 } // end namespace clang
70 
71 namespace llvm {
72   // Provide PointerLikeTypeTraits for non-cvr pointers.
73   template<>
74   class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
75   public:
getAsVoidPointer(::clang::AnyFunctionDecl F)76     static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
77       return F.get();
78     }
getFromVoidPointer(void * P)79     static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
80       return ::clang::AnyFunctionDecl::getFromNamedDecl(
81                                       static_cast< ::clang::NamedDecl*>(P));
82     }
83 
84     enum { NumLowBitsAvailable = 2 };
85   };
86 
87 } // end namespace llvm
88 
89 namespace clang {
90 
91 /// \brief Represents an access specifier followed by colon ':'.
92 ///
93 /// An objects of this class represents sugar for the syntactic occurrence
94 /// of an access specifier followed by a colon in the list of member
95 /// specifiers of a C++ class definition.
96 ///
97 /// Note that they do not represent other uses of access specifiers,
98 /// such as those occurring in a list of base specifiers.
99 /// Also note that this class has nothing to do with so-called
100 /// "access declarations" (C++98 11.3 [class.access.dcl]).
101 class AccessSpecDecl : public Decl {
102   virtual void anchor();
103   /// \brief The location of the ':'.
104   SourceLocation ColonLoc;
105 
AccessSpecDecl(AccessSpecifier AS,DeclContext * DC,SourceLocation ASLoc,SourceLocation ColonLoc)106   AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
107                  SourceLocation ASLoc, SourceLocation ColonLoc)
108     : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
109     setAccess(AS);
110   }
AccessSpecDecl(EmptyShell Empty)111   AccessSpecDecl(EmptyShell Empty)
112     : Decl(AccessSpec, Empty) { }
113 public:
114   /// \brief The location of the access specifier.
getAccessSpecifierLoc()115   SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
116   /// \brief Sets the location of the access specifier.
setAccessSpecifierLoc(SourceLocation ASLoc)117   void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
118 
119   /// \brief The location of the colon following the access specifier.
getColonLoc()120   SourceLocation getColonLoc() const { return ColonLoc; }
121   /// \brief Sets the location of the colon.
setColonLoc(SourceLocation CLoc)122   void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
123 
getSourceRange()124   SourceRange getSourceRange() const override LLVM_READONLY {
125     return SourceRange(getAccessSpecifierLoc(), getColonLoc());
126   }
127 
Create(ASTContext & C,AccessSpecifier AS,DeclContext * DC,SourceLocation ASLoc,SourceLocation ColonLoc)128   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
129                                 DeclContext *DC, SourceLocation ASLoc,
130                                 SourceLocation ColonLoc) {
131     return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
132   }
133   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
134 
135   // Implement isa/cast/dyncast/etc.
classof(const Decl * D)136   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)137   static bool classofKind(Kind K) { return K == AccessSpec; }
138 };
139 
140 
141 /// \brief Represents a base class of a C++ class.
142 ///
143 /// Each CXXBaseSpecifier represents a single, direct base class (or
144 /// struct) of a C++ class (or struct). It specifies the type of that
145 /// base class, whether it is a virtual or non-virtual base, and what
146 /// level of access (public, protected, private) is used for the
147 /// derivation. For example:
148 ///
149 /// \code
150 ///   class A { };
151 ///   class B { };
152 ///   class C : public virtual A, protected B { };
153 /// \endcode
154 ///
155 /// In this code, C will have two CXXBaseSpecifiers, one for "public
156 /// virtual A" and the other for "protected B".
157 class CXXBaseSpecifier {
158   /// \brief The source code range that covers the full base
159   /// specifier, including the "virtual" (if present) and access
160   /// specifier (if present).
161   SourceRange Range;
162 
163   /// \brief The source location of the ellipsis, if this is a pack
164   /// expansion.
165   SourceLocation EllipsisLoc;
166 
167   /// \brief Whether this is a virtual base class or not.
168   bool Virtual : 1;
169 
170   /// \brief Whether this is the base of a class (true) or of a struct (false).
171   ///
172   /// This determines the mapping from the access specifier as written in the
173   /// source code to the access specifier used for semantic analysis.
174   bool BaseOfClass : 1;
175 
176   /// \brief Access specifier as written in the source code (may be AS_none).
177   ///
178   /// The actual type of data stored here is an AccessSpecifier, but we use
179   /// "unsigned" here to work around a VC++ bug.
180   unsigned Access : 2;
181 
182   /// \brief Whether the class contains a using declaration
183   /// to inherit the named class's constructors.
184   bool InheritConstructors : 1;
185 
186   /// \brief The type of the base class.
187   ///
188   /// This will be a class or struct (or a typedef of such). The source code
189   /// range does not include the \c virtual or the access specifier.
190   TypeSourceInfo *BaseTypeInfo;
191 
192 public:
CXXBaseSpecifier()193   CXXBaseSpecifier() { }
194 
CXXBaseSpecifier(SourceRange R,bool V,bool BC,AccessSpecifier A,TypeSourceInfo * TInfo,SourceLocation EllipsisLoc)195   CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
196                    TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
197     : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
198       Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
199 
200   /// \brief Retrieves the source range that contains the entire base specifier.
getSourceRange()201   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
getLocStart()202   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
getLocEnd()203   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
204 
205   /// \brief Determines whether the base class is a virtual base class (or not).
isVirtual()206   bool isVirtual() const { return Virtual; }
207 
208   /// \brief Determine whether this base class is a base of a class declared
209   /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
isBaseOfClass()210   bool isBaseOfClass() const { return BaseOfClass; }
211 
212   /// \brief Determine whether this base specifier is a pack expansion.
isPackExpansion()213   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
214 
215   /// \brief Determine whether this base class's constructors get inherited.
getInheritConstructors()216   bool getInheritConstructors() const { return InheritConstructors; }
217 
218   /// \brief Set that this base class's constructors should be inherited.
219   void setInheritConstructors(bool Inherit = true) {
220     InheritConstructors = Inherit;
221   }
222 
223   /// \brief For a pack expansion, determine the location of the ellipsis.
getEllipsisLoc()224   SourceLocation getEllipsisLoc() const {
225     return EllipsisLoc;
226   }
227 
228   /// \brief Returns the access specifier for this base specifier.
229   ///
230   /// This is the actual base specifier as used for semantic analysis, so
231   /// the result can never be AS_none. To retrieve the access specifier as
232   /// written in the source code, use getAccessSpecifierAsWritten().
getAccessSpecifier()233   AccessSpecifier getAccessSpecifier() const {
234     if ((AccessSpecifier)Access == AS_none)
235       return BaseOfClass? AS_private : AS_public;
236     else
237       return (AccessSpecifier)Access;
238   }
239 
240   /// \brief Retrieves the access specifier as written in the source code
241   /// (which may mean that no access specifier was explicitly written).
242   ///
243   /// Use getAccessSpecifier() to retrieve the access specifier for use in
244   /// semantic analysis.
getAccessSpecifierAsWritten()245   AccessSpecifier getAccessSpecifierAsWritten() const {
246     return (AccessSpecifier)Access;
247   }
248 
249   /// \brief Retrieves the type of the base class.
250   ///
251   /// This type will always be an unqualified class type.
getType()252   QualType getType() const {
253     return BaseTypeInfo->getType().getUnqualifiedType();
254   }
255 
256   /// \brief Retrieves the type and source location of the base class.
getTypeSourceInfo()257   TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
258 };
259 
260 /// \brief A lazy pointer to the definition data for a declaration.
261 /// FIXME: This is a little CXXRecordDecl-specific that the moment.
262 template<typename Decl, typename T> class LazyDefinitionDataPtr {
263   llvm::PointerUnion<T *, Decl *> DataOrCanonicalDecl;
264 
update()265   LazyDefinitionDataPtr update() {
266     if (Decl *Canon = DataOrCanonicalDecl.template dyn_cast<Decl*>()) {
267       if (Canon->isCanonicalDecl())
268         Canon->getMostRecentDecl();
269       else
270         // Declaration isn't canonical any more;
271         // update it and perform path compression.
272         *this = Canon->getPreviousDecl()->DefinitionData.update();
273     }
274     return *this;
275   }
276 
277 public:
LazyDefinitionDataPtr(Decl * Canon)278   LazyDefinitionDataPtr(Decl *Canon) : DataOrCanonicalDecl(Canon) {}
LazyDefinitionDataPtr(T * Data)279   LazyDefinitionDataPtr(T *Data) : DataOrCanonicalDecl(Data) {}
getNotUpdated()280   T *getNotUpdated() { return DataOrCanonicalDecl.template dyn_cast<T*>(); }
get()281   T *get() { return update().getNotUpdated(); }
282 };
283 
284 /// \brief Represents a C++ struct/union/class.
285 class CXXRecordDecl : public RecordDecl {
286 
287   friend void TagDecl::startDefinition();
288 
289   /// Values used in DefinitionData fields to represent special members.
290   enum SpecialMemberFlags {
291     SMF_DefaultConstructor = 0x1,
292     SMF_CopyConstructor = 0x2,
293     SMF_MoveConstructor = 0x4,
294     SMF_CopyAssignment = 0x8,
295     SMF_MoveAssignment = 0x10,
296     SMF_Destructor = 0x20,
297     SMF_All = 0x3f
298   };
299 
300   struct DefinitionData {
301     DefinitionData(CXXRecordDecl *D);
302 
303     /// \brief True if this class has any user-declared constructors.
304     bool UserDeclaredConstructor : 1;
305 
306     /// \brief The user-declared special members which this class has.
307     unsigned UserDeclaredSpecialMembers : 6;
308 
309     /// \brief True when this class is an aggregate.
310     bool Aggregate : 1;
311 
312     /// \brief True when this class is a POD-type.
313     bool PlainOldData : 1;
314 
315     /// true when this class is empty for traits purposes,
316     /// i.e. has no data members other than 0-width bit-fields, has no
317     /// virtual function/base, and doesn't inherit from a non-empty
318     /// class. Doesn't take union-ness into account.
319     bool Empty : 1;
320 
321     /// \brief True when this class is polymorphic, i.e., has at
322     /// least one virtual member or derives from a polymorphic class.
323     bool Polymorphic : 1;
324 
325     /// \brief True when this class is abstract, i.e., has at least
326     /// one pure virtual function, (that can come from a base class).
327     bool Abstract : 1;
328 
329     /// \brief True when this class has standard layout.
330     ///
331     /// C++11 [class]p7.  A standard-layout class is a class that:
332     /// * has no non-static data members of type non-standard-layout class (or
333     ///   array of such types) or reference,
334     /// * has no virtual functions (10.3) and no virtual base classes (10.1),
335     /// * has the same access control (Clause 11) for all non-static data
336     ///   members
337     /// * has no non-standard-layout base classes,
338     /// * either has no non-static data members in the most derived class and at
339     ///   most one base class with non-static data members, or has no base
340     ///   classes with non-static data members, and
341     /// * has no base classes of the same type as the first non-static data
342     ///   member.
343     bool IsStandardLayout : 1;
344 
345     /// \brief True when there are no non-empty base classes.
346     ///
347     /// This is a helper bit of state used to implement IsStandardLayout more
348     /// efficiently.
349     bool HasNoNonEmptyBases : 1;
350 
351     /// \brief True when there are private non-static data members.
352     bool HasPrivateFields : 1;
353 
354     /// \brief True when there are protected non-static data members.
355     bool HasProtectedFields : 1;
356 
357     /// \brief True when there are private non-static data members.
358     bool HasPublicFields : 1;
359 
360     /// \brief True if this class (or any subobject) has mutable fields.
361     bool HasMutableFields : 1;
362 
363     /// \brief True if this class (or any nested anonymous struct or union)
364     /// has variant members.
365     bool HasVariantMembers : 1;
366 
367     /// \brief True if there no non-field members declared by the user.
368     bool HasOnlyCMembers : 1;
369 
370     /// \brief True if any field has an in-class initializer, including those
371     /// within anonymous unions or structs.
372     bool HasInClassInitializer : 1;
373 
374     /// \brief True if any field is of reference type, and does not have an
375     /// in-class initializer.
376     ///
377     /// In this case, value-initialization of this class is illegal in C++98
378     /// even if the class has a trivial default constructor.
379     bool HasUninitializedReferenceMember : 1;
380 
381     /// \brief These flags are \c true if a defaulted corresponding special
382     /// member can't be fully analyzed without performing overload resolution.
383     /// @{
384     bool NeedOverloadResolutionForMoveConstructor : 1;
385     bool NeedOverloadResolutionForMoveAssignment : 1;
386     bool NeedOverloadResolutionForDestructor : 1;
387     /// @}
388 
389     /// \brief These flags are \c true if an implicit defaulted corresponding
390     /// special member would be defined as deleted.
391     /// @{
392     bool DefaultedMoveConstructorIsDeleted : 1;
393     bool DefaultedMoveAssignmentIsDeleted : 1;
394     bool DefaultedDestructorIsDeleted : 1;
395     /// @}
396 
397     /// \brief The trivial special members which this class has, per
398     /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
399     /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
400     ///
401     /// This excludes any user-declared but not user-provided special members
402     /// which have been declared but not yet defined.
403     unsigned HasTrivialSpecialMembers : 6;
404 
405     /// \brief The declared special members of this class which are known to be
406     /// non-trivial.
407     ///
408     /// This excludes any user-declared but not user-provided special members
409     /// which have been declared but not yet defined, and any implicit special
410     /// members which have not yet been declared.
411     unsigned DeclaredNonTrivialSpecialMembers : 6;
412 
413     /// \brief True when this class has a destructor with no semantic effect.
414     bool HasIrrelevantDestructor : 1;
415 
416     /// \brief True when this class has at least one user-declared constexpr
417     /// constructor which is neither the copy nor move constructor.
418     bool HasConstexprNonCopyMoveConstructor : 1;
419 
420     /// \brief True if a defaulted default constructor for this class would
421     /// be constexpr.
422     bool DefaultedDefaultConstructorIsConstexpr : 1;
423 
424     /// \brief True if this class has a constexpr default constructor.
425     ///
426     /// This is true for either a user-declared constexpr default constructor
427     /// or an implicitly declared constexpr default constructor.
428     bool HasConstexprDefaultConstructor : 1;
429 
430     /// \brief True when this class contains at least one non-static data
431     /// member or base class of non-literal or volatile type.
432     bool HasNonLiteralTypeFieldsOrBases : 1;
433 
434     /// \brief True when visible conversion functions are already computed
435     /// and are available.
436     bool ComputedVisibleConversions : 1;
437 
438     /// \brief Whether we have a C++11 user-provided default constructor (not
439     /// explicitly deleted or defaulted).
440     bool UserProvidedDefaultConstructor : 1;
441 
442     /// \brief The special members which have been declared for this class,
443     /// either by the user or implicitly.
444     unsigned DeclaredSpecialMembers : 6;
445 
446     /// \brief Whether an implicit copy constructor would have a const-qualified
447     /// parameter.
448     bool ImplicitCopyConstructorHasConstParam : 1;
449 
450     /// \brief Whether an implicit copy assignment operator would have a
451     /// const-qualified parameter.
452     bool ImplicitCopyAssignmentHasConstParam : 1;
453 
454     /// \brief Whether any declared copy constructor has a const-qualified
455     /// parameter.
456     bool HasDeclaredCopyConstructorWithConstParam : 1;
457 
458     /// \brief Whether any declared copy assignment operator has either a
459     /// const-qualified reference parameter or a non-reference parameter.
460     bool HasDeclaredCopyAssignmentWithConstParam : 1;
461 
462     /// \brief Whether this class describes a C++ lambda.
463     bool IsLambda : 1;
464 
465     /// \brief Whether we are currently parsing base specifiers.
466     bool IsParsingBaseSpecifiers : 1;
467 
468     /// \brief The number of base class specifiers in Bases.
469     unsigned NumBases;
470 
471     /// \brief The number of virtual base class specifiers in VBases.
472     unsigned NumVBases;
473 
474     /// \brief Base classes of this class.
475     ///
476     /// FIXME: This is wasted space for a union.
477     LazyCXXBaseSpecifiersPtr Bases;
478 
479     /// \brief direct and indirect virtual base classes of this class.
480     LazyCXXBaseSpecifiersPtr VBases;
481 
482     /// \brief The conversion functions of this C++ class (but not its
483     /// inherited conversion functions).
484     ///
485     /// Each of the entries in this overload set is a CXXConversionDecl.
486     LazyASTUnresolvedSet Conversions;
487 
488     /// \brief The conversion functions of this C++ class and all those
489     /// inherited conversion functions that are visible in this class.
490     ///
491     /// Each of the entries in this overload set is a CXXConversionDecl or a
492     /// FunctionTemplateDecl.
493     LazyASTUnresolvedSet VisibleConversions;
494 
495     /// \brief The declaration which defines this record.
496     CXXRecordDecl *Definition;
497 
498     /// \brief The first friend declaration in this class, or null if there
499     /// aren't any.
500     ///
501     /// This is actually currently stored in reverse order.
502     LazyDeclPtr FirstFriend;
503 
504     /// \brief Retrieve the set of direct base classes.
getBasesDefinitionData505     CXXBaseSpecifier *getBases() const {
506       if (!Bases.isOffset())
507         return Bases.get(nullptr);
508       return getBasesSlowCase();
509     }
510 
511     /// \brief Retrieve the set of virtual base classes.
getVBasesDefinitionData512     CXXBaseSpecifier *getVBases() const {
513       if (!VBases.isOffset())
514         return VBases.get(nullptr);
515       return getVBasesSlowCase();
516     }
517 
518   private:
519     CXXBaseSpecifier *getBasesSlowCase() const;
520     CXXBaseSpecifier *getVBasesSlowCase() const;
521   };
522 
523   typedef LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>
524       DefinitionDataPtr;
525   friend class LazyDefinitionDataPtr<CXXRecordDecl, struct DefinitionData>;
526 
527   mutable DefinitionDataPtr DefinitionData;
528 
529   /// \brief Describes a C++ closure type (generated by a lambda expression).
530   struct LambdaDefinitionData : public DefinitionData {
531     typedef LambdaCapture Capture;
532 
LambdaDefinitionDataLambdaDefinitionData533     LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
534                          bool Dependent, bool IsGeneric,
535                          LambdaCaptureDefault CaptureDefault)
536       : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
537         CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
538         ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
539         MethodTyInfo(Info) {
540       IsLambda = true;
541     }
542 
543     /// \brief Whether this lambda is known to be dependent, even if its
544     /// context isn't dependent.
545     ///
546     /// A lambda with a non-dependent context can be dependent if it occurs
547     /// within the default argument of a function template, because the
548     /// lambda will have been created with the enclosing context as its
549     /// declaration context, rather than function. This is an unfortunate
550     /// artifact of having to parse the default arguments before.
551     unsigned Dependent : 1;
552 
553     /// \brief Whether this lambda is a generic lambda.
554     unsigned IsGenericLambda : 1;
555 
556     /// \brief The Default Capture.
557     unsigned CaptureDefault : 2;
558 
559     /// \brief The number of captures in this lambda is limited 2^NumCaptures.
560     unsigned NumCaptures : 15;
561 
562     /// \brief The number of explicit captures in this lambda.
563     unsigned NumExplicitCaptures : 13;
564 
565     /// \brief The number used to indicate this lambda expression for name
566     /// mangling in the Itanium C++ ABI.
567     unsigned ManglingNumber;
568 
569     /// \brief The declaration that provides context for this lambda, if the
570     /// actual DeclContext does not suffice. This is used for lambdas that
571     /// occur within default arguments of function parameters within the class
572     /// or within a data member initializer.
573     Decl *ContextDecl;
574 
575     /// \brief The list of captures, both explicit and implicit, for this
576     /// lambda.
577     Capture *Captures;
578 
579     /// \brief The type of the call method.
580     TypeSourceInfo *MethodTyInfo;
581 
582   };
583 
data()584   struct DefinitionData &data() const {
585     auto *DD = DefinitionData.get();
586     assert(DD && "queried property of class with no definition");
587     return *DD;
588   }
589 
getLambdaData()590   struct LambdaDefinitionData &getLambdaData() const {
591     // No update required: a merged definition cannot change any lambda
592     // properties.
593     auto *DD = DefinitionData.getNotUpdated();
594     assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
595     return static_cast<LambdaDefinitionData&>(*DD);
596   }
597 
598   /// \brief The template or declaration that this declaration
599   /// describes or was instantiated from, respectively.
600   ///
601   /// For non-templates, this value will be null. For record
602   /// declarations that describe a class template, this will be a
603   /// pointer to a ClassTemplateDecl. For member
604   /// classes of class template specializations, this will be the
605   /// MemberSpecializationInfo referring to the member class that was
606   /// instantiated or specialized.
607   llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
608     TemplateOrInstantiation;
609 
610   friend class DeclContext;
611   friend class LambdaExpr;
612 
613   /// \brief Called from setBases and addedMember to notify the class that a
614   /// direct or virtual base class or a member of class type has been added.
615   void addedClassSubobject(CXXRecordDecl *Base);
616 
617   /// \brief Notify the class that member has been added.
618   ///
619   /// This routine helps maintain information about the class based on which
620   /// members have been added. It will be invoked by DeclContext::addDecl()
621   /// whenever a member is added to this record.
622   void addedMember(Decl *D);
623 
624   void markedVirtualFunctionPure();
625   friend void FunctionDecl::setPure(bool);
626 
627   friend class ASTNodeImporter;
628 
629   /// \brief Get the head of our list of friend declarations, possibly
630   /// deserializing the friends from an external AST source.
631   FriendDecl *getFirstFriend() const;
632 
633 protected:
634   CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
635                 SourceLocation StartLoc, SourceLocation IdLoc,
636                 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
637 
638 public:
639   /// \brief Iterator that traverses the base classes of a class.
640   typedef CXXBaseSpecifier*       base_class_iterator;
641 
642   /// \brief Iterator that traverses the base classes of a class.
643   typedef const CXXBaseSpecifier* base_class_const_iterator;
644 
getCanonicalDecl()645   CXXRecordDecl *getCanonicalDecl() override {
646     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
647   }
getCanonicalDecl()648   virtual const CXXRecordDecl *getCanonicalDecl() const {
649     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
650   }
651 
getPreviousDecl()652   CXXRecordDecl *getPreviousDecl() {
653     return cast_or_null<CXXRecordDecl>(
654             static_cast<RecordDecl *>(this)->getPreviousDecl());
655   }
getPreviousDecl()656   const CXXRecordDecl *getPreviousDecl() const {
657     return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
658   }
659 
getMostRecentDecl()660   CXXRecordDecl *getMostRecentDecl() {
661     return cast<CXXRecordDecl>(
662             static_cast<RecordDecl *>(this)->getMostRecentDecl());
663   }
664 
getMostRecentDecl()665   const CXXRecordDecl *getMostRecentDecl() const {
666     return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
667   }
668 
getDefinition()669   CXXRecordDecl *getDefinition() const {
670     auto *DD = DefinitionData.get();
671     return DD ? DD->Definition : nullptr;
672   }
673 
hasDefinition()674   bool hasDefinition() const { return DefinitionData.get(); }
675 
676   static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
677                                SourceLocation StartLoc, SourceLocation IdLoc,
678                                IdentifierInfo *Id,
679                                CXXRecordDecl *PrevDecl = nullptr,
680                                bool DelayTypeCreation = false);
681   static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
682                                      TypeSourceInfo *Info, SourceLocation Loc,
683                                      bool DependentLambda, bool IsGeneric,
684                                      LambdaCaptureDefault CaptureDefault);
685   static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
686 
isDynamicClass()687   bool isDynamicClass() const {
688     return data().Polymorphic || data().NumVBases != 0;
689   }
690 
setIsParsingBaseSpecifiers()691   void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
692 
isParsingBaseSpecifiers()693   bool isParsingBaseSpecifiers() const {
694     return data().IsParsingBaseSpecifiers;
695   }
696 
697   /// \brief Sets the base classes of this struct or class.
698   void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
699 
700   /// \brief Retrieves the number of base classes of this class.
getNumBases()701   unsigned getNumBases() const { return data().NumBases; }
702 
703   typedef llvm::iterator_range<base_class_iterator> base_class_range;
704   typedef llvm::iterator_range<base_class_const_iterator>
705     base_class_const_range;
706 
bases()707   base_class_range bases() {
708     return base_class_range(bases_begin(), bases_end());
709   }
bases()710   base_class_const_range bases() const {
711     return base_class_const_range(bases_begin(), bases_end());
712   }
713 
bases_begin()714   base_class_iterator bases_begin() { return data().getBases(); }
bases_begin()715   base_class_const_iterator bases_begin() const { return data().getBases(); }
bases_end()716   base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
bases_end()717   base_class_const_iterator bases_end() const {
718     return bases_begin() + data().NumBases;
719   }
720 
721   /// \brief Retrieves the number of virtual base classes of this class.
getNumVBases()722   unsigned getNumVBases() const { return data().NumVBases; }
723 
vbases()724   base_class_range vbases() {
725     return base_class_range(vbases_begin(), vbases_end());
726   }
vbases()727   base_class_const_range vbases() const {
728     return base_class_const_range(vbases_begin(), vbases_end());
729   }
730 
vbases_begin()731   base_class_iterator vbases_begin() { return data().getVBases(); }
vbases_begin()732   base_class_const_iterator vbases_begin() const { return data().getVBases(); }
vbases_end()733   base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
vbases_end()734   base_class_const_iterator vbases_end() const {
735     return vbases_begin() + data().NumVBases;
736   }
737 
738   /// \brief Determine whether this class has any dependent base classes which
739   /// are not the current instantiation.
740   bool hasAnyDependentBases() const;
741 
742   /// Iterator access to method members.  The method iterator visits
743   /// all method members of the class, including non-instance methods,
744   /// special methods, etc.
745   typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
746   typedef llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>
747     method_range;
748 
methods()749   method_range methods() const {
750     return method_range(method_begin(), method_end());
751   }
752 
753   /// \brief Method begin iterator.  Iterates in the order the methods
754   /// were declared.
method_begin()755   method_iterator method_begin() const {
756     return method_iterator(decls_begin());
757   }
758   /// \brief Method past-the-end iterator.
method_end()759   method_iterator method_end() const {
760     return method_iterator(decls_end());
761   }
762 
763   /// Iterator access to constructor members.
764   typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
765   typedef llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>
766     ctor_range;
767 
ctors()768   ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
769 
ctor_begin()770   ctor_iterator ctor_begin() const {
771     return ctor_iterator(decls_begin());
772   }
ctor_end()773   ctor_iterator ctor_end() const {
774     return ctor_iterator(decls_end());
775   }
776 
777   /// An iterator over friend declarations.  All of these are defined
778   /// in DeclFriend.h.
779   class friend_iterator;
780   typedef llvm::iterator_range<friend_iterator> friend_range;
781 
782   friend_range friends() const;
783   friend_iterator friend_begin() const;
784   friend_iterator friend_end() const;
785   void pushFriendDecl(FriendDecl *FD);
786 
787   /// Determines whether this record has any friends.
hasFriends()788   bool hasFriends() const {
789     return data().FirstFriend.isValid();
790   }
791 
792   /// \brief \c true if we know for sure that this class has a single,
793   /// accessible, unambiguous move constructor that is not deleted.
hasSimpleMoveConstructor()794   bool hasSimpleMoveConstructor() const {
795     return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
796            !data().DefaultedMoveConstructorIsDeleted;
797   }
798   /// \brief \c true if we know for sure that this class has a single,
799   /// accessible, unambiguous move assignment operator that is not deleted.
hasSimpleMoveAssignment()800   bool hasSimpleMoveAssignment() const {
801     return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
802            !data().DefaultedMoveAssignmentIsDeleted;
803   }
804   /// \brief \c true if we know for sure that this class has an accessible
805   /// destructor that is not deleted.
hasSimpleDestructor()806   bool hasSimpleDestructor() const {
807     return !hasUserDeclaredDestructor() &&
808            !data().DefaultedDestructorIsDeleted;
809   }
810 
811   /// \brief Determine whether this class has any default constructors.
hasDefaultConstructor()812   bool hasDefaultConstructor() const {
813     return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
814            needsImplicitDefaultConstructor();
815   }
816 
817   /// \brief Determine if we need to declare a default constructor for
818   /// this class.
819   ///
820   /// This value is used for lazy creation of default constructors.
needsImplicitDefaultConstructor()821   bool needsImplicitDefaultConstructor() const {
822     return !data().UserDeclaredConstructor &&
823            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
824   }
825 
826   /// \brief Determine whether this class has any user-declared constructors.
827   ///
828   /// When true, a default constructor will not be implicitly declared.
hasUserDeclaredConstructor()829   bool hasUserDeclaredConstructor() const {
830     return data().UserDeclaredConstructor;
831   }
832 
833   /// \brief Whether this class has a user-provided default constructor
834   /// per C++11.
hasUserProvidedDefaultConstructor()835   bool hasUserProvidedDefaultConstructor() const {
836     return data().UserProvidedDefaultConstructor;
837   }
838 
839   /// \brief Determine whether this class has a user-declared copy constructor.
840   ///
841   /// When false, a copy constructor will be implicitly declared.
hasUserDeclaredCopyConstructor()842   bool hasUserDeclaredCopyConstructor() const {
843     return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
844   }
845 
846   /// \brief Determine whether this class needs an implicit copy
847   /// constructor to be lazily declared.
needsImplicitCopyConstructor()848   bool needsImplicitCopyConstructor() const {
849     return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
850   }
851 
852   /// \brief Determine whether we need to eagerly declare a defaulted copy
853   /// constructor for this class.
needsOverloadResolutionForCopyConstructor()854   bool needsOverloadResolutionForCopyConstructor() const {
855     return data().HasMutableFields;
856   }
857 
858   /// \brief Determine whether an implicit copy constructor for this type
859   /// would have a parameter with a const-qualified reference type.
implicitCopyConstructorHasConstParam()860   bool implicitCopyConstructorHasConstParam() const {
861     return data().ImplicitCopyConstructorHasConstParam;
862   }
863 
864   /// \brief Determine whether this class has a copy constructor with
865   /// a parameter type which is a reference to a const-qualified type.
hasCopyConstructorWithConstParam()866   bool hasCopyConstructorWithConstParam() const {
867     return data().HasDeclaredCopyConstructorWithConstParam ||
868            (needsImplicitCopyConstructor() &&
869             implicitCopyConstructorHasConstParam());
870   }
871 
872   /// \brief Whether this class has a user-declared move constructor or
873   /// assignment operator.
874   ///
875   /// When false, a move constructor and assignment operator may be
876   /// implicitly declared.
hasUserDeclaredMoveOperation()877   bool hasUserDeclaredMoveOperation() const {
878     return data().UserDeclaredSpecialMembers &
879              (SMF_MoveConstructor | SMF_MoveAssignment);
880   }
881 
882   /// \brief Determine whether this class has had a move constructor
883   /// declared by the user.
hasUserDeclaredMoveConstructor()884   bool hasUserDeclaredMoveConstructor() const {
885     return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
886   }
887 
888   /// \brief Determine whether this class has a move constructor.
hasMoveConstructor()889   bool hasMoveConstructor() const {
890     return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
891            needsImplicitMoveConstructor();
892   }
893 
894   /// \brief Set that we attempted to declare an implicitly move
895   /// constructor, but overload resolution failed so we deleted it.
setImplicitMoveConstructorIsDeleted()896   void setImplicitMoveConstructorIsDeleted() {
897     assert((data().DefaultedMoveConstructorIsDeleted ||
898             needsOverloadResolutionForMoveConstructor()) &&
899            "move constructor should not be deleted");
900     data().DefaultedMoveConstructorIsDeleted = true;
901   }
902 
903   /// \brief Determine whether this class should get an implicit move
904   /// constructor or if any existing special member function inhibits this.
needsImplicitMoveConstructor()905   bool needsImplicitMoveConstructor() const {
906     return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
907            !hasUserDeclaredCopyConstructor() &&
908            !hasUserDeclaredCopyAssignment() &&
909            !hasUserDeclaredMoveAssignment() &&
910            !hasUserDeclaredDestructor();
911   }
912 
913   /// \brief Determine whether we need to eagerly declare a defaulted move
914   /// constructor for this class.
needsOverloadResolutionForMoveConstructor()915   bool needsOverloadResolutionForMoveConstructor() const {
916     return data().NeedOverloadResolutionForMoveConstructor;
917   }
918 
919   /// \brief Determine whether this class has a user-declared copy assignment
920   /// operator.
921   ///
922   /// When false, a copy assigment operator will be implicitly declared.
hasUserDeclaredCopyAssignment()923   bool hasUserDeclaredCopyAssignment() const {
924     return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
925   }
926 
927   /// \brief Determine whether this class needs an implicit copy
928   /// assignment operator to be lazily declared.
needsImplicitCopyAssignment()929   bool needsImplicitCopyAssignment() const {
930     return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
931   }
932 
933   /// \brief Determine whether we need to eagerly declare a defaulted copy
934   /// assignment operator for this class.
needsOverloadResolutionForCopyAssignment()935   bool needsOverloadResolutionForCopyAssignment() const {
936     return data().HasMutableFields;
937   }
938 
939   /// \brief Determine whether an implicit copy assignment operator for this
940   /// type would have a parameter with a const-qualified reference type.
implicitCopyAssignmentHasConstParam()941   bool implicitCopyAssignmentHasConstParam() const {
942     return data().ImplicitCopyAssignmentHasConstParam;
943   }
944 
945   /// \brief Determine whether this class has a copy assignment operator with
946   /// a parameter type which is a reference to a const-qualified type or is not
947   /// a reference.
hasCopyAssignmentWithConstParam()948   bool hasCopyAssignmentWithConstParam() const {
949     return data().HasDeclaredCopyAssignmentWithConstParam ||
950            (needsImplicitCopyAssignment() &&
951             implicitCopyAssignmentHasConstParam());
952   }
953 
954   /// \brief Determine whether this class has had a move assignment
955   /// declared by the user.
hasUserDeclaredMoveAssignment()956   bool hasUserDeclaredMoveAssignment() const {
957     return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
958   }
959 
960   /// \brief Determine whether this class has a move assignment operator.
hasMoveAssignment()961   bool hasMoveAssignment() const {
962     return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
963            needsImplicitMoveAssignment();
964   }
965 
966   /// \brief Set that we attempted to declare an implicit move assignment
967   /// operator, but overload resolution failed so we deleted it.
setImplicitMoveAssignmentIsDeleted()968   void setImplicitMoveAssignmentIsDeleted() {
969     assert((data().DefaultedMoveAssignmentIsDeleted ||
970             needsOverloadResolutionForMoveAssignment()) &&
971            "move assignment should not be deleted");
972     data().DefaultedMoveAssignmentIsDeleted = true;
973   }
974 
975   /// \brief Determine whether this class should get an implicit move
976   /// assignment operator or if any existing special member function inhibits
977   /// this.
needsImplicitMoveAssignment()978   bool needsImplicitMoveAssignment() const {
979     return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
980            !hasUserDeclaredCopyConstructor() &&
981            !hasUserDeclaredCopyAssignment() &&
982            !hasUserDeclaredMoveConstructor() &&
983            !hasUserDeclaredDestructor();
984   }
985 
986   /// \brief Determine whether we need to eagerly declare a move assignment
987   /// operator for this class.
needsOverloadResolutionForMoveAssignment()988   bool needsOverloadResolutionForMoveAssignment() const {
989     return data().NeedOverloadResolutionForMoveAssignment;
990   }
991 
992   /// \brief Determine whether this class has a user-declared destructor.
993   ///
994   /// When false, a destructor will be implicitly declared.
hasUserDeclaredDestructor()995   bool hasUserDeclaredDestructor() const {
996     return data().UserDeclaredSpecialMembers & SMF_Destructor;
997   }
998 
999   /// \brief Determine whether this class needs an implicit destructor to
1000   /// be lazily declared.
needsImplicitDestructor()1001   bool needsImplicitDestructor() const {
1002     return !(data().DeclaredSpecialMembers & SMF_Destructor);
1003   }
1004 
1005   /// \brief Determine whether we need to eagerly declare a destructor for this
1006   /// class.
needsOverloadResolutionForDestructor()1007   bool needsOverloadResolutionForDestructor() const {
1008     return data().NeedOverloadResolutionForDestructor;
1009   }
1010 
1011   /// \brief Determine whether this class describes a lambda function object.
isLambda()1012   bool isLambda() const {
1013     // An update record can't turn a non-lambda into a lambda.
1014     auto *DD = DefinitionData.getNotUpdated();
1015     return DD && DD->IsLambda;
1016   }
1017 
1018   /// \brief Determine whether this class describes a generic
1019   /// lambda function object (i.e. function call operator is
1020   /// a template).
1021   bool isGenericLambda() const;
1022 
1023   /// \brief Retrieve the lambda call operator of the closure type
1024   /// if this is a closure type.
1025   CXXMethodDecl *getLambdaCallOperator() const;
1026 
1027   /// \brief Retrieve the lambda static invoker, the address of which
1028   /// is returned by the conversion operator, and the body of which
1029   /// is forwarded to the lambda call operator.
1030   CXXMethodDecl *getLambdaStaticInvoker() const;
1031 
1032   /// \brief Retrieve the generic lambda's template parameter list.
1033   /// Returns null if the class does not represent a lambda or a generic
1034   /// lambda.
1035   TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1036 
getLambdaCaptureDefault()1037   LambdaCaptureDefault getLambdaCaptureDefault() const {
1038     assert(isLambda());
1039     return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1040   }
1041 
1042   /// \brief For a closure type, retrieve the mapping from captured
1043   /// variables and \c this to the non-static data members that store the
1044   /// values or references of the captures.
1045   ///
1046   /// \param Captures Will be populated with the mapping from captured
1047   /// variables to the corresponding fields.
1048   ///
1049   /// \param ThisCapture Will be set to the field declaration for the
1050   /// \c this capture.
1051   ///
1052   /// \note No entries will be added for init-captures, as they do not capture
1053   /// variables.
1054   void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1055                         FieldDecl *&ThisCapture) const;
1056 
1057   typedef const LambdaCapture *capture_const_iterator;
1058   typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
1059 
captures()1060   capture_const_range captures() const {
1061     return capture_const_range(captures_begin(), captures_end());
1062   }
captures_begin()1063   capture_const_iterator captures_begin() const {
1064     return isLambda() ? getLambdaData().Captures : nullptr;
1065   }
captures_end()1066   capture_const_iterator captures_end() const {
1067     return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1068                       : nullptr;
1069   }
1070 
1071   typedef UnresolvedSetIterator conversion_iterator;
conversion_begin()1072   conversion_iterator conversion_begin() const {
1073     return data().Conversions.get(getASTContext()).begin();
1074   }
conversion_end()1075   conversion_iterator conversion_end() const {
1076     return data().Conversions.get(getASTContext()).end();
1077   }
1078 
1079   /// Removes a conversion function from this class.  The conversion
1080   /// function must currently be a member of this class.  Furthermore,
1081   /// this class must currently be in the process of being defined.
1082   void removeConversion(const NamedDecl *Old);
1083 
1084   /// \brief Get all conversion functions visible in current class,
1085   /// including conversion function templates.
1086   std::pair<conversion_iterator, conversion_iterator>
1087     getVisibleConversionFunctions();
1088 
1089   /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1090   /// which is a class with no user-declared constructors, no private
1091   /// or protected non-static data members, no base classes, and no virtual
1092   /// functions (C++ [dcl.init.aggr]p1).
isAggregate()1093   bool isAggregate() const { return data().Aggregate; }
1094 
1095   /// \brief Whether this class has any in-class initializers
1096   /// for non-static data members (including those in anonymous unions or
1097   /// structs).
hasInClassInitializer()1098   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1099 
1100   /// \brief Whether this class or any of its subobjects has any members of
1101   /// reference type which would make value-initialization ill-formed.
1102   ///
1103   /// Per C++03 [dcl.init]p5:
1104   ///  - if T is a non-union class type without a user-declared constructor,
1105   ///    then every non-static data member and base-class component of T is
1106   ///    value-initialized [...] A program that calls for [...]
1107   ///    value-initialization of an entity of reference type is ill-formed.
hasUninitializedReferenceMember()1108   bool hasUninitializedReferenceMember() const {
1109     return !isUnion() && !hasUserDeclaredConstructor() &&
1110            data().HasUninitializedReferenceMember;
1111   }
1112 
1113   /// \brief Whether this class is a POD-type (C++ [class]p4)
1114   ///
1115   /// For purposes of this function a class is POD if it is an aggregate
1116   /// that has no non-static non-POD data members, no reference data
1117   /// members, no user-defined copy assignment operator and no
1118   /// user-defined destructor.
1119   ///
1120   /// Note that this is the C++ TR1 definition of POD.
isPOD()1121   bool isPOD() const { return data().PlainOldData; }
1122 
1123   /// \brief True if this class is C-like, without C++-specific features, e.g.
1124   /// it contains only public fields, no bases, tag kind is not 'class', etc.
1125   bool isCLike() const;
1126 
1127   /// \brief Determine whether this is an empty class in the sense of
1128   /// (C++11 [meta.unary.prop]).
1129   ///
1130   /// A non-union class is empty iff it has a virtual function, virtual base,
1131   /// data member (other than 0-width bit-field) or inherits from a non-empty
1132   /// class.
1133   ///
1134   /// \note This does NOT include a check for union-ness.
isEmpty()1135   bool isEmpty() const { return data().Empty; }
1136 
1137   /// Whether this class is polymorphic (C++ [class.virtual]),
1138   /// which means that the class contains or inherits a virtual function.
isPolymorphic()1139   bool isPolymorphic() const { return data().Polymorphic; }
1140 
1141   /// \brief Determine whether this class has a pure virtual function.
1142   ///
1143   /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1144   /// a pure virtual function or inherits a pure virtual function that is
1145   /// not overridden.
isAbstract()1146   bool isAbstract() const { return data().Abstract; }
1147 
1148   /// \brief Determine whether this class has standard layout per
1149   /// (C++ [class]p7)
isStandardLayout()1150   bool isStandardLayout() const { return data().IsStandardLayout; }
1151 
1152   /// \brief Determine whether this class, or any of its class subobjects,
1153   /// contains a mutable field.
hasMutableFields()1154   bool hasMutableFields() const { return data().HasMutableFields; }
1155 
1156   /// \brief Determine whether this class has any variant members.
hasVariantMembers()1157   bool hasVariantMembers() const { return data().HasVariantMembers; }
1158 
1159   /// \brief Determine whether this class has a trivial default constructor
1160   /// (C++11 [class.ctor]p5).
hasTrivialDefaultConstructor()1161   bool hasTrivialDefaultConstructor() const {
1162     return hasDefaultConstructor() &&
1163            (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1164   }
1165 
1166   /// \brief Determine whether this class has a non-trivial default constructor
1167   /// (C++11 [class.ctor]p5).
hasNonTrivialDefaultConstructor()1168   bool hasNonTrivialDefaultConstructor() const {
1169     return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1170            (needsImplicitDefaultConstructor() &&
1171             !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1172   }
1173 
1174   /// \brief Determine whether this class has at least one constexpr constructor
1175   /// other than the copy or move constructors.
hasConstexprNonCopyMoveConstructor()1176   bool hasConstexprNonCopyMoveConstructor() const {
1177     return data().HasConstexprNonCopyMoveConstructor ||
1178            (needsImplicitDefaultConstructor() &&
1179             defaultedDefaultConstructorIsConstexpr());
1180   }
1181 
1182   /// \brief Determine whether a defaulted default constructor for this class
1183   /// would be constexpr.
defaultedDefaultConstructorIsConstexpr()1184   bool defaultedDefaultConstructorIsConstexpr() const {
1185     return data().DefaultedDefaultConstructorIsConstexpr &&
1186            (!isUnion() || hasInClassInitializer() || !hasVariantMembers());
1187   }
1188 
1189   /// \brief Determine whether this class has a constexpr default constructor.
hasConstexprDefaultConstructor()1190   bool hasConstexprDefaultConstructor() const {
1191     return data().HasConstexprDefaultConstructor ||
1192            (needsImplicitDefaultConstructor() &&
1193             defaultedDefaultConstructorIsConstexpr());
1194   }
1195 
1196   /// \brief Determine whether this class has a trivial copy constructor
1197   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
hasTrivialCopyConstructor()1198   bool hasTrivialCopyConstructor() const {
1199     return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1200   }
1201 
1202   /// \brief Determine whether this class has a non-trivial copy constructor
1203   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
hasNonTrivialCopyConstructor()1204   bool hasNonTrivialCopyConstructor() const {
1205     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1206            !hasTrivialCopyConstructor();
1207   }
1208 
1209   /// \brief Determine whether this class has a trivial move constructor
1210   /// (C++11 [class.copy]p12)
hasTrivialMoveConstructor()1211   bool hasTrivialMoveConstructor() const {
1212     return hasMoveConstructor() &&
1213            (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1214   }
1215 
1216   /// \brief Determine whether this class has a non-trivial move constructor
1217   /// (C++11 [class.copy]p12)
hasNonTrivialMoveConstructor()1218   bool hasNonTrivialMoveConstructor() const {
1219     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1220            (needsImplicitMoveConstructor() &&
1221             !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1222   }
1223 
1224   /// \brief Determine whether this class has a trivial copy assignment operator
1225   /// (C++ [class.copy]p11, C++11 [class.copy]p25)
hasTrivialCopyAssignment()1226   bool hasTrivialCopyAssignment() const {
1227     return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1228   }
1229 
1230   /// \brief Determine whether this class has a non-trivial copy assignment
1231   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
hasNonTrivialCopyAssignment()1232   bool hasNonTrivialCopyAssignment() const {
1233     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1234            !hasTrivialCopyAssignment();
1235   }
1236 
1237   /// \brief Determine whether this class has a trivial move assignment operator
1238   /// (C++11 [class.copy]p25)
hasTrivialMoveAssignment()1239   bool hasTrivialMoveAssignment() const {
1240     return hasMoveAssignment() &&
1241            (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1242   }
1243 
1244   /// \brief Determine whether this class has a non-trivial move assignment
1245   /// operator (C++11 [class.copy]p25)
hasNonTrivialMoveAssignment()1246   bool hasNonTrivialMoveAssignment() const {
1247     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1248            (needsImplicitMoveAssignment() &&
1249             !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1250   }
1251 
1252   /// \brief Determine whether this class has a trivial destructor
1253   /// (C++ [class.dtor]p3)
hasTrivialDestructor()1254   bool hasTrivialDestructor() const {
1255     return data().HasTrivialSpecialMembers & SMF_Destructor;
1256   }
1257 
1258   /// \brief Determine whether this class has a non-trivial destructor
1259   /// (C++ [class.dtor]p3)
hasNonTrivialDestructor()1260   bool hasNonTrivialDestructor() const {
1261     return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1262   }
1263 
1264   /// \brief Determine whether this class has a destructor which has no
1265   /// semantic effect.
1266   ///
1267   /// Any such destructor will be trivial, public, defaulted and not deleted,
1268   /// and will call only irrelevant destructors.
hasIrrelevantDestructor()1269   bool hasIrrelevantDestructor() const {
1270     return data().HasIrrelevantDestructor;
1271   }
1272 
1273   /// \brief Determine whether this class has a non-literal or/ volatile type
1274   /// non-static data member or base class.
hasNonLiteralTypeFieldsOrBases()1275   bool hasNonLiteralTypeFieldsOrBases() const {
1276     return data().HasNonLiteralTypeFieldsOrBases;
1277   }
1278 
1279   /// \brief Determine whether this class is considered trivially copyable per
1280   /// (C++11 [class]p6).
1281   bool isTriviallyCopyable() const;
1282 
1283   /// \brief Determine whether this class is considered trivial.
1284   ///
1285   /// C++11 [class]p6:
1286   ///    "A trivial class is a class that has a trivial default constructor and
1287   ///    is trivially copiable."
isTrivial()1288   bool isTrivial() const {
1289     return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1290   }
1291 
1292   /// \brief Determine whether this class is a literal type.
1293   ///
1294   /// C++11 [basic.types]p10:
1295   ///   A class type that has all the following properties:
1296   ///     - it has a trivial destructor
1297   ///     - every constructor call and full-expression in the
1298   ///       brace-or-equal-intializers for non-static data members (if any) is
1299   ///       a constant expression.
1300   ///     - it is an aggregate type or has at least one constexpr constructor
1301   ///       or constructor template that is not a copy or move constructor, and
1302   ///     - all of its non-static data members and base classes are of literal
1303   ///       types
1304   ///
1305   /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1306   /// treating types with trivial default constructors as literal types.
isLiteral()1307   bool isLiteral() const {
1308     return hasTrivialDestructor() &&
1309            (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1310             hasTrivialDefaultConstructor()) &&
1311            !hasNonLiteralTypeFieldsOrBases();
1312   }
1313 
1314   /// \brief If this record is an instantiation of a member class,
1315   /// retrieves the member class from which it was instantiated.
1316   ///
1317   /// This routine will return non-null for (non-templated) member
1318   /// classes of class templates. For example, given:
1319   ///
1320   /// \code
1321   /// template<typename T>
1322   /// struct X {
1323   ///   struct A { };
1324   /// };
1325   /// \endcode
1326   ///
1327   /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1328   /// whose parent is the class template specialization X<int>. For
1329   /// this declaration, getInstantiatedFromMemberClass() will return
1330   /// the CXXRecordDecl X<T>::A. When a complete definition of
1331   /// X<int>::A is required, it will be instantiated from the
1332   /// declaration returned by getInstantiatedFromMemberClass().
1333   CXXRecordDecl *getInstantiatedFromMemberClass() const;
1334 
1335   /// \brief If this class is an instantiation of a member class of a
1336   /// class template specialization, retrieves the member specialization
1337   /// information.
getMemberSpecializationInfo()1338   MemberSpecializationInfo *getMemberSpecializationInfo() const {
1339     return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1340   }
1341 
1342   /// \brief Specify that this record is an instantiation of the
1343   /// member class \p RD.
1344   void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1345                                      TemplateSpecializationKind TSK);
1346 
1347   /// \brief Retrieves the class template that is described by this
1348   /// class declaration.
1349   ///
1350   /// Every class template is represented as a ClassTemplateDecl and a
1351   /// CXXRecordDecl. The former contains template properties (such as
1352   /// the template parameter lists) while the latter contains the
1353   /// actual description of the template's
1354   /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1355   /// CXXRecordDecl that from a ClassTemplateDecl, while
1356   /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1357   /// a CXXRecordDecl.
getDescribedClassTemplate()1358   ClassTemplateDecl *getDescribedClassTemplate() const {
1359     return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1360   }
1361 
setDescribedClassTemplate(ClassTemplateDecl * Template)1362   void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1363     TemplateOrInstantiation = Template;
1364   }
1365 
1366   /// \brief Determine whether this particular class is a specialization or
1367   /// instantiation of a class template or member class of a class template,
1368   /// and how it was instantiated or specialized.
1369   TemplateSpecializationKind getTemplateSpecializationKind() const;
1370 
1371   /// \brief Set the kind of specialization or template instantiation this is.
1372   void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1373 
1374   /// \brief Returns the destructor decl for this class.
1375   CXXDestructorDecl *getDestructor() const;
1376 
1377   /// \brief If the class is a local class [class.local], returns
1378   /// the enclosing function declaration.
isLocalClass()1379   const FunctionDecl *isLocalClass() const {
1380     if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1381       return RD->isLocalClass();
1382 
1383     return dyn_cast<FunctionDecl>(getDeclContext());
1384   }
1385 
isLocalClass()1386   FunctionDecl *isLocalClass() {
1387     return const_cast<FunctionDecl*>(
1388         const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1389   }
1390 
1391   /// \brief Determine whether this dependent class is a current instantiation,
1392   /// when viewed from within the given context.
1393   bool isCurrentInstantiation(const DeclContext *CurContext) const;
1394 
1395   /// \brief Determine whether this class is derived from the class \p Base.
1396   ///
1397   /// This routine only determines whether this class is derived from \p Base,
1398   /// but does not account for factors that may make a Derived -> Base class
1399   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1400   /// base class subobjects.
1401   ///
1402   /// \param Base the base class we are searching for.
1403   ///
1404   /// \returns true if this class is derived from Base, false otherwise.
1405   bool isDerivedFrom(const CXXRecordDecl *Base) const;
1406 
1407   /// \brief Determine whether this class is derived from the type \p Base.
1408   ///
1409   /// This routine only determines whether this class is derived from \p Base,
1410   /// but does not account for factors that may make a Derived -> Base class
1411   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1412   /// base class subobjects.
1413   ///
1414   /// \param Base the base class we are searching for.
1415   ///
1416   /// \param Paths will contain the paths taken from the current class to the
1417   /// given \p Base class.
1418   ///
1419   /// \returns true if this class is derived from \p Base, false otherwise.
1420   ///
1421   /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1422   /// tangling input and output in \p Paths
1423   bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1424 
1425   /// \brief Determine whether this class is virtually derived from
1426   /// the class \p Base.
1427   ///
1428   /// This routine only determines whether this class is virtually
1429   /// derived from \p Base, but does not account for factors that may
1430   /// make a Derived -> Base class ill-formed, such as
1431   /// private/protected inheritance or multiple, ambiguous base class
1432   /// subobjects.
1433   ///
1434   /// \param Base the base class we are searching for.
1435   ///
1436   /// \returns true if this class is virtually derived from Base,
1437   /// false otherwise.
1438   bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1439 
1440   /// \brief Determine whether this class is provably not derived from
1441   /// the type \p Base.
1442   bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1443 
1444   /// \brief Function type used by forallBases() as a callback.
1445   ///
1446   /// \param BaseDefinition the definition of the base class
1447   ///
1448   /// \returns true if this base matched the search criteria
1449   typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1450                                    void *UserData);
1451 
1452   /// \brief Determines if the given callback holds for all the direct
1453   /// or indirect base classes of this type.
1454   ///
1455   /// The class itself does not count as a base class.  This routine
1456   /// returns false if the class has non-computable base classes.
1457   ///
1458   /// \param BaseMatches Callback invoked for each (direct or indirect) base
1459   /// class of this type, or if \p AllowShortCircuit is true then until a call
1460   /// returns false.
1461   ///
1462   /// \param UserData Passed as the second argument of every call to
1463   /// \p BaseMatches.
1464   ///
1465   /// \param AllowShortCircuit if false, forces the callback to be called
1466   /// for every base class, even if a dependent or non-matching base was
1467   /// found.
1468   bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1469                    bool AllowShortCircuit = true) const;
1470 
1471   /// \brief Function type used by lookupInBases() to determine whether a
1472   /// specific base class subobject matches the lookup criteria.
1473   ///
1474   /// \param Specifier the base-class specifier that describes the inheritance
1475   /// from the base class we are trying to match.
1476   ///
1477   /// \param Path the current path, from the most-derived class down to the
1478   /// base named by the \p Specifier.
1479   ///
1480   /// \param UserData a single pointer to user-specified data, provided to
1481   /// lookupInBases().
1482   ///
1483   /// \returns true if this base matched the search criteria, false otherwise.
1484   typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1485                                    CXXBasePath &Path,
1486                                    void *UserData);
1487 
1488   /// \brief Look for entities within the base classes of this C++ class,
1489   /// transitively searching all base class subobjects.
1490   ///
1491   /// This routine uses the callback function \p BaseMatches to find base
1492   /// classes meeting some search criteria, walking all base class subobjects
1493   /// and populating the given \p Paths structure with the paths through the
1494   /// inheritance hierarchy that resulted in a match. On a successful search,
1495   /// the \p Paths structure can be queried to retrieve the matching paths and
1496   /// to determine if there were any ambiguities.
1497   ///
1498   /// \param BaseMatches callback function used to determine whether a given
1499   /// base matches the user-defined search criteria.
1500   ///
1501   /// \param UserData user data pointer that will be provided to \p BaseMatches.
1502   ///
1503   /// \param Paths used to record the paths from this class to its base class
1504   /// subobjects that match the search criteria.
1505   ///
1506   /// \returns true if there exists any path from this class to a base class
1507   /// subobject that matches the search criteria.
1508   bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1509                      CXXBasePaths &Paths) const;
1510 
1511   /// \brief Base-class lookup callback that determines whether the given
1512   /// base class specifier refers to a specific class declaration.
1513   ///
1514   /// This callback can be used with \c lookupInBases() to determine whether
1515   /// a given derived class has is a base class subobject of a particular type.
1516   /// The user data pointer should refer to the canonical CXXRecordDecl of the
1517   /// base class that we are searching for.
1518   static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1519                             CXXBasePath &Path, void *BaseRecord);
1520 
1521   /// \brief Base-class lookup callback that determines whether the
1522   /// given base class specifier refers to a specific class
1523   /// declaration and describes virtual derivation.
1524   ///
1525   /// This callback can be used with \c lookupInBases() to determine
1526   /// whether a given derived class has is a virtual base class
1527   /// subobject of a particular type.  The user data pointer should
1528   /// refer to the canonical CXXRecordDecl of the base class that we
1529   /// are searching for.
1530   static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1531                                    CXXBasePath &Path, void *BaseRecord);
1532 
1533   /// \brief Base-class lookup callback that determines whether there exists
1534   /// a tag with the given name.
1535   ///
1536   /// This callback can be used with \c lookupInBases() to find tag members
1537   /// of the given name within a C++ class hierarchy. The user data pointer
1538   /// is an opaque \c DeclarationName pointer.
1539   static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1540                             CXXBasePath &Path, void *Name);
1541 
1542   /// \brief Base-class lookup callback that determines whether there exists
1543   /// a member with the given name.
1544   ///
1545   /// This callback can be used with \c lookupInBases() to find members
1546   /// of the given name within a C++ class hierarchy. The user data pointer
1547   /// is an opaque \c DeclarationName pointer.
1548   static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1549                                  CXXBasePath &Path, void *Name);
1550 
1551   /// \brief Base-class lookup callback that determines whether there exists
1552   /// a member with the given name that can be used in a nested-name-specifier.
1553   ///
1554   /// This callback can be used with \c lookupInBases() to find membes of
1555   /// the given name within a C++ class hierarchy that can occur within
1556   /// nested-name-specifiers.
1557   static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1558                                             CXXBasePath &Path,
1559                                             void *UserData);
1560 
1561   /// \brief Retrieve the final overriders for each virtual member
1562   /// function in the class hierarchy where this class is the
1563   /// most-derived class in the class hierarchy.
1564   void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1565 
1566   /// \brief Get the indirect primary bases for this class.
1567   void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1568 
1569   /// Renders and displays an inheritance diagram
1570   /// for this C++ class and all of its base classes (transitively) using
1571   /// GraphViz.
1572   void viewInheritance(ASTContext& Context) const;
1573 
1574   /// \brief Calculates the access of a decl that is reached
1575   /// along a path.
MergeAccess(AccessSpecifier PathAccess,AccessSpecifier DeclAccess)1576   static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1577                                      AccessSpecifier DeclAccess) {
1578     assert(DeclAccess != AS_none);
1579     if (DeclAccess == AS_private) return AS_none;
1580     return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1581   }
1582 
1583   /// \brief Indicates that the declaration of a defaulted or deleted special
1584   /// member function is now complete.
1585   void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1586 
1587   /// \brief Indicates that the definition of this class is now complete.
1588   void completeDefinition() override;
1589 
1590   /// \brief Indicates that the definition of this class is now complete,
1591   /// and provides a final overrider map to help determine
1592   ///
1593   /// \param FinalOverriders The final overrider map for this class, which can
1594   /// be provided as an optimization for abstract-class checking. If NULL,
1595   /// final overriders will be computed if they are needed to complete the
1596   /// definition.
1597   void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1598 
1599   /// \brief Determine whether this class may end up being abstract, even though
1600   /// it is not yet known to be abstract.
1601   ///
1602   /// \returns true if this class is not known to be abstract but has any
1603   /// base classes that are abstract. In this case, \c completeDefinition()
1604   /// will need to compute final overriders to determine whether the class is
1605   /// actually abstract.
1606   bool mayBeAbstract() const;
1607 
1608   /// \brief If this is the closure type of a lambda expression, retrieve the
1609   /// number to be used for name mangling in the Itanium C++ ABI.
1610   ///
1611   /// Zero indicates that this closure type has internal linkage, so the
1612   /// mangling number does not matter, while a non-zero value indicates which
1613   /// lambda expression this is in this particular context.
getLambdaManglingNumber()1614   unsigned getLambdaManglingNumber() const {
1615     assert(isLambda() && "Not a lambda closure type!");
1616     return getLambdaData().ManglingNumber;
1617   }
1618 
1619   /// \brief Retrieve the declaration that provides additional context for a
1620   /// lambda, when the normal declaration context is not specific enough.
1621   ///
1622   /// Certain contexts (default arguments of in-class function parameters and
1623   /// the initializers of data members) have separate name mangling rules for
1624   /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1625   /// the declaration in which the lambda occurs, e.g., the function parameter
1626   /// or the non-static data member. Otherwise, it returns NULL to imply that
1627   /// the declaration context suffices.
getLambdaContextDecl()1628   Decl *getLambdaContextDecl() const {
1629     assert(isLambda() && "Not a lambda closure type!");
1630     return getLambdaData().ContextDecl;
1631   }
1632 
1633   /// \brief Set the mangling number and context declaration for a lambda
1634   /// class.
setLambdaMangling(unsigned ManglingNumber,Decl * ContextDecl)1635   void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1636     getLambdaData().ManglingNumber = ManglingNumber;
1637     getLambdaData().ContextDecl = ContextDecl;
1638   }
1639 
1640   /// \brief Returns the inheritance model used for this record.
1641   MSInheritanceAttr::Spelling getMSInheritanceModel() const;
1642   /// \brief Calculate what the inheritance model would be for this class.
1643   MSInheritanceAttr::Spelling calculateInheritanceModel() const;
1644 
1645   /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1646   /// member pointer if we can guarantee that zero is not a valid field offset,
1647   /// or if the member pointer has multiple fields.  Polymorphic classes have a
1648   /// vfptr at offset zero, so we can use zero for null.  If there are multiple
1649   /// fields, we can use zero even if it is a valid field offset because
1650   /// null-ness testing will check the other fields.
nullFieldOffsetIsZero()1651   bool nullFieldOffsetIsZero() const {
1652     return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1653                                                getMSInheritanceModel()) ||
1654            (hasDefinition() && isPolymorphic());
1655   }
1656 
1657   /// \brief Controls when vtordisps will be emitted if this record is used as a
1658   /// virtual base.
1659   MSVtorDispAttr::Mode getMSVtorDispMode() const;
1660 
1661   /// \brief Determine whether this lambda expression was known to be dependent
1662   /// at the time it was created, even if its context does not appear to be
1663   /// dependent.
1664   ///
1665   /// This flag is a workaround for an issue with parsing, where default
1666   /// arguments are parsed before their enclosing function declarations have
1667   /// been created. This means that any lambda expressions within those
1668   /// default arguments will have as their DeclContext the context enclosing
1669   /// the function declaration, which may be non-dependent even when the
1670   /// function declaration itself is dependent. This flag indicates when we
1671   /// know that the lambda is dependent despite that.
isDependentLambda()1672   bool isDependentLambda() const {
1673     return isLambda() && getLambdaData().Dependent;
1674   }
1675 
getLambdaTypeInfo()1676   TypeSourceInfo *getLambdaTypeInfo() const {
1677     return getLambdaData().MethodTyInfo;
1678   }
1679 
classof(const Decl * D)1680   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)1681   static bool classofKind(Kind K) {
1682     return K >= firstCXXRecord && K <= lastCXXRecord;
1683   }
1684 
1685   friend class ASTDeclReader;
1686   friend class ASTDeclWriter;
1687   friend class ASTReader;
1688   friend class ASTWriter;
1689 };
1690 
1691 /// \brief Represents a static or instance method of a struct/union/class.
1692 ///
1693 /// In the terminology of the C++ Standard, these are the (static and
1694 /// non-static) member functions, whether virtual or not.
1695 class CXXMethodDecl : public FunctionDecl {
1696   void anchor() override;
1697 protected:
CXXMethodDecl(Kind DK,ASTContext & C,CXXRecordDecl * RD,SourceLocation StartLoc,const DeclarationNameInfo & NameInfo,QualType T,TypeSourceInfo * TInfo,StorageClass SC,bool isInline,bool isConstexpr,SourceLocation EndLocation)1698   CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1699                 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1700                 QualType T, TypeSourceInfo *TInfo,
1701                 StorageClass SC, bool isInline,
1702                 bool isConstexpr, SourceLocation EndLocation)
1703     : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
1704                    SC, isInline, isConstexpr) {
1705     if (EndLocation.isValid())
1706       setRangeEnd(EndLocation);
1707   }
1708 
1709 public:
1710   static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1711                                SourceLocation StartLoc,
1712                                const DeclarationNameInfo &NameInfo,
1713                                QualType T, TypeSourceInfo *TInfo,
1714                                StorageClass SC,
1715                                bool isInline,
1716                                bool isConstexpr,
1717                                SourceLocation EndLocation);
1718 
1719   static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1720 
1721   bool isStatic() const;
isInstance()1722   bool isInstance() const { return !isStatic(); }
1723 
1724   /// Returns true if the given operator is implicitly static in a record
1725   /// context.
isStaticOverloadedOperator(OverloadedOperatorKind OOK)1726   static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1727     // [class.free]p1:
1728     // Any allocation function for a class T is a static member
1729     // (even if not explicitly declared static).
1730     // [class.free]p6 Any deallocation function for a class X is a static member
1731     // (even if not explicitly declared static).
1732     return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1733            OOK == OO_Array_Delete;
1734   }
1735 
isConst()1736   bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
isVolatile()1737   bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1738 
isVirtual()1739   bool isVirtual() const {
1740     CXXMethodDecl *CD =
1741       cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1742 
1743     // Member function is virtual if it is marked explicitly so, or if it is
1744     // declared in __interface -- then it is automatically pure virtual.
1745     if (CD->isVirtualAsWritten() || CD->isPure())
1746       return true;
1747 
1748     return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1749   }
1750 
1751   /// \brief Determine whether this is a usual deallocation function
1752   /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1753   /// delete or delete[] operator with a particular signature.
1754   bool isUsualDeallocationFunction() const;
1755 
1756   /// \brief Determine whether this is a copy-assignment operator, regardless
1757   /// of whether it was declared implicitly or explicitly.
1758   bool isCopyAssignmentOperator() const;
1759 
1760   /// \brief Determine whether this is a move assignment operator.
1761   bool isMoveAssignmentOperator() const;
1762 
getCanonicalDecl()1763   CXXMethodDecl *getCanonicalDecl() override {
1764     return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1765   }
getCanonicalDecl()1766   const CXXMethodDecl *getCanonicalDecl() const override {
1767     return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1768   }
1769 
getMostRecentDecl()1770   CXXMethodDecl *getMostRecentDecl() {
1771     return cast<CXXMethodDecl>(
1772             static_cast<FunctionDecl *>(this)->getMostRecentDecl());
1773   }
getMostRecentDecl()1774   const CXXMethodDecl *getMostRecentDecl() const {
1775     return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
1776   }
1777 
1778   /// True if this method is user-declared and was not
1779   /// deleted or defaulted on its first declaration.
isUserProvided()1780   bool isUserProvided() const {
1781     return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1782   }
1783 
1784   ///
1785   void addOverriddenMethod(const CXXMethodDecl *MD);
1786 
1787   typedef const CXXMethodDecl *const* method_iterator;
1788 
1789   method_iterator begin_overridden_methods() const;
1790   method_iterator end_overridden_methods() const;
1791   unsigned size_overridden_methods() const;
1792 
1793   /// Returns the parent of this method declaration, which
1794   /// is the class in which this method is defined.
getParent()1795   const CXXRecordDecl *getParent() const {
1796     return cast<CXXRecordDecl>(FunctionDecl::getParent());
1797   }
1798 
1799   /// Returns the parent of this method declaration, which
1800   /// is the class in which this method is defined.
getParent()1801   CXXRecordDecl *getParent() {
1802     return const_cast<CXXRecordDecl *>(
1803              cast<CXXRecordDecl>(FunctionDecl::getParent()));
1804   }
1805 
1806   /// \brief Returns the type of the \c this pointer.
1807   ///
1808   /// Should only be called for instance (i.e., non-static) methods.
1809   QualType getThisType(ASTContext &C) const;
1810 
getTypeQualifiers()1811   unsigned getTypeQualifiers() const {
1812     return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1813   }
1814 
1815   /// \brief Retrieve the ref-qualifier associated with this method.
1816   ///
1817   /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1818   /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1819   /// @code
1820   /// struct X {
1821   ///   void f() &;
1822   ///   void g() &&;
1823   ///   void h();
1824   /// };
1825   /// @endcode
getRefQualifier()1826   RefQualifierKind getRefQualifier() const {
1827     return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1828   }
1829 
1830   bool hasInlineBody() const;
1831 
1832   /// \brief Determine whether this is a lambda closure type's static member
1833   /// function that is used for the result of the lambda's conversion to
1834   /// function pointer (for a lambda with no captures).
1835   ///
1836   /// The function itself, if used, will have a placeholder body that will be
1837   /// supplied by IR generation to either forward to the function call operator
1838   /// or clone the function call operator.
1839   bool isLambdaStaticInvoker() const;
1840 
1841   /// \brief Find the method in \p RD that corresponds to this one.
1842   ///
1843   /// Find if \p RD or one of the classes it inherits from override this method.
1844   /// If so, return it. \p RD is assumed to be a subclass of the class defining
1845   /// this method (or be the class itself), unless \p MayBeBase is set to true.
1846   CXXMethodDecl *
1847   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1848                                 bool MayBeBase = false);
1849 
1850   const CXXMethodDecl *
1851   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1852                                 bool MayBeBase = false) const {
1853     return const_cast<CXXMethodDecl *>(this)
1854               ->getCorrespondingMethodInClass(RD, MayBeBase);
1855   }
1856 
1857   // Implement isa/cast/dyncast/etc.
classof(const Decl * D)1858   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)1859   static bool classofKind(Kind K) {
1860     return K >= firstCXXMethod && K <= lastCXXMethod;
1861   }
1862 };
1863 
1864 /// \brief Represents a C++ base or member initializer.
1865 ///
1866 /// This is part of a constructor initializer that
1867 /// initializes one non-static member variable or one base class. For
1868 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1869 /// initializers:
1870 ///
1871 /// \code
1872 /// class A { };
1873 /// class B : public A {
1874 ///   float f;
1875 /// public:
1876 ///   B(A& a) : A(a), f(3.14159) { }
1877 /// };
1878 /// \endcode
1879 class CXXCtorInitializer {
1880   /// \brief Either the base class name/delegating constructor type (stored as
1881   /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1882   /// (IndirectFieldDecl*) being initialized.
1883   llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1884     Initializee;
1885 
1886   /// \brief The source location for the field name or, for a base initializer
1887   /// pack expansion, the location of the ellipsis.
1888   ///
1889   /// In the case of a delegating
1890   /// constructor, it will still include the type's source location as the
1891   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1892   SourceLocation MemberOrEllipsisLocation;
1893 
1894   /// \brief The argument used to initialize the base or member, which may
1895   /// end up constructing an object (when multiple arguments are involved).
1896   Stmt *Init;
1897 
1898   /// \brief Location of the left paren of the ctor-initializer.
1899   SourceLocation LParenLoc;
1900 
1901   /// \brief Location of the right paren of the ctor-initializer.
1902   SourceLocation RParenLoc;
1903 
1904   /// \brief If the initializee is a type, whether that type makes this
1905   /// a delegating initialization.
1906   bool IsDelegating : 1;
1907 
1908   /// \brief If the initializer is a base initializer, this keeps track
1909   /// of whether the base is virtual or not.
1910   bool IsVirtual : 1;
1911 
1912   /// \brief Whether or not the initializer is explicitly written
1913   /// in the sources.
1914   bool IsWritten : 1;
1915 
1916   /// If IsWritten is true, then this number keeps track of the textual order
1917   /// of this initializer in the original sources, counting from 0; otherwise,
1918   /// it stores the number of array index variables stored after this object
1919   /// in memory.
1920   unsigned SourceOrderOrNumArrayIndices : 13;
1921 
1922   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1923                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1924                      SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1925 
1926 public:
1927   /// \brief Creates a new base-class initializer.
1928   explicit
1929   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1930                      SourceLocation L, Expr *Init, SourceLocation R,
1931                      SourceLocation EllipsisLoc);
1932 
1933   /// \brief Creates a new member initializer.
1934   explicit
1935   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1936                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1937                      SourceLocation R);
1938 
1939   /// \brief Creates a new anonymous field initializer.
1940   explicit
1941   CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1942                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1943                      SourceLocation R);
1944 
1945   /// \brief Creates a new delegating initializer.
1946   explicit
1947   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1948                      SourceLocation L, Expr *Init, SourceLocation R);
1949 
1950   /// \brief Creates a new member initializer that optionally contains
1951   /// array indices used to describe an elementwise initialization.
1952   static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1953                                     SourceLocation MemberLoc, SourceLocation L,
1954                                     Expr *Init, SourceLocation R,
1955                                     VarDecl **Indices, unsigned NumIndices);
1956 
1957   /// \brief Determine whether this initializer is initializing a base class.
isBaseInitializer()1958   bool isBaseInitializer() const {
1959     return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1960   }
1961 
1962   /// \brief Determine whether this initializer is initializing a non-static
1963   /// data member.
isMemberInitializer()1964   bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1965 
isAnyMemberInitializer()1966   bool isAnyMemberInitializer() const {
1967     return isMemberInitializer() || isIndirectMemberInitializer();
1968   }
1969 
isIndirectMemberInitializer()1970   bool isIndirectMemberInitializer() const {
1971     return Initializee.is<IndirectFieldDecl*>();
1972   }
1973 
1974   /// \brief Determine whether this initializer is an implicit initializer
1975   /// generated for a field with an initializer defined on the member
1976   /// declaration.
1977   ///
1978   /// In-class member initializers (also known as "non-static data member
1979   /// initializations", NSDMIs) were introduced in C++11.
isInClassMemberInitializer()1980   bool isInClassMemberInitializer() const {
1981     return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
1982   }
1983 
1984   /// \brief Determine whether this initializer is creating a delegating
1985   /// constructor.
isDelegatingInitializer()1986   bool isDelegatingInitializer() const {
1987     return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1988   }
1989 
1990   /// \brief Determine whether this initializer is a pack expansion.
isPackExpansion()1991   bool isPackExpansion() const {
1992     return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1993   }
1994 
1995   // \brief For a pack expansion, returns the location of the ellipsis.
getEllipsisLoc()1996   SourceLocation getEllipsisLoc() const {
1997     assert(isPackExpansion() && "Initializer is not a pack expansion");
1998     return MemberOrEllipsisLocation;
1999   }
2000 
2001   /// If this is a base class initializer, returns the type of the
2002   /// base class with location information. Otherwise, returns an NULL
2003   /// type location.
2004   TypeLoc getBaseClassLoc() const;
2005 
2006   /// If this is a base class initializer, returns the type of the base class.
2007   /// Otherwise, returns null.
2008   const Type *getBaseClass() const;
2009 
2010   /// Returns whether the base is virtual or not.
isBaseVirtual()2011   bool isBaseVirtual() const {
2012     assert(isBaseInitializer() && "Must call this on base initializer!");
2013 
2014     return IsVirtual;
2015   }
2016 
2017   /// \brief Returns the declarator information for a base class or delegating
2018   /// initializer.
getTypeSourceInfo()2019   TypeSourceInfo *getTypeSourceInfo() const {
2020     return Initializee.dyn_cast<TypeSourceInfo *>();
2021   }
2022 
2023   /// \brief If this is a member initializer, returns the declaration of the
2024   /// non-static data member being initialized. Otherwise, returns null.
getMember()2025   FieldDecl *getMember() const {
2026     if (isMemberInitializer())
2027       return Initializee.get<FieldDecl*>();
2028     return nullptr;
2029   }
getAnyMember()2030   FieldDecl *getAnyMember() const {
2031     if (isMemberInitializer())
2032       return Initializee.get<FieldDecl*>();
2033     if (isIndirectMemberInitializer())
2034       return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2035     return nullptr;
2036   }
2037 
getIndirectMember()2038   IndirectFieldDecl *getIndirectMember() const {
2039     if (isIndirectMemberInitializer())
2040       return Initializee.get<IndirectFieldDecl*>();
2041     return nullptr;
2042   }
2043 
getMemberLocation()2044   SourceLocation getMemberLocation() const {
2045     return MemberOrEllipsisLocation;
2046   }
2047 
2048   /// \brief Determine the source location of the initializer.
2049   SourceLocation getSourceLocation() const;
2050 
2051   /// \brief Determine the source range covering the entire initializer.
2052   SourceRange getSourceRange() const LLVM_READONLY;
2053 
2054   /// \brief Determine whether this initializer is explicitly written
2055   /// in the source code.
isWritten()2056   bool isWritten() const { return IsWritten; }
2057 
2058   /// \brief Return the source position of the initializer, counting from 0.
2059   /// If the initializer was implicit, -1 is returned.
getSourceOrder()2060   int getSourceOrder() const {
2061     return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
2062   }
2063 
2064   /// \brief Set the source order of this initializer.
2065   ///
2066   /// This can only be called once for each initializer; it cannot be called
2067   /// on an initializer having a positive number of (implicit) array indices.
2068   ///
2069   /// This assumes that the initialzier was written in the source code, and
2070   /// ensures that isWritten() returns true.
setSourceOrder(int pos)2071   void setSourceOrder(int pos) {
2072     assert(!IsWritten &&
2073            "calling twice setSourceOrder() on the same initializer");
2074     assert(SourceOrderOrNumArrayIndices == 0 &&
2075            "setSourceOrder() used when there are implicit array indices");
2076     assert(pos >= 0 &&
2077            "setSourceOrder() used to make an initializer implicit");
2078     IsWritten = true;
2079     SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
2080   }
2081 
getLParenLoc()2082   SourceLocation getLParenLoc() const { return LParenLoc; }
getRParenLoc()2083   SourceLocation getRParenLoc() const { return RParenLoc; }
2084 
2085   /// \brief Determine the number of implicit array indices used while
2086   /// described an array member initialization.
getNumArrayIndices()2087   unsigned getNumArrayIndices() const {
2088     return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
2089   }
2090 
2091   /// \brief Retrieve a particular array index variable used to
2092   /// describe an array member initialization.
getArrayIndex(unsigned I)2093   VarDecl *getArrayIndex(unsigned I) {
2094     assert(I < getNumArrayIndices() && "Out of bounds member array index");
2095     return reinterpret_cast<VarDecl **>(this + 1)[I];
2096   }
getArrayIndex(unsigned I)2097   const VarDecl *getArrayIndex(unsigned I) const {
2098     assert(I < getNumArrayIndices() && "Out of bounds member array index");
2099     return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
2100   }
setArrayIndex(unsigned I,VarDecl * Index)2101   void setArrayIndex(unsigned I, VarDecl *Index) {
2102     assert(I < getNumArrayIndices() && "Out of bounds member array index");
2103     reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
2104   }
getArrayIndexes()2105   ArrayRef<VarDecl *> getArrayIndexes() {
2106     assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
2107     return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
2108                                getNumArrayIndices());
2109   }
2110 
2111   /// \brief Get the initializer.
getInit()2112   Expr *getInit() const { return static_cast<Expr*>(Init); }
2113 };
2114 
2115 /// \brief Represents a C++ constructor within a class.
2116 ///
2117 /// For example:
2118 ///
2119 /// \code
2120 /// class X {
2121 /// public:
2122 ///   explicit X(int); // represented by a CXXConstructorDecl.
2123 /// };
2124 /// \endcode
2125 class CXXConstructorDecl : public CXXMethodDecl {
2126   void anchor() override;
2127   /// \brief Whether this constructor declaration has the \c explicit keyword
2128   /// specified.
2129   bool IsExplicitSpecified : 1;
2130 
2131   /// \name Support for base and member initializers.
2132   /// \{
2133   /// \brief The arguments used to initialize the base or member.
2134   CXXCtorInitializer **CtorInitializers;
2135   unsigned NumCtorInitializers;
2136   /// \}
2137 
CXXConstructorDecl(ASTContext & C,CXXRecordDecl * RD,SourceLocation StartLoc,const DeclarationNameInfo & NameInfo,QualType T,TypeSourceInfo * TInfo,bool isExplicitSpecified,bool isInline,bool isImplicitlyDeclared,bool isConstexpr)2138   CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2139                      const DeclarationNameInfo &NameInfo,
2140                      QualType T, TypeSourceInfo *TInfo,
2141                      bool isExplicitSpecified, bool isInline,
2142                      bool isImplicitlyDeclared, bool isConstexpr)
2143     : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2144                     SC_None, isInline, isConstexpr, SourceLocation()),
2145       IsExplicitSpecified(isExplicitSpecified), CtorInitializers(nullptr),
2146       NumCtorInitializers(0) {
2147     setImplicit(isImplicitlyDeclared);
2148   }
2149 
2150 public:
2151   static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2152   static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2153                                     SourceLocation StartLoc,
2154                                     const DeclarationNameInfo &NameInfo,
2155                                     QualType T, TypeSourceInfo *TInfo,
2156                                     bool isExplicit,
2157                                     bool isInline, bool isImplicitlyDeclared,
2158                                     bool isConstexpr);
2159 
2160   /// \brief Determine whether this constructor declaration has the
2161   /// \c explicit keyword specified.
isExplicitSpecified()2162   bool isExplicitSpecified() const { return IsExplicitSpecified; }
2163 
2164   /// \brief Determine whether this constructor was marked "explicit" or not.
isExplicit()2165   bool isExplicit() const {
2166     return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
2167   }
2168 
2169   /// \brief Iterates through the member/base initializer list.
2170   typedef CXXCtorInitializer **init_iterator;
2171 
2172   /// \brief Iterates through the member/base initializer list.
2173   typedef CXXCtorInitializer * const * init_const_iterator;
2174 
2175   typedef llvm::iterator_range<init_iterator> init_range;
2176   typedef llvm::iterator_range<init_const_iterator> init_const_range;
2177 
inits()2178   init_range inits() { return init_range(init_begin(), init_end()); }
inits()2179   init_const_range inits() const {
2180     return init_const_range(init_begin(), init_end());
2181   }
2182 
2183   /// \brief Retrieve an iterator to the first initializer.
init_begin()2184   init_iterator       init_begin()       { return CtorInitializers; }
2185   /// \brief Retrieve an iterator to the first initializer.
init_begin()2186   init_const_iterator init_begin() const { return CtorInitializers; }
2187 
2188   /// \brief Retrieve an iterator past the last initializer.
init_end()2189   init_iterator       init_end()       {
2190     return CtorInitializers + NumCtorInitializers;
2191   }
2192   /// \brief Retrieve an iterator past the last initializer.
init_end()2193   init_const_iterator init_end() const {
2194     return CtorInitializers + NumCtorInitializers;
2195   }
2196 
2197   typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2198   typedef std::reverse_iterator<init_const_iterator>
2199           init_const_reverse_iterator;
2200 
init_rbegin()2201   init_reverse_iterator init_rbegin() {
2202     return init_reverse_iterator(init_end());
2203   }
init_rbegin()2204   init_const_reverse_iterator init_rbegin() const {
2205     return init_const_reverse_iterator(init_end());
2206   }
2207 
init_rend()2208   init_reverse_iterator init_rend() {
2209     return init_reverse_iterator(init_begin());
2210   }
init_rend()2211   init_const_reverse_iterator init_rend() const {
2212     return init_const_reverse_iterator(init_begin());
2213   }
2214 
2215   /// \brief Determine the number of arguments used to initialize the member
2216   /// or base.
getNumCtorInitializers()2217   unsigned getNumCtorInitializers() const {
2218       return NumCtorInitializers;
2219   }
2220 
setNumCtorInitializers(unsigned numCtorInitializers)2221   void setNumCtorInitializers(unsigned numCtorInitializers) {
2222     NumCtorInitializers = numCtorInitializers;
2223   }
2224 
setCtorInitializers(CXXCtorInitializer ** initializers)2225   void setCtorInitializers(CXXCtorInitializer ** initializers) {
2226     CtorInitializers = initializers;
2227   }
2228 
2229   /// \brief Determine whether this constructor is a delegating constructor.
isDelegatingConstructor()2230   bool isDelegatingConstructor() const {
2231     return (getNumCtorInitializers() == 1) &&
2232       CtorInitializers[0]->isDelegatingInitializer();
2233   }
2234 
2235   /// \brief When this constructor delegates to another, retrieve the target.
2236   CXXConstructorDecl *getTargetConstructor() const;
2237 
2238   /// Whether this constructor is a default
2239   /// constructor (C++ [class.ctor]p5), which can be used to
2240   /// default-initialize a class of this type.
2241   bool isDefaultConstructor() const;
2242 
2243   /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2244   /// which can be used to copy the class.
2245   ///
2246   /// \p TypeQuals will be set to the qualifiers on the
2247   /// argument type. For example, \p TypeQuals would be set to \c
2248   /// Qualifiers::Const for the following copy constructor:
2249   ///
2250   /// \code
2251   /// class X {
2252   /// public:
2253   ///   X(const X&);
2254   /// };
2255   /// \endcode
2256   bool isCopyConstructor(unsigned &TypeQuals) const;
2257 
2258   /// Whether this constructor is a copy
2259   /// constructor (C++ [class.copy]p2, which can be used to copy the
2260   /// class.
isCopyConstructor()2261   bool isCopyConstructor() const {
2262     unsigned TypeQuals = 0;
2263     return isCopyConstructor(TypeQuals);
2264   }
2265 
2266   /// \brief Determine whether this constructor is a move constructor
2267   /// (C++0x [class.copy]p3), which can be used to move values of the class.
2268   ///
2269   /// \param TypeQuals If this constructor is a move constructor, will be set
2270   /// to the type qualifiers on the referent of the first parameter's type.
2271   bool isMoveConstructor(unsigned &TypeQuals) const;
2272 
2273   /// \brief Determine whether this constructor is a move constructor
2274   /// (C++0x [class.copy]p3), which can be used to move values of the class.
isMoveConstructor()2275   bool isMoveConstructor() const {
2276     unsigned TypeQuals = 0;
2277     return isMoveConstructor(TypeQuals);
2278   }
2279 
2280   /// \brief Determine whether this is a copy or move constructor.
2281   ///
2282   /// \param TypeQuals Will be set to the type qualifiers on the reference
2283   /// parameter, if in fact this is a copy or move constructor.
2284   bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2285 
2286   /// \brief Determine whether this a copy or move constructor.
isCopyOrMoveConstructor()2287   bool isCopyOrMoveConstructor() const {
2288     unsigned Quals;
2289     return isCopyOrMoveConstructor(Quals);
2290   }
2291 
2292   /// Whether this constructor is a
2293   /// converting constructor (C++ [class.conv.ctor]), which can be
2294   /// used for user-defined conversions.
2295   bool isConvertingConstructor(bool AllowExplicit) const;
2296 
2297   /// \brief Determine whether this is a member template specialization that
2298   /// would copy the object to itself. Such constructors are never used to copy
2299   /// an object.
2300   bool isSpecializationCopyingObject() const;
2301 
2302   /// \brief Get the constructor that this inheriting constructor is based on.
2303   const CXXConstructorDecl *getInheritedConstructor() const;
2304 
2305   /// \brief Set the constructor that this inheriting constructor is based on.
2306   void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2307 
getCanonicalDecl()2308   const CXXConstructorDecl *getCanonicalDecl() const override {
2309     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2310   }
getCanonicalDecl()2311   CXXConstructorDecl *getCanonicalDecl() override {
2312     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2313   }
2314 
2315   // Implement isa/cast/dyncast/etc.
classof(const Decl * D)2316   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2317   static bool classofKind(Kind K) { return K == CXXConstructor; }
2318 
2319   friend class ASTDeclReader;
2320   friend class ASTDeclWriter;
2321 };
2322 
2323 /// \brief Represents a C++ destructor within a class.
2324 ///
2325 /// For example:
2326 ///
2327 /// \code
2328 /// class X {
2329 /// public:
2330 ///   ~X(); // represented by a CXXDestructorDecl.
2331 /// };
2332 /// \endcode
2333 class CXXDestructorDecl : public CXXMethodDecl {
2334   void anchor() override;
2335 
2336   FunctionDecl *OperatorDelete;
2337 
CXXDestructorDecl(ASTContext & C,CXXRecordDecl * RD,SourceLocation StartLoc,const DeclarationNameInfo & NameInfo,QualType T,TypeSourceInfo * TInfo,bool isInline,bool isImplicitlyDeclared)2338   CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2339                     const DeclarationNameInfo &NameInfo,
2340                     QualType T, TypeSourceInfo *TInfo,
2341                     bool isInline, bool isImplicitlyDeclared)
2342     : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2343                     SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2344       OperatorDelete(nullptr) {
2345     setImplicit(isImplicitlyDeclared);
2346   }
2347 
2348 public:
2349   static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2350                                    SourceLocation StartLoc,
2351                                    const DeclarationNameInfo &NameInfo,
2352                                    QualType T, TypeSourceInfo* TInfo,
2353                                    bool isInline,
2354                                    bool isImplicitlyDeclared);
2355   static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2356 
setOperatorDelete(FunctionDecl * OD)2357   void setOperatorDelete(FunctionDecl *OD) {
2358     cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete = OD;
2359   }
getOperatorDelete()2360   const FunctionDecl *getOperatorDelete() const {
2361     return cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete;
2362   }
2363 
2364   // Implement isa/cast/dyncast/etc.
classof(const Decl * D)2365   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2366   static bool classofKind(Kind K) { return K == CXXDestructor; }
2367 
2368   friend class ASTDeclReader;
2369   friend class ASTDeclWriter;
2370 };
2371 
2372 /// \brief Represents a C++ conversion function within a class.
2373 ///
2374 /// For example:
2375 ///
2376 /// \code
2377 /// class X {
2378 /// public:
2379 ///   operator bool();
2380 /// };
2381 /// \endcode
2382 class CXXConversionDecl : public CXXMethodDecl {
2383   void anchor() override;
2384   /// Whether this conversion function declaration is marked
2385   /// "explicit", meaning that it can only be applied when the user
2386   /// explicitly wrote a cast. This is a C++0x feature.
2387   bool IsExplicitSpecified : 1;
2388 
CXXConversionDecl(ASTContext & C,CXXRecordDecl * RD,SourceLocation StartLoc,const DeclarationNameInfo & NameInfo,QualType T,TypeSourceInfo * TInfo,bool isInline,bool isExplicitSpecified,bool isConstexpr,SourceLocation EndLocation)2389   CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2390                     const DeclarationNameInfo &NameInfo,
2391                     QualType T, TypeSourceInfo *TInfo,
2392                     bool isInline, bool isExplicitSpecified,
2393                     bool isConstexpr, SourceLocation EndLocation)
2394     : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2395                     SC_None, isInline, isConstexpr, EndLocation),
2396       IsExplicitSpecified(isExplicitSpecified) { }
2397 
2398 public:
2399   static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2400                                    SourceLocation StartLoc,
2401                                    const DeclarationNameInfo &NameInfo,
2402                                    QualType T, TypeSourceInfo *TInfo,
2403                                    bool isInline, bool isExplicit,
2404                                    bool isConstexpr,
2405                                    SourceLocation EndLocation);
2406   static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2407 
2408   /// Whether this conversion function declaration is marked
2409   /// "explicit", meaning that it can only be used for direct initialization
2410   /// (including explitly written casts).  This is a C++11 feature.
isExplicitSpecified()2411   bool isExplicitSpecified() const { return IsExplicitSpecified; }
2412 
2413   /// \brief Whether this is an explicit conversion operator (C++11 and later).
2414   ///
2415   /// Explicit conversion operators are only considered for direct
2416   /// initialization, e.g., when the user has explicitly written a cast.
isExplicit()2417   bool isExplicit() const {
2418     return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
2419   }
2420 
2421   /// \brief Returns the type that this conversion function is converting to.
getConversionType()2422   QualType getConversionType() const {
2423     return getType()->getAs<FunctionType>()->getReturnType();
2424   }
2425 
2426   /// \brief Determine whether this conversion function is a conversion from
2427   /// a lambda closure type to a block pointer.
2428   bool isLambdaToBlockPointerConversion() const;
2429 
2430   // Implement isa/cast/dyncast/etc.
classof(const Decl * D)2431   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2432   static bool classofKind(Kind K) { return K == CXXConversion; }
2433 
2434   friend class ASTDeclReader;
2435   friend class ASTDeclWriter;
2436 };
2437 
2438 /// \brief Represents a linkage specification.
2439 ///
2440 /// For example:
2441 /// \code
2442 ///   extern "C" void foo();
2443 /// \endcode
2444 class LinkageSpecDecl : public Decl, public DeclContext {
2445   virtual void anchor();
2446 public:
2447   /// \brief Represents the language in a linkage specification.
2448   ///
2449   /// The values are part of the serialization ABI for
2450   /// ASTs and cannot be changed without altering that ABI.  To help
2451   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2452   /// from the dwarf standard.
2453   enum LanguageIDs {
2454     lang_c = /* DW_LANG_C */ 0x0002,
2455     lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2456   };
2457 private:
2458   /// \brief The language for this linkage specification.
2459   unsigned Language : 3;
2460   /// \brief True if this linkage spec has braces.
2461   ///
2462   /// This is needed so that hasBraces() returns the correct result while the
2463   /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
2464   /// not used, so it doesn't need to be serialized.
2465   unsigned HasBraces : 1;
2466   /// \brief The source location for the extern keyword.
2467   SourceLocation ExternLoc;
2468   /// \brief The source location for the right brace (if valid).
2469   SourceLocation RBraceLoc;
2470 
LinkageSpecDecl(DeclContext * DC,SourceLocation ExternLoc,SourceLocation LangLoc,LanguageIDs lang,bool HasBraces)2471   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2472                   SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2473     : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2474       Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2475       RBraceLoc(SourceLocation()) { }
2476 
2477 public:
2478   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2479                                  SourceLocation ExternLoc,
2480                                  SourceLocation LangLoc, LanguageIDs Lang,
2481                                  bool HasBraces);
2482   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2483 
2484   /// \brief Return the language specified by this linkage specification.
getLanguage()2485   LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2486   /// \brief Set the language specified by this linkage specification.
setLanguage(LanguageIDs L)2487   void setLanguage(LanguageIDs L) { Language = L; }
2488 
2489   /// \brief Determines whether this linkage specification had braces in
2490   /// its syntactic form.
hasBraces()2491   bool hasBraces() const {
2492     assert(!RBraceLoc.isValid() || HasBraces);
2493     return HasBraces;
2494   }
2495 
getExternLoc()2496   SourceLocation getExternLoc() const { return ExternLoc; }
getRBraceLoc()2497   SourceLocation getRBraceLoc() const { return RBraceLoc; }
setExternLoc(SourceLocation L)2498   void setExternLoc(SourceLocation L) { ExternLoc = L; }
setRBraceLoc(SourceLocation L)2499   void setRBraceLoc(SourceLocation L) {
2500     RBraceLoc = L;
2501     HasBraces = RBraceLoc.isValid();
2502   }
2503 
getLocEnd()2504   SourceLocation getLocEnd() const LLVM_READONLY {
2505     if (hasBraces())
2506       return getRBraceLoc();
2507     // No braces: get the end location of the (only) declaration in context
2508     // (if present).
2509     return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2510   }
2511 
getSourceRange()2512   SourceRange getSourceRange() const override LLVM_READONLY {
2513     return SourceRange(ExternLoc, getLocEnd());
2514   }
2515 
classof(const Decl * D)2516   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2517   static bool classofKind(Kind K) { return K == LinkageSpec; }
castToDeclContext(const LinkageSpecDecl * D)2518   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2519     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2520   }
castFromDeclContext(const DeclContext * DC)2521   static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2522     return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2523   }
2524 };
2525 
2526 /// \brief Represents C++ using-directive.
2527 ///
2528 /// For example:
2529 /// \code
2530 ///    using namespace std;
2531 /// \endcode
2532 ///
2533 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2534 /// artificial names for all using-directives in order to store
2535 /// them in DeclContext effectively.
2536 class UsingDirectiveDecl : public NamedDecl {
2537   void anchor() override;
2538   /// \brief The location of the \c using keyword.
2539   SourceLocation UsingLoc;
2540 
2541   /// \brief The location of the \c namespace keyword.
2542   SourceLocation NamespaceLoc;
2543 
2544   /// \brief The nested-name-specifier that precedes the namespace.
2545   NestedNameSpecifierLoc QualifierLoc;
2546 
2547   /// \brief The namespace nominated by this using-directive.
2548   NamedDecl *NominatedNamespace;
2549 
2550   /// Enclosing context containing both using-directive and nominated
2551   /// namespace.
2552   DeclContext *CommonAncestor;
2553 
2554   /// \brief Returns special DeclarationName used by using-directives.
2555   ///
2556   /// This is only used by DeclContext for storing UsingDirectiveDecls in
2557   /// its lookup structure.
getName()2558   static DeclarationName getName() {
2559     return DeclarationName::getUsingDirectiveName();
2560   }
2561 
UsingDirectiveDecl(DeclContext * DC,SourceLocation UsingLoc,SourceLocation NamespcLoc,NestedNameSpecifierLoc QualifierLoc,SourceLocation IdentLoc,NamedDecl * Nominated,DeclContext * CommonAncestor)2562   UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2563                      SourceLocation NamespcLoc,
2564                      NestedNameSpecifierLoc QualifierLoc,
2565                      SourceLocation IdentLoc,
2566                      NamedDecl *Nominated,
2567                      DeclContext *CommonAncestor)
2568     : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2569       NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2570       NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2571 
2572 public:
2573   /// \brief Retrieve the nested-name-specifier that qualifies the
2574   /// name of the namespace, with source-location information.
getQualifierLoc()2575   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2576 
2577   /// \brief Retrieve the nested-name-specifier that qualifies the
2578   /// name of the namespace.
getQualifier()2579   NestedNameSpecifier *getQualifier() const {
2580     return QualifierLoc.getNestedNameSpecifier();
2581   }
2582 
getNominatedNamespaceAsWritten()2583   NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
getNominatedNamespaceAsWritten()2584   const NamedDecl *getNominatedNamespaceAsWritten() const {
2585     return NominatedNamespace;
2586   }
2587 
2588   /// \brief Returns the namespace nominated by this using-directive.
2589   NamespaceDecl *getNominatedNamespace();
2590 
getNominatedNamespace()2591   const NamespaceDecl *getNominatedNamespace() const {
2592     return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2593   }
2594 
2595   /// \brief Returns the common ancestor context of this using-directive and
2596   /// its nominated namespace.
getCommonAncestor()2597   DeclContext *getCommonAncestor() { return CommonAncestor; }
getCommonAncestor()2598   const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2599 
2600   /// \brief Return the location of the \c using keyword.
getUsingLoc()2601   SourceLocation getUsingLoc() const { return UsingLoc; }
2602 
2603   // FIXME: Could omit 'Key' in name.
2604   /// \brief Returns the location of the \c namespace keyword.
getNamespaceKeyLocation()2605   SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2606 
2607   /// \brief Returns the location of this using declaration's identifier.
getIdentLocation()2608   SourceLocation getIdentLocation() const { return getLocation(); }
2609 
2610   static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2611                                     SourceLocation UsingLoc,
2612                                     SourceLocation NamespaceLoc,
2613                                     NestedNameSpecifierLoc QualifierLoc,
2614                                     SourceLocation IdentLoc,
2615                                     NamedDecl *Nominated,
2616                                     DeclContext *CommonAncestor);
2617   static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2618 
getSourceRange()2619   SourceRange getSourceRange() const override LLVM_READONLY {
2620     return SourceRange(UsingLoc, getLocation());
2621   }
2622 
classof(const Decl * D)2623   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2624   static bool classofKind(Kind K) { return K == UsingDirective; }
2625 
2626   // Friend for getUsingDirectiveName.
2627   friend class DeclContext;
2628 
2629   friend class ASTDeclReader;
2630 };
2631 
2632 /// \brief Represents a C++ namespace alias.
2633 ///
2634 /// For example:
2635 ///
2636 /// \code
2637 /// namespace Foo = Bar;
2638 /// \endcode
2639 class NamespaceAliasDecl : public NamedDecl {
2640   void anchor() override;
2641 
2642   /// \brief The location of the \c namespace keyword.
2643   SourceLocation NamespaceLoc;
2644 
2645   /// \brief The location of the namespace's identifier.
2646   ///
2647   /// This is accessed by TargetNameLoc.
2648   SourceLocation IdentLoc;
2649 
2650   /// \brief The nested-name-specifier that precedes the namespace.
2651   NestedNameSpecifierLoc QualifierLoc;
2652 
2653   /// \brief The Decl that this alias points to, either a NamespaceDecl or
2654   /// a NamespaceAliasDecl.
2655   NamedDecl *Namespace;
2656 
NamespaceAliasDecl(DeclContext * DC,SourceLocation NamespaceLoc,SourceLocation AliasLoc,IdentifierInfo * Alias,NestedNameSpecifierLoc QualifierLoc,SourceLocation IdentLoc,NamedDecl * Namespace)2657   NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2658                      SourceLocation AliasLoc, IdentifierInfo *Alias,
2659                      NestedNameSpecifierLoc QualifierLoc,
2660                      SourceLocation IdentLoc, NamedDecl *Namespace)
2661     : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2662       NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2663       QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2664 
2665   friend class ASTDeclReader;
2666 
2667 public:
2668   /// \brief Retrieve the nested-name-specifier that qualifies the
2669   /// name of the namespace, with source-location information.
getQualifierLoc()2670   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2671 
2672   /// \brief Retrieve the nested-name-specifier that qualifies the
2673   /// name of the namespace.
getQualifier()2674   NestedNameSpecifier *getQualifier() const {
2675     return QualifierLoc.getNestedNameSpecifier();
2676   }
2677 
2678   /// \brief Retrieve the namespace declaration aliased by this directive.
getNamespace()2679   NamespaceDecl *getNamespace() {
2680     if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2681       return AD->getNamespace();
2682 
2683     return cast<NamespaceDecl>(Namespace);
2684   }
2685 
getNamespace()2686   const NamespaceDecl *getNamespace() const {
2687     return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2688   }
2689 
2690   /// Returns the location of the alias name, i.e. 'foo' in
2691   /// "namespace foo = ns::bar;".
getAliasLoc()2692   SourceLocation getAliasLoc() const { return getLocation(); }
2693 
2694   /// Returns the location of the \c namespace keyword.
getNamespaceLoc()2695   SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2696 
2697   /// Returns the location of the identifier in the named namespace.
getTargetNameLoc()2698   SourceLocation getTargetNameLoc() const { return IdentLoc; }
2699 
2700   /// \brief Retrieve the namespace that this alias refers to, which
2701   /// may either be a NamespaceDecl or a NamespaceAliasDecl.
getAliasedNamespace()2702   NamedDecl *getAliasedNamespace() const { return Namespace; }
2703 
2704   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2705                                     SourceLocation NamespaceLoc,
2706                                     SourceLocation AliasLoc,
2707                                     IdentifierInfo *Alias,
2708                                     NestedNameSpecifierLoc QualifierLoc,
2709                                     SourceLocation IdentLoc,
2710                                     NamedDecl *Namespace);
2711 
2712   static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2713 
getSourceRange()2714   SourceRange getSourceRange() const override LLVM_READONLY {
2715     return SourceRange(NamespaceLoc, IdentLoc);
2716   }
2717 
classof(const Decl * D)2718   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2719   static bool classofKind(Kind K) { return K == NamespaceAlias; }
2720 };
2721 
2722 /// \brief Represents a shadow declaration introduced into a scope by a
2723 /// (resolved) using declaration.
2724 ///
2725 /// For example,
2726 /// \code
2727 /// namespace A {
2728 ///   void foo();
2729 /// }
2730 /// namespace B {
2731 ///   using A::foo; // <- a UsingDecl
2732 ///                 // Also creates a UsingShadowDecl for A::foo() in B
2733 /// }
2734 /// \endcode
2735 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
2736   void anchor() override;
2737 
2738   /// The referenced declaration.
2739   NamedDecl *Underlying;
2740 
2741   /// \brief The using declaration which introduced this decl or the next using
2742   /// shadow declaration contained in the aforementioned using declaration.
2743   NamedDecl *UsingOrNextShadow;
2744   friend class UsingDecl;
2745 
UsingShadowDecl(ASTContext & C,DeclContext * DC,SourceLocation Loc,UsingDecl * Using,NamedDecl * Target)2746   UsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
2747                   UsingDecl *Using, NamedDecl *Target)
2748     : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2749       redeclarable_base(C), Underlying(Target),
2750       UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2751     if (Target) {
2752       setDeclName(Target->getDeclName());
2753       IdentifierNamespace = Target->getIdentifierNamespace();
2754     }
2755     setImplicit();
2756   }
2757 
2758   typedef Redeclarable<UsingShadowDecl> redeclarable_base;
getNextRedeclarationImpl()2759   UsingShadowDecl *getNextRedeclarationImpl() override {
2760     return getNextRedeclaration();
2761   }
getPreviousDeclImpl()2762   UsingShadowDecl *getPreviousDeclImpl() override {
2763     return getPreviousDecl();
2764   }
getMostRecentDeclImpl()2765   UsingShadowDecl *getMostRecentDeclImpl() override {
2766     return getMostRecentDecl();
2767   }
2768 
2769 public:
Create(ASTContext & C,DeclContext * DC,SourceLocation Loc,UsingDecl * Using,NamedDecl * Target)2770   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2771                                  SourceLocation Loc, UsingDecl *Using,
2772                                  NamedDecl *Target) {
2773     return new (C, DC) UsingShadowDecl(C, DC, Loc, Using, Target);
2774   }
2775 
2776   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2777 
2778   typedef redeclarable_base::redecl_range redecl_range;
2779   typedef redeclarable_base::redecl_iterator redecl_iterator;
2780   using redeclarable_base::redecls_begin;
2781   using redeclarable_base::redecls_end;
2782   using redeclarable_base::redecls;
2783   using redeclarable_base::getPreviousDecl;
2784   using redeclarable_base::getMostRecentDecl;
2785 
getCanonicalDecl()2786   UsingShadowDecl *getCanonicalDecl() override {
2787     return getFirstDecl();
2788   }
getCanonicalDecl()2789   const UsingShadowDecl *getCanonicalDecl() const {
2790     return getFirstDecl();
2791   }
2792 
2793   /// \brief Gets the underlying declaration which has been brought into the
2794   /// local scope.
getTargetDecl()2795   NamedDecl *getTargetDecl() const { return Underlying; }
2796 
2797   /// \brief Sets the underlying declaration which has been brought into the
2798   /// local scope.
setTargetDecl(NamedDecl * ND)2799   void setTargetDecl(NamedDecl* ND) {
2800     assert(ND && "Target decl is null!");
2801     Underlying = ND;
2802     IdentifierNamespace = ND->getIdentifierNamespace();
2803   }
2804 
2805   /// \brief Gets the using declaration to which this declaration is tied.
2806   UsingDecl *getUsingDecl() const;
2807 
2808   /// \brief The next using shadow declaration contained in the shadow decl
2809   /// chain of the using declaration which introduced this decl.
getNextUsingShadowDecl()2810   UsingShadowDecl *getNextUsingShadowDecl() const {
2811     return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2812   }
2813 
classof(const Decl * D)2814   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2815   static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2816 
2817   friend class ASTDeclReader;
2818   friend class ASTDeclWriter;
2819 };
2820 
2821 /// \brief Represents a C++ using-declaration.
2822 ///
2823 /// For example:
2824 /// \code
2825 ///    using someNameSpace::someIdentifier;
2826 /// \endcode
2827 class UsingDecl : public NamedDecl {
2828   void anchor() override;
2829 
2830   /// \brief The source location of the 'using' keyword itself.
2831   SourceLocation UsingLocation;
2832 
2833   /// \brief The nested-name-specifier that precedes the name.
2834   NestedNameSpecifierLoc QualifierLoc;
2835 
2836   /// \brief Provides source/type location info for the declaration name
2837   /// embedded in the ValueDecl base class.
2838   DeclarationNameLoc DNLoc;
2839 
2840   /// \brief The first shadow declaration of the shadow decl chain associated
2841   /// with this using declaration.
2842   ///
2843   /// The bool member of the pair store whether this decl has the \c typename
2844   /// keyword.
2845   llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2846 
UsingDecl(DeclContext * DC,SourceLocation UL,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,bool HasTypenameKeyword)2847   UsingDecl(DeclContext *DC, SourceLocation UL,
2848             NestedNameSpecifierLoc QualifierLoc,
2849             const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
2850     : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2851       UsingLocation(UL), QualifierLoc(QualifierLoc),
2852       DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
2853   }
2854 
2855 public:
2856   /// \brief Return the source location of the 'using' keyword.
getUsingLoc()2857   SourceLocation getUsingLoc() const { return UsingLocation; }
2858 
2859   /// \brief Set the source location of the 'using' keyword.
setUsingLoc(SourceLocation L)2860   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2861 
2862   /// \brief Retrieve the nested-name-specifier that qualifies the name,
2863   /// with source-location information.
getQualifierLoc()2864   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2865 
2866   /// \brief Retrieve the nested-name-specifier that qualifies the name.
getQualifier()2867   NestedNameSpecifier *getQualifier() const {
2868     return QualifierLoc.getNestedNameSpecifier();
2869   }
2870 
getNameInfo()2871   DeclarationNameInfo getNameInfo() const {
2872     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2873   }
2874 
2875   /// \brief Return true if it is a C++03 access declaration (no 'using').
isAccessDeclaration()2876   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2877 
2878   /// \brief Return true if the using declaration has 'typename'.
hasTypename()2879   bool hasTypename() const { return FirstUsingShadow.getInt(); }
2880 
2881   /// \brief Sets whether the using declaration has 'typename'.
setTypename(bool TN)2882   void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
2883 
2884   /// \brief Iterates through the using shadow declarations associated with
2885   /// this using declaration.
2886   class shadow_iterator {
2887     /// \brief The current using shadow declaration.
2888     UsingShadowDecl *Current;
2889 
2890   public:
2891     typedef UsingShadowDecl*          value_type;
2892     typedef UsingShadowDecl*          reference;
2893     typedef UsingShadowDecl*          pointer;
2894     typedef std::forward_iterator_tag iterator_category;
2895     typedef std::ptrdiff_t            difference_type;
2896 
shadow_iterator()2897     shadow_iterator() : Current(nullptr) { }
shadow_iterator(UsingShadowDecl * C)2898     explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2899 
2900     reference operator*() const { return Current; }
2901     pointer operator->() const { return Current; }
2902 
2903     shadow_iterator& operator++() {
2904       Current = Current->getNextUsingShadowDecl();
2905       return *this;
2906     }
2907 
2908     shadow_iterator operator++(int) {
2909       shadow_iterator tmp(*this);
2910       ++(*this);
2911       return tmp;
2912     }
2913 
2914     friend bool operator==(shadow_iterator x, shadow_iterator y) {
2915       return x.Current == y.Current;
2916     }
2917     friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2918       return x.Current != y.Current;
2919     }
2920   };
2921 
2922   typedef llvm::iterator_range<shadow_iterator> shadow_range;
2923 
shadows()2924   shadow_range shadows() const {
2925     return shadow_range(shadow_begin(), shadow_end());
2926   }
shadow_begin()2927   shadow_iterator shadow_begin() const {
2928     return shadow_iterator(FirstUsingShadow.getPointer());
2929   }
shadow_end()2930   shadow_iterator shadow_end() const { return shadow_iterator(); }
2931 
2932   /// \brief Return the number of shadowed declarations associated with this
2933   /// using declaration.
shadow_size()2934   unsigned shadow_size() const {
2935     return std::distance(shadow_begin(), shadow_end());
2936   }
2937 
2938   void addShadowDecl(UsingShadowDecl *S);
2939   void removeShadowDecl(UsingShadowDecl *S);
2940 
2941   static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2942                            SourceLocation UsingL,
2943                            NestedNameSpecifierLoc QualifierLoc,
2944                            const DeclarationNameInfo &NameInfo,
2945                            bool HasTypenameKeyword);
2946 
2947   static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2948 
2949   SourceRange getSourceRange() const override LLVM_READONLY;
2950 
classof(const Decl * D)2951   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)2952   static bool classofKind(Kind K) { return K == Using; }
2953 
2954   friend class ASTDeclReader;
2955   friend class ASTDeclWriter;
2956 };
2957 
2958 /// \brief Represents a dependent using declaration which was not marked with
2959 /// \c typename.
2960 ///
2961 /// Unlike non-dependent using declarations, these *only* bring through
2962 /// non-types; otherwise they would break two-phase lookup.
2963 ///
2964 /// \code
2965 /// template \<class T> class A : public Base<T> {
2966 ///   using Base<T>::foo;
2967 /// };
2968 /// \endcode
2969 class UnresolvedUsingValueDecl : public ValueDecl {
2970   void anchor() override;
2971 
2972   /// \brief The source location of the 'using' keyword
2973   SourceLocation UsingLocation;
2974 
2975   /// \brief The nested-name-specifier that precedes the name.
2976   NestedNameSpecifierLoc QualifierLoc;
2977 
2978   /// \brief Provides source/type location info for the declaration name
2979   /// embedded in the ValueDecl base class.
2980   DeclarationNameLoc DNLoc;
2981 
UnresolvedUsingValueDecl(DeclContext * DC,QualType Ty,SourceLocation UsingLoc,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)2982   UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2983                            SourceLocation UsingLoc,
2984                            NestedNameSpecifierLoc QualifierLoc,
2985                            const DeclarationNameInfo &NameInfo)
2986     : ValueDecl(UnresolvedUsingValue, DC,
2987                 NameInfo.getLoc(), NameInfo.getName(), Ty),
2988       UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2989       DNLoc(NameInfo.getInfo())
2990   { }
2991 
2992 public:
2993   /// \brief Returns the source location of the 'using' keyword.
getUsingLoc()2994   SourceLocation getUsingLoc() const { return UsingLocation; }
2995 
2996   /// \brief Set the source location of the 'using' keyword.
setUsingLoc(SourceLocation L)2997   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2998 
2999   /// \brief Return true if it is a C++03 access declaration (no 'using').
isAccessDeclaration()3000   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3001 
3002   /// \brief Retrieve the nested-name-specifier that qualifies the name,
3003   /// with source-location information.
getQualifierLoc()3004   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3005 
3006   /// \brief Retrieve the nested-name-specifier that qualifies the name.
getQualifier()3007   NestedNameSpecifier *getQualifier() const {
3008     return QualifierLoc.getNestedNameSpecifier();
3009   }
3010 
getNameInfo()3011   DeclarationNameInfo getNameInfo() const {
3012     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3013   }
3014 
3015   static UnresolvedUsingValueDecl *
3016     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3017            NestedNameSpecifierLoc QualifierLoc,
3018            const DeclarationNameInfo &NameInfo);
3019 
3020   static UnresolvedUsingValueDecl *
3021   CreateDeserialized(ASTContext &C, unsigned ID);
3022 
3023   SourceRange getSourceRange() const override LLVM_READONLY;
3024 
classof(const Decl * D)3025   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)3026   static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3027 
3028   friend class ASTDeclReader;
3029   friend class ASTDeclWriter;
3030 };
3031 
3032 /// \brief Represents a dependent using declaration which was marked with
3033 /// \c typename.
3034 ///
3035 /// \code
3036 /// template \<class T> class A : public Base<T> {
3037 ///   using typename Base<T>::foo;
3038 /// };
3039 /// \endcode
3040 ///
3041 /// The type associated with an unresolved using typename decl is
3042 /// currently always a typename type.
3043 class UnresolvedUsingTypenameDecl : public TypeDecl {
3044   void anchor() override;
3045 
3046   /// \brief The source location of the 'typename' keyword
3047   SourceLocation TypenameLocation;
3048 
3049   /// \brief The nested-name-specifier that precedes the name.
3050   NestedNameSpecifierLoc QualifierLoc;
3051 
UnresolvedUsingTypenameDecl(DeclContext * DC,SourceLocation UsingLoc,SourceLocation TypenameLoc,NestedNameSpecifierLoc QualifierLoc,SourceLocation TargetNameLoc,IdentifierInfo * TargetName)3052   UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3053                               SourceLocation TypenameLoc,
3054                               NestedNameSpecifierLoc QualifierLoc,
3055                               SourceLocation TargetNameLoc,
3056                               IdentifierInfo *TargetName)
3057     : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3058                UsingLoc),
3059       TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
3060 
3061   friend class ASTDeclReader;
3062 
3063 public:
3064   /// \brief Returns the source location of the 'using' keyword.
getUsingLoc()3065   SourceLocation getUsingLoc() const { return getLocStart(); }
3066 
3067   /// \brief Returns the source location of the 'typename' keyword.
getTypenameLoc()3068   SourceLocation getTypenameLoc() const { return TypenameLocation; }
3069 
3070   /// \brief Retrieve the nested-name-specifier that qualifies the name,
3071   /// with source-location information.
getQualifierLoc()3072   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3073 
3074   /// \brief Retrieve the nested-name-specifier that qualifies the name.
getQualifier()3075   NestedNameSpecifier *getQualifier() const {
3076     return QualifierLoc.getNestedNameSpecifier();
3077   }
3078 
3079   static UnresolvedUsingTypenameDecl *
3080     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3081            SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3082            SourceLocation TargetNameLoc, DeclarationName TargetName);
3083 
3084   static UnresolvedUsingTypenameDecl *
3085   CreateDeserialized(ASTContext &C, unsigned ID);
3086 
classof(const Decl * D)3087   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)3088   static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3089 };
3090 
3091 /// \brief Represents a C++11 static_assert declaration.
3092 class StaticAssertDecl : public Decl {
3093   virtual void anchor();
3094   llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3095   StringLiteral *Message;
3096   SourceLocation RParenLoc;
3097 
StaticAssertDecl(DeclContext * DC,SourceLocation StaticAssertLoc,Expr * AssertExpr,StringLiteral * Message,SourceLocation RParenLoc,bool Failed)3098   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3099                    Expr *AssertExpr, StringLiteral *Message,
3100                    SourceLocation RParenLoc, bool Failed)
3101     : Decl(StaticAssert, DC, StaticAssertLoc),
3102       AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3103       RParenLoc(RParenLoc) { }
3104 
3105 public:
3106   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3107                                   SourceLocation StaticAssertLoc,
3108                                   Expr *AssertExpr, StringLiteral *Message,
3109                                   SourceLocation RParenLoc, bool Failed);
3110   static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3111 
getAssertExpr()3112   Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
getAssertExpr()3113   const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3114 
getMessage()3115   StringLiteral *getMessage() { return Message; }
getMessage()3116   const StringLiteral *getMessage() const { return Message; }
3117 
isFailed()3118   bool isFailed() const { return AssertExprAndFailed.getInt(); }
3119 
getRParenLoc()3120   SourceLocation getRParenLoc() const { return RParenLoc; }
3121 
getSourceRange()3122   SourceRange getSourceRange() const override LLVM_READONLY {
3123     return SourceRange(getLocation(), getRParenLoc());
3124   }
3125 
classof(const Decl * D)3126   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
classofKind(Kind K)3127   static bool classofKind(Kind K) { return K == StaticAssert; }
3128 
3129   friend class ASTDeclReader;
3130 };
3131 
3132 /// An instance of this class represents the declaration of a property
3133 /// member.  This is a Microsoft extension to C++, first introduced in
3134 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3135 /// and Managed C++.
3136 ///
3137 /// A property must always be a non-static class member.
3138 ///
3139 /// A property member superficially resembles a non-static data
3140 /// member, except preceded by a property attribute:
3141 ///   __declspec(property(get=GetX, put=PutX)) int x;
3142 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3143 ///
3144 /// A reference to a property is always an lvalue.  If the lvalue
3145 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3146 /// required, and that member is called with no arguments.
3147 /// If the lvalue is assigned into, then a setter name is required,
3148 /// and that member is called with one argument, the value assigned.
3149 /// Both operations are potentially overloaded.  Compound assignments
3150 /// are permitted, as are the increment and decrement operators.
3151 ///
3152 /// The getter and putter methods are permitted to be overloaded,
3153 /// although their return and parameter types are subject to certain
3154 /// restrictions according to the type of the property.
3155 ///
3156 /// A property declared using an incomplete array type may
3157 /// additionally be subscripted, adding extra parameters to the getter
3158 /// and putter methods.
3159 class MSPropertyDecl : public DeclaratorDecl {
3160   IdentifierInfo *GetterId, *SetterId;
3161 
MSPropertyDecl(DeclContext * DC,SourceLocation L,DeclarationName N,QualType T,TypeSourceInfo * TInfo,SourceLocation StartL,IdentifierInfo * Getter,IdentifierInfo * Setter)3162   MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3163                  QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3164                  IdentifierInfo *Getter, IdentifierInfo *Setter)
3165       : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3166         GetterId(Getter), SetterId(Setter) {}
3167 
3168 public:
3169   static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3170                                 SourceLocation L, DeclarationName N, QualType T,
3171                                 TypeSourceInfo *TInfo, SourceLocation StartL,
3172                                 IdentifierInfo *Getter, IdentifierInfo *Setter);
3173   static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3174 
classof(const Decl * D)3175   static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3176 
hasGetter()3177   bool hasGetter() const { return GetterId != nullptr; }
getGetterId()3178   IdentifierInfo* getGetterId() const { return GetterId; }
hasSetter()3179   bool hasSetter() const { return SetterId != nullptr; }
getSetterId()3180   IdentifierInfo* getSetterId() const { return SetterId; }
3181 
3182   friend class ASTDeclReader;
3183 };
3184 
3185 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
3186 /// into a diagnostic with <<.
3187 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3188                                     AccessSpecifier AS);
3189 
3190 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3191                                     AccessSpecifier AS);
3192 
3193 } // end namespace clang
3194 
3195 #endif
3196