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