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