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