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