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