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