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