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