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