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