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