DeclCXX.h revision 5bbe816cd08bd28a87e8dadedf2cafb19ebf3b0b
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/TypeLoc.h"
21#include "clang/AST/UnresolvedSet.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 CXXIndirectPrimaryBaseSet;
38class FriendDecl;
39
40/// \brief Represents any kind of function declaration, whether it is a
41/// concrete function or a function template.
42class AnyFunctionDecl {
43  NamedDecl *Function;
44
45  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
46
47public:
48  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
49  AnyFunctionDecl(FunctionTemplateDecl *FTD);
50
51  /// \brief Implicily converts any function or function template into a
52  /// named declaration.
53  operator NamedDecl *() const { return Function; }
54
55  /// \brief Retrieve the underlying function or function template.
56  NamedDecl *get() const { return Function; }
57
58  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
59    return AnyFunctionDecl(ND);
60  }
61};
62
63} // end namespace clang
64
65namespace llvm {
66  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
67  /// AnyFunctionDecl to any function or function template declaration.
68  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
69    typedef ::clang::NamedDecl* SimpleType;
70    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
71      return Val;
72    }
73  };
74  template<> struct simplify_type< ::clang::AnyFunctionDecl>
75  : public simplify_type<const ::clang::AnyFunctionDecl> {};
76
77  // Provide PointerLikeTypeTraits for non-cvr pointers.
78  template<>
79  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
80  public:
81    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
82      return F.get();
83    }
84    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
85      return ::clang::AnyFunctionDecl::getFromNamedDecl(
86                                      static_cast< ::clang::NamedDecl*>(P));
87    }
88
89    enum { NumLowBitsAvailable = 2 };
90  };
91
92} // end namespace llvm
93
94namespace clang {
95
96/// AccessSpecDecl - An access specifier followed by colon ':'.
97///
98/// An objects of this class represents sugar for the syntactic occurrence
99/// of an access specifier followed by a colon in the list of member
100/// specifiers of a C++ class definition.
101///
102/// Note that they do not represent other uses of access specifiers,
103/// such as those occurring in a list of base specifiers.
104/// Also note that this class has nothing to do with so-called
105/// "access declarations" (C++98 11.3 [class.access.dcl]).
106class AccessSpecDecl : public Decl {
107  /// ColonLoc - The location of the ':'.
108  SourceLocation ColonLoc;
109
110  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
111                 SourceLocation ASLoc, SourceLocation ColonLoc)
112    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
113    setAccess(AS);
114  }
115  AccessSpecDecl(EmptyShell Empty)
116    : Decl(AccessSpec, Empty) { }
117public:
118  /// getAccessSpecifierLoc - The location of the access specifier.
119  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
120  /// setAccessSpecifierLoc - Sets the location of the access specifier.
121  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
122
123  /// getColonLoc - The location of the colon following the access specifier.
124  SourceLocation getColonLoc() const { return ColonLoc; }
125  /// setColonLoc - Sets the location of the colon.
126  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
127
128  SourceRange getSourceRange() const {
129    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
130  }
131
132  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
133                                DeclContext *DC, SourceLocation ASLoc,
134                                SourceLocation ColonLoc) {
135    return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
136  }
137  static AccessSpecDecl *Create(ASTContext &C, EmptyShell Empty) {
138    return new (C) AccessSpecDecl(Empty);
139  }
140
141  // Implement isa/cast/dyncast/etc.
142  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
143  static bool classof(const AccessSpecDecl *D) { return true; }
144  static bool classofKind(Kind K) { return K == AccessSpec; }
145};
146
147
148/// CXXBaseSpecifier - A base class of a C++ class.
149///
150/// Each CXXBaseSpecifier represents a single, direct base class (or
151/// struct) of a C++ class (or struct). It specifies the type of that
152/// base class, whether it is a virtual or non-virtual base, and what
153/// level of access (public, protected, private) is used for the
154/// derivation. For example:
155///
156/// @code
157///   class A { };
158///   class B { };
159///   class C : public virtual A, protected B { };
160/// @endcode
161///
162/// In this code, C will have two CXXBaseSpecifiers, one for "public
163/// virtual A" and the other for "protected B".
164class CXXBaseSpecifier {
165  /// Range - The source code range that covers the full base
166  /// specifier, including the "virtual" (if present) and access
167  /// specifier (if present).
168  SourceRange Range;
169
170  /// \brief The source location of the ellipsis, if this is a pack
171  /// expansion.
172  SourceLocation EllipsisLoc;
173
174  /// Virtual - Whether this is a virtual base class or not.
175  bool Virtual : 1;
176
177  /// BaseOfClass - Whether this is the base of a class (true) or of a
178  /// struct (false). This determines the mapping from the access
179  /// specifier as written in the source code to the access specifier
180  /// used for semantic analysis.
181  bool BaseOfClass : 1;
182
183  /// Access - Access specifier as written in the source code (which
184  /// may be AS_none). The actual type of data stored here is an
185  /// AccessSpecifier, but we use "unsigned" here to work around a
186  /// VC++ bug.
187  unsigned Access : 2;
188
189  /// InheritConstructors - Whether the class contains a using declaration
190  /// to inherit the named class's constructors.
191  bool InheritConstructors : 1;
192
193  /// BaseTypeInfo - The type of the base class. This will be a class or struct
194  /// (or a typedef of such). The source code range does not include the
195  /// "virtual" or access specifier.
196  TypeSourceInfo *BaseTypeInfo;
197
198public:
199  CXXBaseSpecifier() { }
200
201  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
202                   TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
203    : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
204      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
205
206  /// getSourceRange - Retrieves the source range that contains the
207  /// entire base specifier.
208  SourceRange getSourceRange() const { return Range; }
209
210  /// isVirtual - Determines whether the base class is a virtual base
211  /// class (or not).
212  bool isVirtual() const { return Virtual; }
213
214  /// \brief Determine whether this base class is a base of a class declared
215  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
216  bool isBaseOfClass() const { return BaseOfClass; }
217
218  /// \brief Determine whether this base specifier is a pack expansion.
219  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
220
221  /// \brief Determine whether this base class's constructors get inherited.
222  bool getInheritConstructors() const { return InheritConstructors; }
223
224  /// \brief Set that this base class's constructors should be inherited.
225  void setInheritConstructors(bool Inherit = true) {
226    InheritConstructors = Inherit;
227  }
228
229  /// \brief For a pack expansion, determine the location of the ellipsis.
230  SourceLocation getEllipsisLoc() const {
231    return EllipsisLoc;
232  }
233
234  /// getAccessSpecifier - Returns the access specifier for this base
235  /// specifier. This is the actual base specifier as used for
236  /// semantic analysis, so the result can never be AS_none. To
237  /// retrieve the access specifier as written in the source code, use
238  /// getAccessSpecifierAsWritten().
239  AccessSpecifier getAccessSpecifier() const {
240    if ((AccessSpecifier)Access == AS_none)
241      return BaseOfClass? AS_private : AS_public;
242    else
243      return (AccessSpecifier)Access;
244  }
245
246  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
247  /// written in the source code (which may mean that no access
248  /// specifier was explicitly written). Use getAccessSpecifier() to
249  /// retrieve the access specifier for use in semantic analysis.
250  AccessSpecifier getAccessSpecifierAsWritten() const {
251    return (AccessSpecifier)Access;
252  }
253
254  /// getType - Retrieves the type of the base class. This type will
255  /// always be an unqualified class type.
256  QualType getType() const { return BaseTypeInfo->getType(); }
257
258  /// getTypeLoc - Retrieves the type and source location of the base class.
259  TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
260};
261
262/// CXXRecordDecl - Represents a C++ struct/union/class.
263/// FIXME: This class will disappear once we've properly taught RecordDecl
264/// to deal with C++-specific things.
265class CXXRecordDecl : public RecordDecl {
266
267  friend void TagDecl::startDefinition();
268
269  struct DefinitionData {
270    DefinitionData(CXXRecordDecl *D);
271
272    /// UserDeclaredConstructor - True when this class has a
273    /// user-declared constructor.
274    bool UserDeclaredConstructor : 1;
275
276    /// UserDeclaredCopyConstructor - True when this class has a
277    /// user-declared copy constructor.
278    bool UserDeclaredCopyConstructor : 1;
279
280    /// UserDeclareMoveConstructor - True when this class has a
281    /// user-declared move constructor.
282    bool UserDeclaredMoveConstructor : 1;
283
284    /// UserDeclaredCopyAssignment - True when this class has a
285    /// user-declared copy assignment operator.
286    bool UserDeclaredCopyAssignment : 1;
287
288    /// UserDeclareMoveAssignment - True when this class has a
289    /// user-declared move assignment.
290    bool UserDeclaredMoveAssignment : 1;
291
292    /// UserDeclaredDestructor - True when this class has a
293    /// user-declared destructor.
294    bool UserDeclaredDestructor : 1;
295
296    /// Aggregate - True when this class is an aggregate.
297    bool Aggregate : 1;
298
299    /// PlainOldData - True when this class is a POD-type.
300    bool PlainOldData : 1;
301
302    /// Empty - true when this class is empty for traits purposes,
303    /// i.e. has no data members other than 0-width bit-fields, has no
304    /// virtual function/base, and doesn't inherit from a non-empty
305    /// class. Doesn't take union-ness into account.
306    bool Empty : 1;
307
308    /// Polymorphic - True when this class is polymorphic, i.e. has at
309    /// least one virtual member or derives from a polymorphic class.
310    bool Polymorphic : 1;
311
312    /// Abstract - True when this class is abstract, i.e. has at least
313    /// one pure virtual function, (that can come from a base class).
314    bool Abstract : 1;
315
316    /// IsStandardLayout - True when this class has standard layout.
317    ///
318    /// C++0x [class]p7.  A standard-layout class is a class that:
319    /// * has no non-static data members of type non-standard-layout class (or
320    ///   array of such types) or reference,
321    /// * has no virtual functions (10.3) and no virtual base classes (10.1),
322    /// * has the same access control (Clause 11) for all non-static data
323    ///   members
324    /// * has no non-standard-layout base classes,
325    /// * either has no non-static data members in the most derived class and at
326    ///   most one base class with non-static data members, or has no base
327    ///   classes with non-static data members, and
328    /// * has no base classes of the same type as the first non-static data
329    ///   member.
330    bool IsStandardLayout : 1;
331
332    /// HasNoNonEmptyBases - True when there are no non-empty base classes.
333    ///
334    /// This is a helper bit of state used to implement IsStandardLayout more
335    /// efficiently.
336    bool HasNoNonEmptyBases : 1;
337
338    /// HasPrivateFields - True when there are private non-static data members.
339    bool HasPrivateFields : 1;
340
341    /// HasProtectedFields - True when there are protected non-static data
342    /// members.
343    bool HasProtectedFields : 1;
344
345    /// HasPublicFields - True when there are private non-static data members.
346    bool HasPublicFields : 1;
347
348    /// \brief True if this class (or any subobject) has mutable fields.
349    bool HasMutableFields : 1;
350
351    /// HasTrivialDefaultConstructor - True when, if this class has a default
352    /// constructor, this default constructor is trivial.
353    ///
354    /// C++0x [class.ctor]p5
355    ///    A default constructor is trivial if it is not user-provided and if
356    ///     -- its class has no virtual functions and no virtual base classes,
357    ///        and
358    ///     -- no non-static data member of its class has a
359    ///        brace-or-equal-initializer, and
360    ///     -- all the direct base classes of its class have trivial
361    ///        default constructors, and
362    ///     -- for all the nonstatic data members of its class that are of class
363    ///        type (or array thereof), each such class has a trivial
364    ///        default constructor.
365    bool HasTrivialDefaultConstructor : 1;
366
367    /// HasConstexprNonCopyMoveConstructor - True when this class has at least
368    /// one constexpr constructor which is neither the copy nor move
369    /// constructor.
370    bool HasConstexprNonCopyMoveConstructor : 1;
371
372    /// HasTrivialCopyConstructor - True when this class has a trivial copy
373    /// constructor.
374    ///
375    /// C++0x [class.copy]p13:
376    ///   A copy/move constructor for class X is trivial if it is neither
377    ///   user-provided and if
378    ///    -- class X has no virtual functions and no virtual base classes, and
379    ///    -- the constructor selected to copy/move each direct base class
380    ///       subobject is trivial, and
381    ///    -- for each non-static data member of X that is of class type (or an
382    ///       array thereof), the constructor selected to copy/move that member
383    ///       is trivial;
384    ///   otherwise the copy/move constructor is non-trivial.
385    bool HasTrivialCopyConstructor : 1;
386
387    /// HasTrivialMoveConstructor - True when this class has a trivial move
388    /// constructor.
389    ///
390    /// C++0x [class.copy]p13:
391    ///   A copy/move constructor for class X is trivial if it is neither
392    ///   user-provided and if
393    ///    -- class X has no virtual functions and no virtual base classes, and
394    ///    -- the constructor selected to copy/move each direct base class
395    ///       subobject is trivial, and
396    ///    -- for each non-static data member of X that is of class type (or an
397    ///       array thereof), the constructor selected to copy/move that member
398    ///       is trivial;
399    ///   otherwise the copy/move constructor is non-trivial.
400    bool HasTrivialMoveConstructor : 1;
401
402    /// HasTrivialCopyAssignment - True when this class has a trivial copy
403    /// assignment operator.
404    ///
405    /// C++0x [class.copy]p27:
406    ///   A copy/move assignment operator for class X is trivial if it is
407    ///   neither user-provided nor deleted and if
408    ///    -- class X has no virtual functions and no virtual base classes, and
409    ///    -- the assignment operator selected to copy/move each direct base
410    ///       class subobject is trivial, and
411    ///    -- for each non-static data member of X that is of class type (or an
412    ///       array thereof), the assignment operator selected to copy/move
413    ///       that member is trivial;
414    ///   otherwise the copy/move assignment operator is non-trivial.
415    bool HasTrivialCopyAssignment : 1;
416
417    /// HasTrivialMoveAssignment - True when this class has a trivial move
418    /// assignment operator.
419    ///
420    /// C++0x [class.copy]p27:
421    ///   A copy/move assignment operator for class X is trivial if it is
422    ///   neither user-provided nor deleted and if
423    ///    -- class X has no virtual functions and no virtual base classes, and
424    ///    -- the assignment operator selected to copy/move each direct base
425    ///       class subobject is trivial, and
426    ///    -- for each non-static data member of X that is of class type (or an
427    ///       array thereof), the assignment operator selected to copy/move
428    ///       that member is trivial;
429    ///   otherwise the copy/move assignment operator is non-trivial.
430    bool HasTrivialMoveAssignment : 1;
431
432    /// HasTrivialDestructor - True when this class has a trivial destructor.
433    ///
434    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
435    /// implicitly-declared destructor and if:
436    /// * all of the direct base classes of its class have trivial destructors
437    ///   and
438    /// * for all of the non-static data members of its class that are of class
439    ///   type (or array thereof), each such class has a trivial destructor.
440    bool HasTrivialDestructor : 1;
441
442    /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
443    /// one non-static data member or base class of non literal type.
444    bool HasNonLiteralTypeFieldsOrBases : 1;
445
446    /// ComputedVisibleConversions - True when visible conversion functions are
447    /// already computed and are available.
448    bool ComputedVisibleConversions : 1;
449
450    /// \brief Whether we have a C++0x user-provided default constructor (not
451    /// explicitly deleted or defaulted).
452    bool UserProvidedDefaultConstructor : 1;
453
454    /// \brief Whether we have already declared the default constructor.
455    bool DeclaredDefaultConstructor : 1;
456
457    /// \brief Whether we have already declared the copy constructor.
458    bool DeclaredCopyConstructor : 1;
459
460    /// \brief Whether we have already declared the move constructor.
461    bool DeclaredMoveConstructor : 1;
462
463    /// \brief Whether we have already declared the copy-assignment operator.
464    bool DeclaredCopyAssignment : 1;
465
466    /// \brief Whether we have already declared the move-assignment operator.
467    bool DeclaredMoveAssignment : 1;
468
469    /// \brief Whether we have already declared a destructor within the class.
470    bool DeclaredDestructor : 1;
471
472    /// \brief Whether an implicit move constructor was attempted to be declared
473    /// but would have been deleted.
474    bool FailedImplicitMoveConstructor : 1;
475
476    /// \brief Whether an implicit move assignment operator was attempted to be
477    /// declared but would have been deleted.
478    bool FailedImplicitMoveAssignment : 1;
479
480    /// NumBases - The number of base class specifiers in Bases.
481    unsigned NumBases;
482
483    /// NumVBases - The number of virtual base class specifiers in VBases.
484    unsigned NumVBases;
485
486    /// Bases - Base classes of this class.
487    /// FIXME: This is wasted space for a union.
488    LazyCXXBaseSpecifiersPtr Bases;
489
490    /// VBases - direct and indirect virtual base classes of this class.
491    LazyCXXBaseSpecifiersPtr VBases;
492
493    /// Conversions - Overload set containing the conversion functions
494    /// of this C++ class (but not its inherited conversion
495    /// functions). Each of the entries in this overload set is a
496    /// CXXConversionDecl.
497    UnresolvedSet<4> Conversions;
498
499    /// VisibleConversions - Overload set containing the conversion
500    /// functions of this C++ class and all those inherited conversion
501    /// functions that are visible in this class. Each of the entries
502    /// in this overload set is a CXXConversionDecl or a
503    /// FunctionTemplateDecl.
504    UnresolvedSet<4> VisibleConversions;
505
506    /// Definition - The declaration which defines this record.
507    CXXRecordDecl *Definition;
508
509    /// FirstFriend - The first friend declaration in this class, or
510    /// null if there aren't any.  This is actually currently stored
511    /// in reverse order.
512    FriendDecl *FirstFriend;
513
514    /// \brief Retrieve the set of direct base classes.
515    CXXBaseSpecifier *getBases() const {
516      return Bases.get(Definition->getASTContext().getExternalSource());
517    }
518
519    /// \brief Retrieve the set of virtual base classes.
520    CXXBaseSpecifier *getVBases() const {
521      return VBases.get(Definition->getASTContext().getExternalSource());
522    }
523  } *DefinitionData;
524
525  struct DefinitionData &data() {
526    assert(DefinitionData && "queried property of class with no definition");
527    return *DefinitionData;
528  }
529
530  const struct DefinitionData &data() const {
531    assert(DefinitionData && "queried property of class with no definition");
532    return *DefinitionData;
533  }
534
535  /// \brief The template or declaration that this declaration
536  /// describes or was instantiated from, respectively.
537  ///
538  /// For non-templates, this value will be NULL. For record
539  /// declarations that describe a class template, this will be a
540  /// pointer to a ClassTemplateDecl. For member
541  /// classes of class template specializations, this will be the
542  /// MemberSpecializationInfo referring to the member class that was
543  /// instantiated or specialized.
544  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
545    TemplateOrInstantiation;
546
547  friend class DeclContext;
548
549  /// \brief Notify the class that member has been added.
550  ///
551  /// This routine helps maintain information about the class based on which
552  /// members have been added. It will be invoked by DeclContext::addDecl()
553  /// whenever a member is added to this record.
554  void addedMember(Decl *D);
555
556  void markedVirtualFunctionPure();
557  friend void FunctionDecl::setPure(bool);
558
559  friend class ASTNodeImporter;
560
561protected:
562  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
563                SourceLocation StartLoc, SourceLocation IdLoc,
564                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
565
566public:
567  /// base_class_iterator - Iterator that traverses the base classes
568  /// of a class.
569  typedef CXXBaseSpecifier*       base_class_iterator;
570
571  /// base_class_const_iterator - Iterator that traverses the base
572  /// classes of a class.
573  typedef const CXXBaseSpecifier* base_class_const_iterator;
574
575  /// reverse_base_class_iterator = Iterator that traverses the base classes
576  /// of a class in reverse order.
577  typedef std::reverse_iterator<base_class_iterator>
578    reverse_base_class_iterator;
579
580  /// reverse_base_class_iterator = Iterator that traverses the base classes
581  /// of a class in reverse order.
582  typedef std::reverse_iterator<base_class_const_iterator>
583    reverse_base_class_const_iterator;
584
585  virtual CXXRecordDecl *getCanonicalDecl() {
586    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
587  }
588  virtual const CXXRecordDecl *getCanonicalDecl() const {
589    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
590  }
591
592  const CXXRecordDecl *getPreviousDeclaration() const {
593    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
594  }
595  CXXRecordDecl *getPreviousDeclaration() {
596    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
597  }
598
599  CXXRecordDecl *getDefinition() const {
600    if (!DefinitionData) return 0;
601    return data().Definition;
602  }
603
604  bool hasDefinition() const { return DefinitionData != 0; }
605
606  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
607                               SourceLocation StartLoc, SourceLocation IdLoc,
608                               IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
609                               bool DelayTypeCreation = false);
610  static CXXRecordDecl *Create(const ASTContext &C, EmptyShell Empty);
611
612  bool isDynamicClass() const {
613    return data().Polymorphic || data().NumVBases != 0;
614  }
615
616  /// setBases - Sets the base classes of this struct or class.
617  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
618
619  /// getNumBases - Retrieves the number of base classes of this
620  /// class.
621  unsigned getNumBases() const { return data().NumBases; }
622
623  base_class_iterator bases_begin() { return data().getBases(); }
624  base_class_const_iterator bases_begin() const { return data().getBases(); }
625  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
626  base_class_const_iterator bases_end() const {
627    return bases_begin() + data().NumBases;
628  }
629  reverse_base_class_iterator       bases_rbegin() {
630    return reverse_base_class_iterator(bases_end());
631  }
632  reverse_base_class_const_iterator bases_rbegin() const {
633    return reverse_base_class_const_iterator(bases_end());
634  }
635  reverse_base_class_iterator bases_rend() {
636    return reverse_base_class_iterator(bases_begin());
637  }
638  reverse_base_class_const_iterator bases_rend() const {
639    return reverse_base_class_const_iterator(bases_begin());
640  }
641
642  /// getNumVBases - Retrieves the number of virtual base classes of this
643  /// class.
644  unsigned getNumVBases() const { return data().NumVBases; }
645
646  base_class_iterator vbases_begin() { return data().getVBases(); }
647  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
648  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
649  base_class_const_iterator vbases_end() const {
650    return vbases_begin() + data().NumVBases;
651  }
652  reverse_base_class_iterator vbases_rbegin() {
653    return reverse_base_class_iterator(vbases_end());
654  }
655  reverse_base_class_const_iterator vbases_rbegin() const {
656    return reverse_base_class_const_iterator(vbases_end());
657  }
658  reverse_base_class_iterator vbases_rend() {
659    return reverse_base_class_iterator(vbases_begin());
660  }
661  reverse_base_class_const_iterator vbases_rend() const {
662    return reverse_base_class_const_iterator(vbases_begin());
663 }
664
665  /// \brief Determine whether this class has any dependent base classes.
666  bool hasAnyDependentBases() const;
667
668  /// Iterator access to method members.  The method iterator visits
669  /// all method members of the class, including non-instance methods,
670  /// special methods, etc.
671  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
672
673  /// method_begin - Method begin iterator.  Iterates in the order the methods
674  /// were declared.
675  method_iterator method_begin() const {
676    return method_iterator(decls_begin());
677  }
678  /// method_end - Method end iterator.
679  method_iterator method_end() const {
680    return method_iterator(decls_end());
681  }
682
683  /// Iterator access to constructor members.
684  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
685
686  ctor_iterator ctor_begin() const {
687    return ctor_iterator(decls_begin());
688  }
689  ctor_iterator ctor_end() const {
690    return ctor_iterator(decls_end());
691  }
692
693  /// An iterator over friend declarations.  All of these are defined
694  /// in DeclFriend.h.
695  class friend_iterator;
696  friend_iterator friend_begin() const;
697  friend_iterator friend_end() const;
698  void pushFriendDecl(FriendDecl *FD);
699
700  /// Determines whether this record has any friends.
701  bool hasFriends() const {
702    return data().FirstFriend != 0;
703  }
704
705  /// \brief Determine if we need to declare a default constructor for
706  /// this class.
707  ///
708  /// This value is used for lazy creation of default constructors.
709  bool needsImplicitDefaultConstructor() const {
710    return !data().UserDeclaredConstructor &&
711           !data().DeclaredDefaultConstructor;
712  }
713
714  /// hasDeclaredDefaultConstructor - Whether this class's default constructor
715  /// has been declared (either explicitly or implicitly).
716  bool hasDeclaredDefaultConstructor() const {
717    return data().DeclaredDefaultConstructor;
718  }
719
720  /// hasConstCopyConstructor - Determines whether this class has a
721  /// copy constructor that accepts a const-qualified argument.
722  bool hasConstCopyConstructor() const;
723
724  /// getCopyConstructor - Returns the copy constructor for this class
725  CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const;
726
727  /// getMoveConstructor - Returns the move constructor for this class
728  CXXConstructorDecl *getMoveConstructor() const;
729
730  /// \brief Retrieve the copy-assignment operator for this class, if available.
731  ///
732  /// This routine attempts to find the copy-assignment operator for this
733  /// class, using a simplistic form of overload resolution.
734  ///
735  /// \param ArgIsConst Whether the argument to the copy-assignment operator
736  /// is const-qualified.
737  ///
738  /// \returns The copy-assignment operator that can be invoked, or NULL if
739  /// a unique copy-assignment operator could not be found.
740  CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
741
742  /// getMoveAssignmentOperator - Returns the move assignment operator for this
743  /// class
744  CXXMethodDecl *getMoveAssignmentOperator() const;
745
746  /// hasUserDeclaredConstructor - Whether this class has any
747  /// user-declared constructors. When true, a default constructor
748  /// will not be implicitly declared.
749  bool hasUserDeclaredConstructor() const {
750    return data().UserDeclaredConstructor;
751  }
752
753  /// hasUserProvidedDefaultconstructor - Whether this class has a
754  /// user-provided default constructor per C++0x.
755  bool hasUserProvidedDefaultConstructor() const {
756    return data().UserProvidedDefaultConstructor;
757  }
758
759  /// hasUserDeclaredCopyConstructor - Whether this class has a
760  /// user-declared copy constructor. When false, a copy constructor
761  /// will be implicitly declared.
762  bool hasUserDeclaredCopyConstructor() const {
763    return data().UserDeclaredCopyConstructor;
764  }
765
766  /// \brief Determine whether this class has had its copy constructor
767  /// declared, either via the user or via an implicit declaration.
768  ///
769  /// This value is used for lazy creation of copy constructors.
770  bool hasDeclaredCopyConstructor() const {
771    return data().DeclaredCopyConstructor;
772  }
773
774  /// hasUserDeclaredMoveOperation - Whether this class has a user-
775  /// declared move constructor or assignment operator. When false, a
776  /// move constructor and assignment operator may be implicitly declared.
777  bool hasUserDeclaredMoveOperation() const {
778    return data().UserDeclaredMoveConstructor ||
779           data().UserDeclaredMoveAssignment;
780  }
781
782  /// \brief Determine whether this class has had a move constructor
783  /// declared by the user.
784  bool hasUserDeclaredMoveConstructor() const {
785    return data().UserDeclaredMoveConstructor;
786  }
787
788  /// \brief Determine whether this class has had a move constructor
789  /// declared.
790  bool hasDeclaredMoveConstructor() const {
791    return data().DeclaredMoveConstructor;
792  }
793
794  /// \brief Determine whether implicit move constructor generation for this
795  /// class has failed before.
796  bool hasFailedImplicitMoveConstructor() const {
797    return data().FailedImplicitMoveConstructor;
798  }
799
800  /// \brief Set whether implicit move constructor generation for this class
801  /// has failed before.
802  void setFailedImplicitMoveConstructor(bool Failed = true) {
803    data().FailedImplicitMoveConstructor = Failed;
804  }
805
806  /// \brief Determine whether this class should get an implicit move
807  /// constructor or if any existing special member function inhibits this.
808  ///
809  /// Covers all bullets of C++0x [class.copy]p9 except the last, that the
810  /// constructor wouldn't be deleted, which is only looked up from a cached
811  /// result.
812  bool needsImplicitMoveConstructor() const {
813    return !hasFailedImplicitMoveConstructor() &&
814           !hasDeclaredMoveConstructor() &&
815           !hasUserDeclaredCopyConstructor() &&
816           !hasUserDeclaredCopyAssignment() &&
817           !hasUserDeclaredMoveAssignment() &&
818           !hasUserDeclaredDestructor();
819  }
820
821  /// hasUserDeclaredCopyAssignment - Whether this class has a
822  /// user-declared copy assignment operator. When false, a copy
823  /// assigment operator will be implicitly declared.
824  bool hasUserDeclaredCopyAssignment() const {
825    return data().UserDeclaredCopyAssignment;
826  }
827
828  /// \brief Determine whether this class has had its copy assignment operator
829  /// declared, either via the user or via an implicit declaration.
830  ///
831  /// This value is used for lazy creation of copy assignment operators.
832  bool hasDeclaredCopyAssignment() const {
833    return data().DeclaredCopyAssignment;
834  }
835
836  /// \brief Determine whether this class has had a move assignment
837  /// declared by the user.
838  bool hasUserDeclaredMoveAssignment() const {
839    return data().UserDeclaredMoveAssignment;
840  }
841
842  /// hasDeclaredMoveAssignment - Whether this class has a
843  /// declared move assignment operator.
844  bool hasDeclaredMoveAssignment() const {
845    return data().DeclaredMoveAssignment;
846  }
847
848  /// \brief Determine whether implicit move assignment generation for this
849  /// class has failed before.
850  bool hasFailedImplicitMoveAssignment() const {
851    return data().FailedImplicitMoveAssignment;
852  }
853
854  /// \brief Set whether implicit move assignment generation for this class
855  /// has failed before.
856  void setFailedImplicitMoveAssignment(bool Failed = true) {
857    data().FailedImplicitMoveAssignment = Failed;
858  }
859
860  /// \brief Determine whether this class should get an implicit move
861  /// assignment operator or if any existing special member function inhibits
862  /// this.
863  ///
864  /// Covers all bullets of C++0x [class.copy]p20 except the last, that the
865  /// constructor wouldn't be deleted.
866  bool needsImplicitMoveAssignment() const {
867    return !hasFailedImplicitMoveAssignment() &&
868           !hasDeclaredMoveAssignment() &&
869           !hasUserDeclaredCopyConstructor() &&
870           !hasUserDeclaredCopyAssignment() &&
871           !hasUserDeclaredMoveConstructor() &&
872           !hasUserDeclaredDestructor();
873  }
874
875  /// hasUserDeclaredDestructor - Whether this class has a
876  /// user-declared destructor. When false, a destructor will be
877  /// implicitly declared.
878  bool hasUserDeclaredDestructor() const {
879    return data().UserDeclaredDestructor;
880  }
881
882  /// \brief Determine whether this class has had its destructor declared,
883  /// either via the user or via an implicit declaration.
884  ///
885  /// This value is used for lazy creation of destructors.
886  bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
887
888  /// getConversions - Retrieve the overload set containing all of the
889  /// conversion functions in this class.
890  UnresolvedSetImpl *getConversionFunctions() {
891    return &data().Conversions;
892  }
893  const UnresolvedSetImpl *getConversionFunctions() const {
894    return &data().Conversions;
895  }
896
897  typedef UnresolvedSetImpl::iterator conversion_iterator;
898  conversion_iterator conversion_begin() const {
899    return getConversionFunctions()->begin();
900  }
901  conversion_iterator conversion_end() const {
902    return getConversionFunctions()->end();
903  }
904
905  /// Removes a conversion function from this class.  The conversion
906  /// function must currently be a member of this class.  Furthermore,
907  /// this class must currently be in the process of being defined.
908  void removeConversion(const NamedDecl *Old);
909
910  /// getVisibleConversionFunctions - get all conversion functions visible
911  /// in current class; including conversion function templates.
912  const UnresolvedSetImpl *getVisibleConversionFunctions();
913
914  /// isAggregate - Whether this class is an aggregate (C++
915  /// [dcl.init.aggr]), which is a class with no user-declared
916  /// constructors, no private or protected non-static data members,
917  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
918  bool isAggregate() const { return data().Aggregate; }
919
920  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
921  /// that is an aggregate that has no non-static non-POD data members, no
922  /// reference data members, no user-defined copy assignment operator and no
923  /// user-defined destructor.
924  bool isPOD() const { return data().PlainOldData; }
925
926  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
927  /// means it has a virtual function, virtual base, data member (other than
928  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
929  /// a check for union-ness.
930  bool isEmpty() const { return data().Empty; }
931
932  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
933  /// which means that the class contains or inherits a virtual function.
934  bool isPolymorphic() const { return data().Polymorphic; }
935
936  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
937  /// which means that the class contains or inherits a pure virtual function.
938  bool isAbstract() const { return data().Abstract; }
939
940  /// isStandardLayout - Whether this class has standard layout
941  /// (C++ [class]p7)
942  bool isStandardLayout() const { return data().IsStandardLayout; }
943
944  /// \brief Whether this class, or any of its class subobjects, contains a
945  /// mutable field.
946  bool hasMutableFields() const { return data().HasMutableFields; }
947
948  // hasTrivialDefaultConstructor - Whether this class has a trivial default
949  // constructor
950  // (C++0x [class.ctor]p5)
951  bool hasTrivialDefaultConstructor() const {
952    return data().HasTrivialDefaultConstructor &&
953           (!data().UserDeclaredConstructor ||
954             data().DeclaredDefaultConstructor);
955  }
956
957  // hasConstexprNonCopyMoveConstructor - Whether this class has at least one
958  // constexpr constructor other than the copy or move constructors.
959  bool hasConstexprNonCopyMoveConstructor() const {
960    return data().HasConstexprNonCopyMoveConstructor;
961  }
962
963  // hasTrivialCopyConstructor - Whether this class has a trivial copy
964  // constructor (C++ [class.copy]p6, C++0x [class.copy]p13)
965  bool hasTrivialCopyConstructor() const {
966    return data().HasTrivialCopyConstructor;
967  }
968
969  // hasTrivialMoveConstructor - Whether this class has a trivial move
970  // constructor (C++0x [class.copy]p13)
971  bool hasTrivialMoveConstructor() const {
972    return data().HasTrivialMoveConstructor;
973  }
974
975  // hasTrivialCopyAssignment - Whether this class has a trivial copy
976  // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27)
977  bool hasTrivialCopyAssignment() const {
978    return data().HasTrivialCopyAssignment;
979  }
980
981  // hasTrivialMoveAssignment - Whether this class has a trivial move
982  // assignment operator (C++0x [class.copy]p27)
983  bool hasTrivialMoveAssignment() const {
984    return data().HasTrivialMoveAssignment;
985  }
986
987  // hasTrivialDestructor - Whether this class has a trivial destructor
988  // (C++ [class.dtor]p3)
989  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
990
991  // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal type
992  // non-static data member or base class.
993  bool hasNonLiteralTypeFieldsOrBases() const {
994    return data().HasNonLiteralTypeFieldsOrBases;
995  }
996
997  // isTriviallyCopyable - Whether this class is considered trivially copyable
998  // (C++0x [class]p6).
999  bool isTriviallyCopyable() const;
1000
1001  // isTrivial - Whether this class is considered trivial
1002  //
1003  // C++0x [class]p6
1004  //    A trivial class is a class that has a trivial default constructor and
1005  //    is trivially copiable.
1006  bool isTrivial() const {
1007    return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1008  }
1009
1010  // isLiteral - Whether this class is a literal type.
1011  //
1012  // C++0x [basic.types]p10
1013  //   A class type that has all the following properties:
1014  //     -- a trivial destructor
1015  //     -- every constructor call and full-expression in the
1016  //        brace-or-equal-intializers for non-static data members (if any) is
1017  //        a constant expression.
1018  //     -- it is an aggregate type or has at least one constexpr constructor or
1019  //        constructor template that is not a copy or move constructor, and
1020  //     -- all non-static data members and base classes of literal types
1021  //
1022  // We resolve DR1361 by ignoring the second bullet.
1023  bool isLiteral() const {
1024    return hasTrivialDestructor() &&
1025           (isAggregate() || hasConstexprNonCopyMoveConstructor()) &&
1026           !hasNonLiteralTypeFieldsOrBases();
1027  }
1028
1029  /// \brief If this record is an instantiation of a member class,
1030  /// retrieves the member class from which it was instantiated.
1031  ///
1032  /// This routine will return non-NULL for (non-templated) member
1033  /// classes of class templates. For example, given:
1034  ///
1035  /// \code
1036  /// template<typename T>
1037  /// struct X {
1038  ///   struct A { };
1039  /// };
1040  /// \endcode
1041  ///
1042  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1043  /// whose parent is the class template specialization X<int>. For
1044  /// this declaration, getInstantiatedFromMemberClass() will return
1045  /// the CXXRecordDecl X<T>::A. When a complete definition of
1046  /// X<int>::A is required, it will be instantiated from the
1047  /// declaration returned by getInstantiatedFromMemberClass().
1048  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1049
1050  /// \brief If this class is an instantiation of a member class of a
1051  /// class template specialization, retrieves the member specialization
1052  /// information.
1053  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1054
1055  /// \brief Specify that this record is an instantiation of the
1056  /// member class RD.
1057  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1058                                     TemplateSpecializationKind TSK);
1059
1060  /// \brief Retrieves the class template that is described by this
1061  /// class declaration.
1062  ///
1063  /// Every class template is represented as a ClassTemplateDecl and a
1064  /// CXXRecordDecl. The former contains template properties (such as
1065  /// the template parameter lists) while the latter contains the
1066  /// actual description of the template's
1067  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1068  /// CXXRecordDecl that from a ClassTemplateDecl, while
1069  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1070  /// a CXXRecordDecl.
1071  ClassTemplateDecl *getDescribedClassTemplate() const {
1072    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1073  }
1074
1075  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1076    TemplateOrInstantiation = Template;
1077  }
1078
1079  /// \brief Determine whether this particular class is a specialization or
1080  /// instantiation of a class template or member class of a class template,
1081  /// and how it was instantiated or specialized.
1082  TemplateSpecializationKind getTemplateSpecializationKind() const;
1083
1084  /// \brief Set the kind of specialization or template instantiation this is.
1085  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1086
1087  /// getDestructor - Returns the destructor decl for this class.
1088  CXXDestructorDecl *getDestructor() const;
1089
1090  /// isLocalClass - If the class is a local class [class.local], returns
1091  /// the enclosing function declaration.
1092  const FunctionDecl *isLocalClass() const {
1093    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1094      return RD->isLocalClass();
1095
1096    return dyn_cast<FunctionDecl>(getDeclContext());
1097  }
1098
1099  /// \brief Determine whether this class is derived from the class \p Base.
1100  ///
1101  /// This routine only determines whether this class is derived from \p Base,
1102  /// but does not account for factors that may make a Derived -> Base class
1103  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1104  /// base class subobjects.
1105  ///
1106  /// \param Base the base class we are searching for.
1107  ///
1108  /// \returns true if this class is derived from Base, false otherwise.
1109  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1110
1111  /// \brief Determine whether this class is derived from the type \p Base.
1112  ///
1113  /// This routine only determines whether this class is derived from \p Base,
1114  /// but does not account for factors that may make a Derived -> Base class
1115  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1116  /// base class subobjects.
1117  ///
1118  /// \param Base the base class we are searching for.
1119  ///
1120  /// \param Paths will contain the paths taken from the current class to the
1121  /// given \p Base class.
1122  ///
1123  /// \returns true if this class is derived from Base, false otherwise.
1124  ///
1125  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1126  /// tangling input and output in \p Paths
1127  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1128
1129  /// \brief Determine whether this class is virtually derived from
1130  /// the class \p Base.
1131  ///
1132  /// This routine only determines whether this class is virtually
1133  /// derived from \p Base, but does not account for factors that may
1134  /// make a Derived -> Base class ill-formed, such as
1135  /// private/protected inheritance or multiple, ambiguous base class
1136  /// subobjects.
1137  ///
1138  /// \param Base the base class we are searching for.
1139  ///
1140  /// \returns true if this class is virtually derived from Base,
1141  /// false otherwise.
1142  bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
1143
1144  /// \brief Determine whether this class is provably not derived from
1145  /// the type \p Base.
1146  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1147
1148  /// \brief Function type used by forallBases() as a callback.
1149  ///
1150  /// \param Base the definition of the base class
1151  ///
1152  /// \returns true if this base matched the search criteria
1153  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1154                                   void *UserData);
1155
1156  /// \brief Determines if the given callback holds for all the direct
1157  /// or indirect base classes of this type.
1158  ///
1159  /// The class itself does not count as a base class.  This routine
1160  /// returns false if the class has non-computable base classes.
1161  ///
1162  /// \param AllowShortCircuit if false, forces the callback to be called
1163  /// for every base class, even if a dependent or non-matching base was
1164  /// found.
1165  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1166                   bool AllowShortCircuit = true) const;
1167
1168  /// \brief Function type used by lookupInBases() to determine whether a
1169  /// specific base class subobject matches the lookup criteria.
1170  ///
1171  /// \param Specifier the base-class specifier that describes the inheritance
1172  /// from the base class we are trying to match.
1173  ///
1174  /// \param Path the current path, from the most-derived class down to the
1175  /// base named by the \p Specifier.
1176  ///
1177  /// \param UserData a single pointer to user-specified data, provided to
1178  /// lookupInBases().
1179  ///
1180  /// \returns true if this base matched the search criteria, false otherwise.
1181  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1182                                   CXXBasePath &Path,
1183                                   void *UserData);
1184
1185  /// \brief Look for entities within the base classes of this C++ class,
1186  /// transitively searching all base class subobjects.
1187  ///
1188  /// This routine uses the callback function \p BaseMatches to find base
1189  /// classes meeting some search criteria, walking all base class subobjects
1190  /// and populating the given \p Paths structure with the paths through the
1191  /// inheritance hierarchy that resulted in a match. On a successful search,
1192  /// the \p Paths structure can be queried to retrieve the matching paths and
1193  /// to determine if there were any ambiguities.
1194  ///
1195  /// \param BaseMatches callback function used to determine whether a given
1196  /// base matches the user-defined search criteria.
1197  ///
1198  /// \param UserData user data pointer that will be provided to \p BaseMatches.
1199  ///
1200  /// \param Paths used to record the paths from this class to its base class
1201  /// subobjects that match the search criteria.
1202  ///
1203  /// \returns true if there exists any path from this class to a base class
1204  /// subobject that matches the search criteria.
1205  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1206                     CXXBasePaths &Paths) const;
1207
1208  /// \brief Base-class lookup callback that determines whether the given
1209  /// base class specifier refers to a specific class declaration.
1210  ///
1211  /// This callback can be used with \c lookupInBases() to determine whether
1212  /// a given derived class has is a base class subobject of a particular type.
1213  /// The user data pointer should refer to the canonical CXXRecordDecl of the
1214  /// base class that we are searching for.
1215  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1216                            CXXBasePath &Path, void *BaseRecord);
1217
1218  /// \brief Base-class lookup callback that determines whether the
1219  /// given base class specifier refers to a specific class
1220  /// declaration and describes virtual derivation.
1221  ///
1222  /// This callback can be used with \c lookupInBases() to determine
1223  /// whether a given derived class has is a virtual base class
1224  /// subobject of a particular type.  The user data pointer should
1225  /// refer to the canonical CXXRecordDecl of the base class that we
1226  /// are searching for.
1227  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1228                                   CXXBasePath &Path, void *BaseRecord);
1229
1230  /// \brief Base-class lookup callback that determines whether there exists
1231  /// a tag with the given name.
1232  ///
1233  /// This callback can be used with \c lookupInBases() to find tag members
1234  /// of the given name within a C++ class hierarchy. The user data pointer
1235  /// is an opaque \c DeclarationName pointer.
1236  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1237                            CXXBasePath &Path, void *Name);
1238
1239  /// \brief Base-class lookup callback that determines whether there exists
1240  /// a member with the given name.
1241  ///
1242  /// This callback can be used with \c lookupInBases() to find members
1243  /// of the given name within a C++ class hierarchy. The user data pointer
1244  /// is an opaque \c DeclarationName pointer.
1245  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1246                                 CXXBasePath &Path, void *Name);
1247
1248  /// \brief Base-class lookup callback that determines whether there exists
1249  /// a member with the given name that can be used in a nested-name-specifier.
1250  ///
1251  /// This callback can be used with \c lookupInBases() to find membes of
1252  /// the given name within a C++ class hierarchy that can occur within
1253  /// nested-name-specifiers.
1254  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1255                                            CXXBasePath &Path,
1256                                            void *UserData);
1257
1258  /// \brief Retrieve the final overriders for each virtual member
1259  /// function in the class hierarchy where this class is the
1260  /// most-derived class in the class hierarchy.
1261  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1262
1263  /// \brief Get the indirect primary bases for this class.
1264  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1265
1266  /// viewInheritance - Renders and displays an inheritance diagram
1267  /// for this C++ class and all of its base classes (transitively) using
1268  /// GraphViz.
1269  void viewInheritance(ASTContext& Context) const;
1270
1271  /// MergeAccess - Calculates the access of a decl that is reached
1272  /// along a path.
1273  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1274                                     AccessSpecifier DeclAccess) {
1275    assert(DeclAccess != AS_none);
1276    if (DeclAccess == AS_private) return AS_none;
1277    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1278  }
1279
1280  /// \brief Indicates that the definition of this class is now complete.
1281  virtual void completeDefinition();
1282
1283  /// \brief Indicates that the definition of this class is now complete,
1284  /// and provides a final overrider map to help determine
1285  ///
1286  /// \param FinalOverriders The final overrider map for this class, which can
1287  /// be provided as an optimization for abstract-class checking. If NULL,
1288  /// final overriders will be computed if they are needed to complete the
1289  /// definition.
1290  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1291
1292  /// \brief Determine whether this class may end up being abstract, even though
1293  /// it is not yet known to be abstract.
1294  ///
1295  /// \returns true if this class is not known to be abstract but has any
1296  /// base classes that are abstract. In this case, \c completeDefinition()
1297  /// will need to compute final overriders to determine whether the class is
1298  /// actually abstract.
1299  bool mayBeAbstract() const;
1300
1301  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1302  static bool classofKind(Kind K) {
1303    return K >= firstCXXRecord && K <= lastCXXRecord;
1304  }
1305  static bool classof(const CXXRecordDecl *D) { return true; }
1306  static bool classof(const ClassTemplateSpecializationDecl *D) {
1307    return true;
1308  }
1309
1310  friend class ASTDeclReader;
1311  friend class ASTDeclWriter;
1312  friend class ASTReader;
1313  friend class ASTWriter;
1314};
1315
1316/// CXXMethodDecl - Represents a static or instance method of a
1317/// struct/union/class.
1318class CXXMethodDecl : public FunctionDecl {
1319protected:
1320  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1321                const DeclarationNameInfo &NameInfo,
1322                QualType T, TypeSourceInfo *TInfo,
1323                bool isStatic, StorageClass SCAsWritten, bool isInline,
1324                bool isConstexpr, SourceLocation EndLocation)
1325    : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1326                   (isStatic ? SC_Static : SC_None),
1327                   SCAsWritten, isInline, isConstexpr) {
1328      if (EndLocation.isValid())
1329        setRangeEnd(EndLocation);
1330    }
1331
1332public:
1333  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1334                               SourceLocation StartLoc,
1335                               const DeclarationNameInfo &NameInfo,
1336                               QualType T, TypeSourceInfo *TInfo,
1337                               bool isStatic,
1338                               StorageClass SCAsWritten,
1339                               bool isInline,
1340                               bool isConstexpr,
1341                               SourceLocation EndLocation);
1342
1343  bool isStatic() const { return getStorageClass() == SC_Static; }
1344  bool isInstance() const { return !isStatic(); }
1345
1346  bool isVirtual() const {
1347    CXXMethodDecl *CD =
1348      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1349
1350    if (CD->isVirtualAsWritten())
1351      return true;
1352
1353    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1354  }
1355
1356  /// \brief Determine whether this is a usual deallocation function
1357  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1358  /// delete or delete[] operator with a particular signature.
1359  bool isUsualDeallocationFunction() const;
1360
1361  /// \brief Determine whether this is a copy-assignment operator, regardless
1362  /// of whether it was declared implicitly or explicitly.
1363  bool isCopyAssignmentOperator() const;
1364
1365  /// \brief Determine whether this is a move assignment operator.
1366  bool isMoveAssignmentOperator() const;
1367
1368  const CXXMethodDecl *getCanonicalDecl() const {
1369    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1370  }
1371  CXXMethodDecl *getCanonicalDecl() {
1372    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1373  }
1374
1375  /// isUserProvided - True if it is either an implicit constructor or
1376  /// if it was defaulted or deleted on first declaration.
1377  bool isUserProvided() const {
1378    return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1379  }
1380
1381  ///
1382  void addOverriddenMethod(const CXXMethodDecl *MD);
1383
1384  typedef const CXXMethodDecl ** method_iterator;
1385
1386  method_iterator begin_overridden_methods() const;
1387  method_iterator end_overridden_methods() const;
1388  unsigned size_overridden_methods() const;
1389
1390  /// getParent - Returns the parent of this method declaration, which
1391  /// is the class in which this method is defined.
1392  const CXXRecordDecl *getParent() const {
1393    return cast<CXXRecordDecl>(FunctionDecl::getParent());
1394  }
1395
1396  /// getParent - Returns the parent of this method declaration, which
1397  /// is the class in which this method is defined.
1398  CXXRecordDecl *getParent() {
1399    return const_cast<CXXRecordDecl *>(
1400             cast<CXXRecordDecl>(FunctionDecl::getParent()));
1401  }
1402
1403  /// getThisType - Returns the type of 'this' pointer.
1404  /// Should only be called for instance methods.
1405  QualType getThisType(ASTContext &C) const;
1406
1407  unsigned getTypeQualifiers() const {
1408    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1409  }
1410
1411  /// \brief Retrieve the ref-qualifier associated with this method.
1412  ///
1413  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1414  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1415  /// \code
1416  /// struct X {
1417  ///   void f() &;
1418  ///   void g() &&;
1419  ///   void h();
1420  /// };
1421  /// \endcode
1422  RefQualifierKind getRefQualifier() const {
1423    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1424  }
1425
1426  bool hasInlineBody() const;
1427
1428  // Implement isa/cast/dyncast/etc.
1429  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1430  static bool classof(const CXXMethodDecl *D) { return true; }
1431  static bool classofKind(Kind K) {
1432    return K >= firstCXXMethod && K <= lastCXXMethod;
1433  }
1434};
1435
1436/// CXXCtorInitializer - Represents a C++ base or member
1437/// initializer, which is part of a constructor initializer that
1438/// initializes one non-static member variable or one base class. For
1439/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1440/// initializers:
1441///
1442/// @code
1443/// class A { };
1444/// class B : public A {
1445///   float f;
1446/// public:
1447///   B(A& a) : A(a), f(3.14159) { }
1448/// };
1449/// @endcode
1450class CXXCtorInitializer {
1451  /// \brief Either the base class name/delegating constructor type (stored as
1452  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1453  /// (IndirectFieldDecl*) being initialized.
1454  llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1455    Initializee;
1456
1457  /// \brief The source location for the field name or, for a base initializer
1458  /// pack expansion, the location of the ellipsis. In the case of a delegating
1459  /// constructor, it will still include the type's source location as the
1460  /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1461  SourceLocation MemberOrEllipsisLocation;
1462
1463  /// \brief The argument used to initialize the base or member, which may
1464  /// end up constructing an object (when multiple arguments are involved).
1465  /// If 0, this is a field initializer, and the in-class member initializer
1466  /// will be used.
1467  Stmt *Init;
1468
1469  /// LParenLoc - Location of the left paren of the ctor-initializer.
1470  SourceLocation LParenLoc;
1471
1472  /// RParenLoc - Location of the right paren of the ctor-initializer.
1473  SourceLocation RParenLoc;
1474
1475  /// \brief If the initializee is a type, whether that type makes this
1476  /// a delegating initialization.
1477  bool IsDelegating : 1;
1478
1479  /// IsVirtual - If the initializer is a base initializer, this keeps track
1480  /// of whether the base is virtual or not.
1481  bool IsVirtual : 1;
1482
1483  /// IsWritten - Whether or not the initializer is explicitly written
1484  /// in the sources.
1485  bool IsWritten : 1;
1486
1487  /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1488  /// number keeps track of the textual order of this initializer in the
1489  /// original sources, counting from 0; otherwise, if IsWritten is false,
1490  /// it stores the number of array index variables stored after this
1491  /// object in memory.
1492  unsigned SourceOrderOrNumArrayIndices : 13;
1493
1494  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1495                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1496                     SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1497
1498public:
1499  /// CXXCtorInitializer - Creates a new base-class initializer.
1500  explicit
1501  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1502                     SourceLocation L, Expr *Init, SourceLocation R,
1503                     SourceLocation EllipsisLoc);
1504
1505  /// CXXCtorInitializer - Creates a new member initializer.
1506  explicit
1507  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1508                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1509                     SourceLocation R);
1510
1511  /// CXXCtorInitializer - Creates a new anonymous field initializer.
1512  explicit
1513  CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1514                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1515                     SourceLocation R);
1516
1517  /// CXXCtorInitializer - Creates a new delegating Initializer.
1518  explicit
1519  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1520                     SourceLocation L, Expr *Init, SourceLocation R);
1521
1522  /// \brief Creates a new member initializer that optionally contains
1523  /// array indices used to describe an elementwise initialization.
1524  static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1525                                    SourceLocation MemberLoc, SourceLocation L,
1526                                    Expr *Init, SourceLocation R,
1527                                    VarDecl **Indices, unsigned NumIndices);
1528
1529  /// isBaseInitializer - Returns true when this initializer is
1530  /// initializing a base class.
1531  bool isBaseInitializer() const {
1532    return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1533  }
1534
1535  /// isMemberInitializer - Returns true when this initializer is
1536  /// initializing a non-static data member.
1537  bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1538
1539  bool isAnyMemberInitializer() const {
1540    return isMemberInitializer() || isIndirectMemberInitializer();
1541  }
1542
1543  bool isIndirectMemberInitializer() const {
1544    return Initializee.is<IndirectFieldDecl*>();
1545  }
1546
1547  /// isInClassMemberInitializer - Returns true when this initializer is an
1548  /// implicit ctor initializer generated for a field with an initializer
1549  /// defined on the member declaration.
1550  bool isInClassMemberInitializer() const {
1551    return !Init;
1552  }
1553
1554  /// isDelegatingInitializer - Returns true when this initializer is creating
1555  /// a delegating constructor.
1556  bool isDelegatingInitializer() const {
1557    return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1558  }
1559
1560  /// \brief Determine whether this initializer is a pack expansion.
1561  bool isPackExpansion() const {
1562    return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1563  }
1564
1565  // \brief For a pack expansion, returns the location of the ellipsis.
1566  SourceLocation getEllipsisLoc() const {
1567    assert(isPackExpansion() && "Initializer is not a pack expansion");
1568    return MemberOrEllipsisLocation;
1569  }
1570
1571  /// If this is a base class initializer, returns the type of the
1572  /// base class with location information. Otherwise, returns an NULL
1573  /// type location.
1574  TypeLoc getBaseClassLoc() const;
1575
1576  /// If this is a base class initializer, returns the type of the base class.
1577  /// Otherwise, returns NULL.
1578  const Type *getBaseClass() const;
1579
1580  /// Returns whether the base is virtual or not.
1581  bool isBaseVirtual() const {
1582    assert(isBaseInitializer() && "Must call this on base initializer!");
1583
1584    return IsVirtual;
1585  }
1586
1587  /// \brief Returns the declarator information for a base class or delegating
1588  /// initializer.
1589  TypeSourceInfo *getTypeSourceInfo() const {
1590    return Initializee.dyn_cast<TypeSourceInfo *>();
1591  }
1592
1593  /// getMember - If this is a member initializer, returns the
1594  /// declaration of the non-static data member being
1595  /// initialized. Otherwise, returns NULL.
1596  FieldDecl *getMember() const {
1597    if (isMemberInitializer())
1598      return Initializee.get<FieldDecl*>();
1599    return 0;
1600  }
1601  FieldDecl *getAnyMember() const {
1602    if (isMemberInitializer())
1603      return Initializee.get<FieldDecl*>();
1604    if (isIndirectMemberInitializer())
1605      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1606    return 0;
1607  }
1608
1609  IndirectFieldDecl *getIndirectMember() const {
1610    if (isIndirectMemberInitializer())
1611      return Initializee.get<IndirectFieldDecl*>();
1612    return 0;
1613  }
1614
1615  SourceLocation getMemberLocation() const {
1616    return MemberOrEllipsisLocation;
1617  }
1618
1619  /// \brief Determine the source location of the initializer.
1620  SourceLocation getSourceLocation() const;
1621
1622  /// \brief Determine the source range covering the entire initializer.
1623  SourceRange getSourceRange() const;
1624
1625  /// isWritten - Returns true if this initializer is explicitly written
1626  /// in the source code.
1627  bool isWritten() const { return IsWritten; }
1628
1629  /// \brief Return the source position of the initializer, counting from 0.
1630  /// If the initializer was implicit, -1 is returned.
1631  int getSourceOrder() const {
1632    return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1633  }
1634
1635  /// \brief Set the source order of this initializer. This method can only
1636  /// be called once for each initializer; it cannot be called on an
1637  /// initializer having a positive number of (implicit) array indices.
1638  void setSourceOrder(int pos) {
1639    assert(!IsWritten &&
1640           "calling twice setSourceOrder() on the same initializer");
1641    assert(SourceOrderOrNumArrayIndices == 0 &&
1642           "setSourceOrder() used when there are implicit array indices");
1643    assert(pos >= 0 &&
1644           "setSourceOrder() used to make an initializer implicit");
1645    IsWritten = true;
1646    SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1647  }
1648
1649  SourceLocation getLParenLoc() const { return LParenLoc; }
1650  SourceLocation getRParenLoc() const { return RParenLoc; }
1651
1652  /// \brief Determine the number of implicit array indices used while
1653  /// described an array member initialization.
1654  unsigned getNumArrayIndices() const {
1655    return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1656  }
1657
1658  /// \brief Retrieve a particular array index variable used to
1659  /// describe an array member initialization.
1660  VarDecl *getArrayIndex(unsigned I) {
1661    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1662    return reinterpret_cast<VarDecl **>(this + 1)[I];
1663  }
1664  const VarDecl *getArrayIndex(unsigned I) const {
1665    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1666    return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1667  }
1668  void setArrayIndex(unsigned I, VarDecl *Index) {
1669    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1670    reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1671  }
1672
1673  /// \brief Get the initializer. This is 0 if this is an in-class initializer
1674  /// for a non-static data member which has not yet been parsed.
1675  Expr *getInit() const {
1676    if (!Init)
1677      return getAnyMember()->getInClassInitializer();
1678
1679    return static_cast<Expr*>(Init);
1680  }
1681};
1682
1683/// CXXConstructorDecl - Represents a C++ constructor within a
1684/// class. For example:
1685///
1686/// @code
1687/// class X {
1688/// public:
1689///   explicit X(int); // represented by a CXXConstructorDecl.
1690/// };
1691/// @endcode
1692class CXXConstructorDecl : public CXXMethodDecl {
1693  /// IsExplicitSpecified - Whether this constructor declaration has the
1694  /// 'explicit' keyword specified.
1695  bool IsExplicitSpecified : 1;
1696
1697  /// ImplicitlyDefined - Whether this constructor was implicitly
1698  /// defined by the compiler. When false, the constructor was defined
1699  /// by the user. In C++03, this flag will have the same value as
1700  /// Implicit. In C++0x, however, a constructor that is
1701  /// explicitly defaulted (i.e., defined with " = default") will have
1702  /// @c !Implicit && ImplicitlyDefined.
1703  bool ImplicitlyDefined : 1;
1704
1705  /// Support for base and member initializers.
1706  /// CtorInitializers - The arguments used to initialize the base
1707  /// or member.
1708  CXXCtorInitializer **CtorInitializers;
1709  unsigned NumCtorInitializers;
1710
1711  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1712                     const DeclarationNameInfo &NameInfo,
1713                     QualType T, TypeSourceInfo *TInfo,
1714                     bool isExplicitSpecified, bool isInline,
1715                     bool isImplicitlyDeclared, bool isConstexpr)
1716    : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
1717                    SC_None, isInline, isConstexpr, SourceLocation()),
1718      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1719      CtorInitializers(0), NumCtorInitializers(0) {
1720    setImplicit(isImplicitlyDeclared);
1721  }
1722
1723public:
1724  static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
1725  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1726                                    SourceLocation StartLoc,
1727                                    const DeclarationNameInfo &NameInfo,
1728                                    QualType T, TypeSourceInfo *TInfo,
1729                                    bool isExplicit,
1730                                    bool isInline, bool isImplicitlyDeclared,
1731                                    bool isConstexpr);
1732
1733  /// isExplicitSpecified - Whether this constructor declaration has the
1734  /// 'explicit' keyword specified.
1735  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1736
1737  /// isExplicit - Whether this constructor was marked "explicit" or not.
1738  bool isExplicit() const {
1739    return cast<CXXConstructorDecl>(getFirstDeclaration())
1740      ->isExplicitSpecified();
1741  }
1742
1743  /// isImplicitlyDefined - Whether this constructor was implicitly
1744  /// defined. If false, then this constructor was defined by the
1745  /// user. This operation can only be invoked if the constructor has
1746  /// already been defined.
1747  bool isImplicitlyDefined() const {
1748    assert(isThisDeclarationADefinition() &&
1749           "Can only get the implicit-definition flag once the "
1750           "constructor has been defined");
1751    return ImplicitlyDefined;
1752  }
1753
1754  /// setImplicitlyDefined - Set whether this constructor was
1755  /// implicitly defined or not.
1756  void setImplicitlyDefined(bool ID) {
1757    assert(isThisDeclarationADefinition() &&
1758           "Can only set the implicit-definition flag once the constructor "
1759           "has been defined");
1760    ImplicitlyDefined = ID;
1761  }
1762
1763  /// init_iterator - Iterates through the member/base initializer list.
1764  typedef CXXCtorInitializer **init_iterator;
1765
1766  /// init_const_iterator - Iterates through the memberbase initializer list.
1767  typedef CXXCtorInitializer * const * init_const_iterator;
1768
1769  /// init_begin() - Retrieve an iterator to the first initializer.
1770  init_iterator       init_begin()       { return CtorInitializers; }
1771  /// begin() - Retrieve an iterator to the first initializer.
1772  init_const_iterator init_begin() const { return CtorInitializers; }
1773
1774  /// init_end() - Retrieve an iterator past the last initializer.
1775  init_iterator       init_end()       {
1776    return CtorInitializers + NumCtorInitializers;
1777  }
1778  /// end() - Retrieve an iterator past the last initializer.
1779  init_const_iterator init_end() const {
1780    return CtorInitializers + NumCtorInitializers;
1781  }
1782
1783  typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
1784  typedef std::reverse_iterator<init_const_iterator>
1785          init_const_reverse_iterator;
1786
1787  init_reverse_iterator init_rbegin() {
1788    return init_reverse_iterator(init_end());
1789  }
1790  init_const_reverse_iterator init_rbegin() const {
1791    return init_const_reverse_iterator(init_end());
1792  }
1793
1794  init_reverse_iterator init_rend() {
1795    return init_reverse_iterator(init_begin());
1796  }
1797  init_const_reverse_iterator init_rend() const {
1798    return init_const_reverse_iterator(init_begin());
1799  }
1800
1801  /// getNumArgs - Determine the number of arguments used to
1802  /// initialize the member or base.
1803  unsigned getNumCtorInitializers() const {
1804      return NumCtorInitializers;
1805  }
1806
1807  void setNumCtorInitializers(unsigned numCtorInitializers) {
1808    NumCtorInitializers = numCtorInitializers;
1809  }
1810
1811  void setCtorInitializers(CXXCtorInitializer ** initializers) {
1812    CtorInitializers = initializers;
1813  }
1814
1815  /// isDelegatingConstructor - Whether this constructor is a
1816  /// delegating constructor
1817  bool isDelegatingConstructor() const {
1818    return (getNumCtorInitializers() == 1) &&
1819      CtorInitializers[0]->isDelegatingInitializer();
1820  }
1821
1822  /// getTargetConstructor - When this constructor delegates to
1823  /// another, retrieve the target
1824  CXXConstructorDecl *getTargetConstructor() const;
1825
1826  /// isDefaultConstructor - Whether this constructor is a default
1827  /// constructor (C++ [class.ctor]p5), which can be used to
1828  /// default-initialize a class of this type.
1829  bool isDefaultConstructor() const;
1830
1831  /// isCopyConstructor - Whether this constructor is a copy
1832  /// constructor (C++ [class.copy]p2, which can be used to copy the
1833  /// class. @p TypeQuals will be set to the qualifiers on the
1834  /// argument type. For example, @p TypeQuals would be set to @c
1835  /// QualType::Const for the following copy constructor:
1836  ///
1837  /// @code
1838  /// class X {
1839  /// public:
1840  ///   X(const X&);
1841  /// };
1842  /// @endcode
1843  bool isCopyConstructor(unsigned &TypeQuals) const;
1844
1845  /// isCopyConstructor - Whether this constructor is a copy
1846  /// constructor (C++ [class.copy]p2, which can be used to copy the
1847  /// class.
1848  bool isCopyConstructor() const {
1849    unsigned TypeQuals = 0;
1850    return isCopyConstructor(TypeQuals);
1851  }
1852
1853  /// \brief Determine whether this constructor is a move constructor
1854  /// (C++0x [class.copy]p3), which can be used to move values of the class.
1855  ///
1856  /// \param TypeQuals If this constructor is a move constructor, will be set
1857  /// to the type qualifiers on the referent of the first parameter's type.
1858  bool isMoveConstructor(unsigned &TypeQuals) const;
1859
1860  /// \brief Determine whether this constructor is a move constructor
1861  /// (C++0x [class.copy]p3), which can be used to move values of the class.
1862  bool isMoveConstructor() const {
1863    unsigned TypeQuals = 0;
1864    return isMoveConstructor(TypeQuals);
1865  }
1866
1867  /// \brief Determine whether this is a copy or move constructor.
1868  ///
1869  /// \param TypeQuals Will be set to the type qualifiers on the reference
1870  /// parameter, if in fact this is a copy or move constructor.
1871  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
1872
1873  /// \brief Determine whether this a copy or move constructor.
1874  bool isCopyOrMoveConstructor() const {
1875    unsigned Quals;
1876    return isCopyOrMoveConstructor(Quals);
1877  }
1878
1879  /// isConvertingConstructor - Whether this constructor is a
1880  /// converting constructor (C++ [class.conv.ctor]), which can be
1881  /// used for user-defined conversions.
1882  bool isConvertingConstructor(bool AllowExplicit) const;
1883
1884  /// \brief Determine whether this is a member template specialization that
1885  /// would copy the object to itself. Such constructors are never used to copy
1886  /// an object.
1887  bool isSpecializationCopyingObject() const;
1888
1889  /// \brief Get the constructor that this inheriting constructor is based on.
1890  const CXXConstructorDecl *getInheritedConstructor() const;
1891
1892  /// \brief Set the constructor that this inheriting constructor is based on.
1893  void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
1894
1895  const CXXConstructorDecl *getCanonicalDecl() const {
1896    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
1897  }
1898  CXXConstructorDecl *getCanonicalDecl() {
1899    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
1900  }
1901
1902  // Implement isa/cast/dyncast/etc.
1903  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1904  static bool classof(const CXXConstructorDecl *D) { return true; }
1905  static bool classofKind(Kind K) { return K == CXXConstructor; }
1906
1907  friend class ASTDeclReader;
1908  friend class ASTDeclWriter;
1909};
1910
1911/// CXXDestructorDecl - Represents a C++ destructor within a
1912/// class. For example:
1913///
1914/// @code
1915/// class X {
1916/// public:
1917///   ~X(); // represented by a CXXDestructorDecl.
1918/// };
1919/// @endcode
1920class CXXDestructorDecl : public CXXMethodDecl {
1921  /// ImplicitlyDefined - Whether this destructor was implicitly
1922  /// defined by the compiler. When false, the destructor was defined
1923  /// by the user. In C++03, this flag will have the same value as
1924  /// Implicit. In C++0x, however, a destructor that is
1925  /// explicitly defaulted (i.e., defined with " = default") will have
1926  /// @c !Implicit && ImplicitlyDefined.
1927  bool ImplicitlyDefined : 1;
1928
1929  FunctionDecl *OperatorDelete;
1930
1931  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1932                    const DeclarationNameInfo &NameInfo,
1933                    QualType T, TypeSourceInfo *TInfo,
1934                    bool isInline, bool isImplicitlyDeclared)
1935    : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
1936                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
1937      ImplicitlyDefined(false), OperatorDelete(0) {
1938    setImplicit(isImplicitlyDeclared);
1939  }
1940
1941public:
1942  static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
1943  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1944                                   SourceLocation StartLoc,
1945                                   const DeclarationNameInfo &NameInfo,
1946                                   QualType T, TypeSourceInfo* TInfo,
1947                                   bool isInline,
1948                                   bool isImplicitlyDeclared);
1949
1950  /// isImplicitlyDefined - Whether this destructor was implicitly
1951  /// defined. If false, then this destructor was defined by the
1952  /// user. This operation can only be invoked if the destructor has
1953  /// already been defined.
1954  bool isImplicitlyDefined() const {
1955    assert(isThisDeclarationADefinition() &&
1956           "Can only get the implicit-definition flag once the destructor has "
1957           "been defined");
1958    return ImplicitlyDefined;
1959  }
1960
1961  /// setImplicitlyDefined - Set whether this destructor was
1962  /// implicitly defined or not.
1963  void setImplicitlyDefined(bool ID) {
1964    assert(isThisDeclarationADefinition() &&
1965           "Can only set the implicit-definition flag once the destructor has "
1966           "been defined");
1967    ImplicitlyDefined = ID;
1968  }
1969
1970  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1971  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1972
1973  // Implement isa/cast/dyncast/etc.
1974  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1975  static bool classof(const CXXDestructorDecl *D) { return true; }
1976  static bool classofKind(Kind K) { return K == CXXDestructor; }
1977
1978  friend class ASTDeclReader;
1979  friend class ASTDeclWriter;
1980};
1981
1982/// CXXConversionDecl - Represents a C++ conversion function within a
1983/// class. For example:
1984///
1985/// @code
1986/// class X {
1987/// public:
1988///   operator bool();
1989/// };
1990/// @endcode
1991class CXXConversionDecl : public CXXMethodDecl {
1992  /// IsExplicitSpecified - Whether this conversion function declaration is
1993  /// marked "explicit", meaning that it can only be applied when the user
1994  /// explicitly wrote a cast. This is a C++0x feature.
1995  bool IsExplicitSpecified : 1;
1996
1997  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1998                    const DeclarationNameInfo &NameInfo,
1999                    QualType T, TypeSourceInfo *TInfo,
2000                    bool isInline, bool isExplicitSpecified,
2001                    bool isConstexpr, SourceLocation EndLocation)
2002    : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
2003                    SC_None, isInline, isConstexpr, EndLocation),
2004      IsExplicitSpecified(isExplicitSpecified) { }
2005
2006public:
2007  static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
2008  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2009                                   SourceLocation StartLoc,
2010                                   const DeclarationNameInfo &NameInfo,
2011                                   QualType T, TypeSourceInfo *TInfo,
2012                                   bool isInline, bool isExplicit,
2013                                   bool isConstexpr,
2014                                   SourceLocation EndLocation);
2015
2016  /// IsExplicitSpecified - Whether this conversion function declaration is
2017  /// marked "explicit", meaning that it can only be applied when the user
2018  /// explicitly wrote a cast. This is a C++0x feature.
2019  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2020
2021  /// isExplicit - Whether this is an explicit conversion operator
2022  /// (C++0x only). Explicit conversion operators are only considered
2023  /// when the user has explicitly written a cast.
2024  bool isExplicit() const {
2025    return cast<CXXConversionDecl>(getFirstDeclaration())
2026      ->isExplicitSpecified();
2027  }
2028
2029  /// getConversionType - Returns the type that this conversion
2030  /// function is converting to.
2031  QualType getConversionType() const {
2032    return getType()->getAs<FunctionType>()->getResultType();
2033  }
2034
2035  // Implement isa/cast/dyncast/etc.
2036  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2037  static bool classof(const CXXConversionDecl *D) { return true; }
2038  static bool classofKind(Kind K) { return K == CXXConversion; }
2039
2040  friend class ASTDeclReader;
2041  friend class ASTDeclWriter;
2042};
2043
2044/// LinkageSpecDecl - This represents a linkage specification.  For example:
2045///   extern "C" void foo();
2046///
2047class LinkageSpecDecl : public Decl, public DeclContext {
2048public:
2049  /// LanguageIDs - Used to represent the language in a linkage
2050  /// specification.  The values are part of the serialization abi for
2051  /// ASTs and cannot be changed without altering that abi.  To help
2052  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
2053  /// from the dwarf standard.
2054  enum LanguageIDs {
2055    lang_c = /* DW_LANG_C */ 0x0002,
2056    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2057  };
2058private:
2059  /// Language - The language for this linkage specification.
2060  LanguageIDs Language;
2061  /// ExternLoc - The source location for the extern keyword.
2062  SourceLocation ExternLoc;
2063  /// RBraceLoc - The source location for the right brace (if valid).
2064  SourceLocation RBraceLoc;
2065
2066  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2067                  SourceLocation LangLoc, LanguageIDs lang,
2068                  SourceLocation RBLoc)
2069    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2070      Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
2071
2072public:
2073  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2074                                 SourceLocation ExternLoc,
2075                                 SourceLocation LangLoc, LanguageIDs Lang,
2076                                 SourceLocation RBraceLoc = SourceLocation());
2077
2078  /// \brief Return the language specified by this linkage specification.
2079  LanguageIDs getLanguage() const { return Language; }
2080  /// \brief Set the language specified by this linkage specification.
2081  void setLanguage(LanguageIDs L) { Language = L; }
2082
2083  /// \brief Determines whether this linkage specification had braces in
2084  /// its syntactic form.
2085  bool hasBraces() const { return RBraceLoc.isValid(); }
2086
2087  SourceLocation getExternLoc() const { return ExternLoc; }
2088  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2089  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2090  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2091
2092  SourceLocation getLocEnd() const {
2093    if (hasBraces())
2094      return getRBraceLoc();
2095    // No braces: get the end location of the (only) declaration in context
2096    // (if present).
2097    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2098  }
2099
2100  SourceRange getSourceRange() const {
2101    return SourceRange(ExternLoc, getLocEnd());
2102  }
2103
2104  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2105  static bool classof(const LinkageSpecDecl *D) { return true; }
2106  static bool classofKind(Kind K) { return K == LinkageSpec; }
2107  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2108    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2109  }
2110  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2111    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2112  }
2113};
2114
2115/// UsingDirectiveDecl - Represents C++ using-directive. For example:
2116///
2117///    using namespace std;
2118///
2119// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2120// artificial name, for all using-directives in order to store
2121// them in DeclContext effectively.
2122class UsingDirectiveDecl : public NamedDecl {
2123  /// \brief The location of the "using" keyword.
2124  SourceLocation UsingLoc;
2125
2126  /// SourceLocation - Location of 'namespace' token.
2127  SourceLocation NamespaceLoc;
2128
2129  /// \brief The nested-name-specifier that precedes the namespace.
2130  NestedNameSpecifierLoc QualifierLoc;
2131
2132  /// NominatedNamespace - Namespace nominated by using-directive.
2133  NamedDecl *NominatedNamespace;
2134
2135  /// Enclosing context containing both using-directive and nominated
2136  /// namespace.
2137  DeclContext *CommonAncestor;
2138
2139  /// getUsingDirectiveName - Returns special DeclarationName used by
2140  /// using-directives. This is only used by DeclContext for storing
2141  /// UsingDirectiveDecls in its lookup structure.
2142  static DeclarationName getName() {
2143    return DeclarationName::getUsingDirectiveName();
2144  }
2145
2146  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2147                     SourceLocation NamespcLoc,
2148                     NestedNameSpecifierLoc QualifierLoc,
2149                     SourceLocation IdentLoc,
2150                     NamedDecl *Nominated,
2151                     DeclContext *CommonAncestor)
2152    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2153      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2154      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2155
2156public:
2157  /// \brief Retrieve the nested-name-specifier that qualifies the
2158  /// name of the namespace, with source-location information.
2159  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2160
2161  /// \brief Retrieve the nested-name-specifier that qualifies the
2162  /// name of the namespace.
2163  NestedNameSpecifier *getQualifier() const {
2164    return QualifierLoc.getNestedNameSpecifier();
2165  }
2166
2167  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2168  const NamedDecl *getNominatedNamespaceAsWritten() const {
2169    return NominatedNamespace;
2170  }
2171
2172  /// getNominatedNamespace - Returns namespace nominated by using-directive.
2173  NamespaceDecl *getNominatedNamespace();
2174
2175  const NamespaceDecl *getNominatedNamespace() const {
2176    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2177  }
2178
2179  /// \brief Returns the common ancestor context of this using-directive and
2180  /// its nominated namespace.
2181  DeclContext *getCommonAncestor() { return CommonAncestor; }
2182  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2183
2184  /// \brief Return the location of the "using" keyword.
2185  SourceLocation getUsingLoc() const { return UsingLoc; }
2186
2187  // FIXME: Could omit 'Key' in name.
2188  /// getNamespaceKeyLocation - Returns location of namespace keyword.
2189  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2190
2191  /// getIdentLocation - Returns location of identifier.
2192  SourceLocation getIdentLocation() const { return getLocation(); }
2193
2194  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2195                                    SourceLocation UsingLoc,
2196                                    SourceLocation NamespaceLoc,
2197                                    NestedNameSpecifierLoc QualifierLoc,
2198                                    SourceLocation IdentLoc,
2199                                    NamedDecl *Nominated,
2200                                    DeclContext *CommonAncestor);
2201
2202  SourceRange getSourceRange() const {
2203    return SourceRange(UsingLoc, getLocation());
2204  }
2205
2206  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2207  static bool classof(const UsingDirectiveDecl *D) { return true; }
2208  static bool classofKind(Kind K) { return K == UsingDirective; }
2209
2210  // Friend for getUsingDirectiveName.
2211  friend class DeclContext;
2212
2213  friend class ASTDeclReader;
2214};
2215
2216/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
2217///
2218/// @code
2219/// namespace Foo = Bar;
2220/// @endcode
2221class NamespaceAliasDecl : public NamedDecl {
2222  /// \brief The location of the "namespace" keyword.
2223  SourceLocation NamespaceLoc;
2224
2225  /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2226  SourceLocation IdentLoc;
2227
2228  /// \brief The nested-name-specifier that precedes the namespace.
2229  NestedNameSpecifierLoc QualifierLoc;
2230
2231  /// Namespace - The Decl that this alias points to. Can either be a
2232  /// NamespaceDecl or a NamespaceAliasDecl.
2233  NamedDecl *Namespace;
2234
2235  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2236                     SourceLocation AliasLoc, IdentifierInfo *Alias,
2237                     NestedNameSpecifierLoc QualifierLoc,
2238                     SourceLocation IdentLoc, NamedDecl *Namespace)
2239    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2240      NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2241      QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2242
2243  friend class ASTDeclReader;
2244
2245public:
2246  /// \brief Retrieve the nested-name-specifier that qualifies the
2247  /// name of the namespace, with source-location information.
2248  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2249
2250  /// \brief Retrieve the nested-name-specifier that qualifies the
2251  /// name of the namespace.
2252  NestedNameSpecifier *getQualifier() const {
2253    return QualifierLoc.getNestedNameSpecifier();
2254  }
2255
2256  /// \brief Retrieve the namespace declaration aliased by this directive.
2257  NamespaceDecl *getNamespace() {
2258    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2259      return AD->getNamespace();
2260
2261    return cast<NamespaceDecl>(Namespace);
2262  }
2263
2264  const NamespaceDecl *getNamespace() const {
2265    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2266  }
2267
2268  /// Returns the location of the alias name, i.e. 'foo' in
2269  /// "namespace foo = ns::bar;".
2270  SourceLocation getAliasLoc() const { return getLocation(); }
2271
2272  /// Returns the location of the 'namespace' keyword.
2273  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2274
2275  /// Returns the location of the identifier in the named namespace.
2276  SourceLocation getTargetNameLoc() const { return IdentLoc; }
2277
2278  /// \brief Retrieve the namespace that this alias refers to, which
2279  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2280  NamedDecl *getAliasedNamespace() const { return Namespace; }
2281
2282  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2283                                    SourceLocation NamespaceLoc,
2284                                    SourceLocation AliasLoc,
2285                                    IdentifierInfo *Alias,
2286                                    NestedNameSpecifierLoc QualifierLoc,
2287                                    SourceLocation IdentLoc,
2288                                    NamedDecl *Namespace);
2289
2290  virtual SourceRange getSourceRange() const {
2291    return SourceRange(NamespaceLoc, IdentLoc);
2292  }
2293
2294  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2295  static bool classof(const NamespaceAliasDecl *D) { return true; }
2296  static bool classofKind(Kind K) { return K == NamespaceAlias; }
2297};
2298
2299/// UsingShadowDecl - Represents a shadow declaration introduced into
2300/// a scope by a (resolved) using declaration.  For example,
2301///
2302/// namespace A {
2303///   void foo();
2304/// }
2305/// namespace B {
2306///   using A::foo(); // <- a UsingDecl
2307///                   // Also creates a UsingShadowDecl for A::foo in B
2308/// }
2309///
2310class UsingShadowDecl : public NamedDecl {
2311  /// The referenced declaration.
2312  NamedDecl *Underlying;
2313
2314  /// \brief The using declaration which introduced this decl or the next using
2315  /// shadow declaration contained in the aforementioned using declaration.
2316  NamedDecl *UsingOrNextShadow;
2317  friend class UsingDecl;
2318
2319  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2320                  NamedDecl *Target)
2321    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2322      Underlying(Target),
2323      UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2324    if (Target) {
2325      setDeclName(Target->getDeclName());
2326      IdentifierNamespace = Target->getIdentifierNamespace();
2327    }
2328    setImplicit();
2329  }
2330
2331public:
2332  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2333                                 SourceLocation Loc, UsingDecl *Using,
2334                                 NamedDecl *Target) {
2335    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2336  }
2337
2338  /// \brief Gets the underlying declaration which has been brought into the
2339  /// local scope.
2340  NamedDecl *getTargetDecl() const { return Underlying; }
2341
2342  /// \brief Sets the underlying declaration which has been brought into the
2343  /// local scope.
2344  void setTargetDecl(NamedDecl* ND) {
2345    assert(ND && "Target decl is null!");
2346    Underlying = ND;
2347    IdentifierNamespace = ND->getIdentifierNamespace();
2348  }
2349
2350  /// \brief Gets the using declaration to which this declaration is tied.
2351  UsingDecl *getUsingDecl() const;
2352
2353  /// \brief The next using shadow declaration contained in the shadow decl
2354  /// chain of the using declaration which introduced this decl.
2355  UsingShadowDecl *getNextUsingShadowDecl() const {
2356    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2357  }
2358
2359  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2360  static bool classof(const UsingShadowDecl *D) { return true; }
2361  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2362
2363  friend class ASTDeclReader;
2364  friend class ASTDeclWriter;
2365};
2366
2367/// UsingDecl - Represents a C++ using-declaration. For example:
2368///    using someNameSpace::someIdentifier;
2369class UsingDecl : public NamedDecl {
2370  /// \brief The source location of the "using" location itself.
2371  SourceLocation UsingLocation;
2372
2373  /// \brief The nested-name-specifier that precedes the name.
2374  NestedNameSpecifierLoc QualifierLoc;
2375
2376  /// DNLoc - Provides source/type location info for the
2377  /// declaration name embedded in the ValueDecl base class.
2378  DeclarationNameLoc DNLoc;
2379
2380  /// \brief The first shadow declaration of the shadow decl chain associated
2381  /// with this using declaration.
2382  UsingShadowDecl *FirstUsingShadow;
2383
2384  // \brief Has 'typename' keyword.
2385  bool IsTypeName;
2386
2387  UsingDecl(DeclContext *DC, SourceLocation UL,
2388            NestedNameSpecifierLoc QualifierLoc,
2389            const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2390    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2391      UsingLocation(UL), QualifierLoc(QualifierLoc),
2392      DNLoc(NameInfo.getInfo()), FirstUsingShadow(0),IsTypeName(IsTypeNameArg) {
2393  }
2394
2395public:
2396  /// \brief Returns the source location of the "using" keyword.
2397  SourceLocation getUsingLocation() const { return UsingLocation; }
2398
2399  /// \brief Set the source location of the 'using' keyword.
2400  void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2401
2402  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2403  /// with source-location information.
2404  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2405
2406  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2407  NestedNameSpecifier *getQualifier() const {
2408    return QualifierLoc.getNestedNameSpecifier();
2409  }
2410
2411  DeclarationNameInfo getNameInfo() const {
2412    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2413  }
2414
2415  /// \brief Return true if the using declaration has 'typename'.
2416  bool isTypeName() const { return IsTypeName; }
2417
2418  /// \brief Sets whether the using declaration has 'typename'.
2419  void setTypeName(bool TN) { IsTypeName = TN; }
2420
2421  /// \brief Iterates through the using shadow declarations assosiated with
2422  /// this using declaration.
2423  class shadow_iterator {
2424    /// \brief The current using shadow declaration.
2425    UsingShadowDecl *Current;
2426
2427  public:
2428    typedef UsingShadowDecl*          value_type;
2429    typedef UsingShadowDecl*          reference;
2430    typedef UsingShadowDecl*          pointer;
2431    typedef std::forward_iterator_tag iterator_category;
2432    typedef std::ptrdiff_t            difference_type;
2433
2434    shadow_iterator() : Current(0) { }
2435    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2436
2437    reference operator*() const { return Current; }
2438    pointer operator->() const { return Current; }
2439
2440    shadow_iterator& operator++() {
2441      Current = Current->getNextUsingShadowDecl();
2442      return *this;
2443    }
2444
2445    shadow_iterator operator++(int) {
2446      shadow_iterator tmp(*this);
2447      ++(*this);
2448      return tmp;
2449    }
2450
2451    friend bool operator==(shadow_iterator x, shadow_iterator y) {
2452      return x.Current == y.Current;
2453    }
2454    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2455      return x.Current != y.Current;
2456    }
2457  };
2458
2459  shadow_iterator shadow_begin() const {
2460    return shadow_iterator(FirstUsingShadow);
2461  }
2462  shadow_iterator shadow_end() const { return shadow_iterator(); }
2463
2464  /// \brief Return the number of shadowed declarations associated with this
2465  /// using declaration.
2466  unsigned shadow_size() const {
2467    return std::distance(shadow_begin(), shadow_end());
2468  }
2469
2470  void addShadowDecl(UsingShadowDecl *S);
2471  void removeShadowDecl(UsingShadowDecl *S);
2472
2473  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2474                           SourceLocation UsingL,
2475                           NestedNameSpecifierLoc QualifierLoc,
2476                           const DeclarationNameInfo &NameInfo,
2477                           bool IsTypeNameArg);
2478
2479  SourceRange getSourceRange() const {
2480    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2481  }
2482
2483  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2484  static bool classof(const UsingDecl *D) { return true; }
2485  static bool classofKind(Kind K) { return K == Using; }
2486
2487  friend class ASTDeclReader;
2488  friend class ASTDeclWriter;
2489};
2490
2491/// UnresolvedUsingValueDecl - Represents a dependent using
2492/// declaration which was not marked with 'typename'.  Unlike
2493/// non-dependent using declarations, these *only* bring through
2494/// non-types; otherwise they would break two-phase lookup.
2495///
2496/// template <class T> class A : public Base<T> {
2497///   using Base<T>::foo;
2498/// };
2499class UnresolvedUsingValueDecl : public ValueDecl {
2500  /// \brief The source location of the 'using' keyword
2501  SourceLocation UsingLocation;
2502
2503  /// \brief The nested-name-specifier that precedes the name.
2504  NestedNameSpecifierLoc QualifierLoc;
2505
2506  /// DNLoc - Provides source/type location info for the
2507  /// declaration name embedded in the ValueDecl base class.
2508  DeclarationNameLoc DNLoc;
2509
2510  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2511                           SourceLocation UsingLoc,
2512                           NestedNameSpecifierLoc QualifierLoc,
2513                           const DeclarationNameInfo &NameInfo)
2514    : ValueDecl(UnresolvedUsingValue, DC,
2515                NameInfo.getLoc(), NameInfo.getName(), Ty),
2516      UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2517      DNLoc(NameInfo.getInfo())
2518  { }
2519
2520public:
2521  /// \brief Returns the source location of the 'using' keyword.
2522  SourceLocation getUsingLoc() const { return UsingLocation; }
2523
2524  /// \brief Set the source location of the 'using' keyword.
2525  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2526
2527  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2528  /// with source-location information.
2529  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2530
2531  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2532  NestedNameSpecifier *getQualifier() const {
2533    return QualifierLoc.getNestedNameSpecifier();
2534  }
2535
2536  DeclarationNameInfo getNameInfo() const {
2537    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2538  }
2539
2540  static UnresolvedUsingValueDecl *
2541    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2542           NestedNameSpecifierLoc QualifierLoc,
2543           const DeclarationNameInfo &NameInfo);
2544
2545  SourceRange getSourceRange() const {
2546    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2547  }
2548
2549  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2550  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2551  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2552
2553  friend class ASTDeclReader;
2554  friend class ASTDeclWriter;
2555};
2556
2557/// UnresolvedUsingTypenameDecl - Represents a dependent using
2558/// declaration which was marked with 'typename'.
2559///
2560/// template <class T> class A : public Base<T> {
2561///   using typename Base<T>::foo;
2562/// };
2563///
2564/// The type associated with a unresolved using typename decl is
2565/// currently always a typename type.
2566class UnresolvedUsingTypenameDecl : public TypeDecl {
2567  /// \brief The source location of the 'using' keyword
2568  SourceLocation UsingLocation;
2569
2570  /// \brief The source location of the 'typename' keyword
2571  SourceLocation TypenameLocation;
2572
2573  /// \brief The nested-name-specifier that precedes the name.
2574  NestedNameSpecifierLoc QualifierLoc;
2575
2576  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2577                              SourceLocation TypenameLoc,
2578                              NestedNameSpecifierLoc QualifierLoc,
2579                              SourceLocation TargetNameLoc,
2580                              IdentifierInfo *TargetName)
2581    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2582               UsingLoc),
2583      TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2584
2585  friend class ASTDeclReader;
2586
2587public:
2588  /// \brief Returns the source location of the 'using' keyword.
2589  SourceLocation getUsingLoc() const { return getLocStart(); }
2590
2591  /// \brief Returns the source location of the 'typename' keyword.
2592  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2593
2594  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2595  /// with source-location information.
2596  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2597
2598  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2599  NestedNameSpecifier *getQualifier() const {
2600    return QualifierLoc.getNestedNameSpecifier();
2601  }
2602
2603  static UnresolvedUsingTypenameDecl *
2604    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2605           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2606           SourceLocation TargetNameLoc, DeclarationName TargetName);
2607
2608  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2609  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2610  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2611};
2612
2613/// StaticAssertDecl - Represents a C++0x static_assert declaration.
2614class StaticAssertDecl : public Decl {
2615  Expr *AssertExpr;
2616  StringLiteral *Message;
2617  SourceLocation RParenLoc;
2618
2619  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2620                   Expr *assertexpr, StringLiteral *message,
2621                   SourceLocation RParenLoc)
2622  : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr),
2623    Message(message), RParenLoc(RParenLoc) { }
2624
2625public:
2626  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2627                                  SourceLocation StaticAssertLoc,
2628                                  Expr *AssertExpr, StringLiteral *Message,
2629                                  SourceLocation RParenLoc);
2630
2631  Expr *getAssertExpr() { return AssertExpr; }
2632  const Expr *getAssertExpr() const { return AssertExpr; }
2633
2634  StringLiteral *getMessage() { return Message; }
2635  const StringLiteral *getMessage() const { return Message; }
2636
2637  SourceLocation getRParenLoc() const { return RParenLoc; }
2638  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2639
2640  SourceRange getSourceRange() const {
2641    return SourceRange(getLocation(), getRParenLoc());
2642  }
2643
2644  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2645  static bool classof(StaticAssertDecl *D) { return true; }
2646  static bool classofKind(Kind K) { return K == StaticAssert; }
2647
2648  friend class ASTDeclReader;
2649};
2650
2651/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
2652/// into a diagnostic with <<.
2653const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2654                                    AccessSpecifier AS);
2655
2656} // end namespace clang
2657
2658#endif
2659