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