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