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