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