DeclCXX.h revision 96a01b4acf76fb8fe1e05341a97a27b39fb0b914
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(ASTContext& C) 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(ASTContext &C,
386                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);
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 provably not derived from
756  /// the type \p Base.
757  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
758
759  /// \brief Function type used by forallBases() as a callback.
760  ///
761  /// \param Base the definition of the base class
762  ///
763  /// \returns true if this base matched the search criteria
764  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
765                                   void *UserData);
766
767  /// \brief Determines if the given callback holds for all the direct
768  /// or indirect base classes of this type.
769  ///
770  /// The class itself does not count as a base class.  This routine
771  /// returns false if the class has non-computable base classes.
772  ///
773  /// \param AllowShortCircuit if false, forces the callback to be called
774  /// for every base class, even if a dependent or non-matching base was
775  /// found.
776  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
777                   bool AllowShortCircuit = true) const;
778
779  /// \brief Function type used by lookupInBases() to determine whether a
780  /// specific base class subobject matches the lookup criteria.
781  ///
782  /// \param Specifier the base-class specifier that describes the inheritance
783  /// from the base class we are trying to match.
784  ///
785  /// \param Path the current path, from the most-derived class down to the
786  /// base named by the \p Specifier.
787  ///
788  /// \param UserData a single pointer to user-specified data, provided to
789  /// lookupInBases().
790  ///
791  /// \returns true if this base matched the search criteria, false otherwise.
792  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
793                                   CXXBasePath &Path,
794                                   void *UserData);
795
796  /// \brief Look for entities within the base classes of this C++ class,
797  /// transitively searching all base class subobjects.
798  ///
799  /// This routine uses the callback function \p BaseMatches to find base
800  /// classes meeting some search criteria, walking all base class subobjects
801  /// and populating the given \p Paths structure with the paths through the
802  /// inheritance hierarchy that resulted in a match. On a successful search,
803  /// the \p Paths structure can be queried to retrieve the matching paths and
804  /// to determine if there were any ambiguities.
805  ///
806  /// \param BaseMatches callback function used to determine whether a given
807  /// base matches the user-defined search criteria.
808  ///
809  /// \param UserData user data pointer that will be provided to \p BaseMatches.
810  ///
811  /// \param Paths used to record the paths from this class to its base class
812  /// subobjects that match the search criteria.
813  ///
814  /// \returns true if there exists any path from this class to a base class
815  /// subobject that matches the search criteria.
816  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
817                     CXXBasePaths &Paths) const;
818
819  /// \brief Base-class lookup callback that determines whether the given
820  /// base class specifier refers to a specific class declaration.
821  ///
822  /// This callback can be used with \c lookupInBases() to determine whether
823  /// a given derived class has is a base class subobject of a particular type.
824  /// The user data pointer should refer to the canonical CXXRecordDecl of the
825  /// base class that we are searching for.
826  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
827                            CXXBasePath &Path, void *BaseRecord);
828
829  /// \brief Base-class lookup callback that determines whether there exists
830  /// a tag with the given name.
831  ///
832  /// This callback can be used with \c lookupInBases() to find tag members
833  /// of the given name within a C++ class hierarchy. The user data pointer
834  /// is an opaque \c DeclarationName pointer.
835  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
836                            CXXBasePath &Path, void *Name);
837
838  /// \brief Base-class lookup callback that determines whether there exists
839  /// a member with the given name.
840  ///
841  /// This callback can be used with \c lookupInBases() to find members
842  /// of the given name within a C++ class hierarchy. The user data pointer
843  /// is an opaque \c DeclarationName pointer.
844  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
845                                 CXXBasePath &Path, void *Name);
846
847  /// \brief Base-class lookup callback that determines whether there exists
848  /// a member with the given name that can be used in a nested-name-specifier.
849  ///
850  /// This callback can be used with \c lookupInBases() to find membes of
851  /// the given name within a C++ class hierarchy that can occur within
852  /// nested-name-specifiers.
853  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
854                                            CXXBasePath &Path,
855                                            void *UserData);
856
857  /// viewInheritance - Renders and displays an inheritance diagram
858  /// for this C++ class and all of its base classes (transitively) using
859  /// GraphViz.
860  void viewInheritance(ASTContext& Context) const;
861
862  /// MergeAccess - Calculates the access of a decl that is reached
863  /// along a path.
864  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
865                                     AccessSpecifier DeclAccess) {
866    assert(DeclAccess != AS_none);
867    if (DeclAccess == AS_private) return AS_none;
868    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
869  }
870
871  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
872  static bool classofKind(Kind K) {
873    return K == CXXRecord ||
874           K == ClassTemplateSpecialization ||
875           K == ClassTemplatePartialSpecialization;
876  }
877  static bool classof(const CXXRecordDecl *D) { return true; }
878  static bool classof(const ClassTemplateSpecializationDecl *D) {
879    return true;
880  }
881};
882
883/// CXXMethodDecl - Represents a static or instance method of a
884/// struct/union/class.
885class CXXMethodDecl : public FunctionDecl {
886protected:
887  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
888                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
889                bool isStatic, bool isInline)
890    : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
891                   isInline) {}
892
893public:
894  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
895                              SourceLocation L, DeclarationName N,
896                              QualType T, TypeSourceInfo *TInfo,
897                              bool isStatic = false,
898                              bool isInline = false);
899
900  bool isStatic() const { return getStorageClass() == Static; }
901  bool isInstance() const { return !isStatic(); }
902
903  bool isVirtual() const {
904    CXXMethodDecl *CD =
905      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
906
907    if (CD->isVirtualAsWritten())
908      return true;
909
910    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
911  }
912
913  /// \brief Determine whether this is a usual deallocation function
914  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
915  /// delete or delete[] operator with a particular signature.
916  bool isUsualDeallocationFunction() const;
917
918  const CXXMethodDecl *getCanonicalDecl() const {
919    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
920  }
921  CXXMethodDecl *getCanonicalDecl() {
922    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
923  }
924
925  ///
926  void addOverriddenMethod(const CXXMethodDecl *MD);
927
928  typedef const CXXMethodDecl ** method_iterator;
929
930  method_iterator begin_overridden_methods() const;
931  method_iterator end_overridden_methods() const;
932
933  /// getParent - Returns the parent of this method declaration, which
934  /// is the class in which this method is defined.
935  const CXXRecordDecl *getParent() const {
936    return cast<CXXRecordDecl>(FunctionDecl::getParent());
937  }
938
939  /// getParent - Returns the parent of this method declaration, which
940  /// is the class in which this method is defined.
941  CXXRecordDecl *getParent() {
942    return const_cast<CXXRecordDecl *>(
943             cast<CXXRecordDecl>(FunctionDecl::getParent()));
944  }
945
946  /// getThisType - Returns the type of 'this' pointer.
947  /// Should only be called for instance methods.
948  QualType getThisType(ASTContext &C) const;
949
950  unsigned getTypeQualifiers() const {
951    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
952  }
953
954  bool hasInlineBody() const;
955
956  // Implement isa/cast/dyncast/etc.
957  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
958  static bool classof(const CXXMethodDecl *D) { return true; }
959  static bool classofKind(Kind K) {
960    return K >= CXXMethod && K <= CXXConversion;
961  }
962};
963
964/// CXXBaseOrMemberInitializer - Represents a C++ base or member
965/// initializer, which is part of a constructor initializer that
966/// initializes one non-static member variable or one base class. For
967/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
968/// initializers:
969///
970/// @code
971/// class A { };
972/// class B : public A {
973///   float f;
974/// public:
975///   B(A& a) : A(a), f(3.14159) { }
976/// };
977/// @endcode
978class CXXBaseOrMemberInitializer {
979  /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
980  /// field being initialized.
981  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
982
983  /// \brief The source location for the field name.
984  SourceLocation MemberLocation;
985
986  /// \brief The argument used to initialize the base or member, which may
987  /// end up constructing an object (when multiple arguments are involved).
988  Stmt *Init;
989
990  /// \brief Stores either the constructor to call to initialize this base or
991  /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
992  /// which the initialized value is a member.
993  ///
994  /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
995  /// anonymous union data member, this field holds the FieldDecl for the
996  /// member of the anonymous union being initialized.
997  /// @code
998  /// struct X {
999  ///   X() : au_i1(123) {}
1000  ///   union {
1001  ///     int au_i1;
1002  ///     float au_f1;
1003  ///   };
1004  /// };
1005  /// @endcode
1006  /// In above example, BaseOrMember holds the field decl. for anonymous union
1007  /// and AnonUnionMember holds field decl for au_i1.
1008  FieldDecl *AnonUnionMember;
1009
1010  /// LParenLoc - Location of the left paren of the ctor-initializer.
1011  SourceLocation LParenLoc;
1012
1013  /// RParenLoc - Location of the right paren of the ctor-initializer.
1014  SourceLocation RParenLoc;
1015
1016public:
1017  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1018  explicit
1019  CXXBaseOrMemberInitializer(ASTContext &Context,
1020                             TypeSourceInfo *TInfo,
1021                             SourceLocation L,
1022                             Expr *Init,
1023                             SourceLocation R);
1024
1025  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1026  explicit
1027  CXXBaseOrMemberInitializer(ASTContext &Context,
1028                             FieldDecl *Member, SourceLocation MemberLoc,
1029                             SourceLocation L,
1030                             Expr *Init,
1031                             SourceLocation R);
1032
1033  /// \brief Destroy the base or member initializer.
1034  void Destroy(ASTContext &Context);
1035
1036  /// isBaseInitializer - Returns true when this initializer is
1037  /// initializing a base class.
1038  bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1039
1040  /// isMemberInitializer - Returns true when this initializer is
1041  /// initializing a non-static data member.
1042  bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1043
1044  /// If this is a base class initializer, returns the type of the
1045  /// base class with location information. Otherwise, returns an NULL
1046  /// type location.
1047  TypeLoc getBaseClassLoc() const;
1048
1049  /// If this is a base class initializer, returns the type of the base class.
1050  /// Otherwise, returns NULL.
1051  const Type *getBaseClass() const;
1052  Type *getBaseClass();
1053
1054  /// \brief Returns the declarator information for a base class initializer.
1055  TypeSourceInfo *getBaseClassInfo() const {
1056    return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1057  }
1058
1059  /// getMember - If this is a member initializer, returns the
1060  /// declaration of the non-static data member being
1061  /// initialized. Otherwise, returns NULL.
1062  FieldDecl *getMember() {
1063    if (isMemberInitializer())
1064      return BaseOrMember.get<FieldDecl*>();
1065    else
1066      return 0;
1067  }
1068
1069  SourceLocation getMemberLocation() const {
1070    return MemberLocation;
1071  }
1072
1073  void setMember(FieldDecl *Member) {
1074    assert(isMemberInitializer());
1075    BaseOrMember = Member;
1076  }
1077
1078  /// \brief Determine the source location of the initializer.
1079  SourceLocation getSourceLocation() const;
1080
1081  /// \brief Determine the source range covering the entire initializer.
1082  SourceRange getSourceRange() const;
1083
1084  FieldDecl *getAnonUnionMember() const {
1085    return AnonUnionMember;
1086  }
1087  void setAnonUnionMember(FieldDecl *anonMember) {
1088    AnonUnionMember = anonMember;
1089  }
1090
1091  SourceLocation getLParenLoc() const { return LParenLoc; }
1092  SourceLocation getRParenLoc() const { return RParenLoc; }
1093
1094  Expr *getInit() { return static_cast<Expr *>(Init); }
1095};
1096
1097/// CXXConstructorDecl - Represents a C++ constructor within a
1098/// class. For example:
1099///
1100/// @code
1101/// class X {
1102/// public:
1103///   explicit X(int); // represented by a CXXConstructorDecl.
1104/// };
1105/// @endcode
1106class CXXConstructorDecl : public CXXMethodDecl {
1107  /// IsExplicitSpecified - Whether this constructor declaration has the
1108  /// 'explicit' keyword specified.
1109  bool IsExplicitSpecified : 1;
1110
1111  /// ImplicitlyDefined - Whether this constructor was implicitly
1112  /// defined by the compiler. When false, the constructor was defined
1113  /// by the user. In C++03, this flag will have the same value as
1114  /// Implicit. In C++0x, however, a constructor that is
1115  /// explicitly defaulted (i.e., defined with " = default") will have
1116  /// @c !Implicit && ImplicitlyDefined.
1117  bool ImplicitlyDefined : 1;
1118
1119  /// Support for base and member initializers.
1120  /// BaseOrMemberInitializers - The arguments used to initialize the base
1121  /// or member.
1122  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1123  unsigned NumBaseOrMemberInitializers;
1124
1125  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1126                     DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1127                     bool isExplicitSpecified, bool isInline,
1128                     bool isImplicitlyDeclared)
1129    : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline),
1130      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1131      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1132    setImplicit(isImplicitlyDeclared);
1133  }
1134  virtual void Destroy(ASTContext& C);
1135
1136public:
1137  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1138                                    SourceLocation L, DeclarationName N,
1139                                    QualType T, TypeSourceInfo *TInfo,
1140                                    bool isExplicit,
1141                                    bool isInline, bool isImplicitlyDeclared);
1142
1143  /// isExplicitSpecified - Whether this constructor declaration has the
1144  /// 'explicit' keyword specified.
1145  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1146
1147  /// isExplicit - Whether this constructor was marked "explicit" or not.
1148  bool isExplicit() const {
1149    return cast<CXXConstructorDecl>(getFirstDeclaration())
1150      ->isExplicitSpecified();
1151  }
1152
1153  /// isImplicitlyDefined - Whether this constructor was implicitly
1154  /// defined. If false, then this constructor was defined by the
1155  /// user. This operation can only be invoked if the constructor has
1156  /// already been defined.
1157  bool isImplicitlyDefined(ASTContext &C) const {
1158    assert(isThisDeclarationADefinition() &&
1159           "Can only get the implicit-definition flag once the "
1160           "constructor has been defined");
1161    return ImplicitlyDefined;
1162  }
1163
1164  /// setImplicitlyDefined - Set whether this constructor was
1165  /// implicitly defined or not.
1166  void setImplicitlyDefined(bool ID) {
1167    assert(isThisDeclarationADefinition() &&
1168           "Can only set the implicit-definition flag once the constructor "
1169           "has been defined");
1170    ImplicitlyDefined = ID;
1171  }
1172
1173  /// init_iterator - Iterates through the member/base initializer list.
1174  typedef CXXBaseOrMemberInitializer **init_iterator;
1175
1176  /// init_const_iterator - Iterates through the memberbase initializer list.
1177  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1178
1179  /// init_begin() - Retrieve an iterator to the first initializer.
1180  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
1181  /// begin() - Retrieve an iterator to the first initializer.
1182  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1183
1184  /// init_end() - Retrieve an iterator past the last initializer.
1185  init_iterator       init_end()       {
1186    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1187  }
1188  /// end() - Retrieve an iterator past the last initializer.
1189  init_const_iterator init_end() const {
1190    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1191  }
1192
1193  /// getNumArgs - Determine the number of arguments used to
1194  /// initialize the member or base.
1195  unsigned getNumBaseOrMemberInitializers() const {
1196      return NumBaseOrMemberInitializers;
1197  }
1198
1199  void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1200    NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1201  }
1202
1203  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1204    BaseOrMemberInitializers = initializers;
1205  }
1206  /// isDefaultConstructor - Whether this constructor is a default
1207  /// constructor (C++ [class.ctor]p5), which can be used to
1208  /// default-initialize a class of this type.
1209  bool isDefaultConstructor() const;
1210
1211  /// isCopyConstructor - Whether this constructor is a copy
1212  /// constructor (C++ [class.copy]p2, which can be used to copy the
1213  /// class. @p TypeQuals will be set to the qualifiers on the
1214  /// argument type. For example, @p TypeQuals would be set to @c
1215  /// QualType::Const for the following copy constructor:
1216  ///
1217  /// @code
1218  /// class X {
1219  /// public:
1220  ///   X(const X&);
1221  /// };
1222  /// @endcode
1223  bool isCopyConstructor(unsigned &TypeQuals) const;
1224
1225  /// isCopyConstructor - Whether this constructor is a copy
1226  /// constructor (C++ [class.copy]p2, which can be used to copy the
1227  /// class.
1228  bool isCopyConstructor() const {
1229    unsigned TypeQuals = 0;
1230    return isCopyConstructor(TypeQuals);
1231  }
1232
1233  /// isConvertingConstructor - Whether this constructor is a
1234  /// converting constructor (C++ [class.conv.ctor]), which can be
1235  /// used for user-defined conversions.
1236  bool isConvertingConstructor(bool AllowExplicit) const;
1237
1238  /// \brief Determine whether this is a member template specialization that
1239  /// looks like a copy constructor. Such constructors are never used to copy
1240  /// an object.
1241  bool isCopyConstructorLikeSpecialization() const;
1242
1243  // Implement isa/cast/dyncast/etc.
1244  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1245  static bool classof(const CXXConstructorDecl *D) { return true; }
1246  static bool classofKind(Kind K) { return K == CXXConstructor; }
1247};
1248
1249/// CXXDestructorDecl - Represents a C++ destructor within a
1250/// class. For example:
1251///
1252/// @code
1253/// class X {
1254/// public:
1255///   ~X(); // represented by a CXXDestructorDecl.
1256/// };
1257/// @endcode
1258class CXXDestructorDecl : public CXXMethodDecl {
1259  /// ImplicitlyDefined - Whether this destructor was implicitly
1260  /// defined by the compiler. When false, the destructor was defined
1261  /// by the user. In C++03, this flag will have the same value as
1262  /// Implicit. In C++0x, however, a destructor that is
1263  /// explicitly defaulted (i.e., defined with " = default") will have
1264  /// @c !Implicit && ImplicitlyDefined.
1265  bool ImplicitlyDefined : 1;
1266
1267  FunctionDecl *OperatorDelete;
1268
1269  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1270                    DeclarationName N, QualType T,
1271                    bool isInline, bool isImplicitlyDeclared)
1272    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline),
1273      ImplicitlyDefined(false), OperatorDelete(0) {
1274    setImplicit(isImplicitlyDeclared);
1275  }
1276
1277public:
1278  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1279                                   SourceLocation L, DeclarationName N,
1280                                   QualType T, bool isInline,
1281                                   bool isImplicitlyDeclared);
1282
1283  /// isImplicitlyDefined - Whether this destructor was implicitly
1284  /// defined. If false, then this destructor was defined by the
1285  /// user. This operation can only be invoked if the destructor has
1286  /// already been defined.
1287  bool isImplicitlyDefined() const {
1288    assert(isThisDeclarationADefinition() &&
1289           "Can only get the implicit-definition flag once the destructor has been defined");
1290    return ImplicitlyDefined;
1291  }
1292
1293  /// setImplicitlyDefined - Set whether this destructor was
1294  /// implicitly defined or not.
1295  void setImplicitlyDefined(bool ID) {
1296    assert(isThisDeclarationADefinition() &&
1297           "Can only set the implicit-definition flag once the destructor has been defined");
1298    ImplicitlyDefined = ID;
1299  }
1300
1301  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1302  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1303
1304  // Implement isa/cast/dyncast/etc.
1305  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1306  static bool classof(const CXXDestructorDecl *D) { return true; }
1307  static bool classofKind(Kind K) { return K == CXXDestructor; }
1308};
1309
1310/// CXXConversionDecl - Represents a C++ conversion function within a
1311/// class. For example:
1312///
1313/// @code
1314/// class X {
1315/// public:
1316///   operator bool();
1317/// };
1318/// @endcode
1319class CXXConversionDecl : public CXXMethodDecl {
1320  /// IsExplicitSpecified - Whether this conversion function declaration is
1321  /// marked "explicit", meaning that it can only be applied when the user
1322  /// explicitly wrote a cast. This is a C++0x feature.
1323  bool IsExplicitSpecified : 1;
1324
1325  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1326                    DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1327                    bool isInline, bool isExplicitSpecified)
1328    : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline),
1329      IsExplicitSpecified(isExplicitSpecified) { }
1330
1331public:
1332  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1333                                   SourceLocation L, DeclarationName N,
1334                                   QualType T, TypeSourceInfo *TInfo,
1335                                   bool isInline, bool isExplicit);
1336
1337  /// IsExplicitSpecified - Whether this conversion function declaration is
1338  /// marked "explicit", meaning that it can only be applied when the user
1339  /// explicitly wrote a cast. This is a C++0x feature.
1340  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1341
1342  /// isExplicit - Whether this is an explicit conversion operator
1343  /// (C++0x only). Explicit conversion operators are only considered
1344  /// when the user has explicitly written a cast.
1345  bool isExplicit() const {
1346    return cast<CXXConversionDecl>(getFirstDeclaration())
1347      ->isExplicitSpecified();
1348  }
1349
1350  /// getConversionType - Returns the type that this conversion
1351  /// function is converting to.
1352  QualType getConversionType() const {
1353    return getType()->getAs<FunctionType>()->getResultType();
1354  }
1355
1356  // Implement isa/cast/dyncast/etc.
1357  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1358  static bool classof(const CXXConversionDecl *D) { return true; }
1359  static bool classofKind(Kind K) { return K == CXXConversion; }
1360};
1361
1362/// FriendDecl - Represents the declaration of a friend entity,
1363/// which can be a function, a type, or a templated function or type.
1364//  For example:
1365///
1366/// @code
1367/// template <typename T> class A {
1368///   friend int foo(T);
1369///   friend class B;
1370///   friend T; // only in C++0x
1371///   template <typename U> friend class C;
1372///   template <typename U> friend A& operator+=(A&, const U&) { ... }
1373/// };
1374/// @endcode
1375///
1376/// The semantic context of a friend decl is its declaring class.
1377class FriendDecl : public Decl {
1378public:
1379  typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
1380
1381private:
1382  // The declaration that's a friend of this class.
1383  FriendUnion Friend;
1384
1385  // Location of the 'friend' specifier.
1386  SourceLocation FriendLoc;
1387
1388  // FIXME: Hack to keep track of whether this was a friend function
1389  // template specialization.
1390  bool WasSpecialization;
1391
1392  FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
1393             SourceLocation FriendL)
1394    : Decl(Decl::Friend, DC, L),
1395      Friend(Friend),
1396      FriendLoc(FriendL),
1397      WasSpecialization(false) {
1398  }
1399
1400public:
1401  static FriendDecl *Create(ASTContext &C, DeclContext *DC,
1402                            SourceLocation L, FriendUnion Friend_,
1403                            SourceLocation FriendL);
1404
1405  /// If this friend declaration names an (untemplated but
1406  /// possibly dependent) type, return the type;  otherwise
1407  /// return null.  This is used only for C++0x's unelaborated
1408  /// friend type declarations.
1409  Type *getFriendType() const {
1410    return Friend.dyn_cast<Type*>();
1411  }
1412
1413  /// If this friend declaration doesn't name an unelaborated
1414  /// type, return the inner declaration.
1415  NamedDecl *getFriendDecl() const {
1416    return Friend.dyn_cast<NamedDecl*>();
1417  }
1418
1419  /// Retrieves the location of the 'friend' keyword.
1420  SourceLocation getFriendLoc() const {
1421    return FriendLoc;
1422  }
1423
1424  bool wasSpecialization() const { return WasSpecialization; }
1425  void setSpecialization(bool WS) { WasSpecialization = WS; }
1426
1427  // Implement isa/cast/dyncast/etc.
1428  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1429  static bool classof(const FriendDecl *D) { return true; }
1430  static bool classofKind(Kind K) { return K == Decl::Friend; }
1431};
1432
1433/// LinkageSpecDecl - This represents a linkage specification.  For example:
1434///   extern "C" void foo();
1435///
1436class LinkageSpecDecl : public Decl, public DeclContext {
1437public:
1438  /// LanguageIDs - Used to represent the language in a linkage
1439  /// specification.  The values are part of the serialization abi for
1440  /// ASTs and cannot be changed without altering that abi.  To help
1441  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1442  /// from the dwarf standard.
1443  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1444  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1445private:
1446  /// Language - The language for this linkage specification.
1447  LanguageIDs Language;
1448
1449  /// HadBraces - Whether this linkage specification had curly braces or not.
1450  bool HadBraces : 1;
1451
1452  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1453                  bool Braces)
1454    : Decl(LinkageSpec, DC, L),
1455      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1456
1457public:
1458  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1459                                 SourceLocation L, LanguageIDs Lang,
1460                                 bool Braces);
1461
1462  LanguageIDs getLanguage() const { return Language; }
1463
1464  /// hasBraces - Determines whether this linkage specification had
1465  /// braces in its syntactic form.
1466  bool hasBraces() const { return HadBraces; }
1467
1468  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1469  static bool classof(const LinkageSpecDecl *D) { return true; }
1470  static bool classofKind(Kind K) { return K == LinkageSpec; }
1471  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1472    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1473  }
1474  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1475    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1476  }
1477};
1478
1479/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1480///
1481///    using namespace std;
1482///
1483// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1484// artificial name, for all using-directives in order to store
1485// them in DeclContext effectively.
1486class UsingDirectiveDecl : public NamedDecl {
1487
1488  /// SourceLocation - Location of 'namespace' token.
1489  SourceLocation NamespaceLoc;
1490
1491  /// \brief The source range that covers the nested-name-specifier
1492  /// preceding the namespace name.
1493  SourceRange QualifierRange;
1494
1495  /// \brief The nested-name-specifier that precedes the namespace
1496  /// name, if any.
1497  NestedNameSpecifier *Qualifier;
1498
1499  /// IdentLoc - Location of nominated namespace-name identifier.
1500  // FIXME: We don't store location of scope specifier.
1501  SourceLocation IdentLoc;
1502
1503  /// NominatedNamespace - Namespace nominated by using-directive.
1504  NamedDecl *NominatedNamespace;
1505
1506  /// Enclosing context containing both using-directive and nominated
1507  /// namespace.
1508  DeclContext *CommonAncestor;
1509
1510  /// getUsingDirectiveName - Returns special DeclarationName used by
1511  /// using-directives. This is only used by DeclContext for storing
1512  /// UsingDirectiveDecls in its lookup structure.
1513  static DeclarationName getName() {
1514    return DeclarationName::getUsingDirectiveName();
1515  }
1516
1517  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1518                     SourceLocation NamespcLoc,
1519                     SourceRange QualifierRange,
1520                     NestedNameSpecifier *Qualifier,
1521                     SourceLocation IdentLoc,
1522                     NamedDecl *Nominated,
1523                     DeclContext *CommonAncestor)
1524    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1525      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1526      Qualifier(Qualifier), IdentLoc(IdentLoc),
1527      NominatedNamespace(Nominated),
1528      CommonAncestor(CommonAncestor) {
1529  }
1530
1531public:
1532  /// \brief Retrieve the source range of the nested-name-specifier
1533  /// that qualifiers the namespace name.
1534  SourceRange getQualifierRange() const { return QualifierRange; }
1535
1536  /// \brief Retrieve the nested-name-specifier that qualifies the
1537  /// name of the namespace.
1538  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1539
1540  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1541  const NamedDecl *getNominatedNamespaceAsWritten() const {
1542    return NominatedNamespace;
1543  }
1544
1545  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1546  NamespaceDecl *getNominatedNamespace();
1547
1548  const NamespaceDecl *getNominatedNamespace() const {
1549    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1550  }
1551
1552  /// getCommonAncestor - returns common ancestor context of using-directive,
1553  /// and nominated by it namespace.
1554  DeclContext *getCommonAncestor() { return CommonAncestor; }
1555  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1556
1557  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1558  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1559
1560  /// getIdentLocation - Returns location of identifier.
1561  SourceLocation getIdentLocation() const { return IdentLoc; }
1562
1563  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1564                                    SourceLocation L,
1565                                    SourceLocation NamespaceLoc,
1566                                    SourceRange QualifierRange,
1567                                    NestedNameSpecifier *Qualifier,
1568                                    SourceLocation IdentLoc,
1569                                    NamedDecl *Nominated,
1570                                    DeclContext *CommonAncestor);
1571
1572  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1573  static bool classof(const UsingDirectiveDecl *D) { return true; }
1574  static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1575
1576  // Friend for getUsingDirectiveName.
1577  friend class DeclContext;
1578};
1579
1580/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1581///
1582/// @code
1583/// namespace Foo = Bar;
1584/// @endcode
1585class NamespaceAliasDecl : public NamedDecl {
1586  SourceLocation AliasLoc;
1587
1588  /// \brief The source range that covers the nested-name-specifier
1589  /// preceding the namespace name.
1590  SourceRange QualifierRange;
1591
1592  /// \brief The nested-name-specifier that precedes the namespace
1593  /// name, if any.
1594  NestedNameSpecifier *Qualifier;
1595
1596  /// IdentLoc - Location of namespace identifier.
1597  SourceLocation IdentLoc;
1598
1599  /// Namespace - The Decl that this alias points to. Can either be a
1600  /// NamespaceDecl or a NamespaceAliasDecl.
1601  NamedDecl *Namespace;
1602
1603  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1604                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1605                     SourceRange QualifierRange,
1606                     NestedNameSpecifier *Qualifier,
1607                     SourceLocation IdentLoc, NamedDecl *Namespace)
1608    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1609      QualifierRange(QualifierRange), Qualifier(Qualifier),
1610      IdentLoc(IdentLoc), Namespace(Namespace) { }
1611
1612public:
1613  /// \brief Retrieve the source range of the nested-name-specifier
1614  /// that qualifiers the namespace name.
1615  SourceRange getQualifierRange() const { return QualifierRange; }
1616
1617  /// \brief Retrieve the nested-name-specifier that qualifies the
1618  /// name of the namespace.
1619  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1620
1621  NamespaceDecl *getNamespace() {
1622    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1623      return AD->getNamespace();
1624
1625    return cast<NamespaceDecl>(Namespace);
1626  }
1627
1628  const NamespaceDecl *getNamespace() const {
1629    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1630  }
1631
1632  /// \brief Retrieve the namespace that this alias refers to, which
1633  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1634  NamedDecl *getAliasedNamespace() const { return Namespace; }
1635
1636  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1637                                    SourceLocation L, SourceLocation AliasLoc,
1638                                    IdentifierInfo *Alias,
1639                                    SourceRange QualifierRange,
1640                                    NestedNameSpecifier *Qualifier,
1641                                    SourceLocation IdentLoc,
1642                                    NamedDecl *Namespace);
1643
1644  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1645  static bool classof(const NamespaceAliasDecl *D) { return true; }
1646  static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1647};
1648
1649/// UsingShadowDecl - Represents a shadow declaration introduced into
1650/// a scope by a (resolved) using declaration.  For example,
1651///
1652/// namespace A {
1653///   void foo();
1654/// }
1655/// namespace B {
1656///   using A::foo(); // <- a UsingDecl
1657///                   // Also creates a UsingShadowDecl for A::foo in B
1658/// }
1659///
1660class UsingShadowDecl : public NamedDecl {
1661  /// The referenced declaration.
1662  NamedDecl *Underlying;
1663
1664  /// The using declaration which introduced this decl.
1665  UsingDecl *Using;
1666
1667  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1668                  NamedDecl *Target)
1669    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1670      Underlying(Target), Using(Using) {
1671    IdentifierNamespace = Target->getIdentifierNamespace();
1672    setImplicit();
1673  }
1674
1675public:
1676  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1677                                 SourceLocation Loc, UsingDecl *Using,
1678                                 NamedDecl *Target) {
1679    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1680  }
1681
1682  /// Gets the underlying declaration which has been brought into the
1683  /// local scope.
1684  NamedDecl *getTargetDecl() const {
1685    return Underlying;
1686  }
1687
1688  /// Gets the using declaration to which this declaration is tied.
1689  UsingDecl *getUsingDecl() const {
1690    return Using;
1691  }
1692
1693  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1694  static bool classof(const UsingShadowDecl *D) { return true; }
1695  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1696};
1697
1698/// UsingDecl - Represents a C++ using-declaration. For example:
1699///    using someNameSpace::someIdentifier;
1700class UsingDecl : public NamedDecl {
1701  /// \brief The source range that covers the nested-name-specifier
1702  /// preceding the declaration name.
1703  SourceRange NestedNameRange;
1704
1705  /// \brief The source location of the "using" location itself.
1706  SourceLocation UsingLocation;
1707
1708  /// \brief Target nested name specifier.
1709  NestedNameSpecifier* TargetNestedName;
1710
1711  /// \brief The collection of shadow declarations associated with
1712  /// this using declaration.  This set can change as a class is
1713  /// processed.
1714  llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1715
1716  // \brief Has 'typename' keyword.
1717  bool IsTypeName;
1718
1719  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1720            SourceLocation UL, NestedNameSpecifier* TargetNNS,
1721            DeclarationName Name, bool IsTypeNameArg)
1722    : NamedDecl(Decl::Using, DC, L, Name),
1723      NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1724      IsTypeName(IsTypeNameArg) {
1725  }
1726
1727public:
1728  /// \brief Returns the source range that covers the nested-name-specifier
1729  /// preceding the namespace name.
1730  SourceRange getNestedNameRange() { return NestedNameRange; }
1731
1732  /// \brief Returns the source location of the "using" location itself.
1733  SourceLocation getUsingLocation() { return UsingLocation; }
1734
1735  /// \brief Get target nested name declaration.
1736  NestedNameSpecifier* getTargetNestedNameDecl() {
1737    return TargetNestedName;
1738  }
1739
1740  /// isTypeName - Return true if using decl has 'typename'.
1741  bool isTypeName() const { return IsTypeName; }
1742
1743  typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1744  shadow_iterator shadow_begin() const { return Shadows.begin(); }
1745  shadow_iterator shadow_end() const { return Shadows.end(); }
1746
1747  void addShadowDecl(UsingShadowDecl *S) {
1748    assert(S->getUsingDecl() == this);
1749    if (!Shadows.insert(S)) {
1750      assert(false && "declaration already in set");
1751    }
1752  }
1753  void removeShadowDecl(UsingShadowDecl *S) {
1754    assert(S->getUsingDecl() == this);
1755    if (!Shadows.erase(S)) {
1756      assert(false && "declaration not in set");
1757    }
1758  }
1759
1760  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1761      SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1762      NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1763
1764  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1765  static bool classof(const UsingDecl *D) { return true; }
1766  static bool classofKind(Kind K) { return K == Decl::Using; }
1767};
1768
1769/// UnresolvedUsingValueDecl - Represents a dependent using
1770/// declaration which was not marked with 'typename'.  Unlike
1771/// non-dependent using declarations, these *only* bring through
1772/// non-types; otherwise they would break two-phase lookup.
1773///
1774/// template <class T> class A : public Base<T> {
1775///   using Base<T>::foo;
1776/// };
1777class UnresolvedUsingValueDecl : public ValueDecl {
1778  /// \brief The source range that covers the nested-name-specifier
1779  /// preceding the declaration name.
1780  SourceRange TargetNestedNameRange;
1781
1782  /// \brief The source location of the 'using' keyword
1783  SourceLocation UsingLocation;
1784
1785  NestedNameSpecifier *TargetNestedNameSpecifier;
1786
1787  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1788                           SourceLocation UsingLoc, SourceRange TargetNNR,
1789                           NestedNameSpecifier *TargetNNS,
1790                           SourceLocation TargetNameLoc,
1791                           DeclarationName TargetName)
1792    : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1793    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1794    TargetNestedNameSpecifier(TargetNNS)
1795  { }
1796
1797public:
1798  /// \brief Returns the source range that covers the nested-name-specifier
1799  /// preceding the namespace name.
1800  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1801
1802  /// \brief Get target nested name declaration.
1803  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1804    return TargetNestedNameSpecifier;
1805  }
1806
1807  /// \brief Returns the source location of the 'using' keyword.
1808  SourceLocation getUsingLoc() const { return UsingLocation; }
1809
1810  static UnresolvedUsingValueDecl *
1811    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1812           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1813           SourceLocation TargetNameLoc, DeclarationName TargetName);
1814
1815  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1816  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1817  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
1818};
1819
1820/// UnresolvedUsingTypenameDecl - Represents a dependent using
1821/// declaration which was marked with 'typename'.
1822///
1823/// template <class T> class A : public Base<T> {
1824///   using typename Base<T>::foo;
1825/// };
1826///
1827/// The type associated with a unresolved using typename decl is
1828/// currently always a typename type.
1829class UnresolvedUsingTypenameDecl : public TypeDecl {
1830  /// \brief The source range that covers the nested-name-specifier
1831  /// preceding the declaration name.
1832  SourceRange TargetNestedNameRange;
1833
1834  /// \brief The source location of the 'using' keyword
1835  SourceLocation UsingLocation;
1836
1837  /// \brief The source location of the 'typename' keyword
1838  SourceLocation TypenameLocation;
1839
1840  NestedNameSpecifier *TargetNestedNameSpecifier;
1841
1842  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1843                    SourceLocation TypenameLoc,
1844                    SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1845                    SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1846  : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1847    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1848    TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
1849  { }
1850
1851public:
1852  /// \brief Returns the source range that covers the nested-name-specifier
1853  /// preceding the namespace name.
1854  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1855
1856  /// \brief Get target nested name declaration.
1857  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1858    return TargetNestedNameSpecifier;
1859  }
1860
1861  /// \brief Returns the source location of the 'using' keyword.
1862  SourceLocation getUsingLoc() const { return UsingLocation; }
1863
1864  /// \brief Returns the source location of the 'typename' keyword.
1865  SourceLocation getTypenameLoc() const { return TypenameLocation; }
1866
1867  static UnresolvedUsingTypenameDecl *
1868    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1869           SourceLocation TypenameLoc,
1870           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1871           SourceLocation TargetNameLoc, DeclarationName TargetName);
1872
1873  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1874  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
1875  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
1876};
1877
1878/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1879class StaticAssertDecl : public Decl {
1880  Expr *AssertExpr;
1881  StringLiteral *Message;
1882
1883  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1884                   Expr *assertexpr, StringLiteral *message)
1885  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1886
1887public:
1888  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1889                                  SourceLocation L, Expr *AssertExpr,
1890                                  StringLiteral *Message);
1891
1892  Expr *getAssertExpr() { return AssertExpr; }
1893  const Expr *getAssertExpr() const { return AssertExpr; }
1894
1895  StringLiteral *getMessage() { return Message; }
1896  const StringLiteral *getMessage() const { return Message; }
1897
1898  virtual ~StaticAssertDecl();
1899  virtual void Destroy(ASTContext& C);
1900
1901  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1902  static bool classof(StaticAssertDecl *D) { return true; }
1903  static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
1904};
1905
1906/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1907/// into a diagnostic with <<.
1908const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1909                                    AccessSpecifier AS);
1910
1911} // end namespace clang
1912
1913#endif
1914