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