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