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