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